aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-22 13:26:56 +0000
committerGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-22 13:26:56 +0000
commitd3aed39ab1ad88b05b9423ee1329c227d1f8f612 (patch)
tree47960b4de36c6188aa8374e89cef85e078b5ebe0 /src
parent1eeaf0ba2381f84ffd889f56303cbe0d1886bb21 (diff)
Unify handleTouch and handleClick in SampleApp.
Allow each sample to handle clicks in Android SampleApp. Remove SampleWindow::handleTouch. Allow an SkWindow to have multiple clicks. Add an owner pointer to SkView::Click. Reviewed at http://codereview.appspot.com/4643052/ git-svn-id: http://skia.googlecode.com/svn/trunk@1673 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/views/SkView.cpp9
-rw-r--r--src/views/SkWindow.cpp88
2 files changed, 57 insertions, 40 deletions
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 1cd63394db..4b99987db1 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -296,10 +296,11 @@ void SkView::onFocusChange(bool gainFocusP)
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()
diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp
index dc833ec0b1..b35f6f26d8 100644
--- a/src/views/SkWindow.cpp
+++ b/src/views/SkWindow.cpp
@@ -41,13 +41,13 @@ private:
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();
@@ -55,9 +55,8 @@ SkWindow::SkWindow() : fFocusView(NULL)
SkWindow::~SkWindow()
{
- delete fClick;
-
- fMenus.deleteAll();
+ fClicks.deleteAll();
+ fMenus.deleteAll();
}
void SkWindow::setMatrix(const SkMatrix& matrix) {
@@ -369,40 +368,57 @@ bool SkWindow::onHandleKeyUp(SkKey key)
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;
}