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

[REBOL] Re: [enum][constructor][memory][cloning][vid] Some other questions

From: antonr::iinet::net::au at: 22-Nov-2003 21:17

> How would you go to create an "enum" type in REBOL ?
I haven't needed or missed enums for a long time! :) I you really need to you could do this: colours: [ red 1000 green 1100 blue 1300 ] colours/green ;== 1100 But to be honest, I'm trying to think of some reason I would need to do that. Perhaps if converting C <-> rebol.
> 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 ?
Rebol by default, calls no constructor function when it creates an object using make. But you can write your own system if you like, really easily: my-make: func [object spec /local new-obj][ new-obj: make object spec if in new-obj 'init [new-obj/init] ; do constructor if exists new-obj ; return the new object ] Now you can do this (over-simplistic example): obj: make object! [val: 0 init: does [val: 23]] probe my-make obj []
> 4) In the same context: > how do I actually 'free' memory/variables ?
In addition to setting the words to none, you can unset them: word: 23 unset 'word Memory is freed automatically at some later point by the garbage collector. You can force garbage collection using recycle: recycle
> 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 ?
My other post about the chickenfarm shows the lack of cloning, which you probably don't want in the chicken example. Look at this: ; make an object measurement: make object! [arm: 23 leg: 34] ; make an object containing a reference to ; the first object person: make object! [sizes: make measurement []] ; clone the second object person2: make person [] ; check if the "sizes" sub-object is the same in each same? person/sizes person2/sizes ;== true Both person and person2 share the same object, well, that means, currently the 'sizes word points to the one and the same object. Here's a picture: person/sizes -----+---> make object! [arm: 23 leg: 34] | | person2/sizes ----' Let's clone the sub-object now, as well: person3: make person [sizes: make sizes []] Here's a picture: person/sizes ---------> make object! [arm: 23 leg: 34] person2/sizes --------> make object! [arm: 23 leg: 34]
> 6) in VIEW/VID: How do you open/create several windows simultaneously ? > I am also talking of being able to refresh each window.
view/new lay: layout [button] view/new center-face lay2: layout [field] wait none ; wait for gui events ; (so you can close the windows, otherwise use ;unview/only lay ;, for instance, to close first window)
> 8) On image rotation: is there any simple way to overcome the 90 > restriction - > I am not tallking of bitshifting manually ;-) > What's the reason for this restriction ?
I wish rotation was built in but it hasn't happened yet. I made a rotation function but it's slow. http://www.lexicon.net/anton/rebol/library/rotate.r
> 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 ? > > Could you for example draw a line on a "virtual" view and save > this then to > an > image file ? > Or would you rather simply take the coordinates of the line and create the > image with that data ? > > 10) Image processing > > Is it possible to create new images (in memory) by adding other images > to the original image at certain coordinates ?
Yes, line drawing and placing images can be done using the Rebol/View Draw dialect: http://www.rebol.com/docs-view.html
> 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 ?
That is a problem of last full release of Rebol/View 1.2.1 A newer beta version will fix it. You can get View 1.2.5 beta here: http://www.rebol.com/beta-versions.html or View 1.2.10 beta which is what we are all using anyway: http://www.reboltech.com/downloads/ (If on windows, download the view1210031.exe) You can place the executable in the same directory as your old rebol (just named differently). I have six different version of rebol/view in the same directory for testing, so it's safe.
> 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?
Yes, there is, but it's a bit advanced, I'm afraid it takes quite a bit of reading and practise. In the beginning I learned from Gabriele, Brett Handley www.codeconscious.com and others. I have also made quite a few styles, see my site http://www.lexicon.net/anton/rebol/ (better if you go there via the view desktop.) Go into the gui/ subdirectory and click on all the links starting with "demo-". Some of them are really simple, so they can help you learn the basic idea.
> 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.
The ultimate truth can be found in the source, and there's lots of that. :) There are some quality docs around, not found on the rebol technologies site. It was a bit of a struggle to learn the order of events at first, I admit. Ask your questions here.
> 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 ?
Unfortunately, that's it. At least it works. :)
> 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.
Here's a start: layout [button feel [probe self]] ; examine button's feel view layout [ button feel [ over: func [face action event][print 'hello] ] ]
> Mike
Anton.