~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/arch/unix/macosx/cocoa/mousedrv.m

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2010-02-11 18:30:16 UTC
  • mfrom: (1.1.8 upstream) (9.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100211183016-f6n8usn3tzp0u6dp
Tags: 2.2.dfsg-1
* New upstream release, C64 DTV is included so update package description
  and add it to the menu.
* Drop patch fixing build failure with gcc-4.4 , applied upstream.
* Fix some lintian problems and clean up debian/rules .

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 *
25
25
 */
26
26
 
 
27
#include "cmdline.h"
27
28
#include "mousedrv.h"
 
29
#include "resources.h"
 
30
#include "translate.h"
28
31
#include "vicemachine.h"
29
32
 
30
33
// mouse.c
31
34
extern int _mouse_enabled;
32
 
static int ptr_x=0,ptr_y=0;
33
 
static int hw_x=0,hw_y=0;
 
35
 
 
36
static BOOL firstMove;
 
37
static int  pointerX;
 
38
static int  pointerY;
 
39
static int  emuX;
 
40
static int  emuY;
 
41
 
 
42
static int  scaleX;
 
43
static int  scaleY;
 
44
 
 
45
static int set_scale_x(int val, void *param)
 
46
{
 
47
    scaleX = val;
 
48
}
 
49
 
 
50
static int set_scale_y(int val, void *param)
 
51
{
 
52
    scaleY = val;
 
53
}
 
54
 
 
55
static resource_int_t resources_int[] =
 
56
{
 
57
    { "MouseScaleX", 4, RES_EVENT_NO, NULL,
 
58
       &scaleX, set_scale_x, NULL },
 
59
    { "MouseScaleY", 4, RES_EVENT_NO, NULL,
 
60
       &scaleY, set_scale_y, NULL },
 
61
    { NULL }
 
62
 };
34
63
 
35
64
int mousedrv_resources_init(void)
36
65
{
37
 
    return 0;
 
66
    return resources_register_int(resources_int);
38
67
}
39
68
 
 
69
static const cmdline_option_t cmdline_options[] = {
 
70
    { "-mousescalex", SET_RESOURCE, 1,
 
71
      NULL, NULL, "MouseScaleX", NULL,
 
72
      USE_PARAM_STRING, USE_DESCRIPTION_STRING,
 
73
      IDCLS_UNUSED, IDCLS_UNUSED,
 
74
      "<1-8>", T_("Set scaling factor for mouse movement along X") },
 
75
    { "-mousescaley", SET_RESOURCE, 1,
 
76
      NULL, NULL, "MouseScaleY", NULL,
 
77
      USE_PARAM_STRING, USE_DESCRIPTION_STRING,
 
78
      IDCLS_UNUSED, IDCLS_UNUSED,
 
79
      "<1-8>", T_("Set scaling factor for mouse movement along Y") },
 
80
    { NULL }
 
81
};
 
82
 
40
83
int mousedrv_cmdline_options_init(void)
41
84
{
42
 
    return 0;
 
85
    return cmdline_register_options(cmdline_options);
43
86
}
44
87
 
45
88
void mousedrv_init(void)
49
92
void mousedrv_mouse_changed(void)
50
93
{
51
94
    [[theVICEMachine machineNotifier] postToggleMouseNotification:_mouse_enabled];
 
95
 
 
96
    if(_mouse_enabled) {
 
97
        firstMove = YES;
 
98
    }
52
99
}
53
100
 
54
101
#define MAX_DELTA  16
55
102
 
 
103
// the HW polls the position
56
104
BYTE mousedrv_get_x(void)
57
105
{
58
 
    int dx = ptr_x - hw_x;
59
 
    if(dx < -MAX_DELTA)
60
 
        dx = -MAX_DELTA;
61
 
    else if(dx > MAX_DELTA)
62
 
        dx = MAX_DELTA;
63
 
    hw_x += dx;
64
 
    return (BYTE)((hw_x&0x3f) << 1);
 
106
    int delta = pointerX - emuX;
 
107
    
 
108
    if (delta > MAX_DELTA) {
 
109
        delta = MAX_DELTA;
 
110
    }
 
111
    else if (delta < -MAX_DELTA) {
 
112
        delta = -MAX_DELTA;
 
113
    }
 
114
 
 
115
    emuX += delta;
 
116
    return (BYTE)((emuX & 63) << 1) & 0x7e;
65
117
}
66
118
 
67
119
BYTE mousedrv_get_y(void)
68
120
{
69
 
    int dy = ptr_y - hw_y;
70
 
    if(dy < -MAX_DELTA)
71
 
        dy = -MAX_DELTA;
72
 
    else if(dy > MAX_DELTA)
73
 
        dy = MAX_DELTA;
74
 
    hw_y += dy;
75
 
    return (BYTE)((hw_y&0x3f) << 1);
 
121
    int delta = pointerY - emuY;
 
122
    
 
123
    if (delta > MAX_DELTA) {
 
124
        delta = MAX_DELTA;
 
125
    }
 
126
    else if (delta < -MAX_DELTA) {
 
127
        delta = -MAX_DELTA;
 
128
    }
 
129
 
 
130
    emuY += delta;
 
131
    return (BYTE)((emuY & 63) << 1) & 0x7e;
76
132
}
77
133
 
78
134
void mouse_move(int x, int y)
79
135
{
80
 
    ptr_x = x;
81
 
    ptr_y = y;
 
136
    pointerX = x * scaleX;
 
137
    pointerY = y * scaleY;
 
138
    if(firstMove) {
 
139
        firstMove = NO;
 
140
        emuX = x * scaleX;
 
141
        emuY = y * scaleY;
 
142
    }
82
143
}