reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkWindow_DEFINED |
| 9 | #define SkWindow_DEFINED |
| 10 | |
| 11 | #include "SkView.h" |
| 12 | #include "SkBitmap.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 13 | #include "SkMatrix.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 24 | class SkCanvas; |
| 25 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 35 | void setColorType(SkColorType); |
commit-bot@chromium.org | b45c56e | 2014-02-18 23:32:05 +0000 | [diff] [blame] | 36 | void resize(int width, int height, SkColorType = kUnknown_SkColorType); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | |
| 38 | bool isDirty() const { return !fDirtyRgn.isEmpty(); } |
reed@google.com | aa400ee | 2012-09-27 21:03:49 +0000 | [diff] [blame] | 39 | bool update(SkIRect* updateArea); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 40 | // does not call through to onHandleInval(), but does force the fDirtyRgn |
| 41 | // to be wide open. Call before update() to ensure we redraw everything. |
| 42 | void forceInvalAll(); |
| 43 | // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none |
| 44 | const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); } |
| 45 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 46 | bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | bool handleChar(SkUnichar); |
| 48 | bool handleKey(SkKey); |
| 49 | bool handleKeyUp(SkKey); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | |
| 51 | void addMenu(SkOSMenu*); |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 52 | const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 53 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 54 | const char* getTitle() const { return fTitle.c_str(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | void setTitle(const char title[]); |
| 56 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 57 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 58 | void setMatrix(const SkMatrix&); |
| 59 | void preConcat(const SkMatrix&); |
| 60 | void postConcat(const SkMatrix&); |
| 61 | |
reed@google.com | 5957f47 | 2012-10-01 20:31:56 +0000 | [diff] [blame] | 62 | virtual SkCanvas* createCanvas(); |
| 63 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 64 | virtual void onPDFSaved(const char title[], const char desc[], |
| 65 | const char path[]) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | protected: |
| 67 | virtual bool onEvent(const SkEvent&); |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 68 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | // called if part of our bitmap is invalidated |
| 70 | virtual void onHandleInval(const SkIRect&); |
| 71 | virtual bool onHandleChar(SkUnichar); |
| 72 | virtual bool onHandleKey(SkKey); |
| 73 | virtual bool onHandleKeyUp(SkKey); |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 74 | virtual void onAddMenu(const SkOSMenu*) {}; |
| 75 | virtual void onUpdateMenu(const SkOSMenu*) {}; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | virtual void onSetTitle(const char title[]) {} |
| 77 | |
| 78 | // overrides from SkView |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 79 | virtual bool handleInval(const SkRect*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | virtual bool onGetFocusView(SkView** focus) const; |
| 81 | virtual bool onSetFocusView(SkView* focus); |
| 82 | |
| 83 | private: |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 84 | SkColorType fColorType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | SkBitmap fBitmap; |
| 86 | SkRegion fDirtyRgn; |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 87 | |
| 88 | SkTDArray<Click*> fClicks; // to track clicks |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | |
| 90 | SkTDArray<SkOSMenu*> fMenus; |
| 91 | |
| 92 | SkView* fFocusView; |
| 93 | bool fWaitingOnInval; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 94 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 95 | SkString fTitle; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 96 | SkMatrix fMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | |
| 98 | typedef SkView INHERITED; |
| 99 | }; |
| 100 | |
tfarina@chromium.org | e229e92 | 2012-09-27 13:44:57 +0000 | [diff] [blame] | 101 | //////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 103 | #if defined(SK_BUILD_FOR_NACL) |
| 104 | #include "SkOSWindow_NaCl.h" |
| 105 | #elif defined(SK_BUILD_FOR_MAC) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | #include "SkOSWindow_Mac.h" |
| 107 | #elif defined(SK_BUILD_FOR_WIN) |
| 108 | #include "SkOSWindow_Win.h" |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 109 | #elif defined(SK_BUILD_FOR_ANDROID) |
Scroggo | f33d153 | 2011-05-31 17:10:21 +0000 | [diff] [blame] | 110 | #include "SkOSWindow_Android.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 111 | #elif defined(SK_BUILD_FOR_UNIX) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 112 | #include "SkOSWindow_Unix.h" |
reed@android.com | 671cd65 | 2009-05-22 20:44:12 +0000 | [diff] [blame] | 113 | #elif defined(SK_BUILD_FOR_SDL) |
| 114 | #include "SkOSWindow_SDL.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 115 | #elif defined(SK_BUILD_FOR_IOS) |
| 116 | #include "SkOSWindow_iOS.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | #endif |
| 118 | |
| 119 | #endif |