On 24 Mar 2007, at 9:19, Mathieu Peyréga wrote:
>> If nothing helps, maybe you can boil some code down to a single
>> page and
>> post it here.
>
> here it is...
OK, I think your basic problem is that you have failed to take
account of the fact that scrolling the scroll widget in effect moves
the origin you are drawing your compass at, and you are not removing
what you drew the last time before you draw it again... So you get a
trail of previous compasses left on the display...
Also, you are changing the default line style but are not restoring
it, and you are not setting the clip region before drawing... (but
that's "by the way")
Anyway, I took what you posted and then guessed at how you might be
using it to create the (unfortunately much longer!) example below...
Is this what you are trying to do? In particular notice that pressing
the "clear" button removes the old compass lines when scrolling...
and that redraws triggered by damage to the scroll (i.e. the compass
timeout) do clear the widget, whereas simply scrolling (which *does
not* damage the scroll region) leaves trailing lines behind... This
is to be expected since the point of the scrolling region is to get a
minimum update, without redrawing the entire region every time.
Of course, what I have done (flushing the entire scroll every time)
is not really a practical solution long term, but it might get you
heading in the right direction.
--------
// Build as fltk-config --compile test_scroll.cxx
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
static Fl_Double_Window *main_win=(Fl_Double_Window *)0;
static Fl_Box *a_map=(Fl_Box *)0;
static Fl_Button *exit_bt=(Fl_Button *)0;
static Fl_Button *clear_bt=(Fl_Button *)0;
class C_MapView : public Fl_Scroll
{
protected:
void draw(void);
public:
int m_ShowCompass;
double m_NorthOffset;
int m_clear;
C_MapView(int X, int Y, int W, int H, const char *L=0) :
Fl_Scroll(X,Y,W,H,L) {
m_ShowCompass = 1;
m_NorthOffset = 0.0;
m_clear = 0;
}
};
void C_MapView::draw(void)
{
Fl_Scroll::draw();
if (m_ShowCompass)
{
fl_push_clip(x(), y(), w()-20, h()-20); /* allow for scrollbars
-
there must be a better way? */
if(m_clear)
{
Fl_Color bg = this->color();
fl_color(bg);
fl_rectf(x(), y(), w()-20, h()-20);
}
fl_color(FL_DARK_GREEN);
fl_line_style(FL_SOLID, 3);
fl_push_matrix();
fl_translate(x()+100,y()+100);
fl_scale(1,-1);
fl_rotate(m_NorthOffset);
fl_begin_line();
fl_vertex(0,0);
fl_vertex(0,100);
fl_end_line();
fl_begin_line();
fl_vertex(-5,95);
fl_vertex(0,100);
fl_vertex(5,95);
fl_end_line();
fl_pop_matrix();
fl_line_style(0); /* restore line style */
fl_pop_clip(); /* remove scroll clip region */
}
}
static C_MapView *scroll=(C_MapView *)0;
static void cb_exit_bt(Fl_Button*, void*) {
main_win->hide();
}
static void cb_clear_bt(Fl_Button*, void*) {
scroll->m_clear = clear_bt->value();
}
static void turn_cb(void*) {
scroll->m_NorthOffset = scroll->m_NorthOffset - 7.0;
if (scroll->m_NorthOffset < 0.0)
scroll->m_NorthOffset = scroll->m_NorthOffset + 360.0;
Fl::repeat_timeout(1.0, turn_cb);
scroll->redraw();
}
int main(int argc, char **argv)
{
main_win = new Fl_Double_Window(461, 425);
scroll = new C_MapView(25, 25, 350, 355);
scroll->type(7);
scroll->box(FL_THIN_DOWN_BOX);
scroll->color(FL_FOREGROUND_COLOR);
a_map = new Fl_Box(20, 20, 512, 512);
scroll->end();
clear_bt = new Fl_Button(315, 385, 64, 25, "Clear");
clear_bt->callback((Fl_Callback*)cb_clear_bt);
clear_bt->type(FL_TOGGLE_BUTTON);
exit_bt = new Fl_Button(385, 385, 64, 25, "Quit");
exit_bt->callback((Fl_Callback*)cb_exit_bt);
main_win->end();
main_win->resizable(scroll);
main_win->show(argc, argv);
Fl::add_timeout(0.5, turn_cb);
return Fl::run();
}
/* End of file */
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk