Chromium Code Reviews| Index: tools/viewer/Viewer.cpp |
| diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp |
| index c4b8b26dc51e3fda5a43a66962f5dba0a397de0d..f0de75d543f31cc46ee579079744139498a9414f 100644 |
| --- a/tools/viewer/Viewer.cpp |
| +++ b/tools/viewer/Viewer.cpp |
| @@ -35,6 +35,12 @@ static bool on_touch_handler(int owner, Window::InputState state, float x, float |
| return viewer->onTouch(owner, state, x, y); |
| } |
| +static void on_ui_state_changed_handler(const SkString& stateName, const SkString& stateValue, void* userData) { |
| + Viewer* viewer = reinterpret_cast<Viewer*>(userData); |
| + |
| + return viewer->onUIStateChanged(stateName, stateValue); |
| +} |
| + |
| DEFINE_bool2(fullscreen, f, true, "Run fullscreen."); |
| DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifying this builder."); |
| DEFINE_string2(match, m, nullptr, |
| @@ -53,6 +59,12 @@ const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { |
| " [Vulkan]" |
| }; |
| +const char* kName = "name"; |
| +const char* kValue = "value"; |
| +const char* kOptions = "options"; |
| +const char* kSlideStateName = "Slide"; |
| +const char* kBackendStateName = "Backend"; |
| + |
| Viewer::Viewer(int argc, char** argv, void* platformData) |
| : fCurrentMeasurement(0) |
| , fDisplayStats(false) |
| @@ -79,6 +91,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData) |
| fCommands.attach(fWindow); |
| fWindow->registerPaintFunc(on_paint_handler, this); |
| fWindow->registerTouchFunc(on_touch_handler, this); |
| + fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this); |
| // add key-bindings |
| fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { |
| @@ -213,6 +226,10 @@ void Viewer::updateTitle() { |
| } |
| void Viewer::setupCurrentSlide(int previousSlide) { |
| + if (fCurrentSlide == previousSlide) { |
| + return; // no change; do nothing |
| + } |
| + |
| fGesture.reset(); |
| fDefaultMatrix.reset(); |
| fDefaultMatrixInv.reset(); |
| @@ -235,6 +252,7 @@ void Viewer::setupCurrentSlide(int previousSlide) { |
| } |
| this->updateTitle(); |
| + this->fWindow->setUIState(computeUIStateJson()); |
|
djsollen
2016/05/26 18:08:40
just call a private updateUIState() function that
|
| fSlides[fCurrentSlide]->load(); |
| if (previousSlide >= 0) { |
| fSlides[previousSlide]->unload(); |
| @@ -382,3 +400,48 @@ void Viewer::onIdle(double ms) { |
| fWindow->inval(); |
| } |
| } |
| + |
| +Json::Value Viewer::computeUIStateJson() const { |
|
djsollen
2016/05/26 18:08:40
rename to updateUIState
|
| + Json::Value slideState(Json::objectValue); |
| + slideState[kName] = kSlideStateName; |
| + slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); |
| + Json::Value allSlideNames(Json::arrayValue); |
| + for(auto slide : fSlides) { |
| + allSlideNames.append(Json::Value(slide->getName().c_str())); |
| + } |
| + slideState[kOptions] = allSlideNames; |
| + |
| + // This state is currently a demo for the one without options. |
| + // We will be able to change the backend too. |
| + Json::Value backendState(Json::objectValue); |
| + backendState[kName] = kBackendStateName; |
| + backendState[kValue] = fBackendType == sk_app::Window::kVulkan_BackendType ? |
| + "Vulkan" : "Other than Vulkan"; |
| + backendState[kOptions] = Json::Value(Json::arrayValue); |
| + |
| + Json::Value state(Json::arrayValue); |
| + state.append(slideState); |
| + state.append(backendState); |
| + return state; |
| +} |
| + |
| +void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) { |
| + // Currently, we only recognize the Slide state |
| + if (stateName.equals(kSlideStateName)) { |
| + int previousSlide = fCurrentSlide; |
| + fCurrentSlide = 0; |
| + for(auto slide : fSlides) { |
| + if (slide->getName().equals(stateValue)) { |
| + setupCurrentSlide(previousSlide); |
| + break; |
| + } |
| + fCurrentSlide++; |
| + } |
| + if (fCurrentSlide >= fSlides.count()) { |
| + fCurrentSlide = previousSlide; |
| + SkDebugf("Slide not found: %s", stateValue.c_str()); |
| + } |
| + } else { |
| + SkDebugf("Unknown stateName: %s", stateName.c_str()); |
| + } |
| +} |