From 26e9f75242d0e1b9fdd3b941f96146e92b146121 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 24 Sep 2015 00:41:43 +0200 Subject: [PATCH] Further code optimizations --- ChangeLog | 3 ++ build.sh | 2 +- finalcut.spec | 2 +- src/fapp.cpp | 10 +++-- src/fbutton.cpp | 6 +-- src/fdialog.cpp | 6 +-- src/flineedit.cpp | 12 ++--- src/flistbox.cpp | 106 ++++++++++++++++++++++---------------------- src/fmessagebox.cpp | 4 +- src/fscrollbar.cpp | 2 +- src/fstatusbar.cpp | 2 +- src/fterm.cpp | 67 +++++++++++++++++----------- src/ftextview.cpp | 73 ++++++++++++++++-------------- src/fwidget.cpp | 6 +-- test/mandelbrot.cpp | 2 +- 15 files changed, 164 insertions(+), 139 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7de6d2f..d9b3c8de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-09-22 Markus Gans + * Further code optimizations + 2015-09-22 Markus Gans * Add the possibility to hide a virtual window * Some code optimizations diff --git a/build.sh b/build.sh index ac279474..3a42f50a 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ PREFIX="/usr" case "$1" in "--help"|"help") - echo "Usage: $0 {help|debug|profile|gcov|release}" + echo "Usage: $0 {help|debug|fulldebug|profile|gcov|release}" exit 1 ;; "--debug"|"debug") diff --git a/finalcut.spec b/finalcut.spec index 1ed9e03e..0b8ed127 100644 --- a/finalcut.spec +++ b/finalcut.spec @@ -137,6 +137,6 @@ rm -rf $RPM_BUILD_ROOT %{_libdir}/%{libname}.a %changelog -* Mon Sep 18 2015 Markus Gans - 0.1.1-1 +* Fri Sep 18 2015 Markus Gans - 0.1.1-1 - Initial Release (version 0.1.1) diff --git a/src/fapp.cpp b/src/fapp.cpp index b9b7cb9b..cbcd675b 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -115,10 +115,14 @@ void FApplication::cmd_options () {0, 0, 0, 0 } }; opterr = 0; - c = getopt_long ( app_argc, app_argv, "" - , long_options, &idx ); + c = getopt_long ( app_argc + , app_argv + , "" + , long_options + , &idx ); if ( c == -1 ) break; + if ( c == 0 ) { if ( strcmp(long_options[idx].name, "encoding") == 0 ) @@ -256,7 +260,7 @@ void FApplication::processKeyboardEvent() while ( (bytesread = readKey()) > 0 ) { - if ( bytesread+fifo_offset-1 < fifo_buf_size ) + if ( bytesread + fifo_offset <= fifo_buf_size ) { for (int i=0; i < bytesread; i++) { diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 143a086b..0ca69106 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -212,7 +212,7 @@ void FButton::draw() if ( margin == 1 ) { setColor (foregroundColor, button_bg); - for (int y=0; y <= height-1; y++) + for (int y=0; y < height; y++) { gotoxy (xpos+xmin-1+d, ypos+ymin-1+y); print (space); // full block █ @@ -310,13 +310,13 @@ void FButton::draw() for (i=0; i < j; i++) { gotoxy (xpos+xmin+d, ypos+ymin-1+i); - for (int z=1; z <= width-1; z++) + for (int z=1; z < width; z++) print (space); // █ } for (i=j+1; i < height; i++) { gotoxy (xpos+xmin+d, ypos+ymin-1+i); - for (int z=1; z <= width-1; z++) + for (int z=1; z < width; z++) print (space); // █ } } diff --git a/src/fdialog.cpp b/src/fdialog.cpp index f115ec1c..3c443cf5 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -226,7 +226,7 @@ void FDialog::drawTitleBar() print (tb_text); // fill the rest of the bar - for (; x+1+int(length) <= width-2; x++) + for (; x+1+int(length) < width-1; x++) print (' '); if ( isMonochron() ) @@ -495,8 +495,8 @@ void FDialog::onMouseUp (FMouseEvent* ev) if ( ev->getButton() == LeftButton ) { if ( ! TitleBarClickPos.isNull() - && titlebar_x >= xpos+xmin+3 - && titlebar_x <= xpos+xmin-1+width + && titlebar_x > xpos+xmin+2 + && titlebar_x < xpos+xmin+width && titlebar_y == ypos+ymin-1 ) { FPoint currentPos(getGeometry().getX(), getGeometry().getY()); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index ea8e833d..3b3398b8 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -178,7 +178,7 @@ void FLineEdit::drawInputField() print (show_text); x = int(show_text.getLength()); - while ( x <= width-2 ) + while ( x < width-1 ) { print (' '); x++; @@ -397,7 +397,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) cursor_pos++; if ( cursor_pos >= len ) cursor_pos=len; - if ( cursor_pos-offset >= width-2 && offset < len-width+2 ) + if ( cursor_pos-offset >= width-2 && offset <= len-width+1 ) offset++; ev->accept(); break; @@ -410,7 +410,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) case fc::Fkey_end: cursor_pos=len; - if ( cursor_pos > width-2 ) + if ( cursor_pos >= width-1 ) offset=len-width+2; ev->accept(); break; @@ -425,7 +425,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) cursor_pos=len; if ( cursor_pos < 0 ) cursor_pos=0; - if ( offset > 0 && len-offset <= width-2 ) + if ( offset > 0 && len-offset < width-1 ) offset--; ev->accept(); break; @@ -496,7 +496,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) processChanged(); } cursor_pos++; - if ( cursor_pos > width-2 ) + if ( cursor_pos >= width-1 ) offset++; ev->accept(); } @@ -601,7 +601,7 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) else if ( mouse_x >= width ) { // drag right - if ( ! scrollTimer && offset < len-width+2 ) + if ( ! scrollTimer && offset <= len-width+1 ) { scrollTimer = true; addTimer(scrollRepeat); diff --git a/src/flistbox.cpp b/src/flistbox.cpp index ed35690f..a8b9a901 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -231,8 +231,8 @@ void FListBox::drawList() && last_current != current ) { // speed up: redraw only the changed rows - uInt last_pos = uInt(current)-uInt(yoffset)-1; - uInt current_pos = uInt(last_current)-uInt(yoffset)-1; + uInt last_pos = uInt(current - yoffset) - 1; + uInt current_pos = uInt(last_current - yoffset) - 1; start = std::min(last_pos, current_pos); end = std::max(last_pos, current_pos)+1; } @@ -242,9 +242,9 @@ void FListBox::drawList() { gotoxy (xpos+xmin, ypos+ymin+int(y)); bool serach_mark = false; - bool lineHasBrackets = hasBrackets(int(y)+yoffset+1); - bool isLineSelected = isSelected(int(y)+yoffset+1); - bool isCurrentLine = bool(uInt(y)+uInt(yoffset)+1 == uInt(current)); + bool lineHasBrackets = hasBrackets(int(y) + yoffset + 1); + bool isLineSelected = isSelected(int(y) + yoffset + 1); + bool isCurrentLine = bool(uInt(y) + uInt(yoffset) + 1 == uInt(current)); if ( isLineSelected ) { @@ -462,7 +462,7 @@ void FListBox::adjustYOffset() yoffset = 0; if ( current < yoffset ) current = yoffset; - if ( current > yoffset+height-2 ) + if ( current >= yoffset + height - 1 ) yoffset = current - height + 2; } @@ -475,24 +475,24 @@ void FListBox::adjustSize() FWidget::adjustSize(); element_count = int(count()); - VBar->setMaximum(element_count-height+2); - VBar->setPageSize(element_count, height-2); + VBar->setMaximum(element_count - height + 2); + VBar->setPageSize(element_count, height - 2); VBar->setX(width); VBar->setHeight (height-2, false); VBar->resize(); - HBar->setMaximum(maxLineWidth-width+nf_offset+4); - HBar->setPageSize(maxLineWidth, width-nf_offset-4); + HBar->setMaximum(maxLineWidth - width + nf_offset + 4); + HBar->setPageSize(maxLineWidth, width - nf_offset - 4); HBar->setY(height); HBar->setWidth (width-2, false); HBar->resize(); - if ( element_count <= height-2 ) + if ( element_count < height - 1 ) VBar->hide(); else VBar->setVisible(); - if ( maxLineWidth <= width-nf_offset-4 ) + if ( maxLineWidth < width - nf_offset - 3 ) HBar->hide(); else HBar->setVisible(); @@ -560,10 +560,10 @@ void FListBox::showInsideBrackets ( int index if ( len > maxLineWidth ) { maxLineWidth = len; - if ( len > width-nf_offset-4 ) + if ( len >= width - nf_offset - 3 ) { - HBar->setMaximum(maxLineWidth-width+nf_offset+4); - HBar->setPageSize(maxLineWidth, width-nf_offset-4); + HBar->setMaximum(maxLineWidth - width + nf_offset + 4); + HBar->setPageSize(maxLineWidth, width - nf_offset - 4); HBar->setValue (xoffset); if ( ! HBar->isVisible() ) HBar->setVisible(); @@ -669,7 +669,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) current++; if ( current > element_count ) current = element_count; - if ( current-yoffset > height - 2 ) + if ( current - yoffset >= height - 1 ) yoffset++; inc_search.clear(); ev->accept(); @@ -685,8 +685,8 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_right: xoffset++; - if ( xoffset > maxLineWidth-width+nf_offset+4 ) - xoffset = maxLineWidth-width+nf_offset+4; + if ( xoffset > maxLineWidth - width + nf_offset + 4 ) + xoffset = maxLineWidth - width + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; inc_search.clear(); @@ -711,7 +711,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) current += height-3; if ( current > element_count ) current = element_count; - if ( current-yoffset > height-2 ) + if ( current - yoffset >= height - 1 ) { yoffset += height-3; if ( yoffset > element_count - height + 2 ) @@ -730,7 +730,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_end: current = element_count; - if ( current > height - 2 ) + if ( current >= height - 1 ) yoffset = element_count - height + 2; inc_search.clear(); ev->accept(); @@ -747,7 +747,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) current++; if ( current > element_count ) current = element_count; - if ( current-yoffset > height - 2 ) + if ( current-yoffset >= height - 1 ) yoffset++; ev->accept(); } @@ -919,8 +919,8 @@ void FListBox::onMouseDown (FMouseEvent* ev) yoffset_before = yoffset; mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width-1 - && mouse_y >= 2 && mouse_y <= height-1 ) + if ( mouse_x > 1 && mouse_x < width + && mouse_y > 1 && mouse_y < height ) { current = yoffset + mouse_y - 1; if ( current > int(count()) ) @@ -970,8 +970,8 @@ void FListBox::onMouseUp (FMouseEvent* ev) { int mouse_x = ev->getX(); int mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width-1 - && mouse_y >= 2 && mouse_y <= height-1 ) + if ( mouse_x > 1 && mouse_x < width + && mouse_y > 1 && mouse_y < height ) { processChanged(); if ( ! isMultiSelection() ) @@ -998,8 +998,8 @@ void FListBox::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width-1 - && mouse_y >= 2 && mouse_y <= height-1 ) + if ( mouse_x > 1 && mouse_x < width + && mouse_y > 1 && mouse_y < height ) { current = yoffset + mouse_y - 1; if ( current > int(count()) ) @@ -1110,8 +1110,8 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width-1 - && mouse_y >= 2 && mouse_y <= height-1 ) + if ( mouse_x > 1 && mouse_x < width + && mouse_y > 1 && mouse_y < height ) { if ( yoffset + mouse_y - 1 > int(count()) ) return; @@ -1157,7 +1157,7 @@ void FListBox::onTimer (FTimerEvent*) current += scrollDistance; if ( current > element_count ) current = element_count; - if ( current-yoffset > height - 2 ) + if ( current - yoffset >= height - 1 ) yoffset += scrollDistance; if ( yoffset > element_count - height + 2 ) yoffset = element_count - height + 2; @@ -1257,7 +1257,7 @@ void FListBox::onWheel (FWheelEvent* ev) yoffset += 4; if ( yoffset > yoffset_end ) { - current += 4 - (yoffset-yoffset_end); + current += 4 - (yoffset - yoffset_end); yoffset = yoffset_end; } else @@ -1336,7 +1336,7 @@ void FListBox::cb_VBarChange (FWidget*, void*) current += distance; if ( current > element_count ) current = element_count; - if ( current-yoffset > height - 2 ) + if ( current - yoffset >= height - 1 ) yoffset += distance; if ( yoffset > element_count - height + 2 ) yoffset = element_count - height + 2; @@ -1398,13 +1398,13 @@ void FListBox::cb_HBarChange (FWidget*, void*) { int distance = 1; int xoffset_before = xoffset; - int xoffset_end = maxLineWidth-width+nf_offset+4; + int xoffset_end = maxLineWidth - width + nf_offset + 4; int scrollType = HBar->getScrollType(); switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = width-nf_offset-4; + distance = width - nf_offset - 4; case FScrollbar::scrollStepBackward: xoffset -= distance; if ( xoffset < 0 ) @@ -1412,11 +1412,11 @@ void FListBox::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = width-nf_offset-4; + distance = width - nf_offset - 4; case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > maxLineWidth-width+nf_offset+4 ) - xoffset = maxLineWidth-width+nf_offset+4; + if ( xoffset > maxLineWidth - width + nf_offset + 4 ) + xoffset = maxLineWidth - width + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; break; @@ -1427,8 +1427,8 @@ void FListBox::cb_HBarChange (FWidget*, void*) if ( xoffset == val ) break; xoffset = val; - if ( xoffset > maxLineWidth-width+nf_offset+4 ) - xoffset = maxLineWidth-width+nf_offset+4; + if ( xoffset > maxLineWidth - width + nf_offset + 4 ) + xoffset = maxLineWidth - width + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; break; @@ -1486,10 +1486,10 @@ void FListBox::insert ( FString item if ( len > maxLineWidth ) { maxLineWidth = len; - if ( len > width-nf_offset-4 ) + if ( len >= width - nf_offset - 3 ) { - HBar->setMaximum(maxLineWidth-width+nf_offset+4); - HBar->setPageSize(maxLineWidth, width-nf_offset-4); + HBar->setMaximum(maxLineWidth - width + nf_offset + 4); + HBar->setPageSize(maxLineWidth, width - nf_offset - 4); HBar->calculateSliderValues(); if ( ! HBar->isVisible() ) HBar->setVisible(); @@ -1498,13 +1498,13 @@ void FListBox::insert ( FString item FListBoxItem listItem (item); listItem.brackets = b; listItem.selected = s; - data.push_back ( listItem ); + data.push_back (listItem); element_count = int(count()); - VBar->setMaximum(element_count-height+2); - VBar->setPageSize(element_count, height-2); + VBar->setMaximum(element_count - height + 2); + VBar->setPageSize(element_count, height - 2); VBar->calculateSliderValues(); - if ( ! VBar->isVisible() && element_count > height-2 ) + if ( ! VBar->isVisible() && element_count >= height - 1 ) VBar->setVisible(); } @@ -1524,7 +1524,7 @@ void FListBox::remove (int item) if ( int(count()) < item ) return; - data.erase (data.begin()+item-1); + data.erase (data.begin() + item - 1); element_count = int(count()); maxLineWidth = 0; @@ -1535,14 +1535,14 @@ void FListBox::remove (int item) if ( len > maxLineWidth ) maxLineWidth = len; } - HBar->setMaximum(maxLineWidth-width+nf_offset+4); - HBar->setPageSize(maxLineWidth, width-nf_offset-4); - if ( HBar->isVisible() && maxLineWidth <= width-nf_offset-4 ) + HBar->setMaximum(maxLineWidth - width + nf_offset + 4); + HBar->setPageSize(maxLineWidth, width - nf_offset - 4); + if ( HBar->isVisible() && maxLineWidth < width - nf_offset - 3 ) HBar->hide(); - VBar->setMaximum(element_count-height+2); - VBar->setPageSize(element_count, height-2); - if ( VBar->isVisible() && element_count <= height-2 ) + VBar->setMaximum(element_count - height + 2); + VBar->setPageSize(element_count, height - 2); + if ( VBar->isVisible() && element_count < height - 1 ) VBar->hide(); if ( current >= item && current > 1 ) diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 80104a3d..1375a02f 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -293,11 +293,11 @@ void FMessageBox::adjustButtons() btn_width += button[n]->getWidth() + gap; } - if ( btn_width > width-5 ) + if ( btn_width >= width-4 ) { setWidth(btn_width + 5); int max_width = getRootWidget()->getClientWidth(); - setX(int((max_width-width)/2)); + setX(int((max_width-width) / 2)); } int btn_x = int((width-btn_width) / 2); diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index 52be0601..98c59438 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -389,7 +389,7 @@ void FScrollbar::onTimer (FTimerEvent*) if ( ( scrollType == scrollPageBackward && SliderPos < SliderClickStopPos ) || ( scrollType == scrollPageForward - && SliderPos+SliderLength-1 >= SliderClickStopPos ) ) + && SliderPos+SliderLength > SliderClickStopPos ) ) { delAllTimer(); return; diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index ebfcaa41..de4d4447 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -608,7 +608,7 @@ void FStatusBar::drawMessage() } } } - for (int i=x; i < termWidth+1; i++) + for (int i=x; i <= termWidth; i++) print (vstatusbar, ' '); if ( isMonochron() ) setReverse(false); diff --git a/src/fterm.cpp b/src/fterm.cpp index 591d1bac..625ea3c3 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -821,10 +821,10 @@ int FTerm::parseKeyString ( char* buffer key = uChar(buffer[0] & 0xff); n = len; - for (; n < buf_size; n++) - buffer[n-len] = buffer[n]; // remove the key - for (; n-len < len; n++) - buffer[n-len] = '\0'; + for (; n < buf_size; n++) // remove the key from the buffer front + buffer[n-len] = buffer[n]; + for (n=n-len; n < buf_size; n++) // fill the rest with '\0' bytes + buffer[n] = '\0'; return int(key == 127 ? fc::Fkey_backspace : key); } @@ -1888,9 +1888,9 @@ void FTerm::updateVTerm (FTerm::term_area* area) if ( ax == 0 ) line_xmin = ol; - if ( ax + line_xmin + 1 > vterm->width ) + if ( ax + line_xmin >= vterm->width ) continue; - if ( aw + rsh + ax - ol > vterm->width - 1 ) + if ( aw + rsh + ax - ol >= vterm->width ) line_xmax = vterm->width + ol - ax - 1; for (register int x=line_xmin; x <= line_xmax; x++) { @@ -2397,19 +2397,23 @@ void FTerm::resizeVTerm() { char_data default_char; line_changes unchanged; - int vterm_size = term->getWidth() * term->getHeight(); + int term_width, term_height, vterm_size; - if ( vterm->height != term->getHeight() ) + term_width = term->getWidth(); + term_height = term->getHeight(); + vterm_size = term_width * term_height; + + if ( vterm->height != term_height ) { if ( vterm->changes != 0 ) delete[] vterm->changes; if ( vterm->text != 0 ) delete[] vterm->text; - vterm->changes = new line_changes[term->getHeight()]; + vterm->changes = new line_changes[term_height]; vterm->text = new char_data[vterm_size]; } - else if ( vterm->width != term->getWidth() ) + else if ( vterm->width != term_width ) { if ( vterm->text != 0 ) delete[] vterm->text; @@ -2418,8 +2422,8 @@ void FTerm::resizeVTerm() else return; - vterm->width = term->getWidth(); - vterm->height = term->getHeight(); + vterm->width = term_width; + vterm->height = term_height; default_char.code = ' '; default_char.fg_color = fc::LightGray; @@ -2429,9 +2433,9 @@ void FTerm::resizeVTerm() default_char.underline = 0; std::fill_n (vterm->text, vterm_size, default_char); - unchanged.xmin = uInt(term->getWidth()); + unchanged.xmin = uInt(term_width); unchanged.xmax = 0; - std::fill_n (vterm->changes, term->getHeight(), unchanged); + std::fill_n (vterm->changes, term_height, unchanged); } //---------------------------------------------------------------------- @@ -2451,6 +2455,7 @@ void FTerm::updateTerminal() term_area* vt; FWidget* focus_widget; FApplication* fapp; + int term_width, term_height; if ( static_cast(term_object)->isQuit() ) return; @@ -2459,6 +2464,8 @@ void FTerm::updateTerminal() return; vt = vterm; + term_width = term->getWidth(); + term_height = term->getHeight(); for (register uInt y=0; y < uInt(vt->height); y++) { @@ -2475,8 +2482,8 @@ void FTerm::updateTerminal() char_data* print_char; print_char = &vt->text[y * uInt(vt->width) + x]; - if ( x_term_pos == term->getWidth() - 1 - && y_term_pos == term->getHeight() - 1 ) + if ( x_term_pos == term_width - 1 + && y_term_pos == term_height - 1 ) appendLowerRight (print_char); else appendCharacter (print_char); @@ -2487,9 +2494,9 @@ void FTerm::updateTerminal() vt->changes[y].xmax = 0; } // cursor wrap - if ( x_term_pos >= term->getWidth() ) + if ( x_term_pos >= term_width ) { - if ( y_term_pos == term->getHeight()-1 ) + if ( y_term_pos == term_height - 1 ) x_term_pos--; else { @@ -2993,22 +3000,26 @@ bool FTerm::gpmMouse (bool on) //---------------------------------------------------------------------- void FTerm::setTermXY (register int x, register int y) { + int term_width, term_height; char* move_str; if ( x_term_pos == x && y_term_pos == y ) return; - if ( x >= term->getWidth() ) + term_width = term->getWidth(); + term_height = term->getHeight(); + + if ( x >= term_width ) { - y += x / term->getWidth(); - x %= term->getWidth(); + y += x / term_width; + x %= term_width; } - if ( y_term_pos > term->getHeight()-1 ) - y_term_pos = term->getHeight() - 1; + if ( y_term_pos >= term_height ) + y_term_pos = term_height - 1; - if ( y > term->getHeight()-1 ) - y = term->getHeight() - 1; + if ( y >= term_height ) + y = term_height - 1; move_str = opti->cursor_move (x_term_pos, y_term_pos, x, y); if ( move_str ) @@ -3841,11 +3852,13 @@ int FTerm::appendLowerRight (char_data*& screen_char) } else { - setTermXY (term->getWidth()-2, term->getHeight()-1); + int x = term->getWidth() - 2; + int y = term->getHeight() - 1; + setTermXY (x, y); appendCharacter (screen_char); x_term_pos++; - setTermXY (term->getWidth()-2, term->getHeight()-1); + setTermXY (x, y); screen_char--; if ( tcap[t_parm_ich].string ) diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 6afff4a1..eaea0aa5 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -73,12 +73,12 @@ void FTextView::draw() setColor (foregroundColor, backgroundColor); if ( ! isNewFont() ) drawBorder(); - setUpdateVTerm(true); if ( VBar->isVisible() ) VBar->redraw(); if ( HBar->isVisible() ) HBar->redraw(); + setUpdateVTerm(true); drawText(); @@ -88,10 +88,14 @@ void FTextView::draw() FString curMsg = statusBar()->getMessage(); if ( curMsg != msg ) { + setUpdateVTerm(false); statusBar()->setMessage(msg); statusBar()->drawMessage(); + setUpdateVTerm(true); } } + updateTerminal(); + flush_out(); } //---------------------------------------------------------------------- @@ -112,8 +116,8 @@ void FTextView::drawText() { gotoxy (xpos+xmin, ypos+ymin-nf_offset+int(y)); uInt i; - FString line = data[y+uInt(yoffset)].mid ( uInt(1+xoffset) - , uInt(width-nf_offset-2) ); + FString line = data[y+uInt(yoffset)].mid ( uInt(1 + xoffset) + , uInt(width - nf_offset - 2) ); const wchar_t* line_str = line.wc_str(); uInt len = line.getLength(); @@ -122,7 +126,7 @@ void FTextView::drawText() print (line_str[i]); else print ('.'); - for (; i < uInt(width-nf_offset-2); i++) + for (; i < uInt(width - nf_offset - 2); i++) print (' '); } setUpdateVTerm(true); @@ -140,24 +144,24 @@ void FTextView::adjustSize() { FWidget::adjustSize(); - VBar->setMaximum(int(getRows())-height+2-nf_offset); - VBar->setPageSize(int(getRows()), height-2+nf_offset); - VBar->setX(width); - VBar->setHeight (height-2+nf_offset, false); + VBar->setMaximum (int(getRows()) - height + 2 - nf_offset); + VBar->setPageSize (int(getRows()), height - 2 + nf_offset); + VBar->setX (width); + VBar->setHeight (height - 2 + nf_offset, false); VBar->resize(); - HBar->setMaximum(int(maxLineWidth)-width+nf_offset+2); - HBar->setPageSize(int(maxLineWidth), width-nf_offset-2); - HBar->setY(height); - HBar->setWidth (width-2, false); + HBar->setMaximum (int(maxLineWidth) - width + nf_offset + 2); + HBar->setPageSize (int(maxLineWidth), width - nf_offset - 2); + HBar->setY (height); + HBar->setWidth (width - 2, false); HBar->resize(); - if ( int(getRows()) <= height+nf_offset-2 ) + if ( int(getRows()) < height + nf_offset - 1 ) VBar->hide(); else VBar->setVisible(); - if ( int(maxLineWidth) <= width-nf_offset-2 ) + if ( int(maxLineWidth) < width-nf_offset - 1 ) HBar->hide(); else HBar->setVisible(); @@ -207,13 +211,13 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_down: - if ( yoffset+height+nf_offset-2 < last_line ) + if ( yoffset + height + nf_offset <= last_line + 1 ) yoffset++; ev->accept(); break; case fc::Fkey_right: - if ( xoffset+width-nf_offset-2 < int(maxLineWidth) ) + if ( xoffset + width - nf_offset <= int(maxLineWidth) + 1 ) xoffset++; ev->accept(); break; @@ -268,6 +272,7 @@ void FTextView::onKeyPress (FKeyEvent* ev) if ( HBar->isVisible() ) HBar->drawBar(); updateTerminal(); + flush_out(); } } @@ -430,13 +435,13 @@ void FTextView::cb_HBarChange (FWidget*, void*) { int distance = 1; int xoffset_before = xoffset; - int xoffset_end = int(maxLineWidth)-width+nf_offset+4; + int xoffset_end = int(maxLineWidth) - width + nf_offset + 4; int scrollType = HBar->getScrollType(); switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = width-nf_offset-4; + distance = width - nf_offset - 4; case FScrollbar::scrollStepBackward: xoffset -= distance; if ( xoffset < 0 ) @@ -444,11 +449,11 @@ void FTextView::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = width-nf_offset-4; + distance = width - nf_offset - 4; case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > int(maxLineWidth)-width+nf_offset+4 ) - xoffset = int(maxLineWidth)-width+nf_offset+4; + if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 ) + xoffset = int(maxLineWidth) - width + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; break; @@ -459,8 +464,8 @@ void FTextView::cb_HBarChange (FWidget*, void*) if ( xoffset == val ) break; xoffset = val; - if ( xoffset > int(maxLineWidth)-width+nf_offset+4 ) - xoffset = int(maxLineWidth)-width+nf_offset+4; + if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 ) + xoffset = int(maxLineWidth) - width + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; break; @@ -509,13 +514,13 @@ void FTextView::setGeometry (int x, int y, int w, int h, bool adjust) if ( isNewFont() ) { - VBar->setGeometry(width, 1, 2, height-1); - HBar->setGeometry(1, height, width-2, 1); + VBar->setGeometry (width, 1, 2, height-1); + HBar->setGeometry (1, height, width-2, 1); } else { - VBar->setGeometry(width, 2, 1, height-2); - HBar->setGeometry(2, height, width-2, 1); + VBar->setGeometry (width, 2, 1, height-2); + HBar->setGeometry (2, height, width-2, 1); } } @@ -616,22 +621,22 @@ void FTextView::insert (const FString& str, int pos) maxLineWidth = len; if ( len > uInt(width-nf_offset-2) ) { - HBar->setMaximum(int(maxLineWidth)-width+nf_offset+2); - HBar->setPageSize(int(maxLineWidth), width-nf_offset-2); + HBar->setMaximum (int(maxLineWidth) - width + nf_offset + 2); + HBar->setPageSize (int(maxLineWidth), width - nf_offset - 2); HBar->calculateSliderValues(); if ( ! HBar->isVisible() ) HBar->setVisible(); } } } - data.insert (iter+pos, text_split.begin(), text_split.end()); + data.insert (iter + pos, text_split.begin(), text_split.end()); - VBar->setMaximum(int(getRows())-height+2-nf_offset); - VBar->setPageSize(int(getRows()), height-2+nf_offset); + VBar->setMaximum (int(getRows()) - height + 2 - nf_offset); + VBar->setPageSize (int(getRows()), height - 2 + nf_offset); VBar->calculateSliderValues(); - if ( ! VBar->isVisible() && int(getRows()) > height+nf_offset-2 ) + if ( ! VBar->isVisible() && int(getRows()) >= height + nf_offset - 1 ) VBar->setVisible(); - if ( VBar->isVisible() && int(getRows()) <= height+nf_offset-2 ) + if ( VBar->isVisible() && int(getRows()) < height + nf_offset - 1 ) VBar->hide(); processChanged(); } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 2247f791..57669904 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1854,7 +1854,7 @@ void FWidget::drawShadow() print (ch.code); } setColor (wc.shadow_bg, wc.shadow_fg); - for (int i=2; i < width+2 && x1+i <= xmax; i++) + for (int i=2; i <= width+1 && x1+i <= xmax; i++) { ch = getCoveredCharacter (x1+i, y2+1, this); if ( ch.code == fc::LowerHalfBlock @@ -1997,7 +1997,7 @@ void FWidget::clearFlatBorder() y2 = ypos+ymin-1+height; setColor (wc.dialog_fg, wc.dialog_bg); - for (register int y=0; y <= height-1; y++) + for (register int y=0; y < height; y++) { gotoxy (x1-1, y1+y+1); print (' '); // clear on left side @@ -2108,7 +2108,7 @@ void FWidget::drawBorder() for (int x=x1+1; x < x2; x++) print (fc::BoxDrawingsHorizontal); // ─ print (fc::NF_border_corner_middle_upper_right); // ┐ - for (int y=y1+1; y < y2+1; y++) + for (int y=y1+1; y <= y2; y++) { gotoxy (x1, y); print (fc::NF_border_line_left); // border left ⎸ diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index ae48ee85..824d0660 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -65,7 +65,7 @@ void Mandelbrot::draw() dX = (x_max - x_min) / (Cols - 1); dY = (y_max - y_min) / Lines; - for (y0=y_min; y0 < y_max && current_line-1 < Lines; y0+=dY) + for (y0=y_min; y0 < y_max && current_line <= Lines; y0+=dY) { gotoxy (xoffset, yoffset+current_line);