00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
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) == '/') 
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 
00062         {
00063           
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       
00079       remove(*i);
00080       delete *i;
00081     }
00082 }
00083 
00084 void
00085 GUIDirectory::place_components ()
00086 {
00087   
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   
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) 
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