home *** CD-ROM | disk | FTP | other *** search
- #include "wimp.h"
- #include "stdlib.h"
- #include "Modes.h"
- #include "hourglass.h"
- #include "os.h"
- #include "string.h"
- #include "math.h"
- #include "windows.h"
-
- wimp_i make_icon (wimp_w win, int h, int l, int r, char *valid, char *text);
- void col_icon( wimp_w window, wimp_i icon, wimp_colour fg, wimp_colour bg);
- void icon_type(wimp_w window, wimp_i icon, int type);
- wimp_i mode_icon(int mode, int barMode);
- wimp_i title_icon(int cols,int noIcons);
- void load_template (wimp_window **window, char* name);
-
-
-
-
- static wimp_window *info;
- static wimp_window *mode;
- static wimp_window *select;
- static wimp_w infoHdl;
- static wimp_w modeHdl;
- static wimp_w selectHdl;
-
- static wimp_i lastIcon;
-
- static int IconTop;
-
- void load_template (wimp_window **window, char* name)
- {
- char *data=NULL;
- int used;
- int data_used;
-
- wimp_load_template ( 0,
- data,
- data,
- (font_f *) -1,
- name,
- 0,
- &used,
- &data_used);
-
- *window = (wimp_window *) malloc (used);
- data = (char *) malloc (data_used);
-
- wimp_load_template (*window,
- data,
- data+data_used,
- (font_f *) -1,
- name,
- 0,
- &used,
- &data_used);
- }
-
-
- void set_up_windows(void)
- {
- wimp_open_template ("<ModeSel$Dir>.Templates");
- load_template (&info, "prog_info");
- load_template (&mode, "Modes");
- load_template (&select, "Select");
- wimp_close_template ();
-
- infoHdl=wimp_create_window (info);
- modeHdl=wimp_create_window (mode);
- selectHdl=wimp_create_window(select);
- }
-
- wimp_w get_info(void)
- {
- return(infoHdl);
- }
-
- wimp_w get_mode(void)
- {
- return(modeHdl);
- }
-
- void update_sel_icons(int mode)
- {
- int position = 0;
- char res[12];
-
- while(get_mode_no(position) != mode) position++;
-
- set_sel_col(get_bpp(position));
- get_res(position, res);
- set_sel_res(res);
- }
-
- wimp_w get_select(void)
- {
- return(selectHdl);
- }
-
- void handle_open_win(wimp_block *block)
- {
- wimp_open_window (& block->open);
- }
-
- void close_mode_window(bool *mainWindowOpen)
- {
- int loop;
- wimp_icon_state icon_state;
-
- icon_state.w = modeHdl;
- for (loop=1; loop<= lastIcon; loop++)
- {
- icon_state.i = loop;
-
- wimp_get_icon_state (&icon_state);
-
- wimp_delete_icon(modeHdl,loop);
- free (icon_state.icon.data.indirected_text.text);
- free (icon_state.icon.data.indirected_text.validation);
- }
- lastIcon = 0;
- wimp_close_window(modeHdl);
- *mainWindowOpen = FALSE;
- }
-
- void close_select_window(void)
- {
- wimp_close_window(selectHdl);
- }
-
-
- void handle_close_win(wimp_block *block, bool *mainWindowOpen)
- {
- wimp_close_window (block->close.w);
- if (block->close.w == modeHdl)
- {
- close_mode_window(mainWindowOpen);
- }
- }
-
- void handle_redraw(wimp_block *block)
- {
- wimp_draw redraw;
- bool more;
-
- redraw.w = block->redraw.w;
- more = wimp_redraw_window (&redraw);
-
- while (more)
- more = wimp_get_rectangle (&redraw);
- }
-
- wimp_i make_icon (wimp_w win, int h, int l, int r, char *valid, char *text)
- {
- wimp_i cpy;
- wimp_icon_create icCre;
-
- icCre.icon.extent.y0 = IconTop-h;
- icCre.icon.extent.y1 = IconTop;
- icCre.icon.extent.x0 = l;
- icCre.icon.extent.x1 = r;
- icCre.icon.flags= 0x17019131;
- icCre.w = win;
-
-
- icCre.icon.data.indirected_text.text = (char *) malloc(30);
- icCre.icon.data.indirected_text.validation = (char*) malloc(4);
- sprintf(icCre.icon.data.indirected_text.validation, "%s", valid);
- sprintf(icCre.icon.data.indirected_text.text, "%s", text);
- cpy = wimp_create_icon (&icCre);
-
- return(cpy);
- }
-
- void col_icon( wimp_w window, wimp_i icon, wimp_colour fg, wimp_colour bg)
- {
- wimp_set_icon_state( window, icon,
- (fg << wimp_ICON_FG_COLOUR_SHIFT) | (bg << wimp_ICON_BG_COLOUR_SHIFT),
- wimp_ICON_BG_COLOUR | wimp_ICON_FG_COLOUR );
- }
-
- void icon_type(wimp_w window, wimp_i icon, int type)
- {
- wimp_set_icon_state(window, icon, wimp_ICON_BUTTON_TYPE, type << wimp_ICON_BUTTON_TYPE_SHIFT );
- }
-
-
- wimp_i mode_icon(int mode, int barMode)
- {
- char str[40];
-
- create_string (mode, str);
-
- set_icon(mode, make_icon(modeHdl,38,30,400,"",str));
- IconTop-=38;
-
- if(hi_res(mode))
- col_icon(modeHdl, get_icon(mode), wimp_COLOUR_DARK_GREEN, wimp_COLOUR_VERY_LIGHT_GREY);
- if(get_mode_no(mode) == barMode)
- col_icon(modeHdl, get_icon(mode), wimp_COLOUR_RED, wimp_COLOUR_VERY_LIGHT_GREY);
-
- return (get_icon(mode));
- }
-
- wimp_i title_icon(int cols,int noIcons)
- {
- char str[20];
- wimp_i icon;
-
- IconTop-=45;
-
- icon= make_icon(modeHdl, ((noIcons+1)*38),10,410,"R4","");
- IconTop+=19;
-
- icon_type(modeHdl, icon, wimp_BUTTON_NEVER);
- wimp_set_icon_state( modeHdl, icon, wimp_ICON_BORDER, wimp_ICON_BORDER);
-
- sprintf(str,"%d Colour Modes",cols);
- icon = make_icon(modeHdl, 38, 35, (strlen(str)*16)+45, "", str);
- IconTop-=38;
-
- col_icon(modeHdl, icon, wimp_COLOUR_DARK_BLUE, wimp_COLOUR_VERY_LIGHT_GREY);
- icon_type(modeHdl, icon, wimp_BUTTON_NEVER);
-
- return (icon);
- }
-
-
- void create_mode_icons(int barMode, int *Opt)
- {
- int Loop, found=0, OptLoop, Bpp,NoIcons;
- os_box extent;
-
- IconTop = -60;
-
- for(Loop=0; Loop<128 ;Loop++)
- set_icon(Loop,(wimp_i) -1);
-
- Bpp=1;
- for (OptLoop=0; OptLoop<=3; OptLoop++)
- {
- if (Opt[OptLoop]!=0)
- {
- NoIcons=0;
- for (Loop=0; Loop<total_modes(); Loop++)
- if (get_bpp(Loop) == Bpp) NoIcons++;
-
- lastIcon = title_icon((int) pow(2,Bpp),NoIcons);
- found++;
-
- for (Loop=0; Loop < total_modes() ; Loop++)
- {
- if (get_bpp(Loop) == Bpp)
- {
- found++;
- lastIcon = mode_icon(Loop,barMode);
- }
- }
- }
- Bpp=Bpp*2;
- }
-
- extent.x0 = 0;
- extent.y0 = IconTop-30;
- extent.y1 = 0;
- extent.x1 = 420;
-
- wimp_set_extent (modeHdl, &extent);
- }
-
- void update_mode_icons(int oldMode, int newMode)
- {
- int position;
-
- for (position=0; position<128; position++)
- {
- if (get_mode_no(position) == oldMode)
- {
- if(hi_res(position))
- col_icon(modeHdl, get_icon(position), wimp_COLOUR_DARK_GREEN, wimp_COLOUR_VERY_LIGHT_GREY);
- else
- col_icon(modeHdl, get_icon(position), wimp_COLOUR_BLACK, wimp_COLOUR_VERY_LIGHT_GREY);
- }
-
- if (get_mode_no(position) == newMode)
- {
- col_icon(modeHdl, get_icon(position), wimp_COLOUR_RED, wimp_COLOUR_VERY_LIGHT_GREY);
- }
-
-
- }
- }
-
- void set_sel_col(int selBpp)
- {
- wimp_icon_state icon_state;
-
- icon_state.i = selCol;
- icon_state.w = selectHdl;
- wimp_get_icon_state (&icon_state);
-
- sprintf (icon_state.icon.data.indirected_text.text,"%d colours",(int) pow((double)2, (double) selBpp));
- wimp_set_icon_state (selectHdl, selCol, 0, 0);
- }
-
- int get_sel_bpp(void)
- {
- int col;
- wimp_icon_state icon_state;
-
- icon_state.i = selCol;
- icon_state.w = selectHdl;
- wimp_get_icon_state (&icon_state);
-
- col =atoi(icon_state.icon.data.indirected_text.text);
- switch(col)
- {
- case 2 : return(1); break;
- case 4 : return(2); break;
- case 16 : return(4); break;
- case 256 : return(8); break;
- default : return(1);
- }
- }
-
-
- void set_sel_res(char *resStr)
- {
- wimp_icon_state icon_state;
-
- icon_state.i = selRes;
- icon_state.w = selectHdl;
- wimp_get_icon_state (&icon_state);
-
- sprintf (icon_state.icon.data.indirected_text.text,"%s",resStr);
- wimp_set_icon_state (selectHdl, selRes, 0, 0);
- }
-
- char* get_sel_res_str(void)
- {
- wimp_icon_state icon_state;
-
- icon_state.i = selRes;
- icon_state.w = selectHdl;
- wimp_get_icon_state (&icon_state);
-
- return(icon_state.icon.data.indirected_text.text);
- }
-