draw has no access to the current face
[1/16] 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
[2/16] from: greggirwin:mindspring at: 29-Sep-2002 11:27
Hi Patrick,
<< Unfortunately face/user-data is unknown in this block.
Is there a way to access the face object here? That is my question ! >>
I don't think so. I'm certainly no guru in this area, but I just
compose/modify my draw blocks and update them myself, then show the face,
rather than putting dynamic elements directly in them for evaluation.
I don't know if you want to do it in REDRAW though, since that can get
called quite a lot, generating a lot of data that needs to be recycled.
--Gregg
[3/16] from: gscottjones:mchsi at: 29-Sep-2002 13:04
From: "Gregg Irwin"
> Hi Patrick,
> << Unfortunately face/user-data is unknown in this block.
<<quoted lines omitted: 4>>
> I don't know if you want to do it in REDRAW though, since that can get
> called quite a lot, generating a lot of data that needs to be recycled.
Hi, Patrick, (Gregg,)
I agree with Gregg. You could use your basic idea, but let init do the
swapping, since it is only called once. The only way that I am familiar
with appending init is as follow:
db: stylize [
draw-button: box 24x24 with [
effect: [
draw [pen black fill-pen x-color circle 12x12 10]
]
user-data: 'white
append init [
replace effect/2 'x-color user-data]
]
]
draw-layout: [
styles db
h2 "Draw buttons"
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
Some other clever chap may know how to append init with the style form
within a layout block.
:-)
--Scott Jones
[4/16] from: gscottjones:mchsi at: 29-Sep-2002 13:53
From: "G. Scott Jones"
> Some other clever chap may know how to append init
> with the style form within a layout block.
Oh (in answer to self but not implying self to necessarily be clever ;-):
draw-layout: [
style draw-button box 24x24 with [
effect: [
draw [pen black fill-pen x-color circle 12x12 10]
]
user-data: 'white
append init [
replace effect/2 'x-color user-data]
]
h2 "Draw buttons"
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
[5/16] from: rotenca:telvia:it at: 29-Sep-2002 22:32
Hi pat,
> 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]]
[...]
> Unfortunately face/user-data is unknown in this block.
> Is there a way to access the face object here? That is my question !
Try:
view layout [
style draw-button box 24x24 with [
effect: [draw [pen black fill-pen user-data circle 12x12 10]]
]
draw-button user-data red
draw-button user-data green
]
So you magically bind the effect block words to the face object words.
---
Ciao
Romano
[6/16] from: anton:lexicon at: 30-Sep-2002 9:19
Here's another way:
view layout [
style button button
effect [draw [pen black fill-pen 0.0.0 circle 12x12 10]]
with [
append init [
effect/2/4: color
color: 120.120.150
]
]
button blue "blue"
button green "green"
]
It takes the fill-color from face/color, which is handier to write
at the end than:
with [user-data: blue]
but, as you can see, the button color behind the circle is
always going to be 120.120.150
Or perhaps a better way is to make your own little dialect,
using the words facet:
view layout [
style button button
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
])
]
]
button blue fill red
button green fill black
]
(Mmm, on REBOL/View 1.2.1.3.1 21-Jun-2001, the second button's
circle looks more like a square to me... a bug in draw? All is ok
in the newer betas.)
Anton.
[7/16] from: rebol665:ifrance at: 30-Sep-2002 8:42
Hi Romano,
Great. This is the kind of guru trick I was hoping for. Where did you learn
stuff like that ?
May be somebody in the List can explain the "with" real meaning, when to use
it, etc ?
Patrick
[8/16] from: rebol665:ifrance at: 30-Sep-2002 8:47
Hi Anton,
I like the dialect thing. I was not aware it was possible to do that. It
opens new way for me.
Thanks.
Patrick
[9/16] 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
[10/16] from: brett:codeconscious at: 1-Oct-2002 8:43
----- Original Message -----
From: "pat665" <[rebol665--ifrance--com]>
To: <[rebol-list--rebol--com]>
Sent: Tuesday, October 01, 2002 7:52 AM
Subject: [REBOL] Re: draw has no access to the current face
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
________________________________________________________________
Etudiant: Wanadoo t'offre le Pack eXtense Haut Débit soit 150,92 euros
d'économies !
[11/16] from: brett:codeconscious at: 1-Oct-2002 9:19
regarding my last post on this thread - Oops wrong button....
Looking at this code:
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 effect is now a set-word! ?
All REBOL/View faces are objects. VID and LAYOUT are used to create this
object but using a simpler more powerful way to express how to create them.
So LAYOUT [ button ] will create an object for the button (it will also
create another for the window but lets ignore that for the moment). When
you use LAYOUT [button red] an object is created but this time with a colour
of Red. The VID language and LAYOUT translate the "red" into an action of
setting the face's colour facet to red.
WITH is part of the VID language that allows you to specify the facets using
a normal REBOL object specification. So the object that is created has this
specification applied to it.
For example, instead of LAYOUT [button red] you could write LAYOUT [ button
with [color: red] ]
As you can see [button red] is easier, but the advantage of WITH is that you
can create entirely new facets using it.
For example,
>> LAYOUT [btn: button with [my-special-facet: "Brett"]]
>> btn/my-special-facet
== "Brett"
Vid styles are objects too. When you use LAYOUT [style draw-button box
24x24]
You are creating another style object, one which is based on the box style.
When Romano used WITH in creating a style he was using a normal REBOL object
specification to change the facets (object fields) of the style. This is why
EFFECT became a set-word.
> why is it no more needed in "user-data red"?
The style that was created now has this EFFECT. Every face based on that
style will have the same EFFECT by default.
The EFFECT block refers to USER-DATA which is a built-in facet of every VID
style.
USER-DATA is a VID keyword and built-in facet. For example
>> LAYOUT [btn: button user-data "Brett"]
>> btn/user-data
== "Brett"
As you can see just like setting the colour we can set USER-DATA just as
easily.
> 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".
...
> 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.
Pretty close. Yes WORDS is a facet, but it is used during LAYOUT *only* not
during the display of the face. It is a way that more keywords can be added
to VID so that your custom styles can have their own specific VID keywords.
So what Anton has done is to create a new keyword FILL that is valid for the
DRAW-BUTTON style. When LAYOUT processes this specification [draw-button
fill red ] it executes the WORDS of DRAW-BUTTON to process the FILL keyword.
> Its goal seems to return whatever is left to be
> processed to finish the face display.
Yes whatever is left needs to be given back so that LAYOUT can process other
attributes and facets after the FILL (and its data).
This is an advanced technique. But as you can see it is very powerful.
Using WITH to make custom facets and WORDS to add custom VID keywords you
can create altogether new VID styles that are very easy to specify.
I hope this helps.
Brett.
[12/16] from: rotenca:telvia:it at: 1-Oct-2002 1:23
Hi pat,
> Romano Paolo Tenca (BTW may I call you Romano for short? )
Yes!
> 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! ?
All the magic is relative to object and binding of words. When you define an
object starting from a previous object:
ob: make object! [a: 1]
make ob [a: 2]
you assign a new value (2) to the word 'a of the object: this can happen
because the word 'a in the block is bound to the word 'a in the object before
executing the block. The sequence of operations is:
1) duplicate object ob and its context
2) bind the block [a: 2] to the new context
3) evaluate the block [a: 2]
Now in 3) when you change the value of 'a in the block, you really change the
value of 'a in the object.
The point is that words are not variable, they have not a value, they are
alphanumeric pointers to context, which are "invisible" structure created by
make object! (not only).
The 'with word of Vid is a shortcut for something like this, only 'ob is the
style face and the block is the 'with block.
The 'effect word of Vid, instead, does not bind the block to the object
context, only assign the block to the effect field.
Effect [draw [pen user-data]] is like:
new-face: make face []
new-face/effect: [draw [pen user-data]]
instead:
with [effect: [draw [pen user-data]]] is like
new-face: make face [effect: [draw [pen user-data]]]
only in the latter case the block is bound to the face object before
executing.
---
Ciao
Romano
[13/16] from: brett:codeconscious at: 1-Oct-2002 22:30
Hi Patrick,
> May I dare to ask how you have learn all this stuff?
One day after learning lots about Core I decided I needed to learn View. I
read all the docs I could find, looked at emails postings to this list.
Looked at the source code of LAYOUT, etc, and made lots of guesses and spent
lots of time. But my goal was to keep searching until understood how it
worked. During much of this process I took some notes and wrote them as if
explaining to someone else. This little process gave me more ideas to test
as well. Eventually the puzzle came together. I'm glad I spent the time.
Like you said "the more closer you look at it the more you find interresting
stuff" I was constantly impressed. :^)
The notes are available on codeconscious.com On the website and the rebsite.
The rebsite is better because the examples are interactive. I don't claim it
is all absolutely correct - so use your judgement :^)
In REBOL/View:
"Goto" http://www.codeconscious.com/index.r
Then find the "Docs" folder.
Allen's rebolforces (http://www.rebolforces.com) site has some old View
documents written by RT which are a little dry but which have good details.
The RT website has "how to" documents which are very good.
The HELP in the latest View beta now shows object fields well, before this
beta I used DocKimbels "Extended Help" (HELP.R).
Regards,
Brett.
[14/16] from: rebol665:ifrance at: 1-Oct-2002 13:24
Thanks Romano,
I have had very exciting moment searching the VID source, experiencing at
the console, trying, failing, asking, being answered ...
Rebol is like some fractals, the more closer you look at it the more you
find interresting stuff, and it never stops.
And its not like God, or stars, or the number pi, it is a human creation !
Thank you Carl at REBOL !
Amazing !
Patrick
[15/16] from: rotenca:telvia:it at: 1-Oct-2002 14:58
Hi pat,
> I have had very exciting moment searching the VID source, experiencing at
> the console, trying, failing, asking, being answered ...
> Rebol is like some fractals, the more closer you look at it the more you
> find interresting stuff, and it never stops.
True.
About Doc-info, beyond all the doc you can find on Rebol site:
- All the Ladislav stuff on its site (but nothing on View).
- Allen's RebolForce site
- Brett's codeconscious site
For a more deep vision of View you should read
http://www.rebolforces.com/archive/view099users.html, it is obsolete (do not
trust every word) but it is also the best doc we have on View architecture.
For Vid you must absolutly read the source of Layout: print it and read
slowly, becouse Carl S. writes very condensed code. Then you can start to read
some complex style code.
To understand well Vid you should try to write some not trivial styles, but
only after the previous steps, else you can gain some results but not a true
understand of what is happening.
To explore objects/face use my anamonitor.r
To see a style code in the shell, use my dump-style.r
To see a complex face in the shell, use my dump-face.r
(They are all in the standard Rebol library)
---
Ciao
Romano
[16/16] from: rebol665:ifrance at: 1-Oct-2002 13:10
Hi List
Brett said
>>I hope this helps.
>>Brett.
Oh, yes. And I am pretty sure that this has been helpful and interresting
for many Rebolers. May I dare to ask how you have learn all this stuff?
Patrick
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted