| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "OverView.h" | 8 #include "OverView.h" |
| 9 | 9 |
| 10 #include "SampleCode.h" | 10 #include "SampleCode.h" |
| 11 | 11 |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkView.h" | 13 #include "SkView.h" |
| 14 | 14 |
| 15 static const int N = 8; | 15 static const int N = 8; |
| 16 static const SkScalar kWidth = SkIntToScalar(640); | 16 static const SkScalar kWidth = SkIntToScalar(640); |
| 17 static const SkScalar kHeight = SkIntToScalar(480); | 17 static const SkScalar kHeight = SkIntToScalar(480); |
| 18 static const char gIsOverview[] = "is-overview"; | 18 static const char gIsOverview[] = "is-overview"; |
| 19 | 19 |
| 20 class OverView : public SkView { | 20 class OverView : public SkView { |
| 21 public: | 21 public: |
| 22 OverView(int count, const SkViewFactory* factories[]); | 22 OverView(int count, const SkViewFactory* factories[]); |
| 23 virtual ~OverView(); | 23 virtual ~OverView(); |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 // Overridden from SkEventSink: | 26 // Overridden from SkEventSink: |
| 27 virtual bool onEvent(const SkEvent&) SK_OVERRIDE; | 27 bool onEvent(const SkEvent&) SK_OVERRIDE; |
| 28 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 28 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
| 29 if (SampleCode::TitleQ(*evt)) { | 29 if (SampleCode::TitleQ(*evt)) { |
| 30 SampleCode::TitleR(evt, "Overview"); | 30 SampleCode::TitleR(evt, "Overview"); |
| 31 return true; | 31 return true; |
| 32 } | 32 } |
| 33 if (evt->isType(gIsOverview)) { | 33 if (evt->isType(gIsOverview)) { |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 return this->INHERITED::onQuery(evt); | 36 return this->INHERITED::onQuery(evt); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 // Overridden from SkView: | 40 // Overridden from SkView: |
| 41 virtual void onSizeChange() SK_OVERRIDE; | 41 void onSizeChange() SK_OVERRIDE; |
| 42 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 42 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 43 canvas->drawColor(SK_ColorLTGRAY); | 43 canvas->drawColor(SK_ColorLTGRAY); |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual SkCanvas* beforeChildren(SkCanvas*) SK_OVERRIDE; | 46 SkCanvas* beforeChildren(SkCanvas*) SK_OVERRIDE; |
| 47 | 47 |
| 48 virtual bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) SK
_OVERRIDE { | 48 bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) SK_OVERRID
E { |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
OVERRIDE { | 52 Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE
{ |
| 53 int ix = (int)(SkScalarDiv(x * N, kWidth)); | 53 int ix = (int)(SkScalarDiv(x * N, kWidth)); |
| 54 int iy = (int)(SkScalarDiv(y * N, kHeight)); | 54 int iy = (int)(SkScalarDiv(y * N, kHeight)); |
| 55 if (ix >= 0 && iy >= 0) { | 55 if (ix >= 0 && iy >= 0) { |
| 56 SkEvent evt("set-curr-index"); | 56 SkEvent evt("set-curr-index"); |
| 57 evt.setFast32(iy * N + ix); | 57 evt.setFast32(iy * N + ix); |
| 58 this->sendEventToParents(evt); | 58 this->sendEventToParents(evt); |
| 59 } | 59 } |
| 60 return NULL; | 60 return NULL; |
| 61 } | 61 } |
| 62 | 62 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 locY += kHeight; | 104 locY += kHeight; |
| 105 locX = 0; | 105 locX = 0; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 SkCanvas* OverView::beforeChildren(SkCanvas* canvas) { | 110 SkCanvas* OverView::beforeChildren(SkCanvas* canvas) { |
| 111 canvas->scale(SK_Scalar1 / N, SK_Scalar1 / N); | 111 canvas->scale(SK_Scalar1 / N, SK_Scalar1 / N); |
| 112 return canvas; | 112 return canvas; |
| 113 } | 113 } |
| OLD | NEW |