Author Topic: Frame Library  (Read 2482 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Frame Library
« on: October 19, 2018, 08:27:36 PM »
Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3. CONST FileName$ = "tt.txt"
  4.  
  5.  
  6. REDIM SHARED WordGrid(0, 0) AS STRING * 1
  7. REDIM SHARED YLines(0, 0) AS STRING
  8. REDIM SHARED XLines(0, 0) AS STRING
  9.  
  10. DIM SHARED SearchTerms(1) AS STRING
  11. SearchTerms(0) = "TRICK": SearchTerms(1) = "TREAT"
  12.  
  13.  
  14. DIM SHARED LeftFrame AS INTEGER, RightFrame AS INTEGER
  15.  
  16.  
  17. SCREEN _NEWIMAGE(1280, 720, 32) '720p HD just cause I like it as a standard
  18.  
  19.  
  20. LeftFrame = NewTextArea(0, 0, 400, _HEIGHT - 1, False)
  21. ColorTextArea LeftFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  22. DrawTextArea LeftFrame
  23.  
  24. RightFrame = NewTextArea(401, 0, _WIDTH - 1, _HEIGHT - 1, False)
  25. ColorTextArea RightFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  26. DrawTextArea RightFrame
  27.  
  28.  
  29.  
  30. LoadWordGrid
  31. MakeDirectional
  32. ShowGrid
  33. FindWords
  34.  
  35.  
  36.  
  37. SUB FindWords
  38.     FOR j = 0 TO UBOUND(SearchTerms)
  39.         SetPrintStyleX RightFrame, CenterJustify
  40.         SetPrintUpdate RightFrame, NewLine
  41.         SetTextForeground RightFrame, _RGB32(255, 255, 0)
  42.         PrintOut RightFrame, "SEARCHING FOR " + SearchTerms(j)
  43.         SetTextForeground RightFrame, _RGB32(255, 255, 255)
  44.         PrintOut RightFrame, ""
  45.         PrintOut RightFrame, "Finding Left to Right Matches"
  46.         SetPrintStyleX RightFrame, NoJustify
  47.         SetPrintUpdate RightFrame, NoNewLine
  48.  
  49.         FOR i = 1 TO Y
  50.             foundone = 0
  51.             DO
  52.                 foundone = INSTR(foundone + 1, YLines(1, i), SearchTerms(j))
  53.                 IF foundone THEN
  54.                     PrintOut RightFrame, "(Line" + STR$(i) + ", Position" + STR$(foundone) + "), "
  55.                     tc = tc + 1
  56.                 END IF
  57.             LOOP UNTIL NOT foundone
  58.         NEXT
  59.  
  60.         SetPrintStyleX RightFrame, CenterJustify
  61.         SetPrintUpdate RightFrame, NewLine
  62.         PrintOut RightFrame, ""
  63.         PrintOut RightFrame, ""
  64.         PrintOut RightFrame, "Finding Right to Left Matches"
  65.         SetPrintUpdate RightFrame, NoNewLine
  66.         SetPrintStyleX RightFrame, NoJustify
  67.         FOR i = 1 TO Y
  68.             foundone = 0
  69.             DO
  70.                 foundone = INSTR(foundone + 1, YLines(2, i), SearchTerms(j))
  71.                 IF foundone THEN
  72.                     PrintOut RightFrame, "(Line" + STR$(i) + ", Position" + STR$(X - foundone + 1) + "), "
  73.                     tc = tc + 1
  74.                 END IF
  75.             LOOP UNTIL NOT foundone
  76.         NEXT
  77.  
  78.         SetPrintStyleX RightFrame, CenterJustify
  79.         SetPrintUpdate RightFrame, NewLine
  80.         PrintOut RightFrame, ""
  81.         PrintOut RightFrame, ""
  82.         PrintOut RightFrame, "Finding Up to Down Matches"
  83.         SetPrintUpdate RightFrame, NoNewLine
  84.         SetPrintStyleX RightFrame, NoJustify
  85.         FOR i = 1 TO X
  86.             foundone = 0
  87.             DO
  88.                 foundone = INSTR(foundone + 1, XLines(1, i), SearchTerms(j))
  89.                 IF foundone THEN
  90.                     PrintOut RightFrame, "(Line" + STR$(foundone) + ", Position" + STR$(i) + "), "
  91.                     tc = tc + 1
  92.                 END IF
  93.             LOOP UNTIL NOT foundone
  94.         NEXT
  95.  
  96.         SetPrintStyleX RightFrame, CenterJustify
  97.         SetPrintUpdate RightFrame, NewLine
  98.         PrintOut RightFrame, ""
  99.         PrintOut RightFrame, ""
  100.         PrintOut RightFrame, "Finding Down to Up Matches"
  101.         SetPrintUpdate RightFrame, NoNewLine
  102.         SetPrintStyleX RightFrame, NoJustify
  103.         FOR i = 1 TO X
  104.             foundone = 0
  105.             DO
  106.                 foundone = INSTR(foundone + 1, XLines(2, i), SearchTerms(j))
  107.                 IF foundone THEN
  108.                     PrintOut RightFrame, "(Line" + STR$(foundone) + ", Position" + STR$(i) + "), "
  109.                     tc = tc + 1
  110.                 END IF
  111.             LOOP UNTIL NOT foundone
  112.         NEXT
  113.  
  114.  
  115.         SetPrintUpdate RightFrame, NewLine
  116.         PrintOut RightFrame, ""
  117.         PrintOut RightFrame, ""
  118.         PrintOut RightFrame, STR$(tc) + " total matches found."
  119.         PrintOut RightFrame, ""
  120.         PrintOut RightFrame, ""
  121.         tc = 0
  122.     NEXT
  123.  
  124.  
  125.  
  126. SUB ShowGrid
  127.     'Print the words in the grid
  128.     SetTextColor LeftFrame, _RGB32(255, 255, 0), 0
  129.     PrintOut LeftFrame, ""
  130.     PrintOut LeftFrame, "                     WORD GRID"
  131.     PrintOut LeftFrame, ""
  132.     SetTextColor LeftFrame, _RGB32(255, 255, 255), 0
  133.     FOR i = 1 TO Y
  134.         PrintOut LeftFrame, "  " + YLines(1, i)
  135.     NEXT
  136.  
  137.  
  138.  
  139.  
  140. SUB LoadWordGrid
  141.     OPEN FileName$ FOR BINARY AS #1
  142.     DO UNTIL EOF(1)
  143.         LINE INPUT #1, junk$
  144.         Y = Y + 1
  145.     LOOP
  146.     X = LEN(junk$): Y = Y
  147.     SEEK #1, 1
  148.  
  149.     REDIM WordGrid(1 TO X, 1 TO Y) AS STRING * 1 'Properly size our grid, with borders
  150.     REDIM YLines(2, Y) AS STRING
  151.     REDIM XLines(2, X) AS STRING
  152.  
  153.     FOR i = 1 TO Y
  154.         LINE INPUT #1, junk$
  155.         FOR j = 1 TO X
  156.             WordGrid(j, i) = MID$(junk$, j) 'Fill in the grid with the letters
  157.         NEXT
  158.     NEXT
  159.     CLOSE #1
  160.  
  161. SUB MakeDirectional
  162.     FOR i = 1 TO Y
  163.         FOR j = 1 TO X
  164.             YLines(1, i) = YLines(1, i) + WordGrid(j, i) 'Left to Right Lines
  165.     NEXT j, i
  166.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
  167.             YLines(2, i) = YLines(2, i) + WordGrid(j, i) 'Right to Left Lines
  168.     NEXT j, i
  169.     FOR i = 1 TO Y: FOR j = 1 TO X
  170.             XLines(1, i) = XLines(1, i) + WordGrid(j, i) 'Up to Down Lines
  171.     NEXT j, i
  172.     FOR i = 1 TO Y: FOR j = X TO 1 STEP -1
  173.             XLines(2, i) = XLines(1, i) + WordGrid(j, i) 'Right to Left Lines
  174.     NEXT j, i
  175.  
  176. '$INCLUDE:'FrameLibrary.BM'
  177.  

Using Bplus's halloween challenge to do a wordsearch from a grid of letters in various directions, I came up with this little demo to highlight the flexibility and ease of use of my little TextFrame Library.

What *IS* the FrameLibrary, you ask??

It's a simple way to designate various areas of the screen to print and interact independently on.  In this case, the left side holds the grid for us, while the right side prints out the results.  If you look at the demo I posted over at the other forums, it has 4 designated frame areas which we can print to.  (HERE: http://qb64.freeforums.net/thread/46/text-frames )

Each of these frames are 100% independent of the others.  You can set them to have various justification levels (left, right, center, no justification) for the text.  You can set whether text prints to a new line when finished, or not.  You can even set if the text frame is visible, or if you want to move it somewhere else onto the screen...

In the example here, we see how easy it is to designate our framed areas:

Code: QB64: [Select]
  1. LeftFrame = NewTextArea(0, 0, 400, _HEIGHT - 1, False)
  2. ColorTextArea LeftFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  3. DrawTextArea LeftFrame
  4.  
  5. RightFrame = NewTextArea(401, 0, _WIDTH - 1, _HEIGHT - 1, False)
  6. ColorTextArea RightFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  7. DrawTextArea RightFrame

You can also see where we center our output text, while moving the pointer to a newline afterwards:
Code: QB64: [Select]
  1.         SetPrintStyleX RightFrame, CenterJustify
  2.         SetPrintUpdate RightFrame, NewLine)

