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

[REBOL] Zoom and Pan

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 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 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. **************************************************************************