|
|
I have used Fl_Pack in the past and I always struggle with its behavior.
In the sample attached demo program I have an Fl_Pack that contains an Fl_Gl_Window widget and a normal Fl_Group inside an Fl_Pack.
I would like the Fl_Gl_Window widget to stretch and fill the Fl_Pack whenever the Fl_Group is hidden when the Hide button is clicked. How can I do that?
#include <iostream>
#include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> #include <FL/Fl_Pack.H> #include <FL/Fl_Group.H> #include <FL/math.h>
#include <FL/gl.h> #include <FL/Fl_Gl_Window.H>
class shape_window : public Fl_Gl_Window { void draw(); public: int sides; shape_window(int x,int y,int w,int h,const char *l=0); void resize( int X,int Y,int W,int H ) { std::cerr << "win resize W=" << W << std::endl; Fl_Gl_Window::resize( X, Y, W, H ); } };
shape_window::shape_window(int x,int y,int w,int h,const char *l) : Fl_Gl_Window(x,y,w,h,l) { sides = 3; }
void shape_window::draw() { if (!valid()) { valid(1); glLoadIdentity(); glViewport(0,0,pixel_w(),pixel_h()); } // draw an amazing but slow graphic: glClear(GL_COLOR_BUFFER_BIT); glColor3f( 0.5, 0.5, 0.75 );
glBegin(GL_POLYGON); for (int j=0; j<sides; j++) { double ang = j*2*M_PI/sides; glVertex3f((GLfloat)cos(ang), (GLfloat)sin(ang), 0); } glEnd(); }
// when you change the data, as in this callback, you must call redraw(): void hide_cb(Fl_Widget *o, void *p) { Fl_Group *d = (Fl_Group *)p; if ( d->visible() ) { std::cerr << "hide grp= " << d << std::endl; d->hide(); } else { std::cerr << "show grp= " << d << std::endl; d->show(); } Fl_Pack* pack = (Fl_Pack*)d->parent(); std::cerr << "pack= " << pack << std::endl; pack->init_sizes(); pack->redraw(); }
int main(int argc, char **argv) {
Fl::use_high_res_GL(1); Fl_Window window(300, 370); window.begin();
Fl_Pack pack(10, 75, 280, 280); std::cerr << "pack= " << &pack << std::endl; pack.type( Fl_Pack::HORIZONTAL ); pack.color( FL_CYAN ); //pack.box( FL_FLAT_BOX ); pack.begin();
int H = window.h()-90; int W = pack.w()/2;
shape_window sw(10, 75, W, H ); sw.end();
Fl_Group grp( 0, 75, W, H ); std::cerr << "grp= " << &grp << std::endl; grp.color( FL_RED ); grp.box( FL_FLAT_BOX ); grp.end();
pack.resizable(&sw); pack.end();
Fl_Button button(30, 5, W, 30, "Hide"); button.callback( hide_cb, &grp );
window.resizable( &pack );
window.end(); window.show(argc,argv);
return Fl::run(); }
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/9CCBF21A-9B0F-44CB-8B5F-9BD3B09EF7AC%40gmail.com.
|
[ Direct Link to Message ] | |
|
| |