SkDebugf("motion event ignored\n");
return;
}
- gWindow->handleTouch(owner, x, y, state);
+ gWindow->handleClick(x, y, state, (void*) owner);
}
JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_updateSize(JNIEnv* env,
SkPoint fOrig, fPrev, fCurr;
SkIPoint fIOrig, fIPrev, fICurr;
State fState;
+ void* fOwner;
private:
SkEventSinkID fTargetID;
char* fType;
// return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
- bool handleClick(int x, int y, Click::State);
+ bool handleClick(int x, int y, Click::State, void* owner = NULL);
bool handleChar(SkUnichar);
bool handleKey(SkKey);
bool handleKeyUp(SkKey);
const char path[]) {}
protected:
virtual bool onEvent(const SkEvent&);
- virtual bool onDispatchClick(int x, int y, Click::State);
+ virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
// called if part of our bitmap is invalidated
virtual void onHandleInval(const SkIRect&);
virtual bool onHandleChar(SkUnichar);
SkBitmap::Config fConfig;
SkBitmap fBitmap;
SkRegion fDirtyRgn;
- Click* fClick; // to track clicks
+
+ SkTDArray<Click*> fClicks; // to track clicks
SkTDArray<SkOSMenu*> fMenus;
static const char gGestureClickType[] = "GestureClickType";
-bool SampleWindow::onDispatchClick(int x, int y, Click::State state) {
+bool SampleWindow::onDispatchClick(int x, int y, Click::State state,
+ void* owner) {
if (Click::kMoved_State == state) {
updatePointer(x, y);
}
if (w - x < 16 && h - y < 16) {
return false; // let the OS handle the click
} else {
- return this->INHERITED::onDispatchClick(x, y, state);
+ return this->INHERITED::onDispatchClick(x, y, state, owner);
}
}
return new GestureClick(this);
}
-union IntPtr {
- int fInt;
- void* fPtr;
-};
-
-static void* int2ptr(int n) {
- IntPtr data;
- data.fInt = n;
- return data.fPtr;
-}
-
-bool SampleWindow::handleTouch(int ownerId, float x, float y, SkView::Click::State state) {
- void* click = int2ptr(ownerId);
- switch(state) {
- case SkView::Click::kDown_State:
- fGesture.touchBegin(click, x, y);
- break;
- case SkView::Click::kMoved_State:
- fGesture.touchMoved(click, x, y);
- this->inval(NULL);
- break;
- case SkView::Click::kUp_State:
- fGesture.touchEnd(click);
- this->inval(NULL);
- break;
- default:
- return false;
- }
- return true;
-}
-
bool SampleWindow::onClick(Click* click) {
if (GestureClick::IsGesture(click)) {
float x = SkScalarToFloat(click->fCurr.fX);
float y = SkScalarToFloat(click->fCurr.fY);
switch (click->fState) {
case SkView::Click::kDown_State:
- fGesture.touchBegin(click, x, y);
+ fGesture.touchBegin(click->fOwner, x, y);
break;
case SkView::Click::kMoved_State:
- fGesture.touchMoved(click, x, y);
+ fGesture.touchMoved(click->fOwner, x, y);
this->inval(NULL);
break;
case SkView::Click::kUp_State:
- fGesture.touchEnd(click);
+ fGesture.touchEnd(click->fOwner);
this->inval(NULL);
break;
}
virtual bool onEvent(const SkEvent& evt);
virtual bool onQuery(SkEvent* evt);
- virtual bool onDispatchClick(int x, int y, Click::State);
+ virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
virtual bool onClick(Click* click);
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
SkView::Click::Click(SkView* target)
{
- SkASSERT(target);
- fTargetID = target->getSinkID();
- fType = NULL;
- fWeOwnTheType = false;
+ SkASSERT(target);
+ fTargetID = target->getSinkID();
+ fType = NULL;
+ fWeOwnTheType = false;
+ fOwner = NULL;
}
SkView::Click::~Click()
SkWindow::SkWindow() : fFocusView(NULL)
{
- fClick = NULL;
- fWaitingOnInval = false;
+ fClicks.reset();
+ fWaitingOnInval = false;
#ifdef SK_BUILD_FOR_WINCE
- fConfig = SkBitmap::kRGB_565_Config;
+ fConfig = SkBitmap::kRGB_565_Config;
#else
- fConfig = SkBitmap::kARGB_8888_Config;
+ fConfig = SkBitmap::kARGB_8888_Config;
#endif
fMatrix.reset();
SkWindow::~SkWindow()
{
- delete fClick;
-
- fMenus.deleteAll();
+ fClicks.deleteAll();
+ fMenus.deleteAll();
}
void SkWindow::setMatrix(const SkMatrix& matrix) {
return false;
}
-bool SkWindow::handleClick(int x, int y, Click::State state) {
- return this->onDispatchClick(x, y, state);
+bool SkWindow::handleClick(int x, int y, Click::State state, void *owner) {
+ return this->onDispatchClick(x, y, state, owner);
}
-bool SkWindow::onDispatchClick(int x, int y, Click::State state) {
+bool SkWindow::onDispatchClick(int x, int y, Click::State state,
+ void* owner) {
bool handled = false;
+ // First, attempt to find an existing click with this owner.
+ int index = -1;
+ for (int i = 0; i < fClicks.count(); i++) {
+ if (owner == fClicks[i]->fOwner) {
+ index = i;
+ break;
+ }
+ }
+
switch (state) {
- case Click::kDown_State:
- if (fClick)
- delete fClick;
- fClick = this->findClickHandler(SkIntToScalar(x), SkIntToScalar(y));
- if (fClick)
- {
- SkView::DoClickDown(fClick, x, y);
- handled = true;
- }
- break;
- case Click::kMoved_State:
- if (fClick)
- {
- SkView::DoClickMoved(fClick, x, y);
- handled = true;
- }
- break;
- case Click::kUp_State:
- if (fClick)
- {
- SkView::DoClickUp(fClick, x, y);
- delete fClick;
- fClick = NULL;
- handled = true;
- }
- break;
+ case Click::kDown_State: {
+ if (index != -1) {
+ delete fClicks[index];
+ fClicks.remove(index);
+ }
+ Click* click = this->findClickHandler(SkIntToScalar(x),
+ SkIntToScalar(y));
+
+ if (click) {
+ click->fOwner = owner;
+ *fClicks.append() = click;
+ SkView::DoClickDown(click, x, y);
+ handled = true;
+ }
+ break;
+ }
+ case Click::kMoved_State:
+ if (index != -1) {
+ SkView::DoClickMoved(fClicks[index], x, y);
+ handled = true;
+ }
+ break;
+ case Click::kUp_State:
+ if (index != -1) {
+ SkView::DoClickUp(fClicks[index], x, y);
+ delete fClicks[index];
+ fClicks.remove(index);
+ handled = true;
+ }
+ break;
+ default:
+ // Do nothing
+ break;
}
return handled;
}