And, where we change back to where we don't want to justify our text, or move to a new line after:
Code: QB64: [Select]
  1.         SetPrintStyleX RightFrame, NoJustify
  2.         SetPrintUpdate RightFrame, NoNewLine

Changing the color of the text is rather simple:
Code: QB64: [Select]
  1.         SetTextForeground RightFrame, _RGB32(255, 255, 0)  

And, doing the actual printing is as simple as:
Code: QB64: [Select]
  1.         PrintOut RightFrame, "SEARCHING FOR " + SearchTerms(j)

The library does automatic word-wrap.  Automatic scrolling of a frame, if we print down to the bottom of the frame, just as QB64 does when we print at the bottom lines of the screen...

*******************************
*******************************

Honestly, it's not that complicated to use, once one tries it just a bit.  Most of the commands mimic what we already have in QB64, with just the extra parameter in front for WHICH frame we're using.

PRINT whatever$  --->  PrintOut frame, whatever$
COLOR fg, bg ---> SetTextColor frame, fg, bg
LOCATE x, y ---> SetPrintPosition frame, x, y
and so...

The only exception is when we go to adding NEW, non-native QB64 capabilities:

SetPrintStyleX frame, HOW -->  frame is the same as above, HOW is: LeftJustify, RightJustify, CenterJustify, or NoJustify

