Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop Down Menu
#1
Here is a bare bones of a drop down menu which I have been using. I have had to use a Slowing value to smooth out the speed at which the drop down occurs. I was wondering if there might be a better way to control the speed.

Cls
Screen _NewImage(1200, 900, 32)
Dim Shared DarkGreen&
Dim Shared Yellow&
Dim Shared Pink&
DarkGreen& = _RGB32(0, 129, 0)
Yellow& = _RGB(255, 255, 0)
Pink& = _RGB(216, 50, 166)


'Large background box
Line (0, 0)-(1199, 50), Pink&, BF
Sleep
c1 = 7
r1 = 7
c2 = 126
r2 = 46
'The 5 smaller box
Line (c1, r1)-(c2, r2), DarkGreen&, BF

r1 = 51
r2 = 93
'The Drop Down
For DDwn = 1 To 25
    Color Yellow&
    _PrintString (12, 15), "Opening Info"
    Line (c1, r1)-(c2, r2), DarkGreen&, BF
    For slow = 1 To 10000000: Next
    r1 = r1 + DDwn
    r2 = r2 + DDwn
Next
Sleep
Reply
#2
Instead of something like:

For slow = 1 To 10000000: Next

Use something which isn't going to depend upon the speed of the users PC to just add numbers in a loop. I'd suggest _LIMIT or _DELAY.
Reply
#3
Use _DELAY for these types of issues...

Code: (Select All)
CLS
SCREEN _NEWIMAGE(1200, 900, 32)
DIM SHARED DarkGreen&
DIM SHARED Yellow&
DIM SHARED Pink&
DarkGreen& = _RGB32(0, 129, 0)
Yellow& = _RGB(255, 255, 0)
Pink& = _RGB(216, 50, 166)


'Large background box
LINE (0, 0)-(1199, 50), Pink&, BF
SLEEP
c1 = 7
r1 = 7
c2 = 126
r2 = 46
'The 5 smaller box
LINE (c1, r1)-(c2, r2), DarkGreen&, BF

r1 = 51
r2 = 93
'The Drop Down
FOR DDwn = 1 TO 25
    COLOR Yellow&
    _PRINTSTRING (12, 15), "Opening Info"
    LINE (c1, r1)-(c2, r2), DarkGreen&, BF
    _DELAY .05 ' <============================== Change the value to increase or decrease the delay time.
    r1 = r1 + DDwn
    r2 = r2 + DDwn
NEXT
SLEEP

Pete
Shoot first and shoot people who ask questions, later.
Reply
#4
Another fun one is TIMER.

Code: (Select All)
CLS
SCREEN _NEWIMAGE(1200, 900, 32)
DIM SHARED DarkGreen&
DIM SHARED Yellow&
DIM SHARED Pink&
DarkGreen& = _RGB32(0, 129, 0)
Yellow& = _RGB(255, 255, 0)
Pink& = _RGB(216, 50, 166)


'Large background box
LINE (0, 0)-(1199, 50), Pink&, BF
SLEEP
c1 = 7
r1 = 7
c2 = 126
r2 = 46
'The 5 smaller box
LINE (c1, r1)-(c2, r2), DarkGreen&, BF

r1 = 51
r2 = 93
'The Drop Down

mydelay = .05 ' <====================
z = TIMER ' <====================

FOR DDwn = 1 TO 25
    COLOR Yellow&
    _PRINTSTRING (12, 15), "Opening Info"
    LINE (c1, r1)-(c2, r2), DarkGreen&, BF
    DO
        _LIMIT 30 ' Cuts down on CPU usage.
        IF z > TIMER THEN z = z - 86400 ' Midnight adjustment.
        IF TIMER - z > mydelay THEN z = TIMER: EXIT DO
        ' Note: You could do other stuff here you couldn't do if a _DELAY statement was used.
    LOOP
    r1 = r1 + DDwn
    r2 = r2 + DDwn
NEXT
SLEEP
Shoot first and shoot people who ask questions, later.
Reply
#5
Now let' take the last example and use it as a GOSUB...

