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