Re: What are you people doing with Euphoria?
- Posted by Daniel Berstein Zimmermann <dberst at CMETNET.CMET.NET> Oct 14, 1996
- 2323 views
--------------4B5763E4E3A Dear Michael: I've done a little improvement to the "menu engine" i sent you yesterday, also is attached a small program to test the engine. Bye... --------------4B5763E4E3A Content-Disposition: inline; filename="menutest.ex" ---------------- -- Menutest.ex ---------------- -- by Daniel Berstein Z. -- e-mail: dberst at cmet.net ---------------- -- This file is intended to test my menu engine MENU_ENG.E, and will -- display a scrollable menu with the contents of your root directory. -- Play with this file, and use it as you want. -- The file MENU_ENG.E is required for this stuff to work. ----------------- include menu_eng.e clear_screen() sequence test, parameters integer selection parameters = repeat(0, 7) parameters[1] = 3 -- Starting row coord. parameters[2] = 10 -- Starting column coord. parameters[3] = 20 -- Maximum column length parameters[4] = 15 -- Column width parameters[5] = 3 -- Number of visible columns parameters[6] = 1 -- Complete lightbar style parameters[7] = 1 -- Activate scrollbar display test = dir("c:\\") for loop = 1 to length(test) do test[loop] = test[loop][D_NAME] end for selection = menu(test, parameters,{WHITE,BLUE,BLUE,WHITE}) position(24,1) if selection = -1 then puts(1, "Selection has been aborted") else puts(1, test[selection] & " has been selected") end if --------------4B5763E4E3A Content-Disposition: inline; filename="menu_eng.e" ------------------------------------------------------------------------------ -- MENU ENGINE -- ------------------------------------------------------------------------------ --Author: Daniel Berstein Zimmermann --Date: 13 of Octubre 1996, Santiago de Chile --E-mail: dberst at cmet.net ---------------- --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) -- options[7] = scroll-bar (0=no, 1=yes) -- "colors" --> sequence with menu colors: -- colors[1] = normal foreground -- colors[2] = normal background -- colors[3] = highlighted foreground -- colors[4] = highlighted backgorund ---------------- ---------------- --Returns: -- Position within "items" of the selected option. -- Returns -1 if the selection is canceled. ---------------- --Notes: -- a) The scrollbar may not work fine if the column length (options[3]) is -- less than 3. ---------------- --Future release: -- Mouse support ---------------- 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() cursor(NO_CURSOR) -- 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 -- Display scrollbar if options[7] then text_color(colors[1]) bk_color(colors[2]) position((options[1] + options[3]), options[2]) puts(1, 17 & repeat(176, (options[4] * options[5]) - 2) & 16) 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 -- Update scrollbar (display cursor) if options[7] then aux2= floor(( options[5] * options[4]) / ( number_of_columns - 1)) * ( current_column - 1) + 1 if aux2 > (options[5] * options[4]) - 2 then aux2 = (options[5] * options[4]) - 2 end if text_color(colors[1]) bk_color(colors[2]) position((options[1] + options[3]), (options[2] + aux2)) puts(1, 178) 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]))) -- Update scrollbar (hide cursor) if options[7] then aux2= floor(( options[5] * options[4]) / ( number_of_columns - 1)) * ( current_column - 1) + 1 if aux2 > (options[5] * options[4]) - 2 then aux2 = (options[5] * options[4]) - 2 end if position((options[1] + options[3]), (options[2] + aux2)) puts(1, 176) end if -- 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 --------------4B5763E4E3A--