/* * games/_shared/ - shared routines for games * * mouse-svgalib.c - SVGAlib 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-05-04 - created */ /* $Platon: games/_shared/mouse-svgalib.c,v 1.5 2003/10/07 12:22:43 nepto Exp $ */ #include #include #include #include #include #include "mouse.h" static int mouse_showed, mousex, mousey, mouse_bstat; static int pressed_count[3], released_count[3]; static char mouse_bitmap[11 * 11 * 4]; /* big enough for 11x11 bitmap in any mode */ void mouse_status_update(void) /* {{{ */ { while (mouse_update()) { register int svgalib_mouse_bstat; int tmpx, tmpy, tmp_bstat; /* int wheel = 0, rx = 0; // TODO: support for wheel */ /* The RX axis represents the wheel on an wheel mouse */ mouse_getposition_6d(&tmpx, &tmpy, NULL, NULL /* &rx */, NULL, NULL); if (tmpx != mousex || tmpy != mousey) { hidemouse(); mousex = tmpx; mousey = tmpy; showmouse(); } svgalib_mouse_bstat = mouse_getbutton(); tmp_bstat = 0; if (svgalib_mouse_bstat & MOUSE_LEFTBUTTON) { pressed_count[0] += mouse_bstat & 1 ? 0 : 1; pressed_count[1] += mouse_bstat & 1 ? 0 : 1; tmp_bstat += 1; } else { released_count[0] += mouse_bstat & 1 ? 1 : 0; released_count[1] += mouse_bstat & 1 ? 1 : 0; } if (svgalib_mouse_bstat & MOUSE_RIGHTBUTTON) { pressed_count[0] += mouse_bstat & 2 ? 0 : 1; pressed_count[2] += mouse_bstat & 2 ? 0 : 1; tmp_bstat += 2; } else { released_count[0] += mouse_bstat & 2 ? 1 : 0; released_count[2] += mouse_bstat & 2 ? 1 : 0; } mouse_bstat = tmp_bstat; #if 0 /* {{{ */ if (wheel && rx) { /* For clarity - wipe the old location out so we can redraw with the new box size */ gl_fillbox(ox, oy, boxsize, boxsize, 0); /* Interpret wheel turns; we care only about direction, not amount, for our purposes */ boxsize += (rx / abs(rx)); (boxsize < 1)?(boxsize = 1):((boxsize > 10)?(boxsize = 10):0); /* Zero the wheel position */ mouse_setposition_6d(0,0,0, 0,0,0, MOUSE_RXDIM); } #endif /* }}} */ } } /* }}} */ BYTE initmouse(void) /* {{{ */ { /* Enable automatic mouse setup at mode set. */ vga_setmousesupport(1); mouse_showed = 0; mousex = 0; mousey = 0; mouse_bstat = 0; pressed_count [0] = pressed_count [1] = pressed_count [2] = 0; released_count[0] = released_count[1] = released_count[2] = 0; return 2; } /* }}} */ void showmouse(void) /* {{{ */ { if (! mouse_showed) { register int x, y, x2, y2; x = mousex > 5 ? mousex - 5 : 0; y = mousey > 5 ? mousey - 5 : 0; x2 = x + 5; y2 = y + 5; gl_getbox(x, y, 11, 11, mouse_bitmap); gl_line(x, y2, x + 10, y2, WHITE); gl_line(x2, y, x2, y + 10, WHITE); mouse_showed = 1; } } /* }}} */ void hidemouse(void) /* {{{ */ { if (mouse_showed) { register int x, y; x = mousex > 5 ? mousex - 5 : 0; y = mousey > 5 ? mousey - 5 : 0; gl_putbox(x, y, 11, 11, mouse_bitmap); mouse_showed = 0; } } /* }}} */ BYTE getmousepos(WORD*x,WORD*y) /* {{{ */ { mouse_status_update(); if (x != NULL) *x = (WORD) mousex; if (y != NULL) *y = (WORD) mousey; return mouse_bstat; } /* }}} */ void setmousepos(WORD x,WORD y) /* {{{ */ { if (mousex != x || mousey != y) { hidemouse(); mouse_setposition(x, y); mousex = x; mousey = y; showmouse(); } } /* }}} */ 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 = mousex; if (y != NULL) *y = mousey; 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 = mousex; if (y != NULL) *y = mousey; return ret; } /* }}} */ void rangex(WORD a_min,WORD a_max) /* {{{ */ { register int new_mousex = mousex; new_mousex = max(a_min, new_mousex); new_mousex = min(a_max, new_mousex); mouse_setxrange(a_min, a_max); if (new_mousex != mousex) { hidemouse(); mousex = new_mousex; showmouse(); } } /* }}} */ void rangey(WORD a_min,WORD a_max) /* {{{ */ { register int new_mousey = mousey; new_mousey = max(a_min, new_mousey); new_mousey = min(a_max, new_mousey); mouse_setyrange(a_min, a_max); if (new_mousey != mousey) { hidemouse(); mousey = new_mousey; showmouse(); } } /* }}} */ void setmousecur(WORD x,WORD y,void*p) /* {{{ */ { return; } /* }}} */ void exclude(WORD x1,WORD y1,WORD x2,WORD y2) /* {{{ */ { return; } /* }}} */ void mousesensitive(WORD x,WORD y) /* {{{ */ { return; } /* }}} */ void setmousespeed(WORD speed) /* {{{ */ { return; } /* }}} */ /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */