2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/UI/UIMOUSE.cpp $
15 * Code for dealing with the mouse
18 * Revision 1.3 2002/06/09 04:41:29 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:53 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:11 root
28 * 2 10/07/98 10:54a Dave
31 * 1 10/07/98 10:51a Dave
33 * 10 4/12/98 5:31p Lawrance
34 * use timer_get_milliseconds() instead of gettime()
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
41 * 8 4/02/98 5:05p Hoffoss
42 * Fixed a timestamp() I missed.
44 * 7 4/02/98 10:04a Adam
45 * Fixed UI mouse problems with buttons not registering correctly.
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).
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.
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.
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.
64 * 2 11/15/96 11:43a John
66 * 1 11/14/96 6:55p John
77 int ui_mouse_inited = 0;
79 void ui_mouse_process()
83 if (!ui_mouse_inited) {
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();
98 buttons = mouse_get_pos( &ui_mouse.x, &ui_mouse.y );
100 // check if mouse pressed
101 if (buttons & MOUSE_LEFT_BUTTON)
102 ui_mouse.b1_status = BUTTON_PRESSED;
104 ui_mouse.b1_status = BUTTON_RELEASED;
106 if (buttons & MOUSE_RIGHT_BUTTON)
107 ui_mouse.b2_status = BUTTON_PRESSED;
109 ui_mouse.b2_status = BUTTON_RELEASED;
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;
115 if (mouse_up_count(MOUSE_LEFT_BUTTON))
116 ui_mouse.b1_status = BUTTON_RELEASED;
118 if (mouse_down_count(MOUSE_RIGHT_BUTTON))
119 ui_mouse.b2_status = BUTTON_PRESSED;
121 if (mouse_up_count(MOUSE_RIGHT_BUTTON))
122 ui_mouse.b2_status = BUTTON_RELEASED;
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;
129 ui_mouse.b1_time_lastpressed = timer_get_milliseconds();
130 ui_mouse.b1_status |= BUTTON_JUST_PRESSED;
132 } else if ((ui_mouse.b1_status & BUTTON_RELEASED) && (ui_mouse.b1_last_status & BUTTON_PRESSED) )
133 ui_mouse.b1_status |= BUTTON_JUST_RELEASED;
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;
139 ui_mouse.b2_time_lastpressed = timer_get_milliseconds();
140 ui_mouse.b2_status |= BUTTON_JUST_PRESSED;
142 } else if ((ui_mouse.b2_status & BUTTON_RELEASED) && (ui_mouse.b2_last_status & BUTTON_PRESSED) )
143 ui_mouse.b2_status |= BUTTON_JUST_RELEASED;
145 ui_mouse.b1_last_status = ui_mouse.b1_status;
146 ui_mouse.b2_last_status = ui_mouse.b2_status;