Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
08-07-2023, 03:34 PM
(This post was last modified: 08-07-2023, 03:44 PM by TerryRitchie.)
(08-07-2023, 02:36 PM)bplus Wrote: Yeah this is essential functionality, it is core of my GUI stuff and just about any game I've done.
SdlBasic called these MouseZones and had a function for IDing which you were in. Thanks for pointing that out. I'm going to investigate SdlBasic's commands related to this and see if I can replicate a library. There have been a few times I've coded something similar to the example I posted for projects over the years. It would be nice to have a library to call upon instead.
Update:
Ah, ok, I see, it's a function that returns the status of the mouse pointer in a defined area.
https://www.sdlbasic.altervista.org/main...one().html
Functionality I've created thousands of times over the years. A command like this added to QB64 would be very helpful hint...hint...
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
08-07-2023, 05:44 PM
(08-07-2023, 03:34 PM)TerryRitchie Wrote: (08-07-2023, 02:36 PM)bplus Wrote: Yeah this is essential functionality, it is core of my GUI stuff and just about any game I've done.
SdlBasic called these MouseZones and had a function for IDing which you were in. Thanks for pointing that out. I'm going to investigate SdlBasic's commands related to this and see if I can replicate a library. There have been a few times I've coded something similar to the example I posted for projects over the years. It would be nice to have a library to call upon instead.
Update:
Ah, ok, I see, it's a function that returns the status of the mouse pointer in a defined area.
https://www.sdlbasic.altervista.org/main...one().html
Functionality I've created thousands of times over the years. A command like this added to QB64 would be very helpful hint...hint...
+1 Definitely wouldn't be bloat
b = b + ...
Posts: 128
Threads: 17
Joined: Apr 2022
Reputation:
10
A method that I've used, which is relatively simple to implement, is use screen masking.
You draw your menu or whatever on the first screen like normal.
Then you create an image the same size as your target screen. This will be the hidden overlay.
Code: (Select All) hiddenScreen = _NEWIMAGE(_WIDTH(0), _HEIGHT(0), 32)
On the second screen (the hidden screen) you mask off the areas that you want the mouse to be sensitive to, and you assign specific colors to those areas.
Code: (Select All) myButton_1 = 1 ' Assign Numbers to masked off areas (colors)
myButton_2 = 2
_DEST hiddenScreen
LINE(10, 10) - (30 ,20), myButton_1, BF
LINE(50, 10) - (80 ,20), myButton_2, BF
_DEST 0
And when you want check your mouse.
Code: (Select All) DO WHILE _MOUSEINPUT ' Check the mouse status
mx = _MOUSEX
my = _MOUSEY
LOOP
_SOURCE hiddenScreen
buttonTouched = POINT(mx ,my)
_SOURCE 0
I find this easier than making a large number of conditionals for my mouse position.
(Forgive me, I haven't tested this code, but it conveys the general idea.)
Posts: 3,968
Threads: 177
Joined: Apr 2022
Reputation:
219
08-07-2023, 08:47 PM
(This post was last modified: 08-07-2023, 08:51 PM by bplus.)
Interesting but for a _MouseZone function I would want to see if mouse or mouse click is in a given rectangle.
If zones overlap, what color would that be?
Sure you would have to track which rectangle(s) is(are) on top (with _MouseZone), just like Windows OS has to.
for i = 1 to nRecs
if mx >= rX(i) and mx <= rX(i) + rW(i) then
if my >= rY(i) nd my <= rY(i) + rH(i) then
_mousezone(i) = -1
end if
end if
next
not so hard
b = b + ...
Posts: 128
Threads: 17
Joined: Apr 2022
Reputation:
10
Quote:Interesting but for a _MouseZone function I would want to see if mouse or mouse click is in a given rectangle.
You are assigning "colors" to boxes. Color is just a 32 bit value, what you do with said value is up to you. In this case I'm using that value to specify regions on the screen that overlay the buttons or whatever I'm interested in clicking. Using POINT command is just an easy way of retrieving that value for a given X,Y coordinate.
As long as your "color" is unique, you should be able discern which "zone" your mouse is on based upon what "color" you assigned it when you drew the boxes on the hidden screen.
Quote:If zones overlap, what color would that be?
It would be the same if you drew a box on top of another box. The second would overwrite the first.
Posts: 128
Threads: 17
Joined: Apr 2022
Reputation:
10
Perhaps it would be better to demonstrate.
This is a GUI demo program I was writing for a bigger project. I utilize the technique I talked about earlier.
You can currently resize and move windows. You double-click to add windows and close them.
Sorry, its messy, I never intended to share it until was in a better state.
QB_GUI.zip (Size: 133.84 KB / Downloads: 107)
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
(08-07-2023, 07:55 PM)justsomeguy Wrote: A method that I've used, which is relatively simple to implement, is use screen masking.
You draw your menu or whatever on the first screen like normal.
Then you create an image the same size as your target screen. This will be the hidden overlay.
Code: (Select All) hiddenScreen = _NEWIMAGE(_WIDTH(0), _HEIGHT(0), 32)
On the second screen (the hidden screen) you mask off the areas that you want the mouse to be sensitive to, and you assign specific colors to those areas.
Code: (Select All) myButton_1 = 1 ' Assign Numbers to masked off areas (colors)
myButton_2 = 2
_DEST hiddenScreen
LINE(10, 10) - (30 ,20), myButton_1, BF
LINE(50, 10) - (80 ,20), myButton_2, BF
_DEST 0
And when you want check your mouse.
Code: (Select All) DO WHILE _MOUSEINPUT ' Check the mouse status
mx = _MOUSEX
my = _MOUSEY
LOOP
_SOURCE hiddenScreen
buttonTouched = POINT(mx ,my)
_SOURCE 0
I find this easier than making a large number of conditionals for my mouse position.
(Forgive me, I haven't tested this code, but it conveys the general idea.)
This is only problematic if a zone has sub-zones.
If there aren't "sub zones", though, then I think this is ingenious for those scenarios.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
08-07-2023, 09:37 PM
(This post was last modified: 08-07-2023, 09:39 PM by CharlieJV.)
(08-07-2023, 03:34 PM)TerryRitchie Wrote: (08-07-2023, 02:36 PM)bplus Wrote: Yeah this is essential functionality, it is core of my GUI stuff and just about any game I've done.
SdlBasic called these MouseZones and had a function for IDing which you were in. Thanks for pointing that out. I'm going to investigate SdlBasic's commands related to this and see if I can replicate a library. There have been a few times I've coded something similar to the example I posted for projects over the years. It would be nice to have a library to call upon instead.
Update:
Ah, ok, I see, it's a function that returns the status of the mouse pointer in a defined area.
https://www.sdlbasic.altervista.org/main...one().html
Functionality I've created thousands of times over the years. A command like this added to QB64 would be very helpful hint...hint...
Need to test the daylights out of it first, but _mouseZone(x,y,w,h), w and h being optional, as in _mouseZone(x,y) meaning 1 pixel wide and 1 pixel tall, later tonight in a new version of BAM.
No pressure ?
ARG! Screenshot did not capture the mouse pointer.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
Silly question: does it make more sense to have third and fourth parameters be width and height, or does it make more sense for those to be x,y coordinates for bottom right corner?
Would consistency with coordinates for LINE make more sense, or maybe width and height are much more practical? (Lack of experience over here in that kind of programming.)
Posts: 128
Threads: 17
Joined: Apr 2022
Reputation:
10
Quote:This is only problematic if a zone has sub-zones.
Sub zones aren't really a problem.
Code: (Select All) _DEST hiddenScreen
finalColor = _RGBA32(zone, subzone, subsubzone,subsubsubzone)
LINE(10, 10)-(30 ,20), finalcolor, BF
Code: (Select All) DO WHILE _MOUSEINPUT ' Check the mouse status
mx = _MOUSEX
my = _MOUSEY
LOOP
_SOURCE hiddenScreen
pt = POINT(mx,my)
zone = _red(pt)
subzone = _green(pt)
subsubzone = _blue(pt)
subsubsubzone = _alpha(pt)
_SOURCE 0
|