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