void NewBrushCommand::createBrush(const Mask* mask) { doc::ImageRef image(new_image_from_mask( UIContext::instance()->activeSite(), mask)); if (!image) return; // New brush doc::BrushRef brush(new doc::Brush()); brush->setImage(image.get()); brush->setPatternOrigin(mask->bounds().getOrigin()); // TODO add a active stock property in app::Context ContextBar* ctxBar = App::instance()->getMainWindow()->getContextBar(); int slot = ctxBar->addBrush(brush); ctxBar->setActiveBrush(brush); // Get the shortcut for this brush and show it to the user Params params; params.set("change", "custom"); params.set("slot", base::convert_to<std::string>(slot).c_str()); Key* key = KeyboardShortcuts::instance()->command( CommandId::ChangeBrush, params); if (key && !key->accels().empty()) { std::string tooltip; tooltip += "Shortcut: "; tooltip += key->accels().front().toString(); StatusBar::instance()->showTip(2000, tooltip.c_str()); } }
void BrushPopup::regenerate(const gfx::Rect& box, const Brushes& brushes) { int columns = 3; if (m_buttons) { for (auto child : m_buttons->getChildren()) m_tooltipManager->removeTooltipFor(child); removeChild(m_buttons.get()); m_buttons.reset(); } if (!defBrushes[0]) { defBrushes[0].reset(new Brush(kCircleBrushType, 7, 0)); defBrushes[1].reset(new Brush(kSquareBrushType, 7, 0)); defBrushes[2].reset(new Brush(kLineBrushType, 7, 44)); } m_buttons.reset(new ButtonSet(columns)); m_buttons->addItem(new Item(this, m_delegate, defBrushes[0])); m_buttons->addItem(new Item(this, m_delegate, defBrushes[1])); m_buttons->addItem(new Item(this, m_delegate, defBrushes[2])); int slot = 1; for (const auto& brush : brushes) { Item* item = new Item(this, m_delegate, brush, slot); m_buttons->addItem(item); Params params; params.set("change", "custom"); params.set("slot", base::convert_to<std::string>(slot).c_str()); Key* key = KeyboardShortcuts::instance()->command( CommandId::ChangeBrush, params); if (key && !key->accels().empty()) { std::string tooltip; tooltip += "Shortcut: "; tooltip += key->accels().front().toString(); m_tooltipManager->addTooltipFor(item, tooltip, TOP); } slot++; } // Add empty spaces while (((slot-1) % columns) > 0) m_buttons->addItem(new Item(this, m_delegate, BrushRef(nullptr), slot++)); m_buttons->ItemChange.connect(&BrushPopup::onButtonChange, this); m_buttons->setTransparent(true); m_buttons->setBgColor(gfx::ColorNone); addChild(m_buttons.get()); gfx::Rect rc = box; int buttons = m_buttons->getChildren().size(); int rows = (buttons/columns + ((buttons%columns) > 0 ? 1: 0)); rc.w *= columns; rc.h = rows * (rc.h-2*guiscale()) + 2*guiscale(); setBounds(rc); }
std::string AniControls::getTooltipFor(int index) const { std::string tooltip; Command* cmd = Commands::instance()->byId(getCommandId(index)); if (cmd) { tooltip = cmd->friendlyName(); Key* key = KeyboardShortcuts::instance()->command(cmd->id().c_str()); if (key && !key->accels().empty()) { tooltip += "\n\nShortcut: "; tooltip += key->accels().front().toString(); } } return tooltip; }
void BrushPopup::regenerate(const gfx::Rect& box) { auto& brushSlots = App::instance()->brushes().getBrushSlots(); if (m_customBrushes) { // As BrushPopup::regenerate() can be called when a // "m_customBrushes" button is clicked we cannot delete // "m_customBrushes" right now. m_customBrushes->parent()->removeChild(m_customBrushes); m_customBrushes->deferDelete(); } m_customBrushes = new ButtonSet(3); m_customBrushes->setTriggerOnMouseUp(true); int slot = 0; for (const auto& brush : brushSlots) { ++slot; // Get shortcut std::string shortcut; { Params params; params.set("change", "custom"); params.set("slot", base::convert_to<std::string>(slot).c_str()); Key* key = KeyboardShortcuts::instance()->command( CommandId::ChangeBrush, params); if (key && !key->accels().empty()) shortcut = key->accels().front().toString(); } m_customBrushes->addItem(new SelectBrushItem(brush, slot)); m_customBrushes->addItem(new BrushShortcutItem(shortcut, slot)); m_customBrushes->addItem(new BrushOptionsItem(this, slot)); } m_customBrushes->addItem(new NewCustomBrushItem, 2, 1); m_customBrushes->addItem(new NewBrushOptionsItem); m_customBrushes->setExpansive(true); m_box.addChild(m_customBrushes); // Resize the window and change the hot region. setBounds(gfx::Rect(box.origin(), sizeHint())); setHotRegion(gfx::Region(bounds())); }
void StatusBar::showTool(int msecs, tools::Tool* tool) { ASSERT(tool != NULL); // Tool name std::string text = tool->getText(); // Tool shortcut Key* key = KeyboardShortcuts::instance()->tool(tool); if (key && !key->accels().empty()) { text += ", Shortcut: "; text += key->accels().front().toString(); } // Set text if (setStatusText(msecs, text.c_str())) { // Show tool m_state = SHOW_TOOL; m_tool = tool; } }
void AdvancedModeCommand::onExecute(Context* context) { // Switch advanced mode. MainWindow* mainWindow = App::instance()->mainWindow(); MainWindow::Mode oldMode = mainWindow->getMode(); MainWindow::Mode newMode = oldMode; switch (oldMode) { case MainWindow::NormalMode: newMode = MainWindow::ContextBarAndTimelineMode; break; case MainWindow::ContextBarAndTimelineMode: newMode = MainWindow::EditorOnlyMode; break; case MainWindow::EditorOnlyMode: newMode = MainWindow::NormalMode; break; } mainWindow->setMode(newMode); auto& pref = Preferences::instance(); if (oldMode == MainWindow::NormalMode && pref.advancedMode.showAlert()) { Key* key = KeyboardShortcuts::instance()->command(this->id().c_str()); if (!key->accels().empty()) { app::gen::AdvancedMode window; window.warningLabel()->setTextf("You can go back pressing \"%s\" key.", key->accels().front().toString().c_str()); window.openWindowInForeground(); pref.advancedMode.showAlert(!window.donotShow()->isSelected()); } } }
void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source) { // <keyboard><commands><key> TiXmlHandle handle(rootElement); TiXmlElement* xmlKey = handle .FirstChild("commands") .FirstChild("key").ToElement(); while (xmlKey) { const char* command_name = xmlKey->Attribute("command"); const char* command_key = get_shortcut(xmlKey); bool removed = bool_attr_is_true(xmlKey, "removed"); if (command_name) { Command* command = CommandsModule::instance()->getCommandByName(command_name); if (command) { // Read context KeyContext keycontext = KeyContext::Any; const char* keycontextstr = xmlKey->Attribute("context"); if (keycontextstr) { if (strcmp(keycontextstr, "Selection") == 0) keycontext = KeyContext::SelectionTool; else if (strcmp(keycontextstr, "Normal") == 0) keycontext = KeyContext::Normal; } // Read params Params params; TiXmlElement* xmlParam = xmlKey->FirstChildElement("param"); while (xmlParam) { const char* param_name = xmlParam->Attribute("name"); const char* param_value = xmlParam->Attribute("value"); if (param_name && param_value) params.set(param_name, param_value); xmlParam = xmlParam->NextSiblingElement(); } // add the keyboard shortcut to the command Key* key = this->command(command_name, params, keycontext); if (key && command_key) { Accelerator accel(command_key); if (!removed) { key->add(accel, source); // Add the shortcut to the menuitems with this command // (this is only visual, the // "CustomizedGuiManager::onProcessMessage" is the only // one that process keyboard shortcuts) if (key->accels().size() == 1) { AppMenus::instance()->applyShortcutToMenuitemsWithCommand( command, params, key); } } else key->disableAccel(accel); } } } xmlKey = xmlKey->NextSiblingElement(); } // Load keyboard shortcuts for tools // <gui><keyboard><tools><key> xmlKey = handle .FirstChild("tools") .FirstChild("key").ToElement(); while (xmlKey) { const char* tool_id = xmlKey->Attribute("tool"); const char* tool_key = get_shortcut(xmlKey); bool removed = bool_attr_is_true(xmlKey, "removed"); if (tool_id) { tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id); if (tool) { Key* key = this->tool(tool); if (key && tool_key) { LOG(" - Shortcut for tool `%s': <%s>\n", tool_id, tool_key); Accelerator accel(tool_key); if (!removed) key->add(accel, source); else key->disableAccel(accel); } } } xmlKey = xmlKey->NextSiblingElement(); } // Load keyboard shortcuts for quicktools // <gui><keyboard><quicktools><key> xmlKey = handle .FirstChild("quicktools") .FirstChild("key").ToElement(); while (xmlKey) { const char* tool_id = xmlKey->Attribute("tool"); const char* tool_key = get_shortcut(xmlKey); bool removed = bool_attr_is_true(xmlKey, "removed"); if (tool_id) { tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id); if (tool) { Key* key = this->quicktool(tool); if (key && tool_key) { LOG(" - Shortcut for quicktool `%s': <%s>\n", tool_id, tool_key); Accelerator accel(tool_key); if (!removed) key->add(accel, source); else key->disableAccel(accel); } } } xmlKey = xmlKey->NextSiblingElement(); } // Load special keyboard shortcuts for sprite editor customization // <gui><keyboard><spriteeditor> xmlKey = handle .FirstChild("actions") .FirstChild("key").ToElement(); while (xmlKey) { const char* tool_action = xmlKey->Attribute("action"); const char* tool_key = get_shortcut(xmlKey); bool removed = bool_attr_is_true(xmlKey, "removed"); if (tool_action) { KeyAction action = base::convert_to<KeyAction, std::string>(tool_action); if (action != KeyAction::None) { Key* key = this->action(action); if (key && tool_key) { LOG(" - Shortcut for action '%s': <%s>\n", tool_action, tool_key); Accelerator accel(tool_key); if (!removed) key->add(accel, source); else key->disableAccel(accel); } } } xmlKey = xmlKey->NextSiblingElement(); } }