| 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"cxx . . $ `<file>/src/mouse.h`/ |
| 20 | |
| 21 | #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/ |
| 22 | #include "nortvars.h"cxx . . $ `<file>/src/nortvars.h`/ |
| 23 | #include "sprite.h"cxx . . $ `<file>/src/sprite.h`/ |
| 24 | #include "video.h"cxx . . $ `<file>/src/video.h`/ |
| 25 | #include "vga256d.h"cxx . . $ `<file>/src/vga256d.h`/ |
| 26 | |
| 27 | #if defined(TARGET_GP2X) || defined(TARGET_DINGUX) |
| 28 | bool has_mouse = false; |
| 29 | #else |
| 30 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! has_mousecxx . . $ has_mouse. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 31 | #endif |
| 32 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouse_has_three_buttonscxx . . $ mouse_has_three_buttons. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 33 | |
| 34 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouseInactivecxx . . $ mouseInactive. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 35 | JE_bytecxx . . $ JE_byte# mouseCursorcxx . . $ mouseCursor.; |
| 36 | JE_wordcxx . . $ JE_word# mouseXcxx . . $ mouseX., mouseYcxx . . $ mouseY., mouseButtoncxx . . $ mouseButton.; |
| 37 | JE_wordcxx . . $ JE_word# mouseXBcxx . . $ mouseXB., mouseYBcxx . . $ mouseYB.; |
| 38 | |
| 39 | static JE_wordcxx . . $ JE_word# mouseGrabXcxx . . $ mouseGrabX., mouseGrabYcxx . . $ mouseGrabY.; |
| 40 | static JE_bytecxx . . $ JE_byte# mouseGrabShapecxx . . $ mouseGrabShape.[24 * 28]; |
| 41 | |
| 42 | static void JE_drawShapeTypeOnecxx . . $ JE_drawShapeTypeOne(b268bc6cbca9b05b).(JE_wordcxx . . $ JE_word# x, JE_wordcxx . . $ JE_word# y, JE_bytecxx . . $ JE_byte# *shape) |
| 43 | { |
| 44 | JE_wordcxx . . $ JE_word# xloop = 0, yloop = 0; |
| 45 | JE_bytecxx . . $ JE_byte# *p = shape; /* shape pointer */ |
| 46 | Uint8cxx . . $ Uint8# *s; /* screen pointer, 8-bit specific */ |
| 47 | Uint8cxx . . $ Uint8# *s_limit; /* buffer boundary */ |
| 48 | |
| 49 | s = (Uint8cxx . . $ Uint8# *)VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.; |
| 50 | s += y * VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. + x; |
| 51 | |
| 52 | s_limit = (Uint8cxx . . $ Uint8# *)VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.; |
| 53 | s_limit += VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h. * VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.; |
| 54 | |
| 55 | for (yloop = 0; yloop < 28; yloop++) |
| 56 | { |
| 57 | for (xloop = 0; xloop < 24; xloop++) |
| 58 | { |
| 59 | if (s >= s_limit) |
| 60 | return; |
| 61 | *s = *p; |
| 62 | s++; p++; |
| 63 | } |
| 64 | s -= 24; |
| 65 | s += VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | static void JE_grabShapeTypeOnecxx . . $ JE_grabShapeTypeOne(b268bc6cbca9b05b).(JE_wordcxx . . $ JE_word# x, JE_wordcxx . . $ JE_word# y, JE_bytecxx . . $ JE_byte# *shape) |
| 70 | { |
| 71 | JE_wordcxx . . $ JE_word# xloop = 0, yloop = 0; |
| 72 | JE_bytecxx . . $ JE_byte# *p = shape; /* shape pointer */ |
| 73 | Uint8cxx . . $ Uint8# *s; /* screen pointer, 8-bit specific */ |
| 74 | Uint8cxx . . $ Uint8# *s_limit; /* buffer boundary */ |
| 75 | |
| 76 | s = (Uint8cxx . . $ Uint8# *)VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.; |
| 77 | s += y * VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. + x; |
| 78 | |
| 79 | s_limit = (Uint8cxx . . $ Uint8# *)VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.; |
| 80 | s_limit += VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h. * VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.; |
| 81 | |
| 82 | for (yloop = 0; yloop < 28; yloop++) |
| 83 | { |
| 84 | for (xloop = 0; xloop < 24; xloop++) |
| 85 | { |
| 86 | if (s >= s_limit) |
| 87 | return; |
| 88 | *p = *s; |
| 89 | s++; p++; |
| 90 | } |
| 91 | s -= 24; |
| 92 | s += VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | typedef structcxx . . $ $anonymous_type_b206f55110f9ed93_0# |
| 97 | { |
| 98 | Uint16cxx . . $ Uint16# indexcxx . . $ $anonymous_type_b206f55110f9ed93_0#index.; |
| 99 | Uint8cxx . . $ Uint8# xcxx . . $ $anonymous_type_b206f55110f9ed93_0#x.; |
| 100 | Uint8cxx . . $ Uint8# ycxx . . $ $anonymous_type_b206f55110f9ed93_0#y.; |
| 101 | Uint8cxx . . $ Uint8# wcxx . . $ $anonymous_type_b206f55110f9ed93_0#w.; |
| 102 | Uint8cxx . . $ Uint8# hcxx . . $ $anonymous_type_b206f55110f9ed93_0#h.; |
| 103 | Uint8cxx . . $ Uint8# fxcxx . . $ $anonymous_type_b206f55110f9ed93_0#fx.; |
| 104 | Uint8cxx . . $ Uint8# fycxx . . $ $anonymous_type_b206f55110f9ed93_0#fy.; |
| 105 | } MousePointerSpriteInfocxx . . $ MousePointerSpriteInfo#; |
| 106 | |
| 107 | static const MousePointerSpriteInfocxx . . $ MousePointerSpriteInfo# mousePointerSpritescxx . . $ mousePointerSprites.[] = // fka mouseCursorGr |
| 108 | { |
| 109 | { 273, 0, 0, 11, 16, 0, 0 }, |
| 110 | { 275, 0, 0, 21, 16, 10, 8 }, |
| 111 | { 277, 0, 0, 21, 16, 10, 7 }, |
| 112 | { 279, 0, 0, 16, 21, 8, 10 }, |
| 113 | { 281, 8, 0, 16, 21, 7, 10 }, |
| 114 | }; |
| 115 | |
| 116 | void JE_mouseStartcxx . . $ JE_mouseStart(49f6e7a06ebc5aa8).(void) |
| 117 | { |
| 118 | if (has_mousecxx . . $ has_mouse.) |
| 119 | { |
| 120 | service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 121 | |
| 122 | mouseButtoncxx . . $ mouseButton. = mousedowncxx . . $ mousedown. ? lastmouse_butcxx . . $ lastmouse_but. : 0; /* incorrect, possibly unimportant */ |
| 123 | |
| 124 | const MousePointerSpriteInfocxx . . $ MousePointerSpriteInfo# *spriteInfo = &mousePointerSpritescxx . . $ mousePointerSprites.[mouseCursorcxx . . $ mouseCursor.]; |
| 125 | |
| 126 | mouseGrabXcxx . . $ mouseGrabX. = MINcxx . . $ `src/opentyr.h:28:9`!(MAXcxx . . $ `src/opentyr.h:29:9`!(spriteInfo->fx, mouse_x), 320 - (spriteInfo->w - spriteInfo->fx)) - spriteInfo->fxcxx . . $ $anonymous_type_b206f55110f9ed93_0#fx.; |
| 127 | mouseGrabYcxx . . $ mouseGrabY. = MINcxx . . $ `src/opentyr.h:28:9`!(MAXcxx . . $ `src/opentyr.h:29:9`!(spriteInfo->fy, mouse_y), 200 - (spriteInfo->h - spriteInfo->fy)) - spriteInfo->fycxx . . $ $anonymous_type_b206f55110f9ed93_0#fy.; |
| 128 | |
| 129 | JE_grabShapeTypeOnecxx . . $ JE_grabShapeTypeOne(b268bc6cbca9b05b).(mouseGrabXcxx . . $ mouseGrabX., mouseGrabYcxx . . $ mouseGrabY., mouseGrabShapecxx . . $ mouseGrabShape.); |
| 130 | |
| 131 | if (!mouseInactivecxx . . $ mouseInactive.) |
| 132 | { |
| 133 | const Sint32cxx . . $ Sint32# x = mouse_xcxx . . $ mouse_x. - spriteInfo->xcxx . . $ $anonymous_type_b206f55110f9ed93_0#x. - spriteInfo->fxcxx . . $ $anonymous_type_b206f55110f9ed93_0#fx.; |
| 134 | const Sint32cxx . . $ Sint32# y = mouse_ycxx . . $ mouse_y. - spriteInfo->ycxx . . $ $anonymous_type_b206f55110f9ed93_0#y. - spriteInfo->fycxx . . $ $anonymous_type_b206f55110f9ed93_0#fy.; |
| 135 | blit_sprite2x2_clipcxx . . $ blit_sprite2x2_clip(b5d0f2be3b000a5b).(VGAScreencxx . . $ VGAScreen., x, y, shopSpriteSheetcxx . . $ shopSpriteSheet., spriteInfo->indexcxx . . $ $anonymous_type_b206f55110f9ed93_0#index.); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void JE_mouseStartFiltercxx . . $ JE_mouseStartFilter(ac50b47256ae7414).(Uint8cxx . . $ Uint8# filter) |
| 141 | { |
| 142 | if (has_mousecxx . . $ has_mouse.) |
| 143 | { |
| 144 | mouseButtoncxx . . $ mouseButton. = mousedowncxx . . $ mousedown. ? lastmouse_butcxx . . $ lastmouse_but. : 0; /* incorrect, possibly unimportant */ |
| 145 | |
| 146 | const MousePointerSpriteInfocxx . . $ MousePointerSpriteInfo# *spriteInfo = &mousePointerSpritescxx . . $ mousePointerSprites.[mouseCursorcxx . . $ mouseCursor.]; |
| 147 | |
| 148 | mouseGrabXcxx . . $ mouseGrabX. = MINcxx . . $ `src/opentyr.h:28:9`!(MAXcxx . . $ `src/opentyr.h:29:9`!(spriteInfo->fx, mouse_x), 320 - (spriteInfo->w - spriteInfo->fx)) - spriteInfo->fxcxx . . $ $anonymous_type_b206f55110f9ed93_0#fx.; |
| 149 | mouseGrabYcxx . . $ mouseGrabY. = MINcxx . . $ `src/opentyr.h:28:9`!(MAXcxx . . $ `src/opentyr.h:29:9`!(spriteInfo->fy, mouse_y), 200 - (spriteInfo->h - spriteInfo->fy)) - spriteInfo->fycxx . . $ $anonymous_type_b206f55110f9ed93_0#fy.; |
| 150 | |
| 151 | JE_grabShapeTypeOnecxx . . $ JE_grabShapeTypeOne(b268bc6cbca9b05b).(mouseGrabXcxx . . $ mouseGrabX., mouseGrabYcxx . . $ mouseGrabY., mouseGrabShapecxx . . $ mouseGrabShape.); |
| 152 | |
| 153 | if (!mouseInactivecxx . . $ mouseInactive.) |
| 154 | { |
| 155 | const Sint32cxx . . $ Sint32# x = mouse_xcxx . . $ mouse_x. - spriteInfo->xcxx . . $ $anonymous_type_b206f55110f9ed93_0#x. - spriteInfo->fxcxx . . $ $anonymous_type_b206f55110f9ed93_0#fx.; |
| 156 | const Sint32cxx . . $ Sint32# y = mouse_ycxx . . $ mouse_y. - spriteInfo->ycxx . . $ $anonymous_type_b206f55110f9ed93_0#y. - spriteInfo->fycxx . . $ $anonymous_type_b206f55110f9ed93_0#fy.; |
| 157 | blit_sprite2x2_filter_clipcxx . . $ blit_sprite2x2_filter_clip(2b2597c85c53621a).(VGAScreencxx . . $ VGAScreen., x, y, shopSpriteSheetcxx . . $ shopSpriteSheet., spriteInfo->indexcxx . . $ $anonymous_type_b206f55110f9ed93_0#index., filter); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void JE_mouseReplacecxx . . $ JE_mouseReplace(49f6e7a06ebc5aa8).(void) |
| 163 | { |
| 164 | if (has_mousecxx . . $ has_mouse.) |
| 165 | JE_drawShapeTypeOnecxx . . $ JE_drawShapeTypeOne(b268bc6cbca9b05b).(mouseGrabXcxx . . $ mouseGrabX., mouseGrabYcxx . . $ mouseGrabY., mouseGrabShapecxx . . $ mouseGrabShape.); |
| 166 | } |