QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Erum on September 16, 2019, 03:28:05 pm

Title: Scroll Bar
Post by: Erum on September 16, 2019, 03:28:05 pm
Respected QB64 team,
I have created a software on QB64 that will analyse temperature and pH of soil and tell which plants can be grown there, along with conditions they need for a national science fair. (I used QB64 as I am a ninth grader and this software is easy to use.) Even though I managed to increase screen size but I need a scroll bar so all my data can fit neatly.
I also want to add colours, for example if I write like this:
English oak:
Water: ABC
Fertiliser:DEF
Distance:GHI  Temperature:XYZ and so on....
For this, I want the heading to be a different colour and each line to be a different colour. How can I do this?
P.S: I am not very advanced in all this but I am deeply interested to know. If any one can help me, I will be infinitely obliged.
Regards.
Title: Re: Scroll Bar
Post by: Petr on September 16, 2019, 05:16:09 pm
Maybe this help you. Use A/Z/Enter.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 256)
  2. DIM Text(20) AS STRING * 15
  3. FOR N = 0 TO 20
  4.     Text(N) = "Value: " + STR$(N)
  5.  
  6.  
  7. height = 5 'list to 5 rows
  8.  
  9.     i$ = UCASE$(INKEY$)
  10.     IF i$ = "A" THEN b = b - 1: ch = ch - 1
  11.     IF i$ = "Z" THEN b = b + 1: ch = ch + 1
  12.  
  13.     IF b > UBOUND(Text) THEN b = UBOUND(Text)
  14.     IF b < LBOUND(Text) THEN b = LBOUND(Text)
  15.     e = b + height '1 row height
  16.     IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - height
  17.     IF e < LBOUND(text) THEN e = LBOUND(Text)
  18.  
  19.     IF ch < LBOUND(text) THEN ch = LBOUND(text)
  20.     IF ch > UBOUND(text) THEN ch = UBOUND(text)
  21.  
  22.     R = 10 'list start on row 10
  23.     FOR scroll = b TO e
  24.         LOCATE R, 30: PRINT Text(scroll)
  25.         IF scroll = ch THEN LOCATE R, 5: PRINT "->" ELSE LOCATE R, 5: PRINT "  "
  26.         COLOR R, 0 'set foreground color    , 0 for background color (black)
  27.         R = R + 1
  28.     NEXT
  29.     IF i$ = CHR$(13) THEN PRINT "Choice:"; ch: END
  30.  

It just depends on how you organize the items in the text box. Color set using COLOR foreground, background. Be aware of the screen mode used. Use RGBA32 unsigned long colors for 32-bit displays and standard COLOR 0 to 255 for 8-bit displays. Also try _PRINTMODE _KEEPBACKGROUND and _PRINTMODE _FILLBACKGROUND.

I'm going to sleep, me look at your answer tomorrow.
Title: Re: Scroll Bar
Post by: Bert22306 on September 16, 2019, 05:20:44 pm
Welcome, Erum. I'm not sure if you are asking simply how to change the color of the type or of the background, or something more complicated. The code here creates initially a screen with dull white background, and types different lines with different colors on that screen.

Then, it creates separate background colors, for each line of type.

You can play around with the effects in many ways. But for example, when the pH comes out with a certain value, to can create an IF statement that sets the type or the background colors, to different values?

Code: [Select]
SCREEN _NEWIMAGE(120, 43, 0)
COLOR 7, 7
CLS
COLOR 0, 7
PRINT "This is black."
COLOR 4, 7
PRINT "This is red."
COLOR 1, 7
PRINT "This is blue."
COLOR 14, 7
PRINT "This is bright yellow."
PRINT
COLOR 15, 0
PRINT "This has bright white type over a black background."
COLOR 7, 0
PRINT "This has dull white type on a black bachground."
COLOR 1, 4
PRINT "This has blue type on a red background."
END
Title: Re: Scroll Bar
Post by: bplus on September 17, 2019, 12:02:51 am
Use mouse wheel to scroll through an array of colored strings::
Code: QB64: [Select]
  1. _TITLE "Colored Lines scroller" 'B+ 2019-09-17
  2. TYPE ColoredLines
  3.     s AS STRING
  4.     c AS INTEGER
  5.  
  6. DIM cl(1 TO 100) AS ColoredLines
  7.  
  8. 'This is just a quick fill of an array of strings with random colors
  9. 'to have something to show, insert your real text and colors into an array.
  10. FOR i = 1 TO 100
  11.     cl(i).c = INT(RND * 15) + 1
  12.     cl(i).s = "This is line number" + STR$(i)
  13.  
  14. show cl()
  15.  
  16.  
  17. SUB show (arr() AS ColoredLines)
  18.     DIM lb AS LONG, ub AS LONG, top AS LONG, i AS LONG, row AS LONG, prevrow AS LONG, n AS LONG
  19.     lb = LBOUND(arr): ub = UBOUND(arr)
  20.     IF ub - lb + 1 < 21 THEN top = ub ELSE top = lb + 19
  21.     CLS
  22.     COLOR 0, 15
  23.     PRINT "press any key to quit scroller..."
  24.     COLOR 15, 0
  25.     LOCATE 2, 1
  26.     FOR i = lb TO top
  27.         COLOR arr(i).c
  28.         PRINT arr(i).s
  29.     NEXT
  30.     DO
  31.         IF ub - lb + 1 > 20 THEN
  32.             DO WHILE _MOUSEINPUT
  33.                 IF row >= lb THEN row = row + _MOUSEWHEEL ELSE row = lb 'prevent under scrolling
  34.                 IF row > ub - 19 THEN row = ub - 19 'prevent over scrolling
  35.                 IF prevrow <> row THEN 'look for a change in row value
  36.                     IF row >= lb AND row <= ub - 19 THEN
  37.  
  38.                         CLS
  39.                         COLOR 0, 15: PRINT "press any key to quit scroller..."
  40.                         COLOR 15, 0
  41.                         LOCATE 2, 1
  42.                         FOR n = row TO row + 19
  43.                             COLOR arr(n).c
  44.                             PRINT arr(n).s
  45.                         NEXT
  46.                     END IF
  47.                 END IF
  48.                 prevrow = row 'store previous row value
  49.             LOOP
  50.         END IF
  51.     LOOP UNTIL INKEY$ > ""
  52.  
  53.  
Title: Re: Scroll Bar
Post by: bplus on September 17, 2019, 01:02:42 am
A mod of last reply:
Code: QB64: [Select]
  1. _TITLE "Colored Lines scroller Ink and Paper Mod" 'B+ 2019-09-17
  2. TYPE ColoredLines
  3.     s AS STRING
  4.     ink AS INTEGER
  5.     paper AS INTEGER
  6.  
  7. DIM cl(1 TO 100) AS ColoredLines
  8.  
  9. FOR i = 1 TO 100
  10.     cl(i).ink = INT(RND * 16)
  11.     r = INT(RND * 8)
  12.     WHILE r = cl(i).ink
  13.         r = INT(RND * 8)
  14.     WEND
  15.     cl(i).paper = r
  16.     cl(i).s = LEFT$("Line #" + STR$(i) + ", This is " + sayColor$(cl(i).ink) + " ink on " + sayColor$(cl(i).paper) + " paper." + SPACE$(_WIDTH), _WIDTH)
  17. show cl()
  18.  
  19. FUNCTION sayColor$ (n)
  20.     SELECT CASE n
  21.         CASE 0: sayColor$ = "Black"
  22.         CASE 1: sayColor$ = "Dark Blue"
  23.         CASE 2: sayColor$ = "Dark Green"
  24.         CASE 3: sayColor$ = "Dark Cyan"
  25.         CASE 4: sayColor$ = "Dark Red"
  26.         CASE 5: sayColor$ = "Dark Purple"
  27.         CASE 6: sayColor$ = "Dirty Dark Yellow"
  28.         CASE 7: sayColor$ = "Dark White"
  29.         CASE 8: sayColor$ = "Light Black"
  30.         CASE 9: sayColor$ = "Blue"
  31.         CASE 10: sayColor$ = "Green"
  32.         CASE 11: sayColor$ = "Cyan"
  33.         CASE 12: sayColor$ = "Red"
  34.         CASE 13: sayColor$ = "Purple"
  35.         CASE 14: sayColor$ = "Yellow"
  36.         CASE 15: sayColor$ = "White"
  37.     END SELECT
  38.  
  39. SUB show (arr() AS ColoredLines)
  40.     DIM lb AS LONG, ub AS LONG, top AS LONG, i AS LONG, row AS LONG, prevrow AS LONG, n AS LONG
  41.     lb = LBOUND(arr): ub = UBOUND(arr)
  42.     IF ub - lb + 1 < 21 THEN top = ub ELSE top = lb + 19
  43.     COLOR 15, 0
  44.     CLS
  45.     COLOR 0, 15
  46.     PRINT "press any key to quit scroller..."
  47.     COLOR 15, 0
  48.     LOCATE 2, 1
  49.     FOR i = lb TO top
  50.         COLOR arr(i).ink, arr(i).paper
  51.         PRINT arr(i).s
  52.     NEXT
  53.     DO
  54.         IF ub - lb + 1 > 20 THEN
  55.             DO WHILE _MOUSEINPUT
  56.                 IF row >= lb THEN row = row + _MOUSEWHEEL ELSE row = lb 'prevent under scrolling
  57.                 IF row > ub - 19 THEN row = ub - 19 'prevent over scrolling
  58.                 IF prevrow <> row THEN 'look for a change in row value
  59.                     IF row >= lb AND row <= ub - 19 THEN
  60.                         COLOR 15, 0
  61.                         CLS
  62.                         COLOR 0, 15: PRINT "press any key to quit scroller..."
  63.                         COLOR 15, 0
  64.                         LOCATE 2, 1
  65.                         FOR n = row TO row + 19
  66.                             COLOR arr(n).ink, arr(n).paper
  67.                             PRINT arr(n).s
  68.                         NEXT
  69.                     END IF
  70.                 END IF
  71.                 prevrow = row 'store previous row value
  72.             LOOP
  73.         END IF
  74.     LOOP UNTIL INKEY$ > ""
  75.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Scroll Bar
Post by: SMcNeill on September 17, 2019, 02:12:57 am
And here's a rather fancy example which does everything you mentioned, and more!

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
Title: Re: Scroll Bar
Post by: Erum on September 17, 2019, 07:09:30 am
Thank you all so much for the helpful and quick responses,
You all really helped me out. I will try each of the methods you mentioned and see which one works best for me.
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 08:04:14 am
very fine Steve
at start I was stucked, no mouse, no arrow then I read code and I found ASDW
and I got this

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

sorry Steve
I have added mouse (Left click to move left, right click to move right, upwheel to move up, downwheel to move down) and arrow keys

Code: QB64: [Select]
  1.     k = _KEYHIT
  2.         IF _MOUSEBUTTON(1) THEN k = ASC("A")
  3.         IF _MOUSEBUTTON(2) THEN k = ASC("d")
  4.         IF _MOUSEWHEEL < 0 THEN k = ASC("w") ELSE IF _MOUSEWHEEL > 0 THEN k = ASC("s")
  5.     WEND
  6.     SELECT CASE k
  7.         CASE ASC("A"), ASC("a"), 19200: StartX = StartX - 10: IF StartX < 0 THEN StartX = 0
  8.         CASE ASC("S"), ASC("s"), 20480: StartY = StartY + 10: IF StartY > _HEIGHT(WorkScreen) - H THEN StartY = _HEIGHT(WorkScreen) - H
  9.         CASE ASC("D"), ASC("d"), 19712: StartX = StartX + 10: IF StartX > _WIDTH(WorkScreen) - W THEN StartX = _WIDTH(WorkScreen) - W
  10.         CASE ASC("W"), ASC("w"), 18432: StartY = StartY - 10: IF StartY < 0 THEN StartY = 0
  11.     END SELECT
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 08:08:48 am
Hi Bplus
 do you like manage only mouse wheel into your example!

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
no keys no horizonthal scrolling... but so many colors!
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 08:18:21 am
Hi Petr

I find you idea very interesting but I need to make a question...

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

why do you choose to move cursor (pointer to item of list) when you reach the end of the list and not at first? I find more often this last behaviour of cursor.
Title: Re: Scroll Bar
Post by: bplus on September 20, 2019, 09:05:51 am
Hi Bplus
 do you like manage only mouse wheel into your example!

 (attachment=1,msg109613)
no keys no horizonthal scrolling... but so many colors!

Yes, just the mouse wheel for just displaying information, is what I like, who likes having to deal with horizontal scroll for reading a presentation?

Of course this is just a demo and all those colors and line numbers would be far too gaudy for a presentation of information. But color coding is a fine idea for the displaying of information and why I played off Bert22306's idea of testing fore and back colors to give a range of what is possible.
Title: Re: Scroll Bar
Post by: Petr on September 20, 2019, 11:30:31 am
Quote
TempodiBasic wrote:

why do you choose to move cursor (pointer to item of list) when you reach the end of the list and not at first? I find more often this last behaviour of cursor.


Hi Tempo, it was just a fast-paced program. Yeah you're right. You know what? I'll do the upgrade!
Title: Re: Scroll Bar
Post by: Petr on September 20, 2019, 12:50:22 pm
TempodiBasic,

Here it is. Notice the possibility of using the mouse wheel or a specific item with the mouse if you move the mouse into the item column. Keyboard control has been retained + added arrows, PgUp, PgDn, Home and End controls. The program has been redesigned as a function for better usability.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 256)
  2. DIM Text(20) AS STRING
  3. FOR N = 0 TO 20
  4.     Text(N) = "Value: " + STR$(N)
  5.  
  6.  
  7. height = 15 'list to 15 rows
  8. TXT_Lenght = 17
  9. XPosition = 30
  10. YPosition = 10
  11.  
  12.  
  13. DO UNTIL Value
  14.     Value = ScrollBar(Text(), XPosition, YPosition, TXT_Lenght, height)
  15. PRINT "Selected:"; Value
  16.  
  17.  
  18.  
  19. FUNCTION ScrollBar (Text() AS STRING, Xposition, Yposition, TXT_Lenght, Height)
  20.     SHARED e, b, ch
  21.     i$ = UCASE$(INKEY$)
  22.         mwh = _MOUSEWHEEL
  23.         ch = ch + mwh
  24.         IF mwh THEN EXIT WHILE
  25.  
  26.         Fx = _FONTWIDTH
  27.         Fy = _FONTHEIGHT
  28.         IF _MOUSEX >= Fx * Xposition AND _MOUSEX <= Fx * (Xposition + TXT_Lenght) THEN
  29.             IF _MOUSEY >= Fy * Yposition AND _MOUSEY <= Fy * (Yposition + Height) THEN
  30.                 IF mwh = 0 THEN
  31.                     ch = b + _CEIL((_MOUSEY - (Yposition * Fy)) / Fy)
  32.                 END IF
  33.             END IF
  34.         END IF
  35.         IF _MOUSEBUTTON(1) THEN i$ = CHR$(13)
  36.     WEND
  37.  
  38.     IF i$ = "A" OR i$ = CHR$(0) + CHR$(72) THEN ch = ch - 1 '+Up
  39.     IF i$ = "Z" OR i$ = CHR$(0) + CHR$(80) THEN ch = ch + 1 '+Dn
  40.     IF i$ = CHR$(0) + CHR$(73) THEN ch = ch - Height 'PgUP
  41.     IF i$ = CHR$(0) + CHR$(81) THEN ch = ch + Height 'PgDN
  42.     IF i$ = CHR$(0) + CHR$(71) THEN ch = LBOUND(text) 'HOME
  43.     IF i$ = CHR$(0) + CHR$(79) THEN ch = UBOUND(text) 'END
  44.  
  45.     IF ch > Height + b THEN b = b + 1: e = e + 1
  46.     IF ch < e - Height THEN b = b - 1: e = e - 1
  47.  
  48.  
  49.     IF b > UBOUND(Text) THEN b = UBOUND(Text)
  50.     IF b < LBOUND(Text) THEN b = LBOUND(Text)
  51.     e = b + Height
  52.     IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - Height
  53.     IF e < LBOUND(text) THEN e = LBOUND(Text)
  54.  
  55.     IF ch < LBOUND(text) THEN ch = LBOUND(text)
  56.     IF ch > UBOUND(text) THEN ch = UBOUND(text)
  57.  
  58.     R = Yposition
  59.     FOR scroll = b TO e
  60.         IF scroll = ch THEN bckc = 94 ELSE bckc = 0
  61.         COLOR R, bckc
  62.         IF LEN(Text(scroll)) > TXT_Lenght THEN t$ = LEFT$(Text(scroll), TXT_Lenght - 3) + "..." ELSE t$ = Text(scroll)
  63.         LOCATE R, Xposition: PRINT t$
  64.         R = R + 1
  65.     NEXT
  66.     IF i$ = CHR$(13) THEN ScrollBar = ch: EXIT FUNCTION
  67.  
Title: Re: Scroll Bar
Post by: bplus on September 20, 2019, 01:43:57 pm
Petr, that looks like great code for item selection from an array.

I would say perfect if it had easy method to color lines.
Title: Re: Scroll Bar
Post by: Petr on September 20, 2019, 02:58:17 pm
Hm, yes. This is solution for standard 2 colored scroll bar:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 256)
  2. DIM Text(20) AS STRING
  3. FOR N = 0 TO 20
  4.     Text(N) = "Value: " + STR$(N)
  5.  
  6.  
  7. height = 15 'list to 15 rows
  8. TXT_Lenght = 20
  9. XPosition = 10
  10. YPosition = 7
  11.  
  12.  
  13.  
  14. Value = ScrollBar(Text(), XPosition, YPosition, TXT_Lenght, height, 99, 127)
  15. PRINT "Selected:"; Value
  16.  
  17.  
  18.  
  19. FUNCTION ScrollBar (Text() AS STRING, Xposition, Yposition, TXT_Lenght, Height, ForegroundColor~&, BackgroundColor~&)
  20.     DO UNTIL ScrollBar
  21.         i$ = UCASE$(INKEY$)
  22.         WHILE _MOUSEINPUT
  23.             mwh = _MOUSEWHEEL
  24.             ch = ch + mwh
  25.             IF mwh THEN EXIT WHILE
  26.  
  27.             Fx = _FONTWIDTH
  28.             Fy = _FONTHEIGHT
  29.             IF _MOUSEX >= Fx * Xposition AND _MOUSEX <= Fx * (Xposition + TXT_Lenght) THEN
  30.                 IF _MOUSEY >= Fy * Yposition AND _MOUSEY <= Fy * (Yposition + Height) THEN
  31.                     IF mwh = 0 THEN
  32.                         ch = b + _CEIL((_MOUSEY - (Yposition * Fy)) / Fy)
  33.                     END IF
  34.                 END IF
  35.             END IF
  36.             IF _MOUSEBUTTON(1) THEN i$ = CHR$(13)
  37.         WEND
  38.  
  39.         IF i$ = "A" OR i$ = CHR$(0) + CHR$(72) THEN ch = ch - 1 '+Up
  40.         IF i$ = "Z" OR i$ = CHR$(0) + CHR$(80) THEN ch = ch + 1 '+Dn
  41.         IF i$ = CHR$(0) + CHR$(73) THEN ch = ch - Height 'PgUP
  42.         IF i$ = CHR$(0) + CHR$(81) THEN ch = ch + Height 'PgDN
  43.         IF i$ = CHR$(0) + CHR$(71) THEN ch = LBOUND(text) 'HOME
  44.         IF i$ = CHR$(0) + CHR$(79) THEN ch = UBOUND(text) 'END
  45.  
  46.         IF ch > Height + b THEN b = b + 1: e = e + 1
  47.         IF ch < e - Height THEN b = b - 1: e = e - 1
  48.  
  49.  
  50.         IF b > UBOUND(Text) THEN b = UBOUND(Text)
  51.         IF b < LBOUND(Text) THEN b = LBOUND(Text)
  52.         e = b + Height
  53.         IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - Height
  54.         IF e < LBOUND(text) THEN e = LBOUND(Text)
  55.  
  56.         IF ch < LBOUND(text) THEN ch = LBOUND(text)
  57.         IF ch > UBOUND(text) THEN ch = UBOUND(text)
  58.  
  59.         R = Yposition
  60.         FOR scroll = b TO e
  61.             IF scroll = ch THEN bckc~& = ForegroundColor~&: fore~& = BackgroundColor~& ELSE bckc~& = BackgroundColor~&: fore~& = ForegroundColor~&
  62.             COLOR fore~&, bckc~&
  63.             IF LEN(Text(scroll)) > TXT_Lenght THEN t$ = LEFT$(Text(scroll), TXT_Lenght - 3) + "..." ELSE t$ = Text(scroll)
  64.             t$ = t$ + SPACE$(TXT_Lenght - LEN(t$))
  65.             IF LEN(t$) > TXT_Lenght THEN t$ = LEFT$(t$, LEN(t$) - 3) + "..."
  66.             LOCATE R, Xposition: PRINT t$
  67.             R = R + 1
  68.         NEXT
  69.         IF i$ = CHR$(13) THEN ScrollBar = ch
  70.     LOOP
  71.  
  72.  
  73.  
  74.  
  75.  
Title: Re: Scroll Bar
Post by: bplus on September 20, 2019, 04:57:21 pm
Well I was thinking more like this:
Code: QB64: [Select]
  1.  
  2. TYPE ColoredLines
  3.     s AS STRING
  4.     ink AS INTEGER
  5.     paper AS INTEGER
  6.  
  7. BoxHeight = 15 'list to 15 rows
  8. TXT_Lenght = 60
  9. XPosition = 10
  10. YPosition = 7
  11.  
  12. DIM text(1 TO 100) AS ColoredLines
  13. FOR i = 1 TO 100
  14.     text(i).ink = INT((i - 1) / 10) + 1
  15.     text(i).paper = (text(i).ink + 7) MOD 8
  16.     text(i).s = LEFT$("Line #" + STR$(i) + ", This is " + sayColor$(text(i).ink) + " ink on " + sayColor$(text(i).paper) + " paper." + SPACE$(TXT_Lenght), TXT_Lenght)
  17.  
  18.  
  19. Value = ScrollBar(text(), XPosition, YPosition, TXT_Lenght, BoxHeight)
  20. COLOR 15, 0: LOCATE 2, 10: PRINT "Selected:"; Value
  21.  
  22. FUNCTION ScrollBar (Text() AS ColoredLines, Xposition, Yposition, TXT_Lenght, Height)
  23.     DO UNTIL ScrollBar
  24.         i$ = UCASE$(INKEY$)
  25.         WHILE _MOUSEINPUT
  26.             mwh = _MOUSEWHEEL
  27.             ch = ch + mwh
  28.             IF mwh THEN EXIT WHILE
  29.  
  30.             Fx = _FONTWIDTH
  31.             Fy = _FONTHEIGHT
  32.             IF _MOUSEX >= Fx * Xposition AND _MOUSEX <= Fx * (Xposition + TXT_Lenght) THEN
  33.                 IF _MOUSEY >= Fy * Yposition AND _MOUSEY <= Fy * (Yposition + Height) THEN
  34.                     IF mwh = 0 THEN
  35.                         ch = b + _CEIL((_MOUSEY - (Yposition * Fy)) / Fy)
  36.                     END IF
  37.                 END IF
  38.             END IF
  39.             IF _MOUSEBUTTON(1) THEN i$ = CHR$(13)
  40.         WEND
  41.  
  42.         IF i$ = "A" OR i$ = CHR$(0) + CHR$(72) THEN ch = ch - 1 '+Up
  43.         IF i$ = "Z" OR i$ = CHR$(0) + CHR$(80) THEN ch = ch + 1 '+Dn
  44.         IF i$ = CHR$(0) + CHR$(73) THEN ch = ch - Height 'PgUP
  45.         IF i$ = CHR$(0) + CHR$(81) THEN ch = ch + Height 'PgDN
  46.         IF i$ = CHR$(0) + CHR$(71) THEN ch = LBOUND(text) 'HOME
  47.         IF i$ = CHR$(0) + CHR$(79) THEN ch = UBOUND(text) 'END
  48.  
  49.         IF ch > Height + b THEN b = b + 1: e = e + 1
  50.         IF ch < e - Height THEN b = b - 1: e = e - 1
  51.  
  52.  
  53.         IF b > UBOUND(Text) THEN b = UBOUND(Text)
  54.         IF b < LBOUND(Text) THEN b = LBOUND(Text)
  55.         e = b + Height
  56.         IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - Height
  57.         IF e < LBOUND(text) THEN e = LBOUND(Text)
  58.  
  59.         IF ch < LBOUND(text) THEN ch = LBOUND(text)
  60.         IF ch > UBOUND(text) THEN ch = UBOUND(text)
  61.  
  62.         R = Yposition
  63.         FOR scroll = b TO e
  64.             IF scroll = ch THEN bckc~& = 15: fore~& = 0 ELSE bckc~& = Text(scroll).paper: fore~& = Text(scroll).ink
  65.             COLOR fore~&, bckc~&
  66.             'IF LEN(Text(scroll)) > TXT_Lenght THEN t$ = LEFT$(Text(scroll), TXT_Lenght - 3) + "..." ELSE t$ = Text(scroll)
  67.             't$ = t$ + SPACE$(TXT_Lenght - LEN(t$))
  68.             'IF LEN(t$) > TXT_Lenght THEN t$ = LEFT$(t$, LEN(t$) - 3) + "..."
  69.             LOCATE R, Xposition: PRINT Text(scroll).s
  70.             R = R + 1
  71.         NEXT
  72.         IF i$ = CHR$(13) THEN ScrollBar = ch
  73.     LOOP
  74.  
  75. FUNCTION sayColor$ (n)
  76.     SELECT CASE n
  77.         CASE 0: sayColor$ = "Black"
  78.         CASE 1: sayColor$ = "Dark Blue"
  79.         CASE 2: sayColor$ = "Dark Green"
  80.         CASE 3: sayColor$ = "Dark Cyan"
  81.         CASE 4: sayColor$ = "Dark Red"
  82.         CASE 5: sayColor$ = "Dark Purple"
  83.         CASE 6: sayColor$ = "Dirty Dark Yellow"
  84.         CASE 7: sayColor$ = "Dark White"
  85.         CASE 8: sayColor$ = "Light Black"
  86.         CASE 9: sayColor$ = "Blue"
  87.         CASE 10: sayColor$ = "Green"
  88.         CASE 11: sayColor$ = "Cyan"
  89.         CASE 12: sayColor$ = "Red"
  90.         CASE 13: sayColor$ = "Purple"
  91.         CASE 14: sayColor$ = "Yellow"
  92.         CASE 15: sayColor$ = "White"
  93.     END SELECT
  94.  
  95.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 05:52:35 pm
