Further code optimizations

This commit is contained in:
Markus Gans 2015-09-24 00:41:43 +02:00
parent d0e4b41bbc
commit 26e9f75242
15 changed files with 164 additions and 139 deletions

View File

@ -1,3 +1,6 @@
2015-09-22 Markus Gans <guru.mail@muenster.de>
* Further code optimizations
2015-09-22 Markus Gans <guru.mail@muenster.de>
* Add the possibility to hide a virtual window
* Some code optimizations

View File

@ -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")

View File

@ -137,6 +137,6 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/%{libname}.a
%changelog
* Mon Sep 18 2015 Markus Gans <guru.mail@muenster.de> - 0.1.1-1
* Fri Sep 18 2015 Markus Gans <guru.mail@muenster.de> - 0.1.1-1
- Initial Release (version 0.1.1)

View File

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

View File

@ -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); // █
}
}

View File

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

View File

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

View File

@ -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;
}
@ -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;
}
@ -487,12 +487,12 @@ void FListBox::adjustSize()
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,7 +560,7 @@ 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);
@ -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();
@ -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;
@ -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;
@ -1486,7 +1486,7 @@ 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);
@ -1504,7 +1504,7 @@ void FListBox::insert ( FString item
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();
}
@ -1537,12 +1537,12 @@ void FListBox::remove (int item)
}
HBar->setMaximum(maxLineWidth - width + nf_offset + 4);
HBar->setPageSize(maxLineWidth, width - nf_offset - 4);
if ( HBar->isVisible() && 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 )
if ( VBar->isVisible() && element_count < height - 1 )
VBar->hide();
if ( current >= item && current > 1 )

View File

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

View File

@ -389,7 +389,7 @@ void FScrollbar::onTimer (FTimerEvent*)
if ( ( scrollType == scrollPageBackward
&& SliderPos < SliderClickStopPos )
|| ( scrollType == scrollPageForward
&& SliderPos+SliderLength-1 >= SliderClickStopPos ) )
&& SliderPos+SliderLength > SliderClickStopPos ) )
{
delAllTimer();
return;

View File

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

View File

@ -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<FApplication*>(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 )

View File

@ -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();
}
//----------------------------------------------------------------------
@ -152,12 +156,12 @@ void FTextView::adjustSize()
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();
}
}
@ -629,9 +634,9 @@ void FTextView::insert (const FString& str, int pos)
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();
}

View File

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

View File

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