blob: 729b7b11394b9c0919d87c25bfbb7c57ac703fd6 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
Scroggo2c8208f2011-06-15 16:49:08 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Skia
Scroggo2c8208f2011-06-15 16:49:08 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
Scroggo2c8208f2011-06-15 16:49:08 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
Scroggo2c8208f2011-06-15 16:49:08 +000010#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.com921091f2011-08-02 13:39:12 +000021#include "SkOSMenu.h"
Scroggo2c8208f2011-06-15 16:49:08 +000022
23class GrContext;
reed@google.com29038ed2011-07-06 17:56:47 +000024class GrRenderTarget;
Scroggo2c8208f2011-06-15 16:49:08 +000025
26class SkEvent;
27class SkCanvas;
Scroggo2c8208f2011-06-15 16:49:08 +000028class SkPicture;
29class SkTypeface;
yangsu@google.com501775e2011-06-24 16:04:50 +000030class SkData;
Scroggo2c8208f2011-06-15 16:49:08 +000031
Scroggo2c8208f2011-06-15 16:49:08 +000032class SampleWindow : public SkOSWindow {
33 SkTDArray<SkViewFactory> fSamples;
34public:
bsalomon@google.com098e96d2011-07-14 14:30:46 +000035 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*);
Scroggo2c8208f2011-06-15 16:49:08 +000077 virtual ~SampleWindow();
78
79 virtual void draw(SkCanvas* canvas);
80
yangsu@google.com921091f2011-08-02 13:39:12 +000081 void setDeviceType(DeviceType type);
Scroggo2c8208f2011-06-15 16:49:08 +000082 void toggleRendering();
83 void toggleSlideshow();
84 void toggleFPS();
yangsu@google.comdb03eaa2011-08-08 15:37:23 +000085 void showOverview();
bsalomon@google.com098e96d2011-07-14 14:30:46 +000086
87 GrContext* getGrContext() const { return fDevManager->getGrContext(); }
88
Scroggo2c8208f2011-06-15 16:49:08 +000089 void setZoomCenter(float x, float y);
90 void changeZoomLevel(float delta);
91 bool nextSample();
92 bool previousSample();
yangsu@google.com501775e2011-06-24 16:04:50 +000093 bool goToSample(int i);
94 SkString getSampleTitle(int i);
95 int sampleCount();
Scroggoa54e2f62011-06-17 12:46:17 +000096 bool handleTouch(int ownerId, float x, float y,
97 SkView::Click::State state);
Scroggo8ac0d542011-06-21 14:44:57 +000098 void saveToPdf();
yangsu@google.com501775e2011-06-24 16:04:50 +000099 SkData* getPDFData() { return fPDFData; }
Scroggo62b65b02011-06-21 16:01:26 +0000100 void postInvalDelay();
Scroggo2c8208f2011-06-15 16:49:08 +0000101
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
Scroggod3aed392011-06-22 13:26:56 +0000116 virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
Scroggo2c8208f2011-06-15 16:49:08 +0000117 virtual bool onClick(Click* click);
118 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
119
120private:
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000121 class DefaultDeviceManager;
122
Scroggo2c8208f2011-06-15 16:49:08 +0000123 int fCurrIndex;
124
125 SkPicture* fPicture;
Scroggo2c8208f2011-06-15 16:49:08 +0000126 SkPath fClipPath;
127
128 SkTouchGesture fGesture;
129 SkScalar fZoomLevel;
130 SkScalar fZoomScale;
131
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000132 DeviceType fDeviceType;
133 DeviceManager* fDevManager;
Scroggo2c8208f2011-06-15 16:49:08 +0000134
Scroggo8ac0d542011-06-21 14:44:57 +0000135 bool fSaveToPdf;
136 SkCanvas* fPdfCanvas;
yangsu@google.com501775e2011-06-24 16:04:50 +0000137 SkData* fPDFData;
Scroggo8ac0d542011-06-21 14:44:57 +0000138
Scroggo2c8208f2011-06-15 16:49:08 +0000139 bool fUseClip;
140 bool fNClip;
141 bool fRepeatDrawing;
142 bool fAnimating;
143 bool fRotate;
144 bool fScale;
145 bool fRequestGrabImage;
Scroggo2c8208f2011-06-15 16:49:08 +0000146 bool fMeasureFPS;
147 SkMSec fMeasureFPS_Time;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000148 bool fMagnify;
149
yangsu@google.comef7bdfa2011-08-12 14:27:47 +0000150
151 bool fUsePipe;
152 int fUsePipeMenuItemID;
153 bool fDebugger;
154
Scroggo2c8208f2011-06-15 16:49:08 +0000155 // The following are for the 'fatbits' drawing
156 // Latest position of the mouse.
157 int fMouseX, fMouseY;
158 int fFatBitsScale;
159 // Used by the text showing position and color values.
160 SkTypeface* fTypeface;
161 bool fShowZoomer;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000162
163 SkOSMenu::TriState fLCDState;
164 SkOSMenu::TriState fAAState;
165 SkOSMenu::TriState fFilterState;
166 SkOSMenu::TriState fHintingState;
Scroggo2c8208f2011-06-15 16:49:08 +0000167 unsigned fFlipAxis;
168
169 int fScrollTestX, fScrollTestY;
170 SkScalar fZoomCenterX, fZoomCenterY;
171
yangsu@google.com921091f2011-08-02 13:39:12 +0000172 //Stores global settings
173 SkOSMenu fAppMenu;
174 //Stores slide specific settings
175 SkOSMenu fSlideMenu;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000176 int fTransitionNext;
177 int fTransitionPrev;
yangsu@google.com921091f2011-08-02 13:39:12 +0000178
Scroggo2c8208f2011-06-15 16:49:08 +0000179 void loadView(SkView*);
180 void updateTitle();
181
Scroggo2c8208f2011-06-15 16:49:08 +0000182 bool zoomIn();
183 bool zoomOut();
184 void updatePointer(int x, int y);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000185 void magnify(SkCanvas* canvas);
Scroggo2c8208f2011-06-15 16:49:08 +0000186 void showZoomer(SkCanvas* canvas);
187
188 void postAnimatingEvent();
189
Scroggo2c8208f2011-06-15 16:49:08 +0000190 typedef SkOSWindow INHERITED;
191};
192
193#endif