Hi Petr

I find your examples good

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

cool the combo of keys and mouse....

I got a glitch that I'm not able to recognize in the code! Doing different attempts I get nothing .

Scrolling by wheel of mouse works well when mouse's cursor is not in action on the scrollingbox.
When cursor of mouse is on the scrollingbox the wheel of mouse works only if user points on the first line of scrolling...
nothing happens if cursor of mouse points to another item of the list of scrolling...


Thanks for sharing
Title: Re: Scroll Bar
Post by: Petr on September 20, 2019, 06:02:11 pm
Hello. Yeah, the wheel only works outside the dump column, because if the mouse is in the dump column, it has priority to calculate the mouse position and thus determine the selection from the list. As for the colors (this is a note for BPlus), then I think it is enough to extend the text field with a flag and choose a color according to the flag. For example, when I return to the original topic, add the water temperature flag and set the text colors according to the water temperature... (or other)
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 06:09:06 pm
Hi Bplus

in this your mod of Petr function for scrolling  you have set off the selection/highlight by pointer of the item pointed by cursor of mouse.

I find in wiki this example of scrolling with wheel of mouse that works like your mod, you must add just color to screen output and the selection highlighting

Code: QB64: [Select]
  1.  
  2. 'Code by Ted Weissgerber
  3. DIM Array$(100)
  4. LINE INPUT "Enter a file name with 100 or more lines of text: ", file$
  5. OPEN file$ FOR INPUT AS #1
  6.   inputcount = inputcount + 1
  7.   LINE INPUT #1, Array$(inputcount)
  8.   IF inputcount = 100 THEN EXIT DO
  9. FOR n = 1 TO 21: PRINT Array$(n): NEXT
  10.     IF row >= 0 THEN row = row + _MOUSEWHEEL ELSE row = 0  'prevent under scrolling
  11.     IF row > inputcount - 20 THEN row = inputcount - 20    'prevent over scrolling
  12.     IF prevrow <> row THEN 'look for a change in row value
  13.       IF row > 0 AND row <= inputcount - 20 THEN
  14.         CLS: LOCATE 2, 1
  15.         FOR n = row TO row + 20
  16.           PRINT Array$(n)
  17.         NEXT
  18.       END IF
  19.     END IF
  20.     prevrow = row 'store previous row value
  21.   LOOP
  22. LOOP UNTIL INKEY$ > ""  
  23.  

you can find it here http://qb64.org/wiki/MOUSEWHEEL (http://qb64.org/wiki/MOUSEWHEEL)

Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 06:17:22 pm
Hi Petr
sorry for my bad communication

about this
Quote
Hello. Yeah, the wheel only works outside the dump column, because if the mouse is in the dump column, it has priority to calculate the mouse position and thus determine the selection from the list
mouse wheel works also when you point with mouse on the first item showed into the scrollingBox...
so if I point to item 1 and move mouseWheel  the item highlighted moves down until it is item 15, then scrolling again the items scroll down. Well now it says that as last item showed there is at the bottom item 18 and I point by cursor of mouse this last it will be highlighted, now if I move mousewheel up or down i get scrolling the item HighLighted, the same i get if i point by cursor of mouse the first item showed in the listbox. Oe exception is if I point by mouse cursor the item 20!
Thanks to read
Title: Re: Scroll Bar
Post by: Petr on September 20, 2019, 06:23:34 pm
Hi.

Yeah, the wheel only works outside the dump column, because if the mouse is in the dump column, it has priority to calculate the mouse position and thus determine the selection from the list. As for the colors (this is a note for BPlus), then I think it is enough to extend the text field with a flag and choose a color according to the flag. For example, when I return to the original topic, add the water temperature flag and set the text colors according to the water temperature... (or other)...


Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 256)
  2.  
  3.     Text AS STRING * 30
  4.     Water AS _UNSIGNED _BYTE
  5.  
  6.  
  7.  
  8. DIM Text(200) AS E
  9. FOR N = 0 TO 200
  10.     temperature = RND * 100
  11.     Text(N).Text = "Water temperature: " + STR$(temperature)
  12.     Text(N).Water = temperature
  13.  
  14.  
  15. height = 15 'list to 15 rows
  16. TXT_Lenght = 30
  17. XPosition = 10
  18. YPosition = 7
  19.  
  20.  
  21.  
  22. Value = ScrollBar(Text(), XPosition, YPosition, TXT_Lenght, height)
  23. PRINT "Selected:"; Value
  24.  
  25.  
  26.  
  27. FUNCTION ScrollBar (Text() AS E, Xposition, Yposition, TXT_Lenght, Height)
  28.     DO UNTIL ScrollBar
  29.         i$ = UCASE$(INKEY$)
  30.         WHILE _MOUSEINPUT
  31.             mwh = _MOUSEWHEEL
  32.             ch = ch + mwh
  33.             IF mwh THEN EXIT WHILE
  34.  
  35.             Fx = _FONTWIDTH
  36.             Fy = _FONTHEIGHT
  37.             IF _MOUSEX >= Fx * Xposition AND _MOUSEX <= Fx * (Xposition + TXT_Lenght) THEN
  38.                 IF _MOUSEY >= Fy * Yposition AND _MOUSEY <= Fy * (Yposition + Height) THEN
  39.                     IF mwh = 0 THEN
  40.                         ch = b + _CEIL((_MOUSEY - (Yposition * Fy)) / Fy)
  41.                     END IF
  42.                 END IF
  43.             END IF
  44.             IF _MOUSEBUTTON(1) THEN i$ = CHR$(13)
  45.         WEND
  46.  
  47.         IF i$ = "A" OR i$ = CHR$(0) + CHR$(72) THEN ch = ch - 1 '+Up
  48.         IF i$ = "Z" OR i$ = CHR$(0) + CHR$(80) THEN ch = ch + 1 '+Dn
  49.         IF i$ = CHR$(0) + CHR$(73) THEN ch = ch - Height 'PgUP
  50.         IF i$ = CHR$(0) + CHR$(81) THEN ch = ch + Height 'PgDN
  51.         IF i$ = CHR$(0) + CHR$(71) THEN ch = LBOUND(text) 'HOME
  52.         IF i$ = CHR$(0) + CHR$(79) THEN ch = UBOUND(text) 'END
  53.  
  54.         IF ch > Height + b THEN b = b + 1: e = e + 1
  55.         IF ch < e - Height THEN b = b - 1: e = e - 1
  56.  
  57.  
  58.         IF b > UBOUND(Text) THEN b = UBOUND(Text)
  59.         IF b < LBOUND(Text) THEN b = LBOUND(Text)
  60.         e = b + Height
  61.         IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - Height
  62.         IF e < LBOUND(text) THEN e = LBOUND(Text)
  63.  
  64.         IF ch < LBOUND(text) THEN ch = LBOUND(text)
  65.         IF ch > UBOUND(text) THEN ch = UBOUND(text)
  66.  
  67.         R = Yposition
  68.         BackgroundColor~& = 0
  69.  
  70.  
  71.         FOR scroll = b TO e
  72.             SELECT CASE Text(scroll).Water
  73.                 CASE 0 TO 20: ForegroundColor~& = 32
  74.                 CASE 20 TO 40: ForegroundColor~& = 52
  75.                 CASE 40 TO 60: ForegroundColor~& = 46
  76.                 CASE 60 TO 80: ForegroundColor~& = 36
  77.                 CASE IS > 80: ForegroundColor~& = 40
  78.             END SELECT
  79.  
  80.             IF scroll = ch THEN bckc~& = 9: fore~& = ForegroundColor~& ELSE bckc~& = BackgroundColor~&: fore~& = ForegroundColor~&
  81.             COLOR fore~&, bckc~&
  82.             IF LEN(Text(scroll).Text) > TXT_Lenght THEN t$ = LEFT$(Text(scroll).Text, TXT_Lenght - 3) + "..." ELSE t$ = Text(scroll).Text
  83.             t$ = t$ + SPACE$(TXT_Lenght - LEN(t$))
  84.             IF LEN(t$) > TXT_Lenght THEN t$ = LEFT$(t$, LEN(t$) - 3) + "..."
  85.             LOCATE R, Xposition: PRINT t$
  86.             R = R + 1
  87.         NEXT
  88.         IF i$ = CHR$(13) THEN ScrollBar = ch
  89.     LOOP
  90.  
Title: Re: Scroll Bar
Post by: TempodiBasic on September 20, 2019, 06:52:11 pm
Hi Petr
also this last code that you have posted shows on my Pc the same strange behaviour, but reading again your affirmation
Quote
Yeah, the wheel only works outside the dump column,
I can suppose that it is linked to the calculation of the position of the cursor of mouse  because it appears only if I point to the first row and the last row of ScrollingBox!
Title: Re: Scroll Bar
Post by: bplus on September 20, 2019, 07:52:14 pm
Hi Bplus

in this your mod of Petr function for scrolling  you have set off the selection/highlight by pointer of the item pointed by cursor of mouse.

I find in wiki this example of scrolling with wheel of mouse that works like your mod, you must add just color to screen output and the selection highlighting

Code: QB64: [Select]
  1.  
  2. 'Code by Ted Weissgerber
  3. DIM Array$(100)
  4. LINE INPUT "Enter a file name with 100 or more lines of text: ", file$
  5. OPEN file$ FOR INPUT AS #1
  6.   inputcount = inputcount + 1
  7.   LINE INPUT #1, Array$(inputcount)
  8.   IF inputcount = 100 THEN EXIT DO
  9. FOR n = 1 TO 21: PRINT Array$(n): NEXT
  10.     IF row >= 0 THEN row = row + _MOUSEWHEEL ELSE row = 0  'prevent under scrolling
  11.     IF row > inputcount - 20 THEN row = inputcount - 20    'prevent over scrolling
  12.     IF prevrow <> row THEN 'look for a change in row value
  13.       IF row > 0 AND row <= inputcount - 20 THEN
  14.         CLS: LOCATE 2, 1
  15.         FOR n = row TO row + 20
  16.           PRINT Array$(n)
  17.         NEXT
  18.       END IF
  19.     END IF
  20.     prevrow = row 'store previous row value
  21.   LOOP
  22. LOOP UNTIL INKEY$ > ""  
  23.  

you can find it here http://qb64.org/wiki/MOUSEWHEEL (http://qb64.org/wiki/MOUSEWHEEL)

Hi TempodiBasic,

Reply #15 IS a mod of Petr's code, I added the ColoredLine Type and SayColor function and modified the display part in Petr's. And the code I first posted could have come from a mod of the Wiki example by Ted for mouse wheel.
Title: Re: Scroll Bar
Post by: Petr on September 21, 2019, 03:18:40 am
Hi TempodiBasic. Here is a slightly modified version, which I think will clearly show why it behaves so in the previous version. Here is added condition IF _MOUSEBUTTON (1), which ensures that the recalculation of the selection position is done only after left-clicking. Therefore, in this version, the mouse wheel responds throughout the list column range:
See row 42, 44.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 256)
  2.  
  3.     Text AS STRING * 30
  4.     Water AS _UNSIGNED _BYTE
  5.  
  6.  
  7.  
  8. DIM Text(200) AS E
  9. FOR N = 0 TO 200
  10.     temperature = RND * 100
  11.     Text(N).Text = "Water temperature: " + STR$(temperature)
  12.     Text(N).Water = temperature
  13.  
  14.  
  15. height = 15 'list to 15 rows
  16. TXT_Lenght = 30
  17. XPosition = 10
  18. YPosition = 7
  19.  
  20.  
  21.  
  22. Value = ScrollBar(Text(), XPosition, YPosition, TXT_Lenght, height)
  23. PRINT "Selected:"; Value
  24.  
  25.  
  26.  
  27. FUNCTION ScrollBar (Text() AS E, Xposition, Yposition, TXT_Lenght, Height)
  28.     DO UNTIL DONE
  29.         i$ = UCASE$(INKEY$)
  30.         WHILE _MOUSEINPUT
  31.             mwh = _MOUSEWHEEL
  32.             ch = ch + mwh
  33.  
  34.  
  35.             Fx = _FONTWIDTH
  36.             Fy = _FONTHEIGHT
  37.             IF _MOUSEX >= Fx * Xposition AND _MOUSEX <= Fx * (Xposition + TXT_Lenght) THEN
  38.                 IF _MOUSEY >= Fy * Yposition AND _MOUSEY <= Fy * (Yposition + Height) THEN
  39.                     IF _MOUSEBUTTON(1) THEN '                                                                   THIS CONDITION
  40.                         ch = b + _CEIL((_MOUSEY - (Yposition * Fy)) / Fy)
  41.                     END IF '                                                                                     --------------
  42.                 END IF
  43.             END IF
  44.             IF _MOUSEBUTTON(1) THEN i$ = CHR$(13)
  45.         WEND
  46.  
  47.         IF i$ = "A" OR i$ = CHR$(0) + CHR$(72) THEN ch = ch - 1 '+Up
  48.         IF i$ = "Z" OR i$ = CHR$(0) + CHR$(80) THEN ch = ch + 1 '+Dn
  49.         IF i$ = CHR$(0) + CHR$(73) THEN ch = ch - Height 'PgUP
  50.         IF i$ = CHR$(0) + CHR$(81) THEN ch = ch + Height 'PgDN
  51.         IF i$ = CHR$(0) + CHR$(71) THEN ch = LBOUND(text) 'HOME
  52.         IF i$ = CHR$(0) + CHR$(79) THEN ch = UBOUND(text) 'END
  53.  
  54.         IF ch > Height + b THEN b = b + 1: e = e + 1
  55.         IF ch < e - Height THEN b = b - 1: e = e - 1
  56.  
  57.  
  58.         IF b > UBOUND(Text) THEN b = UBOUND(Text)
  59.         IF b < LBOUND(Text) THEN b = LBOUND(Text)
  60.         e = b + Height
  61.         IF e > UBOUND(Text) THEN e = UBOUND(Text): b = e - Height
  62.         IF e < LBOUND(text) THEN e = LBOUND(Text)
  63.  
  64.         IF ch < LBOUND(text) THEN ch = LBOUND(text)
  65.         IF ch > UBOUND(text) THEN ch = UBOUND(text)
  66.  
  67.         R = Yposition
  68.         BackgroundColor~& = 0
  69.  
  70.  
  71.         FOR Scroll = b TO e
  72.             SELECT CASE Text(Scroll).Water
  73.                 CASE 0 TO 20: ForegroundColor~& = 32
  74.                 CASE 20 TO 40: ForegroundColor~& = 52
  75.                 CASE 40 TO 60: ForegroundColor~& = 46
  76.                 CASE 60 TO 80: ForegroundColor~& = 36
  77.                 CASE IS > 80: ForegroundColor~& = 40
  78.             END SELECT
  79.  
  80.             IF Scroll = ch THEN bckc~& = 9: fore~& = ForegroundColor~& ELSE bckc~& = BackgroundColor~&: fore~& = ForegroundColor~&
  81.             COLOR fore~&, bckc~&
  82.             IF LEN(Text(Scroll).Text) > TXT_Lenght THEN t$ = LEFT$(Text(Scroll).Text, TXT_Lenght - 3) + "..." ELSE t$ = Text(Scroll).Text
  83.             t$ = t$ + SPACE$(TXT_Lenght - LEN(t$))
  84.             IF LEN(t$) > TXT_Lenght THEN t$ = LEFT$(t$, LEN(t$) - 3) + "..."
  85.             LOCATE R, Xposition: PRINT t$
  86.             R = R + 1
  87.         NEXT
  88.         IF i$ = CHR$(13) THEN ScrollBar = ch: DONE = 1
  89.     LOOP
  90.  
Title: Re: Scroll Bar
Post by: TempodiBasic on September 21, 2019, 06:33:10 am
Hi Petr
Yes I can affirm that this version has no conflict between pointer and wheel of mouse and
IMHO it is a great present to whom need a such performed task!

Thanks to share
Title: Re: Scroll Bar
Post by: Erum on September 21, 2019, 08:12:57 am
OK, I will make my question more clear.
You see, as I am a beginner with no special knowledge, my program is very basic with something like this:

CLS
myscreen$= _NEWIMAGE(1600, 800, 32)
SCREEN= myscreen$
INPUT "ENTER pH OF SOIL"; p
INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; T
IF p >= 1 AND p < 4.5 AND T > 113 AND T < 134 THEN
    PRINT "pH IS TOO LOW AND TEMPERATURE IS TOO HIGH. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p >= 1 AND p < 4.5 AND T < 32 THEN
    PRINT "BOTH pH AND TEMPERATURE ARE TOO LOW. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p > 8.4 AND p <= 14 AND T > 113 AND T <= 134 THEN
    PRINT "BOTH pH AND TEMPERATURE ARE TOO HIGH. CONTROL pH WITH ORGANIC MATTER ( PEAT MOSS), ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVERY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p > 8.4 AND p < 14 AND T < 32 THEN
    PRINT "pH IS TOO HIGH AND TEMPERATURE IS TOO LOW. CONTROL pH WITH ORAGNIC MATTER LIKE PEAT MOSS, ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVRY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p >= 4.5 AND p <= 8.4 AND T > 113 AND T < 134 THEN
    PRINT "TEMPERATURE IS TOO HIGH."
ELSEIF p >= 4.5 AND p <= 8.4 AND T < 32 THEN
    PRINT "TEMPERATURE IS TOO LOW."
ELSEIF p <= 14 AND p > 8.4 AND T >= 32 AND T <= 113 THEN
    PRINT "pH IS TOO HIGH. CONTROL IT USING HYDRATED LIMESTONE OR WOOD ASH. (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p >= 1 AND p < 4.5 AND T >= 32 AND T < 134 THEN
    PRINT "pH IS TOO LOW. CONTROL pH USING HYDRATED LIMETONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
ELSEIF p < 1 OR p > 14 AND T > 134 THEN
    PRINT "PLEASE ENTER VALID VALUES."
ELSEIF p >= 1 AND p <= 14 AND T > 134 THEN
    PRINT "ENTER VALID TEMPERATURE VALUE."
ELSEIF p < 1 OR p > 14 AND T <= 134 THEN
    PRINT "ENTER VALID pH VALUE."
ELSEIF T >= 32 AND T <= 50 AND p >= 4.5 AND p <= 5 THEN
    PRINT "PLANTS THAT WILL GROW BEST IN THESE CONDITIONS:"
    PRINT "1.ENGLISH OAK (TREE):"
    PRINT "WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS."
    PRINT "FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)"
    PRINT "DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0."
    PRINT "SUNLIGHT:HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
    PRINT
    PRINT "2.PAPER BIRCH (TREE):"
    PRINT "WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP."
    PRINT "FERTILIZER: USE 11-22-22 FERTILIZER ANNUALLY AND COVER SOIL WELL. WHEN MATURE, FERTILIZE ONLY WHEN DEFFIECENCY NOTED."
    PRINT "DISTANCE:PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4"
    PRINT "SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
    PRINT
    PRINT "3.AZALEAS (FLOWERS):"
    PRINT "WATER:4 GALLONS PER SQUARE METRE EVERY 2 WEEKS."
    PRINT "FERTILIZER:USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR."
    PRINT "DISTANCE:PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0."
    PRINT "SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%"
    PRINT
    PRINT "NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY."
    PRINT "NOTE 2:PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)"
    PRINT "NOTE 3:INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:"
    PRINT "COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN"
    PRINT "FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS"
    PRINT "KELP MEAL, HARDWOOD ASH, AND GREEN ORGANIC MATERIAL FOR POTASSIUM"

You see, I want to add colours to my program on each line that is printed (each line must have a different background and foreground colour). The colour statements on each line are not working when nested in if-then-else statements., so I want to ask if there is another way of doing this. Also, in some conditions, the amount of best suited plants is quite large, and they all are not fitting on the screen. For that, I need a scroll bar.
Hope you all clearly understand and will do an immense favour by helping me again.
Regards.
Title: Re: Scroll Bar
Post by: TempodiBasic on September 21, 2019, 08:21:50 am
Hi Bplus

you're showing complete Reference pages of your posts!
while I was thinking that I had found a third way to do scrolling in wiki page and to not appear to be mine that code I put as first line the author.
I need better glasses !

Title: Re: Scroll Bar
Post by: bplus on September 21, 2019, 09:28:15 am
Hi Erum,

You can CLS and control COLOR before each and every PRINT statement even when they are inside an IF block.

If you have a block of text to present that does not fit your screen then the little scroller I showed would work fine, you need to set up an array to hold the text, lets call it tempText$() how many lines? 50?

DIM tempText$(1 to 50)
tempText$(1) = "This is line #1 of tempText$()."
tempText$(2) = "This is second line to display."...
continue on to fill up tempText

another way is to put all the lines in DATA statements and READ the lines into tempText$()


