Defining clickable regions
I am making a media player and posted a question (that i got answered) about creating a skin to go over the program. I now want to know how I can track the mouse movement and define clickable regions within the program...such as play buttons, etc. Another thing I would like to know is how to create buttons that act as rollovers...I know how to do this using javascript and css, but what steps do I take to accomplish this using c++? Thanks in advance...
-Sean-
Assuming you're using the Win32 API, you could do something like the following:
- xeddiex
region coordinates:Point pt = {5, 10};HRGN hrgn = Region...check if point is in region:if ( PtInRegion(hrgn, pt.x, pt.y) ) // point in region...
- xeddiex
I would like to try to use another way because I have to check if the mouse is in a certain polygonal area (the button). Doesn't that just try to check if the mouse is at that one single pixel. Also...that function can be a memory hog on the gdi stack when complex polygons are introduced.
Quote:Original post by compugeekpro
I would like to try to use another way because I have to check if the mouse is in a certain polygonal area (the button). Doesn't that just try to check if the mouse is at that one single pixel. Also...that function can be a memory hog on the gdi stack when complex polygons are introduced.
Using the code I posted above, the button is the region:
HRGN hrgn = // button region...
and, the mouse click is the point:
Point pt = {5, 10}; // cursor position
you then check if the mouse cursor/arrow is clicked over the button:
if ( PtInRegion(hrgn, pt.x, pt.y) )
// mouse pos clicked over button...
- xeddiex
Here's a really brief idea of what you can do:
class CButton{public:void Update();{if(PtInRect(&recPosition,Manager.Mouse.ptCurrentPos)==true && Manager.Mouse.bClick==true))bIsClicked=true;}//..other stuffprivate:bool bIsClicked;RECT recPosition;//..other stuff};class CManager{public://..other stuffbool IsButtonClicked(const string &sButtonName);{find button//<- psudo codereturn pButton->bIsClicked;}private:CMouse *Mouse //mouse class would be updated based on mouse buttons clickedlsit of buttons//<- psudo code//..other stuff};//main.cppif(Manager.IsButtonClicked("Button1")==true) //play sound, etc whatever
I'd create some arrays.
unsigned char windowIndices[Max_X * Max_Y] = {0xff},buttonIndices[Max_X * Max_Y] = {0xff};//0xff - empyunsigned char numWindows;WINDOW *windows;//255 max/*...*/class BUTTON{/*...*/};class WINDOW{public: unsigned short x,y,width,height; unsigned char *windowsPrev,*butonsPrev;//window width * window height unsigned char numButtons; BUTTON *buttons;//255 max bool visible; void Display(void);//slow//If window isn't visible//Draw window into "windowIndices" and buttons into "buttonIndices"//Store previous indices on window area void Hide(void);//slow//If window is visible//Restore previous indices/*...*/};void CheckMouse(void){ unsigned int pixel = Mouse.Y * Max_X + Mouse.X; unsigned char winIndex = windowIndices[pixel], butIndex = buttonIndices[pixel]; switch(winIndex) { case 0: switch(butIndex) {/*...*/ } break; case 1:/*...*/ break;/*...*/ }/*...*/}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement