aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer/ImGuiLayer.h
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-12-08 16:46:09 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-11 17:37:58 +0000
commitd67e5189802e89e74217244b36cc7263883d5dba (patch)
tree89870d274c56c96dda04329f73538011c762a3d6 /tools/viewer/ImGuiLayer.h
parent2326177e3499d96e1e5df68504cc98764d80209a (diff)
Move ImGui support code to ImGuiLayer
Viewer still has plenty of code that uses ImGui to create application specific UI, but the structural code that forwards input to ImGui, and converts per-frame ImGui rendering data to Skia draw commands is now in a single component that can be reused in any sk_app-based application. Bug: skia: Change-Id: Ic14ece659d4af8ee13b69c638bdaf7df6c24f5c0 Reviewed-on: https://skia-review.googlesource.com/82627 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'tools/viewer/ImGuiLayer.h')
-rw-r--r--tools/viewer/ImGuiLayer.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/viewer/ImGuiLayer.h b/tools/viewer/ImGuiLayer.h
new file mode 100644
index 0000000000..1cefcd4097
--- /dev/null
+++ b/tools/viewer/ImGuiLayer.h
@@ -0,0 +1,37 @@
+/*
+* Copyright 2017 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#ifndef ImGuiLayer_DEFINED
+#define ImGuiLayer_DEFINED
+
+#include "SkPaint.h"
+#include "SkTArray.h"
+#include "sk_app/Window.h"
+#include "imgui.h"
+
+class ImGuiLayer : public sk_app::Window::Layer {
+public:
+ ImGuiLayer();
+
+ typedef std::function<void(SkCanvas*)> SkiaWidgetFunc;
+ void skiaWidget(const ImVec2& size, SkiaWidgetFunc func);
+
+ void onAttach(sk_app::Window* window) override;
+ void onPrePaint() override;
+ void onPaint(SkCanvas* canvas) override;
+ bool onMouse(int x, int y, sk_app::Window::InputState state, uint32_t modifiers) override;
+ bool onMouseWheel(float delta, uint32_t modifiers) override;
+ bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) override;
+ bool onChar(SkUnichar c, uint32_t modifiers) override;
+
+private:
+ sk_app::Window* fWindow;
+ SkPaint fFontPaint;
+ SkTArray<SkiaWidgetFunc> fSkiaWidgetFuncs;
+};
+
+#endif