EGLWLInputEventExample: touch event support and improvement of drawing
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Sat, 29 Sep 2012 22:43:07 +0000 (07:43 +0900)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Thu, 22 Nov 2012 10:01:28 +0000 (02:01 -0800)
-Adds touch event listener.
-Drawing of eyes by polygon instead of line.

LayerManagerExamples/EGLWLInputEventExample/include/WLContext.h
LayerManagerExamples/EGLWLInputEventExample/include/WLEyes.h
LayerManagerExamples/EGLWLInputEventExample/include/WLEyesRenderer.h
LayerManagerExamples/EGLWLInputEventExample/src/WLContext.cpp
LayerManagerExamples/EGLWLInputEventExample/src/WLEGLSurface.cpp
LayerManagerExamples/EGLWLInputEventExample/src/WLEyes.cpp
LayerManagerExamples/EGLWLInputEventExample/src/WLEyesRenderer.cpp
LayerManagerExamples/EGLWLInputEventExample/src/WLSurface.cpp

index f0f4154..864959e 100644 (file)
@@ -34,12 +34,14 @@ private:
     struct wl_seat*       m_wlSeat;
     struct wl_pointer*    m_wlPointer;
     struct wl_keyboard*   m_wlKeyboard;
+    struct wl_touch*      m_wlTouch;
     struct serverinfo*    m_wlServerInfo;
     uint32_t m_mask;
     uint32_t m_connectionId;
 
     struct wl_pointer_listener*  m_wlPointerListener;
     struct wl_keyboard_listener* m_wlKeyboardListener;
+    struct wl_touch_listener*    m_wlTouchListener;
 
 // methods
 public:
@@ -47,15 +49,18 @@ public:
     virtual ~WLContext();
 
     bool InitWLContext(const struct wl_pointer_listener* wlPointerListener = NULL,
-                       const struct wl_keyboard_listener* wlKeyboardListener = NULL);
+                       const struct wl_keyboard_listener* wlKeyboardListener = NULL,
+                       const struct wl_touch_listener* wlTouchListener = NULL);
 
     struct wl_compositor* GetWLCompositor() const;
     struct wl_display* GetWLDisplay() const;
     struct wl_pointer* GetWLPointer() const;
     struct wl_keyboard* GetWLKeyboard() const;
+    struct wl_touch* GetWLTouch() const;
     struct wl_seat* GetWLSeat() const;
     struct wl_pointer_listener* GetWLPointerListener() const;
     struct wl_keyboard_listener* GetWLKeyboardListener() const;
+    struct wl_touch_listener* GetWLTouchListener() const;
     uint32_t GetConnectionId() const;
 
     void SetEventMask(uint32_t mask);
@@ -65,6 +70,7 @@ public:
     void SetConnectionId(uint32_t connectionId);
     void SetWLPointer(struct wl_pointer* wlPointer);
     void SetWLKeyboard(struct wl_keyboard* wlKeyboard);
+    void SetWLTouch(struct wl_touch* wlTouch);
 
     static void DisplayHandleGlobal(struct wl_display* display,
                                     uint32_t id,
@@ -87,11 +93,14 @@ inline struct wl_compositor* WLContext::GetWLCompositor() const { return m_wlCom
 inline struct wl_display* WLContext::GetWLDisplay() const { return m_wlDisplay; }
 inline struct wl_pointer* WLContext::GetWLPointer() const { return m_wlPointer; }
 inline struct wl_keyboard* WLContext::GetWLKeyboard() const { return m_wlKeyboard; }
+inline struct wl_touch* WLContext::GetWLTouch() const { return m_wlTouch; }
 inline struct wl_seat* WLContext::GetWLSeat() const { return m_wlSeat; }
 inline struct wl_pointer_listener* WLContext::GetWLPointerListener() const
     { return m_wlPointerListener; }
 inline struct wl_keyboard_listener* WLContext::GetWLKeyboardListener() const
     { return m_wlKeyboardListener; }
+inline struct wl_touch_listener* WLContext::GetWLTouchListener() const
+    { return m_wlTouchListener; }
 inline uint32_t WLContext::GetConnectionId() const { return m_connectionId; }
 
 inline void WLContext::SetEventMask(uint32_t mask) { m_mask = mask; }
@@ -107,5 +116,7 @@ inline void WLContext::SetWLPointer(struct wl_pointer* wlPointer)
     { m_wlPointer = wlPointer; }
 inline void WLContext::SetWLKeyboard(struct wl_keyboard* wlKeyboard)
     { m_wlKeyboard = wlKeyboard; }
+inline void WLContext::SetWLTouch(struct wl_touch* wlTouch)
+    { m_wlTouch = wlTouch; }
 
 #endif
index 3807913..e4d9552 100644 (file)
@@ -31,6 +31,8 @@ private:
     TPoint* m_eyeLiner;
     int     m_nPupilPoint;
     TPoint* m_pupil;
+    int     m_nWhiteEyePoint;
+    TPoint* m_whiteEye;
 
 public:
     WLEye();
@@ -46,7 +48,14 @@ public:
                      const Transform& trans);
 
     void GetEyeLinerGeom(int* nPoint, float** points);
+    void GetWhiteEyeGeom(int* nPoint, float** points);
     void GetPupilGeom(int* nPoint, float** points);
+
+private:
+    void CreateWhiteEye(const float& centerX,
+                        const float& centerY,
+                        const float& diam,
+                        const Transform& trans);
 };
 
 //////////////////////////////////////////////////////////////////////////////
