|
|
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   |
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  |
|
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
|
|
|
Goto Forum:
Current Time: Sat Apr 26 18:10:32 CEST 2025
Total time taken to generate the page: 0.00849 seconds
|
|
|