3 * A true-colour dialogue box thingy
7 * © 1994-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 #define tcol__REDUP 27
44 #define tcol__REDDOWN 2
45 #define tcol__REDWRITE 3
46 #define tcol__REDSLIDE 6
47 #define tcol__GREENUP 9
48 #define tcol__GREENDOWN 10
49 #define tcol__GREENWRITE 11
50 #define tcol__GREENSLIDE 14
51 #define tcol__BLUEUP 17
52 #define tcol__BLUEDOWN 18
53 #define tcol__BLUEWRITE 19
54 #define tcol__BLUESLIDE 22
55 #define tcol__ACTIONOK 0
56 #define tcol__COLOUR 25
57 #define tcol__ACTIONCANCEL 1
58 #define tcol__EDITING 30
61 * A structure to handle everything
66 tcol_finishhandler proc;
74 static void tcol__updateColour(tcol__tcolstr *t)
77 pal.bytes.red=t->red*255/100;
78 pal.bytes.green=t->green*255/100;
79 pal.bytes.blue=t->blue*255/100;
80 buttons_updateColourButton(t->d,tcol__COLOUR,pal);
83 static void tcol__updateRed(tcol__tcolstr *t)
85 dbox_setNumeric(t->d,tcol__REDWRITE,t->red);
86 buttons_updateSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE);
87 tcol__updateColour(t);
90 static void tcol__updateGreen(tcol__tcolstr *t)
92 dbox_setNumeric(t->d,tcol__GREENWRITE,t->green);
93 buttons_updateSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE);
94 tcol__updateColour(t);
97 static void tcol__updateBlue(tcol__tcolstr *t)
99 dbox_setNumeric(t->d,tcol__BLUEWRITE,t->blue);
100 buttons_updateSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE);
101 tcol__updateColour(t);
104 static void tcol__redAltered(tcol__tcolstr *t)
106 buttons_arrowClick(t->d,tcol__REDWRITE,0,100,0,FALSE);
107 t->red=dbox_getNumeric(t->d,tcol__REDWRITE);
108 buttons_updateSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE);
109 tcol__updateColour(t);
112 static void tcol__greenAltered(tcol__tcolstr *t)
114 buttons_arrowClick(t->d,tcol__GREENWRITE,0,100,0,FALSE);
115 t->green=dbox_getNumeric(t->d,tcol__GREENWRITE);
116 buttons_updateSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE);
117 tcol__updateColour(t);
120 static void tcol__blueAltered(tcol__tcolstr *t)
122 buttons_arrowClick(t->d,tcol__BLUEWRITE,0,100,0,FALSE);
123 t->blue=dbox_getNumeric(t->d,tcol__BLUEWRITE);
124 buttons_updateSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE);
125 tcol__updateColour(t);
128 static void tcol__redraw(wimp_redrawstr *r,void *handle)
130 tcol__tcolstr *t=(tcol__tcolstr *)handle;
131 wimp_paletteword pal;
133 pal.bytes.red=t->red*255/100;
134 pal.bytes.green=t->green*255/100;
135 pal.bytes.blue=t->blue*255/100;
136 buttons_redrawSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE);
137 buttons_redrawSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE);
138 buttons_redrawSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE);
139 buttons_redrawColourButton(t->d,tcol__COLOUR,pal);
142 static BOOL tcol__raw(dbox d,wimp_eventstr *e,void *handle)
144 tcol__tcolstr *t=(tcol__tcolstr *)handle;
151 wimpt_redraw(tcol__redraw,t);
155 key=e->data.key.chcode;
161 case akbd_TabK+akbd_Sh:
162 case akbd_UpK+akbd_Ctl:
163 case akbd_DownK+akbd_Ctl:
166 switch (e->data.key.c.i)
169 if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor)
172 case tcol__GREENWRITE:
173 if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor)
174 tcol__greenAltered(t);
176 case tcol__BLUEWRITE:
177 if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor)
178 tcol__blueAltered(t);
186 static void tcol__redSlide(dbox d,wimp_i i,int val,void *handle)
188 tcol__tcolstr *t=(tcol__tcolstr *)handle;
192 dbox_setNumeric(t->d,tcol__REDWRITE,t->red);
193 tcol__updateColour(t);
196 static void tcol__greenSlide(dbox d,wimp_i i,int val,void *handle)
198 tcol__tcolstr *t=(tcol__tcolstr *)handle;
202 dbox_setNumeric(t->d,tcol__GREENWRITE,t->green);
203 tcol__updateColour(t);
205 static void tcol__blueSlide(dbox d,wimp_i i,int val,void *handle)
207 tcol__tcolstr *t=(tcol__tcolstr *)handle;
211 dbox_setNumeric(t->d,tcol__BLUEWRITE,t->blue);
212 tcol__updateColour(t);
215 static void tcol__redArrow(dbox d,dbox_field f,int diff,void *handle)
217 tcol__tcolstr *t=(tcol__tcolstr *)handle;
218 buttons_arrowClick(d,f,0,100,diff,FALSE);
222 static void tcol__greenArrow(dbox d,dbox_field f,int diff,void *handle)
224 tcol__tcolstr *t=(tcol__tcolstr *)handle;
225 buttons_arrowClick(d,f,0,100,diff,FALSE);
226 tcol__greenAltered(t);
229 static void tcol__blueArrow(dbox d,dbox_field f,int diff,void *handle)
231 tcol__tcolstr *t=(tcol__tcolstr *)handle;
232 buttons_arrowClick(d,f,0,100,diff,FALSE);
233 tcol__blueAltered(t);
236 static void tcol__handler(dbox d,dbox_field clicked,void *handle)
238 wimp_paletteword pal;
239 tcol__tcolstr *t=(tcol__tcolstr *)handle;
246 (t->proc)(tcol_CANCEL,
254 help_addLine(msgs_lookup("tcolHM:This is the Colour Selector."));
261 if (!dbox_wasAdjustClick())
263 dbox_clickicon(d,tcol__ACTIONOK);
271 dbox_clickicon(d,tcol__ACTIONOK);
276 pal.bytes.red=t->red*255/100;
277 pal.bytes.green=t->green*255/100;
278 pal.bytes.blue=t->blue*255/100;
279 (t->proc)(dbox_wasAdjustClick() ? tcol_OK_REOPEN : tcol_OK,
284 case tcol__ACTIONCANCEL:
285 dbox_clickicon(d,tcol__ACTIONCANCEL);
291 (t->proc)(tcol_CANCEL,
298 buttons_arrow(d,clicked,d,tcol__REDWRITE,tcol__redArrow,+1,t);
301 buttons_arrow(d,clicked,d,tcol__REDWRITE,tcol__redArrow,-1,t);
304 buttons_arrow(d,clicked,d,tcol__GREENWRITE,tcol__greenArrow,+1,t);
306 case tcol__GREENDOWN:
307 buttons_arrow(d,clicked,d,tcol__GREENWRITE,tcol__greenArrow,-1,t);
310 buttons_arrow(d,clicked,d,tcol__BLUEWRITE,tcol__blueArrow,+1,t);
313 buttons_arrow(d,clicked,d,tcol__BLUEWRITE,tcol__blueArrow,-1,t);
316 buttons_slideSlider(d,tcol__REDSLIDE,100,
317 &(t->red),11,FALSE,tcol__redSlide,t);
319 case tcol__GREENSLIDE:
320 buttons_slideSlider(d,tcol__GREENSLIDE,100,
321 &(t->green),10,FALSE,tcol__greenSlide,t);
323 case tcol__BLUESLIDE:
324 buttons_slideSlider(d,tcol__BLUESLIDE,100,
325 &(t->blue),8,FALSE,tcol__blueSlide,t);
334 * wimp_paletteword c,
336 * tcol_finishhandler proc,
341 * Creates and handles a dbox, which allows the user to input a true
342 * colour. You must have a template called 'tcol' for this routine.
345 * char *editing == what we're editing (put in the little box at the top)
346 * wimp_paletteword c == the initial colour
347 * BOOL isStatic == whether the dbox is static. Actually, you can use
348 * any of the dbox display types (e.g. dbox_STATIC_OVERPTR)
349 * tcol_finishhandler proc == procedure called when the user clicks OK
350 * void *handle == the jolly old handle
358 tcol_finishhandler proc,
362 tcol__tcolstr *t=(tcol__tcolstr *)mem_alloc(sizeof(tcol__tcolstr));
365 werr(FALSE,msgs_lookup("tcolNEM:Not enough memory to create dbox."));
368 t->d=dbox_create("tcol");
371 dbox_rawEventHandler(t->d,tcol__raw,t);
372 dbox_eventHandler(t->d,tcol__handler,t);
373 dbox_setfield(t->d,tcol__EDITING,"%s",editing);
374 t->red=c.bytes.red*100/255;
375 t->green=c.bytes.green*100/255;
376 t->blue=c.bytes.blue*100/255;
380 tcol__updateGreen(t);
382 dbox_display(t->d,isStatic);