]> icculus.org git repositories - btb/d2x.git/blob - unused/ui/icon.c
improved mac pig loading/reverted TRANSPARENCY_COLOR changes
[btb/d2x.git] / unused / ui / icon.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: icon.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "mem.h"
24 #include "fix.h"
25 #include "types.h"
26 #include "gr.h"
27 #include "ui.h"
28 #include "key.h"
29
30 #define Middle(x) ((2*(x)+1)/4)
31
32 extern void ui_draw_shad( short x1, short y1, short x2, short y2, short c1, short c2 );
33
34 void ui_draw_box_in1( short x1, short y1, short x2, short y2 )
35 {
36
37         gr_setcolor( CWHITE );
38         gr_urect( x1+1, y1+1, x2-1, y2-1 );
39
40         ui_draw_shad( x1+0, y1+0, x2-0, y2-0, CGREY, CBRIGHT );
41 }
42
43
44 void ui_draw_icon( UI_GADGET_ICON * icon )
45 {
46         int height, width, avg;
47         int x, y;
48         
49         
50         if ((icon->status==1) || (icon->position != icon->oldposition))
51         {
52                 icon->status = 0;
53
54                 ui_mouse_hide();
55         
56                 gr_set_current_canvas( icon->canvas );
57                 gr_get_string_size(icon->text, &width, &height, &avg );
58         
59                 x = ((icon->width-1)/2)-((width-1)/2);
60                 y = ((icon->height-1)/2)-((height-1)/2);
61
62                 if (icon->position==1 )
63                 {
64                         // Draw pressed
65                         ui_draw_box_in( 0, 0, icon->width, icon->height );
66                         x += 2; y += 2;
67                 }
68                 else if (icon->flag)
69                 {
70                         // Draw part out
71                         ui_draw_box_in1( 0, 0, icon->width, icon->height );
72                         x += 1; y += 1; 
73                 }
74                 else
75                 {
76                         // Draw released!
77                         ui_draw_box_out( 0, 0, icon->width, icon->height );
78                 }
79         
80                 gr_set_fontcolor( CBLACK, -1 );         
81                 gr_ustring( x, y, icon->text );
82
83                 ui_mouse_show();
84         }
85 }
86
87
88 UI_GADGET_ICON * ui_add_gadget_icon( UI_WINDOW * wnd, char * text, short x, short y, short w, short h, int k,int (*f)(void) )
89 {
90         UI_GADGET_ICON * icon;
91
92         icon = (UI_GADGET_ICON *)ui_gadget_add( wnd, 9, x, y, x+w-1, y+h-1 );
93
94         icon->width = w;
95         icon->height = h;
96         MALLOC( icon->text, char, strlen( text )+2);
97         strcpy( icon->text, text );
98         icon->trap_key = k;
99         icon->user_function = f;
100         icon->oldposition = 0;
101         icon->position = 0;
102         icon->pressed = 0;
103         icon->canvas->cv_font = ui_small_font;
104
105         // Call twice to get original;
106         if (f)
107         {
108                 icon->flag = (byte)f();
109                 icon->flag = (byte)f();
110         } else {
111                 icon->flag = 0;
112         }
113
114
115         return icon;
116
117 }
118
119 void ui_icon_do( UI_GADGET_ICON * icon, int keypress )
120 {
121         int OnMe;
122
123         OnMe = ui_mouse_on_gadget( (UI_GADGET *)icon );
124
125         icon->oldposition = icon->position;
126
127         if ( B1_PRESSED && OnMe )
128         {
129                 icon->position = 1;
130         } else  {
131                 icon->position = 0;
132         }
133
134         icon->pressed = 0;
135
136         if ((icon->position==0) && (icon->oldposition==1) && OnMe )
137                 icon->pressed = 1;
138
139         if (icon->pressed == 1 || keypress==icon->trap_key )
140         {
141                 icon->status = 1;
142                 icon->flag = (byte)icon->user_function();
143                 if (keypress==icon->trap_key) last_keypress = 0;
144         }
145
146         ui_draw_icon( icon );
147
148 }