1. window menu

hi, fellows, could you please help me getting a copy of a empty menu like
those
of the windows(pop-menu) or tell me how to program it, I'm new in Euphoria!
Thanks a lot.

new topic     » topic index » view message » categorize

2. Re: window menu

Alfredo asked:



> hi, fellows, could you please help me getting a copy of a empty menu
> like those of the windows(pop-menu) or tell me how to program it, I'm
> new in Euphoria!

Here is a *very* simple pop-up menu. There are lots of ways that it can be
embellished - it could draw a frame around the menu, calcuate the width of
the menu items, save and restore the area behind it, hightlight items as the
cursor moved over it, etc. etc...

Most of these features would be fairly simple to add. But since you said you
were new to Euphoria, I've kept the example basic. Even so, there are a two
things I should point out:

1. The mouse values have to be scaled (divided by 7.2) to correspond to text
positions. This number happened to work on my computer; your mileage may
vary.

2. The and_bits() function is used to see if the mouse button is being
pressed. This is because the mouse event flag can return multiple events.
For example, the mouse could be pressed AND moving at the same time. If you
don't use and_bits to test the flag, you'll miss the event.

Both of these are explained in the documentation supplied with Euphoria.

If you want a more sophisticated menu system, you could look into the menus
supplied with my TextGUI, on the Euphoria Archive page.

Hope this helps!

-- David Cuny

-- popUpMenu
-- *very* simple demo of pop up menu
-- david cuny
-- dcuny at lanset.com

include mouse.e
include graphics.e
include image.e

function popUpMenu( integer x, integer y, sequence list )
    integer items       -- count of items in menu
    integer wide        -- menu width
    integer pick        -- item picked
    object mouse        -- mouse event
    -- menu size
    items = length( list )
    wide = length( list[1] )
    -- color scheme
    text_color( BRIGHT_WHITE )
    bk_color( BLUE )
    -- put up a popup menu at requested position
    for i = 1 to items do
        position( x+i-1, y )
        puts( 1, list[i] )
    end for
    -- wait for a mouse click
    while 1 do
        -- watch the mouse
        mouse = get_mouse()
        if sequence( mouse ) then
            -- scale the position
            mouse[2..3] = floor( mouse[2..3]/7.2)

            -- pressed?
            if and_bits( mouse[1], LEFT_DOWN ) then
                -- leave loop
                exit
            end if

        end if
    end while
    -- did the mouse hit fall into the menu?
    if mouse[2] >= x            -- right of left edge
    and mouse[2] < x+wide       -- left of right edge
    and mouse[3] >= y           -- below top
    and mouse[3] < y+items then -- above bottom
        -- which item was it?
        pick = mouse[3] - y + 1
    else
        -- no item
        pick = 0
    end if
    return pick

end function

-- demonstrate the menu
integer pick
-- show the mouse
mouse_pointer(1)
-- run the menu
pick = popUpMenu( 10, 10, { "this      ",
                            "that      ",
                            "the other "} )
-- hide the mouse
mouse_pointer(0)
position( 1, 1)
printf( 1, "You picked %d", {pick} )

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu