Hi Gerard,

Happily, everything you ask for is possible.
See bottom for a partial VID conversion of your
robot control script.

Here are some additional tips:

I noticed much similarity in the legend faces,
so you can save a lot of code by using an existing face object
as a prototype, eg:

        legend-2: make legend-1 [
                 text: "Start pos"
                ;font: make font [align: 'center] ; <-- this is the same
                offset: 30x70
                size: 80x20
                color: white
                ;edge: none ; <-- this is the same
        ]

So you don't have to begin with a simple face every time.

Now, converting to VID.
The way to MAKE from the standard face inside the layout dialect:

        view layout [

                face with [
                        init: []
                        size: 0x0
                ]

        ]

That is the bare minimum.
You must specify at least INIT and SIZE or there is an error.

You can use FACE because it is in this list:

        extract svv/vid-styles 2
        ;== [face blank-face IMAGE BACKDROP BACKTILE BOX

Now, back to the Legend.
You can use STYLE to create your own styles for use in your layout
specification block.

        layout [

                style legend box 80x20 gray "legend" font [size: 14 color: 
black shadow:
0x0] top

                legend-1: legend gold "Robot"
                legend-2: legend white "Start Pos"

        ]

Here I found a style similar to what I want - BOX.
(Is it really ? I had to modify the font etc.. Perhaps there is another
style that is better, perhaps TXT ?)
So the above has created a LEGEND style that is a BOX with all the modified
facets
in it by default.
Now I can use the LEGEND style several times, and I only have to specify the
changing parts.

Key handling.
You should look at the default window key handler first before
you make your own:

        view/new window: layout []
        unview
        probe window/feel

You can see how it looks for subfaces which can handle the key
event and delegates to them. I often just blow away the default
key handler for programs like this.

        view/new window: layout []
        window/feel: make window/feel [
                detect: func [face event][
                        if event/type = 'key [
                                ;...
                        ]
                        event ; allow event to continue
                ]
        ]
        do-events

You must allow some event types to continue, like the 'close
event, otherwise the window close gadget will not respond.
I often just let all the events continue, even if I am
handling some of them, like the key events here.

I never really bothered with INSERT-EVENT-FUNC.
I always got what I wanted using the above technique (which seems
to be less abstract), but insert-event-func might be good for
a situation with multiple windows, or maybe saving a few keystrokes.

I hope this was useful. (see script at bottom)
Regards,

Anton.

> Hi List,
>
> I just began a small robot simulation project to help new people
> to get acquainted with pseudo-code (robot instructions).
>
> I almost finally completed my display but without using VID.
> Enclosed below is my first version of the code needed to create this
> display so you can try it for yourself.
>
> At this point I asked myself some questions but found only vague
> answers. So if someone can help It could be useful to me in a near
> future.
>
> 1. Can we design something almost similar using VID and buttons
> instead of the "robot-cmds" pane with its
>      Forward, Back, Left, Right, Pick and Deliver faces  knowing
> that the first "game-space" panel face has a grid effect (is this
> possible to translate it under VID?) . The second difficulty I
> saw to using VID was the precise positioning (in fact everything can
> be repositioned but this first design seemed realistic enough for me).
>
> 2. How can the actual keyboard handler enclosed with the Robot
> face be transfered into a more central place than inside a specific
> face as now - it is inside the Robot face since this is what is
> kept moving - even if this seems logic at first. I read about the
> Insert-event-func and tried to mimic the Cyphre's way of doing
> things with his draw-tutor2.r but I can't use it satisfactorily for
> the moment. Is it the way to go ?
>
> From this point on I will work on the display of simple cmds
> given to the robot and recognition of them by the robot which will
> translate them into basic operations (Forward, Back, Left and
> Right plus Pick an object and Deliver it).
>
> Any help would be appreciated!
>
> Regards,
> Gerard

rebol [
        Title: "robot2"
        File: %robot2.r
        Date: 31-Oct-2005
        Version: 1.0.0
        Progress: 0.0
        Status: "working"
        Needs: [View]
        Author: "Anton Rolls"
        Language: "English"
        Purpose: {example conversion to VID of Gerard Cote's robot script}
        Usage: {}
        History: [
                1.0.0 [31-Oct-2005 {First version} "Anton"]
        ]
        ToDo: {
        -
        }
        Notes: {}
]

view/new window: center-face layout [
        size 700x450 + 2x2 ; 2x2 for right/bottom gridline

        backeffect [grid 50x50 0x0 2x2 0.200.0]
        backcolor water

        origin 0 space 0

        at 50x50
        robot: txt 50x50 black gold

        at 0x300
        panel 550x150 effect [merge luma -20] [ ; <-- command panel

                ; LEGEND
                at 20x10
                panel 100x130 effect [merge luma -20] font-size 14 "- Legend -" 
top [

                        pad 10x24 ; leave some room for the panel text

                        style legend box 80x20 font [color: black shadow: 0x0]
                        legend gold "Robot"
                        legend white "Start Pos"
                ]

                ; ROBOT COMMANDS
                at 240x10
                panel 250x130 effect [merge luma -20] font-size 14 "- Robot 
Commands -"
top [

                        pad 10x24
                        ;button "Up"  ;<-- you could use BTN BUTTON or just BOX
                ]

        ]

        at 550x25
        panel 150x400 effect [merge colorize 210.80.80] "Here will be the 
program"
[

                origin 20x20
                btn "Begin"
        ]

]

move: func [offset [pair!]][
        robot/offset: robot/offset + offset

        ; limit to play area
        robot/offset: min max robot/offset (0x0) (window/size - robot/size - 
2x2 -
100x100)

        show robot
]

; Here is a window global key handler, if you want to do it this way

window/feel: make window/feel [
        detect: func [face event /local key][
                if event/type = 'key [

                        ;if char? key: event/key [key: uppercase key]
                        key: event/key

                        case [
                                find [#"L" #"l" left ] key [move -50x0]
                                find [#"R" #"r" right] key [move 50x0]
                                find [#"U" #"u" up   ] key [move 0x-50]
                                find [#"D" #"d" down ] key [move 0x50]
                        ]
                ]

                event ; allow the event to continue
        ]
]

do-events

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to