| OLD | NEW |
| 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 "CommandSet.h" | 8 #include "CommandSet.h" |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 for (Command& cmd : fCommands) { | 64 for (Command& cmd : fCommands) { |
| 65 if (Command::kChar_CommandType == cmd.fType && c == cmd.fChar) { | 65 if (Command::kChar_CommandType == cmd.fType && c == cmd.fChar) { |
| 66 cmd.fFunction(); | 66 cmd.fFunction(); |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool CommandSet::onSoftkey(const SkString& softkey) { |
| 75 for (const Command& cmd : fCommands) { |
| 76 if (cmd.getSoftkeyString().equals(softkey)) { |
| 77 cmd.fFunction(); |
| 78 return true; |
| 79 } |
| 80 } |
| 81 return false; |
| 82 } |
| 83 |
| 74 void CommandSet::addCommand(SkUnichar c, const char* group, const char* descript
ion, | 84 void CommandSet::addCommand(SkUnichar c, const char* group, const char* descript
ion, |
| 75 std::function<void(void)> function) { | 85 std::function<void(void)> function) { |
| 76 fCommands.push_back(Command(c, group, description, function)); | 86 fCommands.push_back(Command(c, group, description, function)); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void CommandSet::addCommand(Window::Key k, const char* keyName, const char* grou
p, | 89 void CommandSet::addCommand(Window::Key k, const char* keyName, const char* grou
p, |
| 80 const char* description, std::function<void(void)> f
unction) { | 90 const char* description, std::function<void(void)> f
unction) { |
| 81 fCommands.push_back(Command(k, keyName, group, description, function)); | 91 fCommands.push_back(Command(k, keyName, group, description, function)); |
| 82 } | 92 } |
| 83 | 93 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 lastGroup = cmd.fGroup; | 157 lastGroup = cmd.fGroup; |
| 148 } | 158 } |
| 149 | 159 |
| 150 canvas->drawText(cmd.fKeyName.c_str(), cmd.fKeyName.size(), x, y, paint)
; | 160 canvas->drawText(cmd.fKeyName.c_str(), cmd.fKeyName.size(), x, y, paint)
; |
| 151 SkString text = SkStringPrintf(": %s", cmd.fDescription.c_str()); | 161 SkString text = SkStringPrintf(": %s", cmd.fDescription.c_str()); |
| 152 canvas->drawText(text.c_str(), text.size(), x + keyWidth, y, paint); | 162 canvas->drawText(text.c_str(), text.size(), x + keyWidth, y, paint); |
| 153 y += paint.getTextSize() + 2; | 163 y += paint.getTextSize() + 2; |
| 154 } | 164 } |
| 155 } | 165 } |
| 156 | 166 |
| 167 std::vector<SkString> CommandSet::getCommandsAsSoftkeys() const { |
| 168 std::vector<SkString> result; |
| 169 for(const Command& command : fCommands) { |
| 170 result.push_back(command.getSoftkeyString()); |
| 171 } |
| 172 return result; |
| 173 } |
| 174 |
| 157 } // namespace sk_app | 175 } // namespace sk_app |
| OLD | NEW |