Author Topic: Scroll bars and resizable programs  (Read 4851 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: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Scroll bars and resizable programs
« on: September 17, 2019, 02:15:13 am »
I wrote this for a demo in a topic elsewhere, but I thought  I'd share it here so folks could find it in the future, if they ever wanted.

Code: QB64: [Select]
  1. DIM SHARED WorkScreen AS LONG, DisplayScreen AS LONG
  2.  
  3. WorkScreen = _NEWIMAGE(3600, 2400, 32) ' a nice large screen so we can scroll like crazy
  4. DisplayScreen = _NEWIMAGE(640, 480, 32) 'a nice small display screen
  5.  
  6. SCREEN DisplayScreen
  7. _DEST WorkScreen
  8. PRINT "Let's print all sorts of stuff on our workscreen, and make certain that it's more than long enough so that it'll scroll quite a ways across from the normal screen."
  9. LINE (400, 400)-(3000, 1200), &HFFFFFF00, BF
  10. FOR i = 1 TO 145
  11.     COLOR _RGB32(RND * 256, RND * 256, RND * 256), 0 'various colors for each line
  12.     PRINT "LINE #"; i; ".  This is just a bunch of junk for testing purposes only.  As you can see, if you want to read all the text from this line, you're going to have to scroll to see it all."
  13.  
  14.  
  15.  
  16.  
  17.  
  18. StartX = 0: StartY = 0: W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  19. _DEST DisplayScreen
  20.         temp = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
  21.         SCREEN temp
  22.         _FREEIMAGE DisplayScreen
  23.         DisplayScreen = temp
  24.         W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  25.         _DELAY .25
  26.         junk = _RESIZE 'clear the resize flag after manually setting the screen to the size we specified.
  27.     END IF
  28.     _LIMIT 30
  29.     CLS
  30.     PRINT StartX, StartY
  31.     ScrollBar StartX, 2
  32.     ScrollBar StartY, 1
  33.  
  34.     k = _KEYHIT
  35.     SELECT CASE k
  36.         CASE ASC("A"), ASC("a"): StartX = StartX - 10: IF StartX < 0 THEN StartX = 0
  37.         CASE ASC("S"), ASC("s"): StartY = StartY + 10: IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  38.         CASE ASC("D"), ASC("d"): StartX = StartX + 10: IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  39.         CASE ASC("W"), ASC("w"): StartY = StartY - 10: IF StartY < 0 THEN StartY = 0
  40.     END SELECT
  41.     _PUTIMAGE (0, 0)-(W - 20, H - 20), WorkScreen, DisplayScreen, (StartX, StartY)-STEP(W, H)
  42.     _DISPLAY
  43.  
  44.  
  45.  
  46.  
  47.  
  48. SUB ScrollBar (Start, Direction)
  49.     D = _DEST: _DEST DisplayScreen 'our scrollbars show on the display
  50.     Min = 0
  51.     MaxH = _HEIGHT(DisplayScreen)
  52.     MaxW = _WIDTH(DisplayScreen)
  53.     H = _HEIGHT(WorkScreen)
  54.     W = _WIDTH(WorkScreen)
  55.     IF Direction = 1 THEN 'up/down bar
  56.         Box MaxW - 20, 0, 20, MaxH - 20, &HFF777777, &HFFFFFFFF
  57.         Box MaxW - 19, Start / H * MaxH, 18, MaxH / H * MaxH - 20, &HFFFF0000, 0 'Red with transparent
  58.     ELSE 'left/right bar
  59.         Box Min, MaxH - 20, MaxW - 20, 20, &HFF777777, &HFFFFFFFF 'Gray with white border
  60.         Box Start / W * MaxW, MaxH - 19, MaxW / W * MaxW - 20, 18, &HFFFF0000, 0 'Red with transparent
  61.     END IF
  62.     _DEST D
  63.  
  64.  
  65. SUB Box (x, y, wide, high, kolor AS _UNSIGNED LONG, border AS _UNSIGNED LONG)
  66.     LINE (x, y)-STEP(wide, high), kolor, BF
  67.     LINE (x, y)-STEP(wide, high), border, B

EDIT:  Might aught to mention:  Use "WASD" keys to scroll the screen around.  :P
« Last Edit: September 17, 2019, 02:19:13 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Scroll bars and resizable programs
« Reply #1 on: September 19, 2019, 02:55:42 pm »
Nice job :)
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Scroll bars and resizable programs
« Reply #2 on: September 21, 2019, 07:32:41 pm »
I find it great!
More if you put away that light yellow as background coming out from the covered part of the text at position >390 for X and >120 for Y.
Thanks to share.
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: Scroll bars and resizable programs
« Reply #3 on: September 23, 2019, 04:00:15 pm »
Petr's and TempodiBasic's interest along with mine have been peaked, I think. I confess I was not particularly interested in a horizontal text scroller but having finished a pretty nice one, I am curious about doing text with a double scrollbar vertical and horizontal. Now Steve has sort of started that topic but also speaks of resizeable programs?? here https://www.qb64.org/forum/index.php?topic=1719.msg109557#msg109557
WTH resizeable programs??? I think he just tapped this section of code out of something bigger that makes more sense as a whole.

