"Fossies" - the Fresh Open Source Software Archive

Member "stella-6.0.2/src/common/MouseControl.cxx" (11 Oct 2019, 7584 Bytes) of package /linux/privat/stella-6.0.2-src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "MouseControl.cxx" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.0.1_vs_6.0.2.

    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-2019 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 
   18 #include "Console.hxx"
   19 #include "Control.hxx"
   20 #include "Paddles.hxx"
   21 #include "Props.hxx"
   22 
   23 #include "MouseControl.hxx"
   24 
   25 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   26 MouseControl::MouseControl(Console& console, const string& mode)
   27   : myProps(console.properties()),
   28     myLeftController(console.leftController()),
   29     myRightController(console.rightController()),
   30     myCurrentModeNum(0)
   31 {
   32   istringstream m_axis(mode);
   33   string m_mode;
   34   m_axis >> m_mode;
   35 
   36   if(BSPF::equalsIgnoreCase(m_mode, "none"))
   37   {
   38     myModeList.push_back(MouseMode("Mouse input is disabled"));
   39     return;
   40   }
   41   else if(!BSPF::equalsIgnoreCase(m_mode, "auto") && m_mode.length() == 2 &&
   42           m_mode[0] >= '0' && m_mode[0] <= '8' &&
   43           m_mode[1] >= '0' && m_mode[1] <= '8')
   44   {
   45     Axis xaxis = Axis(int(m_mode[0]) - '0');
   46     Axis yaxis = Axis(int(m_mode[1]) - '0');
   47     ostringstream msg;
   48     msg << "Mouse X-axis is ";
   49     Controller::Type xtype = Controller::Joystick, ytype = Controller::Joystick;
   50     int xid = -1, yid = -1;
   51     switch(xaxis)
   52     {
   53       case NoControl:
   54         msg << "not used";
   55         break;
   56       case Paddle0:
   57         xtype = Controller::Paddles;
   58         xid = 0;
   59         msg << "Paddle 0";
   60         break;
   61       case Paddle1:
   62         xtype = Controller::Paddles;
   63         xid = 1;
   64         msg << "Paddle 1";
   65         break;
   66       case Paddle2:
   67         xtype = Controller::Paddles;
   68         xid = 2;
   69         msg << "Paddle 2";
   70         break;
   71       case Paddle3:
   72         xtype = Controller::Paddles;
   73         xid = 3;
   74         msg << "Paddle 3";
   75         break;
   76       case Driving0:
   77         xtype = Controller::Driving;
   78         xid = 0;
   79         msg << "Driving 0";
   80         break;
   81       case Driving1:
   82         xtype = Controller::Driving;
   83         xid = 1;
   84         msg << "Driving 1";
   85         break;
   86       case MindLink0:
   87         xtype = Controller::MindLink;
   88         xid = 0;
   89         msg << "MindLink 0";
   90         break;
   91       case MindLink1:
   92         xtype = Controller::MindLink;
   93         xid = 1;
   94         msg << "MindLink 1";
   95         break;
   96     }
   97     msg << ", Y-axis is ";
   98     switch(yaxis)
   99     {
  100       case NoControl:
  101         msg << "not used";
  102         break;
  103       case Paddle0:
  104         ytype = Controller::Paddles;
  105         yid = 0;
  106         msg << "Paddle 0";
  107         break;
  108       case Paddle1:
  109         ytype = Controller::Paddles;
  110         yid = 1;
  111         msg << "Paddle 1";
  112         break;
  113       case Paddle2:
  114         ytype = Controller::Paddles;
  115         yid = 2;
  116         msg << "Paddle 2";
  117         break;
  118       case Paddle3:
  119         ytype = Controller::Paddles;
  120         yid = 3;
  121         msg << "Paddle 3";
  122         break;
  123       case Driving0:
  124         ytype = Controller::Driving;
  125         yid = 0;
  126         msg << "Driving 0";
  127         break;
  128       case Driving1:
  129         ytype = Controller::Driving;
  130         yid = 1;
  131         msg << "Driving 1";
  132         break;
  133       case MindLink0:
  134         ytype = Controller::MindLink;
  135         yid = 0;
  136         msg << "MindLink 0";
  137         break;
  138       case MindLink1:
  139         ytype = Controller::MindLink;
  140         yid = 1;
  141         msg << "MindLink 1";
  142         break;
  143     }
  144     myModeList.push_back(MouseMode(xtype, xid, ytype, yid, msg.str()));
  145   }
  146 
  147   // Now consider the possible modes for the mouse based on the left
  148   // and right controllers
  149   bool noswap = BSPF::equalsIgnoreCase(myProps.get(Console_SwapPorts), "NO");
  150   if(noswap)
  151   {
  152     addLeftControllerModes(noswap);
  153     addRightControllerModes(noswap);
  154   }
  155   else
  156   {
  157     addRightControllerModes(noswap);
  158     addLeftControllerModes(noswap);
  159   }
  160 
  161   // Set range information (currently only for paddles, but may be used
  162   // for other controllers in the future)
  163   int m_range = 100;
  164   if(!(m_axis >> m_range))
  165     m_range = 100;
  166   Paddles::setPaddleRange(m_range);
  167 
  168   // If the mouse isn't used at all, we still need one item in the list
  169   if(myModeList.size() == 0)
  170     myModeList.push_back(MouseMode("Mouse not used for current controllers"));
  171 
  172 #if 0
  173   for(const auto& m: myModeList)
  174     cerr << m << endl;
  175 #endif
  176 }
  177 
  178 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  179 const string& MouseControl::next()
  180 {
  181   const MouseMode& mode = myModeList[myCurrentModeNum];
  182   myCurrentModeNum = (myCurrentModeNum + 1) % myModeList.size();
  183 
  184   myLeftController.setMouseControl(mode.xtype, mode.xid, mode.ytype, mode.yid);
  185   myRightController.setMouseControl(mode.xtype, mode.xid, mode.ytype, mode.yid);
  186 
  187   return mode.message;
  188 }
  189 
  190 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  191 void MouseControl::addLeftControllerModes(bool noswap)
  192 {
  193   if(controllerSupportsMouse(myLeftController))
  194   {
  195     if(myLeftController.type() == Controller::Paddles)
  196     {
  197       if(noswap)  addPaddleModes(0, 1, 0, 1);
  198       else        addPaddleModes(2, 3, 0, 1);
  199     }
  200     else
  201     {
  202       ostringstream msg;
  203       msg << "Mouse is left " << myLeftController.name() << " controller";
  204       Controller::Type type = myLeftController.type();
  205       int id = noswap ? 0 : 1;
  206       myModeList.push_back(MouseMode(type, id, type, id, msg.str()));
  207     }
  208   }
  209 }
  210 
  211 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  212 void MouseControl::addRightControllerModes(bool noswap)
  213 {
  214   if(controllerSupportsMouse(myRightController))
  215   {
  216     if(myRightController.type() == Controller::Paddles)
  217     {
  218       if(noswap)  addPaddleModes(2, 3, 2, 3);
  219       else        addPaddleModes(0, 1, 2, 3);
  220     }
  221     else
  222     {
  223       ostringstream msg;
  224       msg << "Mouse is right " << myRightController.name() << " controller";
  225       Controller::Type type = myRightController.type();
  226       int id = noswap ? 1 : 0;
  227       myModeList.push_back(MouseMode(type, id, type, id, msg.str()));
  228     }
  229   }
  230 }
  231 
  232 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  233 void MouseControl::addPaddleModes(int lport, int rport, int lname, int rname)
  234 {
  235   Controller::Type type = Controller::Paddles;
  236   ostringstream msg;
  237   msg << "Mouse is Paddle " << lname << " controller";
  238   MouseMode mode0(type, lport, type, lport, msg.str());
  239 
  240   msg.str("");
  241   msg << "Mouse is Paddle " << rname << " controller";
  242   MouseMode mode1(type, rport, type, rport, msg.str());
  243 
  244   if(BSPF::equalsIgnoreCase(myProps.get(Controller_SwapPaddles), "NO"))
  245   {
  246     myModeList.push_back(mode0);
  247     myModeList.push_back(mode1);
  248   }
  249   else
  250   {
  251     myModeList.push_back(mode1);
  252     myModeList.push_back(mode0);
  253   }
  254 }
  255 
  256 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  257 bool MouseControl::controllerSupportsMouse(Controller& controller)
  258 {
  259   // Test whether the controller uses the mouse at all
  260   // We can pass in dummy values here, since the controllers will be
  261   // initialized by a call to next() once the system is up and running
  262   return controller.setMouseControl(
  263       Controller::Joystick, -1, Controller::Joystick, -1);
  264 }