~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/input/scroller_factory.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: scroller_factory.cxx,v 1.10 2002/09/28 19:31:06 torangan Exp $
2
 
// 
3
 
//  Pingus - A free Lemmings clone
4
 
//  Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
5
 
//
6
 
//  This program is free software; you can redistribute it and/or
7
 
//  modify it under the terms of the GNU General Public License
8
 
//  as published by the Free Software Foundation; either version 2
9
 
//  of the License, or (at your option) any later version.
10
 
//
11
 
//  This program is distributed in the hope that it will be useful,
12
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
//  GNU General Public License for more details.
15
 
// 
16
 
//  You should have received a copy of the GNU General Public License
17
 
//  along with this program; if not, write to the Free Software
18
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
 
20
 
#include <stdlib.h>
21
 
#include "../xml_helper.hxx"
22
 
#include "../pingus_error.hxx"
23
 
#include "axis.hxx"
24
 
#include "axis_factory.hxx"
25
 
#include "button.hxx"
26
 
#include "button_factory.hxx"
27
 
#include "pointer.hxx"
28
 
#include "pointer_factory.hxx"
29
 
#include "scroller_factory.hxx"
30
 
#include "scrollers/axis_scroller.hxx"
31
 
#include "scrollers/inverted_scroller.hxx"
32
 
#include "scrollers/joystick_scroller.hxx"
33
 
#include "scrollers/mouse_scroller.hxx"
34
 
#include "scrollers/multiple_scroller.hxx"
35
 
#include "scrollers/pointer_scroller.hxx"
36
 
 
37
 
 
38
 
namespace Input {
39
 
 
40
 
using namespace Scrollers;
41
 
 
42
 
Scroller*
43
 
ScrollerFactory::create(xmlNodePtr cur)
44
 
{
45
 
  if (!cur)
46
 
    PingusError::raise("ScrollerFactory called without an element");
47
 
 
48
 
  if (XMLhelper::equal_str(cur->name, "axis-scroller"))
49
 
    return axis_scroller(cur);
50
 
    
51
 
  else if (XMLhelper::equal_str(cur->name, "inverted-scroller"))
52
 
    return inverted_scroller(cur);
53
 
    
54
 
  else if (XMLhelper::equal_str(cur->name, "joystick-scroller"))
55
 
    return joystick_scroller(cur);
56
 
    
57
 
  else if (XMLhelper::equal_str(cur->name, "mouse-scroller"))
58
 
    return mouse_scroller(cur);
59
 
    
60
 
  else if (XMLhelper::equal_str(cur->name, "multiple-scroller"))
61
 
    return multiple_scroller(cur->children);
62
 
    
63
 
  else if (XMLhelper::equal_str(cur->name, "pointer-scroller"))
64
 
    return pointer_scroller(XMLhelper::skip_blank(cur->children));
65
 
    
66
 
  else
67
 
    PingusError::raise(std::string("Unknown scroller type: ") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
68
 
    
69
 
  return 0; // never reached
70
 
}
71
 
 
72
 
Scroller*
73
 
ScrollerFactory::axis_scroller (xmlNodePtr cur)
74
 
{
75
 
  float speed;
76
 
  if (!XMLhelper::get_prop(cur, "speed", speed))
77
 
    PingusError::raise("AxisScroller without speed parameter");
78
 
 
79
 
  std::vector<Axis*> axes;
80
 
  cur = cur->children;
81
 
  
82
 
  while (cur)
83
 
    {
84
 
      if (xmlIsBlankNode(cur))
85
 
        {
86
 
          cur = cur->next;
87
 
          continue;
88
 
        }
89
 
        
90
 
      axes.push_back(AxisFactory::create(cur));
91
 
      cur = cur->next;
92
 
    }
93
 
 
94
 
  return new AxisScroller(axes, speed);
95
 
}
96
 
 
97
 
Scroller*
98
 
ScrollerFactory::inverted_scroller (xmlNodePtr cur)
99
 
{
100
 
  bool invert_x;
101
 
  if (!XMLhelper::get_prop(cur, "invert-x", invert_x))
102
 
    PingusError::raise("InvertedScroller without invert X parameter");
103
 
 
104
 
  bool invert_y;
105
 
  if (!XMLhelper::get_prop(cur, "invert-y", invert_y))
106
 
    PingusError::raise("InvertedScroller without invert Y parameter");
107
 
 
108
 
  Scroller* scroller;
109
 
  cur = XMLhelper::skip_blank(cur->children);
110
 
  scroller = create(cur);
111
 
  
112
 
  return new InvertedScroller(scroller, invert_x, invert_y);
113
 
}
114
 
 
115
 
Scroller*
116
 
ScrollerFactory::joystick_scroller (xmlNodePtr cur)
117
 
{
118
 
  int id;
119
 
  if (!XMLhelper::get_prop(cur, "id", id))
120
 
    PingusError::raise("JoystickScroller without id parameter");
121
 
    
122
 
  float speed;
123
 
  if (!XMLhelper::get_prop(cur, "speed", speed))
124
 
    PingusError::raise("JoystickScroller without speed parameter");
125
 
  
126
 
  return new JoystickScroller(id, speed);
127
 
}
128
 
 
129
 
Scroller*
130
 
ScrollerFactory::mouse_scroller (xmlNodePtr)
131
 
{
132
 
  return new MouseScroller;
133
 
}
134
 
 
135
 
Scroller*
136
 
ScrollerFactory::multiple_scroller (xmlNodePtr cur)
137
 
{
138
 
  std::vector<Scroller*> scrollers;
139
 
  
140
 
  while (cur)
141
 
    {    
142
 
      if (xmlIsBlankNode(cur))
143
 
        cur = cur->next;
144
 
    
145
 
      scrollers.push_back(create(cur));
146
 
      cur = cur->next;
147
 
    }
148
 
          
149
 
  return new MultipleScroller(scrollers);
150
 
}
151
 
 
152
 
Scroller*
153
 
ScrollerFactory::pointer_scroller (xmlNodePtr cur)
154
 
{
155
 
  Pointer* pointer;
156
 
  Button*  button;
157
 
  
158
 
  pointer = PointerFactory::create(cur);
159
 
  
160
 
  cur = XMLhelper::skip_blank(cur->next);
161
 
  button = ButtonFactory::create(cur);
162
 
  
163
 
  return new PointerScroller(pointer, button);
164
 
}
165
 
 
166
 
} // namespace Input
167
 
 
168
 
/* EOF */