Author Topic: Frame Library  (Read 13868 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Frame Library
« Reply #15 on: October 21, 2018, 05:00:50 am »

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.  ;)

That's what I imagined that you were doing (how else could it be done?), but I couldn't find a _SCREENIMAGE statement anywhere - and then take the relevant part of that image.  You must be doing it another way.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Frame Library
« Reply #16 on: October 21, 2018, 05:28:10 am »
Hi Qwerkey.

_SCREENIMAGE is of course not used. It uses NEWIMAGE by the area it wants to store, and then restores this backed area again via PUTIMAGE. It's the same way as when you copy only one area of  photo to a different screen. I think this is done by lines 81, 82, 83 and 84 in FrameLibrary.bm

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Frame Library
« Reply #17 on: October 21, 2018, 06:47:55 am »
Petr, I also found those lines in the Library.  When looking to see if the background was copied, I had first looked for _SCREENIMAGE, assuming that the background was already on screen.  But Steve uses the background image direct - wooly thinking on my part!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Frame Library
« Reply #18 on: October 21, 2018, 07:05:40 am »
Sorry. I look in it again, so Image is saved to array in line 348, 349  and copyed back before next print in line 371 is background restore from this array to screen.
« Last Edit: October 21, 2018, 07:11:53 am by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #19 on: October 21, 2018, 12:07:45 pm »
Library files updated to offer us one more option which we didn't have before:  FONTS.  (As long as they're monospaced fonts.  The word-wrap routine would need some work to play nice with non-monospaced fonts, and that's a chore for another day, as I found bigger fish to fry ATM.  :P

A demo of setting different monospaced fonts is below:

Code: QB64: [Select]
  1. '$INCLUDE:'FrameLibrary.BI'
  2.  
  3. Cyberbit = _LOADFONT("cyberbit.ttf", 24, "MONOSPACE")
  4.  
  5. SCREEN _NEWIMAGE(640, 480, 32)
  6.  
  7. CIRCLE (320, 240), 200, _RGB32(255, 0, 0)
  8. PAINT (320, 240), _RGB32(255, 0, 0)
  9. LOCATE 15, 35: PRINT "See the circle?"
  10.  
  11.  
  12. PopUp = NewTextArea(200, 150, 400, 300, True)
  13. ColorTextArea PopUp, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  14. DrawTextArea PopUp
  15. SetFont PopUp, 8
  16. PrintOut PopUp, "See how we popped up text in the box here, which has now overdrawn our circle?"
  17.  
  18.  
  19. BottomFrame = NewTextArea(0, 400, 639, 479, True)
  20. ColorTextArea BottomFrame, _RGB32(255, 255, 255), _RGB32(0, 0, 128)
  21. DrawTextArea BottomFrame
  22. SetFont BottomFrame, Cyberbit
  23. PrintOut BottomFrame, "Testing a different font."
  24.  
  25.  
  26.  
  27. HideFrame PopUp
  28. LOCATE 2, 2: PRINT "Notice how we preserve the background when we hide/close the frame?"
  29.  
  30.  
  31. '$INCLUDE:'FrameLibrary.BM'

(New Library files replaced the old ones at the bottom of the first post so that folks who grab the files there will always have the newest version available.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Frame Library
« Reply #20 on: October 21, 2018, 04:10:49 pm »
Hi Steve
great tool this frame library !!!
Please adjourn the files that you have appended!
Using these files I got different error, while getting those from this link (HERE: http://qb64.freeforums.net/thread/46/text-frames ) they run fine. 
With the files that you have posted at the beginning of the thread I have got some trouble that I want to share with screenshots.

Thanks to read
demo_Handle_Error.jpg
* demo_Handle_Error.jpg (Filesize: 215.58 KB, Dimensions: 1298x723, Views: 410)
Demo Centering text with original library files.jpg
* Demo Centering text with original library files.jpg (Filesize: 233.14 KB, Dimensions: 1300x721, Views: 406)
demo_Handle_Error2.jpg
* demo_Handle_Error2.jpg (Filesize: 251.32 KB, Dimensions: 1336x724, Views: 379)
demo_newNameforSubRoutine.jpg
* demo_newNameforSubRoutine.jpg (Filesize: 215.18 KB, Dimensions: 1300x721, Views: 510)
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #21 on: October 21, 2018, 08:55:47 pm »
Aye.  It's as you noticed; I changed the routine name a little to make it less confusing.

SetPrintPoistionX became SetPrintStyleX, while SetPrintPositionY became SetPrintStyleY. 

SetPrintPosition works as a LOCATE for us, and I felt that SetPrintPositionX/Y was just asking for folks to get confused.  We aren't actually changing the X/Y coordinates, as much as we're changing the style of how we interact with those coordinates.

I was going to fix those demos to match, but noticed that the precompiler did weird things for us (as I described here: https://www.qb64.org/forum/index.php?topic=720.0 ), and since it's my little baby that I hijacked into QB64, I thought I'd drop everything and get right on it.  Others might not use $IF or $LET very often, but I find them invaluable tools for my work, so I certainly want them to work properly.

Good news though:  The precompiler has been fixed and its capabilities have even been expanded!!

Now, we can bypass the CONST issue I was talking about earlier with libraries by:

Code: QB64: [Select]
  1. $IF TRUEFALSE = UNDEFINED THEN
  2.     CONST TRUE = -1, FALSE = 0
  3.     $LET TRUEFALSE = TRUE

Appear once in a set of code and it executes, setting the CONST values.  Appear another 50 times, and all those are excluded from operation.  It's a good way around the library issue, and simply just adds more power/flexibility for people when writing their code.

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

I'll fix the examples later tonight, or tomorrow, to reflect the name change in the Subs.  Honestly, I didn't think anyone would notice the difference that fast!  You've got sharp eyes and the heart of a beta-tester!  Many thanks for trying everything out so diligently, Tempodibasic!  ;D
« Last Edit: October 21, 2018, 08:57:29 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Marked as best answer by SMcNeill on October 21, 2018, 07:48:03 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Frame Library
« Reply #22 on: October 21, 2018, 10:47:37 pm »
Demos corrected; they should all now run with the new library, which took a little tweaking to correct a bug introduced with the addition of Font ability.  (Frames didn't start with a default font, so unless you manually set one, they crapped out -- that's been fixed now.)

FrameLibrary.BM has been corrected and updated under the first post.  If you're going to use this library, grab the latest version of it and simply overwrite the old version.  FrameLibrary.BI hasn't changed since the second update, so if you've grabbed it already, you don't need to worry about replacing it.

Just a reminder:  If you don't get the latest FrameLibrary.BM, the demos aren't going to work, and you'll need to manually set a font for any frame which you want to print to, as I overlooked adding a default to the original upgrade.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!