Browse Source

Port 2.0 drawing optimizations for Fl_Input_ - this provides a more

efficient fix for anti-aliased text.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2118 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/168/head
Michael R Sweet 23 years ago
parent
commit
a48e1cac3f
  1. 26
      CREDITS
  2. 72
      src/Fl_Input_.cxx

26
CREDITS

@ -27,30 +27,14 @@ CORE DEVELOPERS
OTHER CONTRIBUTORS OTHER CONTRIBUTORS
Documentation and OS/2 porting: The following people have contributed fixes or enhancements
for FLTK:
Alexander Mai
WIN32 and Cygwin testing and fixes:
Teun Burgers Teun Burgers
OpenGL enhancements and widget fixes:
Stuart Levy Stuart Levy
Documentation:
Andrea Suatoni
Fl_Scroll fixes:
Mike Lindner Mike Lindner
Alexander Mai
Fl_Input fixes:
Alexander Rabi Alexander Rabi
X11 resource support:
James Roth James Roth
Andrea Suatoni
Paul Sydney

72
src/Fl_Input_.cxx

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Input_.cxx,v 1.21.2.11.2.11 2002/04/16 17:11:11 easysw Exp $" // "$Id: Fl_Input_.cxx,v 1.21.2.11.2.12 2002/04/27 19:20:50 easysw Exp $"
// //
// Common input widget routines for the Fast Light Tool Kit (FLTK). // Common input widget routines for the Fast Light Tool Kit (FLTK).
// //
@ -146,12 +146,12 @@ void Fl_Input_::minimal_update(int p) {
mu_p = p; mu_p = p;
} }
#if defined(__APPLE__) || USE_XFT //#if defined(__APPLE__) || USE_XFT
redraw(); // redraw();
#else //#else
damage(FL_DAMAGE_EXPOSE); damage(FL_DAMAGE_EXPOSE);
erase_cursor_only = 0; erase_cursor_only = 0;
#endif // __APPLE__ || USE_XFT //#endif // __APPLE__ || USE_XFT
} }
void Fl_Input_::minimal_update(int p, int q) { void Fl_Input_::minimal_update(int p, int q) {
@ -241,11 +241,12 @@ void Fl_Input_::drawtext(int X, int Y, int W, int H) {
} }
fl_clip(X, Y, W, H); fl_clip(X, Y, W, H);
Fl_Color color = active_r() ? textcolor() : fl_inactive(textcolor()); Fl_Color tc = active_r() ? textcolor() : fl_inactive(textcolor());
p = value(); p = value();
// visit each line and draw it: // visit each line and draw it:
int desc = height-fl_descent(); int desc = height-fl_descent();
int xpos = X-xscroll_; if (W > 12) xpos += 3;
int ypos = -yscroll_; int ypos = -yscroll_;
for (; ypos < H;) { for (; ypos < H;) {
@ -256,56 +257,71 @@ void Fl_Input_::drawtext(int X, int Y, int W, int H) {
if (do_mu) { // for minimal update: if (do_mu) { // for minimal update:
const char* pp = value()+mu_p; // pointer to where minimal update starts const char* pp = value()+mu_p; // pointer to where minimal update starts
if (e >= pp && (!erase_cursor_only || p <= pp)) { // we must erase this if (e < pp) goto CONTINUE2; // this line is before the changes
if (erase_cursor_only && p > pp) goto CONTINUE2; // this line is after
// calculate area to erase: // calculate area to erase:
int x1 = -xscroll_; int r = X+W;
if (p < pp) x1 += int(expandpos(p, pp, buf, 0)); int x;
// erase it: if (p >= pp) {
fl_color(this->color()); x = X;
fl_rectf(X+x1, Y+ypos, erase_cursor_only?2:W-x1, height); if (erase_cursor_only) r = xpos+2;
} else {
x = xpos+(int)expandpos(p, pp, buf, 0);
if (erase_cursor_only) r = x+2;
}
// clip to and erase it:
fl_color(color());
fl_rectf(x, Y+ypos, r-x, height);
fl_push_clip(x, Y+ypos, r-x, height);
// it now draws entire line over it // it now draws entire line over it
// this should not draw letters to left of erased area, but // this should not draw letters to left of erased area, but
// that is nyi. // that is nyi.
} }
}
// Draw selection area if required: // Draw selection area if required:
if (selstart < selend && selstart <= e-value() && selend > p-value()) { if (selstart < selend && selstart <= e-value() && selend > p-value()) {
const char* pp = value()+selstart; const char* pp = value()+selstart;
int x1 = -xscroll_; int x1 = xpos;
int offset1 = 0; int offset1 = 0;
if (pp > p) { if (pp > p) {
fl_color(color); fl_color(tc);
x1 += int(expandpos(p, pp, buf, &offset1)); x1 += int(expandpos(p, pp, buf, &offset1));
fl_draw(buf, offset1, X-xscroll_, Y+ypos+desc); fl_draw(buf, offset1, xpos, Y+ypos+desc);
} }
pp = value()+selend; pp = value()+selend;
int x2 = W; int x2 = X+W;
int offset2; int offset2;
if (pp <= e) x2 = int(expandpos(p, pp, buf, &offset2))-xscroll_; if (pp <= e) x2 = xpos+int(expandpos(p, pp, buf, &offset2));
else offset2 = strlen(buf); else offset2 = strlen(buf);
fl_color(selection_color()); fl_color(selection_color());
fl_rectf(X+int(x1+.5), Y+ypos, int(x2-x1), height); fl_rectf(x1, Y+ypos, x2-x1, height);
fl_color(fl_contrast(textcolor(), selection_color())); fl_color(fl_contrast(textcolor(), selection_color()));
fl_draw(buf+offset1, offset2-offset1, X+x1, Y+ypos+desc); fl_draw(buf+offset1, offset2-offset1, x1, Y+ypos+desc);
if (pp < e) { if (pp < e) {
fl_color(color); fl_color(tc);
fl_draw(buf+offset2, X+x2, Y+ypos+desc); fl_draw(buf+offset2, x2, Y+ypos+desc);
} }
} else { } else {
// draw unselected text
fl_color(tc);
fl_draw(buf, xpos, Y+ypos+desc);
}
if (do_mu) fl_pop_clip();
CONTINUE2:
// draw the cursor: // draw the cursor:
if (Fl::focus() == this && selstart == selend && if (Fl::focus() == this && selstart == selend &&
position() >= p-value() && position() <= e-value()) { position() >= p-value() && position() <= e-value()) {
fl_color(cursor_color()); fl_color(cursor_color());
fl_rectf(X+curx-xscroll_, Y+ypos, 2, height); fl_rectf(xpos+curx, Y+ypos, 2, height);
}
fl_color(color);
fl_draw(buf, X-xscroll_, Y+ypos+desc);
} }
CONTINUE: CONTINUE:
ypos += height; ypos += height;
if (e >= value_+size_) break; if (e >= value_+size_) break;
p = e+1; if (*e == '\n' || *e == ' ') e++;
p = e;
} }
// for minimal update, erase all lines below last one if necessary: // for minimal update, erase all lines below last one if necessary:
@ -869,5 +885,5 @@ Fl_Input_::~Fl_Input_() {
} }
// //
// End of "$Id: Fl_Input_.cxx,v 1.21.2.11.2.11 2002/04/16 17:11:11 easysw Exp $". // End of "$Id: Fl_Input_.cxx,v 1.21.2.11.2.12 2002/04/27 19:20:50 easysw Exp $".
// //

Loading…
Cancel
Save