In this case, LeftJustify prints our text at the left edge of the frame; RightJustify prints the text starting from the right edge of the frame, CenterJustify centers the text on the line, and NoJustify doesn't do any justification (much like a simple PRINT statement.)

**************************
**************************

Anywho... I thought I'd just share and show off the library a bit.  I don't think many people have even taken a look at this one (much less used it), but I find it to be useful in a TON of things which I do.  Being able to designate and print to multiple sections of the screen, without disturbing the rest of the screen, has always been something which I felt was too difficult to do -- thus, the birth of this.  :D
« Last Edit: October 21, 2018, 10:38:29 PM by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Forum Resident
  • Posts: 611
  • Semper Fidelis
Re: Frame Library
« Reply #1 on: October 19, 2018, 09:26:20 PM »
Awesome! Thanks for sharing :)
In order to understand recursion, one must first understand recursion.

Offline codeguy

  • Forum Regular
  • Posts: 181
Re: Frame Library
« Reply #2 on: October 20, 2018, 01:02:33 AM »
Nifty.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #3 on: October 20, 2018, 01:31:14 AM »
Another simple demo to highlight some of the power of the library:

Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  7. PAINT (320, 240), _RGB32(255, 0, 0)
  8. LOCATE 15, 35: PRINT "See the circle?"
  9.  
  10. PopUp = NewTextArea(200, 150, 400, 300, True)
  11. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  12. DrawTextArea PopUp
  13. PrintOut PopUp, "See how we popped up text in the box here, which has now overdrawn our circle?"
  14.  
  15. HideFrame PopUp
  16. LOCATE 2, 2: PRINT "Notice how we preserve the background when we hide/close the frame?"
  17.  
  18.  
  19. '$include:'FrameLibrary.BM'

