aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sk_app/Window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/sk_app/Window.cpp')
-rw-r--r--tools/sk_app/Window.cpp87
1 files changed, 40 insertions, 47 deletions
diff --git a/tools/sk_app/Window.cpp b/tools/sk_app/Window.cpp
index d7904fd8a7..436b6b9aa9 100644
--- a/tools/sk_app/Window.cpp
+++ b/tools/sk_app/Window.cpp
@@ -13,45 +13,7 @@
namespace sk_app {
-static void default_backend_created_func(void* userData) {}
-
-static bool default_char_func(SkUnichar c, uint32_t modifiers, void* userData) {
- return false;
-}
-
-static bool default_key_func(Window::Key key, Window::InputState state, uint32_t modifiers,
- void* userData) {
- return false;
-}
-
-static bool default_mouse_func(int x, int y, Window::InputState state, uint32_t modifiers,
- void* userData) {
- return false;
-}
-
-static bool default_mouse_wheel_func(float delta, uint32_t modifiers, void* userData) {
- return false;
-}
-
-static bool default_touch_func(intptr_t owner, Window::InputState state, float x, float y,
- void* userData) {
- return false;
-}
-
-static void default_ui_state_changed_func(
- const SkString& stateName, const SkString& stateValue, void* userData) {}
-
-static void default_paint_func(SkCanvas*, void* userData) {}
-
-Window::Window() : fBackendCreatedFunc(default_backend_created_func)
- , fCharFunc(default_char_func)
- , fKeyFunc(default_key_func)
- , fMouseFunc(default_mouse_func)
- , fMouseWheelFunc(default_mouse_wheel_func)
- , fTouchFunc(default_touch_func)
- , fUIStateChangedFunc(default_ui_state_changed_func)
- , fPaintFunc(default_paint_func) {
-}
+Window::Window() {}
void Window::detach() {
delete fWindowContext;
@@ -59,31 +21,60 @@ void Window::detach() {
}
void Window::onBackendCreated() {
- fBackendCreatedFunc(fBackendCreatedUserData);
+ for (int i = 0; i < fLayers.count(); ++i) {
+ fLayers[i]->onBackendCreated();
+ }
}
bool Window::onChar(SkUnichar c, uint32_t modifiers) {
- return fCharFunc(c, modifiers, fCharUserData);
+ for (int i = fLayers.count() - 1; i >= 0; --i) {
+ if (fLayers[i]->onChar(c, modifiers)) {
+ return true;
+ }
+ }
+ return false;
}
bool Window::onKey(Key key, InputState state, uint32_t modifiers) {
- return fKeyFunc(key, state, modifiers, fKeyUserData);
+ for (int i = fLayers.count() - 1; i >= 0; --i) {
+ if (fLayers[i]->onKey(key, state, modifiers)) {
+ return true;
+ }
+ }
+ return false;
}
bool Window::onMouse(int x, int y, InputState state, uint32_t modifiers) {
- return fMouseFunc(x, y, state, modifiers, fMouseUserData);
+ for (int i = fLayers.count() - 1; i >= 0; --i) {
+ if (fLayers[i]->onMouse(x, y, state, modifiers)) {
+ return true;
+ }
+ }
+ return false;
}
bool Window::onMouseWheel(float delta, uint32_t modifiers) {
- return fMouseWheelFunc(delta, modifiers, fMouseWheelUserData);
+ for (int i = fLayers.count() - 1; i >= 0; --i) {
+ if (fLayers[i]->onMouseWheel(delta, modifiers)) {
+ return true;
+ }
+ }
+ return false;
}
bool Window::onTouch(intptr_t owner, InputState state, float x, float y) {
- return fTouchFunc(owner, state, x, y, fTouchUserData);
+ for (int i = fLayers.count() - 1; i >= 0; --i) {
+ if (fLayers[i]->onTouch(owner, state, x, y)) {
+ return true;
+ }
+ }
+ return false;
}
void Window::onUIStateChanged(const SkString& stateName, const SkString& stateValue) {
- return fUIStateChangedFunc(stateName, stateValue, fUIStateChangedUserData);
+ for (int i = 0; i < fLayers.count(); ++i) {
+ fLayers[i]->onUIStateChanged(stateName, stateValue);
+ }
}
void Window::onPaint() {
@@ -96,7 +87,9 @@ void Window::onPaint() {
// draw into the canvas of this surface
SkCanvas* canvas = backbuffer->getCanvas();
- fPaintFunc(canvas, fPaintUserData);
+ for (int i = 0; i < fLayers.count(); ++i) {
+ fLayers[i]->onPaint(canvas);
+ }
canvas->flush();