get rid of compiler warnings
[btb/d2x.git] / ui / userbox.c
1 /* $Id: userbox.c,v 1.4 2005-01-24 22:19:10 schaffner Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 #ifdef RCS
16 static char rcsid[] = "$Id: userbox.c,v 1.4 2005-01-24 22:19:10 schaffner Exp $";
17 #endif
18
19 #ifdef HAVE_CONFIG_H
20 #include "conf.h"
21 #endif
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "fix.h"
27 #include "pstypes.h"
28 #include "gr.h"
29 #include "ui.h"
30 #include "key.h"
31
32 void ui_draw_userbox( UI_GADGET_USERBOX * userbox )
33 {
34
35         if ( userbox->status==1 )
36         {
37                 userbox->status = 0;
38
39                 ui_mouse_hide();
40                 gr_set_current_canvas( userbox->canvas );
41
42                 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)userbox)
43                         gr_setcolor( CRED );
44                 else
45                         gr_setcolor( CBRIGHT );
46
47                 gr_box( -1, -1, userbox->width, userbox->height );
48
49                 ui_mouse_show();
50         }
51 }
52
53
54 UI_GADGET_USERBOX * ui_add_gadget_userbox( UI_WINDOW * wnd, short x, short y, short w, short h )
55 {
56         UI_GADGET_USERBOX * userbox;
57
58         userbox = (UI_GADGET_USERBOX *)ui_gadget_add( wnd, 7, x, y, x+w-1, y+h-1 );
59
60         userbox->width = w;
61         userbox->height = h;
62         userbox->b1_held_down=0;
63         userbox->b1_clicked=0;
64         userbox->b1_double_clicked=0;
65         userbox->b1_dragging=0;
66         userbox->b1_drag_x1=0;
67         userbox->b1_drag_y1=0;
68         userbox->b1_drag_x2=0;
69         userbox->b1_drag_y2=0;
70         userbox->b1_done_dragging = 0;
71         userbox->keypress = 0;
72         userbox->mouse_onme = 0;
73         userbox->mouse_x = 0;
74         userbox->mouse_y = 0;
75         userbox->bitmap = &(userbox->canvas->cv_bitmap);
76
77         return userbox;
78
79 }
80
81 void ui_userbox_do( UI_GADGET_USERBOX * userbox, int keypress )
82 {
83         int OnMe, olddrag;
84
85         OnMe = ui_mouse_on_gadget( (UI_GADGET *)userbox );
86
87         olddrag  = userbox->b1_dragging;
88
89         userbox->mouse_onme = OnMe;
90         userbox->mouse_x = Mouse.x - userbox->x1;
91         userbox->mouse_y = Mouse.y - userbox->y1;
92
93         userbox->b1_clicked = 0;
94
95         if (OnMe)
96         {
97                 if ( B1_JUST_PRESSED )
98                 {
99                         userbox->b1_dragging = 1;
100                         userbox->b1_drag_x1 = Mouse.x - userbox->x1;
101                         userbox->b1_drag_y1 = Mouse.y - userbox->y1;
102                         userbox->b1_clicked = 1;
103                 }
104
105                 if ( B1_PRESSED )
106                 {
107                         userbox->b1_held_down = 1;
108                         userbox->b1_drag_x2 = Mouse.x - userbox->x1;
109                         userbox->b1_drag_y2 = Mouse.y - userbox->y1;
110                 }
111                 else    {
112                         userbox->b1_held_down = 0;
113                         userbox->b1_dragging = 0;
114                 }
115
116                 if ( B1_DOUBLE_CLICKED )
117                         userbox->b1_double_clicked = 1;
118                 else
119                         userbox->b1_double_clicked = 0;
120
121         }
122
123         if (!B1_PRESSED)
124                 userbox->b1_dragging = 0;
125
126         userbox->b1_done_dragging = 0;
127
128         if (olddrag==1 && userbox->b1_dragging==0 )
129         {
130                 if ((userbox->b1_drag_x1 !=  userbox->b1_drag_x2) || (userbox->b1_drag_y1 !=  userbox->b1_drag_y2) )
131                         userbox->b1_done_dragging = 1;
132         }
133
134         if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)userbox)
135                 userbox->keypress = keypress;
136
137         ui_draw_userbox( userbox );
138
139 }
140
141
142
143
144