Author Topic: Scrollable Text Windows for Graphics Screens  (Read 4877 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Scrollable Text Windows for Graphics Screens
« on: May 16, 2019, 02:55:28 pm »
Here is first test demo that I have working as Modal Windows in a graphics screen running a graphics program.
Ctrl + C to view a line numbered array
Ctrl + F to view the contents of the file if you name this code "Array window.bas"

While these windows are showing you can press h for a message box for using scrollWindow SUB demo.

Two ways to exit (at least): press esc or click X in red box in current modal window. This was the tricky part, how to press esc and not to fall through all windows to end program. Just a _KEYCLEAR was not enough.

Code: QB64: [Select]
  1. _TITLE "Array Window: Ctrl + C for sample array, Ctrl + F for this file, then <h>elp for message box, <esc> for exits"
  2. ' B+ started 2019-05-15  as test demo for SUB scrollWindow
  3.  
  4. '                          save this file as "Array window.bas"
  5. '              so you can load it and view it in a scrollable window with Ctrl + F
  6.  
  7.  
  8. 'Modified from "getArrayItemClicked v4 mbox"
  9. ' Main testing and demo of the FUNCTION  getArrayItemNumber%
  10. 'started 2018-08-31 B+  developing a general purpose display and select app of a string array
  11.  
  12. '2018-09-04 post v2 bak 9-3_9PM
  13. '2018-09-07 getArrayItem v4 mbox - time to test mbox with help window
  14. ' spotted nasty text distortion, Fellippe point me to place to fix.
  15.  
  16. ' press h while an Array Window is up and check out my mBox routine!
  17.  
  18. '2019-05-15 modified code to simulate scrollable window
  19. ' added  "Beating Cardiod" 'B+ 2019-02-16 for some background program to run
  20. ' 2019-05-16 man what a B trying to clear keypresses and clicks!!!
  21. ' mainly the escape key to exit one window without
  22. ' falling through and exiting the next and the next...
  23.  
  24. '2019-05-17 get rid of _KEYDOWN(27) for exit of sub's
  25.  
  26. CONST nArr = 92 'ubound of array = actual amount of items if LBound = 1
  27. CONST LB = 10 'try different lower bounds not just 0, 1
  28. CONST WW = 1200 'Window Width
  29. CONST WH = 600 'Window Height
  30.  
  31. 'center of screen for background Cardiod graphics
  32. CONST CX = WW / 2
  33. CONST CY = WH / 2 - 50
  34.  
  35. SCREEN _NEWIMAGE(WW, WH, 32)
  36. _SCREENMOVE 100, 60
  37.  
  38. 'test string array, use indexes in lines for alignment to code for function
  39. REDIM arr(LB TO nArr) AS STRING
  40. DIM i AS INTEGER, loopcount AS INTEGER, magnify AS SINGLE, a AS SINGLE, x AS SINGLE, y AS SINGLE, lastx AS SINGLE, lasty AS SINGLE
  41. DIM kh AS LONG, locRow AS INTEGER, locCol AS INTEGER, boxWidth AS INTEGER, boxHeight AS INTEGER, lnCnt AS INTEGER
  42. FOR i = LB TO nArr
  43.     arr(i) = "This is arr item:" + STR$(i)
  44.  
  45.     'some background graphics program running...
  46.     CLS
  47.     loopcount = (loopcount + 1) MOD 2
  48.     IF loopcount THEN magnify = 10 ELSE magnify = RND * 10 + 12
  49.     FOR a = -_PI TO _PI STEP _PI(1 / 360)
  50.         x = CX + magnify * xCard(a)
  51.         y = CY - magnify * yCard(a)
  52.         IF a <> -_PI THEN
  53.             LINE (x, y)-(lastx, lasty), _RGB(140, 0, 0)
  54.         END IF
  55.         lastx = x: lasty = y
  56.     NEXT
  57.     PAINT (CX, CY), _RGB(180, 0, 0), _RGB(140, 0, 0)
  58.     _DISPLAY
  59.     IF loopcount THEN _DELAY 40 / 60 ELSE _DELAY (30 + RND * 15) / 65
  60.  
  61.     'access to array windows which will act modally
  62.     kh = _KEYHIT
  63.     IF kh = 99 THEN 'ctrl + C
  64.         locRow = 5: locCol = 150 - 25 - 5: boxWidth = 25: boxHeight = 17 '< displays 15 lines of array items
  65.         ''boxHeight is actual screen space in character units, the display uses 2 of the lines for control bars.
  66.         ''boxWidth will include item numbers displayed to left of array string item
  67.         scrollWindow locRow, locCol, boxWidth, boxHeight, arr()
  68.     ELSEIF kh = 102 THEN 'ctrl + F
  69.         REDIM fArr(500) AS STRING
  70.         lnCnt = fLines("Array window.bas", fArr()) '<<<<<<<<<<<<<<<<<<< or whatever name you gave this file AND SAVED!
  71.         LOCATE 25, 1: PRINT "Array window.bas code:"
  72.         scrollWindow 26, 1, 150, 12, fArr()
  73.     ELSEIF kh = 27 THEN 'done
  74.         EXIT WHILE
  75.     END IF
  76.  
  77. 'attempting to create a scrollable view port for displaying an array
  78. ' locateRow and locateCol are the same as if using LOCATE row, col  and will get same errors as LOCATE
  79. ' boxWidth is in characters 8 pixels wide,
  80. ' boxheight uses 2 rows (16 pixels per) to draw Page Up and Page Down Bars, so add 2 more to height than rows of text desired
  81. ' arr() is the array we desire to display and scroll
  82.  
  83. 'this sub uses a Help sub which in turn uses mBox
  84. SUB scrollWindow (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  85.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  86.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  87.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  88.     DIM wate$
  89.     IF boxHeight < 3 THEN INPUT "boxHeight is too small for call on scrollWindow.", wate$: EXIT SUB
  90.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER
  91.     DIM mb AS INTEGER, mx AS INTEGER, my AS INTEGER
  92.     DIM lba AS LONG, uba AS LONG, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG, clrStr AS STRING
  93.     DIM kh AS LONG, lastmx AS INTEGER, lastmy AS INTEGER, row AS INTEGER, index AS LONG
  94.     maxWidth = boxWidth '       number of characters in box
  95.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  96.     lba = LBOUND(arr)
  97.     uba = UBOUND(arr)
  98.     page = 0
  99.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  100.     clrStr = SPACE$(maxWidth) ' clearing a display line
  101.     fg = _DEFAULTCOLOR
  102.     bg = _BACKGROUNDCOLOR
  103.  
  104.     GOSUB update '              show the beginning of the array items for selection
  105.  
  106.     WHILE 1 'until get a selection or demand exit
  107.  
  108.         'handle the key stuff
  109.         kh = _KEYHIT
  110.         IF kh THEN
  111.             IF kh > 0 AND kh < 255 THEN
  112.                 IF CHR$(kh) = "h" THEN HELP
  113.                 IF kh = 27 THEN EXIT WHILE
  114.             ELSE
  115.                 SELECT CASE kh 'choosing sections of array to display and highlighted item
  116.                     CASE 20736 'pg dn
  117.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  118.                     CASE 18688 'pg up
  119.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  120.                     CASE 18432 'up
  121.                         IF hlite - 1 < 0 THEN
  122.                             IF page > 0 THEN
  123.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  124.                             END IF
  125.                         ELSE
  126.                             hlite = hlite - 1: GOSUB update
  127.                         END IF
  128.                     CASE 20480 'down
  129.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  130.                             IF hlite + 1 > maxHeight - 1 THEN
  131.                                 page = page + 1: hlite = 0: GOSUB update
  132.                             ELSE
  133.                                 hlite = hlite + 1: GOSUB update
  134.                             END IF
  135.                         END IF
  136.                     CASE 18176 'home
  137.                         page = 0: hlite = 0: GOSUB update
  138.                     CASE 20224 ' end
  139.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  140.                 END SELECT
  141.             END IF
  142.         END IF
  143.  
  144.         'handle the mouse stuff
  145.         WHILE _MOUSEINPUT
  146.             IF _MOUSEWHEEL = -1 THEN 'up?
  147.                 IF hlite - 1 < 0 THEN
  148.                     IF page > 0 THEN
  149.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  150.                     END IF
  151.                 ELSE
  152.                     hlite = hlite - 1: GOSUB update
  153.                 END IF
  154.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  155.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  156.                     IF hlite + 1 > maxHeight - 1 THEN
  157.                         page = page + 1: hlite = 0: GOSUB update
  158.                     ELSE
  159.                         hlite = hlite + 1: GOSUB update
  160.                     END IF
  161.                 END IF
  162.             END IF
  163.         WEND
  164.         mb = _MOUSEBUTTON(1)
  165.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - (locateRow + 1) * 16) / 16) + 2
  166.         IF mb THEN 'click contols or select array item
  167.             '_delay .2 'this sucks but won't clear mouse click
  168.             WHILE mb 'OK!
  169.                 IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  170.             WEND
  171.  
  172.             IF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  173.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  174.                     EXIT WHILE 'escape plan for mouse click top right corner of display box
  175.                 ELSE 'PgUp bar clicked
  176.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  177.                 END IF
  178.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  179.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  180.             END IF
  181.         ELSE '   mouse over highlighting, only if mouse has moved!
  182.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  183.                 IF mx <> lastmx OR my <> lastmy THEN
  184.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  185.                         hlite = my - 1
  186.                         lastmx = mx: lastmy = my
  187.                         GOSUB update
  188.                     END IF
  189.                 END IF
  190.             END IF
  191.         END IF
  192.         _LIMIT 200
  193.     WEND
  194.  
  195.     'restore previous color settings
  196.     COLOR fg, bg
  197.     'attempt to clear all key presses before exit
  198.     _KEYCLEAR
  199.     EXIT SUB
  200.  
  201.     'display of array sections and controls on screen
  202.     update:
  203.  
  204.     'fix hlite if it has dropped below last array item
  205.     WHILE hlite + page * maxHeight + lba > uba
  206.         hlite = hlite - 1
  207.     WEND
  208.  
  209.     'main display of array items at page * maxHeight (lines high)
  210.     FOR row = 0 TO maxHeight - 1
  211.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  212.         LOCATE locateRow + row + 1, locateColumn: PRINT clrStr$;
  213.         index = row + page * maxHeight + lba
  214.         IF index >= lba AND index <= uba THEN
  215.             LOCATE locateRow + row + 1, locateColumn
  216.             PRINT LEFT$(arr(index), maxWidth);
  217.         END IF
  218.     NEXT
  219.  
  220.     'make page up and down bars to click, print PgUp / PgDn if available
  221.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  222.     LOCATE locateRow, locateColumn: PRINT SPACE$(maxWidth);
  223.     IF page <> 0 THEN LOCATE locateRow, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth);
  224.     LOCATE locateRow + maxHeight + 1, locateColumn: PRINT SPACE$(maxWidth);
  225.     IF page <> INT(uba / maxHeight) THEN
  226.         LOCATE locateRow + maxHeight + 1, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth);
  227.     END IF
  228.     'make exit sign for mouse click
  229.     COLOR _RGB32(255, 255, 255), _RGB32(200, 50, 0)
  230.     LOCATE locateRow, locateColumn + maxWidth - 3
  231.     PRINT " X ";
  232.  
  233.     _DISPLAY
  234.     RETURN
  235.  
  236.  
  237. SUB HELP
  238.     DIM n AS STRING, t AS STRING, m AS STRING
  239.     n$ = CHR$(10)
  240.     t$ = "*** Mouse and Key Instructions ***"
  241.     m$ = "Mouse, mouse wheel, and arrow keys should work as expected for navigation."
  242.     m$ = m$ + " Home starts you at lowest array item, End highlights the highest item."
  243.     m$ = m$ + " Use PgUp and PgDn keys or Click Green bars to flip through pages of array items."
  244.     m$ = m$ + " Escape to exit."
  245.     mBox m$, t$
  246.  
  247.  
  248. 'title$ limit is 57 chars, all lines are 58 chars max
  249. ' version bak 2018-09-07_10P
  250. SUB mBox (m AS STRING, title AS STRING)
  251.  
  252.     'first screen dimensions items to restore at exit
  253.     DIM curScrn AS LONG, backScrn AS LONG, mbx AS LONG 'some handles
  254.     DIM ti AS INTEGER, limit AS INTEGER 'ti = text index for t$(), limit is number of chars per line
  255.     DIM i AS INTEGER, j AS INTEGER, ff AS _BIT, add AS _BYTE 'index, flag and
  256.     DIM bxH AS INTEGER, bxW AS INTEGER 'first as cells then as pixels
  257.     DIM mb AS INTEGER, mx AS INTEGER, my AS INTEGER, mi AS INTEGER, grabx AS INTEGER, graby AS INTEGER
  258.     DIM tlx AS INTEGER, tly AS INTEGER 'top left corner of message box
  259.     DIM lastx AS INTEGER, lasty AS INTEGER, t AS STRING, b AS STRING, c AS STRING, tail AS STRING
  260.     DIM d AS STRING, r AS SINGLE, kh AS LONG
  261.  
  262.     sw = _WIDTH
  263.     sh = _HEIGHT
  264.     fg = _DEFAULTCOLOR
  265.     bg = _BACKGROUNDCOLOR
  266.     'screen snapshot
  267.     curScrn = _DEST
  268.     backScrn = _NEWIMAGE(sw, sh, 32)
  269.     _PUTIMAGE , curScrn, backScrn
  270.  
  271.     'setup t() to store strings with ti as index, linit 58 chars per line max, b is for build
  272.     REDIM t(0) AS STRING: ti = 0: limit = 58: b = ""
  273.     FOR i = 1 TO LEN(m)
  274.         c = MID$(m, i, 1)
  275.         'are there any new line signals, CR, LF or both? take CRLF or LFCR as one break but dbl LF or CR means blank line
  276.         SELECT CASE c
  277.             CASE CHR$(13) 'load line
  278.                 IF MID$(m, i + 1, 1) = CHR$(10) THEN i = i + 1
  279.                 t(ti) = b: b = "": ti = ti + 1: REDIM _PRESERVE t(ti) AS STRING
  280.             CASE CHR$(10)
  281.                 IF MID$(m, i + 1, 1) = CHR$(13) THEN i = i + 1
  282.                 t(ti) = b: b = "": ti = ti + 1: REDIM _PRESERVE t(ti)
  283.             CASE ELSE
  284.                 IF c = CHR$(9) THEN c = SPACE$(4): add = 4 ELSE add = 1
  285.                 IF LEN(b) + add > limit THEN
  286.                     tail = "": ff = 0
  287.                     FOR j = LEN(b) TO 1 STEP -1 'backup until find a space, save the tail end for next line
  288.                         d = MID$(b, j, 1)
  289.                         IF d = " " THEN
  290.                             t(ti) = MID$(b, 1, j - 1): b = tail + c: ti = ti + 1: REDIM _PRESERVE t(ti)
  291.                             ff = 1 'found space flag
  292.                             EXIT FOR
  293.                         ELSE
  294.                             tail = d + tail 'the tail grows!
  295.                         END IF
  296.                     NEXT
  297.                     IF ff = 0 THEN 'no break? OK
  298.                         t(ti) = b: b = c: ti = ti + 1: REDIM _PRESERVE t(ti)
  299.                     END IF
  300.                 ELSE
  301.                     b = b + c 'just keep building the line
  302.                 END IF
  303.         END SELECT
  304.     NEXT
  305.     t(ti) = b
  306.     bxH = ti + 3: bxW = limit + 2
  307.  
  308.     'draw message box
  309.     mbx = _NEWIMAGE(60 * 8, (bxH + 1) * 16, 32)
  310.     _DEST mbx
  311.     COLOR _RGB32(60, 40, 25), _RGB32(225, 225, 255)
  312.     LOCATE 1, 1: PRINT LEFT$(SPACE$((bxW - LEN(title) - 3) / 2) + title + SPACE$(bxW), bxW)
  313.     COLOR _RGB32(225, 225, 255), _RGB32(200, 0, 0)
  314.     LOCATE 1, bxW - 2: PRINT " X "
  315.     COLOR _RGB32(60, 40, 25), _RGB32(255, 160, 90)
  316.     LOCATE 2, 1: PRINT SPACE$(bxW);
  317.     FOR r = 0 TO ti
  318.         LOCATE 1 + r + 2, 1: PRINT LEFT$(" " + t(r) + SPACE$(bxW), bxW);
  319.     NEXT
  320.     LOCATE 1 + bxH, 1: PRINT SPACE$(limit + 2);
  321.  
  322.     'now for the action
  323.     _DEST curScrn
  324.  
  325.     'convert to pixels the top left corner of box at moment
  326.     bxW = bxW * 8: bxH = bxH * 16
  327.     tlx = (sw - bxW) / 2: tly = (sh - bxH) / 2
  328.     lastx = tlx: lasty = tly
  329.     'now allow user to move it around or just read it
  330.     WHILE 1
  331.         CLS
  332.         _PUTIMAGE , backScrn
  333.         _PUTIMAGE (tlx, tly), mbx, curScrn
  334.         _DISPLAY
  335.         WHILE _MOUSEINPUT: WEND
  336.         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  337.         IF mb THEN
  338.             IF mx >= tlx AND mx <= tlx + bxW AND my >= tly AND my <= tly + 16 THEN 'mouse down on title bar
  339.                 IF mx >= tlx + bxW - 24 THEN EXIT WHILE
  340.                 grabx = mx - tlx: graby = my - tly
  341.                 DO WHILE mb 'wait for release
  342.                     mi = _MOUSEINPUT: mb = _MOUSEBUTTON(1)
  343.                     mx = _MOUSEX: my = _MOUSEY
  344.                     IF mx - grabx >= 0 AND mx - grabx <= sw - bxW AND my - graby >= 0 AND my - graby <= sh - bxH THEN
  345.                         'attempt to speed up with less updates
  346.                         IF ((lastx - (mx - grabx)) ^ 2 + (lasty - (my - graby)) ^ 2) ^ .5 > 10 THEN
  347.                             tlx = mx - grabx: tly = my - graby
  348.                             CLS
  349.                             _PUTIMAGE , backScrn
  350.                             _PUTIMAGE (tlx, tly), mbx, curScrn
  351.                             lastx = tlx: lasty = tly
  352.                             _DISPLAY
  353.                         END IF
  354.                     END IF
  355.                     _LIMIT 400
  356.                 LOOP
  357.             END IF
  358.         END IF
  359.         kh = _KEYHIT
  360.         IF kh = 27 OR kh = 13 OR kh = 32 THEN EXIT WHILE
  361.         _LIMIT 400
  362.     WEND
  363.     'put things back
  364.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  365.     _PUTIMAGE , backScrn
  366.     _DISPLAY
  367.     COLOR fg, bg
  368.     _FREEIMAGE backScrn
  369.     _FREEIMAGE mbx
  370.     'clear key presses
  371.     _KEYCLEAR
  372.     'clear mouse clicks
  373.     mb = _MOUSEBUTTON(1)
  374.     IF mb THEN 'clear it
  375.         WHILE mb 'OK!
  376.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  377.             _LIMIT 10
  378.         WEND
  379.     END IF
  380.  
  381. ' these subs are used for the background graphics program testing usage of ScrollWindow
  382. 'Reference and thanks to:
  383. ' http://mathworld.wolfram.com/HeartCurve.html
  384. ' find the 6th heart curve equations #7, 8
  385. FUNCTION xCard (t)
  386.     xCard = 16 * SIN(t) ^ 3
  387.  
  388. FUNCTION yCard (t)
  389.     yCard = 13 * COS(t) - 5 * COS(2 * t) - 2 * COS(3 * t) - COS(4 * t)
  390.  
  391. ' this is used to load a file into an array and returns the number of lines in the file
  392. FUNCTION fLines& (fileName$, arr() AS STRING)
  393.     DIM fileCount AS LONG
  394.     IF _FILEEXISTS(fileName$) THEN
  395.         OPEN fileName$ FOR INPUT AS #1
  396.         DO UNTIL EOF(1)
  397.             LINE INPUT #1, arr(fileCount)
  398.             'PRINT filecount%, arr(filecount)
  399.             fileCount = fileCount + 1
  400.         LOOP
  401.         CLOSE #1
  402.         REDIM _PRESERVE arr(fileCount - 1)
  403.     END IF
  404.     fLines& = fileCount 'this file returns the number of lines loaded, 0 means file did not exist
  405.  
  406.  
