Sign in to follow this  
compugeekpro

Defining clickable regions

Recommended Posts

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-

Share this post


Link to post
Share on other sites
Assuming you're using the Win32 API, you could do something like the following:


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 stuff
private:
bool bIsClicked;
RECT recPosition;
//..other stuff
};

class CManager
{
public:
//..other stuff
bool IsButtonClicked(const string &sButtonName);
{
find button//<- psudo code
return pButton->bIsClicked;}
private:
CMouse *Mouse //mouse class would be updated based on mouse buttons clicked
lsit of buttons//<- psudo code
//..other stuff
};

//main.cpp
if(Manager.IsButtonClicked("Button1")==true)
//play sound, etc whatever


Share this post


Link to post
Share on other sites
I'd create some arrays.


unsigned char windowIndices[Max_X * Max_Y] = {0xff},buttonIndices[Max_X * Max_Y] = {0xff};//0xff - empy
unsigned 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;
/*
...
*/

}
/*
...
*/

}







Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this