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

gui_directory.cxx

Go to the documentation of this file.
00001 //  $Id: gui_directory.cxx,v 1.10 2003/01/11 19:07:48 grumbel Exp $
00002 //
00003 //  Construo - A wire-frame construction gamee
00004 //  Copyright (C) 2002 Ingo Ruhnke <[email protected]>
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 "construo.hxx"
00021 #include "system_context.hxx"
00022 #include "world_button.hxx"
00023 #include "gui_directory_button.hxx"
00024 #include "gui_file_manager.hxx"
00025 #include "gui_new_file_button.hxx"
00026 #include "gui_directory.hxx"
00027 
00028 GUIDirectory::GUIDirectory (const std::string& arg_pathname, Mode m)
00029   : GUIChildManager (0, 0, 800, 600),
00030     pathname (arg_pathname),
00031     mode (m)
00032 {
00033   mtime = system_context->get_mtime(pathname);
00034   std::vector<std::string> dir = system_context->read_directory(pathname);
00035   
00036   if (mode == SAVE_DIRECTORY && pathname != "/")
00037     files.push_back(new GUINewFileButton(pathname));
00038 
00039   for (std::vector<std::string>::iterator i = dir.begin(); i != dir.end(); ++i)
00040     {
00041       std::string filename = pathname + *i;
00042 
00043       FileType type = system_context->get_file_type (filename);
00044 
00045       std::cout << "Creating object for: " << filename << std::endl;
00046 
00047       if (type == FT_DIRECTORY)
00048         {
00049           if (*(filename.end()-1) == '/') // FIXME: Hack
00050             files.push_back (new GUIDirectoryButton (filename));
00051           else
00052             files.push_back (new GUIDirectoryButton (filename + "/"));
00053         }
00054       else if (type == FT_CONSTRUO_FILE)
00055         {
00056           if (mode == SAVE_DIRECTORY)
00057             files.push_back (new WorldButton (filename, WorldButton::SAVE_BUTTON));
00058           else
00059             files.push_back (new WorldButton (filename, WorldButton::LOAD_BUTTON));
00060         }
00061       else // (type == FT_UNKNOWN_FILE)
00062         {
00063           // ignore unknown files
00064           std::cout << "GUIFileManager: ignoring '" << filename
00065                     << "' since it has unknown filetype" << std::endl;
00066         }
00067     }
00068 
00069   offset = 0;
00070   place_components ();
00071 }
00072 
00073 GUIDirectory::~GUIDirectory ()
00074 {
00075   for(std::vector<GUIFileButton*>::iterator i = files.begin();
00076       i != files.end(); ++i)
00077     {
00078       // FIXME: Very ugly, we remove all components from the manager so that he doesn't delete them twice
00079       remove(*i);
00080       delete *i;
00081     }
00082 }
00083 
00084 void
00085 GUIDirectory::place_components ()
00086 {
00087   // Remove all file components
00088   for(std::vector<GUIFileButton*>::iterator i = files.begin();
00089       i != files.end(); ++i)
00090     {
00091       remove(*i);
00092     }
00093 
00094   int row = 0;
00095   int column = 0;
00096   int count = 0;
00097 
00098   //std::cout << "OFFSET: " << offset << std::endl;
00099 
00100   for(std::vector<GUIFileButton*>::size_type i = 0 + offset;
00101       i < files.size() && count < 9;
00102       ++i)
00103     {
00104       files[i]->set_position(column * (200 + 50) + 50,
00105                              row * (150 + 37) + 30);
00106       add(files[i]);
00107 
00108       column += 1;
00109       if (column >= 3) // row is full
00110         {
00111           column = 0;
00112           row += 1;
00113         }
00114       if (row >= 3)
00115         return;
00116 
00117       ++count;
00118     }
00119 }
00120 
00121 void
00122 GUIDirectory::draw_overlay (GraphicContext* gc)
00123 {
00124 }
00125 
00126 void
00127 GUIDirectory::move_up ()
00128 {
00129   if (offset >= 3)
00130     offset -= 3;
00131 
00132   place_components ();
00133 }
00134 
00135 void
00136 GUIDirectory::move_down ()
00137 {
00138   offset += 3;
00139 
00140   if (offset >= int(files.size()))
00141     offset -= 3;
00142 
00143   place_components ();
00144 }
00145 
00146 void
00147 GUIDirectory::wheel_up (int x, int y)
00148 {
00149   move_up(); 
00150 }
00151 
00152 void
00153 GUIDirectory::wheel_down (int x, int y) 
00154 {
00155   move_down();  
00156 }
00157 
00158 /* EOF */

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