Author Topic: I seem to be sinning against syntax for UBOUND  (Read 7330 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #15 on: August 31, 2018, 09:07:11 am »
Hi OldMoses,

If you are drawing something and then clearing and redrawing over and over in a loop, use _DISPLAY to stop the flickering.

I put the _LIMIT (which saves CPU from overheating making fan go on) statement just after _DISPLAY.

BUT! Once you use _DISPLAY, you have to use it each time you want to show a screen update, like just writing a message over the current screen displayed. _DISPLAY saves up all screen drawing until the command to _DISPLAY is made.

BUT! _DISPLAY can be disabled with command _AUTODISPLAY


Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #16 on: August 31, 2018, 12:40:54 pm »
Hi OldMoses,

If you are drawing something and then clearing and redrawing over and over in a loop, use _DISPLAY to stop the flickering.

I put the _LIMIT (which saves CPU from overheating making fan go on) statement just after _DISPLAY.

BUT! Once you use _DISPLAY, you have to use it each time you want to show a screen update, like just writing a message over the current screen displayed. _DISPLAY saves up all screen drawing until the command to _DISPLAY is made.

BUT! _DISPLAY can be disabled with command _AUTODISPLAY

Yes! That worked like a charm. I see what you mean by having to use _AUTODISPLAY, the screen would lock when I tried to EXIT SUB unless I invoked it just before the exit.  So much to learn...such a great place to do it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #17 on: August 31, 2018, 01:26:55 pm »
Hi OldMoses,

If you are drawing something and then clearing and redrawing over and over in a loop, use _DISPLAY to stop the flickering.

I put the _LIMIT (which saves CPU from overheating making fan go on) statement just after _DISPLAY.

BUT! Once you use _DISPLAY, you have to use it each time you want to show a screen update, like just writing a message over the current screen displayed. _DISPLAY saves up all screen drawing until the command to _DISPLAY is made.

BUT! _DISPLAY can be disabled with command _AUTODISPLAY

Yes! That worked like a charm. I see what you mean by having to use _AUTODISPLAY, the screen would lock when I tried to EXIT SUB unless I invoked it just before the exit.  So much to learn...such a great place to do it.

Well _DISPLAY won't prevent an EXIT SUB, you just won't see anything new until the command _DISPLAY occurs again.

If you really did lock up the execution, that may be a bug and need reporting but I am pretty sure you just saw the illusion of being locked because nothing was happening on screen.

Say, I am considering working on getMenuItemNUmber function some more, do you have any plans for using fonts?
I am considering case when all the items won't fit in predefined page or rectangle on screen, plus the mouse over highlight plus more discrimination with mouse clicks on the right side of the listing. Maybe for being able to read the records from a file and select one to edit. Come to think, I have something that scrolls through an array with mouse wheel.... :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #18 on: August 31, 2018, 05:55:11 pm »
Say, I am considering working on getMenuItemNUmber function some more, do you have any plans for using fonts?
I am considering case when all the items won't fit in predefined page or rectangle on screen, plus the mouse over highlight plus more discrimination with mouse clicks on the right side of the listing. Maybe for being able to read the records from a file and select one to edit. Come to think, I have something that scrolls through an array with mouse wheel.... :)

I hadn't really thought about fonts, at this stage I wouldn't have a clue how to work with them. The program that was doing the flickering, my RPG character generator, has a mousewheel scroll routine for long skill and weapon lists. The code I used is:

Code: QB64: [Select]
  1. SUB Mouse_Loop (var AS INTEGER, var2 AS INTEGER)
  2.  
  3.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4.     ' SUB: Mouse_Loop
  5.     '
  6.     ' Purpose:
  7.     ' Primary mouse input loop. Controls mousewheel scrolling and conditions
  8.     ' x,y position data.
  9.     '
  10.     ' Passed Variables:
  11.     ' var sends whether data list is extensive enough for using offset printing values
  12.     ' var2 sends maximum allowed offset value
  13.     '
  14.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  15.  
  16.  
  17.     'scan for changes in mouse position and save to global variables
  18.         IF var = 1 THEN
  19.             offset = offset + _MOUSEWHEEL 'mousewheel offset determines starting element to print
  20.             IF offset < 0 THEN offset = 0 'don't go beyond bottom of array
  21.             IF offset > var2 THEN offset = var2 'don't go beyond upper boundary of array
  22.         END IF
  23.         IF _MOUSEY - INT(_MOUSEY) >= .5 THEN
  24.             mouse_y = INT(_MOUSEY + 1)
  25.         ELSE
  26.             mouse_y = INT(_MOUSEY)
  27.         END IF
  28.         mouse_x = INT(_MOUSEX)
  29.     LOOP
  30.  
  31. END SUB 'Mouse_Loop
  32.  

The preceding loop, nested in and called from a display loop, sends 'offset', 'mouse_x' & 'mouse_y', all global variables, out to the display iteration. It's the same code in my original post, since I recycled it for the Grain4 program, but in that case the arrays are too short to need it so I just send 0 for 'var' and 'var2'.

Then MousePoint% grabs the actual choice determination on mouse click and sends it to IF...THEN or SELECT CASE or whatever...

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #19 on: September 01, 2018, 01:25:10 pm »
Hi Bplus,

I've been playing around with code you created. By repositioning the print interation within the DO...LOOP and bringing in a modification of my Mouse_Loop SUB I've got it to do the mouseover highlighting and retain the number hotkeys. I'm having a hard time getting my head wrapped around graphics screen x and y handling, but this one {seems} to work.

Code: QB64: [Select]
  1. 'Bplus overhauled OldMoses code 2018-08-31
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 200, 60
  4.  
  5. '' Data type for truck list array
  6. TYPE Vehicle
  7.     trucknm AS STRING * 10 'Truck name
  8.     tare AS LONG 'Tare weight
  9.  
  10. DIM SHARED farmindex(x) AS STRING 'Farm index array
  11. DIM SHARED truck(x) AS Vehicle 'Truck index array
  12. DIM SHARED mouse_x AS INTEGER 'column position of mouse
  13. DIM SHARED mouse_y AS INTEGER 'row position of mouse
  14.  
  15. ''Initialize truck list from truck.txt
  16. OPEN "truck.txt" FOR RANDOM AS #3 LEN = LEN(truck(0))
  17. IF LOF(3) = 0 THEN 'TRUCK.TXT is empty/not present
  18.     REDIM truck(1) AS Vehicle
  19.     truck(1).trucknm = "default" 'create blank truck record
  20.     truck(1).tare = 0
  21.     PUT #3, 1, truck(1)
  22. ELSE 'TRUCK.TXT is present
  23.     y% = LOF(3) / LEN(truck(0)) 'retrieve truck records
  24.     REDIM truck(y%) AS Vehicle
  25.     FOR x = 1 TO y%
  26.         GET #3, x, truck(x)
  27.     NEXT x
  28.     CLOSE #3
  29.  
  30. ''Initialize farm list into farmindex array
  31. OPEN "farm.txt" FOR RANDOM AS #4 LEN = 20
  32. IF LOF(4) = 0 THEN 'FARM.TXT is empty/not present
  33.     REDIM farmindex(1) AS STRING
  34.     farmindex(1) = "Main" 'create blank farm record
  35.     PUT #4, 1, farmindex(1)
  36. ELSE 'FARM.TXT is present
  37.     y% = LOF(4) / 20 'retrieve farm records
  38.     REDIM farmindex(y%) AS STRING
  39.     FOR x = 1 TO y%
  40.         GET #4, x, farmindex(x)
  41.     NEXT x
  42.     CLOSE #4
  43.  
  44. 'End Main Module code
  45.  
  46.  
  47. 'This code executed in SUB ConfigRun which runs in a
  48. COLOR _RGB32(255, 255, 255)
  49. LOCATE 2, 10: PRINT "SELECT FARM"
  50. ch = getMenuItemNumber(3, 7, farmindex())
  51. PRINT: PRINT "          The farm you selected was "; farmindex(ch)
  52.  
  53. DIM menutruck(UBOUND(truck)) AS STRING
  54. FOR i = 1 TO UBOUND(truck)
  55.     menutruck(i) = truck(i).trucknm
  56.  
  57. LOCATE 15, 10: PRINT "CHOOSE TRUCK"
  58. ch = getMenuItemNumber(16, 7, menutruck())
  59. PRINT: PRINT "         You chose truck: "; truck(ch).trucknm
  60.  
  61. FUNCTION getMenuItemNumber (locateRow, locateColumn, menu() AS STRING)
  62.     DO
  63.         FOR m = 1 TO UBOUND(menu)
  64.             IF mouse_x >= 1 AND mouse_y = m THEN
  65.                 COLOR _RGB32(255, 51, 51)
  66.             END IF
  67.             LOCATE locateRow + m - 1, locateColumn: PRINT LTRIM$(STR$(m)) + ") " + menu(m)
  68.             COLOR _RGB32(255, 255, 255)
  69.         NEXT
  70.         LOCATE locateRow + m + 1, locateColumn: PRINT "To select: Enter number or click item."
  71.  
  72.         k$ = INKEY$
  73.         IF LEN(k$) THEN
  74.             IF INSTR("0123456789", k$) > 0 THEN b$ = b$ + k$
  75.             IF VAL(b$) >= 1 AND VAL(b$) <= UBOUND(menu) THEN choice = VAL(b$): EXIT DO ELSE b$ = ""
  76.             IF ASC(k$) = 8 THEN
  77.                 IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1)
  78.             END IF
  79.         END IF
  80.  
  81.         Mouse_Loop 0, 0, locateRow, locateColumn
  82.         IF _MOUSEBUTTON(1) THEN
  83.             mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  84.             IF mx >= 1 AND my >= 1 AND my <= UBOUND(menu) THEN
  85.                 choice = my
  86.             END IF
  87.         END IF
  88.         _LIMIT 200
  89.     LOOP UNTIL choice
  90.     getMenuItemNumber = choice
  91.  
  92.  
  93. SUB Mouse_Loop (var AS INTEGER, var2 AS INTEGER, ypos AS INTEGER, xpos AS INTEGER)
  94.  
  95.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  96.     ' SUB: Mouse_Loop
  97.     '
  98.     ' Purpose:
  99.     ' Primary mouse input loop. Controls mousewheel scrolling and conditions
  100.     ' x,y position data.
  101.     '
  102.     ' Passed Variables:
  103.     ' var sends whether data list is extensive enough for using offset printing values
  104.     ' var2 sends maximum allowed offset value
  105.     '
  106.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  107.  
  108.     'scan for changes in mouse position and save to global variables
  109.         IF var = 1 THEN
  110.             offset = offset + _MOUSEWHEEL 'mousewheel offset determines starting element to print
  111.             IF offset < 0 THEN offset = 0 'don't go beyond bottom of array
  112.             IF offset > var2 THEN offset = var2 'don't go beyond upper boundary of array
  113.         END IF
  114.         mouse_x = INT((_MOUSEX - (xpos * 8)) / 8) + 2
  115.         mouse_y = INT((_MOUSEY - (ypos * 16)) / 16) + 2
  116.     LOOP
  117.  
  118. END SUB 'Mouse_Loop
  119.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #20 on: September 01, 2018, 05:15:12 pm »
