Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1370)

Side by Side Diff: tools/viewer/Viewer.cpp

Issue 2035923002: Add Softkey UIState to Viewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/viewer/sk_app/CommandSet.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Viewer.h" 8 #include "Viewer.h"
9 9
10 #include "GMSlide.h" 10 #include "GMSlide.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { 58 const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
59 " [OpenGL]", 59 " [OpenGL]",
60 " [Vulkan]" 60 " [Vulkan]"
61 }; 61 };
62 62
63 const char* kName = "name"; 63 const char* kName = "name";
64 const char* kValue = "value"; 64 const char* kValue = "value";
65 const char* kOptions = "options"; 65 const char* kOptions = "options";
66 const char* kSlideStateName = "Slide"; 66 const char* kSlideStateName = "Slide";
67 const char* kBackendStateName = "Backend"; 67 const char* kBackendStateName = "Backend";
68 const char* kSoftkeyStateName = "Softkey";
69 const char* kSoftkeyHint = "Please select a softkey";
70
68 71
69 Viewer::Viewer(int argc, char** argv, void* platformData) 72 Viewer::Viewer(int argc, char** argv, void* platformData)
70 : fCurrentMeasurement(0) 73 : fCurrentMeasurement(0)
71 , fDisplayStats(false) 74 , fDisplayStats(false)
72 , fBackendType(sk_app::Window::kVulkan_BackendType) 75 , fBackendType(sk_app::Window::kVulkan_BackendType)
73 , fZoomCenterX(0.0f) 76 , fZoomCenterX(0.0f)
74 , fZoomCenterY(0.0f) 77 , fZoomCenterY(0.0f)
75 , fZoomLevel(0.0f) 78 , fZoomLevel(0.0f)
76 , fZoomScale(SK_Scalar1) 79 , fZoomScale(SK_Scalar1)
77 { 80 {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 407 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
405 SkASSERT(fCurrentMeasurement < kMeasurementCount); 408 SkASSERT(fCurrentMeasurement < kMeasurementCount);
406 409
407 fAnimTimer.updateTime(); 410 fAnimTimer.updateTime();
408 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 411 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
409 fWindow->inval(); 412 fWindow->inval();
410 } 413 }
411 } 414 }
412 415
413 void Viewer::updateUIState() { 416 void Viewer::updateUIState() {
417 // Slide state
414 Json::Value slideState(Json::objectValue); 418 Json::Value slideState(Json::objectValue);
415 slideState[kName] = kSlideStateName; 419 slideState[kName] = kSlideStateName;
416 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); 420 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
417 Json::Value allSlideNames(Json::arrayValue); 421 Json::Value allSlideNames(Json::arrayValue);
418 for(auto slide : fSlides) { 422 for(auto slide : fSlides) {
419 allSlideNames.append(Json::Value(slide->getName().c_str())); 423 allSlideNames.append(Json::Value(slide->getName().c_str()));
420 } 424 }
421 slideState[kOptions] = allSlideNames; 425 slideState[kOptions] = allSlideNames;
422 426
423 // This state is currently a demo for the one without options. 427 // Backend state
424 // We will be able to change the backend too.
425 Json::Value backendState(Json::objectValue); 428 Json::Value backendState(Json::objectValue);
426 backendState[kName] = kBackendStateName; 429 backendState[kName] = kBackendStateName;
427 backendState[kValue] = kBackendTypeStrings[fBackendType]; 430 backendState[kValue] = kBackendTypeStrings[fBackendType];
428 backendState[kOptions] = Json::Value(Json::arrayValue); 431 backendState[kOptions] = Json::Value(Json::arrayValue);
429 for(auto str : kBackendTypeStrings) { 432 for (auto str : kBackendTypeStrings) {
430 backendState[kOptions].append(Json::Value(str)); 433 backendState[kOptions].append(Json::Value(str));
431 } 434 }
432 435
436 // Softkey state
437 Json::Value softkeyState(Json::objectValue);
438 softkeyState[kName] = kSoftkeyStateName;
439 softkeyState[kValue] = kSoftkeyHint;
440 softkeyState[kOptions] = Json::Value(Json::arrayValue);
441 softkeyState[kOptions].append(kSoftkeyHint);
442 for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) {
443 softkeyState[kOptions].append(Json::Value(softkey.c_str()));
444 }
445
433 Json::Value state(Json::arrayValue); 446 Json::Value state(Json::arrayValue);
434 state.append(slideState); 447 state.append(slideState);
435 state.append(backendState); 448 state.append(backendState);
449 state.append(softkeyState);
436 450
437 fWindow->setUIState(state); 451 fWindow->setUIState(state);
438 } 452 }
439 453
440 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa lue) { 454 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa lue) {
441 // For those who will add more features to handle the state change in this f unction: 455 // For those who will add more features to handle the state change in this f unction:
442 // After the change, please call updateUIState no notify the frontend (e.g., Android app). 456 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
443 // For example, after slide change, updateUIState is called inside setupCurr entSlide; 457 // For example, after slide change, updateUIState is called inside setupCurr entSlide;
444 // after backend change, updateUIState is called in this function. 458 // after backend change, updateUIState is called in this function.
445 if (stateName.equals(kSlideStateName)) { 459 if (stateName.equals(kSlideStateName)) {
(...skipping 17 matching lines...) Expand all
463 fBackendType = (sk_app::Window::BackendType)i; 477 fBackendType = (sk_app::Window::BackendType)i;
464 fWindow->detach(); 478 fWindow->detach();
465 fWindow->attach(fBackendType, DisplayParams()); 479 fWindow->attach(fBackendType, DisplayParams());
466 fWindow->inval(); 480 fWindow->inval();
467 updateTitle(); 481 updateTitle();
468 updateUIState(); 482 updateUIState();
469 } 483 }
470 break; 484 break;
471 } 485 }
472 } 486 }
487 } else if (stateName.equals(kSoftkeyStateName)) {
488 if (!stateValue.equals(kSoftkeyHint)) {
489 fCommands.onSoftkey(stateValue);
490 updateUIState(); // This is still needed to reset the value to kSoft keyHint
491 }
473 } else { 492 } else {
474 SkDebugf("Unknown stateName: %s", stateName.c_str()); 493 SkDebugf("Unknown stateName: %s", stateName.c_str());
475 } 494 }
476 } 495 }
OLDNEW
« no previous file with comments | « no previous file | tools/viewer/sk_app/CommandSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698