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>
* Refactoring FLabel::draw
* Refactoring FFileDialog::readDir

View File

@ -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;

View File

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

View File

@ -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;

View File

@ -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();

View File

@ -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()
{

View File

@ -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,12 +129,20 @@ 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 ( isMonochron() )
@ -176,9 +184,14 @@ void FSwitch::drawCheckButton()
setReverse(false);
setCursorPos (3 + switch_offset_pos, 1);
}
else
{
}
//----------------------------------------------------------------------
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() )
@ -218,5 +231,4 @@ void FSwitch::drawCheckButton()
setBold(false);
setCursorPos (7 + switch_offset_pos, 1);
}
}

View File

@ -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<FWidget*>(*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<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw();
}
++iter;
}
}
//----------------------------------------------------------------------
void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2)
{