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" |
| 22 | #include "SkRegion.h" |
| 23 | #include "SkEvent.h" |
| 24 | #include "SkKey.h" |
| 25 | #include "SkTDArray.h" |
| 26 | |
| 27 | #ifdef SK_BUILD_FOR_WINCEx |
| 28 | #define SHOW_FPS |
| 29 | #endif |
| 30 | //#define USE_GX_SCREEN |
| 31 | |
| 32 | class SkOSMenu; |
| 33 | |
| 34 | class SkWindow : public SkView { |
| 35 | public: |
| 36 | SkWindow(); |
| 37 | virtual ~SkWindow(); |
| 38 | |
| 39 | const SkBitmap& getBitmap() const { return fBitmap; } |
| 40 | |
| 41 | void setConfig(SkBitmap::Config); |
| 42 | void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config); |
| 43 | void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 44 | void eraseRGB(U8CPU r, U8CPU g, U8CPU b); |
| 45 | |
| 46 | bool isDirty() const { return !fDirtyRgn.isEmpty(); } |
| 47 | bool update(SkIRect* updateArea); |
| 48 | bool handleClick(int x, int y, Click::State); |
| 49 | bool handleChar(SkUnichar); |
| 50 | bool handleKey(SkKey); |
| 51 | bool handleKeyUp(SkKey); |
| 52 | bool handleMenu(uint32_t os_cmd); |
| 53 | |
| 54 | void addMenu(SkOSMenu*); |
| 55 | void setTitle(const char title[]); |
| 56 | |
| 57 | protected: |
| 58 | virtual bool onEvent(const SkEvent&); |
| 59 | |
| 60 | // called if part of our bitmap is invalidated |
| 61 | virtual void onHandleInval(const SkIRect&); |
| 62 | virtual bool onHandleChar(SkUnichar); |
| 63 | virtual bool onHandleKey(SkKey); |
| 64 | virtual bool onHandleKeyUp(SkKey); |
| 65 | virtual void onAddMenu(const SkOSMenu*) {} |
| 66 | virtual void onSetTitle(const char title[]) {} |
| 67 | |
| 68 | // overrides from SkView |
| 69 | virtual bool handleInval(const SkRect&); |
| 70 | virtual bool onGetFocusView(SkView** focus) const; |
| 71 | virtual bool onSetFocusView(SkView* focus); |
| 72 | |
| 73 | private: |
| 74 | SkBitmap::Config fConfig; |
| 75 | SkBitmap fBitmap; |
| 76 | SkRegion fDirtyRgn; |
| 77 | Click* fClick; // to track clicks |
| 78 | |
| 79 | SkTDArray<SkOSMenu*> fMenus; |
| 80 | |
| 81 | SkView* fFocusView; |
| 82 | bool fWaitingOnInval; |
| 83 | |
| 84 | typedef SkView INHERITED; |
| 85 | }; |
| 86 | |
| 87 | /////////////////////////////////////////////////////////// |
| 88 | |
| 89 | #ifndef SK_USE_WXWIDGETS |
| 90 | #ifdef SK_BUILD_FOR_MAC |
| 91 | #include "SkOSWindow_Mac.h" |
| 92 | #elif defined(SK_BUILD_FOR_WIN) |
| 93 | #include "SkOSWindow_Win.h" |
| 94 | #elif defined(SK_BUILD_FOR_UNIXx) |
| 95 | #include "SkOSWindow_Unix.h" |
| 96 | #endif |
| 97 | #else |
| 98 | #include "SkOSWindow_wxwidgets.h" |
| 99 | #endif |
| 100 | |
| 101 | #endif |
| 102 | |