[REBOL] Re: draw has no access to the current face
From: rebol665::ifrance::com at: 30-Sep-2002 23:52
Hi List
Previously in the "draw has no access to the current face" post:
On my quest to produce buttons displayed with the draw dialect and to be
able to have several colors I came to the List with the following code. I
was looking for a more elegant coding.
draw-layout: [
h2 "Draw buttons"
style draw-button box 24x24 effect [
draw [pen black fill-pen x-color circle 12x12 10]]
feel [
redraw: func [face act pos][
if act = 'draw [replace face/effect/2 'x-color face/user-data]
]
]
with [user-data: 'white]
across
r-btn: draw-button [ print "hey, I'm red"] with [user-data: 'red]
b-btn: draw-button [ print "hey, I'm blue"] with [user-data: 'blue]
y-btn: draw-button [ print "hey, I'm yellow!"] with [user-data: 'yellow]
g-btn: draw-button [ print "hey, I'm green!"] with [user-data: 'green]
]
view center-face layout draw-layout
Romano Paolo Tenca (BTW may I call you Romano for short? ) came with this
beauty:
draw-layout: [
h2 "Draw buttons"
style draw-button box 24x24 with [
effect: [draw [pen black fill-pen user-data circle 12x12 10]]
]
across
r-btn: draw-button user-data red [ print "hey, I'm red"]
b-btn: draw-button user-data blue [ print "hey, I'm blue"]
y-btn: draw-button user-data yellow [ print "hey, I'm yellow!"]
g-btn: draw-button user-data green [ print "hey, I'm green!"]
]
view center-face layout draw-layout
Quoting Romano the with "magically binds the effect block words to the face
objects words".
I have some questions about this:
Could someone tell me more about this "magic" with ? why is it no more
needed in "user-data red"? why effect is now a set-word! ?
I was asking myself the same questions, when Anton stabbed me in the back
with an even more puzzling code with a "little dialect using the words
facet".
draw-layout: [
h2 "Draw buttons"
style draw-button box 24x24
effect [draw [pen black fill-pen 0.0.0 circle 12x12 10]]
with [ words: compose [fill ( func [new args][
new/effect/2/4: second args
next args ] ) ] ]
across
r-btn: draw-button fill red [ print "hey, I'm red"]
b-btn: draw-button fill blue [ print "hey, I'm blue"]
y-btn: draw-button fill yellow [ print "hey, I'm yellow!"]
g-btn: draw-button fill green [ print "hey, I'm green!"]
]
view center-face layout draw-layout
As it seems to me, words is a face/facet used to define a face behaviour in
the form of a function. In this function, new is the object face, while args
is a block like [fill 255.0.0 [print "hey, I'm red"]]. The "next args" part
is a bit of a puzzle, because it cannot be removed or the face is not
displayed correctly. Its goal seems to return whatever is left to be
processed to finish the face display.
Here again, guru's help and comments will be greatly appreciated.
And BTW, I am very thankful to Anton and Romano for their brilliant
contributions.
Patrick