So I am wondering should we continue discussion here with the horizontal text conquered or should we move to Steve's thread and try and improve on his double scrollbars by connecting up mouse and normal keys arrows, home. end, pgUp, pgDn... mouse Clicks, mouse dragging, mouse wheel to the scrollers?

There is one other underlying issue to consider, the control of mouse and key inputs over the whole screen which might contain several scrollbars, mouse click or drag areas, say for buttons or lists or text boxes... going this far in thinking ahead, I see we have arrived at on InForm like GUI! (I arrived at this central mouse and key controller problem with Tiny Navigator trying to do 2 Lists to select from Files or Directories.) So now I wonder is it worth the time for working out double scrollbars for giant text which will likely mean a central controller for all mouse and key activity in order to actually use it in an app. ???

Now my head hurts ;-))

Well we are in the Discussion board, so let's continue discussion here if it pleases Petr and TempodiBasic and anyone else interested in this coding problem.

Give the demo a try and use your mouse to resize the window.  I cobbled this together just as a very quick little demo -- it wasn't actually part of anything else -- but I was trying to work out several other little things (such as setting up my camera and testing out recording for the new video tutorials), so I just cobbled the concept together really quickly.  (Which is why we use WASD keys to scroll, rather than arrow keys, since I didn't bother to lookup their actual values...)

If you guys want, I can take a few moments and swap over to arrow keys and add mouse support for a better demo.  This was really just a bare bones example to see if it was what might've been needed, and if it was, I would've expanded upon it better in a future post.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Marked as best answer by SMcNeill on September 23, 2019, 12:23:13 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Scroll bars and resizable programs
« Reply #4 on: September 23, 2019, 04:22:34 pm »
The scroll bar concept fleshed out a little better to highlight what I was trying to showcase:

Code: QB64: [Select]
  1. DIM SHARED WorkScreen AS LONG, DisplayScreen AS LONG
  2.  
  3. WorkScreen = _NEWIMAGE(3600, 2400, 32) ' a nice large screen so we can scroll like crazy
  4. DisplayScreen = _NEWIMAGE(640, 480, 32) 'a nice small display screen
  5.  
  6. SCREEN DisplayScreen
  7. _DEST WorkScreen
  8. PRINT "Let's print all sorts of stuff on our workscreen, and make certain that it's more than long enough so that it'll scroll quite a ways across from the normal screen."
  9. LINE (400, 400)-(3000, 1200), &HFFFFFF00, BF
  10. FOR i = 1 TO 145
  11.     COLOR _RGB32(RND * 256, RND * 256, RND * 256), 0 'various colors for each line
  12.     PRINT "LINE #"; i; ".  This is just a bunch of junk for testing purposes only.  As you can see, if you want to read all the text from this line, you're going to have to scroll to see it all."
  13.  
  14.  
  15.  
  16.  
  17.  
  18. StartX = 0: StartY = 0: W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  19. _DEST DisplayScreen
  20.         temp = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
  21.         SCREEN temp
  22.         _FREEIMAGE DisplayScreen
  23.         DisplayScreen = temp
  24.         W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  25.         _DELAY .25
  26.         junk = _RESIZE 'clear the resize flag after manually setting the screen to the size we specified.
  27.     END IF
  28.     _LIMIT 30
  29.     CLS
  30.     ScrollBar StartX, 2
  31.     ScrollBar StartY, 1
  32.  
  33.     k = _KEYHIT
  34.     SELECT CASE k
  35.         CASE ASC("A"), ASC("a"), 19200: StartX = StartX - 10: IF StartX < 0 THEN StartX = 0
  36.         CASE ASC("S"), ASC("s"), 20480: StartY = StartY + 10: IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  37.         CASE ASC("D"), ASC("d"), 19712: StartX = StartX + 10: IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  38.         CASE ASC("W"), ASC("w"), 18432: StartY = StartY - 10: IF StartY < 0 THEN StartY = 0
  39.     END SELECT
  40.         IF _MOUSEX > W - 21 AND _MOUSEY < H - 20 THEN 'We're on a up/down scroll bar
  41.             StartY = _MOUSEY / _HEIGHT(DisplayScreen) * _HEIGHT(WorkScreen)
  42.             IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  43.         END IF
  44.         IF _MOUSEY > H - 21 AND _MOUSEX < W - 20 THEN 'we're on the left/right scroll bar
  45.             StartX = _MOUSEX / _WIDTH(DisplayScreen) * _WIDTH(WorkScreen)
  46.             IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  47.         END IF
  48.     END IF
  49.  
  50.     _PUTIMAGE (0, 0)-(W - 20, H - 20), WorkScreen, DisplayScreen, (StartX, StartY)-STEP(W, H)
  51.     _DISPLAY
  52.  
  53.  
  54.  
  55.  
  56.  
  57. SUB ScrollBar (Start, Direction)
  58.     D = _DEST: _DEST DisplayScreen 'our scrollbars show on the display
  59.     Min = 0
  60.     MaxH = _HEIGHT(DisplayScreen)
  61.     MaxW = _WIDTH(DisplayScreen)
  62.     H = _HEIGHT(WorkScreen)
  63.     W = _WIDTH(WorkScreen)
  64.     IF Direction = 1 THEN 'up/down bar
  65.         Box MaxW - 20, 0, 20, MaxH - 20, &HFF777777, &HFFFFFFFF
  66.         Box MaxW - 19, Start / H * MaxH, 18, MaxH / H * MaxH - 20, &HFFFF0000, 0 'Red with transparent
  67.     ELSE 'left/right bar
  68.         Box Min, MaxH - 20, MaxW - 20, 20, &HFF777777, &HFFFFFFFF 'Gray with white border
  69.         Box Start / W * MaxW, MaxH - 19, MaxW / W * MaxW - 20, 18, &HFFFF0000, 0 'Red with transparent
  70.     END IF
  71.     _DEST D
  72.  
  73.  
  74. SUB Box (x, y, wide, high, kolor AS _UNSIGNED LONG, border AS _UNSIGNED LONG)
  75.     LINE (x, y)-STEP(wide, high), kolor, BF
  76.     LINE (x, y)-STEP(wide, high), border, B
  77.  

