Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

gui_new_file_button.cxx

Go to the documentation of this file.
00001 //  $Id$
00002 //
00003 //  Pingus - A free Lemmings clone
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 <time.h>
00021 #include "controller.hxx"
00022 #include "screen_manager.hxx"
00023 #include "gui_new_file_button.hxx"
00024 
00025 GUINewFileButton::GUINewFileButton(const std::string& p)
00026   : GUIFileButton (p), pathname (p)
00027 {
00028   
00029 }
00030 
00031 void
00032 GUINewFileButton::draw(GraphicContext* parent_gc)
00033 {
00034   parent_gc->draw_fill_rect (x_pos, y_pos, 
00035                              x_pos +  width, y_pos + height,
00036                              Color (0x999900FF));
00037 
00038   parent_gc->draw_string (x_pos + 20, y_pos + 75, "..:: Save to new file ::..");
00039   //parent_gc->draw_string (x_pos + 30, y_pos + 40, filename);
00040 
00041   if (mouse_over)
00042     parent_gc->draw_rect (x_pos, y_pos, 
00043                           x_pos +  width, y_pos + height,
00044                           Color (0xFFFFFFFF));
00045   else
00046     parent_gc->draw_rect (x_pos, y_pos, 
00047                           x_pos +  width, y_pos + height,
00048                           Color (0xFF0000FF));
00049 }
00050 
00051 std::string 
00052 GUINewFileButton::generate_filename()
00053 {
00054   char buffer[32];
00055   time_t curtime;
00056   struct tm *loctime;
00057   curtime = time (NULL);
00058   loctime = localtime(&curtime);
00059   strftime(buffer, 32, "%Y%m%d-%H%M%S", loctime);
00060 
00061   return pathname + "/" + std::string(buffer) + ".construo";
00062 }
00063 
00064 void
00065 GUINewFileButton::on_click()
00066 {
00067   std::string filename = generate_filename();
00068   std::cout << "Saving to: " <<  filename << std::endl;
00069   Controller::instance()->save_world (filename); 
00070   ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI);
00071 }
00072 
00073 /* EOF */

Generated on Thu Jul 24 10:24:30 2003 for Construo by doxygen1.3-rc3