2 // "$Id: image.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Fl_Image test program for the Fast Light Tool Kit (FLTK).
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.
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
27 // Please report all bugs and problems on the following page:
29 // http://www.fltk.org/str.php
33 #include <FL/Fl_Double_Window.H>
34 #include <FL/Fl_Button.H>
35 #include <FL/Fl_Image.H>
45 image
= new uchar
[4*width
*height
];
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
56 int alpha
= (int)(255 * sqrt(X
* X
+ Y
* Y
));
57 if (alpha
< 255) *p
++ = uchar(alpha
); // alpha transparency
64 #include <FL/Fl_Toggle_Button.H>
66 Fl_Toggle_Button
*leftb
,*rightb
,*topb
,*bottomb
,*insideb
,*overb
,*inactb
;
70 void button_cb(Fl_Widget
*,void *) {
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
;
79 if (inactb
->value()) b
->deactivate();
85 #if !defined(WIN32) && !defined(__APPLE__)
86 #include "list_visuals.cxx"
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]);
100 int main(int argc
, char **argv
) {
101 #if !defined(WIN32) && !defined(__APPLE__)
104 Fl::args(argc
,argv
,i
,arg
);
108 XVisualInfo templt
; int num
;
109 templt
.visualid
= visid
;
110 fl_visual
= XGetVisualInfo(fl_display
, VisualIDMask
, &templt
, &num
);
112 fprintf(stderr
, "No visual with id %d, use one of:\n",visid
);
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
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
;
132 rgb
= new Fl_RGB_Image(image
, width
, height
,4);
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
);
155 window
.show(argc
, argv
);
160 // End of "$Id: image.cxx 7903 2010-11-28 21:06:39Z matt $".