2 * $Logfile: /Freespace2/code/UI/UIMOUSE.cpp $
7 * Code for dealing with the mouse
10 * Revision 1.1 2002/05/03 03:28:11 root
14 * 2 10/07/98 10:54a Dave
17 * 1 10/07/98 10:51a Dave
19 * 10 4/12/98 5:31p Lawrance
20 * use timer_get_milliseconds() instead of gettime()
22 * 9 4/02/98 5:27p John
23 * Removed the mouse_count stuff that Hoffoss added.
24 * Still some problems with mose_up_count being used twice, but that is
27 * 8 4/02/98 5:05p Hoffoss
28 * Fixed a timestamp() I missed.
30 * 7 4/02/98 10:04a Adam
31 * Fixed UI mouse problems with buttons not registering correctly.
33 * 6 4/01/98 5:07p Hoffoss
34 * Changed mouse button handling for UI in order to track fast events
35 * (like button going down and released all between frames).
37 * 5 2/06/98 3:36p Hoffoss
38 * Made disabled buttons play failed sound if clicked on. This is now
39 * standard behavior for all UI buttons everywhere.
41 * 4 1/14/98 6:44p Hoffoss
42 * Massive changes to UI code. A lot cleaner and better now. Did all
43 * this to get the new UI_DOT_SLIDER to work properly, which the old code
44 * wasn't flexible enough to handle.
46 * 3 12/02/96 2:17p John
47 * Made right button drag UI gadgets around and
48 * Ctrl+Shift+Alt+F12 dumps out where they are.
50 * 2 11/15/96 11:43a John
52 * 1 11/14/96 6:55p John
63 int ui_mouse_inited = 0;
65 void ui_mouse_process()
69 if (!ui_mouse_inited) {
75 ui_mouse.b1_status = 0;
76 ui_mouse.b1_last_status = 0;
77 ui_mouse.b1_time_lastpressed=0;
78 ui_mouse.b2_status = 0;
79 ui_mouse.b2_last_status = 0;
80 ui_mouse.b2_time_lastpressed = 0;
81 ui_mouse.timestamp = timer_get_milliseconds();
84 buttons = mouse_get_pos( &ui_mouse.x, &ui_mouse.y );
86 // check if mouse pressed
87 if (buttons & MOUSE_LEFT_BUTTON)
88 ui_mouse.b1_status = BUTTON_PRESSED;
90 ui_mouse.b1_status = BUTTON_RELEASED;
92 if (buttons & MOUSE_RIGHT_BUTTON)
93 ui_mouse.b2_status = BUTTON_PRESSED;
95 ui_mouse.b2_status = BUTTON_RELEASED;
97 // now check if we missed something between checks, just in case
98 if (mouse_down_count(MOUSE_LEFT_BUTTON))
99 ui_mouse.b1_status = BUTTON_PRESSED;
101 if (mouse_up_count(MOUSE_LEFT_BUTTON))
102 ui_mouse.b1_status = BUTTON_RELEASED;
104 if (mouse_down_count(MOUSE_RIGHT_BUTTON))
105 ui_mouse.b2_status = BUTTON_PRESSED;
107 if (mouse_up_count(MOUSE_RIGHT_BUTTON))
108 ui_mouse.b2_status = BUTTON_RELEASED;
110 // check for double clicks
111 if ((ui_mouse.b1_status & BUTTON_PRESSED) && (ui_mouse.b1_last_status & BUTTON_RELEASED) ) {
112 if ( timer_get_milliseconds() <= ui_mouse.b1_time_lastpressed + 250 ) //&& (ui_mouse.moved==0)
113 ui_mouse.b1_status |= BUTTON_DOUBLE_CLICKED;
115 ui_mouse.b1_time_lastpressed = timer_get_milliseconds();
116 ui_mouse.b1_status |= BUTTON_JUST_PRESSED;
118 } else if ((ui_mouse.b1_status & BUTTON_RELEASED) && (ui_mouse.b1_last_status & BUTTON_PRESSED) )
119 ui_mouse.b1_status |= BUTTON_JUST_RELEASED;
121 if ((ui_mouse.b2_status & BUTTON_PRESSED) && (ui_mouse.b2_last_status & BUTTON_RELEASED) ) {
122 if ( timer_get_milliseconds() <= ui_mouse.b2_time_lastpressed + 250 ) //&& (ui_mouse.moved==0)
123 ui_mouse.b2_status |= BUTTON_DOUBLE_CLICKED;
125 ui_mouse.b2_time_lastpressed = timer_get_milliseconds();
126 ui_mouse.b2_status |= BUTTON_JUST_PRESSED;
128 } else if ((ui_mouse.b2_status & BUTTON_RELEASED) && (ui_mouse.b2_last_status & BUTTON_PRESSED) )
129 ui_mouse.b2_status |= BUTTON_JUST_RELEASED;
131 ui_mouse.b1_last_status = ui_mouse.b1_status;
132 ui_mouse.b2_last_status = ui_mouse.b2_status;