/* * games/_shared/ - shared routines for games * * mouse-win32.c - Win32 mouse handler * ____________________________________________________________ * * Developed by Ondrej Jombik * Copyright (c) 2003-2004 Platon SDG, http://platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://platon.sk/projects/games/ * * Changelog: * 2003-06-23 - created */ /* $Platon: games/_shared/mouse-win32.c,v 1.3 2003/10/27 09:52:10 nepto Exp $ */ #include #include #include "mouse.h" #define MOUSE_WIN32_DEBUG 0 static int mouse_x, mouse_y, mouse_bstat; static int pressed_count[3], released_count[3]; static void mouse_status_update(void) /* {{{ */ { register int bstat_diff = 0; /* Clearing double-click events */ if (ismouseclick(WM_LBUTTONDBLCLK)) clearmouseclick(WM_LBUTTONDBLCLK); if (ismouseclick(WM_RBUTTONDBLCLK)) clearmouseclick(WM_RBUTTONDBLCLK); if (ismouseclick(WM_MBUTTONDBLCLK)) clearmouseclick(WM_MBUTTONDBLCLK); /* Mouse mouse */ if (ismouseclick(WM_MOUSEMOVE)) { getmouseclick(WM_MOUSEMOVE, mouse_x, mouse_y); mouse_x = max(0, mouse_x); mouse_y = max(0, mouse_y); } /* Mouse button press */ if (ismouseclick(WM_LBUTTONDOWN)) { clearmouseclick(WM_LBUTTONDOWN); pressed_count[0]++; bstat_diff += 1; } if (ismouseclick(WM_RBUTTONDOWN)) { clearmouseclick(WM_RBUTTONDOWN); pressed_count[1]++; bstat_diff += 2; } if (ismouseclick(WM_MBUTTONDOWN)) { clearmouseclick(WM_MBUTTONDOWN); pressed_count[2]++; bstat_diff += 3; } /* Mouse button release */ if (ismouseclick(WM_LBUTTONUP)) { clearmouseclick(WM_LBUTTONUP); released_count[0]++; bstat_diff -= 1; } if (ismouseclick(WM_RBUTTONUP)) { clearmouseclick(WM_RBUTTONUP); released_count[1]++; bstat_diff -= 2; } if (ismouseclick(WM_MBUTTONUP)) { clearmouseclick(WM_MBUTTONUP); released_count[2]++; bstat_diff -= 3; } #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG if (bstat_diff != 0) fprintf(stderr, __FILE__ ": mouse_status_update(): [1] mouse_bstat = %d, bstat_diff = %d\n", mouse_bstat, bstat_diff); #endif /* Buttons status counting */ bstat_diff %= 3; mouse_bstat += bstat_diff; mouse_bstat = min(3, mouse_bstat); mouse_bstat = max(0, mouse_bstat); #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG if (bstat_diff != 0) fprintf(stderr, __FILE__ ": mouse_status_update(): [2] mouse_bstat = %d\n", mouse_bstat); #endif } /* }}} */ BYTE initmouse(void) /* {{{ */ { #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG fprintf(stderr, __FILE__ ": initmouse(): mouse initialized\n"); #endif return 2; /* always return 2 buttons available */ } /* }}} */ void showmouse(void) /* {{{ */ { return; /* simply do nothing */ } /* }}} */ void hidemouse(void) /* {{{ */ { return; /* simply do nothing */ } /* }}} */ BYTE getmousepos(WORD *x, WORD *y) /* {{{ */ { mouse_status_update(); if (x != NULL) *x = (WORD) mouse_x; if (y != NULL) *y = (WORD) mouse_y; #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG fprintf(stderr, __FILE__ ": getmousepos(%u, %u) = %d\n", mouse_x, mouse_y, mouse_bstat); #endif return mouse_bstat; } /* }}} */ void setmousepos(WORD x, WORD y) /* {{{ */ { x = x; y = y; /* it is not possible to set up mouse position under Win32 */ return; } /* }}} */ BYTE pressbutton(BYTE but, WORD *x, WORD *y) /* {{{ */ { register BYTE ret; mouse_status_update(); if (but > 2) { ret = 0; } else { ret = pressed_count[but]; pressed_count[but] = 0; } if (x != NULL) *x = mouse_x; if (y != NULL) *y = mouse_y; #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG fprintf(stderr, __FILE__ ": pressbutton(%u, %u) = %d\n", mouse_x, mouse_y, ret); #endif return ret; } /* }}} */ BYTE releasebutton(BYTE but, WORD *x, WORD *y) /* {{{ */ { register BYTE ret; mouse_status_update(); if (but > 2) { ret = 0; } else { ret = released_count[but]; released_count[but] = 0; } if (x != NULL) *x = mouse_x; if (y != NULL) *y = mouse_y; #if defined(MOUSE_WIN32_DEBUG) && MOUSE_WIN32_DEBUG fprintf(stderr, __FILE__ ": releasebutton(%u, %u) = %d\n", mouse_x, mouse_y, ret); #endif return ret; } /* }}} */ void rangex(WORD a_min, WORD a_max) /* {{{ */ { a_min = a_min; a_max = a_max; return; } /* }}} */ void rangey(WORD a_min, WORD a_max) /* {{{ */ { a_min = a_min; a_max = a_max; return; } /* }}} */ void setmousecur(WORD x, WORD y, void*p) /* {{{ */ { x = x; y = y; p = p; return; } /* }}} */ void exclude(WORD x1, WORD y1, WORD x2, WORD y2) /* {{{ */ { x1 = x1; y1 = y1; x2 = x2; y2 = y2; return; } /* }}} */ void mousesensitive(WORD x, WORD y) /* {{{ */ { x = x; y = y; return; } /* }}} */ void setmousespeed(WORD speed) /* {{{ */ { speed = speed; return; } /* }}} */ /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */