The widget flags are now stored in a bit field

This commit is contained in:
Markus Gans 2018-11-04 23:00:06 +01:00
parent 1f8d16791a
commit 5a356664b2
24 changed files with 139 additions and 224 deletions

View File

@ -1,3 +1,6 @@
2018-11-04 Markus Gans <guru.mail@muenster.de>
* Widget flags are now stored in a bit field
2018-11-03 Markus Gans <guru.mail@muenster.de> 2018-11-03 Markus Gans <guru.mail@muenster.de>
* New method rgb2ColorIndex() to converts a 24-bit RGB color * New method rgb2ColorIndex() to converts a 24-bit RGB color
to a 256-color compatible approximation to a 256-color compatible approximation

View File

@ -12,6 +12,7 @@
&#160;&#160;&#160;&#160;&#160;[![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html) &#160;&#160;&#160;&#160;&#160;[![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html)
The FINAL CUT is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen. The FINAL CUT is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen.
The structure of the Qt framework was originally the inspiration for the C++ class design of FINAL CUT. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. The structure of the Qt framework was originally the inspiration for the C++ class design of FINAL CUT. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on.
### Installation ### Installation

View File

@ -7,7 +7,8 @@ support for creating a text-based user interface. The library supports
the programmer to develop an application for the text console. It allows the programmer to develop an application for the text console. It allows
the simultaneous handling of multiple text windows on the screen. the simultaneous handling of multiple text windows on the screen.
The C++ class design was inspired by the Qt framework. It provides The structure of the Qt framework was originally the inspiration for
common controls like dialog boxes, push buttons, check boxes, the C++ class design of FINAL CUT. It provides common controls like
radio buttons, input lines, list boxes, status bars and so on. dialog boxes, push buttons, check boxes, radio buttons, input lines,
list boxes, status bars and so on.

View File

