From 579f18054987052024f8f3734ab11d6e4d261c89 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 21 Jan 2011 14:11:06 +0000 Subject: [PATCH] blink console panel icon to indicate new errors/warnings/infos git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1630 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/set/console_panel.cpp | 54 +++++++++++++++++++++++++++++++++-- src/gui/set/console_panel.hpp | 13 +++++++++ src/gui/set/window.cpp | 10 +++++++ src/gui/set/window.hpp | 3 ++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/gui/set/console_panel.cpp b/src/gui/set/console_panel.cpp index 9f088162..e9cafd24 100644 --- a/src/gui/set/console_panel.cpp +++ b/src/gui/set/console_panel.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -268,6 +269,9 @@ END_EVENT_TABLE() ConsolePanel::ConsolePanel(Window* parent, int id) : SetWindowPanel(parent, id) + , is_active_window(false) + , blinker_state(0) + , blinker_timer(this) { // init controls splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); @@ -301,11 +305,18 @@ void ConsolePanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // Menus // focus on entry entry->SetFocus(); + + // stop blinker + is_active_window = true; + stop_blinker(); } void ConsolePanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { // Toolbar // Menus + + // we are no longer active, allow blinker + is_active_window = false; } void ConsolePanel::onUpdateUI(wxUpdateUIEvent& ev) { @@ -334,9 +345,12 @@ void ConsolePanel::get_pending_errors() { String msg; while (get_queued_message(type,msg)) { messages->add_message(type,msg); + // If this panel doesn't have the focus, then highlight it somehow + if (!is_active_window) { + new_errors_since_last_view = max(new_errors_since_last_view,type); + start_blinker(); + } } - // If this panel doesn't have the focus, then highlight it somehow - } void ConsolePanel::exec(String const& command) { @@ -388,6 +402,7 @@ void ConsolePanel::exec(String const& command) { BEGIN_EVENT_TABLE(ConsolePanel, wxPanel) EVT_TEXT_ENTER(wxID_ANY,ConsolePanel::onEnter) EVT_IDLE(ConsolePanel::onIdle) + EVT_TIMER(wxID_ANY,ConsolePanel::onTimer) END_EVENT_TABLE () // ----------------------------------------------------------------------------- : Clipboard @@ -399,3 +414,38 @@ void ConsolePanel::doCut() { entry->doCut(); } void ConsolePanel::doCopy() { entry->doCopy(); } void ConsolePanel::doPaste() { entry->doPaste(); } */ + +// ----------------------------------------------------------------------------- : Annoying blinking icon thing + +void ConsolePanel::start_blinker() { + if (new_errors_since_last_view) { + blinker_state = 0; + blinker_timer.Start(BLINK_TIME); + update_blinker(); + } +} +void ConsolePanel::stop_blinker() { + blinker_state = 0; + new_errors_since_last_view = static_cast(0); + blinker_timer.Stop(); + update_blinker(); +} +void ConsolePanel::onTimer(wxTimerEvent&) { + blinker_state++; + if (blinker_state > MAX_BLINKS) { + blinker_timer.Stop(); + } + update_blinker(); +} +void ConsolePanel::update_blinker() { + SetWindow* parent = static_cast(GetParent()); + if (blinker_state % 2 == 1 || !new_errors_since_last_view) { + parent->setPanelIcon(this, load_resource_image(_("tool/window_console"))); + } else if (new_errors_since_last_view == MESSAGE_INFO) { + parent->setPanelIcon(this, load_resource_image(_("message_information"))); + } else if (new_errors_since_last_view == MESSAGE_WARNING) { + parent->setPanelIcon(this, load_resource_image(_("message_warning"))); + } else { + parent->setPanelIcon(this, load_resource_image(_("message_error"))); + } +} diff --git a/src/gui/set/console_panel.hpp b/src/gui/set/console_panel.hpp index 807186ea..51580b51 100644 --- a/src/gui/set/console_panel.hpp +++ b/src/gui/set/console_panel.hpp @@ -55,6 +55,19 @@ class ConsolePanel : public SetWindowPanel { void get_pending_errors(); void exec(String const& code); + + // notification of new messages + bool is_active_window; + MessageType new_errors_since_last_view; + int blinker_state; + wxTimer blinker_timer; + static const int MAX_BLINKS = 5; + static const int BLINK_TIME = 1000; + + void stop_blinker(); + void start_blinker(); + void update_blinker(); + void onTimer(wxTimerEvent&); }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 1412294d..8de58616 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -250,6 +250,16 @@ void SetWindow::selectPanel(int id) { current_panel->SetFocus(); } +void SetWindow::setPanelIcon(SetWindowPanel* panel, wxBitmap const& icon) { + for (size_t i = 0 ; i < panels.size() ; ++i) { + if (panels[i] == panel) { + wxToolBar* tabBar = (wxToolBar*)FindWindow(ID_TAB_BAR); + tabBar->SetToolNormalBitmap(ID_WINDOW_MIN+i, icon); + return; + } + } +} + // ----------------------------------------------------------------------------- : Window managment vector SetWindow::set_windows; diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index e2d50dab..6b3eb23a 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -30,6 +30,9 @@ class SetWindow : public wxFrame, public SetView { SetWindow(Window* parent, const SetP& set); ~SetWindow(); + /// Set the icon of one of the panels + void setPanelIcon(SetWindowPanel* panel, wxBitmap const& icon); + // --------------------------------------------------- : Set actions private: