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

Side by Side Diff: tools/viewer/sk_app/CommandSet.h

Issue 1955293002: Add flexible keybinding/command system to sk_app (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Extract keybinding system as CommandSet. Add grouping and two help modes. Created 4 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef CommandSet_DEFINED
9 #define CommandSet_DEFINED
10
11 #include "SkString.h"
12 #include "Window.h"
13
14 #include <functional>
15
16 class SkCanvas;
17
18 namespace sk_app {
19
20 class CommandSet {
bsalomon 2016/05/09 20:25:53 Maybe a little bit of comment text to explain what
21 public:
22 CommandSet();
23
24 void attach(Window* window);
25 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32 _t modifiers);
26 bool onChar(SkUnichar, uint32_t modifiers);
27
28 void addCommand(SkUnichar c, const char* group, const char* description,
29 std::function<void(void)> function);
30 void addCommand(Window::Key k, const char* keyName, const char* group, const char* description,
31 std::function<void(void)> function);
32
33 void drawHelp(SkCanvas* canvas);
34
35 private:
36 struct Command {
37 enum CommandType {
38 kChar_CommandType,
39 kKey_CommandType,
40 };
41
42 Command(SkUnichar c, const char* group, const char* description,
43 std::function<void(void)> function)
44 : fType(kChar_CommandType)
45 , fChar(c)
46 , fKeyName(SkStringPrintf("%c", c))
47 , fGroup(group)
48 , fDescription(description)
49 , fFunction(function) {}
50
51 Command(Window::Key k, const char* keyName, const char* group, const cha r* description,
52 std::function<void(void)> function)
53 : fType(kKey_CommandType)
54 , fKey(k)
55 , fKeyName(keyName)
56 , fGroup(group)
57 , fDescription(description)
58 , fFunction(function) {}
59
60 CommandType fType;
61
62 // For kChar_CommandType
63 SkUnichar fChar;
64
65 // For kKey_CommandType
66 Window::Key fKey;
67
68 // Common to all command types
69 SkString fKeyName;
70 SkString fGroup;
71 SkString fDescription;
72 std::function<void(void)> fFunction;
73 };
74
75 static bool compareCommandKey(const Command& first, const Command& second);
76 static bool compareCommandGroup(const Command& first, const Command& second) ;
77
78 enum HelpMode {
79 kNone_HelpMode,
80 kGrouped_HelpMode,
81 kAlphabetical_HelpMode,
82 };
83
84 Window* fWindow;
85 SkTArray<Command> fCommands;
86 HelpMode fHelpMode;
87 };
88
89 } // namespace sk_app
90
91 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698