| 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkDumpCanvas.h" | 9 #include "SkDumpCanvas.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 fPictures[i] = NULL; | 40 fPictures[i] = NULL; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual ~PictFileView() { | 44 virtual ~PictFileView() { |
| 45 for (int i = 0; i < kBBoxTypeCount; ++i) { | 45 for (int i = 0; i < kBBoxTypeCount; ++i) { |
| 46 SkSafeUnref(fPictures[i]); | 46 SkSafeUnref(fPictures[i]); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void onTileSizeChanged(const SkSize &tileSize) SK_OVERRIDE { | 50 void onTileSizeChanged(const SkSize &tileSize) SK_OVERRIDE { |
| 51 if (tileSize != fTileSize) { | 51 if (tileSize != fTileSize) { |
| 52 fTileSize = tileSize; | 52 fTileSize = tileSize; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 // overrides from SkEventSink | 57 // overrides from SkEventSink |
| 58 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 58 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
| 59 if (SampleCode::TitleQ(*evt)) { | 59 if (SampleCode::TitleQ(*evt)) { |
| 60 SkString name("P:"); | 60 SkString name("P:"); |
| 61 const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); | 61 const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); |
| 62 name.append(basename ? basename+1: fFilename.c_str()); | 62 name.append(basename ? basename+1: fFilename.c_str()); |
| 63 switch (fBBox) { | 63 switch (fBBox) { |
| 64 case kNo_BBoxType: | 64 case kNo_BBoxType: |
| 65 // No name appended | 65 // No name appended |
| 66 break; | 66 break; |
| 67 case kRTree_BBoxType: | 67 case kRTree_BBoxType: |
| 68 name.append(" <bbox: R>"); | 68 name.append(" <bbox: R>"); |
| 69 break; | 69 break; |
| 70 default: | 70 default: |
| 71 SkASSERT(false); | 71 SkASSERT(false); |
| 72 break; | 72 break; |
| 73 } | 73 } |
| 74 SampleCode::TitleR(evt, name.c_str()); | 74 SampleCode::TitleR(evt, name.c_str()); |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 return this->INHERITED::onQuery(evt); | 77 return this->INHERITED::onQuery(evt); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE { | 80 bool onEvent(const SkEvent& evt) SK_OVERRIDE { |
| 81 if (evt.isType("PictFileView::toggleBBox")) { | 81 if (evt.isType("PictFileView::toggleBBox")) { |
| 82 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount); | 82 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 return this->INHERITED::onEvent(evt); | 85 return this->INHERITED::onEvent(evt); |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 88 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
| 89 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount); | 89 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount); |
| 90 SkPicture** picture = fPictures + fBBox; | 90 SkPicture** picture = fPictures + fBBox; |
| 91 | 91 |
| 92 if (!*picture) { | 92 if (!*picture) { |
| 93 *picture = LoadPicture(fFilename.c_str(), fBBox); | 93 *picture = LoadPicture(fFilename.c_str(), fBBox); |
| 94 } | 94 } |
| 95 if (*picture) { | 95 if (*picture) { |
| 96 canvas->drawPicture(*picture); | 96 canvas->drawPicture(*picture); |
| 97 } | 97 } |
| 98 } | 98 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 SampleView* CreateSamplePictFileView(const char filename[]) { | 175 SampleView* CreateSamplePictFileView(const char filename[]) { |
| 176 return new PictFileView(filename); | 176 return new PictFileView(filename); |
| 177 } | 177 } |
| 178 | 178 |
| 179 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
| 180 | 180 |
| 181 #if 0 | 181 #if 0 |
| 182 static SkView* MyFactory() { return new PictFileView; } | 182 static SkView* MyFactory() { return new PictFileView; } |
| 183 static SkViewRegister reg(MyFactory); | 183 static SkViewRegister reg(MyFactory); |
| 184 #endif | 184 #endif |
| OLD | NEW |