]> icculus.org git repositories - taylor/freespace2.git/blob - src/ui/uimouse.cpp
fix event and state help text
[taylor/freespace2.git] / src / ui / uimouse.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/UI/UIMOUSE.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Code for dealing with the mouse
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:29  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:53  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:11  root
25  * Initial import.
26  *
27  * 
28  * 2     10/07/98 10:54a Dave
29  * Initial checkin.
30  * 
31  * 1     10/07/98 10:51a Dave
32  * 
33  * 10    4/12/98 5:31p Lawrance
34  * use timer_get_milliseconds() instead of gettime()
35  * 
36  * 9     4/02/98 5:27p John
37  * Removed the mouse_count stuff that Hoffoss added.
38  * Still some problems with mose_up_count being used twice, but that is
39  * easily fixed.
40  * 
41  * 8     4/02/98 5:05p Hoffoss
42  * Fixed a timestamp() I missed.
43  * 
44  * 7     4/02/98 10:04a Adam
45  * Fixed UI mouse problems with buttons not registering correctly.
46  * 
47  * 6     4/01/98 5:07p Hoffoss
48  * Changed mouse button handling for UI in order to track fast events
49  * (like button going down and released all between frames).
50  * 
51  * 5     2/06/98 3:36p Hoffoss
52  * Made disabled buttons play failed sound if clicked on.  This is now
53  * standard behavior for all UI buttons everywhere.
54  * 
55  * 4     1/14/98 6:44p Hoffoss
56  * Massive changes to UI code.  A lot cleaner and better now.  Did all
57  * this to get the new UI_DOT_SLIDER to work properly, which the old code
58  * wasn't flexible enough to handle.
59  * 
60  * 3     12/02/96 2:17p John
61  * Made right button drag UI gadgets around and
62  * Ctrl+Shift+Alt+F12 dumps out where they are.
63  * 
64  * 2     11/15/96 11:43a John
65  * 
66  * 1     11/14/96 6:55p John
67  *
68  * $NoKeywords: $
69  */
70
71 #include "uidefs.h"
72 #include "ui.h"
73 #include "timer.h"
74
75 UI_MOUSE ui_mouse;
76
77 int ui_mouse_inited = 0;
78
79 void ui_mouse_process()
80 {
81         int buttons;
82
83         if (!ui_mouse_inited) {
84                 ui_mouse_inited = 1;
85                 ui_mouse.x = 0;
86                 ui_mouse.y = 0;
87                 ui_mouse.dx = 0;
88                 ui_mouse.dy = 0;
89                 ui_mouse.b1_status = 0;
90                 ui_mouse.b1_last_status = 0;
91                 ui_mouse.b1_time_lastpressed=0;
92                 ui_mouse.b2_status = 0;
93                 ui_mouse.b2_last_status = 0;
94                 ui_mouse.b2_time_lastpressed = 0;
95                 ui_mouse.timestamp = timer_get_milliseconds();
96         }
97
98         buttons = mouse_get_pos( &ui_mouse.x, &ui_mouse.y );
99
100         // check if mouse pressed
101         if (buttons & MOUSE_LEFT_BUTTON)
102                 ui_mouse.b1_status = BUTTON_PRESSED;
103         else
104                 ui_mouse.b1_status = BUTTON_RELEASED;
105
106         if (buttons & MOUSE_RIGHT_BUTTON)
107                 ui_mouse.b2_status = BUTTON_PRESSED;
108         else
109                 ui_mouse.b2_status = BUTTON_RELEASED;
110
111         // now check if we missed something between checks, just in case
112         if (mouse_down_count(MOUSE_LEFT_BUTTON))
113                 ui_mouse.b1_status = BUTTON_PRESSED;
114
115         if (mouse_up_count(MOUSE_LEFT_BUTTON))
116                 ui_mouse.b1_status = BUTTON_RELEASED;
117
118         if (mouse_down_count(MOUSE_RIGHT_BUTTON))
119                 ui_mouse.b2_status = BUTTON_PRESSED;
120
121         if (mouse_up_count(MOUSE_RIGHT_BUTTON))
122                 ui_mouse.b2_status = BUTTON_RELEASED;
123
124         // check for double clicks
125         if ((ui_mouse.b1_status & BUTTON_PRESSED) && (ui_mouse.b1_last_status & BUTTON_RELEASED) ) {
126                 if ( timer_get_milliseconds() <= ui_mouse.b1_time_lastpressed + 250 )  //&& (ui_mouse.moved==0)
127                         ui_mouse.b1_status |= BUTTON_DOUBLE_CLICKED;
128
129                 ui_mouse.b1_time_lastpressed = timer_get_milliseconds();
130                 ui_mouse.b1_status |= BUTTON_JUST_PRESSED;
131
132         } else if ((ui_mouse.b1_status & BUTTON_RELEASED) && (ui_mouse.b1_last_status & BUTTON_PRESSED) )
133                 ui_mouse.b1_status |= BUTTON_JUST_RELEASED;
134
135         if ((ui_mouse.b2_status & BUTTON_PRESSED) && (ui_mouse.b2_last_status & BUTTON_RELEASED) ) {
136                 if ( timer_get_milliseconds() <= ui_mouse.b2_time_lastpressed + 250 )  //&& (ui_mouse.moved==0)
137                         ui_mouse.b2_status |= BUTTON_DOUBLE_CLICKED;
138
139                 ui_mouse.b2_time_lastpressed = timer_get_milliseconds();
140                 ui_mouse.b2_status |= BUTTON_JUST_PRESSED;
141
142         } else if ((ui_mouse.b2_status & BUTTON_RELEASED) && (ui_mouse.b2_last_status & BUTTON_PRESSED) )
143                 ui_mouse.b2_status |= BUTTON_JUST_RELEASED;
144
145         ui_mouse.b1_last_status = ui_mouse.b1_status;
146         ui_mouse.b2_last_status = ui_mouse.b2_status;
147 }
148