« Last Edit: May 17, 2019, 03:20:45 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #1 on: May 17, 2019, 07:12:28 am »
Nice work, Bplus.

Instead of using _keyclear, I use a DO LOOP UNTIL loop that is waiting to release the button. This in turn ensures that one mouse click is not applied to more places than intended. Something like this:

Code: [Select]
SUB Reset_Mouse
    'reset mouseinputs from previous subs
    DO UNTIL _MOUSEBUTTON(1) = 0
        WHILE _MOUSEINPUT: WEND
    LOOP
    '--------------------------------
END SUB


« Last Edit: May 17, 2019, 07:17:23 am by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #2 on: May 17, 2019, 09:48:10 am »
Hi Petr,

Yes, for SUB mBox, I resorted to having to clear both keypresses and clicks with following code and it still didn't work until I added a _LIMIT to slow it down, possibly because the code executes the exit of sub while button or key is still down?

In SUB scrollWindow, I used similar _MOUSEBUTTON(1) clear immediately when click detected, otherwise the Pg Up, Pg Dn bar clicks would keep processing until at start or end of array being displayed.

Code: QB64: [Select]
  1.     'clear key presses
  2.     kh = _KEYHIT
  3.     WHILE _KEYDOWN(27) OR _KEYDOWN(13) OR _KEYDOWN(32) OR kh
  4.         kh = _KEYHIT
  5.         _KEYCLEAR 'ah that got it, nope damn it!
  6.         _LIMIT 10 'try slowing this down
  7.     WEND
  8.     'clear mouse clicks
  9.     mb = _MOUSEBUTTON(1)
  10.     IF mb THEN 'clear it
  11.         '_delay .2 'this sucks but won't clear mouse click
  12.         WHILE mb 'OK!
  13.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  14.             _LIMIT 10
  15.         WEND
  16.     END IF
  17.  