Needs the library files above to work, so grab them before trying this.

Notice here when I make the frame, the last option is set to TRUE:

Code: QB64: [Select]
  1. PopUp = NewTextArea(200, 150, 400, 300, TRUE)

PopUp is the name which I'm calling my designated text area.  200, 150, 400,300 are the screen coordinates where the frame is created.  The last option (TRUE in this case) is a toggle asking, "Do we want to preserve the background underneath the PopUp?"

Since we said, TRUE, when we hide the PopUp, the background is restored...

** These frames can hide/appear without disturbing existing text which we already have on the screen!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #4 on: October 20, 2018, 01:35:53 AM »
And to expand with another demo, highlighting a little more flexibility:

Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  7. PAINT (320, 240), _RGB32(255, 0, 0)
  8. LOCATE 15, 35: PRINT "See the circle?"
  9.  
  10. PopUp = NewTextArea(200, 150, 400, 300, True)
  11. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  12. DrawTextArea PopUp
  13. PrintOut PopUp, "See how we popped up text in the box here, which has now overdrawn our circle?"
  14.  
  15. FOR x = 0 TO 100
  16.     _LIMIT 30
  17.     MoveFrame PopUp, 200 - x, 150 - x
  18. LOCATE 2, 2: PRINT "Notice how how even moving the frame doesn't harm the background?"
  19.  
  20.  
  21. '$include:'FrameLibrary.BM'
  22.  

Just like before, hit the space bar a few times and watch as we interact with our background, and pay attention to the simple fact that:

** We can MOVE the frames, and still not disturb the background as we do so!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #5 on: October 20, 2018, 01:43:07 AM »
Just a demo of the centering technique:
Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  7. PAINT (320, 240), _RGB32(255, 0, 0)
  8. LOCATE 15, 35: PRINT "See the circle?"
  9.  
  10.  
  11. PopUp = NewTextArea(200, 150, 400, 300, True)
  12. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  13. DrawTextArea PopUp
  14. SetPrintStyleX PopUp, CenterJustify
  15. SetTextColor PopUp, -1, 0
  16. PrintOut PopUp, "See how we popped up text in the box here, which has now overdrawn our circle?                AND...                Do you notice how with one command we can center each line automatically??"
  17.  
  18.  
  19.  
  20. '$include:'FrameLibrary.BM'
  21.  

SetPrintStyleX PopUp, CenterJustify --This one line centers all the text which pops out for us, in the frame.  Other options are LeftJustify, RightJustify, NoJustify
« Last Edit: October 21, 2018, 10:40:22 PM by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #6 on: October 20, 2018, 01:48:13 AM »
And to showcase another simple option:
Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  7. PAINT (320, 240), _RGB32(255, 0, 0)
  8. LOCATE 15, 35: PRINT "See the circle?"
  9.  
  10.  
  11. PopUp = NewTextArea(200, 150, 400, 300, True)
  12. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  13. DrawTextArea PopUp
  14. SetPrintStyleX PopUp, CenterJustify
  15. SetPrintStyleY PopUp, CenterLine
  16. SetTextColor PopUp, -1, 0
  17. PrintOut PopUp, "Perfectly centered!"
  18.  
  19.  
  20.  
  21. '$include:'FrameLibrary.BM'
  22.  

