Clean up some inconsistencies in themes.
[ntk.git] / test / image.cxx
blob25e19c5682473e27ae5363439b9d3f426a6b2516
1 //
2 // "$Id: image.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Fl_Image test program for the Fast Light Tool Kit (FLTK).
5 //
6 // Notice that Fl_Image is for a static, multiple-reuse image, such
7 // as an icon or postage stamp. Use fl_draw_image to go directly
8 // from an buffered image that changes often.
9 //
10 // Copyright 1998-2010 by Bill Spitzak and others.
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Library General Public
14 // License as published by the Free Software Foundation; either
15 // version 2 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Library General Public License for more details.
22 // You should have received a copy of the GNU Library General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 // USA.
27 // Please report all bugs and problems on the following page:
29 // http://www.fltk.org/str.php
32 #include <FL/Fl.H>
33 #include <FL/Fl_Double_Window.H>
34 #include <FL/Fl_Button.H>
35 #include <FL/Fl_Image.H>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <math.h>
40 int width = 100;
41 int height = 100;
42 uchar *image;
44 void make_image() {
45 image = new uchar[4*width*height];
46 uchar *p = image;
47 for (int y = 0; y < height; y++) {
48 double Y = double(y)/(height-1);
49 for (int x = 0; x < width; x++) {
50 double X = double(x)/(width-1);
51 *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left
52 *p++ = uchar(255*((1-X)*Y)); // green in lower-left
53 *p++ = uchar(255*(X*Y)); // blue in lower-right
54 X -= 0.5;
55 Y -= 0.5;
56 int alpha = (int)(255 * sqrt(X * X + Y * Y));
57 if (alpha < 255) *p++ = uchar(alpha); // alpha transparency
58 else *p++ = 255;
59 Y += 0.5;
64 #include <FL/Fl_Toggle_Button.H>
66 Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb,*inactb;
67 Fl_Button *b;
68 Fl_Double_Window *w;
70 void button_cb(Fl_Widget *,void *) {
71 int i = 0;
72 if (leftb->value()) i |= FL_ALIGN_LEFT;
73 if (rightb->value()) i |= FL_ALIGN_RIGHT;
74 if (topb->value()) i |= FL_ALIGN_TOP;
75 if (bottomb->value()) i |= FL_ALIGN_BOTTOM;
76 if (insideb->value()) i |= FL_ALIGN_INSIDE;
77 if (overb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE;
78 b->align(i);
79 if (inactb->value()) b->deactivate();
80 else b->activate();
81 w->redraw();
84 #include <FL/x.H>
85 #if !defined(WIN32) && !defined(__APPLE__)
86 #include "list_visuals.cxx"
87 #endif
89 int visid = -1;
90 int arg(int argc, char **argv, int &i) {
91 if (argv[i][1] == 'v') {
92 if (i+1 >= argc) return 0;
93 visid = atoi(argv[i+1]);
94 i += 2;
95 return 2;
97 return 0;
100 int main(int argc, char **argv) {
101 #if !defined(WIN32) && !defined(__APPLE__)
102 int i = 1;
104 Fl::args(argc,argv,i,arg);
106 if (visid >= 0) {
107 fl_open_display();
108 XVisualInfo templt; int num;
109 templt.visualid = visid;
110 fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
111 if (!fl_visual) {
112 fprintf(stderr, "No visual with id %d, use one of:\n",visid);
113 list_visuals();
114 exit(1);
116 fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
117 fl_visual->visual, AllocNone);
118 fl_xpixel(FL_BLACK); // make sure black is allocated in overlay visuals
119 } else {
120 Fl::visual(FL_RGB);
122 #endif
124 Fl_Double_Window window(400,400); ::w = &window;
125 window.color(FL_WHITE);
126 Fl_Button b(140,160,120,120,"Image w/Alpha"); ::b = &b;
128 Fl_RGB_Image *rgb;
129 Fl_Image *dergb;
131 make_image();
132 rgb = new Fl_RGB_Image(image, width, height,4);
133 dergb = rgb->copy();
134 dergb->inactive();
136 b.image(rgb);
137 b.deimage(dergb);
139 leftb = new Fl_Toggle_Button(25,50,50,25,"left");
140 leftb->callback(button_cb);
141 rightb = new Fl_Toggle_Button(75,50,50,25,"right");
142 rightb->callback(button_cb);
143 topb = new Fl_Toggle_Button(125,50,50,25,"top");
144 topb->callback(button_cb);
145 bottomb = new Fl_Toggle_Button(175,50,50,25,"bottom");
146 bottomb->callback(button_cb);
147 insideb = new Fl_Toggle_Button(225,50,50,25,"inside");
148 insideb->callback(button_cb);
149 overb = new Fl_Toggle_Button(25,75,100,25,"text over");
150 overb->callback(button_cb);
151 inactb = new Fl_Toggle_Button(125,75,100,25,"inactive");
152 inactb->callback(button_cb);
153 window.resizable(window);
154 window.end();
155 window.show(argc, argv);
156 return Fl::run();
160 // End of "$Id: image.cxx 7903 2010-11-28 21:06:39Z matt $".