#23726 - 2002-06-28 05:23 AM
Re: DOS Menu
|
punkie
Getting the hang of it
Registered: 2002-06-23
Posts: 67
|
Dean, I don't think I could thank you enough for taking your time to work on this. I'm going to give it a try and see how it works
He sure does deserve a 5 star! There's no doubt about that Thanks again Dean.
|
Top
|
|
|
|
#23728 - 2002-06-28 07:58 AM
Re: DOS Menu
|
punkie
Getting the hang of it
Registered: 2002-06-23
Posts: 67
|
I took a look at the script, did some modifications - added to following: menu position, width between colums, menu height and width. And it works perfectly now
I couldn't find any problems using the code either, but I guess I can post the whole thing on here. You did a wonderful job Dean.
code:
; KixMenu.kix ; version 1.0 for Kix2001 ; written by Dean E. Behrman ; created 06.25.2002
; modified by punkie june 28, 2002 ; $x,$y: Menu position. ; $colw: Width between colums. ; $width: Menu width. ; $height: Menu height.
function kixmenu ($_array,$_maxrows,optional $_title,$x,$y,$colw,$width,$height) ;$_array: Items to display in tabular format ;$_maxrows: Specify the maximum number of rows in the table ;$_title: Optional title for the window
cls if val(@kix) <> 4 ? "Requires Kixtart 2001" $kixmenu = -1 exit 1 endif
dim $_width,$_acount,$_cols,$_rows,$_currow,$_curcol,$_curitem,$_colitems[1],$_rowitems[1],$_x,$_key $_rc = setoption("HideCursor","ON") $_width = $colw $_currow = 0 $_curcol = 0 $_curitem = 0 if $_maxrows <= 0 $_maxrows = 24 endif
$_acount = ubound($_array) for $_x = 0 to $_acount $_item = $_array[$_x] if len($_item) > $_width $_width = len($_item) endif next
$_maxcols = 78 / ($_width + 1) if $_maxcols < 1 or $_acount > ($_maxcols * $_maxrows) $kixmenu = -1 goto end endif if $_acount / $_cols > $_maxrows $kixmenu = -1 goto end endif $_cols = ($_acount / $_maxrows) + 1 $_rows = ($_acount + 1) / $_cols gosub drawscreen gosub buildmenu gosub pickitem :end $rc = setoption("HideCursor","OFF") cls return
:drawscreen Color w+/b Box ($y,$x,$height,$width,"SINGLE") if $_title <> "" and $_title <> 0 at ($y,$x+1) $_title endif return
:buildmenu $_curitem = 0 redim $_colitems[$_cols], $_rowitems[$_rows] for $_curcol = 0 to $_cols for $_currow = 0 to $_rows - 1 if $_curitem <= $_acount at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] $_colitems[$_curcol] = $_currow $_rowitems[$_currow] = $_curcol endif $_curitem = $_curitem + 1
next next return
:pickitem $_currow = 0 $_curcol = 0 $_curitem = 0 gosub showcursor at (0,0) do get $_key if asc($_key) = 224 ; Extended Key get $_key if asc($_key) = 80 ; Down Arrow gosub hidecursor $_currow = $_currow + 1 $_curitem = $_curitem + 1 if $_currow > $_colitems[$_curcol] $_currow = 0 $_curitem = $_curitem - $_colitems[$_curcol] - 1 endif gosub showcursor endif if asc($_key) = 72 ; Up Arrow gosub hidecursor $_currow = $_currow - 1 $_curitem = $_curitem - 1 if $_currow < 0 $_currow = $_colitems[$_curcol] $_curitem = $_curitem + $_colitems[$_curcol] + 1 endif gosub showcursor endif if asc($_key) = 75 ; Left Arrow gosub hidecursor $_curcol = $_curcol - 1 if $_curcol < 0 $_curcol = $_rowitems[$_currow] $_curitem = $_curitem + $_rowitems[$_currow] * $_rows else $_curitem = $_curitem - $_colitems[$_curcol] - 1 endif gosub showcursor endif if asc($_key) = 77 ; Right Arrow gosub hidecursor $_prev = $_curcol $_curcol = $_curcol + 1 if $_curcol > $_rowitems[$_currow] $_curcol = 0 $_curitem = $_curitem - $_rowitems[$_currow] * $_rows else $_curitem = $_curitem + $_colitems[$_prev] + 1 endif gosub showcursor endif endif until asc($_key) = 13 or asc($_key) = 27 ; ENTER or ESC
if asc($_key) = 13 $kixmenu = $_curitem else $kixmenu = -2 endif return
:showcursor color b/w+ at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] color w/n at (0,0) return
:hidecursor color w+/b at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] color w/n at (0,0) return
endfunction
|
Top
|
|
|
|
#23729 - 2002-06-28 08:01 AM
Re: DOS Menu
|
punkie
Getting the hang of it
Registered: 2002-06-23
Posts: 67
|
I agree NTDOC, I didn't expect someone to do that, was basically just looking for some help to do it all. I got lucky.
|
Top
|
|
|
|
#23731 - 2002-06-28 03:59 PM
Re: DOS Menu
|
punkie
Getting the hang of it
Registered: 2002-06-23
Posts: 67
|
Glad you liked it Dean but I have noticed that if you move down the menu the box shrinks, does anyone know why this happens?
|
Top
|
|
|
|
#23732 - 2002-06-28 05:15 PM
Re: DOS Menu
|
Dean B.
Fresh Scripter
Registered: 2002-02-04
Posts: 46
Loc: Allegan, MI USA
|
punkie -
You need to make this change in the drawscreen subroutine:
Box ($y,$x,$y + $height,$x + $width,"SINGLE")
I think there is going to be problems with the parameters for $_maxrows and $height. Here is my proposed code modifications. Please note that the parameter order has changed.
code:
; KixMenu.kix ; version 1.0 for Kix2001 ; written by Dean E. Behrman ; created 06.25.2002
; modified by punkie june 28, 2002
; modified 06.28.2002 by Dean E. Behrman
function kixmenu ($_array,optional $_title,$x,$y,$colw,$width,$height) ; $_array: Items to display in tabular format ; $_title: Optional title for the window ; $x,$y: Menu position. ; $colw: Width between colums. ; $width: Menu width. ; $height: Menu height.
cls
dim $_width,$_acount,$_cols,$_rows,$_currow,$_curcol,$_curitem,$_colitems[1],$_rowitems[1],$_x,$_key $_rc = setoption("HideCursor","ON") $_width = $colw $_currow = 0 $_curcol = 0 $_curitem = 0 if $height <= 0 $height = 24 endif
$_acount = ubound($_array) for $_x = 0 to $_acount $_item = $_array[$_x] if len($_item) > $_width $_width = len($_item) endif next
$_maxcols = 78 / ($_width + 1) if $_maxcols < 1 or $_acount > ($_maxcols * $height) $kixmenu = -1 goto end endif if $_acount / $_cols > $height $kixmenu = -1 goto end endif $_cols = ($_acount / $height) + 1 $_rows = $height ; ($_acount + 1) / $_cols gosub drawscreen gosub buildmenu gosub pickitem :end $rc = setoption("HideCursor","OFF") cls return
:drawscreen Color w+/b Box ($y,$x,$y + $height + 1,$x + $width,"SINGLE") if $_title <> "" and $_title <> 0 at ($y,$x+1) $_title endif return
:buildmenu $_curitem = 0 redim $_colitems[$_cols], $_rowitems[$_rows] for $_curcol = 0 to $_cols for $_currow = 0 to $_rows - 1 if $_curitem <= $_acount at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] $_colitems[$_curcol] = $_currow $_rowitems[$_currow] = $_curcol endif $_curitem = $_curitem + 1 next next return
:pickitem $_currow = 0 $_curcol = 0 $_curitem = 0 gosub showcursor at (0,0) do get $_key if asc($_key) = 224 ; Extended Key get $_key if asc($_key) = 80 ; Down Arrow gosub hidecursor $_currow = $_currow + 1 $_curitem = $_curitem + 1 if $_currow > $_colitems[$_curcol] $_currow = 0 $_curitem = $_curitem - $_colitems[$_curcol] - 1 endif gosub showcursor endif if asc($_key) = 72 ; Up Arrow gosub hidecursor $_currow = $_currow - 1 $_curitem = $_curitem - 1 if $_currow < 0 $_currow = $_colitems[$_curcol] $_curitem = $_curitem + $_colitems[$_curcol] + 1 endif gosub showcursor endif if asc($_key) = 75 ; Left Arrow gosub hidecursor $_curcol = $_curcol - 1 if $_curcol < 0 $_curcol = $_rowitems[$_currow] $_curitem = $_curitem + $_rowitems[$_currow] * $_rows else $_curitem = $_curitem - $_colitems[$_curcol] - 1 endif gosub showcursor endif if asc($_key) = 77 ; Right Arrow gosub hidecursor $_prev = $_curcol $_curcol = $_curcol + 1 if $_curcol > $_rowitems[$_currow] $_curcol = 0 $_curitem = $_curitem - $_rowitems[$_currow] * $_rows else $_curitem = $_curitem + $_colitems[$_prev] + 1 endif gosub showcursor endif endif until asc($_key) = 13 or asc($_key) = 27 ; ENTER or ESC
if asc($_key) = 13 $kixmenu = $_curitem else $kixmenu = -2 endif return
:showcursor color b/w+ at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] color w/n at (0,0) return
:hidecursor color w+/b at ($_currow + $y+1,$_curcol * ($_width + 1) + $x+1) $_array[$_curitem] color w/n at (0,0) return
endfunction
_________________________
Dean
|
Top
|
|
|
|
#23733 - 2002-06-28 08:00 PM
Re: DOS Menu
|
punkie
Getting the hang of it
Registered: 2002-06-23
Posts: 67
|
The code for drawscreen fixed it but worked fine with using the $_maxrows and $height. I needed this part because I wanted a empty line between the options and the bottom of the box.
Probably should also note, in case anyone else want to use this one to remove the cls code at the begining of the script, if you want to display anything else than the menu itself.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 367 anonymous users online.
|
|
|