2011-03-09 5 views
1

레이블을 클릭하거나 뾰족하게 눌렀을 때를 탐지하려고합니다. 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; 
}; 

답변

0

당신이해야 할 몇 가지를 볼 수 있습니다 아래의 클릭을 감지하는

내 시도는 일을 해달라고. 먼저 setMain (mainLayout)을 호출하여 mainLayout을 Screen의 기본 위젯으로 설정해야한다. 이것에 의해, mainLayout를 인식 할 수 있도록 (듯이) 스크린이 인식합니다. 이 작업을 완료하면 화면에서 위젯을 볼 수 있으며 클릭 이벤트도 받아야합니다.

pointerPressedEvent에서 거의 옳았습니다. testLabel의 contains 메서드는 Screen이 아닌 포인터를 사용합니다. 여기서해야 할 일은 testLabel-> contains (p.x, p.y)를 호출하여 testLabel이 클릭되었는지 평가하는 것입니다.

#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 
{ 
    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); 

      setMain(mainLayout); 
     } 

     void pointerPressEvent(MAPoint2d p) 
     { 
      if (testLabel->contains(p.x, p.y)) 
      { 
       printf("Label clicked"); 
      } 
     } 

     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; 
}; 

참고 : 현재 MoSync UI 시스템이 아닌 터치 휴대폰에 대한 설계, 그래서 포인터 이벤트를 처리하기 위해 고안 조금있다하고,이 그러나 것

전체 개정 된 코드는 다음과 같이 보입니다 출시 될 때 개선되었습니다.

기본 기능을 유지할지 여부에 따라 부모 기능을 호출할지 여부를 결정해야합니다. 현재 Screen의 기본 구현은 아무 것도하지 않습니다.