[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/input scroller_factory.cxx,NONE,1.1 s
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/input scroller_factory.cxx,NONE,1.1 scroller_factory.hxx,NONE,1.1 |
Date: |
11 Jul 2002 16:09:10 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv27654
Added Files:
scroller_factory.cxx scroller_factory.hxx
Log Message:
Factory for Scrollers
--- NEW FILE: scroller_factory.cxx ---
// $Id: scroller_factory.cxx,v 1.1 2002/07/11 16:09:08 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 <stdlib.h>
#include "../xml_helper.hxx"
#include "../pingus_error.hxx"
#include "axis.hxx"
#include "axis_factory.hxx"
#include "axis_scroller.hxx"
#include "button.hxx"
#include "button_factory.hxx"
#include "joystick_scroller.hxx"
#include "mouse_scroller.hxx"
#include "pointer.hxx"
#include "pointer_factory.hxx"
#include "pointer_scroller.hxx"
#include "scroller_factory.hxx"
namespace Input {
Scroller*
ScrollerFactory::create(xmlNodePtr cur)
{
if (!cur)
throw PingusError("ScrollerFactory called without an element");
if (xmlIsBlankNode(cur))
cur = cur->next;
if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "axis-scroller"))
return axis_scroller(cur);
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"joystick-scroller"))
return joystick_scroller(cur);
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"mouse-scroller"))
return mouse_scroller(cur);
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"pointer-scroller"))
return pointer_scroller(cur);
else
throw PingusError(std::string("Unknown scroller type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
}
Scroller*
ScrollerFactory::axis_scroller (xmlNodePtr cur)
{
char * speed_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("speed")));
if (!speed_str)
throw PingusError("AxisScroller without speed parameter");
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
free(speed_str);
Axis *axis1, *axis2;
cur = cur->children;
if (xmlIsBlankNode(cur))
cur = cur->next;
axis1 = AxisFactory::create(cur);
cur = cur-> next;
if (xmlIsBlankNode(cur))
cur = cur->next;
axis2 = AxisFactory::create(cur);
return new AxisScroller(axis1, axis2, speed);
}
Scroller*
ScrollerFactory::joystick_scroller (xmlNodePtr cur)
{
char * id_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("id")));
if (!id_str)
throw PingusError("JoystickScroller without id parameter");
char * speed_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("speed")));
if (!speed_str)
throw PingusError("JoystickScroller without speed parameter");
int id = strtol(id_str, reinterpret_cast<char**>(NULL), 10);
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
free(id_str);
free(speed_str);
return new JoystickScroller(id, speed);
}
Scroller*
ScrollerFactory::mouse_scroller (xmlNodePtr)
{
return new MouseScroller;
}
Scroller*
ScrollerFactory::pointer_scroller (xmlNodePtr cur)
{
Pointer* pointer;
Button* button;
cur = cur->children;
if (xmlIsBlankNode(cur))
cur = cur->next;
pointer = PointerFactory::create(cur);
cur = cur->next;
if (xmlIsBlankNode(cur))
cur = cur->next;
button = ButtonFactory::create(cur);
return new PointerScroller(pointer, button);
}
}
/* EOF */
--- NEW FILE: scroller_factory.hxx ---
// $Id: scroller_factory.hxx,v 1.1 2002/07/11 16:09:08 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_FACTORY_HXX
#define HEADER_PINGUS_INPUT_SCROLLER_FACTORY_HXX
#include "../libxmlfwd.hxx"
namespace Input {
class Scroller;
class ScrollerFactory
{
private:
static inline Scroller* axis_scroller (xmlNodePtr cur);
static inline Scroller* joystick_scroller (xmlNodePtr cur);
static inline Scroller* mouse_scroller (xmlNodePtr cur);
static inline Scroller* pointer_scroller (xmlNodePtr cur);
public:
static Scroller* create (xmlNodePtr cur);
};
}
#endif
/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/input scroller_factory.cxx,NONE,1.1 scroller_factory.hxx,NONE,1.1,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/input button_factory.cxx,1.3,1.4 button_factory.hxx,1.2,1.3
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/input inverted_scroller.cxx,NONE,1.1 inverted_scroller.hxx,NONE,1.1 multiple_scroller.cxx,NONE,1.1 multiple_scroller.hxx,NONE,1.1 joystick_scroller.cxx,1.1,1.2 scroller_factory.cxx,1.1,1.2 scroller_factory.hxx,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/input button_factory.cxx,1.3,1.4 button_factory.hxx,1.2,1.3
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/input inverted_scroller.cxx,NONE,1.1 inverted_scroller.hxx,NONE,1.1 multiple_scroller.cxx,NONE,1.1 multiple_scroller.hxx,NONE,1.1 joystick_scroller.cxx,1.1,1.2 scroller_factory.cxx,1.1,1.2 scroller_factory.hxx,1.1,1.2
- Index(es):