SetPrintStyleY PopUp, CenterLine  -- Notice that with the single addition of this one line of code, we're now perfectly centering our text inside the box vertically!  Other options here are OnLine, TopLine, BottomLine

OnLine says we print on the line where we left off, doing nothing special.
TopLine says we print from the top line of the frame.
BottomLine  says we print from the bottom line of the frame.

Simple enough!  ;)
« Last Edit: October 21, 2018, 10:41:29 PM by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #7 on: October 20, 2018, 02:04:51 AM »
And, one more option available for us:

Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3.  
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5.  
  6. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  7. PAINT (320, 240), _RGB32(255, 0, 0)
  8. LOCATE 15, 35: PRINT "See the circle?"
  9.  
  10.  
  11. PopUp = NewTextArea(200, 150, 400, 300, True)
  12. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  13. DrawTextArea PopUp
  14. SetTextColor PopUp, -1, 0
  15.  
  16.  
  17. PrintOut PopUp, "Now, watch as we count to 10, while fiddling with a few settings.  (Press <ANY KEY> to start."
  18. SetPrintUpdate PopUp, NewLine
  19. FOR i = 1 TO 10
  20.     PrintOut PopUp, STR$(i)
  21.     _DELAY .3
  22. PrintOut PopUp, "Did you notice the frame scroll the text as we counted??  Like we'd expect, huh?  Press <ANY KEY> to continue."
  23.  
  24. ClearTextArea PopUp
  25. SetPrintUpdate PopUp, NoNewLine
  26. FOR i = 1 TO 10
  27.     PrintOut PopUp, STR$(i)
  28.     _DELAY .3
  29. PrintOut PopUp, ".....  HEY?!!  What's up??  "
  30. PrintOut PopUp, "These lines aren't automatically printing to a new line?!!"
  31. '$include:'FrameLibrary.BM'
  32.  

What we're focusing on here are two commands in particular:

SetPrintUpdate PopUp, NewLine
SetPrintUpdate PopUp, NoNewLine

Our first command (above), is how we tell the library if we want to PRINT and then move to a new line afterwards, or if we want to stay on the same line, at the same position.  Think of it as the difference between PRINT text$ and PRINT text$; (see that semi-colon?)

ClearTextArea PopUp -- and our second command, which strangely enough, Clears the Text Area we specify.  NOTE:  This doesn't change our text printing position; it simply clears the frame for us.  To change the print position we use the almost-LOCATE command:  SetPrintPosition.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1064
  • Live long and prosper.
Re: Frame Library
« Reply #8 on: October 20, 2018, 02:13:45 AM »
Brilliant demos!  Cool....

:)
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1580
  • The best code is the DNA of the hops.
Re: Frame Library
« Reply #9 on: October 20, 2018, 03:32:53 AM »
Thank you for sharing this library. Wonderful is also the ability to share text fields in this way (as PopUp in your program) . That's what I'm using in the latest program I'm doing. But I have a lot of work ahead of me.

Offline Qwerkey

  • Forum Resident
  • Posts: 736
Re: Frame Library
« Reply #10 on: October 20, 2018, 05:55:50 AM »
Steve, marvellous as ever.  We expect nothing less.


Since we said, TRUE, when we hide the PopUp, the background is restored...

** These frames can hide/appear without disturbing existing text which we already have on the screen!

