blob: 9b47b8e0dd5a0df94cf26328815abede074f4338 [file] [log] [blame]
Scroggo2c8208f2011-06-15 16:49:08 +00001/*
2 * Copyright (C) 2011 Skia
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SampleWindow_DEFINED
18#define SampleWindow_DEFINED
19
20#include "SkWindow.h"
21
22#include "SampleCode.h"
23#include "SkPath.h"
24#include "SkScalar.h"
25#include "SkTDArray.h"
26#include "SkTouchGesture.h"
27#include "SkWindow.h"
28
29class GrContext;
reed@google.com29038ed2011-07-06 17:56:47 +000030class GrRenderTarget;
Scroggo2c8208f2011-06-15 16:49:08 +000031
32class SkEvent;
33class SkCanvas;
Scroggo2c8208f2011-06-15 16:49:08 +000034class SkPicture;
35class SkTypeface;
yangsu@google.com501775e2011-06-24 16:04:50 +000036class SkData;
Scroggo2c8208f2011-06-15 16:49:08 +000037
38enum SkTriState {
39 kFalse_SkTriState,
40 kTrue_SkTriState,
41 kUnknown_SkTriState,
42};
43
44class SampleWindow : public SkOSWindow {
45 SkTDArray<SkViewFactory> fSamples;
46public:
senorblanco@chromium.org78b82532011-06-28 19:44:03 +000047 SampleWindow(void* hwnd, int argc, char** argv);
Scroggo2c8208f2011-06-15 16:49:08 +000048 virtual ~SampleWindow();
49
50 virtual void draw(SkCanvas* canvas);
51
52 void toggleRendering();
53 void toggleSlideshow();
54 void toggleFPS();
55 bool drawsToHardware() { return fCanvasType == kGPU_CanvasType; }
56 bool setGrContext(GrContext*);
57 GrContext* getGrContext();
58 void setZoomCenter(float x, float y);
59 void changeZoomLevel(float delta);
60 bool nextSample();
61 bool previousSample();
yangsu@google.com501775e2011-06-24 16:04:50 +000062 bool goToSample(int i);
63 SkString getSampleTitle(int i);
64 int sampleCount();
Scroggoa54e2f62011-06-17 12:46:17 +000065 bool handleTouch(int ownerId, float x, float y,
66 SkView::Click::State state);
Scroggo8ac0d542011-06-21 14:44:57 +000067 void saveToPdf();
yangsu@google.com501775e2011-06-24 16:04:50 +000068 SkData* getPDFData() { return fPDFData; }
Scroggo62b65b02011-06-21 16:01:26 +000069 void postInvalDelay();
Scroggo2c8208f2011-06-15 16:49:08 +000070
71protected:
72 virtual void onDraw(SkCanvas* canvas);
73 virtual bool onHandleKey(SkKey key);
74 virtual bool onHandleChar(SkUnichar);
75 virtual void onSizeChange();
76
77 virtual SkCanvas* beforeChildren(SkCanvas*);
78 virtual void afterChildren(SkCanvas*);
79 virtual void beforeChild(SkView* child, SkCanvas* canvas);
80 virtual void afterChild(SkView* child, SkCanvas* canvas);
81
82 virtual bool onEvent(const SkEvent& evt);
83 virtual bool onQuery(SkEvent* evt);
84
Scroggod3aed392011-06-22 13:26:56 +000085 virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
Scroggo2c8208f2011-06-15 16:49:08 +000086 virtual bool onClick(Click* click);
87 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
88
89private:
90 int fCurrIndex;
91
92 SkPicture* fPicture;
Scroggo2c8208f2011-06-15 16:49:08 +000093 GrContext* fGrContext;
reed@google.com29038ed2011-07-06 17:56:47 +000094 GrRenderTarget* fGrRenderTarget;
Scroggo2c8208f2011-06-15 16:49:08 +000095 SkPath fClipPath;
96
97 SkTouchGesture fGesture;
98 SkScalar fZoomLevel;
99 SkScalar fZoomScale;
100
101 enum CanvasType {
102 kRaster_CanvasType,
103 kPicture_CanvasType,
104 kGPU_CanvasType
105 };
106 CanvasType fCanvasType;
107
Scroggo8ac0d542011-06-21 14:44:57 +0000108 bool fSaveToPdf;
109 SkCanvas* fPdfCanvas;
yangsu@google.com501775e2011-06-24 16:04:50 +0000110 SkData* fPDFData;
Scroggo8ac0d542011-06-21 14:44:57 +0000111
Scroggo2c8208f2011-06-15 16:49:08 +0000112 bool fUseClip;
113 bool fNClip;
114 bool fRepeatDrawing;
115 bool fAnimating;
116 bool fRotate;
117 bool fScale;
118 bool fRequestGrabImage;
119 bool fUsePipe;
120 bool fMeasureFPS;
121 SkMSec fMeasureFPS_Time;
122
123 // The following are for the 'fatbits' drawing
124 // Latest position of the mouse.
125 int fMouseX, fMouseY;
126 int fFatBitsScale;
127 // Used by the text showing position and color values.
128 SkTypeface* fTypeface;
129 bool fShowZoomer;
130
131 SkTriState fLCDState;
132 SkTriState fAAState;
133 SkTriState fFilterState;
134 SkTriState fHintingState;
135 unsigned fFlipAxis;
136
137 int fScrollTestX, fScrollTestY;
138 SkScalar fZoomCenterX, fZoomCenterY;
139
140 bool make3DReady();
141
142 void loadView(SkView*);
143 void updateTitle();
144
145 void toggleZoomer();
146 bool zoomIn();
147 bool zoomOut();
148 void updatePointer(int x, int y);
149 void showZoomer(SkCanvas* canvas);
150
151 void postAnimatingEvent();
152
153 static CanvasType cycle_canvastype(CanvasType);
154
155 typedef SkOSWindow INHERITED;
156};
157
158#endif