/* * Tcol * A true-colour dialogue box thingy * * v. 1.00 24 July 1993 * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "dbox.h" #include "buttons.h" #include "wimp.h" #include "wimpt.h" #include "werr.h" #include "tcol.h" #include "help.h" #include "msgs.h" #include "mem.h" #include "akbd.h" #include #include #include #define tcol__REDUP 27 #define tcol__REDDOWN 2 #define tcol__REDWRITE 3 #define tcol__REDSLIDE 6 #define tcol__GREENUP 9 #define tcol__GREENDOWN 10 #define tcol__GREENWRITE 11 #define tcol__GREENSLIDE 14 #define tcol__BLUEUP 17 #define tcol__BLUEDOWN 18 #define tcol__BLUEWRITE 19 #define tcol__BLUESLIDE 22 #define tcol__ACTIONOK 0 #define tcol__COLOUR 25 #define tcol__ACTIONCANCEL 1 #define tcol__EDITING 30 /* * A structure to handle everything */ typedef struct { dbox d; tcol_finishhandler proc; void *handle; int red; int green; int blue; } tcol__tcolstr; static void tcol__updateColour(tcol__tcolstr *t) { wimp_paletteword pal; pal.bytes.red=t->red*255/100; pal.bytes.green=t->green*255/100; pal.bytes.blue=t->blue*255/100; buttons_updateColourButton(t->d,tcol__COLOUR,pal); } static void tcol__updateRed(tcol__tcolstr *t) { dbox_setNumeric(t->d,tcol__REDWRITE,t->red); buttons_updateSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE); tcol__updateColour(t); } static void tcol__updateGreen(tcol__tcolstr *t) { dbox_setNumeric(t->d,tcol__GREENWRITE,t->green); buttons_updateSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE); tcol__updateColour(t); } static void tcol__updateBlue(tcol__tcolstr *t) { dbox_setNumeric(t->d,tcol__BLUEWRITE,t->blue); buttons_updateSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE); tcol__updateColour(t); } static void tcol__redAltered(tcol__tcolstr *t) { buttons_arrowClick(t->d,tcol__REDWRITE,0,100,0,FALSE); t->red=dbox_getNumeric(t->d,tcol__REDWRITE); buttons_updateSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE); tcol__updateColour(t); } static void tcol__greenAltered(tcol__tcolstr *t) { buttons_arrowClick(t->d,tcol__GREENWRITE,0,100,0,FALSE); t->green=dbox_getNumeric(t->d,tcol__GREENWRITE); buttons_updateSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE); tcol__updateColour(t); } static void tcol__blueAltered(tcol__tcolstr *t) { buttons_arrowClick(t->d,tcol__BLUEWRITE,0,100,0,FALSE); t->blue=dbox_getNumeric(t->d,tcol__BLUEWRITE); buttons_updateSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE); tcol__updateColour(t); } static void tcol__redraw(wimp_redrawstr *r,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; wimp_paletteword pal; r=r; pal.bytes.red=t->red*255/100; pal.bytes.green=t->green*255/100; pal.bytes.blue=t->blue*255/100; buttons_redrawSlider(t->d,tcol__REDSLIDE,100,t->red,11,FALSE); buttons_redrawSlider(t->d,tcol__GREENSLIDE,100,t->green,10,FALSE); buttons_redrawSlider(t->d,tcol__BLUESLIDE,100,t->blue,8,FALSE); buttons_redrawColourButton(t->d,tcol__COLOUR,pal); } static BOOL tcol__raw(dbox d,wimp_eventstr *e,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; BOOL handled=FALSE; BOOL cursor=FALSE; int key; switch (e->e) { case wimp_EREDRAW: wimpt_redraw(tcol__redraw,t); handled=TRUE; break; case wimp_EKEY: key=e->data.key.chcode; switch (key) { case akbd_DownK: case akbd_UpK: case akbd_TabK: case akbd_TabK+akbd_Sh: case akbd_UpK+akbd_Ctl: case akbd_DownK+akbd_Ctl: cursor=TRUE; } switch (e->data.key.c.i) { case tcol__REDWRITE: if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor) tcol__redAltered(t); break; case tcol__GREENWRITE: if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor) tcol__greenAltered(t); break; case tcol__BLUEWRITE: if (handled=buttons_insertChar(d,key,'0','9'),handled || cursor) tcol__blueAltered(t); break; } break; } return (handled); } static void tcol__redSlide(dbox d,wimp_i i,int val,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; i=i; d=d; val=val; dbox_setNumeric(t->d,tcol__REDWRITE,t->red); tcol__updateColour(t); } static void tcol__greenSlide(dbox d,wimp_i i,int val,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; i=i; d=d; val=val; dbox_setNumeric(t->d,tcol__GREENWRITE,t->green); tcol__updateColour(t); } static void tcol__blueSlide(dbox d,wimp_i i,int val,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; i=i; d=d; val=val; dbox_setNumeric(t->d,tcol__BLUEWRITE,t->blue); tcol__updateColour(t); } static void tcol__redArrow(dbox d,dbox_field f,int diff,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; buttons_arrowClick(d,f,0,100,diff,FALSE); tcol__redAltered(t); } static void tcol__greenArrow(dbox d,dbox_field f,int diff,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; buttons_arrowClick(d,f,0,100,diff,FALSE); tcol__greenAltered(t); } static void tcol__blueArrow(dbox d,dbox_field f,int diff,void *handle) { tcol__tcolstr *t=(tcol__tcolstr *)handle; buttons_arrowClick(d,f,0,100,diff,FALSE); tcol__blueAltered(t); } static void tcol__handler(dbox d,dbox_field clicked,void *handle) { wimp_paletteword pal; tcol__tcolstr *t=(tcol__tcolstr *)handle; switch (clicked) { case dbox_CLOSE: dbox_delete(d); if (t->proc) { (t->proc)(tcol_CANCEL, pal, t->handle); } mem_free(t); break; case dbox_HELP: help_startHelp(); help_addLine(msgs_lookup("tcolHM:This is the Colour Selector.")); help_readFromIcon(); help_endHelp(); break; case tcol__COLOUR: break; case tcol__ACTIONOK: if (!dbox_wasAdjustClick()) { dbox_clickicon(d,tcol__ACTIONOK); dbox_hide(d); dbox_unclick(); dbox_delete(d); mem_free(t); } else { dbox_clickicon(d,tcol__ACTIONOK); dbox_unclick(); } if (t->proc) { pal.bytes.red=t->red*255/100; pal.bytes.green=t->green*255/100; pal.bytes.blue=t->blue*255/100; (t->proc)(dbox_wasAdjustClick() ? tcol_OK_REOPEN : tcol_OK, pal, t->handle); } break; case tcol__ACTIONCANCEL: dbox_clickicon(d,tcol__ACTIONCANCEL); dbox_hide(d); dbox_unclick(); dbox_delete(d); if (t->proc) { (t->proc)(tcol_CANCEL, pal, t->handle); } mem_free(t); break; case tcol__REDUP: buttons_arrow(d,clicked,d,tcol__REDWRITE,tcol__redArrow,+1,t); break; case tcol__REDDOWN: buttons_arrow(d,clicked,d,tcol__REDWRITE,tcol__redArrow,-1,t); break; case tcol__GREENUP: buttons_arrow(d,clicked,d,tcol__GREENWRITE,tcol__greenArrow,+1,t); break; case tcol__GREENDOWN: buttons_arrow(d,clicked,d,tcol__GREENWRITE,tcol__greenArrow,-1,t); break; case tcol__BLUEUP: buttons_arrow(d,clicked,d,tcol__BLUEWRITE,tcol__blueArrow,+1,t); break; case tcol__BLUEDOWN: buttons_arrow(d,clicked,d,tcol__BLUEWRITE,tcol__blueArrow,-1,t); break; case tcol__REDSLIDE: buttons_slideSlider(d,tcol__REDSLIDE,100, &(t->red),11,FALSE,tcol__redSlide,t); break; case tcol__GREENSLIDE: buttons_slideSlider(d,tcol__GREENSLIDE,100, &(t->green),10,FALSE,tcol__greenSlide,t); break; case tcol__BLUESLIDE: buttons_slideSlider(d,tcol__BLUESLIDE,100, &(t->blue),8,FALSE,tcol__blueSlide,t); break; } } /* * void tcol * ( * char *editing, * wimp_paletteword c, * BOOL isStatic, * tcol_finishhandler proc, * void *handle * ) * * Use * Creates and handles a dbox, which allows the user to input a true * colour. You must have a template called 'tcol' for this routine. * * Parameters * char *editing == what we're editing (put in the little box at the top) * wimp_paletteword c == the initial colour * BOOL isStatic == whether the dbox is static. Actually, you can use * any of the dbox display types (e.g. dbox_STATIC_OVERPTR) * tcol_finishhandler proc == procedure called when the user clicks OK * void *handle == the jolly old handle */ void tcol ( char *editing, wimp_paletteword c, BOOL isStatic, tcol_finishhandler proc, void *handle ) { tcol__tcolstr *t=(tcol__tcolstr *)mem_alloc(sizeof(tcol__tcolstr)); if (!t) { werr(FALSE,msgs_lookup("tcolNEM:Not enough memory to create dbox.")); return; } t->d=dbox_create("tcol"); if (!t->d) return; dbox_rawEventHandler(t->d,tcol__raw,t); dbox_eventHandler(t->d,tcol__handler,t); dbox_setfield(t->d,tcol__EDITING,"%s",editing); t->red=c.bytes.red*100/255; t->green=c.bytes.green*100/255; t->blue=c.bytes.blue*100/255; t->proc=proc; t->handle=handle; tcol__updateRed(t); tcol__updateGreen(t); tcol__updateBlue(t); dbox_display(t->d,isStatic); }