Oh heck here is your code rewritten:
Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(800, 700, 32) ' <<<< 32 here means you are using RGB and aplha colors _RGB32(red , green, blue)
  3.  
  4. 'set color then CLS so entire background is same
  5. COLOR _RGB32(100, 100, 255), _RGB32(0, 0, 120) ' <<< light blueish ink on dark blue paper
  6. CLS 'so now entire background is dark blue paper
  7.  
  8. INPUT "ENTER pH OF SOIL"; p
  9. INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; T
  10.  
  11. IF p >= 1 AND p < 4.5 AND T > 113 AND T < 134 THEN
  12.     PRINT "pH IS TOO LOW AND TEMPERATURE IS TOO HIGH. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  13. ELSEIF p >= 1 AND p < 4.5 AND T < 32 THEN
  14.     PRINT "BOTH pH AND TEMPERATURE ARE TOO LOW. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  15. ELSEIF p > 8.4 AND p <= 14 AND T > 113 AND T <= 134 THEN
  16.     PRINT "BOTH pH AND TEMPERATURE ARE TOO HIGH. CONTROL pH WITH ORGANIC MATTER ( PEAT MOSS), ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVERY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  17. ELSEIF p > 8.4 AND p < 14 AND T < 32 THEN
  18.     PRINT "pH IS TOO HIGH AND TEMPERATURE IS TOO LOW. CONTROL pH WITH ORAGNIC MATTER LIKE PEAT MOSS, ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVRY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  19. ELSEIF p >= 4.5 AND p <= 8.4 AND T > 113 AND T < 134 THEN
  20.     PRINT "TEMPERATURE IS TOO HIGH."
  21. ELSEIF p >= 4.5 AND p <= 8.4 AND T < 32 THEN
  22.     PRINT "TEMPERATURE IS TOO LOW."
  23. ELSEIF p <= 14 AND p > 8.4 AND T >= 32 AND T <= 113 THEN
  24.     PRINT "pH IS TOO HIGH. CONTROL IT USING HYDRATED LIMESTONE OR WOOD ASH. (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  25. ELSEIF p >= 1 AND p < 4.5 AND T >= 32 AND T < 134 THEN
  26.     PRINT "pH IS TOO LOW. CONTROL pH USING HYDRATED LIMETONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  27. ELSEIF p < 1 OR p > 14 AND T > 134 THEN
  28.     PRINT "PLEASE ENTER VALID VALUES."
  29. ELSEIF p >= 1 AND p <= 14 AND T > 134 THEN
  30.     PRINT "ENTER VALID TEMPERATURE VALUE."
  31. ELSEIF p < 1 OR p > 14 AND T <= 134 THEN
  32.     PRINT "ENTER VALID pH VALUE."
  33. ELSEIF T >= 32 AND T <= 50 AND p >= 4.5 AND p <= 5 THEN
  34.     PRINT "PLANTS THAT WILL GROW BEST IN THESE CONDITIONS:"
  35.     COLOR _RGB32(255, 255, 255)
  36.     PRINT "1.ENGLISH OAK (TREE):"
  37.     PRINT "WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS."
  38.     PRINT "FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)"
  39.     PRINT "DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0."
  40.     PRINT "SUNLIGHT:HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  41.     PRINT
  42.     COLOR _RGB32(0, 180, 0)
  43.     PRINT "2.PAPER BIRCH (TREE):"
  44.     PRINT "WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP."
  45.     PRINT "FERTILIZER: USE 11-22-22 FERTILIZER ANNUALLY AND COVER SOIL WELL. WHEN MATURE, FERTILIZE ONLY WHEN DEFFIECENCY NOTED."
  46.     PRINT "DISTANCE:PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4"
  47.     PRINT "SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  48.     PRINT
  49.     COLOR _RGB32(255, 255, 0)
  50.     PRINT "3.AZALEAS (FLOWERS):"
  51.     PRINT "WATER:4 GALLONS PER SQUARE METRE EVERY 2 WEEKS."
  52.     PRINT "FERTILIZER:USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR."
  53.     PRINT "DISTANCE:PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0."
  54.     PRINT "SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%"
  55.     PRINT
  56.     COLOR _RGB32(200, 0, 100)
  57.     PRINT "NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY."
  58.     PRINT "NOTE 2:PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)"
  59.     PRINT "NOTE 3:INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:"
  60.     PRINT "COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN"
  61.     PRINT "FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS"
  62.     PRINT "KELP MEAL, HARDWOOD ASH, AND GREEN ORGANIC MATERIAL FOR POTASSIUM"
  63.  
  64.  

To do scrolling = display of more that a screen worth of information, will take 'special knowledge' over and above basic CLS and COLOR statements because you will need mouse functions and arrays to hold text.

But if you could limit all info pages to one screen size or less, you could offer a menu to each page and then come back to main menu to allow selection of another page. All the commands you would need are CLS, COLOR, PRINT, and INPUT, you could use an IF THEN ELSEIF ENDIF block or SELECT CASE block. Maybe just your level of coding.
Title: Re: Scroll Bar
Post by: Erum on September 21, 2019, 10:20:55 am
Respected bplus,
Could you please tell me the code for just a scroll bar? That would be a big help. I would do a detailed study on that code later.
Regards.
Title: Re: Scroll Bar
Post by: TempodiBasic on September 21, 2019, 10:33:16 am
Hi Erum
about your issue I think you have so many to evaluate and then to adapt to your specific goal.

Quote
' Today more than yesterday programming is problem solving so
' a good programmer is a good problem solver that speaks some programming languages
so before write QB64code  you must plan the structure of the program, you must define the items or the objects of the program and how they interact among themselves or what is their behaviour, just after this  you can think how to translate all these things into a programming language (just QB64 here). IMHO only the translation depends about how you know of that language and tips for that language.

Here my little feedback about your piece of code:
IF data to show are a mess maybe that you can manage well the data to show using files. So , if you need, you can change also the data without rewrite the program! (see Bplus suggestions!)

you can build a SUB that works following your needs for printing using PRINT or _PRINTSTRING plus COLOR to set background (paper) and foreground (ink)
Bplus and Steve have made many example in the forum! Search and get solutions!

here  my mod for  more readably (I hope so ):
Code: QB64: [Select]
  1. ' Bplus suggestion
  2. SCREEN _NEWIMAGE(1600, 800, 32) ' <<<< 32 here means you are using RGB and aplha colors _RGB32(red , green, blue)
  3.  
  4. 'set color then CLS so entire background is same
  5. COLOR _RGB32(100, 100, 255), _RGB32(0, 0, 120) ' <<< light blueish ink on dark blue paper
  6. CLS 'so now entire background is dark blue paper
  7.  
  8. ' input data
  9. INPUT "ENTER pH OF SOIL"; p
  10. INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; T
  11.  
  12. 'reducing the forest     TDB
  13. ' IF you use NESTED if..then..else..end if
  14. ' and not CHAINED if..then..else..end if
  15. ' the code can be more readable for humans :-)
  16. ' Today more than yesterday programming is problem solving so
  17. ' a good programmer is a good problem solver that speaks some programming languages
  18.  
  19. 'analizer  of input and giver of output
  20. IF p >= 1 AND p < 4.5 THEN
  21.     'p >= 1 AND p < 4.5 AND <-- seems the same
  22.     IF T > 113 AND T < 134 THEN
  23.         PRINT "pH IS TOO LOW AND TEMPERATURE IS TOO HIGH. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  24.     ELSEIF T < 32 THEN
  25.         PRINT "BOTH pH AND TEMPERATURE ARE TOO LOW. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  26.     ELSEIF T >= 32 AND T < 134 THEN
  27.         PRINT "pH IS TOO LOW. CONTROL pH USING HYDRATED LIMETONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  28.     END IF
  29.     '    IF p >= 1 AND p < 4.5 AND is the same condition of previous IF
  30. ELSEIF p > 8.4 AND p <= 14 THEN
  31.     'IF p > 8.4 AND p < 14 AND <-- seems the same
  32.     ' p <= 14 AND p > 8.4 AND  <-- seems the same
  33.     IF T > 113 AND T <= 134 THEN
  34.         PRINT "BOTH pH AND TEMPERATURE ARE TOO HIGH. CONTROL pH WITH ORGANIC MATTER ( PEAT MOSS), ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVERY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  35.     ELSEIF T < 32 THEN
  36.         PRINT "pH IS TOO HIGH AND TEMPERATURE IS TOO LOW. CONTROL pH WITH ORAGNIC MATTER LIKE PEAT MOSS, ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVRY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  37.     ELSEIF T >= 32 AND T <= 113 THEN
  38.         PRINT "pH IS TOO HIGH. CONTROL IT USING HYDRATED LIMESTONE OR WOOD ASH. (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  39.     END IF
  40. ELSEIF p >= 4.5 AND p <= 8.4 THEN
  41.     'p >= 4.5 AND p <= 8.4 AND  <-- seems the same
  42.     IF T > 113 AND T < 134 THEN
  43.         PRINT "TEMPERATURE IS TOO HIGH."
  44.     ELSEIF T < 32 THEN
  45.         PRINT "TEMPERATURE IS TOO LOW."
  46.     END IF
  47.     'ELSEIF p < 1 OR p > 14 AND T > 134 THEN   <-- redundant
  48.     '    PRINT "PLEASE ENTER VALID VALUES."    <-- redundant
  49. ELSEIF T > 134 THEN
  50.     PRINT "ENTER VALID TEMPERATURE VALUE."
  51. ELSEIF p < 1 OR p > 14 THEN
  52.     PRINT "ENTER VALID pH VALUE."
  53. ELSEIF T >= 32 AND T <= 50 AND p >= 4.5 AND p <= 5 THEN ' this appears to be a subrange of the last range
  54.     PRINT "PLANTS THAT WILL GROW BEST IN THESE CONDITIONS:"
  55.     PRINT "1.ENGLISH OAK (TREE):"
  56.     PRINT "WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS."
  57.     PRINT "FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)"
  58.     PRINT "DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0."
  59.     PRINT "SUNLIGHT:HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  60.     PRINT
  61.     PRINT "2.PAPER BIRCH (TREE):"
  62.     PRINT "WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP."
  63.     PRINT "FERTILIZER: USE 11-22-22 FERTILIZER ANNUALLY AND COVER SOIL WELL. WHEN MATURE, FERTILIZE ONLY WHEN DEFFIECENCY NOTED."
  64.     PRINT "DISTANCE:PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4"
  65.     PRINT "SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  66.     PRINT
  67.     PRINT "3.AZALEAS (FLOWERS):"
  68.     PRINT "WATER:4 GALLONS PER SQUARE METRE EVERY 2 WEEKS."
  69.     PRINT "FERTILIZER:USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR."
  70.     PRINT "DISTANCE:PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0."
  71.     PRINT "SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%"
  72.     PRINT
  73.     PRINT "NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY."
  74.     PRINT "NOTE 2:PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)"
  75.     PRINT "NOTE 3:INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:"
  76.     PRINT "COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN"
  77.     PRINT "FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS"
  78.     PRINT "KELP MEAL, HARDWOOD ASH, AND GREEN ORGANIC MATERIAL FOR POTASSIUM"

For scrolling
you must load all strings to scroll into an array and pass it to the SUB/Function of scrolling!
Good Luck
Title: Re: Scroll Bar
Post by: bplus on September 21, 2019, 10:39:23 am
Respected bplus,
Could you please tell me the code for just a scroll bar? That would be a big help. I would do a detailed study on that code later.
Regards.

Steve posted code that uses actual scroll bars but I suspect it is way over your head, for some strange reason he does not use normal arrow keys, pg keys... and mouse wheel?

As TempodiBasic said,
Quote
For scrolling
you must load all strings to scroll into an array and pass it to the SUB/Function of scrolling!
Good Luck

Here is menu made from your code you might be able to understand, that sort of does what you want:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 700, 32) ' <<<< 32 here means you are using RGB and aplha colors _RGB32(red , green, blue)
  2.  
  3.     'set color then CLS so entire background is same
  4.     COLOR _RGB32(200, 200, 255), _RGB32(0, 0, 120) ' <<< light blueish ink on dark blue paper
  5.     CLS 'so now entire background is dark blue paper
  6.  
  7.     _KEYCLEAR ' need to clear last key press  so first input is not skipped
  8.  
  9.  
  10.     INPUT "ENTER pH OF SOIL"; p
  11.     INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; T
  12.  
  13.     IF p >= 1 AND p < 4.5 AND T > 113 AND T < 134 THEN
  14.         PRINT "pH IS TOO LOW AND TEMPERATURE IS TOO HIGH. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  15.         PRINT: PRINT "Press any to continue... ": SLEEP
  16.     ELSEIF p >= 1 AND p < 4.5 AND T < 32 THEN
  17.         PRINT "BOTH pH AND TEMPERATURE ARE TOO LOW. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  18.         PRINT: PRINT "Press any to continue... ": SLEEP
  19.     ELSEIF p > 8.4 AND p <= 14 AND T > 113 AND T <= 134 THEN
  20.         PRINT "BOTH pH AND TEMPERATURE ARE TOO HIGH. CONTROL pH WITH ORGANIC MATTER ( PEAT MOSS), ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVERY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  21.         PRINT: PRINT "Press any to continue... ": SLEEP
  22.     ELSEIF p > 8.4 AND p < 14 AND T < 32 THEN
  23.         PRINT "pH IS TOO HIGH AND TEMPERATURE IS TOO LOW. CONTROL pH WITH ORAGNIC MATTER LIKE PEAT MOSS, ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVRY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  24.         PRINT: PRINT "Press any to continue... ": SLEEP
  25.     ELSEIF p >= 4.5 AND p <= 8.4 AND T > 113 AND T < 134 THEN
  26.         PRINT "TEMPERATURE IS TOO HIGH."
  27.         PRINT: PRINT "Press any to continue... ": SLEEP
  28.     ELSEIF p >= 4.5 AND p <= 8.4 AND T < 32 THEN
  29.         PRINT "TEMPERATURE IS TOO LOW."
  30.         PRINT: PRINT "Press any to continue... ": SLEEP
  31.     ELSEIF p <= 14 AND p > 8.4 AND T >= 32 AND T <= 113 THEN
  32.         PRINT "pH IS TOO HIGH. CONTROL IT USING HYDRATED LIMESTONE OR WOOD ASH. (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  33.         PRINT: PRINT "Press any to continue... ": SLEEP
  34.     ELSEIF p >= 1 AND p < 4.5 AND T >= 32 AND T < 134 THEN
  35.         PRINT "pH IS TOO LOW. CONTROL pH USING HYDRATED LIMETONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  36.         PRINT: PRINT "Press any to continue... ": SLEEP
  37.     ELSEIF p < 1 OR p > 14 AND T > 134 THEN
  38.         PRINT "PLEASE ENTER VALID VALUES."
  39.         PRINT: PRINT "Press any to continue... ": SLEEP
  40.     ELSEIF p >= 1 AND p <= 14 AND T > 134 THEN
  41.         PRINT "ENTER VALID TEMPERATURE VALUE."
  42.         PRINT: PRINT "Press any to continue... ": SLEEP
  43.     ELSEIF p < 1 OR p > 14 AND T <= 134 THEN
  44.         PRINT "ENTER VALID pH VALUE."
  45.         PRINT: PRINT "Press any to continue... ": SLEEP
  46.     ELSEIF T >= 32 AND T <= 50 AND p >= 4.5 AND p <= 5 THEN
  47.         DO
  48.             'set color then CLS so entire background is same
  49.             COLOR _RGB32(200, 200, 255), _RGB32(0, 0, 120)
  50.             CLS
  51.             PRINT "PLANTS THAT WILL GROW BEST IN THESE CONDITIONS:"
  52.             PRINT "Menu:"
  53.             PRINT "1 ENGLISH OAK (TREE):"
  54.             PRINT "2 PAPER BIRCH (TREE):"
  55.             PRINT "3 AZALEAS (FLOWERS):"
  56.             PRINT "4 More Notes"
  57.             PRINT "5 Quit Menu"
  58.             PRINT
  59.             INPUT "Please enter your number choice "; choice
  60.             SELECT CASE choice
  61.                 CASE 1
  62.                     'set color then CLS so entire background is same
  63.                     COLOR _RGB32(128, 64, 32), _RGB32(255, 200, 100)
  64.                     CLS
  65.                     PRINT
  66.                     PRINT "1.ENGLISH OAK (TREE):"
  67.                     PRINT "WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS."
  68.                     PRINT "FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)"
  69.                     PRINT "DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0."
  70.                     PRINT "SUNLIGHT:HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  71.                     PRINT
  72.                     PRINT "press any to continue... "
  73.                     SLEEP
  74.  
  75.                 CASE 2
  76.                     'set color then CLS so entire background is same
  77.                     COLOR _RGB32(0, 64, 0), _RGB32(100, 100, 255)
  78.                     CLS
  79.                     PRINT "2.PAPER BIRCH (TREE):"
  80.                     PRINT "WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP."
  81.                     PRINT "FERTILIZER: USE 11-22-22 FERTILIZER ANNUALLY AND COVER SOIL WELL. WHEN MATURE, FERTILIZE ONLY WHEN DEFFIECENCY NOTED."
  82.                     PRINT "DISTANCE:PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4"
  83.                     PRINT "SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  84.                     PRINT
  85.                     PRINT "press any to continue... "
  86.                     SLEEP
  87.  
  88.                 CASE 3
  89.                     'set color then CLS so entire background is same
  90.                     COLOR _RGB32(255, 255, 0), _RGB32(0, 0, 100)
  91.                     CLS
  92.                     PRINT "3.AZALEAS (FLOWERS):"
  93.                     PRINT "WATER:4 GALLONS PER SQUARE METRE EVERY 2 WEEKS."
  94.                     PRINT "FERTILIZER:USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR."
  95.                     PRINT "DISTANCE:PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0."
  96.                     PRINT "SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%"
  97.                     PRINT
  98.                     PRINT "press any to continue... "
  99.                     SLEEP
  100.  
  101.                 CASE 4
  102.                     'set color then CLS so entire background is same
  103.                     COLOR _RGB32(200, 200, 255), _RGB32(60, 0, 60)
  104.                     CLS
  105.                     PRINT "NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY."
  106.                     PRINT "NOTE 2:PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)"
  107.                     PRINT "NOTE 3:INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:"
  108.                     PRINT "COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN"
  109.                     PRINT "FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS"
  110.                     PRINT "KELP MEAL, HARDWOOD ASH, AND GREEN ORGANIC MATERIAL FOR POTASSIUM"
  111.                     PRINT
  112.                     PRINT "press any to continue... "
  113.                     SLEEP
  114.  
  115.             END SELECT
  116.  
  117.         LOOP UNTIL choice = 5
  118.     END IF
  119.  
Title: Re: Scroll Bar
Post by: Erum on September 21, 2019, 10:41:13 am
Respected TempodiBasic,
I know I am annoying all the experts like you with my dumbness ;) Thank you for that kind and enlightening reply. I guess that coding for scroll bar is going to take a bit of studying and research. Thanks.
Regards.
Title: Re: Scroll Bar
Post by: Erum on September 21, 2019, 10:45:36 am
Respected bplus,
Thank you for that reply. You did a great job helping a dummy like me, as I said Iam a ninth grader and the only BASIC I learnt was from the chapter 'basics of BASIC." ;) I completely understand the select case syntax and I think I might use that. Thanks again.
Regards.
Title: Re: Scroll Bar
Post by: bplus on September 21, 2019, 10:58:13 am
Hi Erum,

I have some advice on the inputs of pH and temperature:

If you handle all the issues of pH First! and then only INPUT temperature after the pH is in range, it might be easier to code and follow the code, instead of having to handle all possible cases of pH AND temperature together.

Just advice take it or leave it :)
Title: Re: Scroll Bar
Post by: Petr on September 21, 2019, 02:00:27 pm
Hi Erum. I try writing for you something tomorrow. I thing, something easy as is PRINT use, but with output to screen area which allow text shift up/down/left/right. Here is psedocode + image how i think it, if it is, what you need:

PseudoCode:

BoxPrint "This is very long text, which i need shifting in text area on the screen and which not allow edit this text. This is very long text, which i need shifting in text area on the screen and which not allow edit this text. This is very long text, which i need shifting in text area on the screen and which not allow edit this text."

and excepted output is something as on image:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

But as I say. I'll start with it tomorrow, because I'm going to a beer. Is Saturday night...

Is this, what you need? I can do it for you, also color tags can be inserted to this boxes, if you need it. Then it can be something as TextBox "/color 15/ This is white text /color 1/ and this is blue text" I ask you for proposal for this TextBox SUB before i start programming it.




Title: Re: Scroll Bar
Post by: bplus on September 21, 2019, 02:38:42 pm
Petr, what you propose would make an excellent tool for all of us. I don't know why Steve hadn't connected his scroll bars to mouse? or normal arrow and pg keys.

I have an array selector too but no scroll bar to it, it uses mouse over and mouse wheel with arrow keys and pg keys, home, end... you can even type the item number and enter to select but it is also pretty complex for Erum.

Even with scroll bar code made for him, Erum would have another problem, getting large amounts of text into an array or arrays, think I will look into that.
Title: Re: Scroll Bar
Post by: Erum on September 21, 2019, 02:51:22 pm
Respected Petr and bplus,
Thank you for showing concern and for constantly helping me.
For Petr: Yes I think text boxes can be used instead. I will try them once you provide the guidelines.
For bplus: I do think that these things can be complex, but Iam sure I can figure them out once I study them in detail. P.S. I am a ‘she’, not a ‘he’ ;)
Regards.
Title: Re: Scroll Bar
Post by: bplus on September 21, 2019, 07:05:34 pm
Hi Erum,

I like your can do attitude and politeness :)

I took your text blocks and pasted then into a normal .txt file using a \ to mark the titles of smaller text blocks.
Filename: "test file.txt"
Code: QB64: [Select]
  1. \1. ENGLISH OAK (TREE):
  2.      WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS.
  3. FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)
  4.   DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0.
  5.   SUNLIGHT: HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)
  6. \2. PAPER BIRCH (TREE):
  7.      WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP.
  8.   DISTANCE: PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4
  9.   SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)
  10. \3. AZALEAS (FLOWERS):
  11.      WATER: 4 GALLONS PER SQUARE METRE EVERY 2 WEEKS.
  12. FERTILIZER: USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR.
  13.   DISTANCE: PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0.
  14.   SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%
  15. \4. Notes:
  16.  NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY.
  17.  NOTE 2: PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)
  18.  NOTE 3: INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:
  19.          COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN
  20.          FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS
  21. \
  22.  

When you have huge amounts of text it is likely more convenient to edit in a txt editor.

Then I put together or made some tools for loading the text file contents into an array and then more tools for picking out the titled sections for displaying in Petr's text scroller or one of our scrollers.

Here is the test code for our simple little 4 text blocks:

