Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How can I callback on staticimage click
Re: How can I callback on staticimage click [message #35390 is a reply to message #35388] Thu, 09 February 2012 06:40 Go to previous messageGo to previous message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Here is something I did. It serves my purpose well. I just need some review on this so I can improve.

I looked at code from mrjt in this thread
http://www.ultimatepp.org/forum/index.php?t=msg&goto=194 95&S=0339fad60b64c135d24482695827b19b&srch=imagebtn# msg_19495

and came up with this
struct ImageBtn : public StaticImage
{
    ImageBtn() 											{ IgnoreMouse(false); }
	virtual void LeftDown(Point p, dword keyflags) 		{ Action(); }
	virtual void MouseEnter(Point p, dword keyflags) 	{ Refresh(); }
	virtual void MouseLeave() 							{ Refresh(); }
	virtual void Paint(Draw& draw) 
	{ 
		if (HasMouse()) 
			draw.DrawRect(GetSize(), SColorHighlight());
		StaticImage::Paint(draw);
	}		
};


Now, I have a small function that gets called by a menu
void	DiaGuage::mnuProfileSelected(int profileno)
{
	PromptOK(AsString(profileno) );
}

void DiaGuage::mnuSettingsProfile(void)
{
ImageBtn imagebtn[11];

	TopWindow	frmProfile;

	// set the new window size to what we are using already
	frmProfile.SetFrameRect(DiaGuage::GetSize());
	
	// give the window a title
	frmProfile.Title("DiaGuage - Select a Profile");
	
	// introduce image buttons into the window
	for (int i=0; i < 11; i++)
	{
		frmProfile.Add(imagebtn[i]);
		imagebtn[i].SetRect((i%6)*120+10,i/6 * 120+10,100,100);
		imagebtn[i].SetFit(StaticImage::FillFrame);
		imagebtn[i].Set(Images::Get(i+1));
		imagebtn[i] <<= THISBACK1(mnuProfileSelected,i);
	}
	frmProfile.Execute();
}


With this code, I am able to get the index of the image button which is clicked. Perfect!!

Thanks to all for the ideas I got here.

[Updated on: Thu, 09 February 2012 06:57]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED] Background in dockable GL objects
Next Topic: EditDouble background color
Goto Forum:
  


Current Time: Sun Aug 24 16:52:14 CEST 2025

Total time taken to generate the page: 0.00769 seconds