// Copyright (c) SuperSpirit Studio, Superspirit
#ifndef xrh_mouse_liarbry #define XRH_MOUSE_LIARBRY
#include
INT far here_range = 2; // mouse Click Range Int Far Mouse_locked = 0; // Mouse Locked Switch 0-> Unlocked, 1-> Locked Int Far dbclick_delay = 6; // mouse double copy time 1 ==> 1 / 18.2 (s)
Struct mouse_status {
INT mouse_x; int mouse_button_status; // Time mouse button status // bit0- left button // bit1-right // bit2- 中 中 // 0-Release Status 1 - Press State} mouse_now_status;
struct Mouse_Event {int Mouse_x; int Mouse_y; int Which_Button; // 1 Left Button, 2 Right Button, 4 Middle int Event_ID;! // Event_ID = 0 Nothing Happend // Event_ID = 1 Mouse Moving // Event_ID = 2 Click Event. Happend. // Event_ID = 3 mouse Button Down. // Event_ID = 4 mouse Button Up. // Event_ID = 5 Double Click Event Happend. Unsigned button_status;};
// mouse_event far event [mouse_max_event] = {0,0,0}; // Event Stack TO RESTORE 3 Event Maxium.
Mouse_Event Far Event = {0, 0, 0, 0, 0}; // INT FAR FULL = 0, EMPTY = 1; // Full = 1, Event Full; Empty = 1, Event Empty. // Int Far Event_Start = 0, EVENT_END = 0; // int far mouse_button_num = 0; unsigned long far click_time [3] = {0,0,0}; unsigned long far * time_p_ = (unsigned long far *) 0x0000046cl); // can not ? Load * Time_p_ Correctly And Get Right Data, I Do not Know Why int far OldEvent = 0; int far User_App_Running = 0; unsigned far Old_Event_Mask = 0; int far Old_M_x = -1, far Old_M_y = -2; int far DB_Old_x = -1, Far DB_OLD_Y = -2; // int far mouse = 0;
const unsigned far _Mouse_Move_ = 0x01, far _L_Button_Down_ = 0x02, far _L_Button_Up_ = 0x04; const unsigned far _R_Button_Down_ = 0x08, far _R_Button_Up_ = 0x10, far _M_Button_Down_ = 0x20; const unsigned far _M_Button_Up_ = 0x40; const unsigned far _Mouse_Nothing_ = 0, / * far _Mouse_Move_ = 1, * / far _Mouse_Button_Click_ = 2, far _Mouse_Button_Down_ = 3, far _Mouse_Button_Up_ = 4, far _Mouse_Button_DBclick_ = 5; const unsigned far _L_Button_ = 1, far _R_Button_ = 2, far _M_Button_ = 4;
Void far user_app (); // int far is_here (int X, int y, int X0, int y0);
INT FAR HAND_SHAPE [2] [16] = {0xF3FF, 0xE1FF, 0xE1FF, 0xE1FF, 0xE001, 0XE000, 0XE000, 0X00000000, 0X0000, 0x0000, 0X000000, 0X8001, 0XC003,
0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0X0DB6, 0x0DB6, 0X0DB6, 0x0DB6, 0X6FFE, 0x6ffe, 0x6ffe, 0x7ffe, 0x7ffe, 0x3FFC, 0x0000};
int far Arrow_Shape [2] [16] = {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,0x4000,0x6000,0x7000 0x7800, 0x7c00, 0x7e00, 0x7f00, 0x7c00, 0x4600, 0x0600, 0x0300, 0x0300, 0x0180}; int 4} [2] [16] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xfff, 0xfff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}, {0x0100,0x0fe0,0x0100,0x0100, 0x4104,0x4104,0x4104,0xfffe, 0x4104,0x4104,0x4104,0x0100, 0x0100,0x0fe0, 0x0100, 0x0000,}}; class mymouse {public: static int mymouse_object_num; private: regpack regs
static int Mouse; // 1 = Mouse Driver Exist, 0 = Mouse Driver Not Exist, Error static int Mouse_Button_Num;. // Number Of Your Mouse Button void Mouse_Setup_User_Application (void far User_App (), unsigned Event_Mask);. // hook User mouse interrupt handler // input parameters: AX = 0CH // CX = event shield (Event_mask) // bit0-mouse move // bit1-mouse left mouse button Press // bit2 - Mouse left mouse release // bit3-mouse Right click // bit4-mouse button to release // bit5 - mouse systems / logitech mouse) // bit6 - mouse center key release (mouse systems / logitech mouse) // All position 1 - Action action When the user program // DX = point to the remote pin of the interrupt subroutine // es = points to the long pointer of the interrupt subroutine: None // Note: When the subroutine is called, It will pass the following parameters: // AX = event (corresponding to defined event mask) // bx = button status // CX = Current mouse cursor x-axis coordinate // DX = Current Mouse Cursor y Alert // Si = Horizontal moving count increment (mickey) // di = vertical moving count increment (mickey) // Some versions of Microsoft drivers returned to errors -CX bit 0 indicate mouse movement / / and exchanged Si and Di content void mouse_unload_user_application (); public: static char mouse_cursor_visible; // void far user_app (); int mouse_reset (); // Detect and Reset Mouse Driver mouse_Event Now_Event;. / * Contain the mouse event and position, very important, We get Mouse Event From this global variable * / void Mouse_Show_Cursor (); void Mouse_Hide_Cursor (); void Mouse_Get_Status (Mouse_Status & Status; void mouse_move_cursor (int x, int y); int mouse_get_event (); void mouse_setup_cursor (int mode_num = 0);
// 2 -> AIM_SHAPE; 1-> Hand_Shape; 0-> arrow_shape mymouse (); ~ mymouse ();}; char mymouse :: mouse_cursor_visible = 2; int mymouse :: mouse_object_num = 0; int mymouse :: mouse = 0 INT mymouse :: mouse_button_num = 0; void mymouse :: mouse_setup_cursor (int mode_num) {regs.r_ax = 9; switch (Mode_Num) {Case 2: regs.r_bx = 7; regs.r_cx = 7; regs. R_dx = fp_off (& :: AIM_SHAPE); regs.r_es = fp_seg (& :: AIM_SHAPE); Break; Case 1: regs.r_bx = 4; regs.r_cx = 0; regs.r_dx = fp_off (& :: hand_shape) ; Regs.r_es = fp_seg (& :: Hand_Shape); break; case 0: default: regs.r_bx = 0; regs.r_cx = 0; regs.r_dx = fp_off (& :: arrow_shape); regs.r_es = fp_seg & :: arrow_shape); Break;} INTR (Mouse_Interrupt, & regs); Return;}
int MyMouse :: Mouse_Reset () // Detect And Reset Mouse Driver {REGPACK regs;. regs.r_ax = 0x0000; intr (MOUSE_INTERRUPT, & regs); if (regs.r_ax == 0xffff) {Mouse = 1; Mouse_Button_Num = regs. R_bx;} else mouse = 0;
Return mouse;}
/ * Int mymouse :: mouse_reset () {regs.r_ax = 0x0000; INTR (mouse_interrupt, & regs); if (regs.r_ax == 0xffffff) {mouse_button_num = regs.r_bx; return 1;}
Else {mouse_button_num = 0; return 0;}} * /
Void mymouse :: mouse_show_cursor () {// if (mouse_cursor_visible == 1) return;
IF (mouse) {regs.r_ax = 0x0001; INTR (mouse_interrupt, & regs);} mouse_cursor_visible = 1;}
void MyMouse :: Mouse_Hide_Cursor () {// if (! Mouse_Cursor_Visible) return; if (Mouse) {regs.r_ax = 0x0002; intr (MOUSE_INTERRUPT, & regs);} Mouse_Cursor_Visible = 0;} void MyMouse :: Mouse_Get_Status (Mouse_Status & Status) {If (mouse) {regs.r_ax = 0x0003; INTR (mouse_interrupt, & regs); status.mouse_x = regs.r_cx; status.mouse_y = regs.r_dx; status.mouse_button_status = regs.r_bx & 0x0007;}}
void MyMouse :: Mouse_Setup_User_Application (void far User_App (), unsigned Event_Mask) {REGPACK regs; if (Mouse) {unsigned Sega = FP_SEG (User_App), Offa = FP_OFF (User_App); regs.r_ax = 0x000c; regs.r_cx = Event_Mask ; // 0x1f; regs.r_dx = OFFA; regs.r_ES = sega; INTR (mouse_interrupt, & regs); // regs.r_ax = 0x0003; // INTR (mouse_interrupt, & regs); // mouse_get_status;}}
Void mymouse :: mouse_unload_user_application ()
{Regpack regs;
IF (mouse) {regs.r_ax = 0x000c; regs.r_cx = 0; INTR (mouse_interrupt, & regs);}
}
Void mymouse :: mouse_move_cursor (mouse) {regs.r_ax = 0x0004; regs.r_cx = x; regs.r_dx = y; INTR (mouse_interrupt, & regs);}}
INT mymouse :: mouse_get_event () {now_event = :: Event; (:: Event). Event_ID = 0; Return now_event.event_id;}
MyMouse :: mymouse () {if (! Mymouse_Object_num) {mouse_reset (); if (! Mouse) {
// ClrsCr (); Printf ("/ N Mouse Driver Not Found, Installing A Microsoft Mouse Driver, please!"); exit (0);}
Mouse_Setup_User_Application (:: User_App, 0x1F); // Mouse_Setup_Cursor (1);} MyMouse_Object_Num ; Now_Event.Event_ID = 0; :: Click_Time [0] = :: Click_Time [1] = :: Click_Time [2] = 0; return; }
MyMouse :: ~ mymouse () {mymouse_object_num--; if (! Mymouse_object_num) mouse_unload_user_application (); Return;}
/ * Int 4, int x, int x = 0, y = 0; x = x-x0; y = y-y0; if (x <0) x = -x ; If (y <0) y = -y; if (-here_range <= x && x <= here_range && - here_range <= y && y <= here_range) return 1; return 0;} * / void far user_app () {unsigned mevent = _ax , MSTATUS = _BX; int mx = _cx, my = _dx;
IF (user_app_running) return; if (mouse_locked) return;
// OldEvent = 2; /*if (Event.event_id==2) OldEvent = event.event_id; * /
User_app_running = 1;
Unsigned long newtime;
if (Mevent & _Mouse_Move_) {Event.Event_ID = _Mouse_Move_; Event.Mouse_x = Mx; Event.Mouse_y = My; Event.Button_Status = Mstatus; User_App_Running = 0; return;} else {if (Mevent & _L_Button_Down_) {Event.Event_ID = _Mouse_Button_Down_; Event .Mouse_x = mx; event.mouse_y = my; OLD_M_Y = Event.mouse_y; Event.Button_Status = MSTATUS; Event.Which_Button = _l_button_;
OLD_EVENT_MASK = Mevent; OLD_M_Y = MX; OLD_M_X = MX;
User_App_running = 0; return;}
if (Mevent & _R_Button_Down_) {Event.Event_ID = _Mouse_Button_Down_; Event.Mouse_x = Mx; Event.Mouse_y = My; Event.Button_Status = Mstatus; Event.Which_Button = _R_Button_; Old_Event_Mask = Mevent; Old_M_y = My; Old_M_x = Mx;
User_App_running = 0; Return;
}
IF (Mevent & _M_Button_Down_) {event.event_id = _mouse_button_down_; event.mouse_x = mx; event.mouse_y = my; event.button_status = mStatus; Event.Which_Button = _m_button_;
OLD_EVENT_MASK = Mevent; OLD_M_Y = MX; OLD_M_X = MX;
User_App_running = 0; Return;
}
if (Mevent & _L_Button_Up_) {if (Old_Event_Mask & _L_Button_Down _ && Is_Here (Mx, My, Old_M_x, Old_M_y)) // && Old_M_x == Mx && Old_M_y == My) {NewTime = * ((unsigned long far *) 0x0000046cl); if (OldEvent == 2 && (( NewTime-Click_Time [0]) <= DBclick_Delay) && Is_Here (Mx, My, DB_Old_x, DB_Old_y)) {Event.Event_ID = _Mouse_Button_DBclick_; Click_Time [0] = 0; OldEvent = 0;} else {Event.Event_ID = _Mouse_Button_Click_ ;: : Click_time [0] = newtime; Oldevent = 2; db_old_x = mx; db_old_y = my;}
} Else evenet.event_id = _mouse_button_up_;
OLD_EVENT_MASK = 0;
Event.mouse_x = mx; event.mouse_y = my; event.button_status = mstatus; event.which_button = _l_button_; user_app_running = 0; Return;}
if (Mevent & _R_Button_Up_) {if (Old_Event_Mask & _R_Button_Down _ && Is_Here (Mx, My, Old_M_x, Old_M_y)) // Old_M_x == Mx && Old_M_y == My) {/ * Event.Event_ID = _Mouse_Button_Click_; * / NewTime = * ((unsigned long far *) 0x0000046cl ); if (OldEvent == 2 && ((NewTime-Click_Time [1]) <= DBclick_Delay) && Is_Here (Mx, My, DB_Old_x, DB_Old_y)) {Event.Event_ID = _Mouse_Button_DBclick_; Click_Time [1] = 0; OldEvent = 0; } else {Event.Event_ID = _Mouse_Button_Click_; Click_Time [1] = NewTime; OldEvent = 2; DB_Old_x = Mx; DB_Old_y = My;}} else Event.Event_ID = _Mouse_Button_Up_; Old_Event_Mask = 0;
Event.mouse_x = mx; event.mouse_y = my; event.button_status = mstatus; Event.Which_Button = _r_button_; user_app_running = 0; Return;}
if (Mevent & _M_Button_Up_) {if (Old_Event_Mask & _M_Button_Down _ && Is_Here (Mx, My, Old_M_x, Old_M_y)) // Old_M_x == Mx && Old_M_y == My) {/*Event.Event_ID=_Mouse_Button_Click_;*/ NewTime = * ((unsigned long far *) 0x0000046cl ); if (OldEvent == 2 && ((NewTime-Click_Time [2]) <= DBclick_Delay) && Is_Here (Mx, My, DB_Old_x, DB_Old_y)) {Event.Event_ID = _Mouse_Button_DBclick_; Click_Time [2] = 0; OldEvent = 0; } Else {event.event_id = _mouse_button_click_; click_time [2] = newtime; OldEvent = 2; DB_OLD_X = MX; DB_OLD_Y = my;}} else evenet.event_id = _mouse_button_up_;
OLD_EVENT_MASK = 0;
Event.mouse_x = mx; event.mouse_y = my; event.button_status = mstatus; event.which_button = _m_button_; user_app_running = 0; Return;}}} #endif