Here's a very MK1 "character mode" listview on a PBCC GRAPHIC WINDOW.
The idea is that the ListBox function is library code and the developer passes to it, amongst other parameters, a pointer to a function which returns one line for the listbox, or &HFF if the data source is exhausted. In the example, this function just returns the string of its argument, which is the line number requested.
The listbox responds only to up and down keys and does not actually do anything.
One little problem, it's very slow, at least on my memory-challenged PC. Any suggestions on how to make it faster would be welcome.
The idea is that the ListBox function is library code and the developer passes to it, amongst other parameters, a pointer to a function which returns one line for the listbox, or &HFF if the data source is exhausted. In the example, this function just returns the string of its argument, which is the line number requested.
The listbox responds only to up and down keys and does not actually do anything.
One little problem, it's very slow, at least on my memory-challenged PC. Any suggestions on how to make it faster would be welcome.
Code:
' PBCC V5 try-out program by Chris Holbrook Oct 2008 ' Listbox POC for GRAPHIC WINDOW ' #INCLUDE "WIN32API.INC" '---------------------------------------------------------- FUNCTION ConsoleHandler(BYVAL dwEvent AS DWORD) AS LONG END END FUNCTION '---------------------------------------------------------- ' param: line number ' return string function of the line number, &HFF at 200+th record. FUNCTION getlineproc(i AS LONG) AS STRING IF i <= 200 THEN FUNCTION = "record #" + STR$(i) ELSE FUNCTION = CHR$(255) END IF END FUNCTION '---------------------------------------------------------- ' first dword of result is result, second is click location ' params : location (X, Y), size(W, H), title, "get line" process pointer ' ESC to end FUNCTION listbox (X AS LONG, Y AS LONG, W AS LONG, H AS LONG, stitles AS STRING, glineproc AS DWORD ) AS QUAD LOCAL i, nlines, pxcwide, pxchigh, top, hilit, lastline AS LONG LOCAL r AS rect LOCAL s, skey, stempbits AS STRING LOCAL hbottombmp AS DWORD GRAPHIC WIDTH 1 GRAPHIC CHR SIZE TO pxcwide, pxchigh setrect r, x + pxcwide, y + pxchigh, x + W + pxcwide*2, y + H + pxchigh 'draw shadow box GRAPHIC BOX (r.nleft, r.ntop) - (r.nright, r.nbottom), 0, 0, 0 setrect ( r, x, y, x + w, y + h) GRAPHIC FONT "Courier" ' draw box around control GRAPHIC BOX (r.nleft, r.ntop) - (r.nright, r.nbottom), 0, %BLUE, %BLUE, 0 '&Hd0d0ff GRAPHIC COLOR %WHITE, %BLUE GRAPHIC SET POS (X + 2, y + 2): GRAPHIC PRINT stitles GRAPHIC COLOR %BLACK, %WHITE ' draw line under title GRAPHIC LINE (X, Y + pxchigh + 2) - (X + W,Y + pxchigh + 2) GRAPHIC BOX (X, Y + pxchigh + 2) - (r.nright, r.nbottom), 0, %BLUE, %WHITE, 0 nlines = ((h - pxchigh - 5) \ pxchigh) -1 top = 1 lastline = 10^6 hilit = 1' the highlighted row FOR i = 1 TO top + nlines GOSUB drawcontents NEXT WHILE skey <> $ESC SLEEP 1 GRAPHIC INKEY$ TO skey IF LEN(skey) = 2 THEN SELECT CASE MID$(skey,2,1) CASE CHR$(&H48)' up IF hilit > 1 THEN DECR hilit IF hilit < top THEN DECR top IF top < 1 THEN top = 1 CASE CHR$(&H50)'down IF hilit < lastline THEN INCR hilit END IF IF hilit > top + nlines THEN INCR top END SELECT GRAPHIC BOX (X, Y + pxchigh + 2) - (r.nright, r.nbottom), 0, %BLUE, %WHITE, 0 FOR i = top TO top + nlines GOSUB drawcontents NEXT i GRAPHIC LINE (r.nleft, r.nbottom - 1) - (r.nright, r.nbottom - 1) GRAPHIC BOX (r.nleft + pxcwide, r.nbottom ) - (r.nright + pxcwide*2, r.nbottom + pxchigh), 0,0,0,0 END IF WEND EXIT FUNCTION drawcontents: CALL DWORD glineproc USING getlineproc(i) TO s IF LEFT$(s,1) = CHR$(255) THEN lastline = i - 1 IF hilit > lastline THEN DECR hilit RETURN END IF GRAPHIC SET POS (X + 4, Y + pxchigh + 4 + ((i - top) * pxchigh)) IF i = hilit THEN GRAPHIC COLOR 0, %CYAN ELSE GRAPHIC COLOR 0, %WHITE END IF GRAPHIC PRINT s; RETURN END FUNCTION '------------------------------------------------------- FUNCTION PBMAIN () AS LONG LOCAL bigx, bigy, thisW, thisH AS LONG LOCAL r AS RECT LOCAL dw AS DWORD LOCAL hGW AS DWORD SetConsoleCtrlHandler CODEPTR(ConsoleHandler), 1 DESKTOP GET SIZE TO bigx, bigy thisW = 400: thisH = 300 GRAPHIC WINDOW "Listbox", (bigx - thisw)/2, (bigY - thisH)/2, ThisW, ThisH TO hGW GRAPHIC ATTACH hGW, 0 setrect r, 0, 0, 400, 300 GRAPHIC BOX (r.nleft, r.ntop) - (r.nright, r.nbottom), 0, -1, %BLUE, 4 Listbox(100, 20, 200, 100, "my first PBCC listbox", CODEPTR(getlineproc)) SetConsoleCtrlHandler CODEPTR(ConsoleHandler), 0 END FUNCTION
Comment