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/scrollers Makefile.am,NONE,1.1


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/input/scrollers Makefile.am,NONE,1.1 axis_scroller.cxx,NONE,1.1 axis_scroller.hxx,NONE,1.1 dummy_scroller.hxx,NONE,1.1 inverted_scroller.cxx,NONE,1.1 inverted_scroller.hxx,NONE,1.1 joystick_scroller.cxx,NONE,1.1 joystick_scroller.hxx,NONE,1.1 mouse_scroller.cxx,NONE,1.1 mouse_scroller.hxx,NONE,1.1 multiple_scroller.cxx,NONE,1.1 multiple_scroller.hxx,NONE,1.1 pointer_scroller.cxx,NONE,1.1 pointer_scroller.hxx,NONE,1.1 scroller.hxx,NONE,1.1
Date: 24 Aug 2002 11:37:34 -0000

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

Added Files:
        Makefile.am axis_scroller.cxx axis_scroller.hxx 
        dummy_scroller.hxx inverted_scroller.cxx inverted_scroller.hxx 
        joystick_scroller.cxx joystick_scroller.hxx mouse_scroller.cxx 
        mouse_scroller.hxx multiple_scroller.cxx multiple_scroller.hxx 
        pointer_scroller.cxx pointer_scroller.hxx scroller.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_scrollers.a

libpingus_input_scrollers_a_SOURCES =       \
        axis_scroller.hxx axis_scroller.cxx \
        dummy_scroller.hxx \
        inverted_scroller.hxx inverted_scroller.cxx \
        joystick_scroller.hxx joystick_scroller.cxx \
        mouse_scroller.hxx mouse_scroller.cxx \
        multiple_scroller.hxx multiple_scroller.cxx \
        pointer_scroller.hxx pointer_scroller.cxx \
        scroller.hxx

# EOF #

--- NEW FILE: axis_scroller.cxx ---
//  $Id: axis_scroller.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_scroller.hxx"

namespace Input {

  using Axes::Axis;

  namespace Scrollers {

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

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

    const float&
    AxisScroller::get_x_delta () const
    {
      return x_delta;
    }

    const float&
    AxisScroller::get_y_delta () const
    {
      return y_delta;
    }

    void
    AxisScroller::get_delta (float& x, float& y) const
    {
      x = x_delta;
      y = y_delta;
    }

    void
    AxisScroller::update (float delta)
    {
      x_delta = 0;
      y_delta = 0;    

      for (std::vector<Axis*>::const_iterator it = axes.begin(); it != 
axes.end(); it++)
        {
          (*it)->update(delta);
      
          x_delta += cos((*it)->get_angle()) * speed * delta;
          y_delta += sin((*it)->get_angle()) * speed * delta;
        } 
  
    }

  }
}

/* EOF */


--- NEW FILE: axis_scroller.hxx ---
//  $Id: axis_scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_AXIS_SCROLLER_HXX

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

namespace Input {

  namespace Axes {
    class Axis;
  }

  namespace Scrollers {

    /**
      @brief create a Scroller out of two or more axes
    
      XML definition: <axis-scroller speed="?"> <axis 1>...<axis N> 
</axis-scroller>
    
      This class requires at least two axes whereby it's enforced that the first
      two have different angles.
      */
    class AxisScroller : public Scroller {
      private:
        const std::vector<Axes::Axis*> axes;
      
        const float speed;
              float x_delta;
              float y_delta;
      
      public:
        AxisScroller (const std::vector<Axes::Axis*>& axes_, float speed_);
       ~AxisScroller ();
      
        const float& get_x_delta () const;
        const float& get_y_delta () const;
      
        void  get_delta (float& x, float& y) const;
      
        void  update (float delta);
      
