pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/input/pointers Makefile.am,NONE,1.1 a


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/input/pointers Makefile.am,NONE,1.1 axis_pointer.cxx,NONE,1.1 axis_pointer.hxx,NONE,1.1 dummy_pointer.hxx,NONE,1.1 mouse_pointer.cxx,NONE,1.1 mouse_pointer.hxx,NONE,1.1 multiple_pointer.cxx,NONE,1.1 multiple_pointer.hxx,NONE,1.1 pointer.hxx,NONE,1.1
Date: 24 Aug 2002 11:37:33 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/input/pointers
In directory dark:/tmp/cvs-serv15327/src/input/pointers

Added Files:
        Makefile.am axis_pointer.cxx axis_pointer.hxx 
        dummy_pointer.hxx mouse_pointer.cxx mouse_pointer.hxx 
        multiple_pointer.cxx multiple_pointer.hxx pointer.hxx 
Log Message:
moved input devices in own subdirs / namespaces


--- NEW FILE: Makefile.am ---
# Pingus - A free Lemmings clone
# Copyright (C) 1999 Ingo Ruhnke <address@hidden>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

noinst_LIBRARIES = libpingus_input_pointers.a

libpingus_input_pointers_a_SOURCES =       \
        axis_pointer.hxx axis_pointer.cxx \
        dummy_pointer.hxx \
        mouse_pointer.hxx mouse_pointer.cxx \
        multiple_pointer.hxx multiple_pointer.cxx \
        pointer.hxx

# EOF #

--- NEW FILE: axis_pointer.cxx ---
//  $Id: axis_pointer.cxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <math.h>
#include <assert.h>
#include "../axes/axis.hxx"
#include "axis_pointer.hxx"

namespace Input {

  using Axes::Axis;

  namespace Pointers {
  
    AxisPointer::AxisPointer (float speed_, const std::vector<Axis*>& axes_) : 
speed(speed_), axes(axes_)
    {
      assert(axes.size() >= 2);
      assert(axes[0]->get_angle() != axes[1]->get_angle());
    }

    AxisPointer::~AxisPointer ()
    {
      for (std::vector<Axis*>::const_iterator it = axes.begin(); it != 
axes.end(); it++)
        delete *it;
    }

    const float&
    AxisPointer::get_x_pos () const
    {
      return x_pos;
    }

    const float&
    AxisPointer::get_y_pos () const
    {
      return y_pos;
    }

    void
    AxisPointer::set_pos (float new_x, float new_y)
    {
      x_pos = new_x;
      y_pos = new_y;
    }
  
    void
    AxisPointer::update (float delta)
    {
      for (std::vector<Axis*>::const_iterator it = axes.begin(); it != 
axes.end(); it++)
        {
          (*it)->update(delta);
        
          x_pos += cos((*it)->get_angle()) * speed * delta;
          y_pos += sin((*it)->get_angle()) * speed * delta;
        } 
    }

  }
}

/* EOF */

--- NEW FILE: axis_pointer.hxx ---
//  $Id: axis_pointer.hxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_AXIS_POINTER_HXX
#define HEADER_PINGUS_INPUT_AXIS_POINTER_HXX

#include <vector>
#include "pointer.hxx"


namespace Input {

  namespace Axes {
    class Axis;
  }

  namespace Pointers {
  
    /**
      @brief maps two or more axes into a pointer
    
      XML definition: <axis-pointer> <axis 1><axis 2>[... <axis N>] 
</axis-pointer>
    
      The number of axes used to create the pointer and their respective angles 
is
      unlimited as long as there are at least two axes and the first two axes 
must have
      different angles.
      */
    class AxisPointer : public Pointer {
  
      private:

        const float        speed;
        std::vector<Axes::Axis*> axes;
           
        float              x_pos;
        float              y_pos;
      
      public:

        AxisPointer (float speed, const std::vector<Axes::Axis*>& axes_);
       ~AxisPointer ();

        virtual const float& get_x_pos () const;
        virtual const float& get_y_pos () const;
      
        virtual void  set_pos(float new_x, float new_y);
      
        virtual void  update (float delta);
      
