Re: What are you people doing with Euphoria?

new topic     » goto parent     » topic index » view thread      » older message » newer message

--------------57C53C247AE3

Michael Packard wrote:

> Hey,  we need more Euphoria web pages.  Seems like there are only
> 6 or 7 pages in the whole world.  I know there are a LOT of people out
> there using euphoria. I saw at least 70 names on this list last time I
> checked.  SHOW US WHAT YOU'RE DOING WITH IT!

Hi everyone,
I'm quite new to euphoria, and not yet got my webpage... but here is some code o
f mine, it's just a generic
menu selector (kind of Clipper's "menu to" but with multiple columns and horizon
tal scrolling).
Hope you like it... and help improve it.

--------------57C53C247AE3
Content-Disposition: inline; filename="menu_eng.e"

----------------
--FUNCTION MENU--
----------------
--Sintax:
-- menu( sequence "items", sequence "options", sequence "colors" )
----------------
--Parameters:
-- "items"   --> sequence containing the menu items
-- "options" --> sequence with the following menu specifications:
--              options[1] = upper row coordinate
--              options[2] = left column coordinate
--              options[3] = maximum column length
--              options[4] = columns width
--              options[5] = number of visible columns
--              options[6] = light-bar style (0=minimum, 1=complete)
-- "colors" --> sequence with menu colors:
--              colors[1] = normal foreground
--              colors[2] = normal background
--              colors[3] = highlighted foreground
--              colors[4] = highlighted backgorund
----------------

include graphics.e
include file.e
include get.e

global function menu(sequence items, sequence options, sequence colors)

    -- Declare variables
    integer number_of_columns, first_column, last_column
    integer current_row, current_column, reimprimir
    sequence video
    object aux1, aux2

    video = video_config()

    -- Check no item is wider than options[4]
    for loop = 1 to length(items) do
        if  options[4] < length(items[loop])then
            options[4] = length(items[loop])
        end if
    end for

    -- Check if number of visible columns is OK
    if options[2] + (options[5] * options[4]) > video[VC_COLUMNS] then
        options[5] = floor((video[VC_COLUMNS] - options[2]) / options[4])
    end if

    -- Check if column length if OK
    if options[1] + options[3] > video[VC_LINES] then
        options[3] = video[VC_LINES] - options[1]
    end if

    -- Define variables
    if integer (length(items) / options[3]) then
        number_of_columns = length(items) / options[3]
    else
        number_of_columns = floor(length(items) / options[3]) + 1
    end if

    first_column = 1
    last_column = options[5]

    if last_column > number_of_columns then
        last_column = number_of_columns
        options[5] = number_of_columns
    end if

    reimprimir = 1
    current_column = first_column
    current_row = 1

    -- Main loop
    while 1 do

        if first_column < 1 then
            first_column = 1
            reimprimir = 0
        end if

        last_column = first_column + options[5] - 1

        if last_column > number_of_columns then
            last_column = number_of_columns
            first_column = last_column - options[5] + 1
            reimprimir = 0
        end if

        if current_column < first_column then
            current_column = first_column
        elsif current_column > last_column then
            current_column = last_column
        end if

        if (options[3] * (current_column - 1) + current_row) >
          length(items) then
            current_row = length(items) -
              (options[3] * (current_column - 1))
        end if

        -- Display visible columns
        if reimprimir = 1 then
            reimprimir = 0
            aux1 = 0
            aux2 = 0
            text_color(colors[1])
            bk_color(colors[2])
            for loop = (options[3] * (first_column - 1) + 1) to
              (options[3] * (last_column - 1) + options[3]) do
                position((options[1] + aux1), (options[2] +
                  (aux2 * options[4])))
                if loop > length(items) then
                    puts(1, repeat(32, options[4]))
                else
                    puts(1, items[loop]
                      & repeat(32, options[4] - length(items[loop])))
                end if
                aux1 = aux1 + 1
                if aux1 = options[3] then
                    aux1 = 0
                    aux2 = aux2 + 1
                end if
            end for
        end if

        -- Display light-bar
        text_color(colors[3])
        bk_color(colors[4])
        position((options[1] + (current_row - 1)),
          (options[2] + ((current_column - first_column)
            * options[4])))
        if options[6] then
            puts(1, items[options[3] * (current_column - 1) + current_row] &
              repeat(32, options[4] - length(items[options[3] *
              (current_column - 1) + current_row])))
        else
            puts(1, items[options[3] * (current_column - 1) + current_row])
        end if

        -- Wait for a key
        aux1 = wait_key()

        -- Hide ligth-bar
        text_color(colors[1])
        bk_color(colors[2])
        position((options[1] + (current_row - 1)),
          (options[2] + ((current_column - first_column)
            * options[4])))
        puts(1, items[options[3] * (current_column - 1) + current_row] &
          repeat(32, options[4] - length(items[options[3] *
          (current_column - 1) + current_row])))


        -- Check which key was pressed
        if aux1 = 13 then
            -- ENTER --> returns selected item's position
            return (options[3] * (current_column - 1) + current_row)
        elsif aux1 = 27 then
            -- ESC --> returns -1, selection canceled
            return -1
        elsif aux1 = 328 then
            -- Up arrow
            if current_row - 1 >= 1 then
                current_row = current_row - 1
            elsif current_row - 1 < 1 then
                if current_column - 1 < first_column then
                    first_column = first_column - 1
                    reimprimir = 1
                end if
                if current_column > 1 then
                    current_row = options[3]
                    current_column = current_column - 1
                end if
            end if
        elsif aux1 = 336 then
            -- Down arrow
            if current_row + 1 <= options[3] then
                current_row = current_row + 1
            elsif current_row + 1 > options[3] then
                if current_column + 1 > last_column then
                    first_column = first_column + 1
                    reimprimir = 1
                end if
                if current_column < number_of_columns then
                    current_row = 1
                    current_column = current_column + 1
                end if
            end if
        elsif aux1 = 331 then
            -- Left arrow
            if current_column - 1 >= first_column then
                current_column = current_column - 1
            elsif current_column - 1 < first_column then
                    current_column = current_column - 1
                    first_column = first_column - 1
                    reimprimir = 1
            end if
        elsif aux1 = 333 then
            -- Right arrow
            if current_column + 1 <= last_column then
                current_column = current_column + 1
            elsif current_column + 1 > last_column then
                current_column = current_column + 1
                first_column = first_column + 1
                reimprimir = 1
            end if
        end if

    end while

end function

--------------57C53C247AE3--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu