~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/common/MouseControl.cxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-02-05 08:09:05 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120205080905-9ej05rmkibowsm7j
Tags: 3.5.5-1
* New upstream version.
* Rewrite debian/copyright, using DEP-5 and updating for 2012.
* Update manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll
 
4
//  SS  SS   tt           ll   ll
 
5
//  SS     tttttt  eeee   ll   ll   aaaa
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-2012 by Bradford W. Mott, Stephen Anthony
 
12
// and the Stella Team
 
13
//
 
14
// See the file "License.txt" for information on usage and redistribution of
 
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
16
//
 
17
// $Id: MouseControl.cxx 2376 2012-01-29 22:33:24Z stephena $
 
18
//============================================================================
 
19
 
 
20
#include "Console.hxx"
 
21
#include "Control.hxx"
 
22
#include "Props.hxx"
 
23
 
 
24
#include "MouseControl.hxx"
 
25
 
 
26
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
27
MouseControl::MouseControl(Console& console, const string& mode)
 
28
  : myProps(console.properties()),
 
29
    myLeftController(console.controller(Controller::Left)),
 
30
    myRightController(console.controller(Controller::Right)),
 
31
    myCurrentModeNum(0)
 
32
{
 
33
  if(BSPF_equalsIgnoreCase(mode, "never"))
 
34
  {
 
35
    myModeList.push_back(MouseMode("Mouse input is disabled"));
 
36
    return;
 
37
  }
 
38
  else if(!BSPF_equalsIgnoreCase(mode, "auto") && mode.length() == 2 &&
 
39
          mode[0] >= '0' && mode[0] <= '5' &&
 
40
          mode[1] >= '0' && mode[1] <= '5')
 
41
  {
 
42
    Axis xaxis = (Axis) ((int)mode[0] - '0');
 
43
    Axis yaxis = (Axis) ((int)mode[1] - '0');
 
44
    ostringstream msg;
 
45
    msg << "Mouse X-axis is ";
 
46
    switch(xaxis)
 
47
    {
 
48
      case Paddle0:
 
49
        msg << "Paddle 0";  break;
 
50
      case Paddle1:
 
51
        msg << "Paddle 1";  break;
 
52
      case Paddle2:
 
53
        msg << "Paddle 2";  break;
 
54
      case Paddle3:
 
55
        msg << "Paddle 3";  break;
 
56
      case Driving0:
 
57
        msg << "Driving 0"; break;
 
58
      case Driving1:
 
59
        msg << "Driving 1"; break;
 
60
      default:              break;
 
61
    }
 
62
    msg << ", Y-axis is ";
 
63
    switch(yaxis)
 
64
    {
 
65
      case Paddle0:
 
66
        msg << "Paddle 0";  break;
 
67
      case Paddle1:
 
68
        msg << "Paddle 1";  break;
 
69
      case Paddle2:
 
70
        msg << "Paddle 2";  break;
 
71
      case Paddle3:
 
72
        msg << "Paddle 3";  break;
 
73
      case Driving0:
 
74
        msg << "Driving 0"; break;
 
75
      case Driving1:
 
76
        msg << "Driving 1"; break;
 
77
      default:              break;
 
78
    }
 
79
    myModeList.push_back(MouseMode(xaxis, yaxis, -1, msg.str()));
 
80
  }
 
81
 
 
82
  // Now consider the possible modes for the mouse based on the left
 
83
  // and right controllers
 
84
  bool noswap = BSPF_equalsIgnoreCase(myProps.get(Console_SwapPorts), "NO");
 
85
  if(noswap)
 
86
  {
 
87
    addLeftControllerModes(noswap);
 
88
    addRightControllerModes(noswap);
 
89
  }
 
90
  else
 
91
  {
 
92
    addRightControllerModes(noswap);
 
93
    addLeftControllerModes(noswap);
 
94
  }
 
95
 
 
96
  // If the mouse isn't used at all, we still need one item in the list
 
97
  if(myModeList.size() == 0)
 
98
    myModeList.push_back(MouseMode("Mouse not used for current controllers"));
 
99
}
 
100
 
 
101
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
102
MouseControl::~MouseControl()
 
103
{
 
104
}
 
105
 
 
106
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
107
const string& MouseControl::next()
 
108
{
 
109
  const MouseMode& mode = myModeList[myCurrentModeNum];
 
110
  myCurrentModeNum = (myCurrentModeNum + 1) % myModeList.size();
 
111
 
 
112
  myLeftController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
 
113
  myRightController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
 
114
 
 
115
  return mode.message;
 
116
}
 
117
 
 
118
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
119
void MouseControl::addLeftControllerModes(bool noswap)
 
120
{
 
121
  switch(myLeftController.type())
 
122
  {
 
123
    case Controller::Joystick:
 
124
    case Controller::BoosterGrip:
 
125
    case Controller::Genesis:
 
126
    case Controller::Driving:
 
127
    case Controller::TrackBall22:
 
128
    case Controller::TrackBall80:
 
129
    case Controller::AmigaMouse:
 
130
//    case Controller::Mindlink:
 
131
    {
 
132
      ostringstream msg;
 
133
      msg << "Mouse is left " << myLeftController.name() << " controller";
 
134
      myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 0 : 1, msg.str()));
 
135
      break;
 
136
    }
 
137
    case Controller::Paddles:
 
138
      if(noswap)  addPaddleModes(0, 1, 0, 1);
 
139
      else        addPaddleModes(2, 3, 0, 1);
 
140
      break;
 
141
    default:
 
142
      break;
 
143
  }
 
144
}
 
145
 
 
146
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
147
void MouseControl::addRightControllerModes(bool noswap)
 
148
{
 
149
  switch(myRightController.type())
 
150
  {
 
151
    case Controller::Joystick:
 
152
    case Controller::BoosterGrip:
 
153
    case Controller::Genesis:
 
154
    case Controller::Driving:
 
155
    case Controller::TrackBall22:
 
156
    case Controller::TrackBall80:
 
157
    case Controller::AmigaMouse:
 
158
//    case Controller::Mindlink:
 
159
    {
 
160
      ostringstream msg;
 
161
      msg << "Mouse is right " << myRightController.name() << " controller";
 
162
      myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 1 : 0, msg.str()));
 
163
      break;
 
164
    }
 
165
    case Controller::Paddles:
 
166
      if(noswap)  addPaddleModes(2, 3, 2, 3);
 
167
      else        addPaddleModes(0, 1, 2, 3);
 
168
      break;
 
169
    default:
 
170
      break;
 
171
  }
 
172
}
 
173
 
 
174
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
175
void MouseControl::addPaddleModes(int lport, int rport, int lname, int rname)
 
176
{
 
177
  ostringstream msg;
 
178
  msg << "Mouse is Paddle " << lname << " controller";
 
179
  MouseMode mode0(Automatic, Automatic, lport, msg.str());
 
180
 
 
181
  msg.str("");
 
182
  msg << "Mouse is Paddle " << rname << " controller";
 
183
  MouseMode mode1(Automatic, Automatic, rport, msg.str());
 
184
 
 
185
  if(BSPF_equalsIgnoreCase(myProps.get(Controller_SwapPaddles), "NO"))
 
186
  {
 
187
    myModeList.push_back(mode0);
 
188
    myModeList.push_back(mode1);
 
189
  }
 
190
  else
 
191
  {
 
192
    myModeList.push_back(mode1);
 
193
    myModeList.push_back(mode0);
 
194
  }
 
195
}