| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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" |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 22 | #include "SkMatrix.h" |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 33 | class SkCanvas; |
| 34 | |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | class SkOSMenu; |
| 36 | |
| 37 | class SkWindow : public SkView { |
| 38 | public: |
| 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(); } |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 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 | |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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*); |
| reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 64 | |
| 65 | const char* getTitle() const { return fTitle.c_str(); } |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | void setTitle(const char title[]); |
| 67 | |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 68 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 69 | void setMatrix(const SkMatrix&); |
| 70 | void preConcat(const SkMatrix&); |
| 71 | void postConcat(const SkMatrix&); |
| 72 | |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | protected: |
| 74 | virtual bool onEvent(const SkEvent&); |
| 75 | |
| 76 | // called if part of our bitmap is invalidated |
| 77 | virtual void onHandleInval(const SkIRect&); |
| 78 | virtual bool onHandleChar(SkUnichar); |
| 79 | virtual bool onHandleKey(SkKey); |
| 80 | virtual bool onHandleKeyUp(SkKey); |
| 81 | virtual void onAddMenu(const SkOSMenu*) {} |
| 82 | virtual void onSetTitle(const char title[]) {} |
| 83 | |
| 84 | // overrides from SkView |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 85 | virtual bool handleInval(const SkRect*); |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | virtual bool onGetFocusView(SkView** focus) const; |
| 87 | virtual bool onSetFocusView(SkView* focus); |
| 88 | |
| 89 | private: |
| 90 | SkBitmap::Config fConfig; |
| 91 | SkBitmap fBitmap; |
| 92 | SkRegion fDirtyRgn; |
| 93 | Click* fClick; // to track clicks |
| 94 | |
| 95 | SkTDArray<SkOSMenu*> fMenus; |
| 96 | |
| 97 | SkView* fFocusView; |
| 98 | bool fWaitingOnInval; |
| reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 99 | |
| 100 | SkString fTitle; |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 101 | SkMatrix fMatrix; |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | |
| 103 | typedef SkView INHERITED; |
| 104 | }; |
| 105 | |
| 106 | /////////////////////////////////////////////////////////// |
| 107 | |
| reed@android.com | 671cd65 | 2009-05-22 20:44:12 +0000 | [diff] [blame] | 108 | #ifdef SK_USE_WXWIDGETS |
| 109 | #include "SkOSWindow_wxwidgets.h" |
| 110 | #elif defined(SK_BUILD_FOR_MAC) |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | #include "SkOSWindow_Mac.h" |
| 112 | #elif defined(SK_BUILD_FOR_WIN) |
| 113 | #include "SkOSWindow_Win.h" |
| scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame^] | 114 | #elif defined(SK_BUILD_FOR_UNIX) |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | #include "SkOSWindow_Unix.h" |
| reed@android.com | 671cd65 | 2009-05-22 20:44:12 +0000 | [diff] [blame] | 116 | #elif defined(SK_BUILD_FOR_SDL) |
| 117 | #include "SkOSWindow_SDL.h" |
| reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 118 | #elif defined(SK_BUILD_FOR_IOS) |
| 119 | #include "SkOSWindow_iOS.h" |
| reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 120 | #endif |
| 121 | |
| 122 | #endif |
| 123 | |