Code: QB64: [Select]
  1. _TITLE "Tool(s) for loading an array from a text file" 'B+ started 2019-09-21
  2.  
  3. DIM txtFile$, nFlines, j, i
  4.  
  5. 'test loading whole file
  6. REDIM test$(1 TO 1)
  7. txtFile$ = "test file.txt"
  8. nFlines = fLineCnt(txtFile$, test$())
  9. 'IF nFLines THEN
  10. '    FOR i = 1 TO nFLines
  11. '        PRINT i; ", "; test$(i)
  12. '        IF (i + 1) MOD 10 = 0 THEN PRINT "press any to continue...": SLEEP: CLS
  13. '    NEXT
  14. 'END IF
  15.  
  16. 'test loading sections of the file into temp$
  17. FOR j = 1 TO 4 'test 4 titles that start with number.
  18.     REDIM temp$(1 TO 1)
  19.     loadTitle test$(), _TRIM$(STR$(j)) + ". ", temp$()
  20.     FOR i = LBOUND(temp$) TO UBOUND(temp$)
  21.         PRINT temp$(i)
  22.     NEXT
  23.     PRINT " end of text... press any to continue..."
  24.     SLEEP
  25. PRINT "Test is done."
  26.  
  27. ' This SUB searches the source array for \+first part of title$ farthest left of source() strings.
  28. ' If a matching string is found, this SUB loads the given dynamic arr() starting at 1 with title string
  29. ' and keeps loading strings until it hits another \ or reaches the end of the file.
  30. SUB loadTitle (source() AS STRING, title$, arr() AS STRING)
  31.     DIM i AS INTEGER
  32.     FOR i = LBOUND(source) TO UBOUND(source)
  33.         IF UCASE$(LEFT$(source$(i), LEN("\" + title$))) = UCASE$("\" + title$) THEN
  34.             REDIM arr(1 TO 1) AS STRING
  35.             arr(1) = MID$(source(i), 2)
  36.             WHILE i + 1 <= UBOUND(source)
  37.                 i = i + 1
  38.                 IF LEFT$(source(i), 1) = "\" THEN 'done
  39.                     EXIT SUB
  40.                 ELSE
  41.                     sAppend arr(), source(i)
  42.                 END IF
  43.             WEND
  44.             EXIT FOR
  45.         END IF
  46.     NEXT
  47.  
  48. 'append to the string array the string item
  49. SUB sAppend (arr() AS STRING, item AS STRING)
  50.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
  51.     arr(UBOUND(arr)) = item
  52.  
  53. ' This FUNCTION loads a file (using CR + LF between lines) contents into an base 1 array
  54. ' so the upper bound and line count match and returns the number of lines.
  55. ' Hence if 0 was returned the file was empty or not found. new 2019-09-21
  56. FUNCTION fLineCnt (txtFile$, arr() AS STRING)
  57.     DIM filecount%, b$
  58.     filecount% = 0
  59.     IF _FILEEXISTS(txtFile$) THEN
  60.         OPEN txtFile$ FOR BINARY AS #1
  61.         b$ = SPACE$(LOF(1))
  62.         GET #1, , b$
  63.         CLOSE #1
  64.         REDIM _PRESERVE arr(1 TO 1) AS STRING
  65.         Split b$, CHR$(13) + CHR$(10), arr()
  66.         filecount% = UBOUND(arr)
  67.     END IF
  68.     fLineCnt = filecount% 'this file returns the number of lines loaded, 0 means file did not exist
  69.  
  70. 'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
  71. 'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.  rev 2019-08-27
  72. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  73.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  74.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  75.     dpos = INSTR(curpos, SplitMeString, delim)
  76.     DO UNTIL dpos = 0
  77.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  78.         arrpos = arrpos + 1
  79.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  80.         curpos = dpos + LD
  81.         dpos = INSTR(curpos, SplitMeString, delim)
  82.     LOOP
  83.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  84.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  85.  

Summary:
Put the txt file in the same directory as the bas file. (And make sure under the RUN menu of IDE the Output EXE to Source Folder is bulleted.)

fLineCnt is a function, so it returns something, in this case the number of lines it loaded into the a dynamic string array you specify ie REDIM for Dynamic arrays (instead of DIM, Dynamic Arrays = Arrays you can change the size of, DIM arrays can't be resized so are called Static not Dynamic.)

Code: QB64: [Select]
  1. lineCount = fLineCnt("myLoadTxtFile.txt", myFileArr$())

if lineCnt = 0 you didn't get anything loaded, otherwise myFileArr$() is loaded with the contents of the txt file.



Now to get a titled section from myFileArr$():

Menus work off numbers so I used your numbers to mark the start of a text block, so once a number is chosen from menu that text block can be loaded into an array and if array is huge we can use a scroller to display the entire contents easily for user of your code.

To get an array ready for the scroller just make this call to sub, say 2 text block
REDIM tempTxt$(1 to1) ' setup container to hold the text block
LoadTitle myFileArr$(), "2. ", tempTxt$() 'this loads tempTxt$() array

now ready to display tempTxt$() in scroller!

Too much?




Title: Re: Scroll Bar
Post by: TempodiBasic on September 21, 2019, 07:13:39 pm
Hi Erum
glad to be useful
please focus your mind before on this
an attempt to analyze the issue that the program must solve.

structure of the program
what does your program?
as you have said in previous posts
1. it takes 2 parameters (pH and Temperature in FAHRENHEIT)
 2. it outputs informations as text on the screen on the basis of 2 parameters


moreover you should think that you manage
 3. the input from keyboard and/or mouse
 4. and the output to the screen
 5. and the storage of the informations (inner to the program or outer in files)
 6. and an interface for user (only text, an ASCII windowed, a graphic windowed)


going deeper
1. you need 2 variables for the 2 parameters... the type of variable used depens of type of data to get from keyboard.
see here for more infohttp://qb64.org/wiki/Variable_Types (http://qb64.org/wiki/Variable_Types)
From your code posted before I can think that pH has a range from 1 to 14 with decimal so in QB64 we can use single declared with ! suffix or none suffix, while for temperature there is a range from 32 or less to 134 , but you manage only integer, so you can use an integer variable declared with suffix %

2. in your code you share analysis of value pH and Temperature with Output to screen.
If you want a more flexible code it is useful to separate these two performances. So tomorrow you can modify only the part of program that you must adapt to new needs and not following the line of flow of the program in chained instructions.
  2.1
  you can make a grid of pH values and Temperature to manage the various cases... (if you do this on you code you can see that the
 case temperature T >= 32 AND T <= 113 is not managed in the range pH p > 8.4 AND p <= 14 so in this case your program
 stucks
 2.2 all strings for output must be loaded into an array of strings  (the string is text between 2 ") (array is a set of variables of the same type and with the same name and with an index to distinguish one from another one)  see here for more informations http://qb64.org/wiki/Arrays (http://qb64.org/wiki/Arrays)

3. input from keyboard
 3.1 you can use old INPUT (a semi editor of Qbasic) and you must control the values typed from user (as you do in your code)
 3.2 or the INKEY$ to accept only digit and . for get pH and temperature values
 3.3 or you can use the powerful _KEYHIT of QB64 at the same way of INKEY$ for your goal
 3.4 or you can use mouse (_MOUSEBUTTON(1) or _MOUSEBUTTON(2) or _MOUSEWHEEL) to set input for pH and Temperature
 3.5 or you can use mouse for interaction of user with a structured interface made in text or graphic mode

4. output to the screen
  4.1 choose the screen mode
        if it is good for you an interface  only text or window text based (ASCII screen) you can use SCREEN 0 and use 8 colors for
        paper color (background 0-7) and 31 ink colors (foreground 0-31, after 15 color is blinking)
        but if you prefer the graphic mode you can have so many graphic options to manage and use
  4.2 choose the interface that you must build it for using in your program see point 6 (for now you have used a line text interface)

5. storage of informations
   5.1  informations stored as strings into the program (the way that you have coded)
   5.2  informations stored as DATA into the program (blocks of DATA) see here for more info http://qb64.org/wiki/DATA (http://qb64.org/wiki/DATA)
   5.3  informations stored as TXT file that you load in the program in a set of variable of type of string called Array (OPEN FOR
          INPUT) see here for more info http://qb64.org/wiki/OPEN (http://qb64.org/wiki/OPEN). The real advantage to code in this way is that you can
          change or adapt the text editing the file with an editor of text from Notepad to OpenOffice Writer and you program gains
          adjourned informations without so many changes to the code.
6. an user interface
   6.1 a line text of interface (that you have coded)
   6.2 a text interface with prefixed space of screen for different actions
   6.3 a text ASCII interface with inputbox, button, listbox
   6.4 a graphic interface with inputbox, button, listbox

Good work and good luck

PS: all the answers that you have got until now is how to make a listbox in ASCII mode or in Graphic mode.
Wrong :-)  before the last Bplus 's post!


Title: Re: Scroll Bar
Post by: Erum on September 22, 2019, 05:37:48 am
Respected TempodiBasic and blpus,
Thnak you so much once again. I am gonna focus and try them and see which one works best.
Regards.
Title: Re: Scroll Bar
Post by: Petr on September 22, 2019, 01:16:57 pm
Hello. Does anyone know why my head hurts today? :) To the thread point. Here is the first version of the text shift in a long sentence. I will add two more things - color support, as promised, and the bottom bar for a quick shift. But I'm having trouble with the mousewheel. It doesn't work as swiftly as I want. Anyone want to look at it? Thanks.

Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(20) AS LONG
  21.  
  22. FOR t = 1 TO 20
  23.     test(t) = INITBOX(100 + 250 * RND, 30 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24.  
  25.  
  26.  
  27.     FOR p = 1 TO 20
  28.         PRINTBOX p
  29.     NEXT
  30.  
  31.  
  32. 'this is future "TextBox.BM"
  33.  
  34. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  35.     UTB = UBOUND(tba)
  36.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  37.     TBA(UTB + 1).X = X
  38.     TBA(UTB + 1).Y = Y
  39.     TBA(UTB + 1).L = BoxLenght
  40.     TBA(UTB + 1).T = Text
  41.     TBA(UTB + 1).B = 1
  42.     INITBOX = UTB + 1
  43.  
  44.  
  45. SUB PRINTBOX (nr AS LONG)
  46.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  47.     TextBoxArrow& = TBA(0).Arrow
  48.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  49.     B = TBA(nr).B
  50.     TextHeight = _FONTHEIGHT
  51.     X = TBA(nr).X
  52.     Y = TBA(nr).Y
  53.     BoxLenght = TBA(nr).L
  54.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  55.  
  56.     FOR h = 1 TO 10
  57.         DO WHILE _MOUSEINPUT
  58.             IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  59.                 IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  60.                     B = B + _MOUSEWHEEL
  61.                 END IF
  62.             END IF
  63.         LOOP
  64.     NEXT
  65.     '
  66.     MB1 = _MOUSEBUTTON(1)
  67.     MX = _MOUSEX
  68.     MY = _MOUSEY
  69.  
  70.  
  71.  
  72.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  73.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  74.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  75.  
  76.     IF TIMER < 1 THEN TBA(nr).D = 0
  77.  
  78.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  79.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  80.             IF TBA(nr).D < TIMER THEN
  81.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  82.                 IF MB1 THEN
  83.                     B = B + 1
  84.                 END IF
  85.                 TBA(nr).D = TIMER + .1
  86.             END IF
  87.         END IF
  88.     END IF
  89.  
  90.     IF MX >= X - 26 AND MX <= X - 15 THEN
  91.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  92.             IF TBA(nr).D < TIMER THEN
  93.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  94.                 IF MB1 THEN
  95.                     B = B - 1
  96.                 END IF
  97.                 TBA(nr).D = TIMER + .1
  98.             END IF
  99.         END IF
  100.     END IF
  101.     IF B < 1 THEN B = 1
  102.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  103.     TBA(nr).B = B
  104.     _PRINTSTRING (X, Y), T$
  105.  
  106.  
  107. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  108.     PutArrow& = _NEWIMAGE(12, 12, 32)
  109.     D = _DEST
  110.     _DEST PutArrow&
  111.     CLS
  112.     LINE (1, 4)-(6, 4) '  ------------     up
  113.     LINE (1, 8)-(6, 8) '  ------------     down
  114.     LINE (1, 4)-(1, 8) '  I                arrow back
  115.     LINE (6, 4)-(6, 1)
  116.     LINE (6, 8)-(6, 11)
  117.     LINE (6, 11)-(11, 6)
  118.     LINE (6, 1)-(11, 6)
  119.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  120.     _DEST D
  121. 'End of future "TextBox.BM"
  122.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Scroll Bar
Post by: Petr on September 22, 2019, 04:41:45 pm
Small upgrade for previous code. Tomorrow i aply colors, replace it to BI and BM for higher clearity and start second box which use shift up/down.

Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(10) AS LONG
  21.  
  22. FOR t = 1 TO 10
  23.     test(t) = INITBOX(100 + 250 * RND, 40 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24. Demo = INITBOX(150, 500, "This is small text", 9)
  25.  
  26.  
  27.  
  28.     FOR p = 1 TO 10
  29.         PRINTBOX p
  30.     NEXT
  31.     PRINTBOX Demo
  32.  
  33.     _DISPLAY
  34.  
  35. 'this is future "TextBox.BM"
  36.  
  37. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  38.     UTB = UBOUND(tba)
  39.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  40.     TBA(UTB + 1).X = X
  41.     TBA(UTB + 1).Y = Y
  42.     TBA(UTB + 1).L = BoxLenght
  43.     TBA(UTB + 1).T = Text
  44.     TBA(UTB + 1).B = 1
  45.     INITBOX = UTB + 1
  46.  
  47.  
  48. SUB PRINTBOX (nr AS LONG)
  49.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  50.     TextBoxArrow& = TBA(0).Arrow
  51.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  52.     B = TBA(nr).B
  53.     TextHeight = _FONTHEIGHT
  54.     X = TBA(nr).X
  55.     Y = TBA(nr).Y
  56.     BoxLenght = TBA(nr).L
  57.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  58.  
  59.     FOR h = 1 TO 10
  60.         DO WHILE _MOUSEINPUT
  61.             IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  62.                 IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  63.                     B = B + _MOUSEWHEEL
  64.                 END IF
  65.             END IF
  66.         LOOP
  67.     NEXT
  68.     '
  69.     MB1 = _MOUSEBUTTON(1)
  70.     MX = _MOUSEX
  71.     MY = _MOUSEY
  72.  
  73.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), &HFF000000, BF
  74.  
  75.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), , B
  76.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  77.  
  78.  
  79.     LL = ((B + TBA(nr).L) / LEN(TBA(nr).T)) * 100
  80.     Full = BoxLenght * _FONTWIDTH + 15
  81.     OnePercent = Full / 100
  82.     Actual = LL * OnePercent
  83.  
  84.     LINE (X + Actual, Y + TextHeight + 5)-(Actual + 10 + X, Y + 10 + TextHeight), , BF
  85.     IF MX >= X + Actual AND MX <= Actual + 10 + X THEN
  86.         IF MY >= Y + TextHeight + 5 AND MY <= Y + 10 + TextHeight THEN
  87.             IF MB1 THEN
  88.                 omx = MX
  89.                 DO UNTIL _MOUSEX <> MX
  90.                     WHILE _MOUSEINPUT: WEND
  91.                     MB1 = _MOUSEBUTTON(1)
  92.                     B = B + _MOUSEX - omx
  93.                 LOOP
  94.             END IF
  95.         END IF
  96.     END IF
  97.  
  98.  
  99.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  100.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  101.  
  102.     IF TIMER < 1 THEN TBA(nr).D = 0
  103.  
  104.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  105.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  106.             IF TBA(nr).D < TIMER THEN
  107.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  108.                 IF MB1 THEN
  109.                     B = B + 1
  110.                 END IF
  111.                 TBA(nr).D = TIMER + .01
  112.             END IF
  113.         END IF
  114.     END IF
  115.  
  116.     IF MX >= X - 26 AND MX <= X - 15 THEN
  117.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  118.             IF TBA(nr).D < TIMER THEN
  119.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  120.                 IF MB1 THEN
  121.                     B = B - 1
  122.                 END IF
  123.                 TBA(nr).D = TIMER + .01
  124.             END IF
  125.         END IF
  126.     END IF
  127.     IF B < 1 THEN B = 1
  128.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  129.     TBA(nr).B = B
  130.     'here will be add color block (and next sub, which calculate text lenght without color flags and other one, which return text string without color flags)
  131.     'future use: V = INITBOX (1, 1, "&HFFFFFFWhite text is here,&HFFFF0000and red text is here", 10)    --  or can be done as "/RED/ This is RED text /WHITE/ and this is white text" with Steve's color constants.
  132.  
  133.     _PRINTSTRING (X, Y), T$
  134.  
  135.  
  136. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  137.     PutArrow& = _NEWIMAGE(12, 12, 32)
  138.     D = _DEST
  139.     _DEST PutArrow&
  140.     CLS
  141.     LINE (1, 4)-(6, 4) '  ------------     up
  142.     LINE (1, 8)-(6, 8) '  ------------     down
  143.     LINE (1, 4)-(1, 8) '  I                arrow back
  144.     LINE (6, 4)-(6, 1)
  145.     LINE (6, 8)-(6, 11)
  146.     LINE (6, 11)-(11, 6)
  147.     LINE (6, 1)-(11, 6)
  148.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  149.     _DEST D
  150. 'End of future "TextBox.BM"
  151.  
Title: Re: Scroll Bar
Post by: TempodiBasic on September 22, 2019, 06:23:16 pm
Hi Petr

I think to have a fix for _mousewheel 
here code
Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(20) AS LONG
  21.  
  22. FOR t = 1 TO 20
  23.     test(t) = INITBOX(100 + 250 * RND, 30 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24.  
  25.  
  26.  
  27.     FOR p = 1 TO 20
  28.         PRINTBOX p
  29.     NEXT
  30.  
  31.  
  32. 'this is future "TextBox.BM"
  33.  
  34. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  35.     UTB = UBOUND(tba)
  36.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  37.     TBA(UTB + 1).X = X
  38.     TBA(UTB + 1).Y = Y
  39.     TBA(UTB + 1).L = BoxLenght
  40.     TBA(UTB + 1).T = Text
  41.     TBA(UTB + 1).B = 1
  42.     INITBOX = UTB + 1
  43.  
  44.  
  45. SUB PRINTBOX (nr AS LONG)
  46.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  47.     TextBoxArrow& = TBA(0).Arrow
  48.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  49.     B = TBA(nr).B
  50.     TextHeight = _FONTHEIGHT
  51.     X = TBA(nr).X
  52.     Y = TBA(nr).Y
  53.     BoxLenght = TBA(nr).L
  54.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  55.  
  56.     '    FOR h = 1 TO 10   ' not need this focusing
  57.     DO
  58.         MW = _MOUSEWHEEL ' a variable to store value -1/+1
  59.         IF MW THEN EXIT DO ' we must exit because _mousewheel resets its value to 0 at each _mouseinput
  60.     '    NEXT
  61.     '
  62.     MB1 = _MOUSEBUTTON(1)
  63.     MX = _MOUSEX
  64.     MY = _MOUSEY
  65.  
  66.  
  67.  
  68.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  69.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  70.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  71.  
  72.     IF TIMER < 1 THEN TBA(nr).D = 0
  73.  
  74.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  75.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  76.             IF TBA(nr).D < TIMER THEN
  77.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  78.                 IF MB1 THEN
  79.                     B = B + 1
  80.                 END IF
  81.                 TBA(nr).D = TIMER + .1
  82.             END IF
  83.         END IF
  84.     END IF
  85.  
  86.     IF MX >= X - 26 AND MX <= X - 15 THEN
  87.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  88.             IF TBA(nr).D < TIMER THEN
  89.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  90.                 IF MB1 THEN
  91.                     B = B - 1
  92.                 END IF
  93.                 TBA(nr).D = TIMER + .1
  94.             END IF
  95.         END IF
  96.     END IF
  97.     ' Here the managment of the event _mousewheel
  98.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  99.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  100.             B = B + MW
  101.             '  DO WHILE _MOUSEINPUT: LOOP  ' <-- this works
  102.             IF _MOUSEINPUT THEN REM   <----  also this works
  103.         END IF
  104.     END IF
  105.  
  106.     IF B < 1 THEN B = 1
  107.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  108.     TBA(nr).B = B
  109.     _PRINTSTRING (X, Y), T$
  110.  
  111.  
  112. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  113.     PutArrow& = _NEWIMAGE(12, 12, 32)
  114.     D = _DEST
  115.     _DEST PutArrow&
  116.     CLS
  117.     LINE (1, 4)-(6, 4) '  ------------     up
  118.     LINE (1, 8)-(6, 8) '  ------------     down
  119.     LINE (1, 4)-(1, 8) '  I                arrow back
  120.     LINE (6, 4)-(6, 1)
  121.     LINE (6, 8)-(6, 11)
  122.     LINE (6, 11)-(11, 6)
  123.     LINE (6, 1)-(11, 6)
  124.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  125.     _DEST D
  126. 'End of future "TextBox.BM"
  127.  
  128.  

I hope it is portable to the final version....
Waiting  feedback
Goog Coding
Title: Re: Scroll Bar
Post by: TempodiBasic on September 22, 2019, 06:47:12 pm
Fine the presence of the bar under the text!

here mod for _mousewheel but after playing for a while with arrows, scroll bar and mouse wheel the program stucks.


Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(10) AS LONG
  21.  
  22. FOR t = 1 TO 10
  23.     test(t) = INITBOX(100 + 250 * RND, 40 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24. Demo = INITBOX(150, 500, "This is small text", 9)
  25.  
  26.  
  27.  
  28.     FOR p = 1 TO 10
  29.         PRINTBOX p
  30.     NEXT
  31.     PRINTBOX Demo
  32.  
  33.     _DISPLAY
  34.  
  35. 'this is future "TextBox.BM"
  36.  
  37. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  38.     UTB = UBOUND(tba)
  39.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  40.     TBA(UTB + 1).X = X
  41.     TBA(UTB + 1).Y = Y
  42.     TBA(UTB + 1).L = BoxLenght
  43.     TBA(UTB + 1).T = Text
  44.     TBA(UTB + 1).B = 1
  45.     INITBOX = UTB + 1
  46.  
  47.  
  48. SUB PRINTBOX (nr AS LONG)
  49.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  50.     TextBoxArrow& = TBA(0).Arrow
  51.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  52.     B = TBA(nr).B
  53.     TextHeight = _FONTHEIGHT
  54.     X = TBA(nr).X
  55.     Y = TBA(nr).Y
  56.     BoxLenght = TBA(nr).L
  57.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  58.  
  59.     FOR h = 1 TO 10
  60.         DO
  61.             MW = _MOUSEWHEEL
  62.             IF MW THEN EXIT DO
  63.         LOOP WHILE _MOUSEINPUT
  64.     NEXT
  65.     '
  66.     MB1 = _MOUSEBUTTON(1)
  67.     MX = _MOUSEX
  68.     MY = _MOUSEY
  69.  
  70.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), &HFF000000, BF
  71.  
  72.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), , B
  73.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  74.  
  75.  
  76.     LL = ((B + TBA(nr).L) / LEN(TBA(nr).T)) * 100
  77.     Full = BoxLenght * _FONTWIDTH + 15
  78.     OnePercent = Full / 100
  79.     Actual = LL * OnePercent
  80.  
  81.     LINE (X + Actual, Y + TextHeight + 5)-(Actual + 10 + X, Y + 10 + TextHeight), , BF
  82.     IF MX >= X + Actual AND MX <= Actual + 10 + X THEN
  83.         IF MY >= Y + TextHeight + 5 AND MY <= Y + 10 + TextHeight THEN
  84.             IF MB1 THEN
  85.                 omx = MX
  86.                 DO UNTIL _MOUSEX <> MX
  87.                     WHILE _MOUSEINPUT: WEND
  88.                     MB1 = _MOUSEBUTTON(1)
  89.                     B = B + _MOUSEX - omx
  90.                 LOOP
  91.             END IF
  92.         END IF
  93.     END IF
  94.  
  95.  
  96.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  97.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  98.  
  99.     IF TIMER < 1 THEN TBA(nr).D = 0
  100.  
  101.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  102.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  103.             IF TBA(nr).D < TIMER THEN
  104.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  105.                 IF MB1 THEN
  106.                     B = B + 1
  107.                 END IF
  108.                 TBA(nr).D = TIMER + .01
  109.             END IF
  110.         END IF
  111.     END IF
  112.  
  113.     IF MX >= X - 26 AND MX <= X - 15 THEN
  114.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  115.             IF TBA(nr).D < TIMER THEN
  116.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  117.                 IF MB1 THEN
  118.                     B = B - 1
  119.                 END IF
  120.                 TBA(nr).D = TIMER + .01
  121.             END IF
  122.         END IF
  123.     END IF
  124.  
  125.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  126.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  127.             B = B + MW
  128.             IF _MOUSEINPUT THEN REM
  129.         END IF
  130.     END IF
  131.  
  132.     IF B < 1 THEN B = 1
  133.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  134.     TBA(nr).B = B
  135.     'here will be add color block (and next sub, which calculate text lenght without color flags and other one, which return text string without color flags)
  136.     'future use: V = INITBOX (1, 1, "&HFFFFFFWhite text is here,&HFFFF0000and red text is here", 10)    --  or can be done as "/RED/ This is RED text /WHITE/ and this is white text" with Steve's color constants.
  137.  
  138.     _PRINTSTRING (X, Y), T$
  139.  
  140.  
  141. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  142.     PutArrow& = _NEWIMAGE(12, 12, 32)
  143.     D = _DEST
  144.     _DEST PutArrow&
  145.     CLS
  146.     LINE (1, 4)-(6, 4) '  ------------     up
  147.     LINE (1, 8)-(6, 8) '  ------------     down
  148.     LINE (1, 4)-(1, 8) '  I                arrow back
  149.     LINE (6, 4)-(6, 1)
  150.     LINE (6, 8)-(6, 11)
  151.     LINE (6, 11)-(11, 6)
  152.     LINE (6, 1)-(11, 6)
  153.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  154.     _DEST D
  155. 'End of future "TextBox.BM"
  156.  
Title: Re: Scroll Bar
Post by: bplus on September 22, 2019, 10:21:16 pm
OK I throw my hat into the ring, colors, arrow keys, home and end, mouse-wheel, click or drag to string position.
Code: QB64: [Select]
  1. _TITLE "hScroller Array test" 'B+ start2019-09-22
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 60
  4. TYPE hScroller
  5.     t AS STRING
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     w AS SINGLE 'in pixels
  9.     'h is constant 20
  10.     start AS INTEGER 'in textstring char
  11.     fC AS _UNSIGNED LONG
  12.     bC AS _UNSIGNED LONG
  13. nHscrollers = 5
  14. DIM SHARED testScroller(1 TO nHscrollers) AS hScroller
  15. S$ = "Here is an extremely long string to test the hSrcoller SUBs, I hope to add separate mouse and key control code either in main loop or in a sub for several kinds of controls not only a hScroll box."
  16. newScroller testScroller(1), S$, 100, 100, 20, &HFFFFFFFF, &HFF0000FF
  17. S$ = "A second long string for scroller #2, we are now testing an array of hScrollers."
  18. newScroller testScroller(2), S$, 300, 100, 10, &HFF99AAFF, &HFFFF0000
  19. S$ = "These scrollers are great! Use the left and right arrow keys to move the text home or end but be sure that the mouse pointer is over the scroller you want to read."
  20. newScroller testScroller(3), S$, 50, 200, 50, &HFF003300, &HFF00FF00
  21. S$ = "The home and end keys also work with these Hscrollers, home of course will take you to start of string and end to the end of course."
  22. newScroller testScroller(4), S$, 150, 300, 30, &HFF000055, &HFF00BBBB
  23. S$ = "The mouse action is the best part or these Hscrollers, the wheel will scroll from one end to the other and back and you cam either click a position in the text string or you can drag to any place of the string."
  24. newScroller testScroller(5), S$, 50, 400, 70, &HFF00FF55, &HFF330033
  25.  
  26. WHILE _KEYDOWN(27) = 0
  27.     CLS
  28.     FOR i = 1 TO nHscrollers
  29.         drawHScroller testScroller(i)
  30.     NEXT
  31.         mx = _MOUSEX: my = _MOUSEY
  32.         FOR i = 1 TO nHscrollers
  33.             maxStart = (LEN(testScroller(i).t) - (testScroller(i).w - 6) / 8) + 1
  34.             IF mx >= testScroller(i).x AND mx <= testScroller(i).x + testScroller(i).w THEN
  35.                 IF my >= testScroller(i).y - 10 AND my <= testScroller(i).y + 20 + 10 THEN
  36.                     mw = _MOUSEWHEEL: mb = _MOUSEBUTTON(1)
  37.                     IF testScroller(i).start + mw >= 1 AND testScroller(i).start + mw <= maxStart THEN
  38.                         testScroller(i).start = testScroller(i).start + mw
  39.                     END IF
  40.                     WHILE mb AND _MOUSEINPUT
  41.                         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  42.                         test = ((mx - testScroller(i).x) / testScroller(i).w)
  43.                         IF test >= 0 AND test <= 1 THEN
  44.                             testScroller(i).start = INT(test * maxStart)
  45.                         END IF
  46.                     WEND
  47.                 END IF
  48.             END IF
  49.         NEXT
  50.     WEND
  51.     kh& = _KEYHIT
  52.     IF kh& THEN
  53.         FOR i = 1 TO nHscrollers
  54.             maxStart = (LEN(testScroller(i).t) - (testScroller(i).w - 6) / 8) + 1
  55.             IF mx >= testScroller(i).x AND mx <= testScroller(i).x + testScroller(i).w THEN
  56.                 IF my >= testScroller(i).y - 10 AND my <= testScroller(i).y + 20 + 10 THEN
  57.                     SELECT CASE kh&
  58.                         CASE 19200: IF testScroller(i).start > 1 THEN testScroller(i).start = testScroller(i).start - 1
  59.                         CASE 19712: IF testScroller(i).start < maxStart THEN testScroller(i).start = testScroller(i).start + 1
  60.                         CASE 18176: testScroller(i).start = 1
  61.                         CASE 20224: testScroller(i).start = maxStart
  62.                     END SELECT
  63.                 END IF
  64.             END IF
  65.         NEXT
  66.     END IF
  67.     _DISPLAY
  68.     _LIMIT 100
  69. LOCATE 1, 1: PRINT "Done"
  70.  
  71. 'get stuff loaded into scoller variable for drawing, then for key and mouse control
  72. SUB newScroller (sharedHScroller AS hScroller, txt$, xPix, yPix, wChars, fore AS _UNSIGNED LONG, back AS _UNSIGNED LONG) 'start will be 1
  73.     sharedHScroller.t = txt$
  74.     sharedHScroller.x = xPix
  75.     sharedHScroller.y = yPix
  76.     sharedHScroller.w = wChars * 8 + 6
  77.     sharedHScroller.start = 1
  78.     sharedHScroller.fC = fore
  79.     sharedHScroller.bC = back
  80.  
  81. SUB drawHScroller (sharedHscroller AS hScroller)
  82.     dx = sharedHscroller.w * sharedHscroller.start / (LEN(sharedHscroller.t) - (sharedHscroller.w - 6) / 8 + 1)
  83.     FOR i = 5 TO 0 STEP -.25
  84.         LINE (sharedHscroller.x + dx - i, sharedHscroller.y - 2 * i)-STEP(2 * i, 20 + 4 * i), _RGB32(255 - i * 50, 255 - i * 50, 255 - i * 50), BF
  85.     NEXT
  86.     LINE (sharedHscroller.x, sharedHscroller.y)-STEP(sharedHscroller.w, 20), sharedHscroller.fC, B
  87.     LINE (sharedHscroller.x + 1, sharedHscroller.y + 1)-STEP(sharedHscroller.w - 2, 18), sharedHscroller.bC, BF
  88.     saveColorF = _DEFAULTCOLOR
  89.     saveColorB = _BACKGROUNDCOLOR
  90.     COLOR sharedHscroller.fC, sharedHscroller.bC
  91.     _PRINTSTRING (sharedHscroller.x + 4, sharedHscroller.y + 3), MID$(sharedHscroller.t, sharedHscroller.start, (sharedHscroller.w - 6) / 8)
  92.     COLOR saveColorF, saveColorB
  93.  
Title: Re: Scroll Bar
Post by: Erum on September 23, 2019, 11:57:29 am
To all the respected QB64 team,
Thank you for all those who helped me so much once again. However, I have one last dumb question.
I am done with the whole software, all I need is to add colours. My software is a bit crowded, so I thought adding colours would make the data vivid and easy to read.
I know how to add colours to each line using RGB mixing, but I want to know if it is possible to add more than one colour on one line (text colour only).
I would be grateful to anyone who takes precious time to answer this dumb question.
Regards.
Title: Re: Scroll Bar
Post by: bplus on September 23, 2019, 12:43:20 pm
Here is an example:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) 'for _rgb32 colors
  2. _SCREENMOVE 300, 60 'to get the screen out of B+ title and tool bars
  3.  
  4. txt$ = "Hello world, let me show you a multi-colored string, in just one longish line."
  5.  
  6. 'the MID$ function takes portions of a string
  7. FOR i = 1 TO LEN(txt$) STEP 5 'print txt$ 5 chars at a time
  8.     'reset the ink of print
  9.     COLOR _RGB32(RND * 255, RND * 255, RND * 155 + 100)
  10.     PRINT MID$(txt$, i, 5);
  11.  
  12.  

PS It is not dumb to ask questions, neither dumb intellectually nor dumb in speech.
Title: Re: Scroll Bar
Post by: SMcNeill on September 23, 2019, 01:04:05 pm
It is not dumb to ask questions, neither dumb intellectually nor dumb in speech.

I couldn’t agree more!  All software, and new experiences, require a learning curve.  By asking questions, and finding friendly folks who will take the time to answer them, you can reduce that learning curve immensely.  It’s not dumb to ask questions; and the only people who thinks it is, are the true idiots.  ;)
Title: Re: Scroll Bar
Post by: Erum on September 23, 2019, 02:37:00 pm
Respected QB64 members,
Thank you for making me feel confident for asking questions, you truly are friendly folks. As for the reply, I understood it, and I’ll use it. Thank you!
My queries are officially over. Thanks once more to everyone.
Regards.
Title: Re: Scroll Bar
Post by: TempodiBasic on September 23, 2019, 03:02:23 pm
about
Quote
PS It is not dumb to ask questions, neither dumb intellectually nor dumb in speech.

in my country there is a phrase from the XIX/XX century : "Chi tene a lengua va in Sardegna!"
translating from Dialect to Italian and from italian to English literally "if you have the tongue you can go to Sardegna !" but for the sense is better "You can go anywhere also to a difficult country to reach like the isle Sardegna if you  use your tongue to talk, to ask, to thank"

about developing a scrollbar function
what do you like to do? Complete or stop the developing?
Title: Re: Scroll Bar
Post by: Petr on September 23, 2019, 03:04:18 pm
Hi again.


Finally, I finished what I promised. So ... I tried it for 256 colors only, I will add support for truecolor hexadecimal colors (now must be writed as  unsigned long number) . So far, it works like this:

(Added support for PgUP, PgDn, Up, Dn)

Despite the fact that Erum will probably no use it, because as she write, is done, i add to this thread the promised second type of textbox + third with a shift in all axes. It will certainly be useful to someone later. (And I enjoy it).

Best joke from testing this program?  Hell, why is text not show? Why it works not if use colors? Yeah, man. 32 bit screen and used 8 bit colors...

Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4. TYPE Colored
  5.     onpos AS INTEGER
  6.     clr AS _UNSIGNED LONG
  7.     flag AS INTEGER
  8. REDIM SHARED k(0) AS Colored
  9.  
  10. TYPE TB
  11.     X AS INTEGER '   X position graphic coord
  12.     Y AS INTEGER '   Y position graphic coord
  13.     L AS INTEGER '   TextBox lenght
  14.     T AS STRING '    TextBox text
  15.     B AS INTEGER '   Text begin in textbox  (for shift)
  16.     Arrow AS LONG
  17.     D AS SINGLE 'for time delay between click to arrows
  18. REDIM SHARED TBA(0) AS TB
  19. SCREEN _NEWIMAGE(800, 600, 256) 'screen must be initialized before PutArrow& is run.
  20.  
  21. TBA(0).Arrow = PutArrow&
  22. 'real textboxes starting from 1
  23.  
  24. 'end of future "TextBox.BI"
  25.  
  26.  
  27. DIM test(10) AS LONG
  28.  
  29. FOR t = 1 TO 10
  30.     test(t) = INITBOX(100 + 250 * RND, 40 * t - 27, "/5Hi, /14I'm working on it./1 This /2is the /15test/14 text/15 of the program for /78longitudinal scrolling /14in the /90window./14 Color capabilities will be added soon. /8The program uses arrays because program need to remember the shift values for more than one /50b/60o/20x.", 15 + RND * 40)
  31. Demo = INITBOX(150, 500, "/17T/18h/19i/20s /21i/22s/23 s/24m/25a/26l/27l /28t/29e/30x/31t", 9)
  32.  
  33.  
  34.  
  35.     FOR p = 1 TO 10
  36.         PRINTBOX p
  37.     NEXT
  38.     PRINTBOX Demo
  39.  
  40.     _DISPLAY
  41.  
  42. 'this is future "TextBox.BM"
  43.  
  44. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  45.     UTB = UBOUND(tba)
  46.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  47.     TBA(UTB + 1).X = X
  48.     TBA(UTB + 1).Y = Y
  49.     TBA(UTB + 1).L = BoxLenght
  50.     CString Text, text2$, k(), UTB + 1
  51.     k(UBOUND(k) - 1).flag = UTB + 1
  52.     TBA(UTB + 1).T = text2$
  53.     TBA(UTB + 1).B = 1
  54.     INITBOX = UTB + 1
  55.  
  56.  
  57. SUB PRINTBOX (nr AS LONG)
  58.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  59.     '256/32 color support:
  60.         CASE 0: BEEP: PRINT "Text mode not supported by PRINTBOX!": _DISPLAY: SLEEP 3: END
  61.         CASE 1
  62.             Black~& = 0
  63.             White~& = 15
  64.             Grey~& = 24
  65.             Grey2~& = 19
  66.         CASE 4
  67.             Black~& = &HFF000000
  68.             White~& = &HFFFFFFFF
  69.             Grey~& = &HFF6666666
  70.             Grey2~& = &HFF221122
  71.     END SELECT
  72.  
  73.  
  74.  
  75.  
  76.     TextBoxArrow& = TBA(0).Arrow
  77.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  78.     B = TBA(nr).B
  79.     TextHeight = _FONTHEIGHT
  80.     X = TBA(nr).X
  81.     Y = TBA(nr).Y
  82.     BoxLenght = TBA(nr).L
  83.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  84.  
  85.  
  86.         mwh = mwh + _MOUSEWHEEL
  87.         IF mwh THEN EXIT WHILE
  88.     WEND
  89.  
  90.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  91.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + 2 * TextHeight THEN
  92.             B = B + mwh * 4
  93.         END IF
  94.     END IF
  95.  
  96.  
  97.     '
  98.     MB1 = _MOUSEBUTTON(1)
  99.     MX = _MOUSEX
  100.     MY = _MOUSEY
  101.  
  102.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + TextHeight * 2), Black~&, BF
  103.  
  104.  
  105.     LINE (X - 30, Y + TextHeight)-(X + 30 + BoxLenght * _FONTWIDTH, Y + TextHeight * 2), Grey~&, BF
  106.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 2 * TextHeight), White~&, B
  107.  
  108.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + TextHeight), White~&, B
  109.  
  110.     TL = B / LEN(TBA(nr).T) * 100 'pocatecni poloha pruhu v procentech       begining position for bottom box (perecentually)
  111.     L = TBA(nr).L * _FONTWIDTH
  112.     Actual = _CEIL(X + (TL / 100 * L)) '                                     graphic position for bottom box
  113.     boxl = BoxLenght * _FONTWIDTH
  114.     BL = boxl / (TextLenght / 100) 'delka posuvneho boxiku  v procentech     box on bottom lenght
  115.     BBL = boxl / 100 * BL
  116.  
  117.     'posuvnik
  118.     LINE (Actual, Y + TextHeight + 5)-(Actual + BBL, Y + TextHeight * 2 - 3), White~&, BF
  119.     LINE (Actual, Y + TextHeight + 5)-(Actual + BBL, Y + TextHeight * 2 - 3), Grey2~&, B
  120.  
  121.  
  122.     IF MX >= Actual AND MX <= Actual + BBL THEN
  123.         IF MY >= Y + TextHeight + 5 AND MY <= Y + TextHeight * 2 - 3 THEN
  124.             IF MB1 THEN
  125.                 omx = MX
  126.                 DO UNTIL _MOUSEX <> MX
  127.                     WHILE _MOUSEINPUT: WEND
  128.                     MB1 = _MOUSEBUTTON(1)
  129.                     B = B + _MOUSEX - omx
  130.                 LOOP
  131.             END IF
  132.         END IF
  133.     END IF
  134.  
  135.  
  136.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1), TextBoxArrow&
  137.     _PUTIMAGE (X - 15, Y + TextHeight + 1)-(X - 27, Y + TextHeight + 1 + 12), TextBoxArrow&
  138.  
  139.     IF TIMER < 1 THEN TBA(nr).D = 0
  140.  
  141.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  142.         IF MY >= Y + 1 + TextHeight AND MY <= Y + TextHeight * 2 THEN
  143.             IF TBA(nr).D < TIMER THEN
  144.                 IF _PIXELSIZE = 4 THEN
  145.                     LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + TextHeight * 2), &H44FFFFFF, BF
  146.                 ELSE
  147.                     LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + TextHeight * 2), 14, B
  148.                 END IF
  149.                 IF MB1 THEN
  150.                     B = B + 1
  151.                 END IF
  152.                 TBA(nr).D = TIMER + .01
  153.             END IF
  154.         END IF
  155.     END IF
  156.  
  157.     IF MX >= X - 26 AND MX <= X - 15 THEN
  158.         ' IF MY >= Y + 1 AND MY <= Y + 13 THEN
  159.         IF MY >= Y + 1 + TextHeight AND MY <= Y + TextHeight * 2 THEN
  160.  
  161.             SELECT CASE _KEYHIT
  162.                 CASE 18176: B = 1
  163.                 CASE 20224: B = LEN(TBA(nr).T) - TBA(nr).L + 1
  164.                 CASE 18688: B = B - TBA(nr).L
  165.                 CASE 20736: B = B + TBA(nr).L
  166.             END SELECT
  167.  
  168.  
  169.             IF TBA(nr).D < TIMER THEN
  170.                 IF _PIXELSIZE = 4 THEN
  171.                     LINE (X - 26, Y + TextHeight + 1)-(X - 15, Y + TextHeight * 2), &H44FFFFFF, BF
  172.                 ELSE
  173.                     LINE (X - 26, Y + TextHeight + 1)-(X - 15, Y + TextHeight * 2), 14, B
  174.                 END IF
  175.                 IF MB1 THEN
  176.                     B = B - 1
  177.                 END IF
  178.                 TBA(nr).D = TIMER + .01
  179.             END IF
  180.         END IF
  181.     END IF
  182.     IF B < 1 THEN B = 1
  183.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  184.     TBA(nr).B = B
  185.  
  186.     IF _PIXELSIZE = 4 THEN COLOR &HFFFFFFFF ELSE COLOR 15
  187.  
  188.  
  189.     FOR V = 1 TO LEN(TBA(nr).T)
  190.         FOR t = LBOUND(k) + 1 TO UBOUND(k)
  191.             IF k(t).flag = nr THEN
  192.                 IF V = k(t).onpos + 1 THEN COLOR k(t).clr: EXIT FOR
  193.             END IF
  194.         NEXT
  195.  
  196.         IF V >= B AND V <= B + TBA(nr).L THEN
  197.             _PRINTSTRING (X + (W * _FONTWIDTH), Y), MID$(TBA(nr).T, V, 1)
  198.             W = W + 1
  199.         END IF
  200.     NEXT
  201.  
  202.  
  203.  
  204. FUNCTION PutArrow&
  205.     IF _PIXELSIZE = 4 THEN
  206.         PutArrow& = _NEWIMAGE(12, 12, 32)
  207.     ELSE
  208.         PutArrow& = _NEWIMAGE(12, 12, 256)
  209.     END IF
  210.  
  211.     D = _DEST
  212.     _DEST PutArrow&
  213.  
  214.     LINE (1, 4)-(6, 4) '  ------------     up
  215.     LINE (1, 8)-(6, 8) '  ------------     down
  216.     LINE (1, 4)-(1, 8) '  I                arrow back
  217.     LINE (6, 4)-(6, 1)
  218.     LINE (6, 8)-(6, 11)
  219.     LINE (6, 11)-(11, 6)
  220.     LINE (6, 1)-(11, 6)
  221.  
  222.     IF _PIXELSIZE(D) = 4 THEN PAINT (6, 6), &HFF777777, &HFFFFFFFF ELSE PAINT (6, 6), 10, 15
  223.     IF _PIXELSIZE(D) = 4 THEN _CLEARCOLOR &HFF000000, PutArrow& ELSE _CLEARCOLOR 0, PutArrow&
  224.     _DEST D
  225.  
  226. SUB CString (source AS STRING, text AS STRING, K() AS Colored, index AS INTEGER)
  227.     FOR S = 1 TO LEN(source$)
  228.         t$ = MID$(source$, S, 1)
  229.         IF ASC(t$) >= 48 AND ASC(t$) <= 57 AND incolor THEN colornr$ = colornr$ + t$
  230.         IF incolor AND ASC(t$) < 48 OR incolor AND ASC(t$) > 57 THEN K(kk).clr = VAL(colornr$): D = D + LEN(colornr$): colornr$ = "": incolor = 0
  231.         IF t$ = "/" THEN
  232.             D = D + 1
  233.             incolor = 1
  234.             REDIM _PRESERVE K(UBOUND(k) + 1) AS Colored
  235.             kk = UBOUND(k)
  236.             K(kk).onpos = S - D
  237.             K(kk).flag = index
  238.         END IF
  239.         IF incolor = 0 THEN text$ = text$ + t$
  240.     NEXT
  241.  
  242. 'End of future "TextBox.BM"
  243.  
  244.  
  245.  
  246.  

