From bce4021f4553ad2756510281323168fca8603a2a Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 31 Jan 2018 00:17:00 +0100 Subject: [PATCH] Refactoring FSwitch::drawCheckButton and FWidget::redraw --- ChangeLog | 3 + examples/string-operations.cpp | 42 ++++++++- include/final/fdialog.h | 2 + include/final/fswitch.h | 4 +- include/final/fwidget.h | 2 + src/fdialog.cpp | 77 +++++++++------- src/fswitch.cpp | 162 ++++++++++++++++++--------------- src/fwidget.cpp | 114 ++++++++++++----------- 8 files changed, 240 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d026976..94718174 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-01-31 Markus Gans + * Refactoring FSwitch::drawCheckButton and FWidget::redraw + 2017-01-30 Markus Gans * Refactoring FLabel::draw * Refactoring FFileDialog::readDir diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index 53cabc01..5c080c31 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2012-2017 Markus Gans * +* Copyright 2012-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -36,6 +36,10 @@ void inputStreamExample(); void outputStreamExample(); void streamingIntoFStringExample(); void streamingFromFStringExample(); +void streamToInterger(); +void streamToUnsignedInterger(); +void streamToDouble(); +void streamToFloat(); void CStringOutputExample(); void copyIntoFString(); void utf8StringOutputExample(); @@ -193,6 +197,23 @@ void streamingFromFStringExample() std::cout << "stream out: " << stream_char << std::endl; // ...to interger + streamToInterger(); + + // ...to unsigned interger + streamToUnsignedInterger(); + + // ...to double + streamToDouble(); + + // ...to float + streamToFloat(); +} + +//---------------------------------------------------------------------- +void streamToInterger() +{ + // Streaming from a FString to interger + try { int stream_int; @@ -212,7 +233,12 @@ void streamingFromFStringExample() std::cerr << "Arithmetic error: " << ex.what() << std::endl; } - // ...to unsigned interger +} + +//---------------------------------------------------------------------- +void streamToUnsignedInterger() +{ + // Streaming from a FString to unsigned interger try { uInt stream_uint; @@ -231,8 +257,12 @@ void streamingFromFStringExample() { std::cerr << "Arithmetic error: " << ex.what() << std::endl; } +} - // ...to double +//---------------------------------------------------------------------- +void streamToDouble() +{ + // Streaming from a FString to double try { double stream_double; @@ -247,8 +277,12 @@ void streamingFromFStringExample() { std::cerr << "Arithmetic error: " << ex.what() << std::endl; } +} - // ...to float +//---------------------------------------------------------------------- +void streamToFloat() +{ + // Streaming from a FString to float try { float stream_float; diff --git a/include/final/fdialog.h b/include/final/fdialog.h index e93e3add..03504408 100644 --- a/include/final/fdialog.h +++ b/include/final/fdialog.h @@ -184,6 +184,8 @@ class FDialog : public FWindow void drawBarButton(); void drawZoomButton(); void drawTextBar(); + void restoreOverlaidWindows(); + void setCursorToFocusWidget(); void leaveMenu(); void openMenu(); void selectFirstMenuItem(); diff --git a/include/final/fswitch.h b/include/final/fswitch.h index 81c844be..40de5186 100644 --- a/include/final/fswitch.h +++ b/include/final/fswitch.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -98,6 +98,8 @@ class FSwitch : public FToggleButton // Methods void draw(); void drawCheckButton(); + void drawChecked(); + void drawUnchecked(); // Data Members int switch_offset_pos; diff --git a/include/final/fwidget.h b/include/final/fwidget.h index be0d158f..fbf9eff7 100644 --- a/include/final/fwidget.h +++ b/include/final/fwidget.h @@ -390,6 +390,8 @@ class FWidget : public FVTerm, public FObject void KeyDownEvent (FKeyEvent*); void processDestroy(); virtual void draw(); + void drawWindows(); + void drawChildren(); void drawTransparentShadow (int, int, int, int); void drawBlockShadow (int, int, int, int); static void setColorTheme(); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index eff99eea..06a80887 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -278,40 +278,9 @@ void FDialog::setPos (int x, int y, bool) restoreVTerm (old_geometry); } - // handle overlaid windows - if ( window_list && ! window_list->empty() ) - { - bool overlaid = false; - widgetList::const_iterator iter, last; - iter = window_list->begin(); - last = window_list->end(); - - while ( iter != last ) - { - if ( overlaid ) - putArea ((*iter)->getTermPos(), (*iter)->getVWin()); - - if ( vwin == (*iter)->getVWin() ) - overlaid = true; - - ++iter; - } - } - + restoreOverlaidWindows(); FWindow::adjustSize(); - - // set the cursor to the focus widget - FWidget* focus_widget = FWidget::getFocusWidget(); - - if ( focus_widget - && focus_widget->isVisible() - && focus_widget->hasVisibleCursor() ) - { - FPoint cursor_pos = focus_widget->getCursorPos(); - focus_widget->setCursorPos(cursor_pos); - updateVTermCursor(vwin); - } - + setCursorToFocusWidget(); updateTerminal(); } @@ -1235,6 +1204,48 @@ void FDialog::drawTextBar() unsetBold(); } +//---------------------------------------------------------------------- +void FDialog::restoreOverlaidWindows() +{ + // Restoring overlaid windows + + if ( ! window_list || window_list->empty() ) + return; + + bool overlaid = false; + widgetList::const_iterator iter, last; + iter = window_list->begin(); + last = window_list->end(); + + while ( iter != last ) + { + if ( overlaid ) + putArea ((*iter)->getTermPos(), (*iter)->getVWin()); + + if ( vwin == (*iter)->getVWin() ) + overlaid = true; + + ++iter; + } +} + +//---------------------------------------------------------------------- +void FDialog::setCursorToFocusWidget() +{ + // Set the cursor to the focus widget + + FWidget* focus_widget = FWidget::getFocusWidget(); + + if ( focus_widget + && focus_widget->isVisible() + && focus_widget->hasVisibleCursor() ) + { + FPoint cursor_pos = focus_widget->getCursorPos(); + focus_widget->setCursorPos(cursor_pos); + updateVTermCursor(vwin); + } +} + //---------------------------------------------------------------------- void FDialog::leaveMenu() { diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 08ab878b..a611a25d 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -129,94 +129,106 @@ void FSwitch::drawCheckButton() if ( ! isVisible() ) return; - wchar_t on[6] = L" On "; - wchar_t off[6] = L" Off "; setPrintPos (1 + switch_offset_pos, 1); if ( checked ) + drawChecked(); + else + drawUnchecked(); +} + +//---------------------------------------------------------------------- +void FSwitch::drawChecked() +{ + wchar_t on[6] = L" On "; + wchar_t off[6] = L" Off "; + + if ( hasFocus() && ! button_pressed ) { - if ( hasFocus() && ! button_pressed ) + if ( isMonochron() ) { - if ( isMonochron() ) - { - std::wcsncpy ( on, L" ", 6); - setBold(true); - } - else if ( getMaxColor() < 16 ) - { - setBold(true); - setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); - } - else - setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); + std::wcsncpy ( on, L" ", 6); + setBold(true); + } + else if ( getMaxColor() < 16 ) + { + setBold(true); + setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); } else - { - if ( isMonochron() || getMaxColor() < 16 ) - setColor (wc.button_active_focus_fg, wc.button_active_bg); - else - setColor (wc.button_hotkey_fg, wc.button_active_bg); - } - - if ( isMonochron() ) - setReverse(false); - - print (on); - - if ( isMonochron() ) - setReverse(true); - - if ( isMonochron() || getMaxColor() < 16 ) - setBold(false); - - setColor (wc.button_inactive_fg, wc.button_inactive_bg); - print (off); - - if ( isMonochron() ) - setReverse(false); - - setCursorPos (3 + switch_offset_pos, 1); + setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); } else { - setColor (wc.button_inactive_fg, wc.button_inactive_bg); + if ( isMonochron() || getMaxColor() < 16 ) + setColor (wc.button_active_focus_fg, wc.button_active_bg); + else + setColor (wc.button_hotkey_fg, wc.button_active_bg); + } + if ( isMonochron() ) + setReverse(false); + + print (on); + + if ( isMonochron() ) + setReverse(true); + + if ( isMonochron() || getMaxColor() < 16 ) + setBold(false); + + setColor (wc.button_inactive_fg, wc.button_inactive_bg); + print (off); + + if ( isMonochron() ) + setReverse(false); + + setCursorPos (3 + switch_offset_pos, 1); +} + +//---------------------------------------------------------------------- +void FSwitch::drawUnchecked() +{ + wchar_t on[6] = L" On "; + wchar_t off[6] = L" Off "; + + setColor (wc.button_inactive_fg, wc.button_inactive_bg); + + if ( isMonochron() ) + setReverse(true); + + print (on); + + if ( hasFocus() && ! button_pressed ) + { if ( isMonochron() ) - setReverse(true); - - print (on); - - if ( hasFocus() && ! button_pressed ) { - if ( isMonochron() ) - { - std::wcsncpy ( off, L"", 6); - setBold(true); - } - else if ( getMaxColor() < 16 ) - { - setBold(true); - setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); - } - else - setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); + std::wcsncpy ( off, L"", 6); + setBold(true); + } + else if ( getMaxColor() < 16 ) + { + setBold(true); + setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); } else - { - if ( isMonochron() || getMaxColor() < 16 ) - setColor (wc.button_active_focus_fg, wc.button_active_bg); - else - setColor (wc.button_hotkey_fg, wc.button_active_bg); - } - - if ( isMonochron() ) - setReverse(false); - - print (off); - - if ( isMonochron() || getMaxColor() < 16 ) - setBold(false); - - setCursorPos (7 + switch_offset_pos, 1); + setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); } + else + { + if ( isMonochron() || getMaxColor() < 16 ) + setColor (wc.button_active_focus_fg, wc.button_active_bg); + else + setColor (wc.button_hotkey_fg, wc.button_active_bg); + } + + if ( isMonochron() ) + setReverse(false); + + print (off); + + if ( isMonochron() || getMaxColor() < 16 ) + setBold(false); + + setCursorPos (7 + switch_offset_pos, 1); } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 388335fa..0077ae58 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1114,60 +1114,9 @@ void FWidget::redraw() draw(); if ( isRootWidget() ) - { - // draw windows - FOptiAttr::char_data default_char; - default_char.code = ' '; - default_char.fg_color = fc::Black; - default_char.bg_color = fc::Black; - default_char.attr.byte[0] = 0; - default_char.attr.byte[1] = 0; - - if ( window_list && ! window_list->empty() ) - { - widgetList::const_iterator iter, last; - iter = window_list->begin(); - last = window_list->end(); - - while ( iter != last ) - { - if ( (*iter)->isVisible() ) - { - term_area* win = (*iter)->getVWin(); - int w = win->width + win->right_shadow; - int h = win->height + win->bottom_shadow; - std::fill_n (win->text, w * h, default_char); - - (*iter)->redraw(); - } - - ++iter; - } - } - } + drawWindows(); else - { - // draw child elements - if ( hasChildren() ) - { - constFObjectIterator iter, last; - iter = FObject::begin(); - last = FObject::end(); - - while ( iter != last ) - { - if ( (*iter)->isWidget() ) - { - FWidget* widget = static_cast(*iter); - - if ( widget->isVisible() && ! widget->isWindowWidget() ) - widget->redraw(); - } - - ++iter; - } - } - } + drawChildren(); if ( isRootWidget() ) finishTerminalUpdate(); @@ -2405,6 +2354,65 @@ void FWidget::KeyDownEvent (FKeyEvent* kev) void FWidget::draw() { } +//---------------------------------------------------------------------- +void FWidget::drawWindows() +{ + // redraw windows + FOptiAttr::char_data default_char; + default_char.code = ' '; + default_char.fg_color = fc::Black; + default_char.bg_color = fc::Black; + default_char.attr.byte[0] = 0; + default_char.attr.byte[1] = 0; + + if ( ! window_list || window_list->empty() ) + return; + + widgetList::const_iterator iter, last; + iter = window_list->begin(); + last = window_list->end(); + + while ( iter != last ) + { + if ( (*iter)->isVisible() ) + { + term_area* win = (*iter)->getVWin(); + int w = win->width + win->right_shadow; + int h = win->height + win->bottom_shadow; + std::fill_n (win->text, w * h, default_char); + + (*iter)->redraw(); + } + + ++iter; + } +} + +//---------------------------------------------------------------------- +void FWidget::drawChildren() +{ + // draw child elements + if ( ! hasChildren() ) + return; + + constFObjectIterator iter, last; + iter = FObject::begin(); + last = FObject::end(); + + while ( iter != last ) + { + if ( (*iter)->isWidget() ) + { + FWidget* widget = static_cast(*iter); + + if ( widget->isVisible() && ! widget->isWindowWidget() ) + widget->redraw(); + } + + ++iter; + } +} + //---------------------------------------------------------------------- void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2) {