Code: (Select All)
CLS
SCREEN _NEWIMAGE(1200, 900, 32)
DIM SHARED DarkGreen&
DIM SHARED Yellow&
DIM SHARED Pink&
DarkGreen& = _RGB32(0, 129, 0)
Yellow& = _RGB(255, 255, 0)
Pink& = _RGB(216, 50, 166)


'Large background box
LINE (0, 0)-(1199, 50), Pink&, BF
SLEEP
c1 = 7
r1 = 7
c2 = 126
r2 = 46
'The 5 smaller box
LINE (c1, r1)-(c2, r2), DarkGreen&, BF

r1 = 51
r2 = 93
'The Drop Down

mydelay = .05 ' <====================
z = TIMER ' <====================
_KEYCLEAR

DO
    IF z > TIMER THEN z = z - 86400 ' Midnight adjustment.
    IF TIMER - z > mydelay THEN z = TIMER: GOSUB dropit
    LOCATE 20, 40: PRINT INT(RND * 100) + 1; "   ";
LOOP UNTIL LEN(INKEY$)
END

dropit:
DDwn = DDwn + 1
COLOR Yellow&
_PRINTSTRING (12, 15), "Opening Info"
LINE (c1, r1)-(c2, r2), DarkGreen&, BF
r1 = r1 + DDwn
r2 = r2 + DDwn
IF DDwn = 25 THEN DDwn = 0: r1 = 0: r2 = 0
RETURN

Pete
Reply
#6
Timer I have always used more for those routines where I need the min, hour, day, year type of stuff and can't recall the last time I use _Limit. It had never occurred to me to use either one of those to control the speed of the drop down.

I do see where you are recommending _Delay as the best practice for this kind of speed control. It definitely works but when I ran it in that little snippet it seemed the graphic drop down box was picking up speed as it dropped.  Optical illusion? Programming without glasses? It really isn't that big of deal. The _Delay is a much more elegant solution.

Thanks Steve and Mr. Re-Gifted (loved that line in another thread Pete)
Reply
#7
(10-21-2022, 05:34 PM)Dimster Wrote: Timer I have always used more for those routines where I need the min, hour, day, year type of stuff and can't recall the last time I use _Limit. It had never occurred to me to use either one of those to control the speed of the drop down.

I do see where you are recommending _Delay as the best practice for this kind of speed control. It definitely works but when I ran it in that little snippet it seemed the graphic drop down box was picking up speed as it dropped.  Optical illusion? Programming without glasses? It really isn't that big of deal. The _Delay is a much more elegant solution.

Thanks Steve and Mr. Re-Gifted (loved that line in another thread Pete)

That's because of 2 things.

1) Your first green block is so much thicker that it looks like it starts faster.

2) You are going back to a thin block but growing it by one with each next loop, so it looks like it is speeding up as it continues.

Something like this may be more of what you are trying for...

Code: (Select All)
CLS
SCREEN _NEWIMAGE(1200, 900, 32)
DIM SHARED DarkGreen&
DIM SHARED Yellow&
DIM SHARED Pink&
DarkGreen& = _RGB32(0, 129, 0)
Yellow& = _RGB(255, 255, 0)
Pink& = _RGB(216, 50, 166)


'Large background box
LINE (0, 0)-(1199, 50), Pink&, BF
c1 = 7
r1 = 7
c2 = 126
r2 = 46
'The 5 smaller box
LINE (c1, r1)-(c2, r2), DarkGreen&, BF

SLEEP

COLOR Yellow&
_PRINTSTRING (12, 15), "Opening Info"
r1 = 51
r2 = 93 - 28 ' Smaller or the first block is too thick.

'The Drop Down
FOR DDwn = 1 TO 25
    LINE (c1, r1)-(c2, r2), DarkGreen&, BF
    _DELAY .05 ' <============================== Change the value to increase or decrease the delay time.
    r1 = r1 + 15
    r2 = r2 + 15
NEXT

Pete - The Re-Gifted Child.
Reply
#8
That works great Pete, thanks
Reply




Users browsing this thread: 7 Guest(s)