added d2demo.mn2
[btb/d2x.git] / unused / ui / userbox.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 #pragma off (unreferenced)
15 static char rcsid[] = "$Id: userbox.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
16 #pragma on (unreferenced)
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "fix.h"
21 #include "types.h"
22 #include "gr.h"
23 #include "ui.h"
24 #include "key.h"
25
26 void ui_draw_userbox( UI_GADGET_USERBOX * userbox )
27 {
28
29         if ( userbox->status==1 )
30         {
31                 userbox->status = 0;
32
33                 ui_mouse_hide();
34                 gr_set_current_canvas( userbox->canvas );
35
36                 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)userbox)
37                         gr_setcolor( CRED );
38                 else
39                         gr_setcolor( CBRIGHT );
40
41                 gr_box( -1, -1, userbox->width, userbox->height );
42
43                 ui_mouse_show();
44         }
45 }
46
47
48 UI_GADGET_USERBOX * ui_add_gadget_userbox( UI_WINDOW * wnd, short x, short y, short w, short h )
49 {
50         UI_GADGET_USERBOX * userbox;
51
52         userbox = (UI_GADGET_USERBOX *)ui_gadget_add( wnd, 7, x, y, x+w-1, y+h-1 );
53
54         userbox->width = w;
55         userbox->height = h;
56         userbox->b1_held_down=0;
57         userbox->b1_clicked=0;
58         userbox->b1_double_clicked=0;
59         userbox->b1_dragging=0;
60         userbox->b1_drag_x1=0;
61         userbox->b1_drag_y1=0;
62         userbox->b1_drag_x2=0;
63         userbox->b1_drag_y2=0;
64         userbox->b1_done_dragging = 0;
65         userbox->keypress = 0;
66         userbox->mouse_onme = 0;
67         userbox->mouse_x = 0;
68         userbox->mouse_y = 0;
69         userbox->bitmap = &(userbox->canvas->cv_bitmap);
70
71         return userbox;
72
73 }
74
75 void ui_userbox_do( UI_GADGET_USERBOX * userbox, int keypress )
76 {
77         int OnMe, olddrag;
78
79         OnMe = ui_mouse_on_gadget( (UI_GADGET *)userbox );
80
81         olddrag  = userbox->b1_dragging;
82
83         userbox->mouse_onme = OnMe;
84         userbox->mouse_x = Mouse.x - userbox->x1;
85         userbox->mouse_y = Mouse.y - userbox->y1;
86
87         userbox->b1_clicked = 0;
88
89         if (OnMe)
90         {
91                 if ( B1_JUST_PRESSED )
92                 {
93                         userbox->b1_dragging = 1;
94                         userbox->b1_drag_x1 = Mouse.x - userbox->x1;
95                         userbox->b1_drag_y1 = Mouse.y - userbox->y1;
96                         userbox->b1_clicked = 1;
97                 }
98
99                 if ( B1_PRESSED )
100                 {
101                         userbox->b1_held_down = 1;
102                         userbox->b1_drag_x2 = Mouse.x - userbox->x1;
103                         userbox->b1_drag_y2 = Mouse.y - userbox->y1;
104                 }
105                 else    {
106                         userbox->b1_held_down = 0;
107                         userbox->b1_dragging = 0;
108                 }
109
110                 if ( B1_DOUBLE_CLICKED )
111                         userbox->b1_double_clicked = 1;
112                 else
113                         userbox->b1_double_clicked = 0;
114
115         }
116
117         if (!B1_PRESSED)
118                 userbox->b1_dragging = 0;
119
120         userbox->b1_done_dragging = 0;
121
122         if (olddrag==1 && userbox->b1_dragging==0 )
123         {
124                 if ((userbox->b1_drag_x1 !=  userbox->b1_drag_x2) || (userbox->b1_drag_y1 !=  userbox->b1_drag_y2) )
125                         userbox->b1_done_dragging = 1;
126         }
127
128         if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)userbox)
129                 userbox->keypress = keypress;
130
131         ui_draw_userbox( userbox );
132
133 }
134
135
136
137
138