From d79d29c1a59b5f2d6103045bf1f9fa006dee4a92 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 24 Apr 2010 01:55:51 -0300 Subject: [PATCH] Now when you pass the mouse over a tool button, the tool name and shortcut are shown in the status bar. Added StatusBar::showTool(). --- src/widgets/statebar.cpp | 44 +++++++++++++++++++++++++++++++++++++--- src/widgets/statebar.h | 7 ++++++- src/widgets/toolbar.cpp | 11 ++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/widgets/statebar.cpp b/src/widgets/statebar.cpp index dc3f40763..c9286593d 100644 --- a/src/widgets/statebar.cpp +++ b/src/widgets/statebar.cpp @@ -146,9 +146,10 @@ void StatusBar::onCurrentToolChange() { if (jwidget_is_visible(this)) { Tool* currentTool = UIContext::instance()->getSettings()->getCurrentTool(); - if (currentTool) - this->setStatusText(500, "%s selected", - currentTool->getText().c_str()); + if (currentTool) { + this->showTool(500, currentTool); + this->setTextf("%s Selected", currentTool->getText().c_str()); + } } } @@ -223,6 +224,30 @@ void StatusBar::showColor(int msecs, const char* text, color_t color, int alpha) } } +void StatusBar::showTool(int msecs, Tool* tool) +{ + assert(tool != NULL); + + // Tool name + std::string text = tool->getText(); + + // Tool shortcut + JAccel accel = get_accel_to_change_tool(tool); + if (accel) { + char buf[512]; // TODO possible buffer overflow + jaccel_to_string(accel, buf); + text += ", Shortcut: "; + text += buf; + } + + // Set text + if (setStatusText(msecs, text.c_str())) { + // Show tool + m_state = SHOW_TOOL; + m_tool = tool; + } +} + ////////////////////////////////////////////////////////////////////// // Progress bars stuff @@ -355,6 +380,19 @@ bool StatusBar::msg_proc(JMessage msg) x += ji_font_text_len(this->getFont(), buf) + 4*jguiscale(); } + // Show tool + if (m_state == SHOW_TOOL) { + // Draw eyedropper icon + BITMAP* icon = theme->get_toolicon(m_tool->getId().c_str()); + if (icon) { + set_alpha_blender(); + draw_trans_sprite(doublebuffer, icon, + x, (rc->y1+rc->y2)/2-icon->h/2); + } + + x += icon->w + 4*jguiscale(); + } + // Status bar text if (this->getTextSize() > 0) { textout_ex(doublebuffer, this->getFont(), this->getText(), diff --git a/src/widgets/statebar.h b/src/widgets/statebar.h index fcee90f98..d61a218c7 100644 --- a/src/widgets/statebar.h +++ b/src/widgets/statebar.h @@ -26,6 +26,7 @@ class Frame; class StatusBar; +class Tool; class Progress { @@ -52,6 +53,7 @@ public: bool setStatusText(int msecs, const char *format, ...); void showTip(int msecs, const char *format, ...); void showColor(int msecs, const char* text, color_t color, int alpha); + void showTool(int msecs, Tool* tool); Progress* addProgress(); void removeProgress(Progress* progress); @@ -63,11 +65,14 @@ private: void onCurrentToolChange(); void updateFromLayer(); - enum State { SHOW_TEXT, SHOW_COLOR }; + enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL }; int m_timeout; State m_state; + // Showing a tool + Tool* m_tool; + // Showing a color color_t m_color; int m_alpha; diff --git a/src/widgets/toolbar.cpp b/src/widgets/toolbar.cpp index 2f18e3741..6dadadb74 100644 --- a/src/widgets/toolbar.cpp +++ b/src/widgets/toolbar.cpp @@ -28,14 +28,15 @@ #include "Vaca/Size.h" #include "app.h" -#include "ui_context.h" -#include "commands/commands.h" #include "commands/command.h" +#include "commands/commands.h" #include "modules/gfx.h" #include "modules/gui.h" #include "modules/skinneable_theme.h" #include "tools/toolbox.h" +#include "ui_context.h" #include "widgets/groupbut.h" +#include "widgets/statebar.h" #include "widgets/toolbar.h" using Vaca::Size; @@ -326,6 +327,9 @@ bool ToolBar::msg_proc(JMessage msg) openTipWindow(tip_index, m_hot_tool); else closeTipWindow(); + + if (m_hot_tool) + app_get_statusbar()->showTool(0, m_hot_tool); } break; } @@ -667,6 +671,9 @@ bool ToolStrip::msg_proc(JMessage msg) m_toolbar->openTipWindow(m_group, m_hot_tool); else m_toolbar->closeTipWindow(); + + if (m_hot_tool) + app_get_statusbar()->showTool(0, m_hot_tool); } break; }