[REBOL] Re: Counter measures
From: carl:cybercraft at: 6-Sep-2002 18:44
On 06-Sep-02, Gabriele Santilli wrote:
> Hi Carl,
> On Friday, September 6, 2002, 12:14:50 AM, you wrote:
>> them.} is probably the way to do this, but I for one would like
>> see an example - as my attempt at doing it doesn't work. (:
> swap: func [series] [reverse/part series 2 series]
> win: layout [
> box 50x50 green
> at 45x45 box 50x50 red
> button "swap" [swap win/pane show win]
> ]
> view win
Thanks Gabriele. I'd got stumped with how to swap a value in a series
without removing and reinserting it, thus giving it a new reference.
I'd forgotten about 'reverse.
For Sunanda, here's the above method in action, just in case you're
not familar with a layout's pane block. (It contains all the styles
(or panes, if you will) in a layout.) I moved the dice to the end of
the layout, as then they'll always be in front of anything else in
the layout and swapping them becomes simple as you just need to swap
the last two panes in the block. And your board's layout is now
called 'board...
rebol []
; This function just makes an image from a layout...
make-die: func [color [tuple!] /local image][
layout [
image: box 30x30 effect [draw [
pen none
fill-pen color none
circle 14x14 15
]]
]
to-image image
]
Board-elements: Stylize [
black-square: box 100.100.100 50x50
white-square: box white 50x50
; 'die is now an image - note the 'key effect used
; to make the black in the image transparent.
die: box 30x30 effect [key 0.0.0 oval]
]
swap: func [face][
if face/color <> get in last board/pane 'color [
reverse/part back back tail board/pane 2
show [d1 d2]
]
]
view board: layout [
styles board-elements
space 0x0
across
black-square
white-square
black-square
return
white-square
black-square
white-square
return
black-square
white-square
black-square
return
; User-defined color. (;
button "change" [
d1/color: random 255.255.255
show d1
]
; The 'feels here are just a copy of the drag & drop
; example from the 'feel how-to example on the REBOL
; site.
d1: die feel [engage: func [face action event] [
if action = 'down [swap :d1 start: event/offset]
if find [over away] action [
face/offset: face/offset + event/offset - start
show face
]
]]
d2: die feel [engage: func [face action event] [
if action = 'down [swap :d2 start: event/offset]
if find [over away] action [
face/offset: face/offset + event/offset - start
show face
]
]]
; Set original colors...
do [
d1/color: red
d2/color: blue
]
]
--
Carl Read