| | [ Return to Articles | Show Comments | Submit Comment ]
Article #1283: Dynamic Buttons and Scrolling Demo
Created at 22:34 Jan 23, 2013 by xecronix
Last modified at 22:35 Jan 23, 2013
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Scroll.H>
class DynamicButtons : public Fl_Scroll
{
private:
Fl_Button *buttons[256];
char labels[256][4];
public:
DynamicButtons(int X, int Y, int W, int H, const char*L=0) : Fl_Scroll(X,Y,W,H,L)
{
int button_width = 50;
int button_height = 50;
int current_button = 0;
int i = 0;
int j = 0;
int color = 1;
int x = 0;
int y = 0;
memset(labels, '\0', 256 * 4);
for (i = 0; i < 16; i++)
{
for (j = 0; j < 16; j++)
{
sprintf(labels[current_button],"%d", color);
buttons[current_button] = new Fl_Button(x,y,button_width, button_height, (const char *)labels[current_button]);
buttons[current_button]->color(color);
current_button++;
x+=button_width;
color++;
}
x=0;
y+=button_height;
}
}
~DynamicButtons()
{
for (int i=0; i < 256; i++)
{
delete buttons[i];
}
}
};
int main(int argc, char *argv[])
{
Fl_Window *win = new Fl_Window(800,800,"Colored Buttons Scorllalbe Window");
win->resizable(win); //Don't forget to do this or else the scroll bars don't show up.
DynamicButtons *buttons = new DynamicButtons(0,0,800,800,0);
win->end();
win->show();
int retval = Fl::run();
delete buttons;
delete win;
return retval;
}
[ Listing ]
[ Submit Comment ] |
| |