// drawing.cxx (example4) #include #include #include #include #include #include #include #include class ShapeWidget : public Fl_Widget { private: int sides_; void draw(); public: int sides() const; void sides(int n); ShapeWidget(int x,int y,int w,int h,const char *l=0); }; ShapeWidget::ShapeWidget(int x,int y,int w,int h,const char *l) : Fl_Widget(x,y,w,h,l), sides_(3) { } void ShapeWidget::draw() { fl_color(FL_BLACK); fl_rectf(x(),y(),w(),h()); fl_push_matrix(); fl_scale(w()/2.0, h()/2.0); fl_translate(1+(2.0*x())/w(),1+(2.0*y())/h()); fl_color(0x8098b000); fl_begin_complex_polygon(); for (int i=0; isides(int(((Fl_Slider*)widget)->value())); } int main( ) { Fl_Window window(300, 330); window.begin(); ShapeWidget sw(10, 10, 280, 280); window.resizable(&sw); Fl_Slider slider(50, 295, window.w()-60, 30, "Sides:"); slider.type(FL_HORIZONTAL); slider.align(FL_ALIGN_LEFT); slider.callback(slider_callback, &sw); slider.value(sw.sides()); slider.step(1); slider.range(3,40); window.end(); window.show(); return Fl::run(); }