Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * OpenTyrian: A modern cross-platform port of Tyrian
  3.  * Copyright (C) 2007-2009  The OpenTyrian Development Team
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18.  */
  19. #include "mouse.h"
  20.  
  21. #include "keyboard.h"
  22. #include "nortvars.h"
  23. #include "sprite.h"
  24. #include "video.h"
  25. #include "vga256d.h"
  26.  
  27. #if defined(TARGET_GP2X) || defined(TARGET_DINGUX)
  28. bool has_mouse = false;
  29. #else
  30. bool has_mouse = true;
  31. #endif
  32. bool mouse_has_three_buttons = true;
  33.  
  34. JE_word lastMouseX, lastMouseY;
  35. JE_byte mouseCursor;
  36. JE_word mouseX, mouseY, mouseButton;
  37. JE_word mouseXB, mouseYB;
  38.  
  39. JE_byte mouseGrabShape[24 * 28];                 /* [1..24*28] */
  40.  
  41. void JE_drawShapeTypeOne( JE_word x, JE_word y, JE_byte *shape )
  42. {
  43.         JE_word xloop = 0, yloop = 0;
  44.         JE_byte *p = shape; /* shape pointer */
  45.         Uint8 *s;   /* screen pointer, 8-bit specific */
  46.         Uint8 *s_limit; /* buffer boundary */
  47.  
  48.         s = (Uint8 *)VGAScreen->pixels;
  49.         s += y * VGAScreen->pitch + x;
  50.  
  51.         s_limit = (Uint8 *)VGAScreen->pixels;
  52.         s_limit += VGAScreen->h * VGAScreen->pitch;
  53.  
  54.         for (yloop = 0; yloop < 28; yloop++)
  55.         {
  56.                 for (xloop = 0; xloop < 24; xloop++)
  57.                 {
  58.                         if (s >= s_limit) return;
  59.                         *s = *p;
  60.                         s++; p++;
  61.                 }
  62.                 s -= 24;
  63.                 s += VGAScreen->pitch;
  64.         }
  65. }
  66.  
  67. void JE_grabShapeTypeOne( JE_word x, JE_word y, JE_byte *shape )
  68. {
  69.         JE_word xloop = 0, yloop = 0;
  70.         JE_byte *p = shape; /* shape pointer */
  71.         Uint8 *s;   /* screen pointer, 8-bit specific */
  72.         Uint8 *s_limit; /* buffer boundary */
  73.  
  74.         s = (Uint8 *)VGAScreen->pixels;
  75.         s += y * VGAScreen->pitch + x;
  76.  
  77.         s_limit = (Uint8 *)VGAScreen->pixels;
  78.         s_limit += VGAScreen->h * VGAScreen->pitch;
  79.  
  80.         for (yloop = 0; yloop < 28; yloop++)
  81.         {
  82.                 for (xloop = 0; xloop < 24; xloop++)
  83.                 {
  84.                         if (s >= s_limit) return;
  85.                         *p = *s;
  86.                         s++; p++;
  87.                 }
  88.                 s -= 24;
  89.                 s += VGAScreen->pitch;
  90.         }
  91. }
  92.  
  93. void JE_mouseStart( void )
  94. {
  95.         const JE_word mouseCursorGr[3] /* [1..3] */ = {273, 275, 277};
  96.        
  97.         if (has_mouse)
  98.         {
  99.                 service_SDL_events(false);
  100.                 mouseButton = mousedown ? lastmouse_but : 0; /* incorrect, possibly unimportant */
  101.                 lastMouseX = MIN(mouse_x, 320 - 13);
  102.                 lastMouseY = MIN(mouse_y, 200 - 16);
  103.                
  104.                 JE_grabShapeTypeOne(lastMouseX, lastMouseY, mouseGrabShape);
  105.                
  106.                 blit_sprite2x2(VGAScreen, lastMouseX, lastMouseY, shapes6, mouseCursorGr[mouseCursor]);
  107.          }
  108. }
  109.  
  110. void JE_mouseReplace( void )
  111. {
  112.         if (has_mouse)
  113.                 JE_drawShapeTypeOne(lastMouseX, lastMouseY, mouseGrabShape);
  114. }
  115.  
  116.