EDIT: Myself found critical bug: Colors from previous call was used also for next call, for next string. REPAIRED in this version. Now all strings use colors as expected. (Bug is also visible on attached image - word's "This" expected color was white. Now it is ok.


  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Title: Re: Scroll Bar
Post by: TempodiBasic on September 23, 2019, 03:13:37 pm
Hi Bplus
I find your version of scrollbar fine and working.
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Hi Petr
very fine multicolor on the same raw of text...
Title: Re: Scroll Bar
Post by: bplus on September 23, 2019, 03:48:13 pm
Quote
about developing a scrollbar function
what do you like to do? Complete or stop the developing?

I am glad we could eventually help Erum. But she has sort of opened a can of worms with this scrollbar(s) thing.

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.




Title: Re: Scroll Bar
Post by: Bert22306 on September 23, 2019, 03:59:05 pm
Yeah, Bplus, Tempo, Steve, and Petr, this discussion started by Erum has been great. Very educational. Always nice to find ways to make QB64 programs look more modern and less DOS-like.
Title: Re: Scroll Bar
Post by: SMcNeill on September 23, 2019, 04:17:12 pm
An upgraded version of my scroll bar system, now that I have a few moments free to flesh it out:

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.  

Arrow keys scroll, and you can use the mouse to maneuver via the scroll bars if you hold the left mouse down while over one of them.  The window is also resizable, with the scroll bars automatically adjusting to the new window sizes.   Test it out, and see what you think of it.  ;)
Title: Re: Scroll Bar
Post by: Petr on September 23, 2019, 05:14:38 pm
I think about it the best. :) Good work, Steve.
Title: Re: Scroll Bar
Post by: bplus on September 23, 2019, 05:29:51 pm
I think about it the best. :) Good work, Steve.

Well I wonder if Steve or anyone can put can put N text boxes up with double scrollers on the same screen like we were doing for text hScrollers with mouse wheel and other key presses also of course!  ;-))
Title: Re: Scroll Bar
Post by: SMcNeill on September 23, 2019, 05:38:32 pm
Well I wonder if Steve or anyone can put can put N text boxes up with double scrollers on the same screen like we were doing for text hScrollers with mouse wheel and other key presses also of course!  ;-))

Sure.  Just make each scroll area independent, and assign them their own unique handle,  like with my little text frames routines.  All this demo needed was to make a screen adjustable/scrollable, but all you do is apply the same principle to any given screen regions — one screen of set size to draw/write on, a second screen to display a portion of it on via _PUTIMAGE, with the scroll bars just being X/Y incremental tools.  (Which is all they do above for us.)
Title: Re: Scroll Bar
Post by: TempodiBasic on September 23, 2019, 05:44:49 pm
about

Quote
So I am wondering should we continue discussion here with the horizontal text conquered or should we move to Steve's thread

Here my answer to unify the threads https://www.qb64.org/forum/index.php?topic=1719.msg109796#msg109796 (https://www.qb64.org/forum/index.php?topic=1719.msg109796#msg109796)

about this issue
Quote
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. ???

IMHO when we go to think as objects or entities to use in our programs we have two option...
1.  centered managing of mouse and keyboard and other input ways  ,
      so we can think about it like a pyramid that has like apex the I/O routine to be directed to the right entity at bottom,
      or like a collection of areas to be activated by a flag (in Windows there are the messages among objects)
