blob: 35a2bb4c0e8646146649375dcac74d006d6bb124 [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();
Scroggo62b65b02011-06-21 16:01:26 +000064 void postInvalDelay();
Scroggo2c8208f2011-06-15 16:49:08 +000065
66protected:
67 virtual void onDraw(SkCanvas* canvas);
68 virtual bool onHandleKey(SkKey key);
69 virtual bool onHandleChar(SkUnichar);
70 virtual void onSizeChange();
71
72 virtual SkCanvas* beforeChildren(SkCanvas*);
73 virtual void afterChildren(SkCanvas*);
74 virtual void beforeChild(SkView* child, SkCanvas* canvas);
75 virtual void afterChild(SkView* child, SkCanvas* canvas);
76
77 virtual bool onEvent(const SkEvent& evt);
78 virtual bool onQuery(SkEvent* evt);
79
Scroggod3aed392011-06-22 13:26:56 +000080 virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
Scroggo2c8208f2011-06-15 16:49:08 +000081 virtual bool onClick(Click* click);
82 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
83
84private:
85 int fCurrIndex;
86
87 SkPicture* fPicture;
88 SkGpuCanvas* fGpuCanvas;
89 GrContext* fGrContext;
90 SkPath fClipPath;
91
92 SkTouchGesture fGesture;
93 SkScalar fZoomLevel;
94 SkScalar fZoomScale;
95
96 enum CanvasType {
97 kRaster_CanvasType,
98 kPicture_CanvasType,
99 kGPU_CanvasType
100 };
101 CanvasType fCanvasType;
102
Scroggo8ac0d542011-06-21 14:44:57 +0000103 bool fSaveToPdf;
104 SkCanvas* fPdfCanvas;
105
Scroggo2c8208f2011-06-15 16:49:08 +0000106 bool fUseClip;
107 bool fNClip;
108 bool fRepeatDrawing;
109 bool fAnimating;
110 bool fRotate;
111 bool fScale;
112 bool fRequestGrabImage;
113 bool fUsePipe;
114 bool fMeasureFPS;
115 SkMSec fMeasureFPS_Time;
116
117 // The following are for the 'fatbits' drawing
118 // Latest position of the mouse.
119 int fMouseX, fMouseY;
120 int fFatBitsScale;
121 // Used by the text showing position and color values.
122 SkTypeface* fTypeface;
123 bool fShowZoomer;
124
125 SkTriState fLCDState;
126 SkTriState fAAState;
127 SkTriState fFilterState;
128 SkTriState fHintingState;
129 unsigned fFlipAxis;
130
131 int fScrollTestX, fScrollTestY;
132 SkScalar fZoomCenterX, fZoomCenterY;
133
134 bool make3DReady();
135
136 void loadView(SkView*);
137 void updateTitle();
138
139 void toggleZoomer();
140 bool zoomIn();
141 bool zoomOut();
142 void updatePointer(int x, int y);
143 void showZoomer(SkCanvas* canvas);
144
145 void postAnimatingEvent();
146
147 static CanvasType cycle_canvastype(CanvasType);
148
149 typedef SkOSWindow INHERITED;
150};
151
152#endif