1 // $Id: world_button.cxx,v 1.8 2003/07/26 11:18:47 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
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.
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.
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.
21 #include "controller.hxx"
22 #include "screen_manager.hxx"
23 #include "world_button.hxx"
24 #include "construo_error.hxx"
26 WorldButton::WorldButton (const std::string
& arg_filename
, Mode m
)
27 : GUIFileButton (arg_filename
),
34 WorldButton::~WorldButton ()
40 WorldButton::load_world ()
44 || mtime
!= system_context
->get_mtime(filename
))
48 world
= new World(filename
);
49 mtime
= system_context
->get_mtime(filename
);
50 } catch (ConstruoError
& err
) {
51 std::cout
<< "ERROR: " << err
.msg
<< std::endl
;
52 std::cout
<< "ERROR: WorldButton: Somthing went wrong loading " << filename
<< std::endl
;
60 WorldButton::draw (GraphicContext
* parent_gc
)
64 parent_gc
->draw_fill_rect (x_pos
, y_pos
,
65 x_pos
+ width
, y_pos
+ height
,
68 ZoomGraphicContext
gc (x_pos
, y_pos
, x_pos
+ width
, y_pos
+ height
);
69 gc
.set_parent_gc(parent_gc
);
75 // FIXME: bounding box should be calculated in construtor
76 const BoundingBox
& box
= world
->calc_bounding_box();
77 gc
.zoom_to((int) box
.x1
, (int)box
.y1
,
78 (int)box
.x2
, (int)box
.y2
);
79 world
->draw_colliders (&gc
);
80 world
->draw_springs (&gc
);
84 // Draw an 'X' for broken levels
85 gc
.draw_line (0,0, gc
.get_width (), gc
.get_height (), Color (0xFF00FFFF));
86 gc
.draw_line (0,gc
.get_height (), gc
.get_width (), 0, Color (0xFF00FFFF));
92 parent_gc
->draw_rect (x_pos
, y_pos
,
93 x_pos
+ width
, y_pos
+ height
,
96 parent_gc
->draw_rect (x_pos
, y_pos
,
97 x_pos
+ width
, y_pos
+ height
,
100 parent_gc
->draw_string (x_pos
+ 20, y_pos
+ 160, filename
);
104 WorldButton::on_click ()
106 std::cout
<< "WorldButton: detected click on: " << filename
<< std::endl
;
107 if (mode
== SAVE_BUTTON
)
109 Controller::instance()->save_world(filename
);
110 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI
);
114 Controller::instance()->load_world(filename
);
115 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI
);