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