~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/mouse.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "keyboard.h"
 
20
#include "nortvars.h"
 
21
#include "sprite.h"
 
22
#include "video.h"
 
23
#include "vga256d.h"
 
24
 
 
25
#if defined(TARGET_GP2X) || defined(TARGET_DINGUX)
 
26
bool has_mouse = false;
 
27
#else
 
28
bool has_mouse = true;
 
29
#endif
 
30
bool mouse_has_three_buttons = true;
 
31
 
 
32
JE_word lastMouseX, lastMouseY;
 
33
JE_byte mouseCursor;
 
34
JE_word mouseX, mouseY, mouseButton;
 
35
JE_word mouseXB, mouseYB;
 
36
 
 
37
JE_byte mouseGrabShape[24 * 28];                 /* [1..24*28] */
 
38
 
 
39
void JE_drawShapeTypeOne( JE_word x, JE_word y, JE_byte *shape )
 
40
{
 
41
        JE_word xloop = 0, yloop = 0;
 
42
        JE_byte *p = shape; /* shape pointer */
 
43
        Uint8 *s;   /* screen pointer, 8-bit specific */
 
44
        Uint8 *s_limit; /* buffer boundary */
 
45
 
 
46
        s = (Uint8 *)VGAScreen->pixels;
 
47
        s += y * VGAScreen->pitch + x;
 
48
 
 
49
        s_limit = (Uint8 *)VGAScreen->pixels;
 
50
        s_limit += VGAScreen->h * VGAScreen->pitch;
 
51
 
 
52
        for (yloop = 0; yloop < 28; yloop++)
 
53
        {
 
54
                for (xloop = 0; xloop < 24; xloop++)
 
55
                {
 
56
                        if (s >= s_limit) return;
 
57
                        *s = *p;
 
58
                        s++; p++;
 
59
                }
 
60
                s -= 24;
 
61
                s += VGAScreen->pitch;
 
62
        }
 
63
}
 
64
 
 
65
void JE_grabShapeTypeOne( JE_word x, JE_word y, JE_byte *shape )
 
66
{
 
67
        JE_word xloop = 0, yloop = 0;
 
68
        JE_byte *p = shape; /* shape pointer */
 
69
        Uint8 *s;   /* screen pointer, 8-bit specific */
 
70
        Uint8 *s_limit; /* buffer boundary */
 
71
 
 
72
        s = (Uint8 *)VGAScreen->pixels;
 
73
        s += y * VGAScreen->pitch + x;
 
74
 
 
75
        s_limit = (Uint8 *)VGAScreen->pixels;
 
76
        s_limit += VGAScreen->h * VGAScreen->pitch;
 
77
 
 
78
        for (yloop = 0; yloop < 28; yloop++)
 
79
        {
 
80
                for (xloop = 0; xloop < 24; xloop++)
 
81
                {
 
82
                        if (s >= s_limit) return;
 
83
                        *p = *s;
 
84
                        s++; p++;
 
85
                }
 
86
                s -= 24;
 
87
                s += VGAScreen->pitch;
 
88
        }
 
89
}
 
90
 
 
91
void JE_mouseStart( void )
 
92
{
 
93
        const JE_word mouseCursorGr[3] /* [1..3] */ = {273, 275, 277};
 
94
        
 
95
        if (has_mouse)
 
96
        {
 
97
                service_SDL_events(false);
 
98
                mouseButton = mousedown ? lastmouse_but : 0; /* incorrect, possibly unimportant */
 
99
                lastMouseX = MIN(mouse_x, 320 - 13);
 
100
                lastMouseY = MIN(mouse_y, 200 - 16);
 
101
                
 
102
                JE_grabShapeTypeOne(lastMouseX, lastMouseY, mouseGrabShape);
 
103
                
 
104
                blit_sprite2x2(VGAScreen, lastMouseX, lastMouseY, shapes6, mouseCursorGr[mouseCursor]);
 
105
         }
 
106
}
 
107
 
 
108
void JE_mouseReplace( void )
 
109
{
 
110
        if (has_mouse)
 
111
                JE_drawShapeTypeOne(lastMouseX, lastMouseY, mouseGrabShape);
 
112
}
 
113