Fix flickering of Fl_Help_View - turns out we were drawing to the

window every time we checked for extension of the selection.  The
new code draws to a 1x1 off-screen buffer, which eliminates the
flickering and runs much faster!


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5681 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
2007-02-08 21:18:50 +00:00
parent c9a93b10f5
commit 1b7589dace
+53 -18
View File
@@ -57,6 +57,7 @@
#include <FL/Fl_Help_View.H> #include <FL/Fl_Help_View.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/Fl_Pixmap.H> #include <FL/Fl_Pixmap.H>
#include <FL/x.H>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "flstring.h" #include "flstring.h"
@@ -219,6 +220,9 @@ fl_line()
img->draw() img->draw()
*/ */
// We don't put the offscreen buffer in the help view class because
// we'd need to include x.H in the header...
static Fl_Offscreen fl_help_view_buffer;
int Fl_Help_View::selection_first = 0; int Fl_Help_View::selection_first = 0;
int Fl_Help_View::selection_last = 0; int Fl_Help_View::selection_last = 0;
int Fl_Help_View::selection_push_first = 0; int Fl_Help_View::selection_push_first = 0;
@@ -2625,34 +2629,67 @@ void Fl_Help_View::clear_global_selection()
char Fl_Help_View::begin_selection() char Fl_Help_View::begin_selection()
{ {
clear_global_selection(); clear_global_selection();
mouse_x = Fl::event_x(); mouse_y = Fl::event_y();
if (!fl_help_view_buffer) fl_help_view_buffer = fl_create_offscreen(1, 1);
mouse_x = Fl::event_x();
mouse_y = Fl::event_y();
draw_mode = 1; draw_mode = 1;
current_view = this;
window()->make_current(); current_view = this;
draw(); fl_begin_offscreen(fl_help_view_buffer);
draw();
fl_end_offscreen();
draw_mode = 0; draw_mode = 0;
if (selection_push_last) return 1; if (selection_push_last) return 1;
return 0; else return 0;
} }
char Fl_Help_View::extend_selection() char Fl_Help_View::extend_selection()
{ {
if (Fl::event_is_click()) if (Fl::event_is_click())
return 0; return 0;
selected = 1;
// printf("old selection_first=%d, selection_last=%d\n",
// selection_first, selection_last);
int sf = selection_first, sl = selection_last; int sf = selection_first, sl = selection_last;
mouse_x = Fl::event_x(); mouse_y = Fl::event_y();
selected = 1;
mouse_x = Fl::event_x();
mouse_y = Fl::event_y();
draw_mode = 2; draw_mode = 2;
window()->make_current();
draw(); fl_begin_offscreen(fl_help_view_buffer);
draw();
fl_end_offscreen();
draw_mode = 0; draw_mode = 0;
if (selection_push_first < selection_drag_first)
selection_first = selection_push_first; else selection_first = selection_drag_first; if (selection_push_first < selection_drag_first) {
if (selection_push_last > selection_drag_last) selection_first = selection_push_first;
selection_last = selection_push_last; else selection_last = selection_drag_last; } else {
if (sf!=selection_first || sl!=selection_last) selection_first = selection_drag_first;
}
if (selection_push_last > selection_drag_last) {
selection_last = selection_push_last;
} else {
selection_last = selection_drag_last;
}
// printf("new selection_first=%d, selection_last=%d\n",
// selection_first, selection_last);
if (sf!=selection_first || sl!=selection_last) {
// puts("REDRAW!!!\n");
return 1; return 1;
return 1; } else {
// puts("");
return 0;
}
} }
// convert a command with up to four letters into an unsigned int // convert a command with up to four letters into an unsigned int
@@ -2811,9 +2848,7 @@ Fl_Help_View::handle(int event) // I - Event to handle
return 1; return 1;
} }
if (current_view==this && selection_push_last) { if (current_view==this && selection_push_last) {
if (extend_selection()) { if (extend_selection()) redraw();
redraw();
}
fl_cursor(FL_CURSOR_INSERT); fl_cursor(FL_CURSOR_INSERT);
return 1; return 1;
} }