We need more mouse commands/events!
BlitzPlus Forums/BlitzPlus Programming/We need more mouse commands/events!
| ||
I have a panel, and I want to know if the mouse enters it. I thought I had a clever solution for this... MouseX(Panel) would be less than 0 if the mouse was to the left of the panel, and greater than the width of the panel if it was to the right of it. But Blitz won't allow me to use a Panel with MouseX. It will only allow me to use a Canvas, or nothing, which basically leaves me with screen coordinates. Now, my panel has a canvas INSIDE it, but the canvas can scroll around, and change scale. Oy, would it be a pain to try to base my mouse being in my panel on that. Especially if I decided to do something crazy like use more than one canvas in my panel and scrolling them all around together. So I can get the mouse position on the screen. Okay, that's not so bad. I'll just get the position of the panel on the screem and it's width and... CRAP! Why is there no way to get the position of a panel on the screen? Oh sure, there's a way to get the position of a panel inside the client space of it's parent gadget. But what have I got to do here, step back through all the parents of each gadget calculating its position in the client area of its parent, and take into account the size of the parent, minus the size of the client area of the parent to calculate the correct coordinates... HEADACHE! All I want to do is know if my mouse is in a certain region! A region which resizes automatically with the window. I could create a canvas, but the draw order of gadgets if I can even control it seems backward (Gadgets created last are drawn first? Huh?) and it would probably slow my app down. So what option do I have left? Creating a simple MouseOver(Gadget) function seems out of the question what with all the recursion crap. Too much trouble. So I am left with one option, and that is to try to manually code this for this one specific case taking into account the parents I know the panel has. Maybe I should check the code archives first though and see if someone else has solved this. |
| ||
Oh and something I forgot to mention... No mouse events for mouse entering/exiting a gadget? That would have solved my whole problem right there in one fell swoop. |
| ||
You might want to ask Halo. Josh has probably done more "app wise" with B+ than anybody else and has managed to find ways to get around many of B+s shortcomings. |
| ||
Ask Halo for help? Are you serious?! I suppose he might help, but then I'd have to listen to him say "Who's your daddy, b*tch!" Though I have to admit, I think he did help me once only a few days ago. He must be going soft. :-) Anyway, I don't need help with it anymore... I found a solution, and I added a code archive entry for it: http://www.blitzbasic.com/codearcs/codearcs.php?code=1290 |
| ||
I know this doesn't help, but there is no reason why the panel shouldn't report these messages. They are sent by windows, it is just b+ that decides to ignore them. *pimp* My bmax module can do it :P *pimp* |
| ||
Halo did create a MouseX and MouseY command using the SendMessage API command so you can check if the mouse is over any gadget. I use it to great effect in my GUI editor. Do a search for it in the b+ forums. There is no code archive entry of it. |
| ||
JimB wrote this magic little bit of code. Might be a good starting point. But I agree we need events on gadgets other then canvases. Oh, it lets you query what gadget you're currently over: .lib "user32.dll" api_GetCursorPos% (lpPoint*) : "GetCursorPos" api_ClientToScreen% (hWnd%,lpPoint*) : "ClientToScreen" Type POINTTYPE Field x%,y% End Type Global point.POINTTYPE=New POINTTYPE Function MouseOverGadget(gad) point\x=0 : point\y=0 api_ClientToScreen(QueryObject(gad,1),point) Local gadX%=point\x , gadY%=point\y api_GetCursorPos(point) Local mX%=point\x , mY%=point\y If mX>=gadX And mX<gadX+GadgetWidth(gad) If mY>=gadY And mY<gadY+GadgetHeight(gad) Return True EndIf EndIf End Function |
| ||
Thanks Cold, but I already solved the problem, and JimB's snippet is what I based the function I put in the code archives on. :-) www.blitzbasic.com/codearcs/codearcs.php?code=1290 |
| ||
temp=CreateBank(8) GetCursorPos(temp) ScreenToClient(QueryObject(gadget,1),temp) x=PeekInt(temp,0) y=PeekInt(temp,4) FreeBank temp |
| ||
I figured you could probably replace the type with a bank... But since the type is in an include file anyway, it's not really going to improve the appearance of the code, and peeks and pokes actually serve to make the code uglier. But thank you for your suggestion anyway Halo. :-) |