This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 // $Id: world_button.cxx,v 1.7 2003/01/11 19:07:48 grumbel Exp $ 00002 // 00003 // Construo - A wire-frame construction gamee 00004 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de> 00005 // 00006 // This program is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU General Public License 00008 // as published by the Free Software Foundation; either version 2 00009 // of the License, or (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 #include "world.hxx" 00021 #include "controller.hxx" 00022 #include "screen_manager.hxx" 00023 #include "world_button.hxx" 00024 #include "construo_error.hxx" 00025 00026 WorldButton::WorldButton (const std::string& arg_filename, Mode m) 00027 : GUIFileButton (arg_filename), 00028 world(0), 00029 file_broken(false), 00030 mode (m) 00031 { 00032 } 00033 00034 WorldButton::~WorldButton () 00035 { 00036 delete world; 00037 } 00038 00039 void 00040 WorldButton::load_world () 00041 { 00042 if ((world == 0 00043 && !file_broken) 00044 || mtime != system_context->get_mtime(filename)) 00045 { 00046 try { 00047 delete world; 00048 world = new World(filename); 00049 mtime = system_context->get_mtime(filename); 00050 } catch (ConstruoError& err) { 00051 std::cout << "ERROR: " << err.msg << std::endl; 00052 std::cout << "ERROR: WorldButton: Somthing went wrong loading " << filename << std::endl; 00053 world = 0; 00054 file_broken = true; 00055 } 00056 } 00057 } 00058 00059 void 00060 WorldButton::draw (GraphicContext* parent_gc) 00061 { 00062 load_world(); 00063 00064 parent_gc->draw_fill_rect (x_pos, y_pos, 00065 x_pos + width, y_pos + height, 00066 Color (0xBB0000FF)); 00067 00068 ZoomGraphicContext gc (x_pos, y_pos, x_pos + width, y_pos + height); 00069 gc.set_parent_gc(parent_gc); 00070 00071 gc.lock(); 00072 00073 if (world) 00074 { 00075 // FIXME: bounding box should be calculated in construtor 00076 const WorldBoundingBox& box = world->calc_bounding_box(); 00077 gc.zoom_to((int) box.x1, (int)box.y1, 00078 (int)box.x2, (int)box.y2); 00079 world->draw_colliders (&gc); 00080 world->draw_springs (&gc); 00081 } 00082 else 00083 { 00084 // Draw an 'X' for broken levels 00085 gc.draw_line (0,0, gc.get_width (), gc.get_height (), Color (0xFF00FFFF)); 00086 gc.draw_line (0,gc.get_height (), gc.get_width (), 0, Color (0xFF00FFFF)); 00087 } 00088 00089 gc.unlock(); 00090 00091 if (mouse_over) 00092 parent_gc->draw_rect (x_pos, y_pos, 00093 x_pos + width, y_pos + height, 00094 Color (0xFFFFFFFF)); 00095 else 00096 parent_gc->draw_rect (x_pos, y_pos, 00097 x_pos + width, y_pos + height, 00098 Color (0xFF0000FF)); 00099 00100 parent_gc->draw_string (x_pos + 20, y_pos + 160, filename); 00101 } 00102 00103 void 00104 WorldButton::on_click () 00105 { 00106 std::cout << "WorldButton: detected click on: " << filename << std::endl; 00107 if (mode == SAVE_BUTTON) 00108 { 00109 Controller::instance()->save_world(filename); 00110 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI); 00111 } 00112 else // LOAD BUTTON 00113 { 00114 Controller::instance()->load_world(filename); 00115 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI); 00116 } 00117 } 00118 00119 /* EOF */