1 // $Id: gui_directory.cxx,v 1.10 2003/01/11 19:07:48 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
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
),
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
));
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
));
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
;
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
85 GUIDirectory::place_components ()
87 // Remove all file components
88 for(std::vector
<GUIFileButton
*>::iterator i
= files
.begin();
89 i
!= files
.end(); ++i
)
98 //std::cout << "OFFSET: " << offset << std::endl;
100 for(std::vector
<GUIFileButton
*>::size_type i
= 0 + offset
;
101 i
< files
.size() && count
< 9;
104 files
[i
]->set_position(column
* (200 + 50) + 50,
105 row
* (150 + 37) + 30);
109 if (column
>= 3) // row is full
122 GUIDirectory::draw_overlay (GraphicContext
* gc
)
127 GUIDirectory::move_up ()
136 GUIDirectory::move_down ()
140 if (offset
>= int(files
.size()))
147 GUIDirectory::wheel_up (int x
, int y
)
153 GUIDirectory::wheel_down (int x
, int y
)