epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Skia |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 10 | #ifndef SampleWindow_DEFINED |
| 11 | #define SampleWindow_DEFINED |
| 12 | |
| 13 | #include "SkWindow.h" |
| 14 | |
| 15 | #include "SampleCode.h" |
| 16 | #include "SkPath.h" |
| 17 | #include "SkScalar.h" |
| 18 | #include "SkTDArray.h" |
| 19 | #include "SkTouchGesture.h" |
| 20 | #include "SkWindow.h" |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 21 | #include "SkOSMenu.h" |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 22 | |
| 23 | class GrContext; |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 24 | class GrRenderTarget; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 25 | |
| 26 | class SkEvent; |
| 27 | class SkCanvas; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 28 | class SkPicture; |
| 29 | class SkTypeface; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 30 | class SkData; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 31 | |
| 32 | enum SkTriState { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 33 | kFalse_SkTriState = SkOSMenu::kOffState, |
| 34 | kTrue_SkTriState = SkOSMenu::kOnState, |
| 35 | kUnknown_SkTriState = SkOSMenu::kMixedState, |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | class SampleWindow : public SkOSWindow { |
| 39 | SkTDArray<SkViewFactory> fSamples; |
| 40 | public: |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 41 | enum DeviceType { |
| 42 | kRaster_DeviceType, |
| 43 | kPicture_DeviceType, |
| 44 | kGPU_DeviceType |
| 45 | }; |
| 46 | /** |
| 47 | * SampleApp ports can subclass this manager class if they want to: |
| 48 | * * filter the types of devices supported |
| 49 | * * customize plugging of SkDevice objects into an SkCanvas |
| 50 | * * customize publishing the results of draw to the OS window |
| 51 | * * manage GrContext / GrRenderTarget lifetimes |
| 52 | */ |
| 53 | class DeviceManager : public SkRefCnt { |
| 54 | public: |
| 55 | // called at end of SampleWindow cons |
| 56 | virtual void init(SampleWindow* win) = 0; |
| 57 | |
| 58 | // called when selecting a new device type |
| 59 | // can disallow a device type by returning false. |
| 60 | virtual bool supportsDeviceType(DeviceType dType) = 0; |
| 61 | |
| 62 | // called before drawing. should install correct device |
| 63 | // type on the canvas. Will skip drawing if returns false. |
| 64 | virtual bool prepareCanvas(DeviceType dType, |
| 65 | SkCanvas* canvas, |
| 66 | SampleWindow* win) = 0; |
| 67 | |
| 68 | // called after drawing, should get the results onto the |
| 69 | // screen. |
| 70 | virtual void publishCanvas(DeviceType dType, |
| 71 | SkCanvas* canvas, |
| 72 | SampleWindow* win) = 0; |
| 73 | |
| 74 | // called when window changes size, guaranteed to be called |
| 75 | // at least once before first draw (after init) |
| 76 | virtual void windowSizeChanged(SampleWindow* win) = 0; |
| 77 | |
| 78 | // return the GrContext backing gpu devices |
| 79 | virtual GrContext* getGrContext() = 0; |
| 80 | }; |
| 81 | |
| 82 | SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 83 | virtual ~SampleWindow(); |
| 84 | |
| 85 | virtual void draw(SkCanvas* canvas); |
| 86 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 87 | void setDeviceType(DeviceType type); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 88 | void toggleRendering(); |
| 89 | void toggleSlideshow(); |
| 90 | void toggleFPS(); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 91 | void togglePipe(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 92 | |
| 93 | GrContext* getGrContext() const { return fDevManager->getGrContext(); } |
| 94 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 95 | void setZoomCenter(float x, float y); |
| 96 | void changeZoomLevel(float delta); |
| 97 | bool nextSample(); |
| 98 | bool previousSample(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 99 | bool goToSample(int i); |
| 100 | SkString getSampleTitle(int i); |
| 101 | int sampleCount(); |
Scroggo | a54e2f6 | 2011-06-17 12:46:17 +0000 | [diff] [blame] | 102 | bool handleTouch(int ownerId, float x, float y, |
| 103 | SkView::Click::State state); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 104 | void saveToPdf(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 105 | SkData* getPDFData() { return fPDFData; } |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 106 | void postInvalDelay(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 107 | |
| 108 | protected: |
| 109 | virtual void onDraw(SkCanvas* canvas); |
| 110 | virtual bool onHandleKey(SkKey key); |
| 111 | virtual bool onHandleChar(SkUnichar); |
| 112 | virtual void onSizeChange(); |
| 113 | |
| 114 | virtual SkCanvas* beforeChildren(SkCanvas*); |
| 115 | virtual void afterChildren(SkCanvas*); |
| 116 | virtual void beforeChild(SkView* child, SkCanvas* canvas); |
| 117 | virtual void afterChild(SkView* child, SkCanvas* canvas); |
| 118 | |
| 119 | virtual bool onEvent(const SkEvent& evt); |
| 120 | virtual bool onQuery(SkEvent* evt); |
| 121 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 122 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 123 | virtual bool onClick(Click* click); |
| 124 | virtual Click* onFindClickHandler(SkScalar x, SkScalar y); |
| 125 | |
| 126 | private: |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 127 | class DefaultDeviceManager; |
| 128 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 129 | int fCurrIndex; |
| 130 | |
| 131 | SkPicture* fPicture; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 132 | SkPath fClipPath; |
| 133 | |
| 134 | SkTouchGesture fGesture; |
| 135 | SkScalar fZoomLevel; |
| 136 | SkScalar fZoomScale; |
| 137 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 138 | DeviceType fDeviceType; |
| 139 | DeviceManager* fDevManager; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 140 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 141 | bool fSaveToPdf; |
| 142 | SkCanvas* fPdfCanvas; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 143 | SkData* fPDFData; |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 144 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 145 | bool fUseClip; |
| 146 | bool fNClip; |
| 147 | bool fRepeatDrawing; |
| 148 | bool fAnimating; |
| 149 | bool fRotate; |
| 150 | bool fScale; |
| 151 | bool fRequestGrabImage; |
| 152 | bool fUsePipe; |
| 153 | bool fMeasureFPS; |
| 154 | SkMSec fMeasureFPS_Time; |
| 155 | |
| 156 | // The following are for the 'fatbits' drawing |
| 157 | // Latest position of the mouse. |
| 158 | int fMouseX, fMouseY; |
| 159 | int fFatBitsScale; |
| 160 | // Used by the text showing position and color values. |
| 161 | SkTypeface* fTypeface; |
| 162 | bool fShowZoomer; |
| 163 | |
| 164 | SkTriState fLCDState; |
| 165 | SkTriState fAAState; |
| 166 | SkTriState fFilterState; |
| 167 | SkTriState fHintingState; |
| 168 | unsigned fFlipAxis; |
| 169 | |
| 170 | int fScrollTestX, fScrollTestY; |
| 171 | SkScalar fZoomCenterX, fZoomCenterY; |
| 172 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 173 | //Stores global settings |
| 174 | SkOSMenu fAppMenu; |
| 175 | //Stores slide specific settings |
| 176 | SkOSMenu fSlideMenu; |
| 177 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 178 | void loadView(SkView*); |
| 179 | void updateTitle(); |
| 180 | |
| 181 | void toggleZoomer(); |
| 182 | bool zoomIn(); |
| 183 | bool zoomOut(); |
| 184 | void updatePointer(int x, int y); |
| 185 | void showZoomer(SkCanvas* canvas); |
| 186 | |
| 187 | void postAnimatingEvent(); |
| 188 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 189 | typedef SkOSWindow INHERITED; |
| 190 | }; |
| 191 | |
| 192 | #endif |