SkWindow.h revision 8ac0d542b0226e68b0faa935b3402ffc91409a02
1/* 2 * Copyright (C) 2006 The Android Open Source Project 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 SkWindow_DEFINED 18#define SkWindow_DEFINED 19 20#include "SkView.h" 21#include "SkBitmap.h" 22#include "SkMatrix.h" 23#include "SkRegion.h" 24#include "SkEvent.h" 25#include "SkKey.h" 26#include "SkTDArray.h" 27 28#ifdef SK_BUILD_FOR_WINCEx 29 #define SHOW_FPS 30#endif 31//#define USE_GX_SCREEN 32 33class SkCanvas; 34 35class SkOSMenu; 36 37class SkWindow : public SkView { 38public: 39 SkWindow(); 40 virtual ~SkWindow(); 41 42 const SkBitmap& getBitmap() const { return fBitmap; } 43 44 void setConfig(SkBitmap::Config); 45 void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config); 46 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); 47 void eraseRGB(U8CPU r, U8CPU g, U8CPU b); 48 49 bool isDirty() const { return !fDirtyRgn.isEmpty(); } 50 bool update(SkIRect* updateArea, SkCanvas* = NULL); 51 // does not call through to onHandleInval(), but does force the fDirtyRgn 52 // to be wide open. Call before update() to ensure we redraw everything. 53 void forceInvalAll(); 54 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none 55 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); } 56 57 bool handleClick(int x, int y, Click::State); 58 bool handleChar(SkUnichar); 59 bool handleKey(SkKey); 60 bool handleKeyUp(SkKey); 61 bool handleMenu(uint32_t os_cmd); 62 63 void addMenu(SkOSMenu*); 64 65 const char* getTitle() const { return fTitle.c_str(); } 66 void setTitle(const char title[]); 67 68 const SkMatrix& getMatrix() const { return fMatrix; } 69 void setMatrix(const SkMatrix&); 70 void preConcat(const SkMatrix&); 71 void postConcat(const SkMatrix&); 72 73 virtual void onPDFSaved(const char title[], const char desc[], 74 const char path[]) {} 75protected: 76 virtual bool onEvent(const SkEvent&); 77 virtual bool onDispatchClick(int x, int y, Click::State); 78 // called if part of our bitmap is invalidated 79 virtual void onHandleInval(const SkIRect&); 80 virtual bool onHandleChar(SkUnichar); 81 virtual bool onHandleKey(SkKey); 82 virtual bool onHandleKeyUp(SkKey); 83 virtual void onAddMenu(const SkOSMenu*) {} 84 virtual void onSetTitle(const char title[]) {} 85 86 // overrides from SkView 87 virtual bool handleInval(const SkRect*); 88 virtual bool onGetFocusView(SkView** focus) const; 89 virtual bool onSetFocusView(SkView* focus); 90 91private: 92 SkBitmap::Config fConfig; 93 SkBitmap fBitmap; 94 SkRegion fDirtyRgn; 95 Click* fClick; // to track clicks 96 97 SkTDArray<SkOSMenu*> fMenus; 98 99 SkView* fFocusView; 100 bool fWaitingOnInval; 101 102 SkString fTitle; 103 SkMatrix fMatrix; 104 105 typedef SkView INHERITED; 106}; 107 108/////////////////////////////////////////////////////////// 109 110#ifdef SK_USE_WXWIDGETS 111 #include "SkOSWindow_wxwidgets.h" 112#elif defined(SK_BUILD_FOR_MAC) 113 #include "SkOSWindow_Mac.h" 114#elif defined(SK_BUILD_FOR_WIN) 115 #include "SkOSWindow_Win.h" 116#elif defined(ANDROID) 117 #include "SkOSWindow_Android.h" 118#elif defined(SK_BUILD_FOR_UNIX) 119 #include "SkOSWindow_Unix.h" 120#elif defined(SK_BUILD_FOR_SDL) 121 #include "SkOSWindow_SDL.h" 122#elif defined(SK_BUILD_FOR_IOS) 123 #include "SkOSWindow_iOS.h" 124#endif 125 126#endif 127 128