Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 29 | class GrContext; |
| 30 | |
| 31 | class SkEvent; |
| 32 | class SkCanvas; |
| 33 | class SkGpuCanvas; |
| 34 | class SkPicture; |
| 35 | class SkTypeface; |
| 36 | |
| 37 | enum SkTriState { |
| 38 | kFalse_SkTriState, |
| 39 | kTrue_SkTriState, |
| 40 | kUnknown_SkTriState, |
| 41 | }; |
| 42 | |
| 43 | class SampleWindow : public SkOSWindow { |
| 44 | SkTDArray<SkViewFactory> fSamples; |
| 45 | public: |
| 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(); |
Scroggo | a54e2f6 | 2011-06-17 12:46:17 +0000 | [diff] [blame] | 61 | bool handleTouch(int ownerId, float x, float y, |
| 62 | SkView::Click::State state); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 63 | void saveToPdf(); |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 64 | void postInvalDelay(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 65 | |
| 66 | protected: |
| 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 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 80 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 81 | virtual bool onClick(Click* click); |
| 82 | virtual Click* onFindClickHandler(SkScalar x, SkScalar y); |
| 83 | |
| 84 | private: |
| 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 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 103 | bool fSaveToPdf; |
| 104 | SkCanvas* fPdfCanvas; |
| 105 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 106 | 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 |