diff options
| author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-08 16:17:50 +0000 |
|---|---|---|
| committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-08 16:17:50 +0000 |
| commit | 4d5c26de0a24f86c37c1da8b0e30d11a550ea67b (patch) | |
| tree | ae6412d266668e9f7ca91e9ef56d65ddb3b6e9ac /samplecode/SampleApp.cpp | |
| parent | 9aaf36de60c2a2e7a6b441bb7db9521a4fd59e08 (diff) | |
pass modifier keys to click events (e.g. control | shift etc.)
Review URL: https://codereview.appspot.com/7062054
git-svn-id: http://skia.googlecode.com/svn/trunk@7082 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode/SampleApp.cpp')
| -rw-r--r-- | samplecode/SampleApp.cpp | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 716998f960..b2789bce22 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -1955,7 +1955,7 @@ bool SampleWindow::onHandleKey(SkKey key) { static const char gGestureClickType[] = "GestureClickType"; bool SampleWindow::onDispatchClick(int x, int y, Click::State state, - void* owner) { + void* owner, unsigned modi) { if (Click::kMoved_State == state) { updatePointer(x, y); } @@ -1970,9 +1970,19 @@ bool SampleWindow::onDispatchClick(int x, int y, Click::State state, //it's only necessary to update the drawing if there's a click this->inval(NULL); return false; //prevent dragging while magnify is enabled - } - else { - return this->INHERITED::onDispatchClick(x, y, state, owner); + } else { + // capture control+option, and trigger debugger + if ((modi & kControl_SkModifierKey) && (modi & kOption_SkModifierKey)) { + if (Click::kDown_State == state) { + SkEvent evt("debug-hit-test"); + evt.setS32("debug-hit-test-x", x); + evt.setS32("debug-hit-test-y", y); + curr_view(this)->doEvent(evt); + } + return true; + } else { + return this->INHERITED::onDispatchClick(x, y, state, owner, modi); + } } } @@ -1987,7 +1997,8 @@ public: } }; -SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y) { +SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y, + unsigned modi) { return new GestureClick(this); } @@ -2234,11 +2245,21 @@ bool SampleView::onEvent(const SkEvent& evt) { fRepeatCount = evt.getFast32(); return true; } + int32_t pipeHolder; if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder); return true; } + + if (evt.isType("debug-hit-test")) { + fDebugHitTest = true; + evt.findS32("debug-hit-test-x", &fDebugHitTestLoc.fX); + evt.findS32("debug-hit-test-y", &fDebugHitTestLoc.fY); + this->inval(NULL); + return true; + } + return this->INHERITED::onEvent(evt); } @@ -2347,13 +2368,46 @@ void SampleView::draw(SkCanvas* canvas) { writer.endRecording(); } } + +#include "SkBounder.h" + +class DebugHitTestBounder : public SkBounder { +public: + DebugHitTestBounder(int x, int y) { + fLoc.set(x, y); + } + + virtual bool onIRect(const SkIRect& bounds) SK_OVERRIDE { + if (bounds.contains(fLoc.x(), fLoc.y())) { + // + // Set a break-point here to see what was being drawn under + // the click point (just needed a line of code to stop the debugger) + // + bounds.centerX(); + } + return true; + } + +private: + SkIPoint fLoc; + typedef SkBounder INHERITED; +}; + void SampleView::onDraw(SkCanvas* canvas) { this->onDrawBackground(canvas); + DebugHitTestBounder bounder(fDebugHitTestLoc.x(), fDebugHitTestLoc.y()); + if (fDebugHitTest) { + canvas->setBounder(&bounder); + } + for (int i = 0; i < fRepeatCount; i++) { SkAutoCanvasRestore acr(canvas, true); this->onDrawContent(canvas); } + + fDebugHitTest = false; + canvas->setBounder(NULL); } void SampleView::onDrawBackground(SkCanvas* canvas) { |
