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
How can I callback on staticimage click [message #35326] Fri, 03 February 2012 07:21 Go to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hello

I have this series of staticimage widgets that are to be clickable. When the user clicks on one, I update a global variable that will be used elsewhere in the code.

index.php?t=getfile&id=3633&private=0


I cannot figure how to capture the mouse click on the static images. Do I need to make a class derived from staticimage widget and then capture the LeftDown event? Or is it something very simple?

Can someone please help me out here.

thanks
Jerson
  • Attachment: LDG.jpg
    (Size: 10.85KB, Downloaded 557 times)
Re: How can I callback on staticimage click [message #35328 is a reply to message #35326] Fri, 03 February 2012 09:11 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Not sure if this is reasonable solution, but how about using buttons with images on them instead of staticimage?
Re: How can I callback on staticimage click [message #35331 is a reply to message #35328] Fri, 03 February 2012 11:47 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

thanks mr_ped. Well definitely workable for me. I shall try it out.
Re: How can I callback on staticimage click [message #35335 is a reply to message #35331] Fri, 03 February 2012 13:31 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Button with image somehow does not FIT the image as in StaticImage. Is there some flag to be set to size the image to button size?
Re: How can I callback on staticimage click [message #35354 is a reply to message #35335] Sun, 05 February 2012 09:25 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

You may derive your own class from Button and Paint the image the way you want in repainting virtual member function.
Re: How can I callback on staticimage click [message #35358 is a reply to message #35326] Mon, 06 February 2012 10:36 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Also you may want to check out toolbars, how they are done, it's probably the most similar (if not identical) case.
Re: How can I callback on staticimage click [message #35380 is a reply to message #35358] Wed, 08 February 2012 17:20 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Try to find on the forum "ImageButton" or "ImageBtn".
There are working example.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: How can I callback on staticimage click [message #35388 is a reply to message #35380] Thu, 09 February 2012 05:09 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Thanks for the tip Sergey

Is there some equivalent to something like this that I used to do in VB?

I am trying to replicate a VB6 implementation that has this:
I have a number of images called Image(0) to Image(12)
Clicking any of this image allows me to pick the index of the image that is clicked. I can use this index to pass into my program.

My UPP version has this
A number of images on a layout(not ideal). I'd rather do this in code later.
Clicking a particular image would give me the index of which image was clicked.

I am sorry for the extremely dumb question, but, I am still pretty raw at UPP and C++. After my initial success with UPP in my first project, I am quite sure it can be done easily. However, my current knowledge level doesn't make it easy for me. Any help (even pseudo code) will help me.

Thanks
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 next 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

Re: How can I callback on staticimage click [message #35479 is a reply to message #35390] Tue, 21 February 2012 22:12 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I use simplest alternative of ImageBtn

ImageBtn.h:
#ifndef _ImageBtn_h_
#define _ImageBtn_h_
class ImageBtn : public ImageCtrl
{
public:
	ImageBtn()	{ IgnoreMouse(false); }
	Image imgb;
	void SetBackImage(Image imgb1) {imgb = imgb1;}
	virtual void LeftDown(Point p, dword keyflags) 		{ Action(); }
	virtual void Paint(Draw& draw);
};
#endif


ImageBtn.cpp:
#include "ImageBtn.h"
void ImageBtn::Paint(Draw& draw){
	draw.DrawImage(GetSize(),imgb);
}


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Tue, 21 February 2012 22:14]

Report message to a moderator

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


Current Time: Thu Mar 28 20:29:39 CET 2024

Total time taken to generate the page: 0.01710 seconds