[REBOL] Re: Counter measures
From: gscottjones:mchsi at: 6-Sep-2002 4:25
From: Sunanda
<snip>
> I need to take an arbitrary screen element and pop it to the top. I think
> this revised code does that. The change is mainly replacing Gabriele's
Swap
> with 'move-to-end, and tweaking Carl's code to use this new function.
This is cool! While in theory I had previously recognized how this effect
might be done, I had never realized how *easily* it could be done.
And just a final bit of *gratuitous* refactoring:
- moved feel up to stylize definition
- defined die color at die instantiation
(that's why I said it was gratuitous :-)
Cool!
--Scott Jones
rebol []
unview/all
; 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.
; and
; The 'feel here are just a copy of the drag & drop
; example from the 'feel how-to example on the REBOL
; site.
die: box 30x30 effect [key 0.0.0 oval] feel [engage: func [face action
event] [
if action = 'down [move-to-end board/pane face start: event/offset]
if find [over away] action [
face/offset: face/offset + event/offset - start
show face
]
]]
]
move-to-end: func [series item /local item-index item-value][
item-index: find series item
item-value: first item-index
remove item-index
append series item-value
show last series
show item-value
]
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
move-to-end board/pane d1
]
d1: die red
d2: die blue
return
d3: die green
d4: die yellow
]