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