Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Some other questions

From: carl:cybercraft at: 24-Dec-2003 22:49

On 22-Nov-03, Mike Loolard wrote:
> I hope you guys don't mind me asking some other questions I have > come up with meanwhile.
Hi Mike, A few answers here, if not for all your questions...
> 1) If I have an object - how do I create an array of objects with it > ? for example > chicken: make object! [ > tasty: "wings" > ] > now I would want to have an array of objects of that type. > I tried it like that: > chickenfarm: make chicken [] array 10 > It doesn't seem to work that way, though ? I've read all stuff > available about objects and array on the REBOL pages, but either I'm > blind or there isn't anything about creating an array of objects ?
chickenfarm: array/initial 10 chicken
> 2) How do you create custom types ? > I am talking of a way to emulate the typedef behavour in C ? > How would you go to create an "enum" type in REBOL ?
Pass...
> 3) Back on objects: > objects seem to be pretty neat in REBOL - but I didn't find anything > about implementing > and using constructor/destructors ? > I know I could manually add a function that serves as constructor > each time I create an object, but is that the way REBOL requires it > ?
Pass...
> 4) In the same context: > how do I actually 'free' memory/variables ?
Memory's managed automatically with REBOL, so unless you're having trouble with it, don't worry about it. For instance, if you have this... file: read %very-big-file ... file: none the memory used by very-big-file will be automatically reclaimed - unless you've referenced it by another word. That said, you can force a freeing up of memory with RECYCLE if needs be.
> 5) On the webpage about objects one passage mentioned that > "sub-objects" don't get cloned- > what does that mean ? Reading that I would expect that all objects > within an object aren't > available when I create an object on the basis of that object. But I > seem to be able to use it anyway. Maybe I am getting something wrong > here ?
It means that sub-objects are the same object. ie...
>> obj: make object! [sub-object: make object! [test: "text"]] >> obj2: make obj [] >> same? obj obj2
== false
>> same? obj/sub-object obj2/sub-object
== true So, if you alter sub-object in obj2 there, sub-object in obj will also be altered...
>> probe obj/sub-object/test
text == "text"
>> obj2/sub-object/test: 10
== 10
>> probe obj/sub-object/test
10 == 10
> 6) in VIEW/VID: How do you open/create several windows > simultaneously ? I am also talking of being able to refresh each > window.
Here's one way... win1: layout [f1: field "1" 100] win2: layout [f2: field "2" 100] win3: layout [f3: field "3" 100] view layout [ button "Open Windows" [ view/new/offset win1 180x40 view/new/offset win2 330x40 view/new/offset win3 480x40 ] button "Update Windows" [ append f1/text first f1/text append f2/text first f2/text append f3/text first f3/text show [win1 win2 win3] ] ]
> 7) Trying to find a solution to the problem above I looked around > the REBOL webpages > and searched for a possibility to create threads - there doesn't > seem to be anything > like that - how is "parallel processing" achieved in REBOL ? How > would you update a dialog but also keep a timer running as well as > rotating an image ?
Each face in a layout can have its own event processing using FEEL. Here's a window with the time being ubdated every second and a box rotating four times a second... pic: to-image layout [backdrop black box blue "A Box"] view layout [ text to-string now/time 100 rate 1 feel [ engage: func [face action event][ if action = 'time [ face/text: to-string now/time show face ] ] ] image pic effect [rotate 90] rate 4 feel [ engage: func [face action event][ if action = 'time [ face/effect/2: face/effect/2 + 90 // 360 show face ] ] ] ] There's a HowTo section on RT's site about FEEL... http://www.rebol.com/how-to/feel.html
> 8) On image rotation: is there any simple way to overcome the 90 > restriction - > I am not tallking of bitshifting manually ;-)
I think you need to be. ;)
> What's the reason for this restriction ?
RT hasn't implimented it yet.
> 9) Image creation/processing > I read it would be possible to create images on the fly and work > with these then - > is it possible to store an entire (view) layout within such an image > ?
Yes - to-image layout [whatever] like I've done above.
> Could you for example draw a line on a "virtual" view and save this > then to an image file ?
Yes, and to disk if you want... save/png %test.png to-image layout [ box effect [draw[line 0x0 199x199]] ] and to view it... view layout [image load %test.png]
> Or would you rather simply take the coordinates of the line and > create the image with that data ?
You can do that to... start: 0x0 view layout [ b: box effect [draw[line start 199x199]] button "+" [start/x: start/x + 10 show b] button "-" [start/x: start/x - 10 show b] ]
> 10) Image processing > Is it possible to create new images (in memory) by adding other > images to the original image at certain coordinates ?
Doing it in a layout and then using TO-IMAGE is the simpliest, though you can work directly on the image datatype...
>> pic: make image! 2x2
== make image! [2x2 #{000000000000000000000000}]
>> pic/1: 255.255.255.255
== make image! [2x2 #{FFFFFF000000000000000000}]
>> pic/3: 18.18.18.18
== make image! [2x2 #{FFFFFF000000121212000000}] Gets a lot trickier to put images into images of course, but is possible.
> Having tried to overlay transparent GIFs in a VIEW layout, I noticed > the transparency attribute doesn't seem to be preserved ? At least > transparent areas of my GIF didn't show the image below that one, > but rather a WHITE area. IF transparent GIFs are supported: what do > you need to do to really display them properly ?
Pass...
> 11) VID controls > If I need certain additional features for a basic control - like a > progress bar or slider, > how do I add these ? Do I need to edit the dialect ? For example, I > want a progress bar with tic-marks as well as a non-continous > filling of the bar. > So, is there any way to "sub-class" controls easily to enhace their > functionality/appearance without having to re-write everything from > scratch?
Pass...
> 12) Is there any really thorough information available on ACTIONS > and EVENTS with REBOL/VIEW ? > They documentation on the REBOL pages seems a bit 'poor' on that > matter. I don't know yet, how these things are really done behind > the scenes.
Have you seen the HowTo on FEEL? (Link above.)
> 13) I didn't see any designated function to set pixels at certain > coordinates in a layout- > my workaround was using the line word - with 1 width/height. > How is this really done ?
That's one way, the other being to work directly on an image in a layout. ie... pic: make image! 100x100 view layout [ image pic rate 10 feel [ engage: func [face action event][ if action = 'time [ poke face/image random (length? face/image) / 4 random 255.255.255 show face ] ] ] ]
> 14) How do I catch mouse events - such as a mouseover event ? I read > about 'over' - it seems to do exactly what I need - I want to > display controls in a certain area only when the mouse cursor is in > that said area. Also, that functionality could be used to add > tooltip-like behaviour to buttons > and menus.
Once again, see the HowTo on FEEL mentioned above.
> Again: thanks for your help and patience folks - it's really > appreciated !!
Hope that helps! Hmm - the rugby's started... ;) -- Carl Read