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