2. a plane or circular managing of I/O  in which the objects/entities have the own different action that is activated by the specific
    position of the mouse and by the specific comboKey

the substantial difference between them is that in the first the apex manages I/O and triggers entity's action, in the second there is a main loop in which each entity tests if position of mouse and combokey activate its action/s.

just as example about previous scrolling horizonthal
in the first kind of  multi entities  there is a main loop that catches I/O  and activate the single scrolling bar...
in the second kind of multi entities, one at time  each entity tests if it must react ot I/O so there is a main loop that cycles among all entities

so in the first kind each entity has a value or code to be activated and disactivated
while in the second kind each entity has an entry of parameters and a routine to activate itself.

Waiting your opinion
Thanks to read
Title: Re: Scroll Bar
Post by: Petr on September 23, 2019, 05:56:22 pm
Quote
Sure.  Just make each scroll area independent, and assign them their own unique handle,  like with my little text frames routines.  All this demo needed was to make a screen adjustable/scrollable, but all you do is apply the same principle to any given screen regions — one screen of set size to draw/write on, a second screen to display a portion of it on via _PUTIMAGE, with the scroll bars just being X/Y incremental tools.  (Which is all they do above for us.)


I'll do it differently. I'll do it with PRINTSTRING (none PUTIMAGE). Yeah, if I wanted to make a slider for pictures with text, that would be harder. To solve the text flow around the picture .... I can think of several possibilities, but I will stay with the text. Of course it will take a while, but it won't be a problem. Of course there will be an unlimited number (according to RAM) of these dialogs on the monitor. I think, i need 2 or 3 days for it (i have very limited time for programming now).


So far, I say goodbye because here is midnight.
Title: Re: Scroll Bar
Post by: Petr on September 23, 2019, 06:09:28 pm
OFFTOPIC - Steve your next video tutorial is in perfect quality! I see it tomorrow!
Title: Re: Scroll Bar
Post by: Petr on September 30, 2019, 04:40:03 pm
So it took a little longer, I didn't have so much time and finally I didn't want much ... and unfortunately I came across a STRING error again. A STRING error is resolved by adding * 10 in the TB2 field definition in the X / Y Slider. Thus, I understand the meaning of STRING * 10 for writing to a file, but I do not understand the meaning of STRING * 10 when writing to memory when the subsequent string is as long as you like. Well, if you remove * 10 from the field definition, you won't color the text and the program will start doing unexpected things. Perhaps we can find the reason for the error, this program is much simpler than the previous one, where the same error manifested itself differently.

So the programs. The XY slider creates a text box at the X, Y position, with the option of scrolling the X and Y axes and coloring the text in / 15 = white for a 256 color screen with the basic color palette, or / 4294967295 in 32bit screen for white color. The number of slider windows is unlimited. The only limit is the size of your RAM.

The slider X program is older and listed here (but the version above has some bugs that the new version no longer contains). It is a one-line slider for text only in the X axis, also with the same colored text option.


XY slider:

Code: QB64: [Select]
  1.  
  2.  
  3. 'this is future "TextBox.BI"
  4. TYPE Colored '                      This Array contains colors positions on text and color values. This array is created in SUB CString.
  5.     onpos AS INTEGER
  6.     clr AS _UNSIGNED LONG
  7.     flag AS INTEGER
  8.     row AS INTEGER
  9. REDIM SHARED k(0) AS Colored
  10.  
  11. TYPE TB2
  12.     X AS INTEGER '   X position graphic coord
  13.     Y AS INTEGER '   Y position graphic coord
  14.     L AS INTEGER '   TextBox lenght
  15.     H AS INTEGER '   Textbox HEIGHT                                            NEW
  16.     T AS STRING * 10 '    TextBox text                                                            AGAIN STRING BUG!!!!!! DELETE *10 and run this program for really unexpected outputs!
  17.     B AS INTEGER '   Text begin in textbox  (for shift), X axis
  18.     BH AS INTEGER '  Text begin in textbox  (for shift), Y axis                NEW
  19.  
  20.     D AS SINGLE '    for time delay between click to arrows
  21.     I_s AS INTEGER
  22.     I_e AS INTEGER
  23.     filter AS _BYTE 'new info flag for CString, which is needed just in the start, but not more.
  24.  
  25. REDIM SHARED TBA2(0) AS TB2
  26. REDIM SHARED GlobalText(0) AS STRING 'spolecne obrovske textove pole obsahujici texty pro vsechna okna vcetne udaju o barvach
  27. DIM SHARED Arrow0 AS LONG, Arrow1 AS LONG, Arrow2 AS LONG, Arrow3 AS LONG
  28.  
  29.  
  30. SCREEN _NEWIMAGE(800, 600, 256) 'screen must be initialized before PutArrow& is run.
  31. Arrow0 = PutArrow
  32. R90 Arrow0, Arrow1, Arrow2, Arrow3 'create four arrows in four directions from first source image
  33. 'end of future "TextBox.BI"
  34.  
  35.  
  36.  
  37.  
  38. DIM Text1(7) AS STRING
  39. DIM Text2(14) AS STRING
  40.  
  41. Text1(1) = "/14This is content /1for /2array /3Text1. Original and source text array content is in"
  42. Text1(2) = "/44array Text1. Because Petr can just 2 ways (first: MEM Pointer to array insert"
  43. Text1(3) = "/45to type), or second, easyest - all texts insert to one STRING SHARED array, and"
  44. Text1(4) = "/46writing informations about start and end index to TYPE, is now this text also"
  45. Text1(5) = "/47inserted to array named as GlobalText. Because this text contains 7 rows and "
  46. Text1(6) = "/48Text1 array is inserted as first, is this saved in indexes 0 to 6 in array"
  47. Text1(7) = "/49GlobalText. Info about this records are here saved to TBA2().I_s and TBA2().I_e"
  48.  
  49.  
  50.  
  51. Text2(1) = "                /14   Example for use:"
  52. Text2(2) = "/40 With '/40/' and then number you set colors. If you use _SCREEN _NEWIMAGE in 256 colors,"
  53. Text2(3) = "then use number from 0 to 256. But if you use 32 bit screen, then dont use &H values but"
  54. Text2(4) = "/50 number. This number can be returned using this easy source code:"
  55. Text2(5) = "/55 COLOR~& = &HFFFFFFFF  /60 or /55 COLOR~& = _RGBA32(255, 255, 255)"
  56. Text2(6) = "PRINT COLOR~&. /60 This is number, which you need for use to 32 bit screens with this"
  57. Text2(7) = "easy program. (i write soon automatic translator for it, but with my time....)/9"
  58. Text2(8) = "Program construction: - All strings are saved to array /14 GlobalText."
  59. Text2(9) = "                     /9 - Function /14R90/9 create 4 images which contains rows, rotated from 1"
  60. Text2(10) = "                       source image, which is created with Function /14PutArrow./9"
  61. Text2(11) = "                     - /14CString /9SUB create help array for colors used in text to array /14K/9."
  62. Text2(12) = "                     - /14MaximalRowLenght/9 Function return lenght of longest row in text array."
  63. Text2(13) = "                     - Function /14INITBOX2/9 write all needed records to program arrays and return record number."
  64. Text2(14) = "                     - /14XY_BOX /9SUB - own program. Study it /33yourself /40:-)"
  65.  
  66.  
  67. A = INITBOX2(100, 50, Text1(), 10, 8)
  68. B = INITBOX2(300, 50, Text1(), 30, 6)
  69. C = INITBOX2(100, 250, Text2(), 20, 15)
  70. D = INITBOX2(350, 180, Text2(), 50, 26)
  71.  
  72.  
  73.  
  74.     XY_BOX A
  75.     XY_BOX B
  76.     XY_BOX C
  77.     XY_BOX D
  78.     _DISPLAY
  79.     _LIMIT 60
  80.  
  81.  
  82.  
  83. 'this is future "TextBox.BM"
  84. FUNCTION INITBOX2 (X AS INTEGER, Y AS INTEGER, Text() AS STRING, BoxLenght AS INTEGER, BoxHeight AS INTEGER) 'X, Y are GRAPHIC coordinates
  85.     UTB = UBOUND(tba2)
  86.     REDIM _PRESERVE TBA2(UTB + 1) AS TB2
  87.     TBA2(UTB + 1).X = X
  88.     TBA2(UTB + 1).Y = Y
  89.     TBA2(UTB + 1).L = BoxLenght
  90.     TBA2(UTB + 1).H = BoxHeight
  91.  
  92.  
  93.  
  94.  
  95.     TBA2(UTB + 1).T = ""
  96.     U1 = UBOUND(globaltext)
  97.     U2 = UBOUND(text)
  98.  
  99.     TBA2(UTB + 1).I_s = U1
  100.     TBA2(UTB + 1).I_e = U1 + U2
  101.  
  102.     REDIM _PRESERVE GlobalText(U1 + U2 + 1) AS STRING
  103.  
  104.     FOR insert = U1 TO U1 + U2
  105.         GlobalText(insert) = Text(t)
  106.         t = t + 1
  107.     NEXT
  108.  
  109.     TBA2(UTB + 1).BH = U1 + 1 'after first start: first row (BH is shift in Y, B is shift in X axis)
  110.     TBA2(UTB + 1).B = 1 'and first column
  111.     INITBOX2 = UTB + 1
  112.  
  113.  
  114. SUB XY_BOX (nr AS LONG)
  115.     '256/32 color support:
  116.  
  117.         CASE 0: BEEP: PRINT "Text mode not supported by PRINTBOX!": _DISPLAY: SLEEP 3: END
  118.         CASE 1
  119.             Black~& = 0
  120.             White~& = 15
  121.             Grey~& = 24
  122.             Grey2~& = 19
  123.         CASE 4
  124.             Black~& = &HFF000000
  125.             White~& = &HFFFFFFFF
  126.             Grey~& = &H226666666
  127.             Grey2~& = &HFF221122
  128.     END SELECT
  129.  
  130.  
  131.     RowLen = MaximalRowLenght(nr)
  132.     TextLenght = RowLen * _FONTWIDTH
  133.     B = TBA2(nr).B
  134.     BH = TBA2(nr).BH
  135.  
  136.     TextHeight = _FONTHEIGHT
  137.     X = TBA2(nr).X
  138.     Y = TBA2(nr).Y
  139.     BoxLenght = TBA2(nr).L - 2
  140.     BoxHeight = 1 + TBA2(nr).H * _FONTHEIGHT
  141.  
  142.         mwh = mwh + _MOUSEWHEEL
  143.         IF mwh THEN EXIT WHILE
  144.     WEND
  145.  
  146.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  147.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + 2 * TextHeight THEN
  148.             B = B + mwh * 4
  149.         END IF
  150.     END IF
  151.  
  152.  
  153.     '
  154.     MB1 = _MOUSEBUTTON(1)
  155.     MX = _MOUSEX
  156.     MY = _MOUSEY
  157.  
  158.  
  159.  
  160.  
  161.     LINE (X - 30, Y)-(X + 30 + BoxLenght * _FONTWIDTH, Y + BoxHeight), Grey~&, BF 'vnitrek okna                                   window inside
  162.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + BoxHeight), White~&, B
  163.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + BoxHeight - TextHeight), White~&, B
  164.  
  165.     'borders for lines up / down
  166.     LINE (X + 30 + BoxLenght * _FONTWIDTH, Y - 1)-(X + 11 + BoxLenght * _FONTWIDTH, Y + BoxHeight - TextHeight), White~&, B
  167.  
  168.  
  169.     '  slider X calculations. For calculating slider lenght you need the number of characters of the longest sentence used in the box. MaximalRowLenght function return it:
  170.     '////////////////////////////////////////////////////////
  171.     TL = B / RowLen * 100 'pocatecni poloha pruhu v procentech            begining position for bottom box (percentually)
  172.     L = TBA2(nr).L * _FONTWIDTH 'celkova delka pruhu v pixelech           total slide lenght in pixels
  173.     Actual = _CEIL(X + (TL / 100 * L)) '                                  graphic position for bottom box
  174.     boxl = BoxLenght * _FONTWIDTH
  175.     BL = boxl / (TextLenght / 100) 'delka posuvneho boxiku  v procentech     box on bottom lenght  (how it is done: Slider lenght is percentually size as window bottom (for X - Shift).
  176.     '                                                                        if 30 percent of the sentence length is visible in the window, then the slider is 30 percent of the length of the X-side this window
  177.     IF BL > 100 THEN BL = 100 '                                              if text lenght < window X side, draw slider as 100 percent of X window side
  178.  
  179.     BBL = boxl / 100 * BL
  180.  
  181.     'posuvnik X        Slider X
  182.     LINE (Actual, Y + BoxHeight - TextHeight + 5)-(Actual + BBL, Y + BoxHeight - TextHeight + 12), White~&, BF
  183.     LINE (Actual, Y + BoxHeight - TextHeight + 5)-(Actual + BBL, Y + BoxHeight - TextHeight + 12), Grey2~&, B
  184.     '////////////////////////////////////////////////////////////
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.     'slider Y (the same os for X slider)
  192.     DelkaSteny = BoxHeight - TextHeight - (2 * _FONTHEIGHT) - 2
  193.     ZaznamuNaStenu = DelkaSteny / _FONTHEIGHT
  194.     Zaznamu100 = ZaznamuNaStenu / (TBA2(nr).I_e - TBA2(nr).I_s) * 100
  195.     BBH = (Zaznamu100 / 100) * DelkaSteny
  196.     IF BBH > DelkaSteny THEN BBH = DelkaSteny
  197.  
  198.     Pozice = 1 + (BH - TBA2(nr).I_e) / TBA2(nr).I_e
  199.     actualH = Y + _FONTHEIGHT + ((DelkaSteny - BBH) * Pozice)
  200.  
  201.  
  202.     'posuvnik Y        Slider Y
  203.     LINE (TBA2(nr).X + TBA2(nr).L * _FONTWIDTH, actualH)-(TBA2(nr).X + TBA2(nr).L * _FONTWIDTH + 7, actualH + BBH), White~&, BF
  204.     LINE (TBA2(nr).X + TBA2(nr).L * _FONTWIDTH, actualH)-(TBA2(nr).X + TBA2(nr).L * _FONTWIDTH + 7, actualH + BBH), Grey2~&, B
  205.  
  206.  
  207.  
  208.     ' solution for moving text by click + move to down box
  209.     IF MX >= X AND MX <= X + _FONTWIDTH * (TBA2(nr).L - 2) THEN
  210.         IF MY >= Y + BoxHeight - TextHeight AND MY <= Y + BoxHeight THEN
  211.             IF MB1 THEN
  212.                 omx = MX
  213.                 DO UNTIL _MOUSEX <> MX
  214.                     WHILE _MOUSEINPUT: WEND
  215.                     MB1 = _MOUSEBUTTON(1)
  216.                     B = B + _MOUSEX - omx
  217.                 LOOP
  218.             END IF
  219.         END IF
  220.     END IF
  221.  
  222.     ' solution for moving text up and down by clicking and move to box on right
  223.     IF MX >= X + 10 + BoxLenght * _FONTWIDTH AND MX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  224.         IF MY >= Y + 16 AND MY <= Y + BoxHeight - 40 THEN
  225.             IF MB1 THEN
  226.                 omy = MY
  227.                 DO UNTIL _MOUSEY <> MY
  228.                     WHILE _MOUSEINPUT: WEND
  229.                     MB1 = _MOUSEBUTTON(1)
  230.                     BH = BH + _MOUSEY - omy
  231.                 LOOP
  232.             END IF
  233.         END IF
  234.     END IF
  235.  
  236.     ABY = Y + 2 + BoxHeight - TextHeight '                  ArrowBottomY coordinate
  237.     LUPAC = X + 15 + BoxLenght * _FONTWIDTH '               Left UP/Down Arrow coordinate
  238.  
  239.     _PUTIMAGE (LUPAC, ABY), Arrow0& '                              Arrow to right
  240.     _PUTIMAGE (X - 27, ABY + 1), Arrow1& '                                  left
  241.     _PUTIMAGE (LUPAC, Y + 2), Arrow3& '                                     up
  242.     _PUTIMAGE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2)), Arrow2& '     down
  243.  
  244.     IF TIMER < 1 THEN TBA2(nr).D = 0
  245.  
  246.     'driving up arrow
  247.     IF MX >= LUPAC AND MX <= LUPAC + 12 THEN
  248.         IF MY >= Y + 2 AND MY <= Y + 14 THEN
  249.             IF TBA2(nr).D < TIMER THEN
  250.                 IF _PIXELSIZE = 4 THEN
  251.                     LINE (LUPAC, Y + 2)-(LUPAC + 12, Y + 14), &H44FFFFFF, BF
  252.                 ELSE
  253.                     LINE (LUPAC, Y + 2)-(LUPAC + 12, Y + 14), 14, B
  254.                 END IF
  255.                 IF MB1 THEN BH = BH - 1
  256.                 TBA2(nr).D = TIMER + .01
  257.                 MB1 = 0
  258.             END IF
  259.         END IF
  260.     END IF
  261.  
  262.     'driving down arrow
  263.     IF MX >= LUPAC - 1 AND MX <= LUPAC + 11 THEN
  264.         IF MY >= Y + TextHeight * (TBA2(nr).H - 2) AND MY <= 12 + Y + TextHeight * (TBA2(nr).H - 2) THEN
  265.             IF TBA2(nr).D < TIMER THEN
  266.                 IF _PIXELSIZE = 4 THEN
  267.                     LINE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2))-(LUPAC + 11, 12 + Y + TextHeight * (TBA2(nr).H - 2)), &H44FFFFFF, BF
  268.                 ELSE
  269.                     LINE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2))-(LUPAC + 11, 12 + Y + TextHeight * (TBA2(nr).H - 2)), 14, B
  270.                 END IF
  271.                 IF MB1 THEN BH = BH + 1
  272.                 TBA2(nr).D = TIMER + .01
  273.                 MB1 = 0
  274.             END IF
  275.         END IF
  276.     END IF
  277.  
  278.  
  279.  
  280.     'driving right arrow on bottom
  281.     IF MX >= LUPAC AND MX <= LUPAC + 12 THEN
  282.         IF MY >= ABY AND MY <= ABY + 12 THEN
  283.  
  284.             IF TBA2(nr).D < TIMER THEN
  285.                 IF _PIXELSIZE = 4 THEN
  286.                     LINE (LUPAC, ABY)-(LUPAC + 12, ABY + 12), &H44FFFFFF, BF
  287.                 ELSE
  288.                     LINE (LUPAC, ABY)-(LUPAC + 12, ABY + 12), 14, B
  289.                 END IF
  290.                 IF MB1 THEN
  291.                     B = B + 1
  292.                     MB1 = 0
  293.                     TBA2(nr).D = TIMER + .01
  294.                 END IF
  295.             END IF
  296.         END IF
  297.     END IF
  298.  
  299.     'driving left arrow on bottom
  300.     IF MX >= X - 27 AND MX <= X - 15 THEN '12 + 15 = 27, 12 is arrow width
  301.         IF MY >= ABY + 1 AND MY <= ABY + 13 THEN
  302.             IF TBA2(nr).D < TIMER THEN
  303.                 IF _PIXELSIZE = 4 THEN
  304.                     LINE (X - 27, ABY + 1)-(X - 15, ABY + 13), &H44FFFFFF, BF
  305.                 ELSE
  306.  
  307.                     LINE (X - 27, ABY + 1)-(X - 15, ABY + 13), 14, B
  308.                 END IF
  309.                 IF MB1 THEN
  310.                     B = B - 1
  311.                     MB1 = 0
  312.                     TBA2(nr).D = TIMER + .01
  313.                 END IF
  314.             END IF
  315.         END IF
  316.     END IF
  317.  
  318.  
  319.     'new: left - right keyboard driving:       (home, end, pg up, pg dn, insert (not edit), delete (not edit), arrows up, down, left, right)
  320.     IF MX >= X - 30 AND MX <= X + BoxLenght * _FONTWIDTH + 30 THEN
  321.         IF MY > Y AND MY <= Y + BoxHeight THEN
  322.  
  323.             KH& = _KEYHIT
  324.             IF KH& THEN
  325.                 SELECT CASE KH&
  326.                     CASE 18176: B = 1
  327.                     CASE 20224: B = RowLen - TBA2(nr).L + 1
  328.                     CASE 18688: B = B - TBA2(nr).L ' PgUP
  329.                     CASE 20736: B = B + TBA2(nr).L ' PgDN
  330.                     CASE 19200: B = B - 1 '          left
  331.                     CASE 19712: B = B + 1 '          right
  332.                     CASE 18432: BH = BH - 1 '        up
  333.                     CASE 20480: BH = BH + 1 '         down
  334.                     CASE 20992: BH = BH + TBA2(nr).H 'insert
  335.                     CASE 21428: BH = BH - TBA2(nr).H 'delete
  336.                 END SELECT
  337.                 _KEYCLEAR
  338.             END IF
  339.  
  340.         END IF
  341.     END IF
  342.  
  343.     IF BH < TBA2(nr).I_s THEN BH = TBA2(nr).I_s
  344.     IF BH > TBA2(nr).I_e THEN BH = TBA2(nr).I_e
  345.  
  346.  
  347.     IF B > RowLen - TBA2(nr).L + 1 THEN B = RowLen - TBA2(nr).L + 1
  348.     IF B < 1 THEN B = 1
  349.  
  350.     TBA2(nr).B = B '      B is variable for shift left and right
  351.     TBA2(nr).BH = BH '    BH is variable for shift up and down
  352.  
  353.     IF _PIXELSIZE = 4 THEN COLOR &HFFFFFFFF ELSE COLOR 15
  354.  
  355.     IF TBA2(nr).filter = 0 THEN CString k(), nr: TBA2(nr).filter = 1 'and this is row, which AGAIN find me STRING BUG. Nr is not correct, if is STRING without star used!
  356.  
  357.  
  358.     BHE = BH + TBA2(nr).H - 2
  359.     IF BHE > TBA2(nr).I_e THEN BHE = TBA2(nr).I_e
  360.  
  361.  
  362.     'coloring and printing content
  363.  
  364.     FOR Rows = BH TO BHE
  365.         FOR v = 1 TO RowLen
  366.             FOR T = LBOUND(k) + 1 TO UBOUND(k)
  367.                 IF k(T).flag = nr THEN '               here is contained color bug. For better solution must be first found starting color, on which text start. It will be done later.
  368.                     IF Rows = k(T).row THEN
  369.                         IF v = k(T).onpos + 1 THEN COLOR k(T).clr: EXIT FOR
  370.                     END IF
  371.                 END IF
  372.             NEXT
  373.             IF v >= B AND v <= B + TBA2(nr).L THEN
  374.                 _PRINTSTRING (X - 20 + (w * _FONTWIDTH), Y + (Rows - BH) * _FONTHEIGHT), MID$(GlobalText(Rows), v, 1)
  375.                 w = w + 1
  376.             END IF
  377.         NEXT
  378.         w = 0
  379.     NEXT Rows
  380.  
  381.  
  382. FUNCTION PutArrow&
  383.     IF _PIXELSIZE = 4 THEN
  384.         PutArrow& = _NEWIMAGE(12, 12, 32)
  385.     ELSE
  386.         PutArrow& = _NEWIMAGE(12, 12, 256)
  387.     END IF
  388.  
  389.     D = _DEST
  390.     _DEST PutArrow&
  391.  
  392.     LINE (1, 4)-(6, 4)
  393.     LINE (1, 8)-(6, 8)
  394.     LINE (1, 4)-(1, 8)
  395.     LINE (6, 4)-(6, 1)
  396.     LINE (6, 8)-(6, 11)
  397.     LINE (6, 11)-(11, 6)
  398.     LINE (6, 1)-(11, 6)
  399.  
  400.     IF _PIXELSIZE(D) = 4 THEN PAINT (6, 6), &HFF777777, &HFFFFFFFF ELSE PAINT (6, 6), 10, 15
  401.     IF _PIXELSIZE(D) = 4 THEN _CLEARCOLOR &HFF000000, PutArrow& ELSE _CLEARCOLOR 0, PutArrow&
  402.     _DEST D
  403.  
  404.  
  405. SUB CString (K() AS Colored, index AS INTEGER)
  406.     FOR rows = TBA2(index).I_s TO TBA2(index).I_e
  407.         source$ = GlobalText(rows)
  408.         FOR S = 1 TO LEN(source$)
  409.             old$ = t$
  410.             t$ = MID$(source$, S, 1)
  411.             IF ASC(t$) >= 48 AND ASC(t$) <= 57 AND incolor THEN colornr$ = colornr$ + t$
  412.             IF incolor AND ASC(t$) < 48 OR incolor AND ASC(t$) > 57 THEN
  413.                 K(kk).clr = VAL(colornr$): D = D + LEN(colornr$): colornr$ = "": incolor = 0
  414.                 IF old$ = "/" THEN text$ = text$ + old$
  415.             END IF
  416.  
  417.             IF t$ = "/" THEN
  418.                 D = D + 1
  419.                 incolor = 1
  420.                 REDIM _PRESERVE K(UBOUND(k) + 1) AS Colored
  421.                 kk = UBOUND(k)
  422.                 K(kk).onpos = S - D
  423.                 K(kk).flag = index
  424.                 K(kk).row = rows
  425.             END IF
  426.             IF incolor = 0 THEN text$ = text$ + t$
  427.         NEXT
  428.  
  429.         GlobalText(rows) = text$
  430.         text$ = ""
  431.         ind = ind + 1
  432.         D = 0
  433.     NEXT rows
  434.  
  435.  
  436. SUB R90 (img0 AS LONG, img1 AS LONG, img2 AS LONG, img3 AS LONG) 'create 4 arrows from one in four directions
  437.     IF img0 >= -1 THEN EXIT SUB 'source image is invalid
  438.     W = _WIDTH(img0)
  439.     H = _HEIGHT(img0)
  440.     P = _PIXELSIZE(img0)
  441.     DIM CC AS _UNSIGNED LONG
  442.  
  443.     SELECT CASE P
  444.         CASE 0: EXIT SUB 'text mode unsupported
  445.         CASE 1: D = 256: CC = 0
  446.         CASE 4: D = 32: CC = &HFF000000
  447.     END SELECT
  448.  
  449.     img1 = _NEWIMAGE(W, H, D)
  450.     _PUTIMAGE , img0, img1, (W, 1)-(1, H) '180 degrees rotating
  451.  
  452.     img2 = _NEWIMAGE(H, W, D) '            90
  453.     _MAPTRIANGLE (0, 0)-(W, 0)-(W, H), img0 TO(H, 0)-(H, W)-(0, W), img2
  454.     _MAPTRIANGLE (0, 0)-(W, H)-(0, H), img0 TO(H, 0)-(0, W)-(0, 0), img2
  455.  
  456.     img3 = _NEWIMAGE(H, W, D)
  457.     _PUTIMAGE , img2, img3, (1, W)-(H, 1) '270
  458.     _CLEARCOLOR CC, img1
  459.     _CLEARCOLOR CC, img2
  460.     _CLEARCOLOR CC, img3
  461.  
  462. FUNCTION MaximalRowLenght (i)
  463.     MaximalRowLenght = 0
  464.     REDIM test(0) AS STRING
  465.     ClearColorRecordsAndVauesFromTextArray TBA2(i).I_s, TBA2(i).I_e, test()
  466.  
  467.     FOR p = LBOUND(test) TO UBOUND(test)
  468.         IF MaximalRowLenght < LEN(test(p)) THEN MaximalRowLenght = LEN(test(p))
  469.     NEXT
  470.  
  471. SUB ClearColorRecordsAndVauesFromTextArray (start, eend, arrname() AS STRING) 'If we need find maximal row lenght, first must color tags be deleted from text.
  472.     REDIM arrname(eend - start) AS STRING
  473.     FOR c = start TO eend
  474.         FOR L = 1 TO LEN(GlobalText(c))
  475.             ch$ = MID$(GlobalText(c), L, 1)
  476.             IF ch$ = "/" THEN iscolor = 1
  477.             IF iscolor AND ASC(ch$) > 47 AND ASC(ch$) < 58 THEN ELSE t$ = t$ + ch$
  478.             IF iscolor AND ASC(ch$) < 47 OR iscolor AND ASC(ch$) > 58 THEN
  479.                 iscolor = 0
  480.             END IF
  481.         NEXT
  482.         arrname(c - start) = t$
  483.         t$ = ""
  484.     NEXT c
  485.  
  486. 'End of future "TextBox.BM"
  487.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

