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 » U++ Library support » Menus&Toolbars » images as menu
Re: images as menu [message #19495 is a reply to message #19494] Mon, 08 December 2008 17:31 Go to previous messageGo to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
If you only want a button (no submenu) you can do it quite easily.

First, you need a custom ctrl to display the image and respond correctly to mouse events:
struct ImageBtn : public ImageCtrl
{
        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());
		ImageCtrl::Paint(draw);
	}		
};

And then add instances of this to your MenuBar:
void basicWindow::MenuMain(Bar &bar){
	bar.Add("Menu", Image::Arrow(), THISBACK(SubMenu));
	
	imagebtn1.SetImage(MyImages::layout1());
	imagebtn1 <<= THISBACK(setLayout1);
	bar.Add(imagebtn1.Tip("Layout 1"), MyImages::layout1().GetSize());
	
	bar.Gap(4);

	imagebtn2.SetImage(MyImages::layout2());
	imagebtn2 <<= THISBACK(setLayout2);
	bar.Add(imagebtn2.Tip("Layout 2"), MyImages::layout2().GetSize());	
}

void basicWindow::SubMenu(Bar &bar)
{
	bar.Add("Item1", Callback());	
	bar.Add("Item2", Callback());
	bar.Add("Item3", Callback());
}
(I've also added a sub-menu to make the example clearer)

Hope that helps,
James

[Updated on: Mon, 08 December 2008 17:33]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: [not a bug] Menu isn`t drawn. NOGTK. FreeBSD/Fluxbox
Next Topic: DropList in Toolbar
Goto Forum:
  


Current Time: Thu May 16 01:12:15 CEST 2024

Total time taken to generate the page: 0.01777 seconds