79086b94ed
Code and docs are at: https://github.com/ocornut/imgui ImGui is an open source immediate mode GUI library that's lightweight and fairly simply to integrate. Widget functions return their state, and the library emits vertex and index data to render everything. It's got a huge set of built-in widgets and really robust layout control. For the initial integration, I had to fix up event handling in the viewer's app framework (to get mouse wheel and more keys, etc...). The new viewer 'Debug' window is toggled with the space bar. For this change, I've added one feature to that window: the slide picker. It's got a list of all slides, with filtering support, and the ability to click to switch slides. I also included the ImGui 'Demo' window (toggled with 'g'). This is nicely laid out, and includes examples of pretty much everything the library can do. It also serves as good documentation - find something that looks like what you want, and then go look at the corresponding code (all of it is in imgui_demo.cpp). I have other CLs with other features (like directly editing the primaries of the working color space), but I wanted to land this chunk first, then start adding more features. Other than adding new debugging features, there are few more outstanding work items: 1) Raster doesn't render the GUI correctly, due to non- invertible pos -> UV matrices. Florin is working on that. 2) Touch inputs aren't being routed yet, so the GUI isn't usable on Android yet. Might also be tough to work with, given the size. 3) ImGui has clipboard integration (that's why it wants the C, X, and V keys), but we need to wire it up to the OS' clipboard functions. 4) Draw commands can carry a void* payload to support drawing images (using whatever mechanism the engine has). I'd like to set that up (probably using SkImage*), which makes it really easy to add visualization of off-screen images in GMs, etc... BUG=skia: Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1 Reviewed-on: https://skia-review.googlesource.com/7702 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef Viewer_DEFINED
|
|
#define Viewer_DEFINED
|
|
|
|
#include "sk_app/Application.h"
|
|
#include "sk_app/CommandSet.h"
|
|
#include "sk_app/Window.h"
|
|
#include "gm.h"
|
|
#include "SkAnimTimer.h"
|
|
#include "SkTouchGesture.h"
|
|
#include "Slide.h"
|
|
|
|
class SkCanvas;
|
|
|
|
class Viewer : public sk_app::Application {
|
|
public:
|
|
Viewer(int argc, char** argv, void* platformData);
|
|
~Viewer() override;
|
|
|
|
void onPaint(SkCanvas* canvas);
|
|
void onIdle() override;
|
|
bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
|
bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
|
|
bool onChar(SkUnichar c, uint32_t modifiers);
|
|
|
|
private:
|
|
void initSlides();
|
|
void updateTitle();
|
|
void setColorMode(SkColorType, sk_sp<SkColorSpace>);
|
|
void setupCurrentSlide(int previousSlide);
|
|
|
|
void updateUIState();
|
|
|
|
void drawSlide(SkCanvas* canvs);
|
|
void drawStats(SkCanvas* canvas);
|
|
void drawImGui(SkCanvas* canvas);
|
|
|
|
void changeZoomLevel(float delta);
|
|
SkMatrix computeMatrix();
|
|
|
|
sk_app::Window* fWindow;
|
|
|
|
static const int kMeasurementCount = 64; // should be power of 2 for fast mod
|
|
double fPaintTimes[kMeasurementCount];
|
|
double fFlushTimes[kMeasurementCount];
|
|
double fAnimateTimes[kMeasurementCount];
|
|
int fCurrentMeasurement;
|
|
|
|
SkAnimTimer fAnimTimer;
|
|
SkTArray<sk_sp<Slide>> fSlides;
|
|
int fCurrentSlide;
|
|
|
|
bool fDisplayStats;
|
|
bool fRefresh; // whether to continuously refresh for measuring render time
|
|
|
|
sk_sp<SkImage> fImGuiFontImage;
|
|
bool fShowImGuiDebugWindow;
|
|
bool fShowImGuiTestWindow;
|
|
|
|
sk_app::Window::BackendType fBackendType;
|
|
|
|
// Color properties for slide rendering
|
|
SkColorType fColorType;
|
|
sk_sp<SkColorSpace> fColorSpace;
|
|
|
|
// transform data
|
|
SkScalar fZoomCenterX;
|
|
SkScalar fZoomCenterY;
|
|
SkScalar fZoomLevel;
|
|
SkScalar fZoomScale;
|
|
|
|
sk_app::CommandSet fCommands;
|
|
|
|
SkTouchGesture fGesture;
|
|
|
|
// identity unless the window initially scales the content to fit the screen.
|
|
SkMatrix fDefaultMatrix;
|
|
SkMatrix fDefaultMatrixInv;
|
|
|
|
Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
|
|
};
|
|
|
|
|
|
#endif
|