Refactoring FSwitch::drawCheckButton and FWidget::redraw

This commit is contained in:
Markus Gans 2018-01-31 00:17:00 +01:00
parent 10275c0953
commit bce4021f45
8 changed files with 240 additions and 166 deletions

View File

@ -1,3 +1,6 @@
2017-01-31 Markus Gans <guru.mail@muenster.de>
* Refactoring FSwitch::drawCheckButton and FWidget::redraw
2017-01-30 Markus Gans <guru.mail@muenster.de> 2017-01-30 Markus Gans <guru.mail@muenster.de>
* Refactoring FLabel::draw * Refactoring FLabel::draw
* Refactoring FFileDialog::readDir * Refactoring FFileDialog::readDir

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -36,6 +36,10 @@ void inputStreamExample();
void outputStreamExample(); void outputStreamExample();
void streamingIntoFStringExample(); void streamingIntoFStringExample();
void streamingFromFStringExample(); void streamingFromFStringExample();
void streamToInterger();
void streamToUnsignedInterger();
void streamToDouble();
void streamToFloat();
void CStringOutputExample(); void CStringOutputExample();
void copyIntoFString(); void copyIntoFString();
void utf8StringOutputExample(); void utf8StringOutputExample();
@ -193,6 +197,23 @@ void streamingFromFStringExample()
std::cout << "stream out: " << stream_char << std::endl; std::cout << "stream out: " << stream_char << std::endl;
// ...to interger // ...to interger
streamToInterger();
// ...to unsigned interger
streamToUnsignedInterger();
// ...to double
streamToDouble();
// ...to float
streamToFloat();
}
//----------------------------------------------------------------------
void streamToInterger()
{
// Streaming from a FString to interger
try try
{ {
int stream_int; int stream_int;
@ -212,7 +233,12 @@ void streamingFromFStringExample()
std::cerr << "Arithmetic error: " << ex.what() << std::endl; std::cerr << "Arithmetic error: " << ex.what() << std::endl;
} }
// ...to unsigned interger }
//----------------------------------------------------------------------
void streamToUnsignedInterger()
{
// Streaming from a FString to unsigned interger
try try
{ {
uInt stream_uint; uInt stream_uint;
@ -231,8 +257,12 @@ void streamingFromFStringExample()
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; std::cerr << "Arithmetic error: " << ex.what() << std::endl;
} }
}
// ...to double //----------------------------------------------------------------------
void streamToDouble()
{
// Streaming from a FString to double
try try
{ {
double stream_double; double stream_double;
@ -247,8 +277,12 @@ void streamingFromFStringExample()
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; std::cerr << "Arithmetic error: " << ex.what() << std::endl;
} }
}
// ...to float //----------------------------------------------------------------------
void streamToFloat()
{
// Streaming from a FString to float
try try
{ {
float stream_float; float stream_float;

View File

@ -184,6 +184,8 @@ class FDialog : public FWindow
void drawBarButton(); void drawBarButton();
void drawZoomButton(); void drawZoomButton();
void drawTextBar(); void drawTextBar();
void restoreOverlaidWindows();
void setCursorToFocusWidget();
void leaveMenu(); void leaveMenu();
void openMenu(); void openMenu();
void selectFirstMenuItem(); void selectFirstMenuItem();

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -98,6 +98,8 @@ class FSwitch : public FToggleButton
// Methods // Methods
void draw(); void draw();
void drawCheckButton(); void drawCheckButton();
void drawChecked();
void drawUnchecked();
// Data Members // Data Members
int switch_offset_pos; int switch_offset_pos;

View File

@ -390,6 +390,8 @@ class FWidget : public FVTerm, public FObject
void KeyDownEvent (FKeyEvent*); void KeyDownEvent (FKeyEvent*);
void processDestroy(); void processDestroy();
virtual void draw(); virtual void draw();
void drawWindows();
void drawChildren();
void drawTransparentShadow (int, int, int, int); void drawTransparentShadow (int, int, int, int);
void drawBlockShadow (int, int, int, int); void drawBlockShadow (int, int, int, int);
static void setColorTheme(); static void setColorTheme();

View File

@ -278,40 +278,9 @@ void FDialog::setPos (int x, int y, bool)
restoreVTerm (old_geometry); restoreVTerm (old_geometry);
} }
// handle overlaid windows restoreOverlaidWindows();
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;
}
}
FWindow::adjustSize(); FWindow::adjustSize();
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);
}
updateTerminal(); updateTerminal();
} }
@ -1235,6 +1204,48 @@ void FDialog::drawTextBar()
unsetBold(); 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() void FDialog::leaveMenu()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -129,94 +129,106 @@ void FSwitch::drawCheckButton()
if ( ! isVisible() ) if ( ! isVisible() )
return; return;
wchar_t on[6] = L" On ";
wchar_t off[6] = L" Off ";
setPrintPos (1 + switch_offset_pos, 1); setPrintPos (1 + switch_offset_pos, 1);
if ( checked ) 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" <On>", 6);
{ setBold(true);
std::wcsncpy ( on, L" <On>", 6); }
setBold(true); else if ( getMaxColor() < 16 )
} {
else if ( getMaxColor() < 16 ) setBold(true);
{ setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
setBold(true);
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
}
else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
} }
else else
{ setColor (wc.button_hotkey_fg, wc.button_active_focus_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);
} }
else 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() ) if ( isMonochron() )
setReverse(true);
print (on);
if ( hasFocus() && ! button_pressed )
{ {
if ( isMonochron() ) std::wcsncpy ( off, L"<Off>", 6);
{ setBold(true);
std::wcsncpy ( off, L"<Off>", 6); }
setBold(true); else if ( getMaxColor() < 16 )
} {
else if ( getMaxColor() < 16 ) setBold(true);
{ setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
setBold(true);
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg);
}
else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
} }
else else
{ setColor (wc.button_hotkey_fg, wc.button_active_focus_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 (off);
if ( isMonochron() || getMaxColor() < 16 )
setBold(false);
setCursorPos (7 + switch_offset_pos, 1);
} }
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);
} }

View File

@ -1114,60 +1114,9 @@ void FWidget::redraw()
draw(); draw();
if ( isRootWidget() ) if ( isRootWidget() )
{ drawWindows();
// 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;
}
}
}
else else
{ drawChildren();
// draw child elements
if ( hasChildren() )
{
constFObjectIterator iter, last;
iter = FObject::begin();
last = FObject::end();
while ( iter != last )
{
if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw();
}
++iter;
}
}
}
if ( isRootWidget() ) if ( isRootWidget() )
finishTerminalUpdate(); finishTerminalUpdate();
@ -2405,6 +2354,65 @@ void FWidget::KeyDownEvent (FKeyEvent* kev)
void FWidget::draw() 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<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw();
}
++iter;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2) void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2)
{ {