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

« back to all changes in this revision

Viewing changes to src/editor/WeatherObj.cc

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: WeatherObj.cc,v 1.9 2001/08/12 18:36:41 grumbel 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 "../XMLhelper.hh"
21
 
#include "../PingusResource.hh"
22
 
#include "EditorView.hh"
23
 
#include "WeatherObj.hh"
24
 
 
25
 
WeatherObj::WeatherObj(const WeatherData& data)
26
 
  : SpriteEditorObj (pos)
27
 
{
28
 
  type = data.type;
29
 
  pos = CL_Vector(0,0,200);
30
 
  dragging = false;
31
 
 
32
 
  if (type == "rain")
33
 
    {
34
 
      sprite = Sprite("editor/weather_rain", "core");
35
 
    }
36
 
  else if (type == "snow")
37
 
    {
38
 
      sprite = Sprite("editor/weather_snow", "core");
39
 
    }  
40
 
  else 
41
 
    {
42
 
      std::cout << "WeatherObj: Unknown weather type: " << type << std::endl;
43
 
      sprite = Sprite("editor/weather_rain", "core");
44
 
    }
45
 
}
46
 
 
47
 
WeatherObj::~WeatherObj()
48
 
{
49
 
}
50
 
 
51
 
void 
52
 
WeatherObj::draw (boost::dummy_ptr<EditorView> view)
53
 
{
54
 
  std::cout << "Dragging: " << dragging << std::endl;
55
 
      
56
 
  if (dragging)
57
 
    {
58
 
      for (int x = 0; x < 320; x += sprite.get_width () + 4)
59
 
        {
60
 
          view->draw_fillrect (x, 0,
61
 
                               x + sprite.get_width (), sprite.get_height (),
62
 
                               1.0f, 1.0f, 1.0f, 0.5f);
63
 
        }
64
 
    }
65
 
 
66
 
  CL_Vector tmp_pos (pos);
67
 
  pos.x = int((pos.x + sprite.get_width ()/2)
68
 
              /sprite.get_width ()) * sprite.get_width ();
69
 
  pos.y = int((pos.y - sprite.get_height ()/2)
70
 
              /sprite.get_height ()) * sprite.get_height ();
71
 
  SpriteEditorObj::draw (view);
72
 
  pos = tmp_pos;
73
 
}
74
 
  
75
 
void   
76
 
WeatherObj::write_xml(std::ofstream* xml)
77
 
{
78
 
  (*xml) << "  <weather>\n"
79
 
         << "    <type>" << type << "</type>\n";
80
 
  XMLhelper::write_position_xml(xml, pos);
81
 
  (*xml) << "  </weather>\n"
82
 
         << std::endl;
83
 
}
84
 
 
85
 
boost::shared_ptr<EditorObj>
86
 
WeatherObj::duplicate()
87
 
{
88
 
  return boost::shared_ptr<EditorObj>(new WeatherObj(*this));
89
 
}
90
 
 
91
 
void 
92
 
WeatherObj::drag ()
93
 
{
94
 
  dragging = true;
95
 
}
96
 
 
97
 
void 
98
 
WeatherObj::drop ()
99
 
{
100
 
  dragging = false;
101
 
  pos.x = int((pos.x + sprite.get_width ()/2)
102
 
              /sprite.get_width ()) * sprite.get_width ();
103
 
  pos.y = int((pos.y - sprite.get_height ()/2)
104
 
              /sprite.get_height ()) * sprite.get_height ();
105
 
}
106
 
 
107
 
/* EOF */