int16_t PaintPlugin::handleEvent(const ANPEvent* evt) { switch (evt->eventType) { case kTouch_ANPEventType: { float x = (float) evt->data.touch.x; float y = (float) evt->data.touch.y; if (kDown_ANPTouchAction == evt->data.touch.action && m_isTouchCurrentInput) { ANPRectF* rect = validTouch(evt->data.touch.x, evt->data.touch.y); if(rect == &m_drawingSurface) { m_isTouchActive = true; gPathI.moveTo(m_touchPath, x, y); paintTouch(); return 1; } } else if (kMove_ANPTouchAction == evt->data.touch.action && m_isTouchActive) { gPathI.lineTo(m_touchPath, x, y); paintTouch(); return 1; } else if (kUp_ANPTouchAction == evt->data.touch.action && m_isTouchActive) { gPathI.lineTo(m_touchPath, x, y); paintTouch(); m_isTouchActive = false; gPathI.reset(m_touchPath); return 1; } else if (kCancel_ANPTouchAction == evt->data.touch.action) { m_isTouchActive = false; gPathI.reset(m_touchPath); return 1; } else if (kDoubleTap_ANPTouchAction == evt->data.touch.action) { gWindowI.requestCenterFitZoom(inst()); return 1; } break; } case kMouse_ANPEventType: { if (m_isTouchActive) gLogI.log(kError_ANPLogType, "----%p Received unintended mouse event", inst()); if (kDown_ANPMouseAction == evt->data.mouse.action) { ANPRectF* rect = validTouch(evt->data.mouse.x, evt->data.mouse.y); if (rect == &m_drawingSurface) paintMouse(evt->data.mouse.x, evt->data.mouse.y); else if (rect == &m_inputToggle) toggleInputMethod(); else if (rect == &m_colorToggle) togglePaintColor(); else if (rect == &m_fullScreenToggle) gWindowI.requestFullScreen(inst()); else if (rect == &m_clearSurface) drawCleanPlugin(); } return 1; } case kCustom_ANPEventType: { switch (evt->data.other[0]) { case kSurfaceCreated_CustomEvent: gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceCreated"); /* The second draw call is added to cover up a problem in this plugin and is not a recommended usage pattern. This plugin does not correctly make partial updates to the double buffered surface and this second call hides that problem. */ drawCleanPlugin(); drawCleanPlugin(); break; case kSurfaceChanged_CustomEvent: { gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceChanged"); int width = evt->data.other[1]; int height = evt->data.other[2]; PluginObject *obj = (PluginObject*) inst()->pdata; const int pW = obj->window->width; const int pH = obj->window->height; // compare to the plugin's surface dimensions if (pW != width || pH != height) gLogI.log(kError_ANPLogType, "----%p Invalid Surface Dimensions (%d,%d):(%d,%d)", inst(), pW, pH, width, height); break; } case kSurfaceDestroyed_CustomEvent: gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceDestroyed"); break; } break; // end KCustom_ANPEventType } default: break; } return 0; // unknown or unhandled event }
void moveMouse(int x, int y) { recMouseBackground(); saveMouseBackground(x, y); paintMouse(x, y); }