@@ -66,6 +75,7 @@ public:
     void SetPointOfView(int mousePosX, int mousePosY);
 
     void GetEyeLinerGeom(int n, int* nPoint, float** points);
+    void GetWhiteEyeGeom(int n, int* nPoint, float** points);
     void GetPupilGeom(int n, int* nPoint, float** points);
 
 private:
index 1a4e276..b268be7 100644 (file)
@@ -50,26 +50,20 @@ void KeyboardHandleKey(void*, struct wl_keyboard*, uint32_t, uint32_t, uint32_t,
 void KeyboardHandleModifiers(void*, struct wl_keyboard*, uint32_t, uint32_t,
                              uint32_t, uint32_t, uint32_t);
 
+// Touch event handler
+void TouchHandleDown(void*, struct wl_touch*, uint32_t, uint32_t, struct wl_surface*,
+                     int32_t, wl_fixed_t, wl_fixed_t);
+void TouchHandleUp(void*, struct wl_touch*, uint32_t, uint32_t, int32_t);
+void TouchHandleMotion(void*, struct wl_touch*, uint32_t, int32_t, wl_fixed_t, wl_fixed_t);
+void TouchHandleFrame(void*, struct wl_touch*);
+void TouchHandleCancel(void*, struct wl_touch*);
+
 bool DrawEyes(WLEGLSurface* surface, WLEyes* eyes);
 void DrawFillPoly(const int nPoint, const float* points, const float color[4]);
 void DrawPoly(const int nPoint, const float* points, const float color[4], int width);
 
-const struct wl_pointer_listener PointerListener
-{
-    PointerHandleEnter,
-    PointerHandleLeave,
-    PointerHandleMotion,
-    PointerHandleButton,
-    PointerHandleAxis
-};
-
-const struct wl_keyboard_listener KeyboardListener
-{
-    KeyboardHandleKeymap,
-    KeyboardHandleEnter,
-    KeyboardHandleLeave,
-    KeyboardHandleKey,
-    KeyboardHandleModifiers,
-};
+extern const struct wl_pointer_listener PointerListener;
+extern const struct wl_keyboard_listener KeyboardListener;
+extern const struct wl_touch_listener TouchListener;
 
 #endif
index 246c070..874b0b9 100644 (file)
@@ -43,10 +43,13 @@ WLContext::WLContext()
 , m_wlCompositor(NULL)
 , m_wlSeat(NULL)
 , m_wlPointer(NULL)
+, m_wlTouch(NULL)
 , m_wlServerInfo(NULL)
 , m_mask(0)
 , m_connectionId(0)
 , m_wlPointerListener(NULL)
+, m_wlKeyboardListener(NULL)
+, m_wlTouchListener(NULL)
 {
 }
 
@@ -155,16 +158,30 @@ WLContext::SeatHandleCapabilities(void* data, struct wl_seat* seat, uint32_t cap
         wlKeyboard = NULL;
     }
     context->SetWLKeyboard(wlKeyboard);
+
+    struct wl_touch* wlTouch = context->GetWLTouch();
+    if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !wlTouch){
+        wlTouch = wl_seat_get_touch(wlSeat);
+        wl_touch_set_user_data(wlTouch, data);
+        wl_touch_add_listener(wlTouch, context->GetWLTouchListener(), data);
+    } else
+    if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && wlTouch){
+        wl_touch_destroy(wlTouch);
+        wlTouch = NULL;
+    }
+    context->SetWLTouch(wlTouch);
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
 bool
 WLContext::InitWLContext(const struct wl_pointer_listener* wlPointerListener,
-                         const struct wl_keyboard_listener* wlKeyboardListener)
+                         const struct wl_keyboard_listener* wlKeyboardListener,
+                         const struct wl_touch_listener* wlTouchListener)
 {
     m_wlPointerListener = const_cast<wl_pointer_listener*>(wlPointerListener);
     m_wlKeyboardListener = const_cast<wl_keyboard_listener*>(wlKeyboardListener);
+    m_wlTouchListener = const_cast<wl_touch_listener*>(wlTouchListener);
 
     m_wlDisplay = wl_display_connect(NULL);
 
index bea6c2f..226a75b 100644 (file)
@@ -64,6 +64,8 @@ WLEGLSurface::CreatePlatformSurface()
         EGL_GREEN_SIZE, 8,
         EGL_BLUE_SIZE,  8,
         EGL_ALPHA_SIZE, 8,
+        //EGL_SAMPLE_BUFFERS, 1,
+        //EGL_SAMPLES,        2,
         EGL_NONE,
     };
     EGLint contextAttribs[] = {
index cf0f3f4..07580b6 100644 (file)
@@ -205,6 +205,8 @@ WLEye::WLEye()
 , m_eyeLiner(NULL)
 , m_nPupilPoint(0)
 , m_pupil(NULL)
+, m_nWhiteEyePoint(0)
+, m_whiteEye(NULL)
 {
 }
 
@@ -216,6 +218,9 @@ WLEye::~WLEye()
     if (m_nPupilPoint > 0 && m_pupil){
         free(m_pupil);
     }
+    if (m_nWhiteEyePoint > 0 && m_whiteEye){
+        free(m_whiteEye);
+    }
 }
 
 void
