1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// Color chooser test program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2018-02-01 00:17:17 +03:00
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/fl_show_colormap.H>
|
|
|
|
#include <FL/Fl_Color_Chooser.H>
|
|
|
|
#include <FL/Fl_Image.H>
|
2018-02-01 00:17:17 +03:00
|
|
|
#include <FL/platform.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2018-06-23 20:04:18 +03:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
|
1998-12-06 18:46:13 +03:00
|
|
|
#include "list_visuals.cxx"
|
1998-10-06 23:18:34 +04:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2015-04-09 23:10:25 +03:00
|
|
|
int width = 100;
|
|
|
|
int height = 100;
|
1998-10-06 22:21:25 +04:00
|
|
|
uchar *image;
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Box *hint;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void make_image() {
|
|
|
|
image = new uchar[3*width*height];
|
|
|
|
uchar *p = image;
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
double Y = double(y)/(height-1);
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
double X = double(x)/(width-1);
|
|
|
|
*p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left
|
|
|
|
*p++ = uchar(255*((1-X)*Y)); // green in lower-left
|
|
|
|
*p++ = uchar(255*(X*Y)); // blue in lower-right
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Pens : public Fl_Box {
|
|
|
|
void draw();
|
|
|
|
public:
|
|
|
|
Pens(int X, int Y, int W, int H, const char* L)
|
2009-12-07 01:21:55 +03:00
|
|
|
: Fl_Box(X,Y,W,H,L) {}
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
void Pens::draw() {
|
|
|
|
// use every color in the gray ramp:
|
|
|
|
for (int i = 0; i < 3*8; i++) {
|
|
|
|
fl_color((Fl_Color)(FL_GRAY_RAMP+i));
|
|
|
|
fl_line(x()+i, y(), x()+i, y()+h());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Color c = FL_GRAY;
|
|
|
|
#define fullcolor_cell (FL_FREE_COLOR)
|
|
|
|
|
|
|
|
void cb1(Fl_Widget *, void *v) {
|
|
|
|
c = fl_show_colormap(c);
|
|
|
|
Fl_Box* b = (Fl_Box*)v;
|
|
|
|
b->color(c);
|
2015-04-09 23:10:25 +03:00
|
|
|
hint->labelcolor(fl_contrast(FL_BLACK,c));
|
1998-10-06 22:21:25 +04:00
|
|
|
b->parent()->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cb2(Fl_Widget *, void *v) {
|
|
|
|
uchar r,g,b;
|
|
|
|
Fl::get_color(c,r,g,b);
|
2010-10-31 00:16:43 +04:00
|
|
|
if (!fl_color_chooser("New color:",r,g,b,3)) return;
|
1998-10-06 22:21:25 +04:00
|
|
|
c = fullcolor_cell;
|
|
|
|
Fl::set_color(fullcolor_cell,r,g,b);
|
|
|
|
Fl_Box* bx = (Fl_Box*)v;
|
|
|
|
bx->color(fullcolor_cell);
|
2015-04-09 23:10:25 +03:00
|
|
|
hint->labelcolor(fl_contrast(FL_BLACK,fullcolor_cell));
|
1998-10-06 22:21:25 +04:00
|
|
|
bx->parent()->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
Fl::set_color(fullcolor_cell,145,159,170);
|
|
|
|
Fl_Window window(400,400);
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Box box(30,30,340,340);
|
1998-10-06 22:21:25 +04:00
|
|
|
box.box(FL_THIN_DOWN_BOX);
|
|
|
|
c = fullcolor_cell;
|
|
|
|
box.color(c);
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Box hintbox(40,40,320,30,"Pick background color with buttons:");
|
|
|
|
hintbox.align(FL_ALIGN_INSIDE);
|
|
|
|
hint = &hintbox;
|
|
|
|
Fl_Button b1(120,80,180,30,"fl_show_colormap()");
|
1998-10-06 22:21:25 +04:00
|
|
|
b1.callback(cb1,&box);
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Button b2(120,120,180,30,"fl_color_chooser()");
|
1998-10-06 22:21:25 +04:00
|
|
|
b2.callback(cb2,&box);
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Box image_box(160,190,width,height,0);
|
1998-10-06 22:21:25 +04:00
|
|
|
make_image();
|
2001-08-06 03:58:54 +04:00
|
|
|
(new Fl_RGB_Image(image, width, height))->label(&image_box);
|
2015-04-09 23:10:25 +03:00
|
|
|
Fl_Box b(160,310,120,30,"Example of fl_draw_image()");
|
|
|
|
Pens p(60,180,3*8,120,"lines");
|
1998-10-06 22:21:25 +04:00
|
|
|
p.align(FL_ALIGN_TOP);
|
|
|
|
int i = 1;
|
2009-12-07 01:21:55 +03:00
|
|
|
if (!Fl::args(argc,argv,i) || i < argc-1) {
|
1998-10-06 22:21:25 +04:00
|
|
|
printf("usage: %s <switches> visual-number\n"
|
2009-12-07 01:21:55 +03:00
|
|
|
" - : default visual\n"
|
|
|
|
" r : call Fl::visual(FL_RGB)\n"
|
|
|
|
" c : call Fl::own_colormap()\n",argv[0]);
|
2018-06-23 20:04:18 +03:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
|
1998-10-06 22:21:25 +04:00
|
|
|
printf(" # : use this visual with an empty colormap:\n");
|
|
|
|
list_visuals();
|
|
|
|
#endif
|
|
|
|
puts(Fl::help);
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
if (i!=argc) {
|
|
|
|
if (argv[i][0] == 'r') {
|
|
|
|
if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n");
|
|
|
|
} else if (argv[i][0] == 'c') {
|
|
|
|
Fl::own_colormap();
|
|
|
|
} else if (argv[i][0] != '-') {
|
2018-06-23 20:04:18 +03:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
|
2009-12-07 01:21:55 +03:00
|
|
|
int visid = atoi(argv[i]);
|
|
|
|
fl_open_display();
|
|
|
|
XVisualInfo templt; int num;
|
|
|
|
templt.visualid = visid;
|
|
|
|
fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
|
|
|
|
if (!fl_visual) Fl::fatal("No visual with id %d",visid);
|
|
|
|
fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
|
|
|
|
fl_visual->visual, AllocNone);
|
|
|
|
fl_xpixel(FL_BLACK); // make sure black is allocated
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
2018-02-09 17:39:42 +03:00
|
|
|
Fl::fatal("Visual id's not supported on Windows or MacOS.");
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
window.show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|
1998-10-20 17:25:25 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|