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

Zoom and Pan

 [1/2] from: atruter::hih::com::au at: 21-Mar-2002 13:28


The following code (apologies for unusually long sample!) implements simple zoom and pan functionality (inspired by http://www.rebol.cz/~can/cyklo.r) and works in its own right but the following issues have me stumped. How can the zoom style call to "refresh-zoom-window" be localised to something like obj/refresh-zoom-window (ie. how can we tell a style to use a function in the parent's scope). Given that the style can have a crop effect (see commented line below) that produces the desired effect, how can we pass the rendered image that results from this effect to another face (ie. can we replace the call to "refresh-zoom-window" with "zoom-img: face/image" . . . where does the face hold its image). The question that arises from 1 & 2 above is how can we direct the style to effect a dynamically determined face other than its own or its parent (eg. instead of "face/parent-face/size: 0x0" we may want "obj/zoom-box/size: 0x0"). I suppose what I am after is the ability to do: stylize/master [ zoom: func[obj other-face] box with [ . . . ] Have I missed any obvious ways of passing word references to a style when it is assigned? (The answer is on the tip of my tongue, so I'll say "DUH!" in advance when someone points out how easy all this really is ;) ) <CODE> stylize/master [ zoom: box with [ size: 100x100 ; effect: compose [crop 0x0 (face/size - 4x4) fit] feel: make feel [ engage: func [face action event] [ if action = 'down [face/data: event/offset] if action = 'alt-down [face/data: none] if event/type = 'move [ either pair? face/data [ face/offset: face/offset + event/offset - face/data face/offset: confine face/offset face/size 0x0 face/parent-face/size ][ ; force square face/size: max event/offset reverse event/offset ; prevent under-size if face/size/x < 10 [face/size: 20x20] ; prevent over-size if (face/offset/x + face/size/x) > face/parent-face/size/x [ face/size: face/parent-face/size - face/offset if face/size/x <> face/size/y [ face/size: min face/size reverse face/size ] ] if (face/offset/y + face/size/y) > face/parent-face/size/y [ face/size: face/parent-face/size - face/offset if face/size/x <> face/size/y [ face/size: min face/size reverse face/size ] ] ] ] show face refresh-zoom-window face/offset face/size ] ] ] ] jpg-file: load-image http://www.rebol.com/view/palms.jpg view/new/offset layout [ origin 0 space 0 text "Move zoombox with left mouse button" text "Resize zoombox with right mouse button" panel jpg-file/size [ at 0x0 img: image jpg-file jpg-file/size at 0x0 img-zoom: zoom ibevel ] button "Close" [quit] ] 3x27 refresh-zoom-window: func [offset size /local crop-at [pair!] crop-size [pair!]] [ crop-size: 0x0 crop-at: jpg-file/size * offset / img/size crop-size/x: jpg-file/size/y * size/y / img/size/y crop-size/y: crop-size/x zoom-img/effect: compose [crop (crop-at) (crop-size) fit] zoom-scale: min img/size/x img/size/y / size/x zoom-info/text: reform [to-integer zoom-scale ": 1"] show zoom-img show zoom-info ] view/new/offset layout [ origin 0 space 0 zoom-info: info green zoom-img: image 200x200 jpg-file do [refresh-zoom-window img-zoom/offset img-zoom/size] ] 3x27 + to-pair reduce [jpg-file/size/x + 6 0] do-events </CODE> Regards, Ashley *****************Privacy, Confidentiality & Liability Notice ************ This email is intended for the named recipient only. The information contained in this message may be confidential, or commercially sensitive. If you are not the intended recipient you must not reproduce or distribute any part of this email, disclose its contents to any other party, or take any action in reliance on it. If you have received this email in error, please contact the sender immediately. Please delete this message from your computer. You must scan this email and any attached files for viruses. The company accepts no liability for any loss, damage or consequence, whether caused by our own negligence or not, resulting directly or indirectly from the use of any attached files. Any views expressed in this Communication are those of the individual sender, except where the sender specifically states them to be the views of the Company. **************************************************************************

 [2/2] from: brett:codeconscious at: 21-Mar-2002 20:26


Hi Ashley,
> How can the zoom style call to "refresh-zoom-window" be localised to > something like obj/refresh-zoom-window (ie. how can we tell a style to > use a function in the parent's scope).
The word WITH in stylize/layout works like MAKE object!. It allows you to add extra fields to your face objects. So in your WITH block for your style you could put a line like: zoom-img: none This will create a new field in your ZOOM style with that name, which will enable you to have nice reference to the dependent magnified face. Or perhaps to the window - the principle is the same. In the same way you could add your refresh-zoom-window function (after modification for references) to the style itself. Also, instead of passing offset and size, pass a reference to the main (image) face. This sort of thing should enable refresh-zoom-window to be localised as you wanted. Now how you set up the link... Various means I guess. You could pass it as a specific keyword that your style defines. For an example have a look at "Custom Style Example" in http://www.codeconscious.com/rebsite/vid-notes.r In this example I've defined a word "bars" specific to that style. Another way (and this is speculation because I have not tried it) could be that your style automatically creates and destroys the magnification window. Perhaps you could do this in the redraw function of the feel. Make a redraw function that creates the window if it is not already created on an action of 'show and destroys the window on an action of 'hide. Then your link is automatic :^).
> Given that the style can have a crop effect (see commented line below) > that produces the desired effect, how can we pass the rendered image > that results from this effect to another face (ie. can we replace the > call to "refresh-zoom-window" with "zoom-img: face/image" . . . where > does the face hold its image).
Perhaps TO-IMAGE face will do the trick.
> The question that arises from 1 & 2 above is how can we direct the
style
> to effect a dynamically determined face other than its own or its
parent
> (eg. instead of "face/parent-face/size: 0x0" we may want > "obj/zoom-box/size: 0x0"). > > I suppose what I am after is the ability to do: > > stylize/master [ > zoom: func[obj other-face] box with [ . . . > ]
I'm not entirely sure want you after here. Regards, Brett.