Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
(01-05-2023, 06:36 PM)TempodiBasic Wrote: Hello,
in theme but on the border...some my questions
Is the stack of mouse events (click of buttons, position of cursor) for all OSes or only for Windows?
Do our QB64 friends living in Linux or MacOs have the same experience of Windows's users?
Is this kind of management of mouse input universal or typical of C/C++? (Our BASIC becomes C++ and then machine language!)
Thank you, for reading, for sharing knowledge and be part of this friendship named QB64 community.
It's been a long time since I've owned a MAC and ran QB64 inside it (back in the 2013 time frame with .954 and SDL). Someone with a MAC using QB64 will need to answer the MAC question.
It's been a while since I ran QB64 in Linux as well (a few years at least). If I remember correctly the mouse buffer was present in Linux as well.
I need to get Linux back up and running (besides the VMs I have) on a real box again. I have an old Itanium server sitting in the corner of my shop collecting dust. Good candidate I suppose. I've also been looking at making iPhone games using Swift and from what I've read it appears you have to have an actual MAC to use Xcode and to upload projects with a valid Apple ID (that good old Apple pay wall). So perhaps another MAC (probably a Mini) is in my near future as well.
Posts: 11
Threads: 3
Joined: Dec 2022
Reputation:
0
01-07-2023, 05:12 AM
(This post was last modified: 01-07-2023, 05:22 AM by fistfullofnails.
Edit Reason: Code printed twice
)
Ok, SMcneill's example program definitely helped me see what is happening, and Terry's explanation helped to solidify the point. I thank y'all very much. So what I've generally tend to do through Terry's tutorials, is to make up my own little programs using some of the things I've just read about. I was going to post this in a separate place, but I'm thinking it might be appropriate being as I think the problem might lie in the buffer situation being discussed. I attempted to make a model of a traffic light. I realize it's pretty rough and I know I could shorten it using some more variables and loops, but I just wanted to get something working to start with. So don't make too much fun haha.
Code: (Select All) CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$
x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)
DO
Keypress$ = INKEY$
CLS
_LIMIT 30
LINE (300, 200)-(600, 700), DULLYELLOW, BF
'Red
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), BRIGHTRED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 8
'Green
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), BRIGHTGREEN, WHITE
SLEEP 8
'Yellow
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), BRIGHTYELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 5
LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM
CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$
x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)
DO
Keypress$ = INKEY$
CLS
_LIMIT 30
LINE (300, 200)-(600, 700), DULLYELLOW, BF
'Red
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), BRIGHTRED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 8
'Green
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), BRIGHTGREEN, WHITE
SLEEP 8
'Yellow
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), BRIGHTYELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 5
LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM
I expected nothing to happen when pressing any key other than escape. But what actually does happen, is that it seems to jump to the next piece of code after the nearest 'sleep' command. Maybe I should be using '_delay' instead? Even when I press 'ESC', it does the same thing, but eventually does exit now and then. I do not know why the code is duplicated here after the first time. Sorry. Also, I had the '_display' command in that code right near the end. But my traffic light always froze after one time through the loop until I removed that command.
Second edit: I have sort of answered my own question about the 'sleep' and '_delay' commands. After reading up on them in the keyword reference guide for QB64, I think it's saying that by pressing any button during the sleep "pause", that it will move on. So I changed all _delays to sleep, and now random button presses seem not to interfere with the timing. I still have the problem of not being able to exit the loop after pressing 'ESC' though.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
"SLEEP" doesn't wait the full length given if a key is pressed. However, "_DELAY" to stick things up for longer than a few seconds could irritate the user running your program. A compromise is to run a loop, say you want to pause for 10 seconds. Do "_DELAY 1" and then check for keypress, per loop pass, to break out of the loop. Specifically check for escape key if you require it, otherwise for a lengthy pause, it should at least display a message to the user so he/she doesn't feel like an MMORPG's eternity.
Be careful when using "_DISPLAY". Don't forget that after showing a lot of stuff on screen, such as doing animations and while it's highly important to get the attention of the user using your program, you place "_AUTODISPLAY". Otherwise some things aren't going to be displayed which is bothersome. The first "_DISPLAY" statement encountered in the code automatically switches to "update only when I'm asked to, not when the system asks me to". So it's easy to forget to change it back to "_AUTODISPLAY".
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
(01-07-2023, 05:12 AM)fistfullofnails Wrote: Ok, SMcneill's example program definitely helped me see what is happening, and Terry's explanation helped to solidify the point. I thank y'all very much. So what I've generally tend to do through Terry's tutorials, is to make up my own little programs using some of the things I've just read about. I was going to post this in a separate place, but I'm thinking it might be appropriate being as I think the problem might lie in the buffer situation being discussed. I attempted to make a model of a traffic light. I realize it's pretty rough and I know I could shorten it using some more variables and loops, but I just wanted to get something working to start with. So don't make too much fun haha.
Code: (Select All) CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$
x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)
DO
Keypress$ = INKEY$
CLS
_LIMIT 30
LINE (300, 200)-(600, 700), DULLYELLOW, BF
'Red
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), BRIGHTRED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 8
'Green
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), BRIGHTGREEN, WHITE
SLEEP 8
'Yellow
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), BRIGHTYELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 5
LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM
CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$
x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)
DO
Keypress$ = INKEY$
CLS
_LIMIT 30
LINE (300, 200)-(600, 700), DULLYELLOW, BF
'Red
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), BRIGHTRED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 8
'Green
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), YELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), BRIGHTGREEN, WHITE
SLEEP 8
'Yellow
CIRCLE (x%, 300), 50, WHITE
PAINT (x%, 300), RED, WHITE
CIRCLE (x%, 450), 50, WHITE
PAINT (x%, 450), BRIGHTYELLOW, WHITE
CIRCLE (x%, 600), 50, WHITE
PAINT (x%, 600), GREEN, WHITE
SLEEP 5
LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM
I expected nothing to happen when pressing any key other than escape. But what actually does happen, is that it seems to jump to the next piece of code after the nearest 'sleep' command. Maybe I should be using '_delay' instead? Even when I press 'ESC', it does the same thing, but eventually does exit now and then. I do not know why the code is duplicated here after the first time. Sorry. Also, I had the '_display' command in that code right near the end. But my traffic light always froze after one time through the loop until I removed that command.
Second edit: I have sort of answered my own question about the 'sleep' and '_delay' commands. After reading up on them in the keyword reference guide for QB64, I think it's saying that by pressing any button during the sleep "pause", that it will move on. So I changed all _delays to sleep, and now random button presses seem not to interfere with the timing. I still have the problem of not being able to exit the loop after pressing 'ESC' though.
Give this style solution a run and see if it makes sense for you. One input handler for the code, without any issues with SLEEP and INKEY$ interacting and producing undesirable results.
Code: (Select All) Const SCREENWIDTH = 900
Const SCREENHEIGHT = 900
Const RED = _RGB32(80, 0, 0)
Const YELLOW = _RGB32(80, 80, 0)
Const GREEN = _RGB32(0, 80, 0)
Const BRIGHTRED = _RGB32(255, 0, 0)
Const BRIGHTYELLOW = _RGB32(255, 255, 0)
Const BRIGHTGREEN = _RGB32(0, 255, 0)
Const DULLYELLOW = _RGB32(40, 40, 0)
Dim x%
Dim Keypress$
x% = SCREENWIDTH / 2
Const WHITE = _RGB32(255, 255, 255)
Screen _NewImage(SCREENWIDTH, SCREENHEIGHT, 32)
Do
Cls
_Limit 30
Line (300, 200)-(600, 700), DULLYELLOW, BF
'Red
Circle (x%, 300), 50, WHITE
Paint (x%, 300), BRIGHTRED, WHITE
Circle (x%, 450), 50, WHITE
Paint (x%, 450), YELLOW, WHITE
Circle (x%, 600), 50, WHITE
Paint (x%, 600), GREEN, WHITE
Pause 8
'Green
Circle (x%, 300), 50, WHITE
Paint (x%, 300), RED, WHITE
Circle (x%, 450), 50, WHITE
Paint (x%, 450), YELLOW, WHITE
Circle (x%, 600), 50, WHITE
Paint (x%, 600), BRIGHTGREEN, WHITE
Pause 8
'Yellow
Circle (x%, 300), 50, WHITE
Paint (x%, 300), RED, WHITE
Circle (x%, 450), 50, WHITE
Paint (x%, 450), BRIGHTYELLOW, WHITE
Circle (x%, 600), 50, WHITE
Paint (x%, 600), GREEN, WHITE
Pause 5
Loop
Sub Pause (seconds#)
t# = Timer + seconds# 'the length of this pause
Do Until Timer > t# Or Timer < 1 'reset at midnight, if necessary. Hope a quick change doesn't cause an accident!
_Delay .1 'a small pause so this timed sleep doesn't use a lot of CPU power
i$ = InKey$ 'check for input from the user
If i$ = Chr$(27) Then System 'if they hit ESC at any point, then exit and shut down the program
If Len(i$) Then Exit Do 'otherwise, if they hit any key, exit the pause early
Loop
End Sub
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
(01-07-2023, 06:29 AM)mnrvovrfc Wrote: Be careful when using "_DISPLAY". Don't forget that after showing a lot of stuff on screen, such as doing animations and while it's highly important to get the attention of the user using your program, you place "_AUTODISPLAY". Otherwise some things aren't going to be displayed which is bothersome. The first "_DISPLAY" statement encountered in the code automatically switches to "update only when I'm asked to, not when the system asks me to". So it's easy to forget to change it back to "_AUTODISPLAY".
In portable GUI library routines I like using:
IF NOT _AUTODISPLAY THEN _DISPLAY
Taking advantage of the function aspect of _AUTODISPLAY to cover both contingencies that could occur in the main code.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
|