      private:
        AxisScroller (const AxisScroller&);
        AxisScroller operator= (const AxisScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: dummy_scroller.hxx ---
//  $Id: dummy_scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_DUMMY_SCROLLER_HXX

#include "scroller.hxx"

namespace Input {

  namespace Scrollers {

    /**
      @brief dummy class to be used if an Scroller is required but none defined
    
      XML definition: none
     */
    class DummyScroller : public Scroller {
      private:
        const float delta;
      
      public:
      
        DummyScroller () : delta(0) { }
      
        const float& get_x_delta () const { return delta; }
        const float& get_y_delta () const { return delta; }
      
        void  get_delta (float& x_delta, float& y_delta) const { x_delta = 
delta; y_delta = delta; }
      
        void  update (float) { }
      
      private:
        DummyScroller (const DummyScroller&);
        DummyScroller operator= (const DummyScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: inverted_scroller.cxx ---
//  $Id: inverted_scroller.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 "inverted_scroller.hxx"

namespace Input {

  namespace Scrollers {

    InvertedScroller::InvertedScroller (Scroller* scroller_, bool invert_x_, 
bool invert_y_) 
                                      : scroller(scroller_),
                                        invert_x(invert_x_), 
                                        invert_y(invert_y_)
    {
    }
  
    InvertedScroller::~InvertedScroller ()
    {
      delete scroller;
    }
  
    const float&
    InvertedScroller::get_x_delta () const
    {
      return x_pos;
    }
  
    const float&
    InvertedScroller::get_y_delta () const
    {
      return y_pos;
    }
  
    void
    InvertedScroller::get_delta (float& x, float& y) const
    {
      x = x_pos;
      y = y_pos;
    }
  
    void
    InvertedScroller::update (float delta)
    {
      scroller->update(delta);
    
      (invert_x) ? x_pos = -(scroller->get_x_delta()) : x_pos = 
scroller->get_x_delta();
      (invert_y) ? y_pos = -(scroller->get_y_delta()) : x_pos = 
scroller->get_y_delta();
    }

  }
}

/* EOF */

--- NEW FILE: inverted_scroller.hxx ---
//  $Id: inverted_scroller.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_INVERTED_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_INVERTED_SCROLLER_HXX

#include "scroller.hxx"

namespace Input {

  namespace Scrollers {

    /**
      @brief inverts the results of the contained scroller
  
      XML definition: <inverted-scroller invert-x="0/1" invert-y="0/1" 
speed="?"> <scroller> </inverted-scroller>
  
      Wheter the X and/or the Y axis shall be inverted must be specified 
explizitly.
      */
    class InvertedScroller : public Scroller {
      private:
        Scroller* const scroller;
    
        const bool invert_x;
        const bool invert_y;
    
        float x_pos;
        float y_pos;
    
      public:
        InvertedScroller (Scroller* scroller_, bool invert_x_, bool invert_y_);
       ~InvertedScroller ();
    
        const float& get_x_delta () const;
        const float& get_y_delta () const;
    
        void  get_delta (float& x, float& y) const;

        void  update (float delta);
    
      private:
        InvertedScroller (const InvertedScroller&);
        InvertedScroller operator= (const InvertedScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: joystick_scroller.cxx ---
//  $Id: joystick_scroller.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 "../axes/joystick_axis.hxx"
#include "joystick_scroller.hxx"

namespace Input {

  using Axes::JoystickAxis;

  namespace Scrollers {

    JoystickScroller::JoystickScroller (int id_, float speed_) 
                                      : id(id_),
                                        axis1(new JoystickAxis(id, 0, 0)),
                                        axis2(new JoystickAxis(id, 1, 90)),
                                        speed(speed_),
                                        x_delta(0),
                                        y_delta(0)
    {
    }
  
    JoystickScroller::~JoystickScroller ()
    {
      delete axis1;
      delete axis2;
    }
  
    const float&
    JoystickScroller::get_x_delta () const
    {
      return x_delta;
    }
  
    const float&
    JoystickScroller::get_y_delta () const
    {
      return y_delta;
    }
  
    void
    JoystickScroller::get_delta (float& x, float& y) const
    {
      x = x_delta;
      y = y_delta;
    }
  
    void
    JoystickScroller::update (float delta)
    {
      axis1->update(delta);
      axis2->update(delta);
    
      x_delta = axis1->get_pos() * speed;
      y_delta = axis2->get_pos() * speed;
    }
    
  }
}

/* EOF */

--- NEW FILE: joystick_scroller.hxx ---
//  $Id: joystick_scroller.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_JOYSTICK_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_JOYSTICK_SCROLLER_HXX

#include "scroller.hxx"

namespace Input {

  namespace Axes {
    class Axis;
  }

  namespace Scrollers {

    /**
      @brief maps the first two axes of a joystick into a Scroller
    
      XML definition: <joystick-scroller id="joystick id" speed="?"/>
      */
    class JoystickScroller : public Scroller {
      private:
        int id;
      
        Axes::Axis* const axis1;
        Axes::Axis* const axis2;
      
        const float speed;
      
        float x_delta;
        float y_delta;
      
      public:
        JoystickScroller (int id_, float speed_);
       ~JoystickScroller ();
      
        const float& get_x_delta () const;
        const float& get_y_delta () const;
      
        void  get_delta (float& x, float& y) const;
      
        void  update (float delta);
      
      private:
        JoystickScroller (const JoystickScroller&);
        JoystickScroller operator= (const JoystickScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: mouse_scroller.cxx ---
//  $Id: mouse_scroller.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_scroller.hxx"

namespace Input {

  namespace Scrollers {

    MouseScroller::MouseScroller () : old_x(0), old_y(0), x_delta(0), y_delta(0)
    {
    }  

    const float&
    MouseScroller::get_x_delta () const
    {
      return x_delta;
    }
  
    const float&
    MouseScroller::get_y_delta () const
    {
      return y_delta;
    }
  
    void
    MouseScroller::get_delta (float& x, float& y) const
    {
      x = x_delta;
      y = y_delta;
    }
  
    void
    MouseScroller::update (float)
    {
      x_delta = CL_Input::pointers[0]->get_cursor(0)->get_x() - old_x;
      y_delta = CL_Input::pointers[0]->get_cursor(0)->get_x() - old_y;
    
      old_x = CL_Input::pointers[0]->get_cursor(0)->get_x();
      old_y = CL_Input::pointers[0]->get_cursor(0)->get_y();
    }

  }
}

/* EOF */


--- NEW FILE: mouse_scroller.hxx ---
//  $Id: mouse_scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_MOUSE_SCROLLER_HXX

#include "scroller.hxx"

namespace Input {

  namespace Scrollers {
  
    /**
      @brief turns the mouse into a scroller
    
      XML definition: <mouse-scroller/>
      */
    class MouseScroller : public Scroller {
      private:
        float old_x;
        float old_y;
        float x_delta;
        float y_delta;
      
      public:
        MouseScroller ();
      
        const float& get_x_delta () const;
        const float& get_y_delta () const;
      
        void  get_delta (float& x, float& y) const;
      
        void  update (float);
      
      private:
        MouseScroller (const MouseScroller&);
        MouseScroller operator= (const MouseScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: multiple_scroller.cxx ---
//  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_scroller.hxx"

namespace Input {

  namespace Scrollers {

    MultipleScroller::MultipleScroller (const std::vector<Scroller*>& 
scrollers_) : scrollers(scrollers_)
    {
    }
  
    MultipleScroller::~MultipleScroller ()
    {
      for (std::vector<Scroller*>::const_iterator it = scrollers.begin(); it != 
scrollers.end(); it++)
        delete *it;
    }
  
    const float&
    MultipleScroller::get_x_delta () const
    {
      return x_pos;
    }
  
    const float&
    MultipleScroller::get_y_delta () const
    {
      return y_pos;
    }
  
    void
    MultipleScroller::get_delta (float& x, float& y) const
    {
      x = x_pos;
      y = y_pos;
    }
  
    void
    MultipleScroller::update (float delta)
    {
      bool found_delta = false;
  
      for (std::vector<Scroller*>::const_iterator it = scrollers.begin(); it != 
scrollers.end(); it++)
        {
          (*it)->update(delta);
        
          if (!found_delta && ((*it)->get_x_delta() || (*it)->get_y_delta()))
            {
              x_pos = (*it)->get_x_delta();
              y_pos = (*it)->get_y_delta();
              found_delta = true;
            }
        }
    }

  }
}

/* EOF */

--- NEW FILE: multiple_scroller.hxx ---
//  $Id: multiple_scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_MULTIPLE_SCROLLER_HXX

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

namespace Input {

  namespace Scrollers {

    /**
      @brief maps multiple Scrollers into one
    
      XML definition: <multiple-scroller> <scroller 1>...<scroller N> 
</multiple-scroller>
     */
    class MultipleScroller : public Scroller {
      private:
        std::vector<Scroller*> scrollers;
      
        float x_pos;
        float y_pos;
      
      public:
        MultipleScroller (const std::vector<Scroller*>& scrollers_);
       ~MultipleScroller ();
      
        const float& get_x_delta () const;
        const float& get_y_delta () const;
      
        void  get_delta (float& x, float& y) const;

        void  update (float delta);
      
      private:
        MultipleScroller (const MultipleScroller&);
        MultipleScroller operator= (const MultipleScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: pointer_scroller.cxx ---
//  $Id: pointer_scroller.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 "../buttons/button.hxx"
#include "../pointers/pointer.hxx"
#include "pointer_scroller.hxx"

namespace Input {

  using Buttons::Button;
  using Pointers::Pointer;

  namespace Scrollers {

    PointerScroller::PointerScroller (Pointer* pointer_, Button* modifier_) : 
pointer(pointer_), modifier(modifier_),
                                                                              
x_delta(0), y_delta(0), x_pos(-1), y_pos(-1)
    {
    }
  
    PointerScroller::~PointerScroller ()
    {
      delete pointer;
      delete modifier;
    }
  
    const float&
    PointerScroller::get_x_delta () const
    {
      return x_delta;
    }
  
    const float&
    PointerScroller::get_y_delta () const
    {
      return y_delta;
    }
  
    void
    PointerScroller::get_delta (float& x, float& y) const
    {
      x = x_delta;
      y = y_delta;
    }
  
    void
    PointerScroller::update (float delta)
    {
      pointer ->update(delta);
      modifier->update(delta);
  
      if (modifier->is_pressed())
        {
          if (x_pos == -1)
            {
              x_pos = pointer->get_x_pos();
              y_pos = pointer->get_y_pos();
            }
          else
            {
              x_delta = pointer->get_x_pos() - x_pos;
              y_delta = pointer->get_y_pos() - y_pos;
          
              pointer->set_pos(x_pos, y_pos);
          }
        }
      else
        {
          x_pos = -1;
          y_pos = -1;
        }
    }

  }
}

/* EOF */

--- NEW FILE: pointer_scroller.hxx ---
//  $Id: pointer_scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_POINTER_SCROLLER_HXX

#include "scroller.hxx"

namespace Input {

  namespace Buttons {
    class Button;
  }
  
  namespace Pointers {
    class Pointer;
  }

  namespace Scrollers {

    /**
      @brief allows a Pointer to be used as a Scroller
    
      XML definition: <pointer-scroller> <pointer><button> </pointer-scroller>
    
      A PointerScroller creates ScrollEvents whenever the associated Button is 
pressed.
      The Pointer itself is then reset to it's original position to prevent the 
visible
      pointer from moving while the Pointer is used as a Scroller.
      */
    class PointerScroller : public Scroller {
      private:
        Pointers::Pointer* const pointer;
        Buttons::Button*   const modifier;
      
        float x_delta;
        float y_delta;
        float x_pos;
        float y_pos;
      
      public:
      
        PointerScroller (Pointers::Pointer* pointer_, Buttons::Button* 
modifier_);
       ~PointerScroller ();
      
        const float& get_x_delta () const;
        const float& get_y_delta () const;
      
        void  get_delta (float& x, float& y) const;
      
        void  update (float delta);
      
      private:
        PointerScroller (const PointerScroller&);
        PointerScroller operator= (const PointerScroller&);
    };

  }
}

#endif

/* EOF */

--- NEW FILE: scroller.hxx ---
//  $Id: scroller.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_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_SCROLLER_HXX

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

namespace Input {

  namespace Scrollers {

    /// abstract base class defining the scroller interface
    class Scroller {
      public:
        Scroller () { }
        virtual ~Scroller () { }
      
        /// returns the scroll delta in X direction
        virtual const float& get_x_delta () const =0;
      
        /// returns the scroll delta in Y direction
        virtual const float& get_y_delta () const =0;
      
        /// writes the X/Y scroll delta into it's parameters
        virtual void  get_delta (float&, float&) const =0;
      
        virtual void  update (float) =0;
      
      private:
        Scroller (const Scroller&);
        Scroller operator= (const Scroller&);
    };
    
  }
}

#endif

/* EOF */





reply via email to

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