Rebuild autotool system
[construo.git] / world_button.cxx
bloba482094d9d35c83e1a6373cd8b5e29bd585e2f57
1 // $Id: world_button.cxx,v 1.8 2003/07/26 11:18:47 grumbel Exp $
2 //
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 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.
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.
20 #include "world.hxx"
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),
28 world(0),
29 file_broken(false),
30 mode (m)
34 WorldButton::~WorldButton ()
36 delete world;
39 void
40 WorldButton::load_world ()
42 if ((world == 0
43 && !file_broken)
44 || mtime != system_context->get_mtime(filename))
46 try {
47 delete world;
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;
53 world = 0;
54 file_broken = true;
59 void
60 WorldButton::draw (GraphicContext* parent_gc)
62 load_world();
64 parent_gc->draw_fill_rect (x_pos, y_pos,
65 x_pos + width, y_pos + height,
66 Color (0xBB0000FF));
68 ZoomGraphicContext gc (x_pos, y_pos, x_pos + width, y_pos + height);
69 gc.set_parent_gc(parent_gc);
71 gc.lock();
73 if (world)
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);
82 else
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));
89 gc.unlock();
91 if (mouse_over)
92 parent_gc->draw_rect (x_pos, y_pos,
93 x_pos + width, y_pos + height,
94 Color (0xFFFFFFFF));
95 else
96 parent_gc->draw_rect (x_pos, y_pos,
97 x_pos + width, y_pos + height,
98 Color (0xFF0000FF));
100 parent_gc->draw_string (x_pos + 20, y_pos + 160, filename);
103 void
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);
112 else // LOAD BUTTON
114 Controller::instance()->load_world(filename);
115 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI);
119 /* EOF */