Author Topic: Text distortion problem  (Read 3193 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Text distortion problem
« on: September 07, 2018, 08:14:06 pm »
I am working on a message box sub and got it working well in testing code program. So I try it out with the getArrayItem code to use as a Help screen (press h) and it does everything it is supposed to do BUT the text is distorted ??? I tested in a QB64 beta and got same results.

The message box is drawn in freshly minted _NEWIMAGE and just using _PUTIMAGE to new locations when mouse grabs title bar but the text image has weird shrinking of every 5 lines or so, the font is unclear to read in places and looks cut into in other places.

Here is the mBox test code:
Code: QB64: [Select]
  1. _TITLE "simple message box test and demo"
  2. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  3.  
  4. 'started 2018-09-05 by B+
  5. ' as of 9/6 1am I have basic display working and mouse grabbing and moving,
  6. ' this after getting main body of text wordwrapped and line count calc'd.
  7. ' need smoother/faster action, what is slowing this down? locate and print?
  8. ' 2018-09-06 Oh draw message box in dest and then _putImage over background = screen image
  9. ' and this will leave main screen unbesmirched? and moving box around is as easy as image!
  10. ' That's plan for tonight.  OK done. Added mouse click x-it.
  11. ' 2018-09-07 bak 2018-09-07_3P and start testing in other apps
  12. ' A disaster! something happened to the font in the getArrayItem app.
  13.  
  14. CONST WW = 800
  15. CONST WH = 600
  16. DIM SHARED curScn&
  17. curScn& = _NEWIMAGE(WW, WH, 32)
  18. SCREEN curScn&
  19. _SCREENMOVE (1280 - WW) / 2 + 30, (760 - WH) / 2
  20.  
  21. 'draw stuff
  22. FOR i = 1 TO 100
  23.     LINE (RND * WW, RND * WH)-STEP(RND * 80, RND * 60), _RGB32(RND * 255, RND * 255, RND * 255), BF
  24.  
  25. mess$ = "This is line 1 followed by LF" + CHR$(10)
  26. mess$ = mess$ + "This is line 2 followed by CR + LF" + CHR$(13) + CHR$(10)
  27. mess$ = mess$ + "Line 3 is followed by a double LF to make a space." + CHR$(10) + CHR$(10)
  28. mess$ = mess$ + "Here is a long line that hopefully won't all fit across the screen, so I just keep going on and on ..."
  29. mess$ = mess$ + "until the screen is half full of this single long, long line so I can test the wrapping my code does "
  30. mess$ = mess$ + "with this long thing! ending with a double CR." + CHR$(13) + CHR$(13)
  31. mess$ = mess$ + CHR$(9) + "This line started with a tab which should be replaced by spaces so now this line should be running too long. The End."
  32. title$ = "1234567890123456789012345678901234567890123456789012345"
  33. mBox mess$, title$
  34. BEEP 'we're back!
  35. WHILE _KEYDOWN(27) = 0
  36.     LINE (RND * WW, RND * WH)-STEP(RND * 80, RND * 60), _RGB32(RND * 255, RND * 255, RND * 255), BF
  37.     _DISPLAY
  38.     _LIMIT 5
  39.  
  40. 'title$ limit is 57 chars, all lines are 58 chars max
  41. ' version bak 2018-09-07_3P < fixing this version as it does not work well in another app
  42. SUB mBox (m$, title$)
  43.  
  44.     'using const WW for Window Width, WH for Window Height
  45.     DIM curScrn AS LONG, backScrn AS LONG, mbx AS LONG 'some handles
  46.     DIM ti AS INTEGER, limit AS INTEGER 'ti = test index for t$(), limit is number of chars per line
  47.     DIM i AS INTEGER, j AS INTEGER, ff AS _BIT, add AS _BYTE 'index, flag and
  48.     DIM bxH AS INTEGER, bxW AS INTEGER 'first as cells then as pixels
  49.     DIM mb AS INTEGER, mx AS INTEGER, my AS INTEGER, mi AS INTEGER, grabx AS INTEGER, graby AS INTEGER
  50.     DIM tlx AS INTEGER, tly AS INTEGER 'top left corner of message box
  51.     DIM lastx AS INTEGER, lasty AS INTEGER
  52.  
  53.     'screen snapshot
  54.     curScrn = _DEST
  55.     backScrn = _NEWIMAGE(WW, WH, 32)
  56.     _PUTIMAGE , curScrn, backScrn
  57.  
  58.     'setup t$() to store strings with ti as index, linit 58 chars per line max, b$ is for build
  59.     REDIM t$(0): ti = 0: limit = 58: b$ = ""
  60.     FOR i = 1 TO LEN(m$)
  61.         c$ = MID$(m$, i, 1)
  62.         '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
  63.         SELECT CASE c$
  64.             CASE CHR$(13) 'load line
  65.                 IF MID$(m$, i + 1, 1) = CHR$(10) THEN i = i + 1
  66.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  67.             CASE CHR$(10)
  68.                 IF MID$(m$, i + 1, 1) = CHR$(13) THEN i = i + 1
  69.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  70.             CASE ELSE
  71.                 IF c$ = CHR$(9) THEN c$ = SPACE$(4): add = 4 ELSE add = 1
  72.                 IF LEN(b$) + add > limit THEN
  73.                     tail$ = "": ff = 0
  74.                     FOR j = LEN(b$) TO 1 STEP -1 'backup until find a space, save the tail end for next line
  75.                         d$ = MID$(b$, j, 1)
  76.                         IF d$ = " " THEN
  77.                             t$(ti) = MID$(b$, 1, j - 1): b$ = tail$ + c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  78.                             ff = 1 'found space flag
  79.                             EXIT FOR
  80.                         ELSE
  81.                             tail$ = d$ + tail$ 'the tail grows!
  82.                         END IF
  83.                     NEXT
  84.                     IF ff = 0 THEN 'no break? OK
  85.                         t$(ti) = b$: b$ = c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  86.                     END IF
  87.                 ELSE
  88.                     b$ = b$ + c$ 'just keep building the line
  89.                 END IF
  90.         END SELECT
  91.     NEXT
  92.     t$(ti) = b$
  93.     bxH = ti + 3: bxW = limit + 2
  94.  
  95.     'draw message box
  96.     mbx = _NEWIMAGE(60 * 8, (bxH + 1) * 16, 32)
  97.     _DEST mbx
  98.     COLOR _RGB32(60, 40, 25), _RGB32(225, 225, 255)
  99.     LOCATE 1, 1: PRINT LEFT$(SPACE$((bxW - LEN(title$) - 3) / 2) + title$ + SPACE$(bxW), bxW)
  100.     COLOR _RGB32(225, 225, 255), _RGB32(200, 0, 0)
  101.     LOCATE 1, bxW - 2: PRINT " X "
  102.     COLOR _RGB32(60, 40, 25), _RGB32(255, 160, 90)
  103.     LOCATE 2, 1: PRINT SPACE$(bxW);
  104.     FOR r = 0 TO ti
  105.         LOCATE 1 + r + 2, 1: PRINT LEFT$(" " + t$(r) + SPACE$(bxW), bxW);
  106.     NEXT
  107.     LOCATE 1 + bxH, 1: PRINT SPACE$(limit + 2);
  108.  
  109.     'now for the action
  110.     _DEST curScrn
  111.  
  112.     'convert to pixels the top left corner of box at moment
  113.     bxW = bxW * 8: bxH = bxH * 16
  114.     tlx = (WW - bxW) / 2: tly = (WH - bxH) / 2
  115.     lastx = tlx: lasty = tly
  116.     'now allow user to move it around or just read it
  117.     WHILE _KEYDOWN(27) = 0 AND _KEYDOWN(13) = 0 AND _KEYDOWN(32) = 0
  118.         CLS
  119.         _PUTIMAGE , backScrn
  120.         _PUTIMAGE (tlx, tly)-STEP(bxW, bxH), mbx, curScrn
  121.         _DISPLAY
  122.         WHILE _MOUSEINPUT: WEND
  123.         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  124.         IF mb THEN
  125.             IF mx >= tlx AND mx <= tlx + bxW AND my >= tly AND my <= tly + 16 THEN 'mouse down on title bar
  126.                 IF mx >= tlx + bxW - 24 THEN EXIT WHILE
  127.                 grabx = mx - tlx: graby = my - tly
  128.                 DO WHILE mb 'wait for release
  129.                     mi = _MOUSEINPUT: mb = _MOUSEBUTTON(1)
  130.                     mx = _MOUSEX: my = _MOUSEY
  131.                     IF mx - grabx >= 0 AND mx - grabx <= WW - bxW AND my - graby >= 0 AND my - graby <= WH - bxH THEN
  132.                         'attempt to speed up with less updates
  133.                         IF ((lastx - (mx - grabx)) ^ 2 + (lasty - (my - graby)) ^ 2) ^ .5 > 10 THEN
  134.                             tlx = mx - grabx: tly = my - graby
  135.                             CLS
  136.                             _PUTIMAGE , backScrn
  137.                             _PUTIMAGE (tlx, tly)-STEP(bxW, bxH), mbx, curScrn
  138.                             lastx = tlx: lasty = tly
  139.                             _DISPLAY
  140.                         END IF
  141.                     END IF
  142.                     _LIMIT 400
  143.                 LOOP
  144.             END IF
  145.         END IF
  146.         _LIMIT 400
  147.     WEND
  148.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  149.     _PUTIMAGE , backScrn
  150.     _FREEIMAGE backScrn
  151.     _FREEIMAGE mbx
  152.     _DISPLAY
  153.  


The resulting text image is fine!

Now here is same code tested with getArrayIndex code as a Help Window:
Code: QB64: [Select]
  1. _TITLE "getArrayItemClicked v4 mbox"
  2.  
  3. ' Main testing and demo of the FUNCTION  getArrayItemNumber%
  4.  
  5. 'started 2018-08-31 B+  developing a general purpose display and select app of a string array
  6. ' in this version want
  7. ' 1 to be able to select item from larger arrays that take several pages to screen
  8. ' 2 highlite mouse over ?
  9. ' 3 colorize print? Eh! bloats parameters in call, if really want, modify function for app.
  10. '   Using dark blue on sky blue and reverse for highlite, pretty easy on eyes and sets off
  11. '   selection area.
  12. ' 4 keep modifiable for possibly adding fonts, I think that means use only locate and print,
  13. '  as _printstring works in pixels, no good for different fonts. (Neither is LOCATE)
  14.  
  15. ' 2018-09-01 yea, finally got everything working and playing together
  16. ' oh yeah, to mouse click an escape along with expected escape button press.
  17. ' I might to build a frame around the list box control? (No, just a bar above and below)
  18.  
  19. '2018-09-03 OK everything working great! But I have added two lines to maxHeight.
  20. ' Do I adjust maxHeight to reflect actual height of box on screen, I think better do it.
  21. ' Oh heck that was easy!  Just calc maxHeight off boxHeight!
  22. ' Clean up instructions for using the function.
  23. ' NEXT project is message box that doesn't need Windows OS calls,
  24. ' so I could offer help here with h keypress!
  25. ' Just tested a font with locate and print and locate does not work.
  26. ' So this is done until I get messageBox working.
  27.  
  28. '2018-09-04 post v2 bak 9-3_9PM
  29. '2018-09-07 getArrayItem v4 mbox - time to test mbox with help window
  30.  
  31. CONST nArr = 92 'ubound of array = actual amount of items if LBound = 1
  32. CONST LB = 1 'try different lower bounds not just 0, 1
  33. CONST WW = 1200 'Window Width
  34. CONST WH = 600 'Window Height
  35.  
  36. SCREEN _NEWIMAGE(WW, WH, 32)
  37. _SCREENMOVE 100, 60
  38.  
  39.  
  40. 'test string array, use indexes in lines for alignment to code for function
  41. REDIM arr(LB TO nArr) AS STRING
  42. FOR i = LB TO nArr
  43.     arr(i) = "This is arr item:" + STR$(i)
  44.  
  45.     CLS
  46.     PRINT
  47.     cp "*** Mouse and Key Instructions ***"
  48.     PRINT
  49.     cp "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  50.     cp "Press spacebar to select a highlighted item or just click it."
  51.     cp "Use number(s) + enter to select an array item by it's index number,"
  52.     cp "backspace will remove last number pressed, c will clear a number started."
  53.     cp "Numbers started are shown in bottom right PgDn bar."
  54.     cp "Enter will also select the highlighted item, if no number has been started."
  55.     cp "Home starts you at lowest array index, End highlights then highest index."
  56.     cp "Use PgUp and PgDn keys or bars to flip through pages of array items."
  57.     PRINT
  58.     cp "Escape returns -1719 to allow a Cancel function and signal no slection."
  59.     PRINT ""
  60.     locRow = 16: locCol = (WW / 8 - 25) / 2: boxWidth = 25: boxHeight = 17 '< displays 15 lines of array items
  61.     'boxHeight is actual screen space in character units, the display uses 2 of the lines for control bars.
  62.     'boxWidth will include item numbers displayed to left of array string item
  63.     CH = getArrayItemNumber(locRow, locCol, boxWidth, boxHeight, arr())
  64.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): LOCATE 32, 1
  65.     IF CH = -1719 THEN cp "You canceled selection process." ELSE cp "You chose index (" + LTRIM$(STR$(CH)) + ") = " + arr(CH)
  66.     IF NOT goAgain THEN EXIT WHILE
  67.  
  68. 'see this file
  69. REDIM fArr(500) AS STRING
  70. lnCnt = fLines("getArrayItem v4 mbox.bas", fArr()) '<<<<<<<<<<<<<<<<<<< or whatever name you gave this file AND SAVED!
  71. CH = getArrayItemNumber(5, 5, 140, 30, fArr())
  72. LOCATE 1, 1: PRINT CH
  73.  
  74. ' Future Help Message Box for the function.
  75. ' "*** Mouse and Key Instructions ***"
  76. '
  77. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  78. ' "Press spacebar to select a highlighted item or just click it."
  79. ' "Use number(s) + enter to select an array item by it's index number,"
  80. ' "backspace will remove last number pressed, c will clear a number started."
  81. ' "Numbers started are shown in bottom right PgDn bar."
  82. ' "Enter will also select the highlighted item, if no number has been started."
  83. ' "Home starts you at lowest array index, End highlights then highest index."
  84. ' "Use PgUp and PgDn keys to flip through pages of array items."
  85. '
  86. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  87. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  88.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  89.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  90.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  91.     '
  92.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  93.     DIM lba AS LONG, uba AS LONG, choice 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.  
  102.     GOSUB update '              show the beginning of the array items for selection
  103.  
  104.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  105.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  106.  
  107.     DO 'until get a selection or demand exit
  108.  
  109.         'handle the key stuff
  110.         kh& = _KEYHIT
  111.         IF kh& THEN
  112.             IF kh& > 0 AND kh& < 255 THEN
  113.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  114.                 IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  115.  
  116.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  117.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  118.                     IF LEN(b$) THEN
  119.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  120.                             choice = VAL(b$): EXIT DO
  121.                         ELSE 'clear b$ to show some response to enter
  122.                             b$ = "": GOSUB update 'clear the value that doesn't work
  123.                         END IF
  124.                     ELSE
  125.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  126.                     END IF
  127.                 END IF
  128.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  129.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  130.                 IF kh& = 8 THEN 'backspace to edit number
  131.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  132.                 END IF
  133.             ELSE
  134.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  135.                     CASE 20736 'pg dn
  136.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  137.                     CASE 18688 'pg up
  138.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  139.                     CASE 18432 'up
  140.                         IF hlite - 1 < 0 THEN
  141.                             IF page > 0 THEN
  142.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  143.                             END IF
  144.                         ELSE
  145.                             hlite = hlite - 1: GOSUB update
  146.                         END IF
  147.                     CASE 20480 'down
  148.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  149.                             IF hlite + 1 > maxHeight - 1 THEN
  150.                                 page = page + 1: hlite = 0: GOSUB update
  151.                             ELSE
  152.                                 hlite = hlite + 1: GOSUB update
  153.                             END IF
  154.                         END IF
  155.                     CASE 18176 'home
  156.                         page = 0: hlite = 0: GOSUB update
  157.                     CASE 20224 ' end
  158.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  159.                 END SELECT
  160.             END IF
  161.         END IF
  162.  
  163.         'handle the mouse stuff
  164.         WHILE _MOUSEINPUT
  165.             IF _MOUSEWHEEL = -1 THEN 'up?
  166.                 IF hlite - 1 < 0 THEN
  167.                     IF page > 0 THEN
  168.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  169.                     END IF
  170.                 ELSE
  171.                     hlite = hlite - 1: GOSUB update
  172.                 END IF
  173.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  174.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  175.                     IF hlite + 1 > maxHeight - 1 THEN
  176.                         page = page + 1: hlite = 0: GOSUB update
  177.                     ELSE
  178.                         hlite = hlite + 1: GOSUB update
  179.                     END IF
  180.                 END IF
  181.             END IF
  182.         WEND
  183.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  184.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  185.             _DELAY .2
  186.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  187.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  188.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  189.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  190.                     EXIT DO 'escape plan for mouse click top right corner of display box
  191.                 ELSE 'PgUp bar clicked
  192.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  193.                 END IF
  194.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  195.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  196.             END IF
  197.         ELSE '   mouse over highlighting, only if mouse has moved!
  198.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  199.                 IF mx <> lastmx OR my <> lastmy THEN
  200.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  201.                         hlite = my - 1
  202.                         lastmx = mx: lastmy = my
  203.                         GOSUB update
  204.                     END IF
  205.                 END IF
  206.             END IF
  207.         END IF
  208.         _LIMIT 200
  209.     LOOP UNTIL choice >= lba AND choice <= uba
  210.     getArrayItemNumber& = choice
  211.     EXIT SUB
  212.  
  213.     'display of array sections and controls on screen
  214.     update:
  215.  
  216.     'fix hlite if it has dropped below last array item
  217.     WHILE hlite + page * maxHeight + lba > uba
  218.         hlite = hlite - 1
  219.     WEND
  220.  
  221.     'main display of array items at page * maxHeight (lines high)
  222.     FOR row = 0 TO maxHeight - 1
  223.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  224.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  225.         index = row + page * maxHeight + lba
  226.         IF index >= lba AND index <= uba THEN
  227.             LOCATE locateRow + row, locateColumn
  228.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  229.         END IF
  230.     NEXT
  231.  
  232.     'make page up and down bars to click, print PgUp / PgDn if available
  233.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  234.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  235.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  236.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  237.     IF page <> INT(uba / maxHeight) THEN
  238.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  239.     END IF
  240.     'make exit sign for mouse click
  241.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  242.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  243.     PRINT " X "
  244.  
  245.     'if a number selection has been started show it's build = b$
  246.     IF LEN(b$) THEN
  247.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  248.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  249.         PRINT b$;
  250.     END IF
  251.     _DISPLAY
  252.     _LIMIT 100
  253.     RETURN
  254.  
  255. '                              These are needed only for the demo and testing of the function:
  256. '  It should be noted I had trouble using INPUT and INKEY$ after using the function being tested, ie inquiring about another test.
  257. '                              Something about clearing keypresses (and enter specially).
  258. FUNCTION goAgain% ()
  259.     WHILE LEN(INKEY$): WEND 'clear inkey$
  260.     PRINT: cp "Go again? press y for yes, any other for no."
  261.     k$ = ""
  262.     WHILE k$ = "": k$ = INKEY$: WEND
  263.     IF k$ = "y" THEN goAgain% = -1
  264.  
  265. SUB cp (s$)
  266.     LOCATE CSRLIN, (WW / 8 - LEN(s$)) / 2: PRINT s$
  267.  
  268. FUNCTION fLines (fileName$, arr() AS STRING)
  269.     filecount% = 0
  270.     IF _FILEEXISTS(fileName$) THEN
  271.         OPEN fileName$ FOR INPUT AS #1
  272.         DO UNTIL EOF(1)
  273.             LINE INPUT #1, arr(filecount%)
  274.             'PRINT filecount%, arr(filecount%)
  275.             filecount% = filecount% + 1
  276.         LOOP
  277.         CLOSE #1
  278.         REDIM _PRESERVE arr(filecount% - 1)
  279.     END IF
  280.     fLines = filecount% 'this file returns the number of lines loaded, 0 means file did not exist
  281.  
  282. SUB HELP
  283.     n$ = CHR$(10)
  284.     t$ = "*** Mouse and Key Instructions ***"
  285.     m$ = "Mouse, mouse wheel, and arrow keys should work as expected for item selection." + n$
  286.     m$ = m$ + "Press spacebar to select a highlighted item or just click it." + n$
  287.     m$ = m$ + "Use number(s) + enter to select an array item by it's index number," + n$
  288.     m$ = m$ + "backspace will remove last number pressed, c will clear a number started." + n$
  289.     m$ = m$ + "Numbers started are shown in bottom right PgDn bar." + n$
  290.     m$ = m$ + "Enter will also select the highlighted item, if no number has been started." + n$
  291.     m$ = m$ + "Home starts you at lowest array index, End highlights then highest index." + n$
  292.     m$ = m$ + "Use PgUp and PgDn keys to flip through pages of array items." + n$ + n$
  293.     m$ = m$ + "Escape (returns -1719) to allow a Cancel function and signal no slection."
  294.     mBox m$, t$
  295.  
  296. 'title$ limit is 57 chars, all lines are 58 chars max
  297. ' version bak 2018-09-07_3P
  298. 'title$ limit is 57 chars, all lines are 58 chars max
  299. ' version bak 2018-09-07_3P < fixing this version as it does not work well in another app
  300. SUB mBox (m$, title$)
  301.  
  302.     'using const WW for Window Width, WH for Window Height
  303.     DIM curScrn AS LONG, backScrn AS LONG, mbx AS LONG 'some handles
  304.     DIM ti AS INTEGER, limit AS INTEGER 'ti = test index for t$(), limit is number of chars per line
  305.     DIM i AS INTEGER, j AS INTEGER, ff AS _BIT, add AS _BYTE 'index, flag and
  306.     DIM bxH AS INTEGER, bxW AS INTEGER 'first as cells then as pixels
  307.     DIM mb AS INTEGER, mx AS INTEGER, my AS INTEGER, mi AS INTEGER, grabx AS INTEGER, graby AS INTEGER
  308.     DIM tlx AS INTEGER, tly AS INTEGER 'top left corner of message box
  309.     DIM lastx AS INTEGER, lasty AS INTEGER
  310.  
  311.     'screen snapshot
  312.     curScrn = _DEST
  313.     backScrn = _NEWIMAGE(WW, WH, 32)
  314.     _PUTIMAGE , curScrn, backScrn
  315.  
  316.     'setup t$() to store strings with ti as index, linit 58 chars per line max, b$ is for build
  317.     REDIM t$(0): ti = 0: limit = 58: b$ = ""
  318.     FOR i = 1 TO LEN(m$)
  319.         c$ = MID$(m$, i, 1)
  320.         '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
  321.         SELECT CASE c$
  322.             CASE CHR$(13) 'load line
  323.                 IF MID$(m$, i + 1, 1) = CHR$(10) THEN i = i + 1
  324.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  325.             CASE CHR$(10)
  326.                 IF MID$(m$, i + 1, 1) = CHR$(13) THEN i = i + 1
  327.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  328.             CASE ELSE
  329.                 IF c$ = CHR$(9) THEN c$ = SPACE$(4): add = 4 ELSE add = 1
  330.                 IF LEN(b$) + add > limit THEN
  331.                     tail$ = "": ff = 0
  332.                     FOR j = LEN(b$) TO 1 STEP -1 'backup until find a space, save the tail end for next line
  333.                         d$ = MID$(b$, j, 1)
  334.                         IF d$ = " " THEN
  335.                             t$(ti) = MID$(b$, 1, j - 1): b$ = tail$ + c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  336.                             ff = 1 'found space flag
  337.                             EXIT FOR
  338.                         ELSE
  339.                             tail$ = d$ + tail$ 'the tail grows!
  340.                         END IF
  341.                     NEXT
  342.                     IF ff = 0 THEN 'no break? OK
  343.                         t$(ti) = b$: b$ = c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  344.                     END IF
  345.                 ELSE
  346.                     b$ = b$ + c$ 'just keep building the line
  347.                 END IF
  348.         END SELECT
  349.     NEXT
  350.     t$(ti) = b$
  351.     bxH = ti + 3: bxW = limit + 2
  352.  
  353.     'draw message box
  354.     mbx = _NEWIMAGE(60 * 8, (bxH + 1) * 16, 32)
  355.     _DEST mbx
  356.     COLOR _RGB32(60, 40, 25), _RGB32(225, 225, 255)
  357.     LOCATE 1, 1: PRINT LEFT$(SPACE$((bxW - LEN(title$) - 3) / 2) + title$ + SPACE$(bxW), bxW)
  358.     COLOR _RGB32(225, 225, 255), _RGB32(200, 0, 0)
  359.     LOCATE 1, bxW - 2: PRINT " X "
  360.     COLOR _RGB32(60, 40, 25), _RGB32(255, 160, 90)
  361.     LOCATE 2, 1: PRINT SPACE$(bxW);
  362.     FOR r = 0 TO ti
  363.         LOCATE 1 + r + 2, 1: PRINT LEFT$(" " + t$(r) + SPACE$(bxW), bxW);
  364.     NEXT
  365.     LOCATE 1 + bxH, 1: PRINT SPACE$(limit + 2);
  366.  
  367.     'now for the action
  368.     _DEST curScrn
  369.  
  370.     'convert to pixels the top left corner of box at moment
  371.     bxW = bxW * 8: bxH = bxH * 16
  372.     tlx = (WW - bxW) / 2: tly = (WH - bxH) / 2
  373.     lastx = tlx: lasty = tly
  374.     'now allow user to move it around or just read it
  375.     WHILE _KEYDOWN(27) = 0 AND _KEYDOWN(13) = 0 AND _KEYDOWN(32) = 0
  376.         CLS
  377.         _PUTIMAGE , backScrn
  378.         _PUTIMAGE (tlx, tly)-STEP(bxW, bxH), mbx, curScrn
  379.         _DISPLAY
  380.         WHILE _MOUSEINPUT: WEND
  381.         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  382.         IF mb THEN
  383.             IF mx >= tlx AND mx <= tlx + bxW AND my >= tly AND my <= tly + 16 THEN 'mouse down on title bar
  384.                 IF mx >= tlx + bxW - 24 THEN EXIT WHILE
  385.                 grabx = mx - tlx: graby = my - tly
  386.                 DO WHILE mb 'wait for release
  387.                     mi = _MOUSEINPUT: mb = _MOUSEBUTTON(1)
  388.                     mx = _MOUSEX: my = _MOUSEY
  389.                     IF mx - grabx >= 0 AND mx - grabx <= WW - bxW AND my - graby >= 0 AND my - graby <= WH - bxH THEN
  390.                         'attempt to speed up with less updates
  391.                         IF ((lastx - (mx - grabx)) ^ 2 + (lasty - (my - graby)) ^ 2) ^ .5 > 10 THEN
  392.                             tlx = mx - grabx: tly = my - graby
  393.                             CLS
  394.                             _PUTIMAGE , backScrn
  395.                             _PUTIMAGE (tlx, tly)-STEP(bxW, bxH), mbx, curScrn
  396.                             lastx = tlx: lasty = tly
  397.                             _DISPLAY
  398.                         END IF
  399.                     END IF
  400.                     _LIMIT 400
  401.                 LOOP
  402.             END IF
  403.         END IF
  404.         _LIMIT 400
  405.     WEND
  406.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  407.     _PUTIMAGE , backScrn
  408.     _FREEIMAGE backScrn
  409.     _FREEIMAGE mbx
  410.     _DISPLAY
  411.  

And here is a snap of the distorted text:
 

FellippeHeitor

  • Guest
Re: Text distortion problem
« Reply #1 on: September 07, 2018, 08:48:28 pm »
When you _PUTIMAGE with STEP, make sure it's width minus 1 and height minus 1.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Text distortion problem
« Reply #2 on: September 07, 2018, 09:11:37 pm »
When you _PUTIMAGE with STEP, make sure it's width minus 1 and height minus 1.

That didn't work but this did the trick!
Code: QB64: [Select]
  1.  _PUTIMAGE (tlx, tly), mbx, curScrn

Get rid of the bottom corner / 2nd coordinate altogether.

Thanks, I hadn't a clue what to fiddle with.
« Last Edit: September 07, 2018, 09:13:28 pm by bplus »