aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sk_app/Window.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-12-08 16:45:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-11 16:46:58 +0000
commit80fc07e8f854cd7c632bc06443d5f120ed002524 (patch)
tree451364a76adac42650893d3f4aaa149f3b9d2b20 /tools/sk_app/Window.cpp
parent46020c4409490dc84e389d26509cf49ea0b9cdf7 (diff)
Create a Window::Layer interface to reduce sk_app glue code
This also makes it possible to manage other parts of viewer, etc (like the stats screen, command set, even samples) as additional layers in the stack. For now, it just removes a lot of boilerplate. Bug: skia: Change-Id: Ic2f80690fc76c683b3736287dc2b738c50d38614 Reviewed-on: https://skia-review.googlesource.com/82688 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
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();