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; |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame^] | 30 | class GrRenderTarget; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 31 | |
| 32 | class SkEvent; |
| 33 | class SkCanvas; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 34 | class SkPicture; |
| 35 | class SkTypeface; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 36 | class SkData; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 37 | |
| 38 | enum SkTriState { |
| 39 | kFalse_SkTriState, |
| 40 | kTrue_SkTriState, |
| 41 | kUnknown_SkTriState, |
| 42 | }; |
| 43 | |
| 44 | class SampleWindow : public SkOSWindow { |
| 45 | SkTDArray<SkViewFactory> fSamples; |
| 46 | public: |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 47 | SampleWindow(void* hwnd, int argc, char** argv); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 48 | virtual ~SampleWindow(); |
| 49 | |
| 50 | virtual void draw(SkCanvas* canvas); |
| 51 | |
| 52 | void toggleRendering(); |
| 53 | void toggleSlideshow(); |
| 54 | void toggleFPS(); |
| 55 | bool drawsToHardware() { return fCanvasType == kGPU_CanvasType; } |
| 56 | bool setGrContext(GrContext*); |
| 57 | GrContext* getGrContext(); |
| 58 | void setZoomCenter(float x, float y); |
| 59 | void changeZoomLevel(float delta); |
| 60 | bool nextSample(); |
| 61 | bool previousSample(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 62 | bool goToSample(int i); |
| 63 | SkString getSampleTitle(int i); |
| 64 | int sampleCount(); |
Scroggo | a54e2f6 | 2011-06-17 12:46:17 +0000 | [diff] [blame] | 65 | bool handleTouch(int ownerId, float x, float y, |
| 66 | SkView::Click::State state); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 67 | void saveToPdf(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 68 | SkData* getPDFData() { return fPDFData; } |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 69 | void postInvalDelay(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 70 | |
| 71 | protected: |
| 72 | virtual void onDraw(SkCanvas* canvas); |
| 73 | virtual bool onHandleKey(SkKey key); |
| 74 | virtual bool onHandleChar(SkUnichar); |
| 75 | virtual void onSizeChange(); |
| 76 | |
| 77 | virtual SkCanvas* beforeChildren(SkCanvas*); |
| 78 | virtual void afterChildren(SkCanvas*); |
| 79 | virtual void beforeChild(SkView* child, SkCanvas* canvas); |
| 80 | virtual void afterChild(SkView* child, SkCanvas* canvas); |
| 81 | |
| 82 | virtual bool onEvent(const SkEvent& evt); |
| 83 | virtual bool onQuery(SkEvent* evt); |
| 84 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 85 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 86 | virtual bool onClick(Click* click); |
| 87 | virtual Click* onFindClickHandler(SkScalar x, SkScalar y); |
| 88 | |
| 89 | private: |
| 90 | int fCurrIndex; |
| 91 | |
| 92 | SkPicture* fPicture; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 93 | GrContext* fGrContext; |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame^] | 94 | GrRenderTarget* fGrRenderTarget; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 95 | SkPath fClipPath; |
| 96 | |
| 97 | SkTouchGesture fGesture; |
| 98 | SkScalar fZoomLevel; |
| 99 | SkScalar fZoomScale; |
| 100 | |
| 101 | enum CanvasType { |
| 102 | kRaster_CanvasType, |
| 103 | kPicture_CanvasType, |
| 104 | kGPU_CanvasType |
| 105 | }; |
| 106 | CanvasType fCanvasType; |
| 107 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 108 | bool fSaveToPdf; |
| 109 | SkCanvas* fPdfCanvas; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 110 | SkData* fPDFData; |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 111 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 112 | bool fUseClip; |
| 113 | bool fNClip; |
| 114 | bool fRepeatDrawing; |
| 115 | bool fAnimating; |
| 116 | bool fRotate; |
| 117 | bool fScale; |
| 118 | bool fRequestGrabImage; |
| 119 | bool fUsePipe; |
| 120 | bool fMeasureFPS; |
| 121 | SkMSec fMeasureFPS_Time; |
| 122 | |
| 123 | // The following are for the 'fatbits' drawing |
| 124 | // Latest position of the mouse. |
| 125 | int fMouseX, fMouseY; |
| 126 | int fFatBitsScale; |
| 127 | // Used by the text showing position and color values. |
| 128 | SkTypeface* fTypeface; |
| 129 | bool fShowZoomer; |
| 130 | |
| 131 | SkTriState fLCDState; |
| 132 | SkTriState fAAState; |
| 133 | SkTriState fFilterState; |
| 134 | SkTriState fHintingState; |
| 135 | unsigned fFlipAxis; |
| 136 | |
| 137 | int fScrollTestX, fScrollTestY; |
| 138 | SkScalar fZoomCenterX, fZoomCenterY; |
| 139 | |
| 140 | bool make3DReady(); |
| 141 | |
| 142 | void loadView(SkView*); |
| 143 | void updateTitle(); |
| 144 | |
| 145 | void toggleZoomer(); |
| 146 | bool zoomIn(); |
| 147 | bool zoomOut(); |
| 148 | void updatePointer(int x, int y); |
| 149 | void showZoomer(SkCanvas* canvas); |
| 150 | |
| 151 | void postAnimatingEvent(); |
| 152 | |
| 153 | static CanvasType cycle_canvastype(CanvasType); |
| 154 | |
| 155 | typedef SkOSWindow INHERITED; |
| 156 | }; |
| 157 | |
| 158 | #endif |