blob: a58c68873e95bfe40e6909b5b87ad3d40e8d347a [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;
30
31class SkEvent;
32class SkCanvas;
33class SkGpuCanvas;
34class SkPicture;
35class SkTypeface;
36
37enum SkTriState {
38 kFalse_SkTriState,
39 kTrue_SkTriState,
40 kUnknown_SkTriState,
41};
42
43class SampleWindow : public SkOSWindow {
44 SkTDArray<SkViewFactory> fSamples;
45public:
46 SampleWindow(void* hwnd);
47 virtual ~SampleWindow();
48
49 virtual void draw(SkCanvas* canvas);
50
51 void toggleRendering();
52 void toggleSlideshow();
53 void toggleFPS();
54 bool drawsToHardware() { return fCanvasType == kGPU_CanvasType; }
55 bool setGrContext(GrContext*);
56 GrContext* getGrContext();
57 void setZoomCenter(float x, float y);
58 void changeZoomLevel(float delta);
59 bool nextSample();
60 bool previousSample();
Scroggoa54e2f62011-06-17 12:46:17 +000061 bool handleTouch(int ownerId, float x, float y,
62 SkView::Click::State state);
Scroggo8ac0d542011-06-21 14:44:57 +000063 void saveToPdf();
Scroggo2c8208f2011-06-15 16:49:08 +000064
65protected:
66 virtual void onDraw(SkCanvas* canvas);
67 virtual bool onHandleKey(SkKey key);
68 virtual bool onHandleChar(SkUnichar);
69 virtual void onSizeChange();
70
71 virtual SkCanvas* beforeChildren(SkCanvas*);
72 virtual void afterChildren(SkCanvas*);
73 virtual void beforeChild(SkView* child, SkCanvas* canvas);
74 virtual void afterChild(SkView* child, SkCanvas* canvas);
75
76 virtual bool onEvent(const SkEvent& evt);
77 virtual bool onQuery(SkEvent* evt);
78
79 virtual bool onDispatchClick(int x, int y, Click::State);
80 virtual bool onClick(Click* click);
81 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
82
83private:
84 int fCurrIndex;
85
86 SkPicture* fPicture;
87 SkGpuCanvas* fGpuCanvas;
88 GrContext* fGrContext;
89 SkPath fClipPath;
90
91 SkTouchGesture fGesture;
92 SkScalar fZoomLevel;
93 SkScalar fZoomScale;
94
95 enum CanvasType {
96 kRaster_CanvasType,
97 kPicture_CanvasType,
98 kGPU_CanvasType
99 };
100 CanvasType fCanvasType;
101
Scroggo8ac0d542011-06-21 14:44:57 +0000102 bool fSaveToPdf;
103 SkCanvas* fPdfCanvas;
104
Scroggo2c8208f2011-06-15 16:49:08 +0000105 bool fUseClip;
106 bool fNClip;
107 bool fRepeatDrawing;
108 bool fAnimating;
109 bool fRotate;
110 bool fScale;
111 bool fRequestGrabImage;
112 bool fUsePipe;
113 bool fMeasureFPS;
114 SkMSec fMeasureFPS_Time;
115
116 // The following are for the 'fatbits' drawing
117 // Latest position of the mouse.
118 int fMouseX, fMouseY;
119 int fFatBitsScale;
120 // Used by the text showing position and color values.
121 SkTypeface* fTypeface;
122 bool fShowZoomer;
123
124 SkTriState fLCDState;
125 SkTriState fAAState;
126 SkTriState fFilterState;
127 SkTriState fHintingState;
128 unsigned fFlipAxis;
129
130 int fScrollTestX, fScrollTestY;
131 SkScalar fZoomCenterX, fZoomCenterY;
132
133 bool make3DReady();
134
135 void loadView(SkView*);
136 void updateTitle();
137
138 void toggleZoomer();
139 bool zoomIn();
140 bool zoomOut();
141 void updatePointer(int x, int y);
142 void showZoomer(SkCanvas* canvas);
143
144 void postAnimatingEvent();
145
146 static CanvasType cycle_canvastype(CanvasType);
147
148 typedef SkOSWindow INHERITED;
149};
150
151#endif