Cabbage Logo
Back to Cabbage Site

Is it possible to dynamically alter an image widget? (fixed)

I’ve been playing around with some instrument ideas that use image files as data sources. It would be useful if I could create an image widget with a specific bounds, and then dynamically alter what it’s contents are via identchannels. The dynamic content should be resized to fit in the original widget’s bounds.

Is this already possible? I tried a quick test, but it didn’t seem to work.

Are you talking about dynamically drawing a new image to the widget? I just looked through the code and it seems like this should be possible? Did you take a look at Iain’s ModifyingWidgets examples in the Instructional examples? He does about everything you can do to an image widget there, except updating the actual image!

I had looked at that example quite a while ago, it actually was an eye opener that really helped me understand some of the fancier things I could do with the widgets. I pulled up that example again, and I don’t see anything relevant to my question… but I could be missing something.

Yes, I’d like to draw a new image to the widget. The instrument has a filebutton to select a .png file, I’d like the image file selected by the user at run time to be dynamically displayed in the image widget.

I tried:

  Sfile chnget "filename"
  if changed(Sfile)==1 then
    chnset sprintfk("file(%s)",Sfile), "image-c"
    chnset sprintfk("text(Loading %s)",Sfile), "debug"

But it doesn’t seem to be working. Just in case, these are the widgets:

filebutton bounds(  5,  5, 90, 25), text("Open Image","Open Image"), fontcolour("white") channel("filename"), shape("ellipse")
image bounds(226, -2, 200, 150), identchannel("image-c")

That’s a bug. Darn it. It was working. I’ll take a look tomorrow when I have more time. The only problem is that I’ll not be able to prepare an OSX build for a few weeks.

Fixed in GIT.

OK, good to know I was going about it correctly. A few weeks is a long wait, but no worries. It will give me some time to work on the actual instrument rather than focusing on the eye candy. Seeing the image would be nice, but is trivial to the function in my particular case.

By the way, there’s a missing quote in Iain’s example that you mentioned, on line 21. It still functions properly, but breaks the syntax highlighting in the editor. It’s a quick and easy fix, I’d imagine Iain wouldn’t mind if you dropped an extra quote in the distributed code. :wink:

I’m sure he won’t mind!

It’s an old topic, but it seems I’m running into the same problem, I can’t change an image file by chnset (other properties are working fine). Do you remember what was the issue ?

I’ll take a look. In the mean time, you can simply load another image and make it invisible (visible(0)) until you need it.

actually, I want to emulate an LCD panel for my synth, I grabbed a cool ttf font. As I don’t see a way of changing the default font in Cabbage (is it possible by the way?),
I wanted to create x tiny images that I could change later according to what I need to display

Hmm. That’s presents a nice programming challenge. One way of doing it would be to create 7 rectangular images. And then move them around according to the value/char you want printed. Maybe make a new thread and we can share some ideas there?