@@ -227,6 +232,19 @@ WLEye::CreateEyeLiner(const float& centerX, const float& centerY,
         m_nPoint = 0;
     }
     CreateEllipsePoints(centerX, centerY, diam, trans, m_nPoint, m_eyeLiner);
+
+    CreateWhiteEye(centerX, centerY, diam * 0.8, trans);
+}
+
+void
+WLEye::CreateWhiteEye(const float& centerX, const float& centerY,
+                      const float& diam, const Transform& trans)
+{
+    if (m_nWhiteEyePoint > 0 && m_whiteEye){
+        free(m_whiteEye);
+        m_nWhiteEyePoint = 0;
+    }
+    CreateEllipsePoints(centerX, centerY, diam, trans, m_nWhiteEyePoint, m_whiteEye);
 }
 
 void
@@ -248,6 +266,13 @@ WLEye::GetEyeLinerGeom(int* nPoint, float** points)
 }
 
 void
+WLEye::GetWhiteEyeGeom(int* nPoint, float** points)
+{
+    *nPoint = m_nWhiteEyePoint;
+    *points = (float*)m_whiteEye;
+}
+
+void
 WLEye::GetPupilGeom(int* nPoint, float** points)
 {
     *nPoint = m_nPupilPoint;
@@ -300,6 +325,16 @@ WLEyes::GetEyeLinerGeom(int n, int* nPoint, float** points)
 }
 
 void
