Rebuild autotool system
[construo.git] / gui_directory.cxx
blob5aa62839874abd1173505cbc0b6d4841d31e96ed
1 // $Id: gui_directory.cxx,v 1.10 2003/01/11 19:07:48 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 "construo.hxx"
21 #include "system_context.hxx"
22 #include "world_button.hxx"
23 #include "gui_directory_button.hxx"
24 #include "gui_file_manager.hxx"
25 #include "gui_new_file_button.hxx"
26 #include "gui_directory.hxx"
28 GUIDirectory::GUIDirectory (const std::string& arg_pathname, Mode m)
29 : GUIChildManager (0, 0, 800, 600),
30 pathname (arg_pathname),
31 mode (m)
33 mtime = system_context->get_mtime(pathname);
34 std::vector<std::string> dir = system_context->read_directory(pathname);
36 if (mode == SAVE_DIRECTORY && pathname != "/")
37 files.push_back(new GUINewFileButton(pathname));
39 for (std::vector<std::string>::iterator i = dir.begin(); i != dir.end(); ++i)
41 std::string filename = pathname + *i;
43 FileType type = system_context->get_file_type (filename);
45 std::cout << "Creating object for: " << filename << std::endl;
47 if (type == FT_DIRECTORY)
49 if (*(filename.end()-1) == '/') // FIXME: Hack
50 files.push_back (new GUIDirectoryButton (filename));
51 else
52 files.push_back (new GUIDirectoryButton (filename + "/"));
54 else if (type == FT_CONSTRUO_FILE)
56 if (mode == SAVE_DIRECTORY)
57 files.push_back (new WorldButton (filename, WorldButton::SAVE_BUTTON));
58 else
59 files.push_back (new WorldButton (filename, WorldButton::LOAD_BUTTON));
61 else // (type == FT_UNKNOWN_FILE)
63 // ignore unknown files
64 std::cout << "GUIFileManager: ignoring '" << filename
65 << "' since it has unknown filetype" << std::endl;
69 offset = 0;
70 place_components ();
73 GUIDirectory::~GUIDirectory ()
75 for(std::vector<GUIFileButton*>::iterator i = files.begin();
76 i != files.end(); ++i)
78 // FIXME: Very ugly, we remove all components from the manager so that he doesn't delete them twice
79 remove(*i);
80 delete *i;
84 void
85 GUIDirectory::place_components ()
87 // Remove all file components
88 for(std::vector<GUIFileButton*>::iterator i = files.begin();
89 i != files.end(); ++i)
91 remove(*i);
94 int row = 0;
95 int column = 0;
96 int count = 0;
98 //std::cout << "OFFSET: " << offset << std::endl;
100 for(std::vector<GUIFileButton*>::size_type i = 0 + offset;
101 i < files.size() && count < 9;
102 ++i)
104 files[i]->set_position(column * (200 + 50) + 50,
105 row * (150 + 37) + 30);
106 add(files[i]);
108 column += 1;
109 if (column >= 3) // row is full
111 column = 0;
112 row += 1;
114 if (row >= 3)
115 return;
117 ++count;
121 void
122 GUIDirectory::draw_overlay (GraphicContext* gc)
126 void
127 GUIDirectory::move_up ()
129 if (offset >= 3)
130 offset -= 3;
132 place_components ();
135 void
136 GUIDirectory::move_down ()
138 offset += 3;
140 if (offset >= int(files.size()))
141 offset -= 3;
143 place_components ();
146 void
147 GUIDirectory::wheel_up (int x, int y)
149 move_up();
152 void
153 GUIDirectory::wheel_down (int x, int y)
155 move_down();
158 /* EOF */