How does the computer know how to restore the background image when the frame is removed?  As I understand software images (I use the word "understand" without justification!), each time that a PRINT statement (or other graphics method) is used, the computer retains that image.  So when the frame is removed, you have to 'overwrite' it with the background (in your demo, this is the red circle - the CIRCLE and PAINT statements are used only once).  One of these days, Fellippe will place a ban on demonstrably stupid members (I'm in that sub-set)!  Richard

Offline Dav

  • Forum Resident
  • Posts: 639
Re: Frame Library
« Reply #11 on: October 20, 2018, 06:23:16 AM »
Cool Library!  Thanks for sharing.

- Dav

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1062
  • TOXIC
Re: Frame Library
« Reply #12 on: October 20, 2018, 07:42:43 AM »
Fun!

I'm sure the next edition will be able handle instances of CHR$(13) inside the printed text. As of now it shows up as a musical note and doesn't break the line. Specifically I tried this:

Code: QB64: [Select]
  1. PrintOut PopUp, "Perfectly center dsfadsfsdfdsfdfsdfd fdf dasf dsafdf dsf df" + CHR$(13) + "ed!"

EDIT (5 minutes later)

Ah, I see this issue can be hacked around by calling PrintOut more than once as the next demo does:
Code: QB64: [Select]
  1. FOR i = 1 TO 10
  2.     PrintOut PopUp, STR$(i)
  3.     _DELAY .3

« Last Edit: October 20, 2018, 07:45:53 AM by STxAxTIC »
TOXIC

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #13 on: October 20, 2018, 12:43:29 PM »
Fun!

I'm sure the next edition will be able handle instances of CHR$(13) inside the printed text. As of now it shows up as a musical note and doesn't break the line. Specifically I tried this:

Code: QB64: [Select]
  1. PrintOut PopUp, "Perfectly center dsfadsfsdfdsfdfsdfd fdf dasf dsafdf dsf df" + CHR$(13) + "ed!"

EDIT (5 minutes later)

Ah, I see this issue can be hacked around by calling PrintOut more than once as the next demo does:
Code: QB64: [Select]
  1. FOR i = 1 TO 10
  2.     PrintOut PopUp, STR$(i)
  3.     _DELAY .3

Aye.  I'd considered fixing it so CHR$(13) worked as a new line, but then decided against it.  What if you simply meant to print the little musical icon instead?  I figured this was something best handled by the user/program and not by library itself.

Easy solution though:  Write a SUB to handle the process for you, in your program.

SUB MultiPrintOut (frame, what$)
IF INSTR(what$, CHR$(13)) THEN
    PrintOut frame, LEFT$(what$, INSTR(what$, CHR$(13))
    SetPrintUpdate frame, NewLine 'Set the option to print to a new line
    PrintOut frame, "" 'Print that Linebreak
    SetPrintUpdate frame, NoNewLine 'Restore back to single line printing
    MultiPrintOut frame, MID$(what$, INSTR(what$, CHR$(13)+1)
ELSE
    PrintOut frame, what$
END IF
END SUB
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3572
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #14 on: October 20, 2018, 01:01:19 PM »
Steve, marvellous as ever.  We expect nothing less.


Since we said, TRUE, when we hide the PopUp, the background is restored...

** These frames can hide/appear without disturbing existing text which we already have on the screen!

How does the computer know how to restore the background image when the frame is removed?  As I understand software images (I use the word "understand" without justification!), each time that a PRINT statement (or other graphics method) is used, the computer retains that image.  So when the frame is removed, you have to 'overwrite' it with the background (in your demo, this is the red circle - the CIRCLE and PAINT statements are used only once).  One of these days, Fellippe will place a ban on demonstrably stupid members (I'm in that sub-set)!  Richard


Here's the trick, explained using strings, to make it easy to see.

Normally, if we replace the middle part of a string, we have no way to revert it back, afterwards.  For example:

a$ = "12345"
MID$(a$, 2) = "ABC"

IF we print a$, it now prints "1ABC5" -- and this is basically how drawing on the screen works.  Draw something and it just overwrites what was already there, replacing it forever, with no way to undo that.

So, how would we undo the process??

We intercept with a back up of what we're overwriting:

a$ = "12345"
temp$ = MID$(a$, 2, 3) 'store the "234"
MID$(a$, 2) = "ABC" 'do our replacement as we wanted before

.....  And, when we want to restore the original:
MID$(a$, 2) = temp$

*********************

And it's the exact same process with graphics.

Start with the old screen.
Take a screen grab of the section we want to write to with _NEWIMAGE and _PUTIMAGE.
Write to the section we want to.

....and, when done, use _Putimage to restore the image we saved! Then _FREEIMAGE that temp image.

**********************

And, this is the process the library does for us, all behind the scenes, of course.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!