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 » mousepos / click for a widget...
mousepos / click for a widget... [message #36697] Tue, 26 June 2012 13:34 Go to next message
Wolfgang is currently offline  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!
Re: mousepos / click for a widget... [message #36698 is a reply to message #36697] Tue, 26 June 2012 15:24 Go to previous message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
think i've solved it by using
class PaintArea : public Button {

instead of public LabelBox.
Previous Topic: Using an existing win32 control.
Next Topic: overwritten virtual void LeftDown - how to invoke WhenAction?
Goto Forum:
  


Current Time: Fri Apr 19 06:48:57 CEST 2024

Total time taken to generate the page: 0.02585 seconds