« Last Edit: May 17, 2019, 10:09:10 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #3 on: May 17, 2019, 10:21:50 am »
This is due to the internal buffer, as show Steve for us here: https://www.qb64.org/forum/index.php?topic=1344.msg105427#msg105427. It is best to wait to clear the contents of the buffer - as it do my program for left mouse button. In the same way it can be done for _KEYDOWN.
It's actually the same as the DO LOOP WHILE _SNDRAWLEN loop that prevents the program from ending before the end of RAW audio playback.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #4 on: May 17, 2019, 12:31:47 pm »
Oh rats! I am still trying to clear a _KEYDOWN.  - Old dog

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #5 on: May 17, 2019, 03:23:50 pm »
First post has been edited to remove all _KEYDOWN(27) used to exit subs or main code loop as well as silly code trying to clear _KEYDOWN values. ecs key presses now working cleanly!
« Last Edit: May 17, 2019, 03:25:14 pm by bplus »

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #6 on: May 18, 2019, 05:22:17 am »
Nice work, of course.

This scrollable text windows would be interesting when used as a selector of something for an other part of a program.

For this, I mean, the heart has no interest.
The selector should show a list. When you double click on an item, the program knows what you want and use it.
In short, a lighter version for a dynamic selector.
But I wrote mine for my use ...
Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scrollable Text Windows for Graphics Screens
« Reply #7 on: May 18, 2019, 09:33:03 am »
Hi euklides,

A scollable list box for selecting an item from a long array was exactly how this code started. You can still see tell signs eg, the lines being hignlighted.

Just seemed like a good place to start for a "window", specially one that I hope to make act like a console window that is always up and appending new stuff as user interacts with code.

Maybe have 3 Text only games going at once or allow selecting blocks of "output" lines for Clipboard.