@ -188,7 +188,7 @@ bool FApplication::sendEvent ( const FObject* receiver
// block events for widgets in non modal windows // block events for widgets in non modal windows
if ( window if ( window
&& (window->getFlags() & fc::modal) == 0 && ! window->getFlags().modal
&& ! window->isMenuWidget() ) && ! window->isMenuWidget() )
{ {
switch ( event->type() ) switch ( event->type() )

View File

@ -157,12 +157,7 @@ void FButton::setInactiveBackgroundColor (short color)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButton::setNoUnderline (bool on) bool FButton::setNoUnderline (bool on)
{ {
if ( on ) return (flags.no_underline = on);
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -211,11 +206,7 @@ bool FButton::setFocus (bool on)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButton::setFlat (bool on) bool FButton::setFlat (bool on)
{ {
if ( on ) return (flags.flat = on);
flags |= fc::flat;
else
flags &= ~fc::flat;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -225,16 +216,16 @@ bool FButton::setShadow (bool on)
&& getEncoding() != fc::VT100 && getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && getEncoding() != fc::ASCII )
{ {
flags |= fc::shadow; flags.shadow = true;
setShadowSize(1,1); setShadowSize(1,1);
} }
else else
{ {
flags &= ~fc::shadow; flags.shadow = false;
setShadowSize(0,0); setShadowSize(0,0);
} }
return on; return flags.shadow;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -465,13 +456,12 @@ void FButton::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::getButtonState() void FButton::getButtonState()
{ {
int active_focus = fc::active + fc::focus; is.active_focus = flags.active && flags.focus;
is.active_focus = ((flags & active_focus) == active_focus); is.active = flags.active;
is.active = ((flags & fc::active) != 0); is.focus = flags.focus;
is.focus = ((flags & fc::focus) != 0);
is.flat = isFlat(); is.flat = isFlat();
is.non_flat_shadow = ((flags & (fc::shadow + fc::flat)) == fc::shadow); is.non_flat_shadow = ! flags.flat && flags.shadow;
is.no_underline = ((flags & fc::no_underline) != 0); is.no_underline = flags.no_underline;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -666,10 +656,14 @@ inline void FButton::drawTopBottomBackground()
inline void FButton::drawButtonTextLine (wchar_t button_text[]) inline void FButton::drawButtonTextLine (wchar_t button_text[])
{ {
std::size_t pos; std::size_t pos;
center_offset = (getWidth() - txtlength - 1) / 2;
setPrintPos (2 + int(indent), 1 + int(vcenter_offset)); setPrintPos (2 + int(indent), 1 + int(vcenter_offset));
setColor (button_fg, button_bg); setColor (button_fg, button_bg);
if ( getWidth() < txtlength + 1 )
center_offset = 0;
else
center_offset = (getWidth() - txtlength - 1) / 2;
// Print button text line -------- // Print button text line --------
for (pos = 0; pos < center_offset; pos++) for (pos = 0; pos < center_offset; pos++)
print (space_char); // █ print (space_char); // █

View File

@ -543,9 +543,6 @@ bool FButtonGroup::isRadioButton (FToggleButton* button) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::init() void FButtonGroup::init()
{ {
if ( isEnabled() )
flags |= fc::active;
setForegroundColor (wc.label_fg); setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg); setBackgroundColor (wc.label_bg);
setMinimumSize (7, 4); setMinimumSize (7, 4);
@ -582,9 +579,6 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
, std::size_t hotkeypos , std::size_t hotkeypos
, std::size_t length ) , std::size_t length )
{ {
bool isActive = ((flags & fc::active) != 0);
bool isNoUnderline = ((flags & fc::no_underline) != 0);
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
@ -595,16 +589,16 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
for (std::size_t z = 0; z < length; z++) for (std::size_t z = 0; z < length; z++)
{ {
if ( (z == hotkeypos) && isActive ) if ( (z == hotkeypos) && flags.active )
{ {
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
if ( ! isNoUnderline ) if ( ! flags.no_underline )
setUnderline(); setUnderline();
print (LabelText[z]); print (LabelText[z]);
if ( ! isNoUnderline ) if ( ! flags.no_underline )
unsetUnderline(); unsetUnderline();
setColor (wc.label_emphasis_fg, wc.label_bg); setColor (wc.label_emphasis_fg, wc.label_bg);

View File

@ -103,16 +103,12 @@ bool FDialog::setDialogWidget (bool on)
if ( isDialogWidget() == on ) if ( isDialogWidget() == on )
return true; return true;
flags.dialog_widget = on;
if ( on ) if ( on )
{
flags |= fc::dialog_widget;
setTermOffsetWithPadding(); setTermOffsetWithPadding();
}
else else
{
flags &= ~fc::dialog_widget;
setParentOffset(); setParentOffset();
}
return on; return on;
} }
@ -123,16 +119,12 @@ bool FDialog::setModal (bool on)
if ( isModal() == on ) if ( isModal() == on )
return true; return true;
flags.modal = on;
if ( on ) if ( on )
{
flags |= fc::modal;
modal_dialogs++; modal_dialogs++;
}
else else
{
flags &= ~fc::modal;
modal_dialogs--; modal_dialogs--;
}
return on; return on;
} }
@ -141,12 +133,7 @@ bool FDialog::setModal (bool on)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FDialog::setScrollable (bool on) bool FDialog::setScrollable (bool on)
{ {
if ( on ) return (flags.scrollable = on);
flags |= fc::scrollable;
else
flags &= ~fc::scrollable;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -835,7 +822,7 @@ void FDialog::draw()
drawTitleBar(); drawTitleBar();
setCursorPos(2, int(getHeight()) - 1); setCursorPos(2, int(getHeight()) - 1);
if ( (flags & fc::shadow) != 0 ) if ( flags.shadow )
drawDialogShadow(); drawDialogShadow();
if ( isMonochron() ) if ( isMonochron() )
@ -845,7 +832,7 @@ void FDialog::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::drawDialogShadow() void FDialog::drawDialogShadow()
{ {
if ( isMonochron() && (flags & fc::trans_shadow) == 0 ) if ( isMonochron() && ! flags.trans_shadow )
return; return;
drawShadow(); drawShadow();

View File

@ -597,9 +597,6 @@ void FLabel::printLine ( wchar_t line[]
{ {
std::size_t to_char; std::size_t to_char;
std::size_t width = std::size_t(getWidth()); std::size_t width = std::size_t(getWidth());
bool isActive, isNoUnderline;
isActive = ((flags & fc::active) != 0);
isNoUnderline = ((flags & fc::no_underline) != 0);
if ( align_offset > 0 ) if ( align_offset > 0 )
print (FString(align_offset, ' ')); // leading spaces print (FString(align_offset, ' ')); // leading spaces
@ -623,16 +620,16 @@ void FLabel::printLine ( wchar_t line[]
} }
} }
if ( z == hotkeypos && isActive ) if ( z == hotkeypos && flags.active )
{ {
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
if ( ! isNoUnderline ) if ( ! flags.no_underline )
setUnderline(); setUnderline();
print (line[z]); print (line[z]);
if ( ! isNoUnderline ) if ( ! flags.no_underline )
unsetUnderline(); unsetUnderline();
if ( hasEmphasis() ) if ( hasEmphasis() )

View File

@ -239,16 +239,16 @@ bool FLineEdit::setShadow (bool on)
&& getEncoding() != fc::VT100 && getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && getEncoding() != fc::ASCII )
{ {
flags |= fc::shadow; flags.shadow = true;
setShadowSize(1,1); setShadowSize(1,1);
} }
else else
{ {
flags &= ~fc::shadow; flags.shadow = false;
setShadowSize(0,0); setShadowSize(0,0);
} }
return on; return flags.shadow;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -698,11 +698,9 @@ bool FLineEdit::hasHotkey()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::draw() void FLineEdit::draw()
{ {
bool isFocus;
drawInputField(); drawInputField();
isFocus = ((flags & fc::focus) != 0);
if ( isFocus && getStatusBar() ) if ( flags.focus && getStatusBar() )
{ {
const FString& msg = getStatusbarMessage(); const FString& msg = getStatusbarMessage();
const FString& curMsg = getStatusBar()->getMessage(); const FString& curMsg = getStatusBar()->getMessage();
@ -718,12 +716,9 @@ void FLineEdit::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::drawInputField() void FLineEdit::drawInputField()
{ {
bool isActiveFocus, isShadow;
std::size_t x; std::size_t x;
FString show_text; FString show_text;
int active_focus = fc::active + fc::focus; bool isActiveFocus = flags.active && flags.focus;
isActiveFocus = ((flags & active_focus) == active_focus);
isShadow = ((flags & fc::shadow) != 0 );
setPrintPos (1, 1); setPrintPos (1, 1);
if ( isMonochron() ) if ( isMonochron() )
@ -776,7 +771,7 @@ void FLineEdit::drawInputField()
setUnderline(false); setUnderline(false);
} }
if ( isShadow ) if ( flags.shadow )
drawShadow (); drawShadow ();
// set the cursor to the first pos. // set the cursor to the first pos.

View File

@ -872,8 +872,6 @@ void FListBox::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::draw() void FListBox::draw()
{ {
bool isFocus;
if ( current < 1 ) if ( current < 1 )
current = 1; current = 1;
@ -910,9 +908,8 @@ void FListBox::draw()
hbar->redraw(); hbar->redraw();
drawList(); drawList();
isFocus = ((flags & fc::focus) != 0);
if ( isFocus && getStatusBar() ) if ( flags.focus && getStatusBar() )
{ {
const FString& msg = getStatusbarMessage(); const FString& msg = getStatusbarMessage();
const FString& curMsg = getStatusBar()->getMessage(); const FString& curMsg = getStatusBar()->getMessage();
@ -1017,14 +1014,13 @@ inline void FListBox::drawListLine ( int y
std::size_t i, len; std::size_t i, len;
std::size_t inc_len = inc_search.getLength(); std::size_t inc_len = inc_search.getLength();
bool isCurrentLine = bool(y + yoffset + 1 == int(current)); bool isCurrentLine = bool(y + yoffset + 1 == int(current));
bool isFocus = ((flags & fc::focus) != 0);
FString element; FString element;
element = getString(iter).mid ( std::size_t(1 + xoffset) element = getString(iter).mid ( std::size_t(1 + xoffset)
, getWidth() - nf_offset - 4 ); , getWidth() - nf_offset - 4 );
const wchar_t* const& element_str = element.wc_str(); const wchar_t* const& element_str = element.wc_str();
len = element.getLength(); len = element.getLength();
if ( isMonochron() && isCurrentLine && isFocus ) if ( isMonochron() && isCurrentLine && flags.focus )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
else else
print (' '); print (' ');
@ -1035,14 +1031,14 @@ inline void FListBox::drawListLine ( int y
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
if ( serach_mark && i == inc_len && isFocus ) if ( serach_mark && i == inc_len && flags.focus )
setColor ( wc.current_element_focus_fg setColor ( wc.current_element_focus_fg
, wc.current_element_focus_bg ); , wc.current_element_focus_bg );
print (element_str[i]); print (element_str[i]);
} }
if ( isMonochron() && isCurrentLine && isFocus ) if ( isMonochron() && isCurrentLine && flags.focus )
{ {
print (fc::BlackLeftPointingPointer); // ◄ print (fc::BlackLeftPointingPointer); // ◄
i++; i++;
@ -1116,9 +1112,8 @@ inline void FListBox::drawListBracketsLine ( int y
, i = 0 , i = 0
, b = 0; , b = 0;
bool isCurrentLine = bool(y + yoffset + 1 == int(current)); bool isCurrentLine = bool(y + yoffset + 1 == int(current));
bool isFocus = ((flags & fc::focus) != 0);
if ( isMonochron() && isCurrentLine && isFocus ) if ( isMonochron() && isCurrentLine && flags.focus )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
else else
print (' '); print (' ');
@ -1164,7 +1159,7 @@ inline void FListBox::drawListBracketsLine ( int y
i++; i++;
} }
if ( isMonochron() && isCurrentLine && isFocus ) if ( isMonochron() && isCurrentLine && flags.focus )
{ {
print (fc::BlackLeftPointingPointer); // ◄ print (fc::BlackLeftPointingPointer); // ◄
i++; i++;
@ -1180,10 +1175,8 @@ inline void FListBox::setLineAttributes ( int y
, bool lineHasBrackets , bool lineHasBrackets
, bool& serach_mark ) , bool& serach_mark )
{ {
bool isFocus = ((flags & fc::focus) != 0) bool isCurrentLine = bool(y + yoffset + 1 == int(current));
, isCurrentLine = bool(y + yoffset + 1 == int(current));
std::size_t inc_len = inc_search.getLength(); std::size_t inc_len = inc_search.getLength();
setPrintPos (2, 2 + int(y)); setPrintPos (2, 2 + int(y));
if ( isLineSelected ) if ( isLineSelected )
@ -1203,14 +1196,14 @@ inline void FListBox::setLineAttributes ( int y
if ( isCurrentLine ) if ( isCurrentLine )
{ {
if ( isFocus && getMaxColor() < 16 ) if ( flags.focus && getMaxColor() < 16 )
setBold(); setBold();
if ( isLineSelected ) if ( isLineSelected )
{ {
if ( isMonochron() ) if ( isMonochron() )
setBold(); setBold();
else if ( isFocus ) else if ( flags.focus )
setColor ( wc.selected_current_element_focus_fg setColor ( wc.selected_current_element_focus_fg
, wc.selected_current_element_focus_bg ); , wc.selected_current_element_focus_bg );
else else
@ -1224,7 +1217,7 @@ inline void FListBox::setLineAttributes ( int y
if ( isMonochron() ) if ( isMonochron() )
unsetBold(); unsetBold();
if ( isFocus ) if ( flags.focus )
{ {
setColor ( wc.current_element_focus_fg setColor ( wc.current_element_focus_fg
, wc.current_element_focus_bg ); , wc.current_element_focus_bg );
@ -1251,7 +1244,7 @@ inline void FListBox::setLineAttributes ( int y
{ {
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
else if ( isFocus && getMaxColor() < 16 ) else if ( flags.focus && getMaxColor() < 16 )
unsetBold(); unsetBold();
} }
} }

View File

@ -1481,8 +1481,6 @@ std::size_t FListView::getAlignOffset ( fc::text_alignment align
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::draw() void FListView::draw()
{ {
bool isFocus;
if ( current_iter.getPosition() < 1 ) if ( current_iter.getPosition() < 1 )
current_iter = itemlist.begin(); current_iter = itemlist.begin();
@ -1519,9 +1517,8 @@ void FListView::draw()
hbar->redraw(); hbar->redraw();
drawList(); drawList();
isFocus = ((flags & fc::focus) != 0);
if ( isFocus && getStatusBar() ) if ( flags.focus && getStatusBar() )
{ {
const FString& msg = getStatusbarMessage(); const FString& msg = getStatusbarMessage();
const FString& curMsg = getStatusBar()->getMessage(); const FString& curMsg = getStatusBar()->getMessage();
@ -1587,7 +1584,6 @@ void FListView::drawColumnLabels()
void FListView::drawList() void FListView::drawList()
{ {
uInt page_height, y; uInt page_height, y;
bool is_focus;
FListViewIterator iter; FListViewIterator iter;
if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 ) if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 )
@ -1595,7 +1591,6 @@ void FListView::drawList()
y = 0; y = 0;
page_height = uInt(getHeight() - 2); page_height = uInt(getHeight() - 2);
is_focus = ((flags & fc::focus) != 0);
iter = first_visible_line; iter = first_visible_line;
while ( iter != itemlist.end() && y < page_height ) while ( iter != itemlist.end() && y < page_height )
@ -1605,9 +1600,9 @@ void FListView::drawList()
setPrintPos (2, 2 + int(y)); setPrintPos (2, 2 + int(y));
// Draw one FListViewItem // Draw one FListViewItem
drawListLine (item, is_focus, is_current_line); drawListLine (item, flags.focus, is_current_line);
if ( is_focus && is_current_line ) if ( flags.focus && is_current_line )
setCursorPos (3, 2 + int(y)); // first character setCursorPos (3, 2 + int(y)); // first character
last_visible_line = iter; last_visible_line = iter;

View File

@ -82,12 +82,7 @@ bool FMenu::setMenuWidget (bool on)
if ( isMenuWidget() == on ) if ( isMenuWidget() == on )
return true; return true;
if ( on ) return (flags.menu_widget = on);
flags |= fc::menu_widget;
else
flags &= ~fc::menu_widget;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1350,7 +1345,7 @@ inline void FMenu::drawMenuLine (FMenuItem* menuitem, int y)
to_char--; to_char--;
txtdata.length = to_char; txtdata.length = to_char;
txtdata.no_underline = ((menuitem->getFlags() & fc::no_underline) != 0); txtdata.no_underline = menuitem->getFlags().no_underline;
setCursorToHotkeyPosition (menuitem); setCursorToHotkeyPosition (menuitem);
if ( ! is_enabled || is_selected ) if ( ! is_enabled || is_selected )

View File

@ -554,7 +554,7 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
bool is_selected = menuitem->isSelected(); bool is_selected = menuitem->isSelected();
txtdata.startpos = x + 1; txtdata.startpos = x + 1;
txtdata.no_underline = ((menuitem->getFlags() & fc::no_underline) != 0); txtdata.no_underline = menuitem->getFlags().no_underline;
// Set screen attributes // Set screen attributes
setLineAttributes (menuitem); setLineAttributes (menuitem);

View File

@ -83,12 +83,12 @@ bool FProgressbar::setShadow (bool on)
&& getEncoding() != fc::VT100 && getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && getEncoding() != fc::ASCII )
{ {
flags |= fc::shadow; flags.shadow = true;
setShadowSize(1,1); setShadowSize(1,1);
} }
else else
{ {
flags &= ~fc::shadow; flags.shadow = false;
setShadowSize(0,0); setShadowSize(0,0);
} }
@ -157,7 +157,7 @@ void FProgressbar::draw()
drawPercentage(); drawPercentage();
drawBar(); drawBar();
if ( (flags & fc::shadow) != 0 ) if ( flags.shadow )
drawShadow (); drawShadow ();
flush_out(); flush_out();

View File

@ -109,12 +109,7 @@ void FToggleButton::setGeometry (int x, int y, std::size_t w, std::size_t h, boo
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FToggleButton::setNoUnderline (bool on) bool FToggleButton::setNoUnderline (bool on)
{ {
if ( on ) return (flags.no_underline = on);
flags |= fc::no_underline;
else
flags &= ~fc::no_underline;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -464,9 +459,7 @@ bool FToggleButton::isCheckboxButton() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::draw() void FToggleButton::draw()
{ {
bool isFocus = ((flags & fc::focus) != 0); if ( flags.focus && getStatusBar() )
if ( isFocus && getStatusBar() )
{ {
const FString& msg = getStatusbarMessage(); const FString& msg = getStatusbarMessage();
const FString& curMsg = getStatusBar()->getMessage(); const FString& curMsg = getStatusBar()->getMessage();
@ -649,12 +642,9 @@ std::size_t FToggleButton::getHotkeyPos ( wchar_t src[]
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawText ( wchar_t LabelText[] void FToggleButton::drawText ( wchar_t LabelText[]
, std::size_t hotkeypos , std::size_t hotkeypos
, std::size_t length ) , std::size_t length )
{ {
bool isActive = ((flags & fc::active) != 0);
bool isNoUnderline = ((flags & fc::no_underline) != 0);
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
@ -665,16 +655,16 @@ void FToggleButton::drawText ( wchar_t LabelText[]
for (std::size_t z = 0; z < length; z++) for (std::size_t z = 0; z < length; z++)
{ {
if ( (z == hotkeypos) && isActive ) if ( (z == hotkeypos) && flags.active )
{ {
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc.label_hotkey_fg, wc.label_hotkey_bg);
if ( ! isNoUnderline ) if ( ! flags.no_underline )
setUnderline(); setUnderline();
print ( LabelText[z] ); print ( LabelText[z] );
if ( ! isNoUnderline ) if ( ! flags.no_underline )
unsetUnderline(); unsetUnderline();
setColor (wc.label_fg, wc.label_bg); setColor (wc.label_fg, wc.label_bg);

View File

@ -58,13 +58,11 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen)
: FVTerm(bool(! parent), disable_alt_screen) : FVTerm(bool(! parent), disable_alt_screen)
, FObject(parent) , FObject(parent)
, accelerator_list(0) , accelerator_list(0)
, flags(0) , flags()
, callback_objects() , callback_objects()
, member_callback_objects() , member_callback_objects()
, enable(true)
, visible(true) , visible(true)
, shown(false) , shown(false)
, focus(false)
, focusable(true) , focusable(true)
, visible_cursor(true) , visible_cursor(true)
, widget_cursor_position(-1, -1) , widget_cursor_position(-1, -1)
@ -84,8 +82,11 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen)
, background_color(fc::Default) , background_color(fc::Default)
, statusbar_message() , statusbar_message()
{ {
if ( isEnabled() ) // init bit field with 0
flags |= fc::active; memset (&flags, 0, sizeof(flags));
// Enable widget by default
flags.active = true;
widget_object = true; widget_object = true;
@ -124,7 +125,7 @@ FWidget::~FWidget() // destructor
setClickedWidget(0); setClickedWidget(0);
// unset the local window widget focus // unset the local window widget focus
if ( focus ) if ( flags.focus )
{ {
if ( FWindow* window = FWindow::getWindowWidget(this) ) if ( FWindow* window = FWindow::getWindowWidget(this) )
window->setWindowFocusWidget(0); window->setWindowFocusWidget(0);
@ -276,12 +277,7 @@ void FWidget::setMainWidget (FWidget* obj)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::setEnable (bool on) bool FWidget::setEnable (bool on)
{ {
if ( on ) return (flags.active = on);
flags |= fc::active;
else
flags &= ~fc::active;
return enable = on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -290,21 +286,16 @@ bool FWidget::setFocus (bool on)
FWindow* window; FWindow* window;
FWidget* last_focus; FWidget* last_focus;
if ( ! enable ) if ( ! isEnabled() )
return false; return false;
if ( on ) if ( flags.focus == on )
flags |= fc::focus;
else
flags &= ~fc::focus;
if ( on == focus )
return true; return true;
last_focus = FWidget::getFocusWidget(); last_focus = FWidget::getFocusWidget();
// set widget focus // set widget focus
if ( on && ! focus ) if ( on && ! flags.focus )
{ {
int focusable_children = numOfFocusableChildren(); int focusable_children = numOfFocusableChildren();
@ -334,7 +325,7 @@ bool FWidget::setFocus (bool on)
window->setWindowFocusWidget(this); window->setWindowFocusWidget(this);
} }
return focus = on; return (flags.focus = on);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -659,7 +650,7 @@ bool FWidget::setCursorPos (int x, int y)
widget_cursor_position.setPoint(x, y); widget_cursor_position.setPoint(x, y);
if ( (flags & fc::focus) == 0 || isWindowWidget() ) if ( ! flags.focus || isWindowWidget() )
return false; return false;
if ( ! FWindow::getWindowWidget(this) ) if ( ! FWindow::getWindowWidget(this) )
@ -856,7 +847,7 @@ bool FWidget::close()
{ {
hide(); hide();
if ( (flags & fc::modal) == 0 ) if ( ! flags.modal )
close_widget->push_back(this); close_widget->push_back(this);
} }
return true; return true;
@ -1266,13 +1257,11 @@ void FWidget::move (int dx, int dy)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::drawShadow() void FWidget::drawShadow()
{ {
bool trans_shadow = ((flags & fc::trans_shadow) != 0); if ( isMonochron() && ! flags.trans_shadow )
if ( isMonochron() && ! trans_shadow )
return; return;
if ( (getEncoding() == fc::VT100 && ! trans_shadow) if ( (getEncoding() == fc::VT100 && ! flags.trans_shadow)
|| (getEncoding() == fc::ASCII && ! trans_shadow) ) || (getEncoding() == fc::ASCII && ! flags.trans_shadow) )
{ {
clearShadow(); clearShadow();
return; return;
@ -1283,7 +1272,7 @@ void FWidget::drawShadow()
, y1 = 1 , y1 = 1
, y2 = int(getHeight()); , y2 = int(getHeight());
if ( trans_shadow ) if ( flags.trans_shadow )
{ {
// transparent shadow // transparent shadow
drawTransparentShadow (x1, y1, x2, y2); drawTransparentShadow (x1, y1, x2, y2);

View File

@ -93,16 +93,12 @@ bool FWindow::setWindowWidget (bool on)
if ( isWindowWidget() == on ) if ( isWindowWidget() == on )
return true; return true;
flags.window_widget = on;
if ( on ) if ( on )
{
flags |= fc::window_widget;
setTermOffset(); setTermOffset();
}
else else
{
flags &= ~fc::window_widget;
setParentOffset(); setParentOffset();
}
return on; return on;
} }
@ -179,29 +175,18 @@ void FWindow::unsetActiveWindow()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWindow::setResizeable (bool on) bool FWindow::setResizeable (bool on)
{ {
if ( on ) return (flags.resizeable = on);
flags |= fc::resizeable;
else
flags &= ~fc::resizeable;
return on;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWindow::setTransparentShadow (bool on) bool FWindow::setTransparentShadow (bool on)
{ {
flags.shadow = flags.trans_shadow = on;
if ( on ) if ( on )
{
flags |= fc::shadow;
flags |= fc::trans_shadow;
setShadowSize (2,1); setShadowSize (2,1);
}
else else
{
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
setShadowSize (0,0); setShadowSize (0,0);
}
return on; return on;
} }
@ -214,14 +199,14 @@ bool FWindow::setShadow (bool on)
if ( on ) if ( on )
{ {
flags |= fc::shadow; flags.shadow = true;
flags &= ~fc::trans_shadow; flags.trans_shadow = false;
setShadowSize (1,1); setShadowSize (1,1);
} }
else else
{ {
flags &= ~fc::shadow; flags.shadow = false;
flags &= ~fc::trans_shadow; flags.trans_shadow = false;
setShadowSize (0,0); setShadowSize (0,0);
} }
@ -234,10 +219,10 @@ bool FWindow::setAlwaysOnTop (bool on)
if ( isAlwaysOnTop() == on ) if ( isAlwaysOnTop() == on )
return true; return true;
flags.always_on_top = on;
if ( on ) if ( on )
{ {
flags |= fc::always_on_top;
if ( always_on_top_list ) if ( always_on_top_list )
{ {
deleteFromAlwaysOnTopList (this); deleteFromAlwaysOnTopList (this);
@ -245,10 +230,7 @@ bool FWindow::setAlwaysOnTop (bool on)
} }
} }
else else
{
flags &= ~fc::always_on_top;
deleteFromAlwaysOnTopList (this); deleteFromAlwaysOnTopList (this);
}
return on; return on;
} }
@ -580,10 +562,10 @@ void FWindow::swapWindow (FWidget* obj1, FWidget* obj2)
if ( window_list->empty() ) if ( window_list->empty() )
return; return;
if ( (obj1->getFlags() & fc::modal) != 0 ) if ( obj1->getFlags().modal )
return; return;
if ( (obj2->getFlags() & fc::modal) != 0 ) if ( obj2->getFlags().modal )
return; return;
iter = window_list->begin(); iter = window_list->begin();
@ -623,7 +605,7 @@ bool FWindow::raiseWindow (FWidget* obj)
if ( window_list->back() == obj ) if ( window_list->back() == obj )
return false; return false;
if ( (window_list->back()->getFlags() & fc::modal) != 0 if ( window_list->back()->getFlags().modal
&& ! obj->isMenuWidget() ) && ! obj->isMenuWidget() )
return false; return false;
@ -665,7 +647,7 @@ bool FWindow::lowerWindow (FWidget* obj)
if ( window_list->front() == obj ) if ( window_list->front() == obj )
return false; return false;
if ( (obj->getFlags() & fc::modal) != 0 ) if ( obj->getFlags().modal )
return false; return false;
iter = window_list->begin(); iter = window_list->begin();

View File

@ -265,7 +265,7 @@ inline bool FButton::unsetClickAnimation()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FButton::isFlat() const inline bool FButton::isFlat() const
{ return ((flags & fc::flat) != 0); } { return flags.flat; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FButton::isDown() const inline bool FButton::isDown() const
@ -273,7 +273,7 @@ inline bool FButton::isDown() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FButton::hasShadow() const inline bool FButton::hasShadow() const
{ return ((flags & fc::shadow) != 0); } { return flags.shadow; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FButton::hasClickAnimation() inline bool FButton::hasClickAnimation()

View File

@ -79,24 +79,6 @@ enum events
Timer_Event // timer event occur Timer_Event // timer event occur
}; };
// Properties of a widget ⚑
enum widget_flags
{
shadow = 0x00000001,
trans_shadow = 0x00000002,
active = 0x00000004,
focus = 0x00000008,
scrollable = 0x00000010,
resizeable = 0x00000020,
modal = 0x00000040,
window_widget = 0x00000080,
dialog_widget = 0x00000100,
menu_widget = 0x00000200,
always_on_top = 0x00000400,
flat = 0x00000800,
no_underline = 0x00001000
};
// Internal character encoding // Internal character encoding
enum encoding enum encoding
{ {

View File

@ -282,11 +282,11 @@ inline void FDialog::setText (const FString& txt)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FDialog::isModal() inline bool FDialog::isModal()
{ return ((flags & fc::modal) != 0); } { return flags.modal; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FDialog::isScrollable() inline bool FDialog::isScrollable()
{ return ((flags & fc::scrollable) != 0); } { return flags.scrollable; }
} // namespace finalcut } // namespace finalcut

View File

@ -227,7 +227,7 @@ inline bool FLineEdit::unsetShadow()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FLineEdit::hasShadow() inline bool FLineEdit::hasShadow()
{ return ((flags & fc::shadow) != 0); } { return flags.shadow; }
} // namespace finalcut } // namespace finalcut

View File

@ -129,7 +129,7 @@ inline bool FProgressbar::unsetShadow()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FProgressbar::hasShadow() inline bool FProgressbar::hasShadow()
{ return ((flags & fc::shadow) != 0); } { return flags.shadow; }
} // namespace finalcut } // namespace finalcut

View File

@ -142,6 +142,8 @@ class FWidget : public FVTerm, public FObject
typedef void (FWidget::*FMemberCallback)(FWidget*, data_ptr); typedef void (FWidget::*FMemberCallback)(FWidget*, data_ptr);
typedef std::vector<accelerator> Accelerators; typedef std::vector<accelerator> Accelerators;
struct widget_flags; // forward declaration
// Constructor // Constructor
explicit FWidget (FWidget* = 0, bool = false); explicit FWidget (FWidget* = 0, bool = false);
@ -188,7 +190,7 @@ class FWidget : public FVTerm, public FObject
const FRect& getTermGeometryWithShadow(); const FRect& getTermGeometryWithShadow();
std::size_t getDesktopWidth(); std::size_t getDesktopWidth();
std::size_t getDesktopHeight(); std::size_t getDesktopHeight();
int getFlags() const; widget_flags getFlags() const;
FPoint getCursorPos(); FPoint getCursorPos();
FPoint getPrintPos(); FPoint getPrintPos();
std::vector<bool>& doubleFlatLine_ref (fc::sides); std::vector<bool>& doubleFlatLine_ref (fc::sides);
@ -373,7 +375,24 @@ class FWidget : public FVTerm, public FObject
virtual void onClose (FCloseEvent*); virtual void onClose (FCloseEvent*);
// Data Members // Data Members
int flags; struct widget_flags // Properties of a widget ⚑
{
uInt32 shadow : 1;
uInt32 trans_shadow : 1;
uInt32 active : 1;
uInt32 focus : 1;
uInt32 scrollable : 1;
uInt32 resizeable : 1;
uInt32 modal : 1;
uInt32 window_widget : 1;
uInt32 dialog_widget : 1;
uInt32 menu_widget : 1;
uInt32 always_on_top : 1;
uInt32 flat : 1;
uInt32 no_underline : 1;
uInt32 : 19; // padding bits
} flags;
static uInt modal_dialogs; static uInt modal_dialogs;
static FWidgetColors wc; static FWidgetColors wc;
static widgetList* dialog_list; static widgetList* dialog_list;
@ -407,10 +426,8 @@ class FWidget : public FVTerm, public FObject
static void setColorTheme(); static void setColorTheme();
// Data Members // Data Members
bool enable;
bool visible; bool visible;
bool shown; bool shown;
bool focus;
bool focusable; bool focusable;
bool visible_cursor; bool visible_cursor;
FPoint widget_cursor_position; FPoint widget_cursor_position;
@ -685,7 +702,7 @@ inline std::size_t FWidget::getDesktopHeight()
{ return getLineNumber(); } { return getLineNumber(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FWidget::getFlags() const inline FWidget::widget_flags FWidget::getFlags() const
{ return flags; } { return flags; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -873,19 +890,19 @@ inline bool FWidget::isShown() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::isWindowWidget() const inline bool FWidget::isWindowWidget() const
{ return ((flags & fc::window_widget) != 0); } { return flags.window_widget; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::isDialogWidget() const inline bool FWidget::isDialogWidget() const
{ return ((flags & fc::dialog_widget) != 0); } { return flags.dialog_widget; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::isMenuWidget() const inline bool FWidget::isMenuWidget() const
{ return ((flags & fc::menu_widget) != 0); } { return flags.menu_widget; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::isEnabled() const inline bool FWidget::isEnabled() const
{ return enable; } { return flags.active; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::hasVisibleCursor() const inline bool FWidget::hasVisibleCursor() const
@ -893,7 +910,7 @@ inline bool FWidget::hasVisibleCursor() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::hasFocus() const inline bool FWidget::hasFocus() const
{ return focus; } { return flags.focus; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWidget::acceptFocus() const // is focusable inline bool FWidget::acceptFocus() const // is focusable

View File

@ -250,19 +250,19 @@ inline bool FWindow::isWindowActive() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWindow::isResizeable() const inline bool FWindow::isResizeable() const
{ return ((flags & fc::resizeable) != 0); } { return flags.resizeable; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWindow::isAlwaysOnTop() const inline bool FWindow::isAlwaysOnTop() const
{ return ((flags & fc::always_on_top) != 0); } { return flags.always_on_top; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWindow::hasTransparentShadow() const inline bool FWindow::hasTransparentShadow() const
{ return ((flags & fc::trans_shadow) != 0); } { return flags.trans_shadow; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FWindow::hasShadow() const inline bool FWindow::hasShadow() const
{ return ((flags & fc::shadow) != 0); } { return flags.shadow; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FWindow* FWindow::getWindowWidgetAt (const FPoint& pos) inline FWindow* FWindow::getWindowWidgetAt (const FPoint& pos)