      private:
        AxisPointer (const AxisPointer&);
        AxisPointer operator= (const AxisPointer&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: dummy_pointer.hxx ---
//  $Id: dummy_pointer.hxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_DUMMY_POINTER_HXX
#define HEADER_PINGUS_INPUT_DUMMY_POINTER_HXX

#include "pointer.hxx"

namespace Input {

  namespace Pointers {

    /**
      @brief dummy class to be used if a pointer is required but none defined
    
      XML definition: none
      */
    class DummyPointer : public Pointer {
  
      private:
        const float pos;
  
      public:

        DummyPointer () : pos(0) { }

        virtual const float& get_x_pos () const { return pos; }
        virtual const float& get_y_pos () const { return pos; }
      
        virtual void  set_pos (float, float) { }
        virtual void  update (float)         { }
      
      private:
        DummyPointer (const DummyPointer&);
        DummyPointer operator= (const DummyPointer&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: mouse_pointer.cxx ---
//  $Id: mouse_pointer.cxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <ClanLib/Display/Input/input.h>
#include <ClanLib/Display/Input/inputdevice.h>
#include <ClanLib/Display/Input/inputcursor.h>
#include "mouse_pointer.hxx"

namespace Input {

  namespace Pointers {

    MousePointer::MousePointer () : x_pos(0), y_pos(0)
    {
    }

    const float&
    MousePointer::get_x_pos () const
    {
      return x_pos;
    }

    const float&
    MousePointer::get_y_pos () const
    {
      return y_pos;
    }

    void
    MousePointer::set_pos (float new_x, float new_y)
    {
      CL_Input::pointers[0]->get_cursor(0)->set_position(new_x, new_y);
    }

    void
    MousePointer::update (float)
    {
      x_pos = CL_Input::pointers[0]->get_cursor(0)->get_x();
      y_pos = CL_Input::pointers[0]->get_cursor(0)->get_y();
    }

  }
}

/* EOF */

--- NEW FILE: mouse_pointer.hxx ---
//  $Id: mouse_pointer.hxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_MOUSE_POINTER_HXX
#define HEADER_PINGUS_INPUT_MOUSE_POINTER_HXX

#include "pointer.hxx"

namespace Input {

  namespace Pointers {
  
    /**
      @brief maps the standard mouse into a pointer
    
      XML definition: <mouse-pointer/>
      */
    class MousePointer : public Pointer {
  
      private:
        float x_pos;
        float y_pos;
      
      public:
        MousePointer ();
    
        virtual const float& get_x_pos () const;
        virtual const float& get_y_pos () const;
      
        virtual void  set_pos (float new_x, float new_y);
      
        virtual void  update (float);
      
      private:
        MousePointer (const MousePointer&);
        MousePointer operator= (const MousePointer&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: multiple_pointer.cxx ---
//  $Id: multiple_pointer.cxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "multiple_pointer.hxx"

namespace Input {

  namespace Pointers {

    MultiplePointer::MultiplePointer (const std::vector<Pointer*>& pointers_) 
                                    : pointers(pointers_),
                                      old_x_pos(0),
                                      old_y_pos(0),
                                      x_pos(0),
                                      y_pos(0)
    {
    }

    MultiplePointer::~MultiplePointer ()
    {
      for (unsigned int i = 0; i < pointers.size(); ++i)
        delete pointers[i];
    }

    const float&
    MultiplePointer::get_x_pos () const
    {
      return x_pos;
    }

    const float&
    MultiplePointer::get_y_pos () const
    {
      return y_pos;
    }

    void
    MultiplePointer::set_pos (float x_pos, float y_pos)
    {
      for (unsigned int i = 0; i < pointers.size(); ++i)
        pointers[i]->set_pos(x_pos, y_pos);
    }    

    void
    MultiplePointer::update (float delta)
    {
      unsigned int do_break = UINT_MAX;
  
      for (unsigned int i = 0; i < pointers.size(); ++i)
        pointers[i]->update(delta);
        
      for (unsigned int i = 0; i < pointers.size(); ++i)
        {
          if (pointers[i]->get_x_pos() != old_x_pos)
            {
              old_x_pos = x_pos;
              x_pos = pointers[i]->get_x_pos();
              do_break = i;
            }
          
          if (pointers[i]->get_y_pos() != old_y_pos)
            {
              old_y_pos = y_pos;
              y_pos = pointers[i]->get_y_pos();
              do_break = i;
            }
          
          if (do_break != UINT_MAX)
            break;
        }

      // no pointer changed, so there's no need to update the other pointers
      if (do_break == UINT_MAX)
        return;
                  
      for (unsigned int n = 0; n < pointers.size(); ++n)
        if (n != do_break)
          pointers[n]->set_pos(x_pos, y_pos);
    }

  }
}

/* EOF */


--- NEW FILE: multiple_pointer.hxx ---
//  $Id: multiple_pointer.hxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_MULTIPLE_POINTER_HXX
#define HEADER_PINGUS_INPUT_MULTIPLE_POINTER_HXX

#include <vector>
#include "pointer.hxx"

namespace Input {

  namespace Pointers {

    /**
      @brief wrapper class allowing multiple pointers to be used as one
    
      XML definition: <multiple-pointer> <pointer 1>...<pointer N> 
</multiple-pointer>
    
      This class will check every contained pointer for changes and if any 
changes all
      pointers are updated to the new coordinates. If more than one pointer 
changes at
      the same time only the change of the first will be registered.
      */
    class MultiplePointer : public Pointer {
  
      private:
        std::vector<Pointer*> pointers;
      
        float old_x_pos;
        float old_y_pos;

        float x_pos;
        float y_pos;

      public:
        MultiplePointer (const std::vector<Pointer*>& pointers_);
       ~MultiplePointer ();
    
        virtual const float& get_x_pos () const;
        virtual const float& get_y_pos () const;
    
        virtual void set_pos (float x_pos, float y_pos);
    
        virtual void update (float delta);
      
      private:
        MultiplePointer (const MultiplePointer&);
        MultiplePointer operator= (const MultiplePointer&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: pointer.hxx ---
//  $Id: pointer.hxx,v 1.1 2002/08/24 11:37:31 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_POINTER_HXX
#define HEADER_PINGUS_INPUT_POINTER_HXX

#include "../../pingus.hxx"

namespace Input {

  namespace Pointers {

    /// abstract base class defining the pointer interface
    class Pointer
    {
    public:
      Pointer () { }
      virtual ~Pointer() { }  
    
      /// returns the X coordinate of the pointer
      virtual const float& get_x_pos () const =0;
    
      /// returns the Y coordinate of the pointer
      virtual const float& get_y_pos () const =0;

      /// sets the pointer to the given position    
      virtual void  set_pos (float, float) =0;
    
      virtual void  update (float) =0;
    
     private:
       Pointer (const Pointer&);
       Pointer operator= (const Pointer&);
    };

  }
}

#endif

/* EOF */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]