> I think you understood correctly, so the example I > commented(offscreen-test.cxx) was using both Fl_Double_Window > 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 > you would recommend me to use offscreen methods? No, just use Fl_Double_Window for your outer widget, and draw directly to your subclassed view widget. > In the case > that I make a component that is a subclass of > Fl_Double_Window, if I keep just calling redraw() or > damage(FL_DAMAGE_ALL) methods each time I want to animate > 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 = 1024; const int view_width = 512; static int trace_pos = 0; static int view_pos = 0; static int view_break = 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=0) : Fl_Box (x,y,w,h,l) {} }; void scope_view::draw() { int wd = w(); int ht = h(); int xo = x(); int yo = 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 = 0; i < view_width; i++) { if(i == 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 = 0; void update_scope(void *) { for (int i = 0; i < 7; i++) { view[view_pos] = trace[trace_pos]; trace_pos++; if(trace_pos >= trace_max) trace_pos = 0; view_pos++; if(view_pos >= view_width) view_pos = 0; } view_break = view_pos; Fl::repeat_timeout(0.05, update_scope); scope->redraw(); } int main(int argc, char **argv) { Fl_Double_Window *main_win = new Fl_Double_Window(522, 210, "Scope Window"); main_win->begin(); scope = new scope_view(5, 5, 512, 200); main_win->end(); // now create the trace - a sine wave for (int i = 0; i < trace_max; i++) { trace[i] = -sin((double)(i*5*2*M_PI/(double)trace_max)); } for (int i = 0; i < view_width; i++) { view[i] = trace[i]; } trace_pos = view_width; main_win->show(argc, argv); Fl::add_timeout(0.1, update_scope); 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. ******************************************************************** _______________________________________________ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk