From fc8ee51e7292184b3a88f5791ce817b70a666b11 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 13 Nov 2016 22:08:40 +0100 Subject: [PATCH] Do not draw shadows on a linux console if not all characters are available --- ChangeLog | 4 +++ src/fbutton.cpp | 33 ++++---------------- src/ffiledialog.cpp | 2 +- src/flineedit.cpp | 40 +++--------------------- src/fprogressbar.cpp | 48 ++--------------------------- src/fstatusbar.cpp | 10 ++++-- src/fterm.cpp | 71 +++++++++++++++++++++++++++++-------------- src/fterm.h | 2 ++ src/fwidget.cpp | 11 +++++-- test/input-dialog.cpp | 12 ++++---- test/ui.cpp | 2 +- 11 files changed, 91 insertions(+), 144 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac01de7c..46d762d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-11-13 Markus Gans + * Do not draw shadows on a linux console if not + all characters are available + 2016-11-12 Markus Gans * Better support for Linux terminals with 8 colors * Optimized input cursor positioning for terminals without hidden cursor diff --git a/src/fbutton.cpp b/src/fbutton.cpp index cf0c5064..96da464e 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -596,41 +596,20 @@ void FButton::draw() if ( isMonochron() && (is_Active || is_Focus) ) setReverse(false); - if ( is_Flat ) + if ( margin == 1 ) { - if ( margin == 1 ) - { - setColor (getForegroundColor(), button_bg); - - for (int y=0; y < getHeight(); y++) - { - setPrintPos (1+d, 1+y); - print (space); // full block █ - } - } - - if ( ! button_down ) - drawFlatBorder(); - } - else if ( ! isMonochron() ) - { - if ( parent_widget ) - setColor (button_bg, parent_widget->getBackgroundColor()); + setColor (getForegroundColor(), button_bg); for (int y=0; y < getHeight(); y++) { setPrintPos (1+d, 1+y); - - // Cygwin terminal use IBM Codepage 850 - if ( isCygwinTerminal() ) - print (fc::FullBlock); // █ - else if ( isTeraTerm() ) - print (0xdb); - else - print (fc::RightHalfBlock); // ▐ + print (space); // full block █ } } + if ( is_Flat && ! button_down ) + drawFlatBorder(); + if ( ! button_down && ! isNewFont() && (is_Flat || ! hasShadow() || isMonochron()) ) diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index aab1682f..134536cc 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -489,7 +489,7 @@ void FFileDialog::init() FDialog::setText("Open file"); filename = new FLineEdit(this); - filename->setLabelText("File&name:"); + filename->setLabelText("File&name"); filename->setText(filter_pattern); filename->setGeometry(11, 1, 28, 1); filename->setFocus(); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 03ff1d0b..2da94386 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -664,7 +664,7 @@ void FLineEdit::adjustLabel() break; case label_left: - label->setGeometry(getX()-label_length, getY(), label_length, 1); + label->setGeometry(getX()-label_length-1, getY(), label_length, 1); break; } } @@ -742,12 +742,11 @@ void FLineEdit::draw() //---------------------------------------------------------------------- void FLineEdit::drawInputField() { - bool isActiveFocus, isActive, isShadow; + bool isActiveFocus, isShadow; int x; FString show_text; int active_focus = fc::active + fc::focus; isActiveFocus = ((flags & active_focus) == active_focus); - isActive = ((flags & fc::active) != 0); isShadow = ((flags & fc::shadow) != 0 ); updateVTerm(false); @@ -763,44 +762,15 @@ void FLineEdit::drawInputField() else setUnderline(true); } - else if ( isActiveFocus ) + else { - setColor (wc.inputfield_active_focus_bg, wc.dialog_bg); - - if ( isCygwinTerminal() ) // IBM Codepage 850 - print (fc::FullBlock); // █ - else if ( isTeraTerm() ) - print (0xdb); - else - print (fc::RightHalfBlock); // ▐ - } - else if ( isActive ) - { - setColor (wc.inputfield_active_bg, wc.dialog_bg); - - if ( isCygwinTerminal() ) // IBM Codepage 850 - print (fc::FullBlock); // █ - else if ( isTeraTerm() ) - print (0xdb); - else - print (fc::RightHalfBlock); // ▐ - } - else // isInactive - { - setColor (wc.inputfield_inactive_bg, wc.dialog_bg); - - if ( isCygwinTerminal() ) // IBM Codepage 850 - print (fc::FullBlock); // █ - else if ( isTeraTerm() ) - print (0xdb); - else - print (fc::RightHalfBlock); // ▐ + setColor(); + print (' '); } if ( isActiveFocus && getMaxColor() < 16 ) setBold(); - setColor(); show_text = text.mid(uInt(1+text_offset), uInt(getWidth()-2)); if ( isUTF8_linux_terminal() ) diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index a0211b6f..1a001195 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -185,53 +185,9 @@ void FProgressbar::drawPercentage() //---------------------------------------------------------------------- void FProgressbar::drawBar() { - int i = 1; + int i = 0; float length = float(bar_length * percentage) / 100; setPrintPos (1,1); - - if ( isMonochron() ) - { - if ( round(length) >= 1) - { - setReverse(false); - print (' '); - setReverse(true); - } - else - print (fc::MediumShade); // ▒ - } - else if ( getMaxColor() < 16 ) - { - setColor ( wc.progressbar_bg - , wc.progressbar_fg ); - - if ( round(length) >= 1) - print (' '); - else - print (fc::MediumShade); - } - - if ( getParentWidget() ) - { - if ( round(length) >= 1) - setColor ( wc.progressbar_fg - , getParentWidget()->getBackgroundColor() ); - else - setColor ( wc.progressbar_bg - , getParentWidget()->getBackgroundColor() ); - } - - if ( ! isMonochron() && getMaxColor() >= 16 ) - { - // Cygwin terminal use IBM Codepage 850 - if ( isCygwinTerminal() ) - print (fc::FullBlock); // █ - else if ( isTeraTerm() ) - print (0xdb); - else - print (fc::RightHalfBlock); // ▐ - } - setColor ( wc.progressbar_bg , wc.progressbar_fg ); @@ -244,7 +200,7 @@ void FProgressbar::drawBar() if ( isMonochron() ) setReverse(true); - if ( trunc(length) >= 1 && trunc(length) < bar_length ) + if ( percentage > 0.0f && trunc(length) < bar_length ) { if ( round(length) > trunc(length) || isCygwinTerminal() diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 22ef61c4..95cd69a8 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -687,9 +687,15 @@ void FStatusBar::drawKeys() if ( isMonochron() ) setReverse(false); - setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); + if ( no_half_block_character ) + print (' '); + else + { + setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); + print (fc::LeftHalfBlock); // ▐ + } + x++; - print (fc::LeftHalfBlock); // ▐ if ( isMonochron() ) setReverse(true); diff --git a/src/fterm.cpp b/src/fterm.cpp index e6b3097d..26fb61e4 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -58,6 +58,8 @@ bool FTerm::vt100_console; bool FTerm::ascii_console; bool FTerm::NewFont; bool FTerm::VGAFont; +bool FTerm::no_shadow_character; +bool FTerm::no_half_block_character; bool FTerm::cursor_optimisation; bool FTerm::xterm_default_colors; termios FTerm::term_init; @@ -1482,6 +1484,8 @@ int FTerm::UTF8decode(char* utf8) //---------------------------------------------------------------------- void FTerm::init_consoleCharMap() { + uInt c1, c2, c3, c4, c5; + if ( NewFont || VGAFont ) return; @@ -1504,6 +1508,26 @@ void FTerm::init_consoleCharMap() character[i][fc::PC] = character[i][fc::ASCII]; } } + + c1 = fc::UpperHalfBlock; + c2 = fc::LowerHalfBlock; + c3 = fc::FullBlock; + + if ( charEncode(c1, fc::PC) == charEncode(c1, fc::ASCII) + || charEncode(c2, fc::PC) == charEncode(c2, fc::ASCII) + || charEncode(c3, fc::PC) == charEncode(c3, fc::ASCII) ) + { + no_shadow_character = true; + } + + c4 = fc::RightHalfBlock; + c5 = fc::LeftHalfBlock; + + if ( charEncode(c4, fc::PC) == charEncode(c4, fc::ASCII) + || charEncode(c5, fc::PC) == charEncode(c5, fc::ASCII) ) + { + no_half_block_character = true; + } } //---------------------------------------------------------------------- @@ -2948,29 +2972,30 @@ void FTerm::init() (*encoding_set)["ASCII"] = fc::ASCII; // Preset to false - utf8_console = \ - utf8_input = \ - utf8_state = \ - utf8_linux_terminal = \ - pc_charset_console = \ - vt100_console = \ - NewFont = \ - VGAFont = \ - ascii_console = \ - mouse_support = \ - - force_vt100 = \ - tera_terminal = \ - kterm_terminal = \ - gnome_terminal = \ - kde_konsole = \ - rxvt_terminal = \ - urxvt_terminal = \ - mlterm_terminal = \ - mintty_terminal = \ - screen_terminal = \ - tmux_terminal = \ - xterm_default_colors = false; + utf8_console = \ + utf8_input = \ + utf8_state = \ + utf8_linux_terminal = \ + pc_charset_console = \ + vt100_console = \ + NewFont = \ + VGAFont = \ + no_shadow_character = \ + no_half_block_character = \ + ascii_console = \ + mouse_support = \ + force_vt100 = \ + tera_terminal = \ + kterm_terminal = \ + gnome_terminal = \ + kde_konsole = \ + rxvt_terminal = \ + urxvt_terminal = \ + mlterm_terminal = \ + mintty_terminal = \ + screen_terminal = \ + tmux_terminal = \ + xterm_default_colors = false; // Preset to true cursor_optimisation = \ diff --git a/src/fterm.h b/src/fterm.h index dfccc306..1e7f32bc 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -250,6 +250,8 @@ class FTerm static int stdout_no; static bool NewFont; static bool VGAFont; + static bool no_shadow_character; + static bool no_half_block_character; static bool cursor_optimisation; static bool xterm_default_colors; static fc::encoding Encoding; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index d102bfaf..22341bd4 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1092,13 +1092,15 @@ void FWidget::show() if ( ! visible ) return; - // Important: Do not use setNewFont() or setVGAFont() after - // the console character mapping has been initialized if ( getMainWidget() == this ) { + // Important: Do not use setNewFont() or setVGAFont() after + // the console character mapping has been initialized init_consoleCharMap(); + // set xterm underline cursor setXTermCursorStyle(fc::blinking_underline); + // set xterm color settings to defaults setXTermDefaults(); } @@ -1326,6 +1328,10 @@ void FWidget::drawShadow() { // non-transparent shadow int block; + + if ( no_shadow_character ) + return; + setPrintPos (x2+1, y1); if ( isWindowWidget() ) @@ -1336,7 +1342,6 @@ void FWidget::drawShadow() else if ( FWidget* p = getParentWidget() ) setColor (wc.shadow_fg, p->getBackgroundColor()); - if ( isTeraTerm() ) { block = 0xdb; // █ diff --git a/test/input-dialog.cpp b/test/input-dialog.cpp index d70977c8..1301d99c 100644 --- a/test/input-dialog.cpp +++ b/test/input-dialog.cpp @@ -58,12 +58,12 @@ int main (int argc, char* argv[]) FLineEdit* st_field = new FLineEdit(&dgl); FLineEdit* c_field = new FLineEdit(&dgl); - name_field->setLabelText(L"&Name:"); - email_field->setLabelText(L"&Email:"); - org_field->setLabelText(L"Or&ganization:"); - city_field->setLabelText(L"&City:"); - st_field->setLabelText(L"&State:"); - c_field->setLabelText(L"&Country:"); + name_field->setLabelText(L"&Name"); + email_field->setLabelText(L"&Email"); + org_field->setLabelText(L"Or&ganization"); + city_field->setLabelText(L"&City"); + st_field->setLabelText(L"&State"); + c_field->setLabelText(L"&Country"); name_field->setGeometry(15, 1, 19, 1); email_field->setGeometry(15, 3, 19, 1); diff --git a/test/ui.cpp b/test/ui.cpp index 8dce781e..cf7922b2 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -467,7 +467,7 @@ MyDialog::MyDialog (FWidget* parent) myLineEdit = new FLineEdit (this); myLineEdit->setGeometry(22, 1, 10, 1); myLineEdit->setText (FString("EnTry").toLower()); - myLineEdit->setLabelText (L"&Input:"); + myLineEdit->setLabelText (L"&Input"); myLineEdit->setStatusbarMessage ("Press Enter to set the title"); // Buttons