我試圖檢測一個標籤被點擊/指出/點擊。我來自Win32 C++編程& Java Swing,我知道這兩種方法都是採用不同的方法來註冊事件/輸入。Mosync:檢測指針/點擊
我看過教程,但找不到檢測點擊的示例。是否有一個常量的點擊,所以然後我可以檢測到keyPressEvent(即,像win32 & WM_LBUTTONDOWN)?或者我需要先註冊點擊,然後調用我自己的函數來處理點擊(如Java & .addActionListener())?
我嘗試檢測下方點擊不工作:
#include <MAUtil/Moblet.h>
#include <MAUI/Layout.h>
#include <MAUI/ListBox.h>
#include <MAUI/Label.h>
#include <MAUI/EditBox.h>
#include <MAUI/Screen.h>
#include <MAUtil/Environment.h>
#include <madmath.h>
#include <conprint.h>
using namespace MAUtil;
using namespace MAUI;
class MouseScreen : public Screen, public PointerListener
{
private:
Label *testLabel;
public:
MouseScreen()
{
MAExtent screenDim = maGetScrSize();
Layout* mainLayout = new Layout(0, 0, EXTENT_X(screenDim), EXTENT_Y(screenDim), NULL, 1, 3);
ListBox* mainListBox = new ListBox(0, 0, 100, 200, mainLayout,
ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR,
true);
mainListBox -> setPaddingLeft(10);
mainListBox -> setPaddingRight(10);
mainListBox -> setPaddingTop(10);
mainListBox -> setPaddingBottom(10);
mainListBox -> setBackgroundColor(900);
mainLayout -> setBackgroundColor(300);
testLabel = new Label(10, 300, 50, 20, mainLayout);
//testLabel -> addPointerListener(this);
testLabel -> setCaption("Click me");
mainLayout -> add(testLabel);
}
void pointerPressEvent(MAPoint2d p)
{
printf("clicked"); // never occurs
// OR
if (testLabel.contains((MouseScreen*)p))
{
printf("Label clicked");
}
// Should I call parent function
// PointerListener :: pointerPressEvent(p);
}
void pointerMoveEvent(MAPoint2d p) {}
void pointerReleaseEvent(MAPoint2d p) {}
};
class MouseMoblet : public Moblet
{
public:
MouseMoblet()
{
instance = new MouseScreen();
instance -> show();
}
~MouseMoblet()
{
delete instance;
}
void keyPressEvent(int keyCode, int nativeCode)
{
// todo: handle key presses
printf("Blah"); // never occurs when I press the mouse, but other KEYS work
}
void keyReleaseEvent(int keyCode, int nativeCode)
{
// todo: handle key releases
}
private:
MouseScreen *instance;
};
extern "C" int MAMain()
{
Moblet::run(new MouseMoblet());
return 0;
};