X - slider:

Also, this program does not have a limited number of sliders. You can place them as much as big is your RAM. This is the older version on which the X/Y new version is based.


Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4. TYPE Colored
  5.     onpos AS INTEGER
  6.     clr AS _UNSIGNED LONG
  7.     flag AS INTEGER
  8. REDIM SHARED k(0) AS Colored
  9.  
  10. TYPE TB
  11.     X AS INTEGER '   X position graphic coord
  12.     Y AS INTEGER '   Y position graphic coord
  13.     L AS INTEGER '   TextBox lenght
  14.     T AS STRING '    TextBox text
  15.     B AS INTEGER '   Text begin in textbox  (for shift)
  16.     Arrow AS LONG
  17.     D AS SINGLE 'for time delay between click to arrows
  18. REDIM SHARED TBA(0) AS TB
  19. SCREEN _NEWIMAGE(800, 600, 256) 'screen must be initialized before PutArrow& is run.
  20.  
  21.  
  22. TBA(0).Arrow = PutArrow&
  23. 'real textboxes starting from 1
  24.  
  25. 'end of future "TextBox.BI"
  26.  
  27.  
  28. DIM test(10) AS LONG
  29.  
  30. FOR t = 1 TO 10
  31.     test(t) = INITBOX(100 + 25 * RND, 40 * t, "/42Hi World in 32 bites/29 colored long text/15 placed in textbox.", 15 + RND * 60)
  32. Demo = INITBOX(150, 500, "/49 Here /55is used /42absolutely random color /77number...", 29)
  33.  
  34.  
  35.  
  36.     FOR p = 1 TO 10
  37.         XY_BOX p
  38.     NEXT
  39.     XY_BOX Demo
  40.  
  41.     _DISPLAY
  42.  
  43. 'this is future "TextBox.BM"
  44.  
  45. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  46.     UTB = UBOUND(tba)
  47.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  48.     TBA(UTB + 1).X = X
  49.     TBA(UTB + 1).Y = Y
  50.     TBA(UTB + 1).L = BoxLenght
  51.     CString Text, text2$, k(), UTB + 1
  52.     TBA(UTB + 1).T = text2$
  53.     TBA(UTB + 1).B = 1
  54.     INITBOX = UTB + 1
  55.  
  56.  
  57. SUB XY_BOX (nr AS LONG)
  58.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  59.     '256/32 color support:
  60.         CASE 0: BEEP: PRINT "Text mode not supported by PRINTBOX!": _DISPLAY: SLEEP 3: END
  61.         CASE 1
  62.             Black~& = 0
  63.             White~& = 15
  64.             Grey~& = 24
  65.             Grey2~& = 19
  66.         CASE 4
  67.             Black~& = &HFF000000
  68.             White~& = &HFFFFFFFF
  69.             Grey~& = &HFF6666666
  70.             Grey2~& = &HFF221122
  71.     END SELECT
  72.  
  73.  
  74.  
  75.  
  76.     TextBoxArrow& = TBA(0).Arrow
  77.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  78.     B = TBA(nr).B
  79.     TextHeight = _FONTHEIGHT
  80.     X = TBA(nr).X
  81.     Y = TBA(nr).Y
  82.     BoxLenght = TBA(nr).L
  83.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  84.  
  85.  
  86.         mwh = mwh + _MOUSEWHEEL
  87.         IF mwh THEN EXIT WHILE
  88.     WEND
  89.  
  90.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  91.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + 2 * TextHeight THEN
  92.             B = B + mwh * 4
  93.         END IF
  94.     END IF
  95.  
  96.  
  97.     '
  98.     MB1 = _MOUSEBUTTON(1)
  99.     MX = _MOUSEX
  100.     MY = _MOUSEY
  101.  
  102.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + TextHeight * 2), Black~&, BF
  103.  
  104.  
  105.     LINE (X - 30, Y + TextHeight)-(X + 30 + BoxLenght * _FONTWIDTH, Y + TextHeight * 2), Grey~&, BF
  106.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 2 * TextHeight), White~&, B
  107.  
  108.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + TextHeight), White~&, B
  109.  
  110.     TL = B / LEN(TBA(nr).T) * 100 'pocatecni poloha pruhu v procentech       begining position for bottom box (perecentually)
  111.     L = TBA(nr).L * _FONTWIDTH
  112.     Actual = _CEIL(X + (TL / 100 * L)) '                                     graphic position for bottom box
  113.     boxl = BoxLenght * _FONTWIDTH
  114.     BL = boxl / (TextLenght / 100) 'delka posuvneho boxiku  v procentech     box on bottom lenght
  115.     IF BL > 100 THEN BL = 100
  116.  
  117.     BBL = boxl / 100 * BL
  118.  
  119.     'posuvnik                 Slider
  120.     LINE (Actual, Y + TextHeight + 5)-(Actual + BBL, Y + TextHeight * 2 - 3), White~&, BF
  121.     LINE (Actual, Y + TextHeight + 5)-(Actual + BBL, Y + TextHeight * 2 - 3), Grey2~&, B
  122.  
  123.  
  124.  
  125.     IF MX >= X AND MX <= X + _FONTWIDTH * TBA(nr).L THEN
  126.         IF MY >= Y + TextHeight + 5 AND MY <= Y + TextHeight * 2 - 3 THEN
  127.             IF MB1 THEN
  128.                 omx = MX
  129.                 DO UNTIL _MOUSEX <> MX
  130.                     WHILE _MOUSEINPUT: WEND
  131.                     MB1 = _MOUSEBUTTON(1)
  132.                     B = B + _MOUSEX - omx
  133.                 LOOP
  134.             END IF
  135.         END IF
  136.     END IF
  137.  
  138.  
  139.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1), TextBoxArrow&
  140.     _PUTIMAGE (X - 15, Y + TextHeight + 1)-(X - 27, Y + TextHeight + 1 + 12), TextBoxArrow&
  141.  
  142.     IF TIMER < 1 THEN TBA(nr).D = 0
  143.  
  144.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  145.         IF MY >= Y + 1 + TextHeight AND MY <= Y + TextHeight * 2 THEN
  146.             IF TBA(nr).D < TIMER THEN
  147.                 IF _PIXELSIZE = 4 THEN
  148.                     LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + TextHeight * 2), &H44FFFFFF, BF
  149.                 ELSE
  150.                     LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + TextHeight + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + TextHeight * 2), 14, B
  151.                 END IF
  152.                 IF MB1 THEN
  153.                     B = B + 1
  154.                 END IF
  155.                 TBA(nr).D = TIMER + .01
  156.             END IF
  157.         END IF
  158.     END IF
  159.  
  160.     IF MX >= X - 26 AND MX <= X - 15 THEN
  161.         IF MY >= Y + 1 + TextHeight AND MY <= Y + TextHeight * 2 THEN
  162.  
  163.             SELECT CASE _KEYHIT
  164.                 CASE 18176: B = 1
  165.                 CASE 20224: B = LEN(TBA(nr).T) - TBA(nr).L + 1
  166.                 CASE 18688: B = B - TBA(nr).L
  167.                 CASE 20736: B = B + TBA(nr).L
  168.             END SELECT
  169.  
  170.  
  171.             IF TBA(nr).D < TIMER THEN
  172.                 IF _PIXELSIZE = 4 THEN
  173.                     LINE (X - 26, Y + TextHeight + 1)-(X - 15, Y + TextHeight * 2), &H44FFFFFF, BF
  174.                 ELSE
  175.                     LINE (X - 26, Y + TextHeight + 1)-(X - 15, Y + TextHeight * 2), 14, B
  176.                 END IF
  177.                 IF MB1 THEN
  178.                     B = B - 1
  179.                 END IF
  180.                 TBA(nr).D = TIMER + .01
  181.             END IF
  182.         END IF
  183.     END IF
  184.  
  185.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  186.     IF B < 1 THEN B = 1
  187.     TBA(nr).B = B
  188.  
  189.     IF _PIXELSIZE = 4 THEN COLOR &HFFFFFFFF ELSE COLOR 15
  190.  
  191.  
  192.     FOR V = 1 TO LEN(TBA(nr).T)
  193.         FOR t = LBOUND(k) + 1 TO UBOUND(k)
  194.             IF k(t).flag = nr THEN
  195.                 IF V = k(t).onpos + 1 THEN COLOR k(t).clr: EXIT FOR
  196.             END IF
  197.         NEXT
  198.  
  199.         IF V >= B AND V <= B + TBA(nr).L THEN
  200.             _PRINTSTRING (X + (W * _FONTWIDTH), Y), MID$(TBA(nr).T, V, 1)
  201.             W = W + 1
  202.         END IF
  203.     NEXT
  204.  
  205.  
  206.  
  207. FUNCTION PutArrow&
  208.     IF _PIXELSIZE = 4 THEN
  209.         PutArrow& = _NEWIMAGE(12, 12, 32)
  210.     ELSE
  211.         PutArrow& = _NEWIMAGE(12, 12, 256)
  212.     END IF
  213.  
  214.     D = _DEST
  215.     _DEST PutArrow&
  216.  
  217.     LINE (1, 4)-(6, 4) '  ------------     up
  218.     LINE (1, 8)-(6, 8) '  ------------     down
  219.     LINE (1, 4)-(1, 8) '  I                arrow back
  220.     LINE (6, 4)-(6, 1)
  221.     LINE (6, 8)-(6, 11)
  222.     LINE (6, 11)-(11, 6)
  223.     LINE (6, 1)-(11, 6)
  224.  
  225.     IF _PIXELSIZE(D) = 4 THEN PAINT (6, 6), &HFF777777, &HFFFFFFFF ELSE PAINT (6, 6), 10, 15
  226.     IF _PIXELSIZE(D) = 4 THEN _CLEARCOLOR &HFF000000, PutArrow& ELSE _CLEARCOLOR 0, PutArrow&
  227.     _DEST D
  228.  
  229. SUB CString (source AS STRING, text AS STRING, K() AS Colored, index AS INTEGER)
  230.     FOR S = 1 TO LEN(source$)
  231.         t$ = MID$(source$, S, 1)
  232.         IF ASC(t$) >= 48 AND ASC(t$) <= 57 AND incolor THEN colornr$ = colornr$ + t$
  233.         IF incolor AND ASC(t$) < 48 OR incolor AND ASC(t$) > 57 THEN K(kk).clr = VAL(colornr$): D = D + LEN(colornr$): colornr$ = "": incolor = 0
  234.         IF t$ = "/" THEN
  235.             D = D + 1
  236.             incolor = 1
  237.             REDIM _PRESERVE K(UBOUND(k) + 1) AS Colored
  238.             kk = UBOUND(k)
  239.             K(kk).onpos = S - D
  240.             K(kk).flag = index
  241.         END IF
  242.         IF incolor = 0 THEN text$ = text$ + t$
  243.     NEXT
  244.  
  245. 'End of future "TextBox.BM"
  246.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

There are two known flies. One - the slider position calculation is not entirely accurate. I really don't want to deal with it. Second - if the color definition starts outside the displayed part in the X / Y slider, it is displayed in white. This is what I want to solve, and I'll solve it sometime.... not today.
Title: Re: Scroll Bar
Post by: TempodiBasic on September 30, 2019, 05:10:29 pm
waiting news...
Title: Re: Scroll Bar
Post by: bplus on October 01, 2019, 06:58:17 pm
Congrats Petr!

I just have worked out all the bugs in mine. I use the whole box as a 2D scroll bar with mouse clicks or down and drag.
Like in my hScroller, I use indicator bars around the box to show the location of text left and right and top to bottom.

I will post code later when I get more than 2D text boxes going.

PS 317 lines so far ;-))

Title: Re: Scroll Bar
Post by: TempodiBasic on October 01, 2019, 08:39:18 pm
Well it seems that here we'll have 3 good tool for textbox with scrolling both as single line both as multiline!
Great work
Title: Re: Scroll Bar
Post by: Petr on October 02, 2019, 08:04:52 am
Quote
BPlus wrote:

I will post code later when I get more than 2D text boxes going.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Quote
PS 317 lines so far ;-))

Yes, without coloring text ;)

TempodiBasic wrote:

Quote
waiting news...
Which?

The color correction (bug repair), about which write on top, is done. I will release another fix as soon as it is time to put it into the program :)
Title: Re: Scroll Bar
Post by: Petr on October 02, 2019, 08:22:23 am
BPlus, there are many options that lead to huge programs with complexity. For example. Someone already solved it but not in the textbox - text and image insertion. This can be done by adding another command (so as is "/") to the text loop. Maybe I'll try. If I am now using the tag / for the color command, I add another one, with the width, height, and name of the image, and then the position of the image in the textbox must follow. This is an example. Or - something lighter - a tag to set the color and transparency of the window background. It kind of starts to remind me of HTML ...

But still. First, I fix the current bugs, only then, maybe I'll try more.

Title: Re: Scroll Bar
Post by: bplus on October 02, 2019, 08:46:03 am
Quote
Yes, without coloring text ;)

I am coloring only the Box in focus, using Tab or Shift + Tab or Mouse over to change Box in focus for mouse or key input.

In screen shot you can see another box in focus, lit up Green background light Blue fore.
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Dang! another bug!
Title: Re: Scroll Bar
Post by: STxAxTIC on October 02, 2019, 09:02:41 am
Beautiful 3d screenshot bplus. I pulled this off once and posted at *.not, but the community was, um, not interested. Let's hope you catch more attention!
Title: Re: Scroll Bar
Post by: bplus on October 02, 2019, 09:14:13 am
Beautiful 3d screenshot bplus. I pulled this off once and posted at *.not, but the community was, um, not interested. Let's hope you catch more attention!

Hi STxAxTIC,

Not sure if you mean the little text indicator bars of my screen shot or Petr's screen shot of "swinging door open" like screen, an effect I like very much. :)
Title: Re: Scroll Bar
Post by: TempodiBasic on October 02, 2019, 09:24:38 am
Well I see news coming often in this thread!
Great job boys!
Title: Re: Scroll Bar
Post by: STxAxTIC on October 03, 2019, 10:21:25 am
Oh oops thats what I get for doing this while driving. Yes, the scrollbars are mad awesome. I admit I scrolled too fast and saw it was Petr that cranked out the tilted screenshot. Nice work both of you though. It's better than mine looked like, and Galleon even complemented it. He'd be even more impressed by you guys.
Title: Re: Scroll Bar
Post by: Petr on October 04, 2019, 01:36:29 pm
Hi. Yeah, 3D... i create also one for you, current version works but from keyboard only, that is not enought. I add 3D version here later (in better graphic).

 This next here is 2D, which can be placed really in many copyes to screen, contains color bug repair.

1980x1050 on screen resolution recommended.

