Author Topic: Is there a way to print a permanent string at a specific location?  (Read 6480 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 FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Hi guys, it's been a while I don't visit this forum. What brings me today is this: can QB64 print a permanent string at a specific location in the box? Say, "THIS IS A DEMO" in the last line and no matter what, it will not be overwritten (not even by scroll)?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #1 on: February 12, 2022, 08:21:41 pm »
You can put one in the _Title "This is a Demo" and it wont change unless you change it.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #2 on: February 12, 2022, 08:36:34 pm »
Problem is, I am already using _TITLE for something else 😬 It would be perfect if I could use a string printed in bright white color, maybe flashing inside the box.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a way to print a permanent string at a specific location?
« Reply #3 on: February 12, 2022, 08:41:51 pm »
VIEW PRINT and VIEW SCREEN might be what you're looking for.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #4 on: February 12, 2022, 09:15:28 pm »
Yeah or just overlay an image after anything done on the screen.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #5 on: February 12, 2022, 11:12:32 pm »
Thanks for the suggestions, guys!

FellippeHeitor

  • Guest
Re: Is there a way to print a permanent string at a specific location?
« Reply #6 on: February 13, 2022, 07:14:09 am »
If it's a text-only app, you can set an ON TIMER that calls a Sub every x milliseconds and prints to the screen. Just be sure to store _defaultcolor, _backgroundcolor, csrlin and pos(0) so you can restore color and cursor position after you've done printing.

Alternatively, store only _defaultcolor and _backgroundcolor and use _printstring, so cursor position is restored automatically.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #7 on: February 13, 2022, 08:11:21 am »

That's introverted thinking (inside the box).  I always thought of you as an extrovert.
Or do you swing both ways ?

FellippeHeitor

  • Guest
Re: Is there a way to print a permanent string at a specific location?
« Reply #8 on: February 13, 2022, 08:13:00 am »
Come again?

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #9 on: February 13, 2022, 08:33:17 am »
Come again?
You missed the joke.... never mind.

Marked as best answer by FilipeEstima on February 16, 2022, 07:43:20 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a way to print a permanent string at a specific location?
« Reply #10 on: February 13, 2022, 08:36:06 am »
I dunno why people like to make things so complicated.  As I mentioned last night (but was already in bed and just browsing on my ipad and not about to post an example then), the simplest and easiest solution to this type of problem is with VIEW PRINT.

Code: QB64: [Select]
  1. 'Screen _NewImage(640, 480, 32)
  2.  
  3. Color 15 + 16 'blinking bringht white
  4. Locate 25, 1: Print "This text will always remain on the screen.";
  5. Color 15 'plain bright white text
  6.  
  7. For i = 1 To 30
  8.     Print i
  9.     Sleep
  10.  
  11.  

"What brings me today is this: can QB64 print a permanent string at a specific location in the box? Say, "THIS IS A DEMO" in the last line and no matter what, it will not be overwritten (not even by scroll)?"....  CHECK!

"It would be perfect if I could use a string printed in bright white color, maybe flashing inside the box"....    CHECK!

Is there anything that I'm missing here?  We're printing on the last line.  Scroll isn't affecting it.  We can do bright white color, and we can flash it in SCREEN 0.  We can do a CLS 2 and only clear the text area, without clearing the view port. 

Isn't a simple VIEW PRINT statement all that's needed in this case?  Or am I missing something?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Is there a way to print a permanent string at a specific location?
« Reply #11 on: February 13, 2022, 09:12:59 am »
I dunno why people like to make things so complicated.

It's a mystery.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a way to print a permanent string at a specific location?
« Reply #12 on: February 13, 2022, 09:51:17 am »
It's a mystery.

Sometimes I honestly feel like people like to over complicate things just to avoid those "Old Skool" commands, just to promote the "better, modern way" to do things.

It's like somebody asks, "What's two plus two?"

One guy answers, "Hold up two fingers on your left hand.  Hold up two fingers on your right hand.  Count them for your answer."

Then other folks come along and say, "OR...  Build a rocket.  Fly it 360 miles above the earth with a mirror on it.  Since light travels 180 miles per second, flash a light at the mirror and start a stopwatch.  When you see the light reflect off the mirror, stop the watch and it'll show your answer."

Sure, it works, but you have to be a rocket scientist to implement the solution!  😁
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there a way to print a permanent string at a specific location?
« Reply #13 on: February 13, 2022, 12:07:42 pm »
Aint that simple for graphics demo!
Code: QB64: [Select]
  1. _Title "Flash Demo test" 'b+ 2022-02-13   how complicated can it be?
  2. ' sample program to test FlashDemo
  3.  
  4. '_Title "Drawlandscape Parallax test" 'started 2019-03-27
  5. 'test if can get end of landscape level to start for big looping background
  6. '2019-03-27 a more gentle adjustment back to Mountain starting height for
  7. 'more seamless connect of back end to front
  8. '2019-03-27 start this file with parallax drawing test
  9.  
  10.  
  11. Screen _NewImage(800, 600, 32)
  12. _ScreenMove 100, 20
  13. Type parallaxType
  14.     handle As Long
  15.     rate As Single 'number of pixels per frame added to le (leading edge)
  16.     le As Single
  17. nLevels = 6
  18. Dim Shared para(1 To nLevels) As parallaxType
  19.  
  20. Dim Shared scape&
  21. LoadLandscape
  22. scapeWidth = _Width(para(1).handle)
  23. scapeHeight = _Height(para(1).handle)
  24.  
  25. ' flash Demo code added ===================================================================================
  26. On Timer(ft&, 2) flashDemo
  27. Timer(ft&) On
  28. ' flash Demo end of code added ============================================================================
  29.  
  30. '' Try Steve simple little ditty ===========================================================================
  31. 'Color 15 + 16 'blinking bringht white
  32. 'Locate 25, 1: Print "This text will always remain on the screen.";
  33. 'Color 15 'plain bright white text
  34.  
  35. 'View Print 1 To 24 ' doesn't seen to do anything ????
  36. '' ==========================================================================================================
  37.  
  38. While t < 6000
  39.     Cls
  40.     For i = 1 To nLevels
  41.         If para(i).le + 800 > scapeWidth Then
  42.             te = scapeWidth - para(i).le
  43.             _PutImage (0, 0)-(te, scapeHeight), para(i).handle, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
  44.             _PutImage (te, 0)-(800, scapeHeight), para(i).handle, 0, (0, 0)-(800 - te, scapeHeight)
  45.  
  46.         Else
  47.             _PutImage (0, 0)-(800, scapeHeight), para(i).handle, 0, (para(i).le, 0)-(para(i).le + 800, scapeHeight)
  48.         End If
  49.  
  50.         para(i).le = para(i).le - para(i).rate
  51.         If para(i).le < 0 Then para(i).le = scapeWidth
  52.     Next
  53.     t = t + 1
  54.     _Display
  55.     _Limit 120
  56.  
  57. Sub LoadLandscape
  58.     cur& = _Dest
  59.     xmax = 800 * 3.25: ymax = 600
  60.     hdl& = 1
  61.     para(hdl&).handle = _NewImage(xmax, ymax, 32)
  62.     _Dest para(hdl&).handle
  63.  
  64.     For i = 0 To ymax
  65.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  66.         Line (0, i)-(xmax, i)
  67.     Next
  68.     'the land
  69.     startH = ymax - 200
  70.     rr = 70: gg = 70: bb = 90
  71.     For mountain = 1 To nLevels
  72.         If mountain > 1 Then
  73.             para(mountain).handle = _NewImage(xmax, ymax, 32)
  74.             _Dest para(mountain).handle
  75.         End If
  76.         Xright = 0
  77.         y = startH
  78.         Color _RGB(rr, gg, bb)
  79.         While Xright < xmax - 50
  80.             ' upDown = local up / down over range, change along Y
  81.             ' range = how far up / down, along X
  82.             upDown = (Rnd * .8 - .4) * (mountain * .5)
  83.             range = Xright + rand%(15, 25) * 2.5 / mountain
  84.             If range > xmax - 50 Then range = xmax - 50
  85.             lastx = Xright - 1
  86.             For x = Xright To range 'need less flat tops
  87.                 test = y + upDown
  88.                 test2 = y - upDown
  89.                 If Abs(test - startH) < .13 * startH Then y = test Else y = test2: upDown = -upDown
  90.                 Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  91.                 lastx = x
  92.             Next
  93.             Xright = range
  94.         Wend
  95.         x = lastx + 1
  96.         dy = (startH - y) / 50 'more gentle adjustment back to start of screen
  97.         While x <= xmax
  98.             y = y + dy
  99.             Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  100.             lastx = x
  101.             x = x + 1
  102.         Wend
  103.         rr = rand%(rr - 15, rr): gg = rand%(gg - 15, gg): bb = rand%(bb - 25, bb)
  104.         If rr < 0 Then rr = 0
  105.         If gg < 0 Then gg = 0
  106.         If bb < 0 Then bb = 0
  107.         startH = startH + mountain * rand%(2, 10)
  108.         para(mountain).le = xmax - 800
  109.         para(mountain).rate = mountain * .5
  110.     Next
  111.     _Dest cur&
  112.  
  113. Function rand% (lo%, hi%)
  114.     rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
  115.  
  116. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  117.     Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  118.  
  119. Sub flashDemo
  120.     Static As Long beenHere, flash
  121.     If beenHere = 0 Then
  122.         flash = _NewImage(_Width, _Height, 32)
  123.         sd& = _Dest
  124.         _Dest flash
  125.         sf& = _Font
  126.         f& = _LoadFont("Arial.ttf", 64)
  127.         _Font f&
  128.         sc~& = _DefaultColor
  129.         sb~& = _BackgroundColor
  130.         Color &HFFFFFFFF, &H00000000
  131.         _PrintString ((_Width - _PrintWidth("This is a Demo.")) / 2, (_Height - _FontHeight(f&)) / 2), "This is a Demo."
  132.         _Dest sd&
  133.         _Font sf&
  134.         Color sc~&, sb~&
  135.         beenHere = -1
  136.     End If
  137.     snap = _NewImage(_Width, _Height, 32)
  138.     _PutImage , 0, snap
  139.     _PutImage , flash, 0
  140.     sa& = _AutoDisplay
  141.     _Display
  142.     _Delay .5
  143.     _PutImage , snap, 0
  144.     _Display
  145.     If sa& Then _AutoDisplay
  146.     _FreeImage snap
  147.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a way to print a permanent string at a specific location?
« Reply #14 on: February 13, 2022, 01:22:08 pm »
Aint that simple for graphics demo!

It is, unless you're trying to showcase rocket science as your demo!  :P

Code: QB64: [Select]
  1. Screen _NewImage(640, 480, 32)
  2.  
  3.  
  4. View Screen(0, 0)-(639, 460)
  5. View Print 30 To 30
  6.  
  7.  
  8. Print "This text stays at the bottom without being overwritten.";
  9.  
  10. changeX = 2: changeY = 2
  11.  
  12.     Cls 1, -1 'white background for the graphics screen
  13.     'moving red ball
  14.     x = x + changeX
  15.     y = y + changeY
  16.     For i = 1 To 25
  17.         Circle (x, y), i, &HFFFF0000 'red filled circle
  18.     Next
  19.     If x < 0 Or x > 640 Then changeX = -changeX
  20.     If y < 0 Or y > 480 Then changeY = -changeY
  21.     _Limit 60
  22.     _Display

Text on the bottom line, that doesn't get overwritten by the graphics being drawn on the screen!

If you look, I can still plot to (640,480) with absolutely no issues, but by making use of VIEW SCREEN, I've designated that only (0,0) to (640,460) are suitable for graphical rendering.  The bottom line of the screen is reserved for my text, which isn't affected at all by my graphics -- not even by the call to CLS the graphical screen! 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!