>
>
> > I think you understood correctly, so the example I=20
> > commented(offscreen-test.cxx) was using both Fl_Double_Window=20
> > and offscreen methods because animation issues?
>
> No, the intention of using the offscreen was to illustrate one way in
> which it is possible to draw a view that is larger than the visible
> window.
>
> There was a question, early in this thread, about how to capture (for
> storage reasons) the entire content of a scrolled area, when only part
> of it is shown. The problem is that only the visible bit actually gets
> redrawn in most cases.
>
> So, the suggestions was to use the offscreen to redraw the entire scene,
> which can then be captured and stored to a file (that stage is not shown
> in the demo!)
>
> > I'm planning to do animations and also real time traces, so=20
> > you would recommend me to use offscreen methods?=20
>
> No, just use Fl_Double_Window for your outer widget, and draw directly
> to your subclassed view widget.
>
> > In the case=20
> > that I make a component that is a subclass of=20
> > Fl_Double_Window, if I keep just calling redraw() or=20
> > damage(FL_DAMAGE_ALL) methods each time I want to animate=20
> > would not be the best way to implement?
>
> I wouldn't subclass Fl_Double_Window, because as a container class it
> brings some baggage with it.
> Better to use a "plain" Fl_Double_Window as your outer window, and have
> a view widget as a child of it to show your scene. Derive the view
> widget from Fl_Box, and do whatever drawing you need in its draw()
> method.
> Trigger animation updates by calling redraw() on the view widget.
> This approach works fine, even up to fairly high frame rates, certainly
> good enough for general purposes. (You might not build an HD-TV this
> way, but fine for everyday!)
>
> OK - here's a worked example of that. Draws a sine wave "oscilloscope"
> trace.
>
> // mini-scope.cxx
> // fltk-config --compile mini-scope.cxx
> //
> #include <FL/Fl.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Box.H>
> #include <FL/fl_draw.H>
>
> #include <math.h>
>
> const int trace_max =3D 1024;
> const int view_width =3D 512;
> static int trace_pos =3D 0;
> static int view_pos =3D 0;
> static int view_break =3D 0;
> static float trace[trace_max];
> static float view[view_width];
>
> class scope_view: public Fl_Box
> {
>       void draw();
> public:
>       scope_view(int x, int y,int w,int h, const char *l=3D0) : Fl_Box=20
> (x,y,w,h,l) {}
> };
>
> void scope_view::draw()
> {
>       int wd =3D w();
>       int ht =3D h();
>       int xo =3D x();
>       int yo =3D y();
>
>       fl_color(FL_BLACK);
>       fl_rectf(xo, yo, wd, ht);
>       fl_color(FL_GREEN);
>
>       fl_push_matrix();
>       fl_translate(xo, (yo + (ht/2)));
>       fl_scale(wd, ht/2);
>
>       fl_begin_line();
>       for (int i =3D 0; i < view_width; i++) {
>               if(i =3D=3D view_break) {
>                       fl_end_line();
>                       fl_begin_line();
>               }
>               fl_vertex(((float)i/(float)view_width), view[i]);
>       }
>       fl_end_line();
>
>       fl_pop_matrix();
> } /* end of draw() method */
>
> static scope_view *scope =3D 0;
>
> void update_scope(void *)
> {
>       for (int i =3D 0; i < 7; i++) {
>               view[view_pos] =3D trace[trace_pos];
>               trace_pos++;
>               if(trace_pos >=3D trace_max) trace_pos =3D 0;
>               view_pos++;
>               if(view_pos >=3D view_width) view_pos =3D 0;
>       }
>       view_break =3D view_pos;
>       Fl::repeat_timeout(0.05, update_scope);
>       scope->redraw();
> }
>
> int main(int argc, char **argv)
> {
>       Fl_Double_Window *main_win =3D new Fl_Double_Window(522, 210,
> "Scope Window");
>       main_win->begin();
>       scope =3D new scope_view(5, 5, 512, 200);
>       main_win->end();
> =09
>       // now create the trace - a sine wave
>       for (int i =3D 0; i < trace_max; i++) {
>               trace[i] =3D -sin((double)(i*5*2*M_PI/(double)trace_max));
>       }
>       for (int i =3D 0; i < view_width; i++) {
>               view[i] =3D trace[i];
>       }
>       trace_pos =3D view_width;
>       main_win->show(argc, argv);
> =09
>       Fl::add_timeout(0.1, update_scope);
> =09
>       return Fl::run();
> }
>
> /* end of file */
>
>
>
>
>
> SELEX Sensors and Airborne Systems Limited
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex=
>  SS14 3EL
> A company registered in England & Wales.  Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
Ok. Very good!!!
The only disadvantage of this method(in comparison with direct draw) is only 
memory consumption, but I don't think It's going to be a big issue for my 
target hardware.
Thank you very much!
J. Marcelo Auler
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to