Code: QB64: [Select]
  1.  
  2.  
  3. 'this is future "TextBox.BI"
  4. TYPE Colored '                      This Array contains colors positions on text and color values. This array is created in SUB CString.
  5.     onpos AS INTEGER
  6.     clr AS _UNSIGNED LONG
  7.     flag AS INTEGER
  8.     row AS INTEGER
  9. REDIM SHARED k(0) AS Colored
  10.  
  11. TYPE TB2
  12.     X AS INTEGER '   X position graphic coord
  13.     Y AS INTEGER '   Y position graphic coord
  14.     L AS INTEGER '   TextBox lenght
  15.     H AS INTEGER '   Textbox HEIGHT                                            NEW
  16.     T AS STRING * 1 '    TextBox text
  17.     B AS INTEGER '   Text begin in textbox  (for shift), X axis
  18.     BH AS INTEGER '  Text begin in textbox  (for shift), Y axis                NEW
  19.  
  20.     D AS SINGLE '    for time delay between click to arrows
  21.     I_s AS INTEGER
  22.     I_e AS INTEGER
  23.     filter AS _BYTE 'new info flag for CString, which is needed just in the start, but not more.
  24.     init AS _BYTE
  25.  
  26. REDIM SHARED TBA2(0) AS TB2
  27. REDIM SHARED GlobalText(0) AS STRING 'spolecne obrovske textove pole obsahujici texty pro vsechna okna vcetne udaju o barvach
  28. DIM SHARED Arrow0 AS LONG, Arrow1 AS LONG, Arrow2 AS LONG, Arrow3 AS LONG
  29.  
  30.  
  31. SCREEN _NEWIMAGE(1980, 1050, 256) 'screen must be initialized before PutArrow& is run.
  32. Arrow0 = PutArrow
  33. R90 Arrow0, Arrow1, Arrow2, Arrow3 'create four arrows in four directions from first source image
  34. 'end of future "TextBox.BI"
  35.  
  36.  
  37.  
  38.  
  39. DIM Text1(7) AS STRING
  40. DIM Text2(14) AS STRING
  41.  
  42. Text1(1) = "/14This is content /1for /2array /3Text1. Original and source text array content is in"
  43. Text1(2) = "/44array Text1. Because Petr can just 2 ways (first: MEM Pointer to array insert"
  44. Text1(3) = "/45to type), or second, easyest - all texts insert to one STRING SHARED array, and"
  45. Text1(4) = "/46writing informations about start and end index to TYPE, is now this text also"
  46. Text1(5) = "/47inserted to array named as GlobalText. Because this text contains 7 rows and "
  47. Text1(6) = "/48Text1 array is inserted as first, is this saved in indexes 0 to 6 in array"
  48. Text1(7) = "/49GlobalText. Info about this records are here saved to TBA2().I_s and TBA2().I_e"
  49.  
  50.  
  51.  
  52. Text2(1) = "                /14   Example for use:"
  53. Text2(2) = "/45With /40'/90/'/40 /45and then number you set colors. If you use _SCREEN _NEWIMAGE in 256 colors,"
  54. Text2(3) = "then use number from 0 to 256. But if you use 32 bit screen, then dont use &H values but"
  55. Text2(4) = "/50 number. This number can be returned using this easy source code:"
  56. Text2(5) = "/55 COLOR~& = &HFFFFFFFF  /60 or /55 COLOR~& = _RGBA32(255, 255, 255)"
  57. Text2(6) = "PRINT COLOR~&. /60 This is number, which you need for use to 32 bit screens with this"
  58. Text2(7) = "easy program. (i write soon automatic translator for it, but with my time....)/9"
  59. Text2(8) = "Program construction: - All strings are saved to array /14 GlobalText."
  60. Text2(9) = "                     /9 - Function /14R90/9 create 4 images which contains rows, rotated from 1"
  61. Text2(10) = "                       source image, which is created with Function /14PutArrow./9"
  62. Text2(11) = "                     - /14CString /9SUB create help array for colors used in text to array /14K/9."
  63. Text2(12) = "                     - /14MaximalRowLenght/9 Function return lenght of longest row in text array."
  64. Text2(13) = "                     - Function /14INITBOX2/9 write all needed records to program arrays and return record number."
  65. Text2(14) = "                     - /14XY_BOX /9SUB - own program. Study it /33yourself /40:-)"
  66.  
  67.  
  68.  
  69. DIM boxes(35)
  70.  
  71. FOR B1 = 1 TO 10
  72.     boxes(B1) = INITBOX2(-158 + 198 * B1, 50, Text1(), 17, 10)
  73.  
  74. FOR B1 = 11 TO 20
  75.     boxes(B1) = INITBOX2(-158 + 198 * (-10 + B1), 250, Text2(), 17, 10)
  76.  
  77. FOR B1 = 21 TO 30
  78.     boxes(B1) = INITBOX2(-158 + 198 * (-20 + B1), 450, Text1(), 17, 15)
  79.  
  80. co = 40
  81. FOR B1 = 31 TO 35
  82.     boxes(B1) = INITBOX2(co, 700, Text2(), 35, 20)
  83.     co = co + 400
  84.  
  85.  
  86.  
  87.  
  88.     FOR B1 = 1 TO 10
  89.         XY_BOX boxes(B1)
  90.     NEXT
  91.  
  92.     FOR B1 = 11 TO 20
  93.         XY_BOX boxes(B1)
  94.     NEXT
  95.  
  96.     FOR B1 = 21 TO 30
  97.         XY_BOX boxes(B1)
  98.     NEXT
  99.  
  100.     FOR B1 = 31 TO 35
  101.         XY_BOX boxes(B1)
  102.     NEXT
  103.  
  104.     _DISPLAY
  105.     _LIMIT 60
  106.  
  107.  
  108.  
  109. 'this is future "TextBox.BM"
  110. FUNCTION INITBOX2 (X AS INTEGER, Y AS INTEGER, Text() AS STRING, BoxLenght AS INTEGER, BoxHeight AS INTEGER) 'X, Y are GRAPHIC coordinates
  111.     UTB = UBOUND(tba2)
  112.     REDIM _PRESERVE TBA2(UTB + 1) AS TB2
  113.     TBA2(UTB + 1).X = X
  114.     TBA2(UTB + 1).Y = Y
  115.     TBA2(UTB + 1).L = BoxLenght
  116.     TBA2(UTB + 1).H = BoxHeight
  117.  
  118.  
  119.  
  120.  
  121.     TBA2(UTB + 1).T = ""
  122.     U1 = UBOUND(globaltext)
  123.     U2 = UBOUND(text)
  124.  
  125.     TBA2(UTB + 1).I_s = U1
  126.     TBA2(UTB + 1).I_e = U1 + U2
  127.  
  128.     REDIM _PRESERVE GlobalText(U1 + U2 + 1) AS STRING
  129.  
  130.     FOR insert = U1 TO U1 + U2
  131.         GlobalText(insert) = Text(t)
  132.         t = t + 1
  133.     NEXT
  134.  
  135.     TBA2(UTB + 1).BH = U1 + 1 'after first start: first row (BH is shift in Y, B is shift in X axis)
  136.     TBA2(UTB + 1).B = 1 'and first column
  137.     INITBOX2 = UTB + 1
  138.  
  139.  
  140. SUB XY_BOX (nr AS LONG)
  141.  
  142.  
  143.         mwh = mwh + _MOUSEWHEEL
  144.         IF mwh THEN EXIT WHILE
  145.     WEND
  146.  
  147.  
  148.     '
  149.     MB1 = _MOUSEBUTTON(1)
  150.     MX = _MOUSEX
  151.     MY = _MOUSEY
  152.     RowLen = MaximalRowLenght(nr)
  153.     TextLenght = RowLen * _FONTWIDTH
  154.     B = TBA2(nr).B
  155.     BH = TBA2(nr).BH
  156.  
  157.     TextHeight = _FONTHEIGHT
  158.     X = TBA2(nr).X
  159.     Y = TBA2(nr).Y
  160.     BoxLenght = TBA2(nr).L - 2
  161.     BoxHeight = 1 + TBA2(nr).H * _FONTHEIGHT
  162.     Init = TBA2(nr).init
  163.  
  164.  
  165.     IF MX >= X - 30 AND MX <= X + 30 + (BoxLenght + 2) * _FONTWIDTH THEN
  166.         IF MY >= Y - 30 AND MY <= Y + BoxHeight THEN
  167.             onpos = 1
  168.         END IF
  169.     END IF
  170.  
  171.     IF Init = 0 OR onpos THEN
  172.  
  173.  
  174.  
  175.         '256/32 color support:
  176.  
  177.         SELECT CASE _PIXELSIZE
  178.             CASE 0: BEEP: PRINT "Text mode not supported by PRINTBOX!": _DISPLAY: SLEEP 3: END
  179.             CASE 1
  180.                 Black~& = 0
  181.                 White~& = 15
  182.                 Grey~& = 24
  183.                 Grey2~& = 19
  184.             CASE 4
  185.                 Black~& = &HFF000000
  186.                 White~& = &HFFFFFFFF
  187.                 Grey~& = &H226666666
  188.                 Grey2~& = &HFF221122
  189.         END SELECT
  190.  
  191.  
  192.         RowLen = MaximalRowLenght(nr)
  193.         TextLenght = RowLen * _FONTWIDTH
  194.         B = TBA2(nr).B
  195.         BH = TBA2(nr).BH
  196.  
  197.         TextHeight = _FONTHEIGHT
  198.         X = TBA2(nr).X
  199.         Y = TBA2(nr).Y
  200.         BoxLenght = TBA2(nr).L - 2
  201.         BoxHeight = 1 + TBA2(nr).H * _FONTHEIGHT
  202.  
  203.         '        WHILE _MOUSEINPUT:
  204.         '        mwh = mwh + _MOUSEWHEEL
  205.         '            IF mwh THEN EXIT WHILE
  206.         '        WEND
  207.  
  208.         '        IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  209.         '        IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + 2 * TextHeight THEN
  210.         '        B = B + mwh * 4
  211.         '    END IF
  212.         '    END IF
  213.  
  214.  
  215.         '
  216.         '       MB1 = _MOUSEBUTTON(1)
  217.         '       MX = _MOUSEX
  218.         '       MY = _MOUSEY
  219.  
  220.  
  221.  
  222.  
  223.         LINE (X - 30, Y)-(X + 30 + BoxLenght * _FONTWIDTH, Y + BoxHeight), Grey~&, BF 'vnitrek okna                                   window inside
  224.         LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + BoxHeight), White~&, B
  225.         LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + BoxHeight - TextHeight), White~&, B
  226.  
  227.         'borders for lines up / down
  228.         LINE (X + 30 + BoxLenght * _FONTWIDTH, Y - 1)-(X + 11 + BoxLenght * _FONTWIDTH, Y + BoxHeight - TextHeight), White~&, B
  229.  
  230.  
  231.         '  slider X calculations. For calculating slider lenght you need the number of characters of the longest sentence used in the box. MaximalRowLenght function return it:
  232.         '////////////////////////////////////////////////////////
  233.         TL = B / RowLen * 100 'pocatecni poloha pruhu v procentech            begining position for bottom box (percentually)
  234.         L = TBA2(nr).L * _FONTWIDTH 'celkova delka pruhu v pixelech           total slide lenght in pixels
  235.         Actual = _CEIL(X + (TL / 100 * L)) '                                  graphic position for bottom box
  236.         boxl = BoxLenght * _FONTWIDTH
  237.         BL = boxl / (TextLenght / 100) 'delka posuvneho boxiku  v procentech     box on bottom lenght  (how it is done: Slider lenght is percentually size as window bottom (for X - Shift).
  238.         '                                                                        if 30 percent of the sentence length is visible in the window, then the slider is 30 percent of the length of the X-side this window
  239.         IF BL > 100 THEN BL = 100 '                                              if text lenght < window X side, draw slider as 100 percent of X window side
  240.  
  241.         BBL = boxl / 100 * BL
  242.  
  243.         'posuvnik X        Slider X
  244.         LINE (Actual, Y + BoxHeight - TextHeight + 5)-(Actual + BBL, Y + BoxHeight - TextHeight + 12), White~&, BF
  245.         LINE (Actual, Y + BoxHeight - TextHeight + 5)-(Actual + BBL, Y + BoxHeight - TextHeight + 12), Grey2~&, B
  246.         '////////////////////////////////////////////////////////////
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.         'slider Y (the same os for X slider)
  254.         DelkaSteny = BoxHeight - TextHeight - (2 * _FONTHEIGHT) - 2
  255.         ZaznamuNaStenu = DelkaSteny / _FONTHEIGHT
  256.         Zaznamu100 = ZaznamuNaStenu / (TBA2(nr).I_e - TBA2(nr).I_s) * 100
  257.         BBH = (Zaznamu100 / 100) * DelkaSteny
  258.         IF BBH > DelkaSteny THEN BBH = DelkaSteny
  259.  
  260.         Pozice = 1 + (BH - TBA2(nr).I_e) / TBA2(nr).I_e
  261.         actualH = Y + _FONTHEIGHT + ((DelkaSteny - BBH) * Pozice)
  262.  
  263.  
  264.         'posuvnik Y        Slider Y
  265.         LINE (TBA2(nr).X + TBA2(nr).L * _FONTWIDTH, actualH)-(TBA2(nr).X + TBA2(nr).L * _FONTWIDTH + 7, actualH + BBH), White~&, BF
  266.         LINE (TBA2(nr).X + TBA2(nr).L * _FONTWIDTH, actualH)-(TBA2(nr).X + TBA2(nr).L * _FONTWIDTH + 7, actualH + BBH), Grey2~&, B
  267.  
  268.  
  269.  
  270.         ' solution for moving text by click + move to down box
  271.         IF MX >= X AND MX <= X + _FONTWIDTH * (TBA2(nr).L - 2) THEN
  272.             IF MY >= Y + BoxHeight - TextHeight AND MY <= Y + BoxHeight THEN
  273.                 IF MB1 THEN
  274.                     omx = MX
  275.                     DO UNTIL _MOUSEX <> MX
  276.                         WHILE _MOUSEINPUT: WEND
  277.                         MB1 = _MOUSEBUTTON(1)
  278.                         B = B + _MOUSEX - omx
  279.                     LOOP
  280.                 END IF
  281.             END IF
  282.         END IF
  283.  
  284.         ' solution for moving text up and down by clicking and move to box on right
  285.         IF MX >= X + 10 + BoxLenght * _FONTWIDTH AND MX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  286.             IF MY >= Y + 16 AND MY <= Y + BoxHeight - 40 THEN
  287.                 IF MB1 THEN
  288.                     omy = MY
  289.                     DO UNTIL _MOUSEY <> MY
  290.                         WHILE _MOUSEINPUT: WEND
  291.                         MB1 = _MOUSEBUTTON(1)
  292.                         BH = BH + _MOUSEY - omy
  293.                     LOOP
  294.                 END IF
  295.             END IF
  296.         END IF
  297.  
  298.         ABY = Y + 2 + BoxHeight - TextHeight '                  ArrowBottomY coordinate
  299.         LUPAC = X + 15 + BoxLenght * _FONTWIDTH '               Left UP/Down Arrow coordinate
  300.  
  301.         _PUTIMAGE (LUPAC, ABY), Arrow0& '                              Arrow to right
  302.         _PUTIMAGE (X - 27, ABY + 1), Arrow1& '                                  left
  303.         _PUTIMAGE (LUPAC, Y + 2), Arrow3& '                                     up
  304.         _PUTIMAGE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2)), Arrow2& '     down
  305.  
  306.         IF TIMER < 1 THEN TBA2(nr).D = 0
  307.  
  308.         'driving up arrow
  309.         IF MX >= LUPAC AND MX <= LUPAC + 12 THEN
  310.             IF MY >= Y + 2 AND MY <= Y + 14 THEN
  311.                 IF TBA2(nr).D < TIMER THEN
  312.                     IF _PIXELSIZE = 4 THEN
  313.                         LINE (LUPAC, Y + 2)-(LUPAC + 12, Y + 14), &H44FFFFFF, BF
  314.                     ELSE
  315.                         LINE (LUPAC, Y + 2)-(LUPAC + 12, Y + 14), 14, B
  316.                     END IF
  317.                     IF MB1 THEN BH = BH - 1
  318.                     TBA2(nr).D = TIMER + .01
  319.                     MB1 = 0
  320.                 END IF
  321.             END IF
  322.         END IF
  323.  
  324.         'driving down arrow
  325.         IF MX >= LUPAC - 1 AND MX <= LUPAC + 11 THEN
  326.             IF MY >= Y + TextHeight * (TBA2(nr).H - 2) AND MY <= 12 + Y + TextHeight * (TBA2(nr).H - 2) THEN
  327.                 IF TBA2(nr).D < TIMER THEN
  328.                     IF _PIXELSIZE = 4 THEN
  329.                         LINE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2))-(LUPAC + 11, 12 + Y + TextHeight * (TBA2(nr).H - 2)), &H44FFFFFF, BF
  330.                     ELSE
  331.                         LINE (LUPAC - 1, Y + TextHeight * (TBA2(nr).H - 2))-(LUPAC + 11, 12 + Y + TextHeight * (TBA2(nr).H - 2)), 14, B
  332.                     END IF
  333.                     IF MB1 THEN BH = BH + 1
  334.                     TBA2(nr).D = TIMER + .01
  335.                     MB1 = 0
  336.                 END IF
  337.             END IF
  338.         END IF
  339.  
  340.  
  341.  
  342.         'driving right arrow on bottom
  343.         IF MX >= LUPAC AND MX <= LUPAC + 12 THEN
  344.             IF MY >= ABY AND MY <= ABY + 12 THEN
  345.  
  346.                 IF TBA2(nr).D < TIMER THEN
  347.                     IF _PIXELSIZE = 4 THEN
  348.                         LINE (LUPAC, ABY)-(LUPAC + 12, ABY + 12), &H44FFFFFF, BF
  349.                     ELSE
  350.                         LINE (LUPAC, ABY)-(LUPAC + 12, ABY + 12), 14, B
  351.                     END IF
  352.                     IF MB1 THEN
  353.                         B = B + 1
  354.                         MB1 = 0
  355.                         TBA2(nr).D = TIMER + .01
  356.                     END IF
  357.                 END IF
  358.             END IF
  359.         END IF
  360.  
  361.         'driving left arrow on bottom
  362.         IF MX >= X - 27 AND MX <= X - 15 THEN '12 + 15 = 27, 12 is arrow width
  363.             IF MY >= ABY + 1 AND MY <= ABY + 13 THEN
  364.                 IF TBA2(nr).D < TIMER THEN
  365.                     IF _PIXELSIZE = 4 THEN
  366.                         LINE (X - 27, ABY + 1)-(X - 15, ABY + 13), &H44FFFFFF, BF
  367.                     ELSE
  368.  
  369.                         LINE (X - 27, ABY + 1)-(X - 15, ABY + 13), 14, B
  370.                     END IF
  371.                     IF MB1 THEN
  372.                         B = B - 1
  373.                         MB1 = 0
  374.                         TBA2(nr).D = TIMER + .01
  375.                     END IF
  376.                 END IF
  377.             END IF
  378.         END IF
  379.  
  380.  
  381.         'new: left - right keyboard driving:       (home, end, pg up, pg dn, insert (not edit), delete (not edit), arrows up, down, left, right)
  382.         IF MX >= X - 30 AND MX <= X + BoxLenght * _FONTWIDTH + 30 THEN
  383.             IF MY > Y AND MY <= Y + BoxHeight THEN
  384.  
  385.                 KH& = _KEYHIT
  386.                 IF KH& THEN
  387.                     SELECT CASE KH&
  388.                         CASE 18176: B = 1
  389.                         CASE 20224: B = RowLen - TBA2(nr).L + 1
  390.                         CASE 18688: B = B - TBA2(nr).L ' PgUP
  391.                         CASE 20736: B = B + TBA2(nr).L ' PgDN
  392.                         CASE 19200: B = B - 1 '          left
  393.                         CASE 19712: B = B + 1 '          right
  394.                         CASE 18432: BH = BH - 1 '        up
  395.                         CASE 20480: BH = BH + 1 '         down
  396.                         CASE 20992: BH = BH + TBA2(nr).H 'insert
  397.                         CASE 21428: BH = BH - TBA2(nr).H 'delete
  398.                     END SELECT
  399.                     _KEYCLEAR
  400.                 END IF
  401.  
  402.             END IF
  403.         END IF
  404.  
  405.         IF BH < TBA2(nr).I_s THEN BH = TBA2(nr).I_s
  406.         IF BH > TBA2(nr).I_e THEN BH = TBA2(nr).I_e
  407.  
  408.  
  409.         IF B > RowLen - TBA2(nr).L + 1 THEN B = RowLen - TBA2(nr).L + 1
  410.         IF B < 1 THEN B = 1
  411.  
  412.         TBA2(nr).B = B '      B is variable for shift left and right
  413.         TBA2(nr).BH = BH '    BH is variable for shift up and down
  414.  
  415.         IF _PIXELSIZE = 4 THEN COLOR &HFFFFFFFF ELSE COLOR 15
  416.  
  417.         IF TBA2(nr).filter = 0 THEN CString k(), nr: TBA2(nr).filter = 1 'and this is row, which AGAIN find me STRING BUG. Nr is not correct, if is STRING without star used!
  418.  
  419.  
  420.         BHE = BH + TBA2(nr).H - 2
  421.         IF BHE > TBA2(nr).I_e THEN BHE = TBA2(nr).I_e
  422.  
  423.  
  424.         'coloring and printing content
  425.  
  426.  
  427.         'first line invalid color bug repair
  428.         FOR t = LBOUND(k) + 1 TO UBOUND(k)
  429.             IF k(t).flag = nr THEN
  430.                 IF k(t).row < BH THEN kkk~& = k(t).clr
  431.             END IF
  432.         NEXT
  433.         COLOR kkk~&
  434.  
  435.  
  436.  
  437.         FOR Rows = BH TO BHE
  438.             FOR v = 1 TO RowLen
  439.                 FOR t = LBOUND(k) + 1 TO UBOUND(k)
  440.                     IF k(t).flag = nr THEN '               here is repaired color bug.
  441.                         IF Rows = k(t).row THEN
  442.                             IF v = k(t).onpos + 1 THEN COLOR k(t).clr: EXIT FOR
  443.                         END IF
  444.                     END IF
  445.                 NEXT
  446.                 IF v >= B AND v <= B + TBA2(nr).L THEN
  447.                     _PRINTSTRING (X - 20 + (w * _FONTWIDTH), Y + (Rows - BH) * _FONTHEIGHT), MID$(GlobalText(Rows), v, 1)
  448.                     w = w + 1
  449.                 END IF
  450.             NEXT
  451.             w = 0
  452.         NEXT Rows
  453.  
  454.  
  455.         TBA2(nr).init = 1
  456.     END IF
  457.  
  458.  
  459.  
  460.  
  461.  
  462. FUNCTION PutArrow&
  463.     IF _PIXELSIZE = 4 THEN
  464.         PutArrow& = _NEWIMAGE(12, 12, 32)
  465.     ELSE
  466.         PutArrow& = _NEWIMAGE(12, 12, 256)
  467.     END IF
  468.  
  469.     D = _DEST
  470.     _DEST PutArrow&
  471.  
  472.     LINE (1, 4)-(6, 4)
  473.     LINE (1, 8)-(6, 8)
  474.     LINE (1, 4)-(1, 8)
  475.     LINE (6, 4)-(6, 1)
  476.     LINE (6, 8)-(6, 11)
  477.     LINE (6, 11)-(11, 6)
  478.     LINE (6, 1)-(11, 6)
  479.  
  480.     IF _PIXELSIZE(D) = 4 THEN PAINT (6, 6), &HFF777777, &HFFFFFFFF ELSE PAINT (6, 6), 10, 15
  481.     IF _PIXELSIZE(D) = 4 THEN _CLEARCOLOR &HFF000000, PutArrow& ELSE _CLEARCOLOR 0, PutArrow&
  482.     _DEST D
  483.  
  484.  
  485. SUB CString (K() AS Colored, index AS INTEGER)
  486.     FOR rows = TBA2(index).I_s TO TBA2(index).I_e
  487.         source$ = GlobalText(rows)
  488.         FOR S = 1 TO LEN(source$)
  489.             old$ = t$
  490.             t$ = MID$(source$, S, 1)
  491.             IF ASC(t$) >= 48 AND ASC(t$) <= 57 AND incolor THEN colornr$ = colornr$ + t$
  492.             IF incolor AND ASC(t$) < 48 OR incolor AND ASC(t$) > 57 THEN
  493.                 K(kk).clr = VAL(colornr$): D = D + LEN(colornr$): colornr$ = "": incolor = 0
  494.                 IF old$ = "/" THEN text$ = text$ + old$
  495.             END IF
  496.  
  497.             IF t$ = "/" THEN
  498.                 D = D + 1
  499.                 incolor = 1
  500.                 REDIM _PRESERVE K(UBOUND(k) + 1) AS Colored
  501.                 kk = UBOUND(k)
  502.                 K(kk).onpos = S - D
  503.                 K(kk).flag = index
  504.                 K(kk).row = rows
  505.             END IF
  506.             IF incolor = 0 THEN text$ = text$ + t$
  507.         NEXT
  508.  
  509.         GlobalText(rows) = text$
  510.         text$ = ""
  511.         ind = ind + 1
  512.         D = 0
  513.     NEXT rows
  514.  
  515.  
  516. SUB R90 (img0 AS LONG, img1 AS LONG, img2 AS LONG, img3 AS LONG) 'create 4 arrows from one in four directions
  517.     IF img0 >= -1 THEN EXIT SUB 'source image is invalid
  518.     W = _WIDTH(img0)
  519.     H = _HEIGHT(img0)
  520.     P = _PIXELSIZE(img0)
  521.     DIM CC AS _UNSIGNED LONG
  522.  
  523.     SELECT CASE P
  524.         CASE 0: EXIT SUB 'text mode unsupported
  525.         CASE 1: D = 256: CC = 0
  526.         CASE 4: D = 32: CC = &HFF000000
  527.     END SELECT
  528.  
  529.     img1 = _NEWIMAGE(W, H, D)
  530.     _PUTIMAGE , img0, img1, (W, 1)-(1, H) '180 degrees rotating
  531.  
  532.     img2 = _NEWIMAGE(H, W, D) '            90
  533.     _MAPTRIANGLE (0, 0)-(W, 0)-(W, H), img0 TO(H, 0)-(H, W)-(0, W), img2
  534.     _MAPTRIANGLE (0, 0)-(W, H)-(0, H), img0 TO(H, 0)-(0, W)-(0, 0), img2
  535.  
  536.     img3 = _NEWIMAGE(H, W, D)
  537.     _PUTIMAGE , img2, img3, (1, W)-(H, 1) '270
  538.     _CLEARCOLOR CC, img1
  539.     _CLEARCOLOR CC, img2
  540.     _CLEARCOLOR CC, img3
  541.  
  542. FUNCTION MaximalRowLenght (i)
  543.     MaximalRowLenght = 0
  544.     REDIM test(0) AS STRING
  545.     ClearColorRecordsAndVauesFromTextArray TBA2(i).I_s, TBA2(i).I_e, test()
  546.  
  547.     FOR p = LBOUND(test) TO UBOUND(test)
  548.         IF MaximalRowLenght < LEN(test(p)) THEN MaximalRowLenght = LEN(test(p))
  549.     NEXT
  550.  
  551. SUB ClearColorRecordsAndVauesFromTextArray (start, eend, arrname() AS STRING) 'If we need find maximal row lenght, first must color tags be deleted from text.
  552.     REDIM arrname(eend - start) AS STRING
  553.     FOR c = start TO eend
  554.         FOR L = 1 TO LEN(GlobalText(c))
  555.             ch$ = MID$(GlobalText(c), L, 1)
  556.             IF ch$ = "/" THEN iscolor = 1
  557.             IF iscolor AND ASC(ch$) > 47 AND ASC(ch$) < 58 THEN ELSE t$ = t$ + ch$
  558.             IF iscolor AND ASC(ch$) < 47 OR iscolor AND ASC(ch$) > 58 THEN
  559.                 iscolor = 0
  560.             END IF
  561.         NEXT
  562.         arrname(c - start) = t$
  563.         t$ = ""
  564.     NEXT c
  565.  
  566. 'End of future "TextBox.BM"
  567.  


Program output:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Scroll Bar
Post by: SMcNeill on October 04, 2019, 10:58:46 pm
Here’s an idea I just had for a 3D window:  Us OpenGL to map textures of segments an image to a cube.  Let the “sliders” rotate the cube left/right, up/down...  It’d basically scroll a screen of text at a time...

If I find time, while the concept is fresh in my head, I might take a shot at having fun and doing it, but you guys are also free to have fun with it if you want.  I think it’d make a cute little 3D- scroller.  😁