root/trunk/luigi/themes/bitmaps.d

Revision 39, 24.9 kB (checked in by baxissimo, 2 years ago)

made compatible with DMD 0.177 and the removal of implicit array to ptr casts.

Line 
1 /****************************************************************************
2  
3   GLUI User Interface Toolkit
4   ---------------------------
5
6      glui_bitmaps.cpp
7
8 Draws the hardcoded images listed in glui_bitmap_img_data with OpenGL.
9
10 FIXME: upload the images to a texture.  This will allow them to be:
11     - Drawn with alpha blending
12     - Drawn at random sizes and angles onscreen
13     - Drawn much faster than with glDrawPixels
14
15  --------------------------------------------------
16
17   Copyright (c) 1998 Paul Rademacher
18
19   WWW:    http://sourceforge.net/projects/glui/
20   Forums: http://sourceforge.net/forum/?group_id=92496
21
22   Converted to ZLIB license with Paul's permission.
23
24 *****************************************************************************/
25 module luigi.themes.bitmaps;
26
27 import luigi.opengl;
28 import luigi.base;
29
30 import std.stdio : writefln;
31
32 enum StdBitmaps
33 {
34     Checkbox_Off = 0,
35     Checkbox_On,
36     Radiobutton_Off,
37     Radiobutton_On,
38     Up_Arrow,
39     Down_Arrow,
40     Left_Arrow,
41     Right_Arrow,
42     Spinner_Up_Off,
43     Spinner_Up_On,
44     Spinner_Down_Off,
45     Spinner_Down_On,
46     Checkbox_Off_Dis,    /*** Disabled control bitmaps ***/
47     Checkbox_On_Dis,
48     Radiobutton_Off_Dis,
49     Radiobutton_On_Dis,
50     Spinner_Up_Dis,
51     Spinner_Down_Dis,
52     Listbox_Up,
53     Listbox_Down,
54     Listbox_Up_Dis,
55 }
56
57
58 // These must be in the same order as the GLUI_STDBITMAP enums from glui.h!
59 ubyte*[21] bitmap_arrays = [
60     img_checkbox_off.ptr,
61     img_checkbox_on.ptr,
62     img_radiobutton_off.ptr,
63     img_radiobutton_on.ptr,
64     img_uparrow.ptr,
65     img_downarrow.ptr,
66     img_leftarrow.ptr,
67     img_rightarrow.ptr,
68     img_spinup_off.ptr,
69     img_spinup_on.ptr,
70     img_spindown_off.ptr,
71     img_spindown_on.ptr,
72     img_checkbox_off_dis.ptr,
73     img_checkbox_on_dis.ptr,
74     img_radiobutton_off_dis.ptr,
75     img_radiobutton_on_dis.ptr,
76     img_spinup_dis.ptr,
77     img_spindown_dis.ptr,
78     img_listbox_up.ptr,
79     img_listbox_down.ptr,
80     img_listbox_up_dis.ptr,
81 ];
82
83
84 /************************************ GLUI_Bitmap::load_from_array() ********/
85 /**
86  GLUI_Bitmap is a simple 2D texture map.  It's used
87  to represent small textures like checkboxes, arrows, etc.
88  via the GLUI_StdBitmaps class.
89 */
90 struct Bitmap
91 {
92     public:
93
94     /** Create bitmap from grayscale byte image */
95     void init_grayscale(ubyte* array)
96     {
97         format = GL_LUMINANCE;
98         m_width = array[0]; m_height = array[1];
99         pixels = array[2..m_width*m_height];
100     }
101    
102     void draw(Point p)
103     {
104         if (width*height != 0 )
105         {
106             glPixelStorei(GL_UNPACK_ALIGNMENT,1);
107             glRasterPos2f(0.5f + p.x, 0.5f + p.y + height);
108             glDrawPixels(
109                 width, height, format, GL_UNSIGNED_BYTE, pixels.ptr);
110         }
111     }
112     int width() { return m_width; }
113     int height() { return m_height; }
114     Size size() { return Size(m_width,m_height); }
115
116 private:
117     ubyte[] pixels;
118     int m_width=0, m_height=0;
119     uint format = GL_LUMINANCE;
120 }
121
122
123 /**
124  * Keeps an array of Bitmap objects to represent all the
125  * images used in the UI: checkboxes, arrows, etc.
126  */
127 class StdBitmapSet
128 {
129     public:
130     this()
131     {
132         for (int i=0; i<bitmaps.length; i++) {
133             bitmaps[i].init_grayscale(bitmap_arrays[i]);
134         }
135     }
136     ~this() {};
137
138     /** Return the width (in pixels) of the n'th standard bitmap. */
139     int  width (int i)
140     {
141         assert(i>=0 && i<=StdBitmaps.max);
142         return bitmaps[i].width;
143     }
144     /** Return the height (in pixels) of the n'th standard bitmap. */
145     int  height(int i)
146     {
147         assert(i>=0 && i<=StdBitmaps.max);
148         return bitmaps[i].height;
149     }
150
151     /** Draw the n'th standard bitmap (one of the enums
152        listed in GLUI_StdBitmaps_Codes) at pixel corner (x,y).
153     */
154     void draw(int i, Point p)
155     {
156         assert(i>=0 && i<=StdBitmaps.max);
157         bitmaps[i].draw(p);
158     }
159
160     Bitmap opIndex(uint i) { return bitmaps[i]; }
161
162     private:
163     Bitmap[StdBitmaps.max+1] bitmaps;
164 };
165
166
167
168
169 /**
170  Bitmaps for all GLUI images.
171  
172  These were converted from original PPM images
173  (mostly lost) with the tools/ppm2array program.
174  
175  The images here are extracted in typical OpenGL
176  bottom-to-top fashion.
177  
178  FIXME: don't use grayscale brightness here--this prevents
179  people changing the background color.  Instead, use a code
180  indicating the underlying purpose of the pixel:
181     0 = shadows; outlines; UI elements (check boxes, arrows)
182     64 = disabled shadows and UI elements
183     128 = shadowing, disabled
184     192 = disabled white; background
185     255 = highlights; checkbox/radio background
186  
187  I'm thinking the way to do this would be to have an
188 enum {
189   BG = 0, // Background shines through-- totally alpha transparent
190   BS, // Background of scrollbar/spin box-- opaque gray
191   SB, // Shadowed-black element-- strong alpha blend to black
192   SD, // Shadowed-dark element-- weak alpha blend to black
193   HL, // Highlight-light-- weak alpha blend to white
194   HW, // Highlight-white-- strong alpha blend to white
195   UB, // User-interface black-- arrows, checkboxes, radio buttons
196   UW, // User-interface white-- backgrounds of checkboxes and radio buttons
197 };
198  
199  Orion Sky Lawlor, olawlor@acm.org
200  @ This stuff was orignally in C++ and labelled LGPL, but Bill Baxter
201  @ got Lawlor's permission to make it ZLIB via email on Aug 13, 2006
202 */
203
204 /*----------------------- checkboxes --------------------------*/
205 ubyte img_checkbox_off[171] = [  13, 13,  /* width, height */
206 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
207 ];
208
209
210 ubyte img_checkbox_off_dis[171] = [  13, 13,  /* width, height */
211 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
212 ];
213
214
215 ubyte img_checkbox_on[171] = [  13, 13,  /* width, height */
216 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255, 255,   0, 255, 255, 255, 255, 255, 192, 255, 128,   0, 255, 255,   0,   0,   0, 255, 255, 255, 255, 192, 255, 128,   0, 255,   0,   0,   0,   0,   0, 255, 255, 255, 192, 255, 128,   0, 255,   0,   0, 255,   0,   0,   0, 255, 255, 192, 255, 128,   0, 255,   0, 255, 255, 255,   0,   0,   0, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255,   0,   0, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255,   0, 255, 192, 255, 128,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
217 ];
218
219
220 ubyte img_checkbox_on_dis[171] = [  13, 13,  /* width, height */
221 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192, 192,  64, 192, 192, 192, 192, 192, 192, 255, 128,  64, 192, 192,  64,  64,  64, 192, 192, 192, 192, 192, 255, 128,  64, 192,  64,  64,  64,  64,  64, 192, 192, 192, 192, 255, 128,  64, 192,  64,  64, 192,  64,  64,  64, 192, 192, 192, 255, 128,  64, 192,  64, 192, 192, 192,  64,  64,  64, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192,  64,  64, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192,  64, 192, 192, 255, 128,  64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
222 ];
223
224
225 /*------------------------------- arrows -------------------------------------*/
226 ubyte img_downarrow[258] = [  16, 16,  /* width, height */
227   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192,   0,   0,   0,   0,   0, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192,   0,   0,   0,   0,   0,   0,   0, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128,   0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,   0,
228 ];
229
230
231 ubyte img_leftarrow[258] = [  16, 16,  /* width, height */
232   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192,   0,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128,   0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,   0,
233 ];
234
235 ubyte img_rightarrow[258] = [  16, 16,  /* width, height */
236   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0,   0, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128,   0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,   0,
237 ];
238
239 ubyte img_uparrow[258] = [  16, 16,  /* width, height */
240   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192,   0,   0,   0,   0,   0,   0,   0, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192,   0,   0,   0,   0,   0, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192,   0,   0,   0, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192,   0, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128,   0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,