Home » Community » Newbie corner » mousepos / click for a widget...
mousepos / click for a widget... [message #36697] |
Tue, 26 June 2012 13:34 |
Wolfgang
Messages: 146 Registered: November 2011 Location: Germany
|
Experienced Member |
|
|
Hi,
I've copied the code from the tutorial to get the current mousepos and display it on left click... but this is for the whole view area.... I try to do this just for a special area (a LabelBox for example).... it compiles but it left click on the area of the labelbox changes / displays nothing.
Here's my Code:
.h
#ifndef _justForTest_justForTest_h
#define _justForTest_justForTest_h
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <justForTest/justForTest.lay>
#include <CtrlCore/lay.h>
class PaintArea : public LabelBox {
private:
Point p;
String text;
virtual void LeftDown(Point pos, dword flags)
{
p = pos;
Refresh();
}
virtual void MouseMove(Point pos, dword flags)
{
text = Format("[%d:%d]", pos.x, pos.y);
Refresh();
}
virtual void Paint(Draw& w)
{
w.DrawRect(GetSize(), SWhite);
w.DrawText(p.x, p.y, text, Arial(20), Magenta);
}
public:
Point getLastPos() { return p; }
};
class justForTest : public WithjustForTestLayout<TopWindow> {
private:
PaintArea myPaintArea;
void btn_pointClick();
int btn_pointCounter;
public:
typedef justForTest CLASSNAME;
justForTest();
};
#endif
.cpp
#include "justForTest.h"
void justForTest::btn_pointClick()
{
btn_pointCounter++;
String c2s;
c2s << "[ " << AsString(btn_pointCounter) << " ] ";
c2s << "A Point\n";
Point p = myPaintArea.getLastPos();
c2s << " [" << AsString(p.x) << "|" << AsString(p.y) << "]";
log_main.Insert(log_main.GetLength(),c2s);
}
justForTest::justForTest()
{
myPaintArea.LeftPosZ(4,530).TopPosZ(4,300);
this->Add(myPaintArea);
CtrlLayout(*this, "Window title");
btn_point <<= THISBACK(btn_pointClick);
btn_pointCounter = 0;
}
GUI_APP_MAIN
{
justForTest().Run();
}
.lay (just to complete the list..)
LAYOUT(justForTestLayout, 544, 560)
ITEM(Button, btn_point, SetLabel(t_("Set Point")).HSizePosZ(8, 480).TopPosZ(308, 20))
ITEM(LineEdit, log_main, LeftPosZ(8, 524).TopPosZ(332, 196))
END_LAYOUT
In my "log" i get this on button click:
[ 1 ] A Point
[-1077075752|135843110][ 2 ] A Point
[-1077075752|135843110][ 3 ] A Point
[-1077075752|135843110]
no matter where I've clicked
Thanks for help!
|
|
|
|
Goto Forum:
Current Time: Sat May 04 17:40:09 CEST 2024
Total time taken to generate the page: 0.04525 seconds
|