Detecting mouse movements and clicks

Started by
1 comment, last by B4 23 years, 10 months ago
I was wondering what the best possible solution for detecting mouse movements or clicks in DirectX would be. When I start my application, I load a list of images, each onto its own offscreen surface. Also when loading, I create an array of structures which has the x and y position. When I use some of these offscreen surfaces and Blit them onto the primary or back buffer, I want them to light up or do something on the event of a mouse over. My best idea right now is to have an array which contains all of the things I want to light up, and their positions on the screen. Whenever the mouse moves, the array is checked to see if the mouse is over something that needs to be lighted up. There won''t be too many elements in this array, probably less than 15, but is there any better way to do this? -B4
Advertisement
Hi B4!

I don''t think you should be worried about this too much. Checking whether a mouse is over an element is pretty cheap (if they are rectangular) and since you only have 15 elements this will not be too bad. Let''s put it this way: Drawing the 15 elements will take more time than checking whether the mouse is over them.

Ciao,

MK42
Another good way to do this (and checking vs the rectangles would work just fine) is to draw out an image in indexed mode (8 bit) with the regions of the buttons in different colors. You can then check the value on the image that corresponds to where the mouse is and know exactly (pixel perfect) which button the mouse is over. I kind of need to diagram it to show you I think, but hopefully my explanation is clear enough.

-BacksideSnap-

This topic is closed to new replies.

Advertisement