Chromium Code Reviews| Index: tools/viewer/sk_app/CommandSet.h |
| diff --git a/tools/viewer/sk_app/CommandSet.h b/tools/viewer/sk_app/CommandSet.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39481079376a0a65531e1b3ecc8f91a8935745d8 |
| --- /dev/null |
| +++ b/tools/viewer/sk_app/CommandSet.h |
| @@ -0,0 +1,91 @@ |
| +/* |
| +* 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 CommandSet_DEFINED |
| +#define CommandSet_DEFINED |
| + |
| +#include "SkString.h" |
| +#include "Window.h" |
| + |
| +#include <functional> |
| + |
| +class SkCanvas; |
| + |
| +namespace sk_app { |
| + |
| +class CommandSet { |
|
bsalomon
2016/05/09 20:25:53
Maybe a little bit of comment text to explain what
|
| +public: |
| + CommandSet(); |
| + |
| + void attach(Window* window); |
| + bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers); |
| + bool onChar(SkUnichar, uint32_t modifiers); |
| + |
| + void addCommand(SkUnichar c, const char* group, const char* description, |
| + std::function<void(void)> function); |
| + void addCommand(Window::Key k, const char* keyName, const char* group, const char* description, |
| + std::function<void(void)> function); |
| + |
| + void drawHelp(SkCanvas* canvas); |
| + |
| +private: |
| + struct Command { |
| + enum CommandType { |
| + kChar_CommandType, |
| + kKey_CommandType, |
| + }; |
| + |
| + Command(SkUnichar c, const char* group, const char* description, |
| + std::function<void(void)> function) |
| + : fType(kChar_CommandType) |
| + , fChar(c) |
| + , fKeyName(SkStringPrintf("%c", c)) |
| + , fGroup(group) |
| + , fDescription(description) |
| + , fFunction(function) {} |
| + |
| + Command(Window::Key k, const char* keyName, const char* group, const char* description, |
| + std::function<void(void)> function) |
| + : fType(kKey_CommandType) |
| + , fKey(k) |
| + , fKeyName(keyName) |
| + , fGroup(group) |
| + , fDescription(description) |
| + , fFunction(function) {} |
| + |
| + CommandType fType; |
| + |
| + // For kChar_CommandType |
| + SkUnichar fChar; |
| + |
| + // For kKey_CommandType |
| + Window::Key fKey; |
| + |
| + // Common to all command types |
| + SkString fKeyName; |
| + SkString fGroup; |
| + SkString fDescription; |
| + std::function<void(void)> fFunction; |
| + }; |
| + |
| + static bool compareCommandKey(const Command& first, const Command& second); |
| + static bool compareCommandGroup(const Command& first, const Command& second); |
| + |
| + enum HelpMode { |
| + kNone_HelpMode, |
| + kGrouped_HelpMode, |
| + kAlphabetical_HelpMode, |
| + }; |
| + |
| + Window* fWindow; |
| + SkTArray<Command> fCommands; |
| + HelpMode fHelpMode; |
| +}; |
| + |
| +} // namespace sk_app |
| + |
| +#endif |