Mapping screen for mouse - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Mapping screen for mouse (/showthread.php?tid=1882) |
RE: Mapping screen for mouse - TerryRitchie - 08-07-2023 (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.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/guide/sections/commands/Mouse/mouseZone().html Functionality I've created thousands of times over the years. A command like this added to QB64 would be very helpful hint...hint... RE: Mapping screen for mouse - bplus - 08-07-2023 (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.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. +1 Definitely wouldn't be bloat RE: Mapping screen for mouse - justsomeguy - 08-07-2023 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) Code: (Select All) DO WHILE _MOUSEINPUT ' Check the mouse status 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.) RE: Mapping screen for mouse - bplus - 08-07-2023 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 RE: Mapping screen for mouse - justsomeguy - 08-07-2023 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. RE: Mapping screen for mouse - justsomeguy - 08-07-2023 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: 13) RE: Mapping screen for mouse - CharlieJV - 08-07-2023 (08-07-2023, 07:55 PM)justsomeguy Wrote: A method that I've used, which is relatively simple to implement, is use screen masking. 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. RE: Mapping screen for mouse - CharlieJV - 08-07-2023 (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.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. 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. RE: Mapping screen for mouse - CharlieJV - 08-07-2023 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.) RE: Mapping screen for mouse - justsomeguy - 08-07-2023 Quote:This is only problematic if a zone has sub-zones.Sub zones aren't really a problem. Code: (Select All) _DEST hiddenScreen Code: (Select All) DO WHILE _MOUSEINPUT ' Check the mouse status |