| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef Window_DEFINED | 8 #ifndef Window_DEFINED |
| 9 #define Window_DEFINED | 9 #define Window_DEFINED |
| 10 | 10 |
| 11 #include "DisplayParams.h" | 11 #include "DisplayParams.h" |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 #include "SkTouchGesture.h" | 13 #include "SkTouchGesture.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 #include "SkJSONCPP.h" | |
| 16 | 15 |
| 17 class SkCanvas; | 16 class SkCanvas; |
| 18 | 17 |
| 19 namespace sk_app { | 18 namespace sk_app { |
| 20 | 19 |
| 21 class WindowContext; | 20 class WindowContext; |
| 22 | 21 |
| 23 class Window { | 22 class Window { |
| 24 public: | 23 public: |
| 25 static Window* CreateNativeWindow(void* platformData); | 24 static Window* CreateNativeWindow(void* platformData); |
| 26 | 25 |
| 27 virtual ~Window() {}; | 26 virtual ~Window() {}; |
| 28 | 27 |
| 29 virtual void setTitle(const char*) = 0; | 28 virtual void setTitle(const char*) = 0; |
| 30 virtual void show() = 0; | 29 virtual void show() = 0; |
| 31 virtual void setUIState(const Json::Value& state) {} // do nothing in defau
lt | |
| 32 | 30 |
| 33 // Shedules an invalidation event for window if one is not currently pending
. | 31 // Shedules an invalidation event for window if one is not currently pending
. |
| 34 // Make sure that either onPaint or markInvalReceived is called when the cli
ent window consumes | 32 // Make sure that either onPaint or markInvalReceived is called when the cli
ent window consumes |
| 35 // the the inval event. They unset fIsContentInvalided which allow future on
Inval. | 33 // the the inval event. They unset fIsContentInvalided which allow future on
Inval. |
| 36 void inval(); | 34 void inval(); |
| 37 | 35 |
| 38 virtual bool scaleContentToFit() const { return false; } | 36 virtual bool scaleContentToFit() const { return false; } |
| 39 virtual bool supportsContentRect() const { return false; } | 37 virtual bool supportsContentRect() const { return false; } |
| 40 virtual SkRect getContentRect() { return SkRect::MakeEmpty(); } | 38 virtual SkRect getContentRect() { return SkRect::MakeEmpty(); } |
| 41 | 39 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 kDown_InputState, | 103 kDown_InputState, |
| 106 kUp_InputState, | 104 kUp_InputState, |
| 107 kMove_InputState // only valid for mouse | 105 kMove_InputState // only valid for mouse |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 // return value of 'true' means 'I have handled this event' | 108 // return value of 'true' means 'I have handled this event' |
| 111 typedef bool(*OnCharFunc)(SkUnichar c, uint32_t modifiers, void* userData); | 109 typedef bool(*OnCharFunc)(SkUnichar c, uint32_t modifiers, void* userData); |
| 112 typedef bool(*OnKeyFunc)(Key key, InputState state, uint32_t modifiers, void
* userData); | 110 typedef bool(*OnKeyFunc)(Key key, InputState state, uint32_t modifiers, void
* userData); |
| 113 typedef bool(*OnMouseFunc)(int x, int y, InputState state, uint32_t modifier
s, void* userData); | 111 typedef bool(*OnMouseFunc)(int x, int y, InputState state, uint32_t modifier
s, void* userData); |
| 114 typedef bool(*OnTouchFunc)(int owner, InputState state, float x, float y, vo
id* userData); | 112 typedef bool(*OnTouchFunc)(int owner, InputState state, float x, float y, vo
id* userData); |
| 115 typedef void(*OnUIStateChangedFunc)( | |
| 116 const SkString& stateName, const SkString& stateValue, void* userDat
a); | |
| 117 typedef void(*OnPaintFunc)(SkCanvas*, void* userData); | 113 typedef void(*OnPaintFunc)(SkCanvas*, void* userData); |
| 118 | 114 |
| 119 void registerCharFunc(OnCharFunc func, void* userData) { | 115 void registerCharFunc(OnCharFunc func, void* userData) { |
| 120 fCharFunc = func; | 116 fCharFunc = func; |
| 121 fCharUserData = userData; | 117 fCharUserData = userData; |
| 122 } | 118 } |
| 123 | 119 |
| 124 void registerKeyFunc(OnKeyFunc func, void* userData) { | 120 void registerKeyFunc(OnKeyFunc func, void* userData) { |
| 125 fKeyFunc = func; | 121 fKeyFunc = func; |
| 126 fKeyUserData = userData; | 122 fKeyUserData = userData; |
| 127 } | 123 } |
| 128 | 124 |
| 129 void registerMouseFunc(OnMouseFunc func, void* userData) { | 125 void registerMouseFunc(OnMouseFunc func, void* userData) { |
| 130 fMouseFunc = func; | 126 fMouseFunc = func; |
| 131 fMouseUserData = userData; | 127 fMouseUserData = userData; |
| 132 } | 128 } |
| 133 | 129 |
| 134 void registerPaintFunc(OnPaintFunc func, void* userData) { | 130 void registerPaintFunc(OnPaintFunc func, void* userData) { |
| 135 fPaintFunc = func; | 131 fPaintFunc = func; |
| 136 fPaintUserData = userData; | 132 fPaintUserData = userData; |
| 137 } | 133 } |
| 138 | 134 |
| 139 void registerTouchFunc(OnTouchFunc func, void* userData) { | 135 void registerTouchFunc(OnTouchFunc func, void* userData) { |
| 140 fTouchFunc = func; | 136 fTouchFunc = func; |
| 141 fTouchUserData = userData; | 137 fTouchUserData = userData; |
| 142 } | 138 } |
| 143 | 139 |
| 144 void registerUIStateChangedFunc(OnUIStateChangedFunc func, void* userData) { | |
| 145 fUIStateChangedFunc = func; | |
| 146 fUIStateChangedUserData = userData; | |
| 147 } | |
| 148 | |
| 149 bool onChar(SkUnichar c, uint32_t modifiers); | 140 bool onChar(SkUnichar c, uint32_t modifiers); |
| 150 bool onKey(Key key, InputState state, uint32_t modifiers); | 141 bool onKey(Key key, InputState state, uint32_t modifiers); |
| 151 bool onMouse(int x, int y, InputState state, uint32_t modifiers); | 142 bool onMouse(int x, int y, InputState state, uint32_t modifiers); |
| 152 bool onTouch(int owner, InputState state, float x, float y); // multi-owner
= multi-touch | 143 bool onTouch(int owner, InputState state, float x, float y); // multi-owner
= multi-touch |
| 153 void onUIStateChanged(const SkString& stateName, const SkString& stateValue)
; | |
| 154 void onPaint(); | 144 void onPaint(); |
| 155 void onResize(uint32_t width, uint32_t height); | 145 void onResize(uint32_t width, uint32_t height); |
| 156 | 146 |
| 157 uint32_t width() { return fWidth; } | 147 uint32_t width() { return fWidth; } |
| 158 uint32_t height() { return fHeight; } | 148 uint32_t height() { return fHeight; } |
| 159 | 149 |
| 160 virtual const DisplayParams& getDisplayParams(); | 150 virtual const DisplayParams& getDisplayParams(); |
| 161 void setDisplayParams(const DisplayParams& params); | 151 void setDisplayParams(const DisplayParams& params); |
| 162 | 152 |
| 163 protected: | 153 protected: |
| 164 Window(); | 154 Window(); |
| 165 | 155 |
| 166 uint32_t fWidth; | 156 uint32_t fWidth; |
| 167 uint32_t fHeight; | 157 uint32_t fHeight; |
| 168 | 158 |
| 169 OnCharFunc fCharFunc; | 159 OnCharFunc fCharFunc; |
| 170 void* fCharUserData; | 160 void* fCharUserData; |
| 171 OnKeyFunc fKeyFunc; | 161 OnKeyFunc fKeyFunc; |
| 172 void* fKeyUserData; | 162 void* fKeyUserData; |
| 173 OnMouseFunc fMouseFunc; | 163 OnMouseFunc fMouseFunc; |
| 174 void* fMouseUserData; | 164 void* fMouseUserData; |
| 175 OnTouchFunc fTouchFunc; | 165 OnTouchFunc fTouchFunc; |
| 176 void* fTouchUserData; | 166 void* fTouchUserData; |
| 177 OnUIStateChangedFunc | |
| 178 fUIStateChangedFunc; | |
| 179 void* fUIStateChangedUserData; | |
| 180 OnPaintFunc fPaintFunc; | 167 OnPaintFunc fPaintFunc; |
| 181 void* fPaintUserData; | 168 void* fPaintUserData; |
| 182 | 169 |
| 183 WindowContext* fWindowContext = nullptr; | 170 WindowContext* fWindowContext = nullptr; |
| 184 | 171 |
| 185 virtual void onInval() = 0; | 172 virtual void onInval() = 0; |
| 186 | 173 |
| 187 // Uncheck fIsContentInvalided to allow future inval/onInval. | 174 // Uncheck fIsContentInvalided to allow future inval/onInval. |
| 188 void markInvalProcessed(); | 175 void markInvalProcessed(); |
| 189 | 176 |
| 190 bool fIsContentInvalidated = false; // use this to avoid duplicate invalida
te events | 177 bool fIsContentInvalidated = false; // use this to avoid duplicate invalida
te events |
| 191 }; | 178 }; |
| 192 | 179 |
| 193 } // namespace sk_app | 180 } // namespace sk_app |
| 194 #endif | 181 #endif |
| OLD | NEW |