+WLEyes::GetWhiteEyeGeom(int n, int* nPoint, float** points)
+{
+    *nPoint = 0;
+    *points = NULL;
+    if (n < 3){
+        m_eyes[n]->GetWhiteEyeGeom(nPoint, points);
+    }
+}
+
+void
 WLEyes::GetPupilGeom(int n, int* nPoint, float** points)
 {
     *nPoint = 0;
index f5fa216..4ddbefc 100644 (file)
@@ -31,6 +31,30 @@ extern int gNeedRedraw;
 extern int gPointerX;
 extern int gPointerY;
 
+const struct wl_pointer_listener PointerListener = {
+    PointerHandleEnter,
+    PointerHandleLeave,
+    PointerHandleMotion,
+    PointerHandleButton,
+    PointerHandleAxis
+};
+
+const struct wl_keyboard_listener KeyboardListener = {
+    KeyboardHandleKeymap,
+    KeyboardHandleEnter,
+    KeyboardHandleLeave,
+    KeyboardHandleKey,
+    KeyboardHandleModifiers,
+};
+
+const struct wl_touch_listener TouchListener = {
+    TouchHandleDown,
+    TouchHandleUp,
+    TouchHandleMotion,
+    TouchHandleFrame,
+    TouchHandleCancel,
+};
+
 void WaitForEvent(struct wl_display* wlDisplay)
 {
     wl_display_iterate(wlDisplay, WL_DISPLAY_READABLE);
@@ -174,6 +198,61 @@ KeyboardHandleModifiers(void* data, struct wl_keyboard* keyboard, uint32_t seria
 
 //////////////////////////////////////////////////////////////////////////////
 
+void
+TouchHandleDown(void* data, struct wl_touch* touch, uint32_t serial, uint32_t time,
+                struct wl_surface* surface, int32_t id, wl_fixed_t xw, wl_fixed_t yw)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(surface);
+    WL_UNUSED(id);
+    WL_UNUSED(xw);
+    WL_UNUSED(yw);
+    printf("ENTER TouchHandleDown\n");
+}
+
+void
+TouchHandleUp(void* data, struct wl_touch* touch, uint32_t serial, uint32_t time, int32_t id)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(id);
+    printf("ENTER TouchHandleUp\n");
+}
+
+void
+TouchHandleMotion(void* data, struct wl_touch* touch, uint32_t time, int32_t id,
+                  wl_fixed_t xw, wl_fixed_t yw)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(time);
+    WL_UNUSED(id);
+    WL_UNUSED(xw);
+    WL_UNUSED(yw);
+    printf("ENTER TouchHandleMotion\n");
+}
+
+void
+TouchHandleFrame(void* data, struct wl_touch* touch)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+}
+
+void
+TouchHandleCancel(void* data, struct wl_touch* touch)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
 typedef struct _es2shaderobject {
     GLuint fragmentShaderId;
     GLuint vertexShaderId;
@@ -384,6 +463,7 @@ DrawEyes(WLEGLSurface* surface, WLEyes* eyes)
                           0.0,    b, 0.0, 0.0,
                           0.0,  0.0, 1.0, 0.0,
                          -1.0, -1.0, 0.0, 1.0};
+
         glUniformMatrix4fv(gShaderObject.matrixLocation, 1, GL_FALSE, mtx);
 
         eyes->SetPointOfView(gPointerX, gPointerY);
@@ -393,18 +473,26 @@ DrawEyes(WLEGLSurface* surface, WLEyes* eyes)
         int nPoint = 0;
         float* points = NULL;
         for (int ii = 0; ii < 2; ++ii){
+            // eye liner
             eyes->GetEyeLinerGeom(ii, &nPoint, &points);
             if (nPoint <= 0 || points == NULL){
                 continue;
             }
-            DrawFillPoly(nPoint, points, white); // eye shape
-            DrawPoly((nPoint - 1), &points[2], black, 20); // eye liner
+            DrawFillPoly(nPoint, points, black);
+
+            // eye shape (white eye)
+            eyes->GetWhiteEyeGeom(ii, &nPoint, &points);
+            if (nPoint <= 0 || points == NULL){
+                continue;
+            }
+            DrawFillPoly(nPoint, points, white);
 
+            // pupil
             eyes->GetPupilGeom(ii, &nPoint, &points);
             if (nPoint <= 0 || points == NULL){
                 continue;
             }
-            DrawFillPoly(nPoint, points, black); // pupil
+            DrawFillPoly(nPoint, points, black);
         }
     }
     DetachVertexBuffer();
index 722c1dd..3bd2f79 100644 (file)
@@ -94,7 +94,7 @@ WLSurface::CreateIlmSurface(t_ilm_layer* layerId,
 
     rtnv = ilm_layerAddSurface(*layerId, *surfaceId);
     rtnv = ilm_UpdateInputEventAcceptanceOn(*surfaceId,
-                                            INPUT_DEVICE_POINTER,
+                                            INPUT_DEVICE_POINTER | INPUT_DEVICE_TOUCH,
                                             ILM_TRUE);
     rtnv = ilm_SetKeyboardFocusOn(*surfaceId);