Home   Archive   Permalink



Change backdrop image in Rebol/View 2.7

The code below displays an apple--forever and ever. Why doesn't it display the apple for two seconds, then display the orange for two seconds?
    
I think I've missed something fundamental.
    
Thanks!
Pete
    
    
R E B O L []
    
view my-face: layout [
    size 512x512
    my-backdrop: backdrop %apple.png
    ]
    
wait 2
    
my-face/my-backdrop: %orange.png
show my-backdrop
    
wait 2


posted by:   Pete Williams     24-Apr-2014/17:23:34-7:00



Hi Pete,
    
The event loop starts as soon as you 'view a layout, so your code after the 'layout block doesn't get evaluated until after the window is closed. You can avoid starting the event loop with view/new:
    
R E B O L []
view/new layout [
     size 512x512
     my-backdrop: backdrop stop.gif
]
wait 2
my-backdrop/image: info.gif
show my-backdrop
wait 2

posted by:   Nick     24-Apr-2014/17:42:07-7:00



Thanks, Nick!
    
I had tried every permutation, and I was cracking up a little. Seeing that it can be made to work makes a big difference, as I'd been unable to find anything quite like it in any of the tutorials or documentation.
    
My actual problem turns out to be with the way I am referencing the image files. I made the assumption that using "%" would work with the image files and *.r file in the same folder. Is there some other way I need to refer to these files, so the code will look in the same folder as the program?

posted by:   Pete Williams     24-Apr-2014/18:40:48-7:00



If your file is in the same folder as your running script, you should be able to refer to them as, for example, %image.png . You can refer to files in other folders as, for example: %../image.jpg %/c/windows/web/wallpaper/img1.jpg

posted by:   Nick     24-Apr-2014/19:13:26-7:00



R E B O L []
view/new my-face: layout [
     size 512x512
     my-backdrop: backdrop %/c/windows/web/wallpaper/img1.jpg
]
wait 2
my-backdrop/image: info.gif
show my-backdrop
wait 2
    
In some cases, you may need to load the image:
    
R E B O L []
view/new my-face: layout [
     size 512x512
     my-backdrop: backdrop (load %/c/windows/web/wallpaper/img1.jpg)
]
wait 2
my-backdrop/image: info.gif
show my-backdrop
wait 2

posted by:   Nick     24-Apr-2014/19:15:35-7:00



Nick,
    
The latter case you provide solves my problem: adding the parentheses and "load" did the trick.
    
    
>>>In some cases, you may need to load the image.
    
Can you help me to understand why this is one of those cases?

posted by:   Pete Williams     24-Apr-2014/19:55:42-7:00



As you probably guess, what I presented above was not the project itself, but a distillation of a problem I'd encountered. I'm very pleased to tell you that I'm now back on track, and am in the home stretch on that project, thanks to you.
    
Best regards!

posted by:   Pete Williams     24-Apr-2014/20:19:35-7:00



About laoding: in some cases, the VID dialect conveniently handles loading the image data for you, where an image is the expected data type (you just type the filename, and the dialect has some built-in logic to automatically load it). Typically though, in cases where you need to manipulate image data, you'll need to load that data from a file (assign it a variable label, etc).

posted by:   Nick     25-Apr-2014/7:49:35-7:00



Okay--thanks!

posted by:   Pete Williams     25-Apr-2014/15:48:39-7:00