Article #1281: Colors and Dynamic Buttons Demo

   
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Articles | Show Comments | Submit Comment ]

Article #1281: Colors and Dynamic Buttons Demo

Created at 07:47 Jan 23, 2013 by xecronix

Last modified at 10:26 Jan 23, 2013

Short demo to show what the standard 256 colors look like and create dynamic labels for a grid of buttons.


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>


int main(int argc, char *argv[])
{
        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;

        Fl_Window *win = new Fl_Window(800,800,"Dynamic Colored Boxes");
        Fl_Button *buttons[256];
        char labels[256][4];
        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;
        }
        win->end();
        win->show();
        int retval =  Fl::run();
        for (i=0; i < 256; i++)
        {
                delete buttons[i];
        }
        delete win;
        return retval; 
}

Listing ]

Comments

Submit Comment ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2012 by Bill Spitzak and others. This project is hosted by Seriss Corporation. Please report site problems to 'erco@seriss.com'.