Yes, the idea is to convert a mouse x, y position in pixels to a character cell position of the screen.

So a standard QB64 font is 8 pixels wide and 16 pixels high.

This is why I asked about fonts, they might have different pixel widths and heights for their character cells.

If you stick to print and locate, I think QB64 can match character cells for a custom font. But finding which cell the mouse is over or clicking is crucial for using mouse selection.

So you need a function that converts mouse pixel x, y to column and row of character cell. For such a routine you could input the Font's width and height, the mouse x, y and out comes the cell row, column for locate.

I have a fuller featured array select index function almost ready for much bigger arrays when you need to page through the array of selections but looks like you've got things handled for your application.
« Last Edit: September 01, 2018, 05:20:21 pm by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: I seem to be sinning against syntax for UBOUND
« Reply #21 on: September 03, 2018, 11:36:23 pm »
I have a fuller featured array select index function almost ready for much bigger arrays when you need to page through the array of selections but looks like you've got things handled for your application.

I look forward to seeing it.

I did something similar to that in a purely SCREEN 0 text environment for my Runequest character generator. There are two displays that utilize mouse wheel scrolling, mouseover highlighting and click and edit various fields.

I'll attach it in case anyone is interested, along with a pre-gen to load. As with most of my creations it's a scatterbrained affair, that could probably benefit from better planning and SUBing out, but mostly seems to work as intended....mostly.... On startup, type "L", or click on Load at the bottom of the screen. It will query for a name, type "Jo" (the included pre-gen). If all files are intact and in the same directory, it should then display a bunch of skill percentages in the central black VIEW PRINT window. A left click on that field will take the user to a scrolling list that allows editing of various fields in the TYPE array, basic instructions displayed in the bottom bar. The main section of code for this is in SUB Mouse_List in the CASE IS = 1 section. Lines 2673 through 2770.

The other display is accessed by typing hotkey "W" or clicking "Weapons/" at the bottom. A split display with the bottom one scrolling by mouse wheel will open. It has several editable fields and displays some popup info on mouse over. The bulk of the code for that one is in SUB Display_Weapons and SUB Print_Arms. That was the one that had the flicker problem that you fixed.
« Last Edit: September 03, 2018, 11:40:15 pm by OldMoses »