/* color.c * * by Revin Guillen * * Implements a simple RGB color builder * * Allegro GUI Clinic Example * http://students.washington.edu/revin/gui/ */ #include int update_color(void *dp3, int d2); DIALOG color_builder[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ { d_clear_proc, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, NULL }, { d_box_proc, 0, 0, 100, 100, 0, 254, 0, 0, 0, 0, NULL }, { d_slider_proc, 10, 110, 16, 64, 1, 0, 0, 0, 63, 0, NULL, update_color, NULL }, { d_slider_proc, 42, 110, 16, 64, 2, 0, 0, 0, 63, 0, NULL, update_color, NULL }, { d_slider_proc, 74, 110, 16, 64, 4, 0, 0, 0, 63, 0, NULL, update_color, NULL }, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL } }; /* slider ID's within the dialog */ #define S_RED 2 #define S_GREEN 3 #define S_BLUE 4 /* callback for the sliders (the parameters are * ignored, since we already know what controls * to look at for data) */ int update_color(void *dp3, int d2) { RGB col; col.r = color_builder[S_RED].d2; col.g = color_builder[S_GREEN].d2; col.b = color_builder[S_BLUE].d2; vsync(); set_color(254, &col); return 0; } int main() { /* initialize */ allegro_init(); install_keyboard(); install_mouse(); install_timer(); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); set_palette(desktop_palette); /* initialize the color box */ update_color(NULL, 0); /* run the dialog */ do_dialog(color_builder, -1); return 0; }