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