Use arrows (or WASD) to scroll the screen, or press the mousebutton down over the scroll bar and see it in action.  Then grab the corner of the screen and resize it, and watch how the scroll bars automatically resize to fit the new dimensions and continue to work as you'd expect them to.

Resizeable program -- Check!
Scroll bars for it -- Check!

As the title says, "Scroll bars and resizable programs".  We do both things in this little demo.  (And now we also do arrow keys and mouse support!)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Scroll bars and resizable programs
« Reply #5 on: September 23, 2019, 05:13:40 pm »
Hi Steve
here my experience with your example
https://www.qb64.org/forum/index.php?topic=1718.msg109612#msg109612
and here added to your last code....
use pageUp, PageDown , arrows left & right & Up & Down, rolling wheel for vertical scrolling, left click to scroll to left of 1 step, right click to scroll to left of 1 step.

Scroll bars working well, resizing black square work less only on the external borders.

Code: QB64: [Select]
  1. DIM SHARED WorkScreen AS LONG, DisplayScreen AS LONG
  2.  
  3. WorkScreen = _NEWIMAGE(3600, 2400, 32) ' a nice large screen so we can scroll like crazy
  4. DisplayScreen = _NEWIMAGE(640, 480, 32) 'a nice small display screen
  5.  
  6. SCREEN DisplayScreen
  7. _DEST WorkScreen
  8. PRINT "Let's print all sorts of stuff on our workscreen, and make certain that it's more than long enough so that it'll scroll quite a ways across from the normal screen."
  9. LINE (400, 400)-(3000, 1200), &HFFFFFF00, BF
  10. FOR i = 1 TO 145
  11.     COLOR _RGB32(RND * 256, RND * 256, RND * 256), 0 'various colors for each line
  12.     PRINT "LINE #"; i; ".  This is just a bunch of junk for testing purposes only.  As you can see, if you want to read all the text from this line, you're going to have to scroll to see it all."
  13.  
  14.  
  15.  
  16.  
  17.  
  18. StartX = 0: StartY = 0: W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  19. _DEST DisplayScreen
  20.         temp = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
  21.         SCREEN temp
  22.         _FREEIMAGE DisplayScreen
  23.         DisplayScreen = temp
  24.         W = _WIDTH(DisplayScreen): H = _HEIGHT(DisplayScreen)
  25.         _DELAY .25
  26.         junk = _RESIZE 'clear the resize flag after manually setting the screen to the size we specified.
  27.     END IF
  28.     _LIMIT 30
  29.     CLS
  30.     ScrollBar StartX, 2
  31.     ScrollBar StartY, 1
  32.  
  33.     k = _KEYHIT
  34.         IF _MOUSEBUTTON(1) THEN k = ASC("A")
  35.         IF _MOUSEBUTTON(2) THEN k = ASC("d")
  36.         IF _MOUSEWHEEL < 0 THEN k = ASC("w") ELSE IF _MOUSEWHEEL > 0 THEN k = ASC("s")
  37.     WEND
  38.     SELECT CASE k
  39.         CASE ASC("A"), ASC("a"), 19200: StartX = StartX - 10: IF StartX < 0 THEN StartX = 0
  40.         CASE ASC("S"), ASC("s"), 20480: StartY = StartY + 10: IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  41.         CASE ASC("D"), ASC("d"), 19712: StartX = StartX + 10: IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  42.         CASE ASC("W"), ASC("w"), 18432: StartY = StartY - 10: IF StartY < 0 THEN StartY = 0
  43.         CASE 18688: StartY = StartY - 20: IF StartY < 0 THEN StartY = 0 'page up
  44.         CASE 20736: StartY = StartY + 20: IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H ' page down
  45.     END SELECT
  46.         IF _MOUSEX > W - 21 AND _MOUSEY < H - 20 THEN 'We're on a up/down scroll bar
  47.             StartY = _MOUSEY / _HEIGHT(DisplayScreen) * _HEIGHT(WorkScreen)
  48.             IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  49.         END IF
  50.         IF _MOUSEY > H - 21 AND _MOUSEX < W - 20 THEN 'we're on the left/right scroll bar
  51.             StartX = _MOUSEX / _WIDTH(DisplayScreen) * _WIDTH(WorkScreen)
  52.             IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  53.         END IF
  54.     END IF
  55.  
  56.     _PUTIMAGE (0, 0)-(W - 20, H - 20), WorkScreen, DisplayScreen, (StartX, StartY)-STEP(W, H)
  57.     _DISPLAY
  58.  
  59.  
  60.  
  61.  
  62.  
  63. SUB ScrollBar (Start, Direction)
  64.     D = _DEST: _DEST DisplayScreen 'our scrollbars show on the display
  65.     Min = 0
  66.     MaxH = _HEIGHT(DisplayScreen)
  67.     MaxW = _WIDTH(DisplayScreen)
  68.     H = _HEIGHT(WorkScreen)
  69.     W = _WIDTH(WorkScreen)
  70.     IF Direction = 1 THEN 'up/down bar
  71.         Box MaxW - 20, 0, 20, MaxH - 20, &HFF777777, &HFFFFFFFF
  72.         Box MaxW - 19, Start / H * MaxH, 18, MaxH / H * MaxH - 20, &HFFFF0000, 0 'Red with transparent
  73.     ELSE 'left/right bar
  74.         Box Min, MaxH - 20, MaxW - 20, 20, &HFF777777, &HFFFFFFFF 'Gray with white border
  75.         Box Start / W * MaxW, MaxH - 19, MaxW / W * MaxW - 20, 18, &HFFFF0000, 0 'Red with transparent
  76.     END IF
  77.     _DEST D
  78.  
  79.  
  80. SUB Box (x, y, wide, high, kolor AS _UNSIGNED LONG, border AS _UNSIGNED LONG)
  81.     LINE (x, y)-STEP(wide, high), kolor, BF
  82.     LINE (x, y)-STEP(wide, high), border, B
  83.  
  84.  

here image
 
Scrolling2 Steve.jpg
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: Scroll bars and resizable programs
« Reply #6 on: September 23, 2019, 05:17:24 pm »
Quote
Scroll bars working well, resizing black square work less only on the external borders.

The black square in the bottom right does nothing.  Click and hold one of the edges of the screen (any edge), and resize the screen however you want, just like you would any other window.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Scroll bars and resizable programs
« Reply #7 on: September 24, 2019, 07:03:43 am »
Interesting.

Useful in a program where you want to display instructions for use, for example.

My question is: is it possible to have more than 145 lines?

Why not yes ?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Scroll bars and resizable programs
« Reply #8 on: September 24, 2019, 07:34:14 am »
Interesting.

Useful in a program where you want to display instructions for use, for example.

My question is: is it possible to have more than 145 lines?

Sure.  Just change the size of the WorkScreen to whatever will suit your needs.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Scroll bars and resizable programs
« Reply #9 on: September 24, 2019, 09:51:24 am »

Number of lines needed:  for instance 2600

2600 *16.55= 43030

Replacing:
WorkScreen = _NEWIMAGE(3600, 2400, 32)
with
WorkScreen = _NEWIMAGE(3600, 43030, 32)
and it works. Fine !
Why not yes ?