[REBOL] draw has no access to the current face
From: rebol665:ifrance at: 29-Sep-2002 18:04
Hi List,
A problem with the draw dialect used in an effect block. My goal is to
display 4 buttons. My first attempt was to use a style.
draw-layout: [
h2 "Draw buttons"
style draw-button box 24x24 effect [draw [pen black fill-pen red circle
12x12 10]]
across
draw-button [ print "hey, I'm clicked!"]
draw-button [ print "hey, I'm clicked!"]
draw-button [ print "hey, I'm clicked!"]
draw-button [ print "hey, I'm clicked!"]
]
view center-face layout draw-layout
This works! However I want 4 different colors and possibly just one
parameterizable style. The idea is to use a unique effect block as a model.
The only thing I want to change is the fill-color of the circle. To help the
changing, I have put a word in the effect block.
[pen black fill-pen x-color circle 12x12 10]
The idea is to replace x-color with the desired color at runtime. Finally
the desired color is stored in the face/user-data .
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
This works too but there could be a simpler solution. I have tried to use a
draw block like that:
[pen black fill-pen face/user-data circle 12x12 10]
Unfortunately face/user-data is unknown in this block.
Is there a way to access the face object here? That is my question !
Patrick