레이블을 클릭하거나 뾰족하게 눌렀을 때를 탐지하려고합니다. Win32 C++ 프로그래밍에서 왔습니다. & Java Swing과 저는 이벤트/입력에 대한 등록 방법에 대해 서로 다른 접근 방식을 취하고 있습니다.Mosync : 포인터/클릭 감지
자습서를 살펴 봤지만 클릭 감지 예제를 찾을 수 없습니다. 클릭에 대한 상수가 있나요? 그렇다면 keyPressEvent에서이를 감지 할 수 있습니다 (예 : win32 & WM_LBUTTONDOWN)? 또는 먼저 클릭을 등록한 다음 자바 (& .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;
};