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