[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3111 - trunk/pingus/src/editor
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3111 - trunk/pingus/src/editor |
Date: |
Sat, 8 Sep 2007 17:52:02 +0200 |
Author: grumbel
Date: 2007-09-08 17:52:02 +0200 (Sat, 08 Sep 2007)
New Revision: 3111
Modified:
trunk/pingus/src/editor/button.cpp
trunk/pingus/src/editor/button.hpp
trunk/pingus/src/editor/editor_screen.hpp
trunk/pingus/src/editor/file_list.cpp
trunk/pingus/src/editor/file_list.hpp
trunk/pingus/src/editor/file_load_dialog.cpp
trunk/pingus/src/editor/file_load_dialog.hpp
Log:
- added filedialog scrolling
- fileloaddialog now works
Modified: trunk/pingus/src/editor/button.cpp
===================================================================
--- trunk/pingus/src/editor/button.cpp 2007-09-08 14:51:50 UTC (rev 3110)
+++ trunk/pingus/src/editor/button.cpp 2007-09-08 15:52:02 UTC (rev 3111)
@@ -33,23 +33,27 @@
: RectComponent(rect),
text(text_),
mouse_over(false),
- mouse_down(false)
+ mouse_down(false),
+ enabled(true)
{
}
void
Button::draw (DrawingContext& gc)
{
- if (mouse_down && mouse_over)
- GUIStyle::draw_lowered_box(gc, rect, Color(237, 233, 227), 2);
- else if (mouse_over)
- GUIStyle::draw_raised_box(gc, rect, Color(255, 255, 255), 2);
- else
- GUIStyle::draw_raised_box(gc, rect, Color(237, 233, 227), 2);
-
- gc.print_center(Fonts::courier_small,
- rect.left + rect.get_width()/2, rect.top +
rect.get_height()/2 - 6,
- text);
+ if (enabled)
+ {
+ if (mouse_down && mouse_over)
+ GUIStyle::draw_lowered_box(gc, rect, Color(237, 233, 227), 2);
+ else if (mouse_over)
+ GUIStyle::draw_raised_box(gc, rect, Color(255, 255, 255), 2);
+ else
+ GUIStyle::draw_raised_box(gc, rect, Color(237, 233, 227), 2);
+ }
+
+ gc.print_center(Fonts::courier_small,
+ rect.left + rect.get_width()/2, rect.top +
rect.get_height()/2 - 6,
+ text);
}
void
Modified: trunk/pingus/src/editor/button.hpp
===================================================================
--- trunk/pingus/src/editor/button.hpp 2007-09-08 14:51:50 UTC (rev 3110)
+++ trunk/pingus/src/editor/button.hpp 2007-09-08 15:52:02 UTC (rev 3111)
@@ -38,6 +38,7 @@
std::string text;
bool mouse_over;
bool mouse_down;
+ bool enabled;
public:
Button(const Rect& rect, const std::string& text);
@@ -51,6 +52,9 @@
void on_primary_button_press(int x, int y);
void on_primary_button_release(int x, int y);
+ void enable() { enabled = true; }
+ void disable() { enabled = false; }
+
boost::signal<void()> on_click;
private:
Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp 2007-09-08 14:51:50 UTC (rev
3110)
+++ trunk/pingus/src/editor/editor_screen.hpp 2007-09-08 15:52:02 UTC (rev
3111)
@@ -96,8 +96,6 @@
/** Load a new level */
void load(const Pathname& file);
-
- void load_level(const std::string& file);
// Functions accessible from the GUI
void level_new();
Modified: trunk/pingus/src/editor/file_list.cpp
===================================================================
--- trunk/pingus/src/editor/file_list.cpp 2007-09-08 14:51:50 UTC (rev
3110)
+++ trunk/pingus/src/editor/file_list.cpp 2007-09-08 15:52:02 UTC (rev
3111)
@@ -27,7 +27,9 @@
FileList::FileList(const Rect& rect)
: RectComponent(rect),
current_item(-1),
- click_item(-1)
+ click_item(-1),
+ page(0),
+ num_pages(0)
{
update_layout();
}
@@ -37,6 +39,13 @@
{
hspace = rect.get_width()/2;
vspace = 20;
+
+ num_pages = directory.size() / items_per_page();
+ if (num_pages % items_per_page() > 0)
+ num_pages += 1;
+
+ if (page >= num_pages)
+ page = num_pages-1;
}
struct DirectorySorter
@@ -63,6 +72,12 @@
{
directory = System::opendir(pathname, pattern);
std::sort(directory.begin(), directory.end(), DirectorySorter());
+
+ num_pages = directory.size() / items_per_page();
+ if (directory.size() % items_per_page() != 0)
+ num_pages += 1;
+
+ page = 0;
}
void
@@ -71,9 +86,14 @@
gc.draw_fillrect(rect.left, rect.top, rect.right, rect.bottom,
Color(0, 0, 0));
+ int end = (page+1) * items_per_page();
+ if (end > int(directory.size()))
+ end = directory.size();
+
int x = rect.left;
int y = rect.top;
- for(System::Directory::iterator i = directory.begin(); i != directory.end();
++i)
+ for(System::Directory::iterator i = directory.begin() + page *
items_per_page();
+ i != directory.begin() + end; ++i)
{
if (i->type == System::DE_DIRECTORY)
gc.draw(directory_icon, x, y);
@@ -128,15 +148,51 @@
current_item = Math::clamp(0, y / vspace, rect.get_height() / vspace - 1)
+ Math::clamp(0, x / hspace, rect.get_width() / hspace - 1) *
(rect.get_height()/vspace);
+
+ current_item += page * items_per_page();
if (current_item < 0 || current_item >= int(directory.size()))
current_item = -1;
}
void
+FileList::next_page()
+{
+ page += 1;
+ if (page >= num_pages)
+ page = num_pages - 1;
+}
+
+void
+FileList::prev_page()
+{
+ page -= 1;
+ if (page < 0)
+ page = 0;
+}
+
+void
FileList::update (float delta)
{
}
+
+int
+FileList::items_per_page()
+{
+ return (rect.get_height()/vspace * 2);
+}
+
+bool
+FileList::has_more_next_pages()
+{
+ return (page < num_pages-1);
+}
+
+bool
+FileList::has_more_prev_pages()
+{
+ return (page > 0);
+}
} // namespace Editor
Modified: trunk/pingus/src/editor/file_list.hpp
===================================================================
--- trunk/pingus/src/editor/file_list.hpp 2007-09-08 14:51:50 UTC (rev
3110)
+++ trunk/pingus/src/editor/file_list.hpp 2007-09-08 15:52:02 UTC (rev
3111)
@@ -39,7 +39,9 @@
System::Directory directory;
int current_item;
int click_item;
-
+ int page;
+ int num_pages;
+
public:
FileList(const Rect& rect);
@@ -54,9 +56,17 @@
void on_primary_button_press (int x, int y);
void on_primary_button_release (int x, int y);
+ void next_page();
+ void prev_page();
+
+ bool has_more_next_pages();
+ bool has_more_prev_pages();
+
boost::signal<void (const System::DirectoryEntry&)> on_click;
private:
+ int items_per_page();
+
FileList (const FileList&);
FileList& operator= (const FileList&);
};
Modified: trunk/pingus/src/editor/file_load_dialog.cpp
===================================================================
--- trunk/pingus/src/editor/file_load_dialog.cpp 2007-09-08 14:51:50 UTC
(rev 3110)
+++ trunk/pingus/src/editor/file_load_dialog.cpp 2007-09-08 15:52:02 UTC
(rev 3111)
@@ -30,6 +30,7 @@
#include "editor_screen.hpp"
#include "gui_style.hpp"
#include "fonts.hpp"
+#include "pathname.hpp"
#include "button.hpp"
#include "file_load_dialog.hpp"
@@ -106,9 +107,7 @@
if (entry.type == System::DE_DIRECTORY)
{
//std::cout << "Directory: " << entry.name << std::endl;
- pathname = System::realpath(pathname + "/" + entry.name);
- file_list.set_directory(pathname);
- filename = "";
+ set_directory(pathname + "/" + entry.name);
}
else
{
@@ -120,8 +119,10 @@
void
FileLoadDialog::set_directory(const std::string& pathname_)
{
+ filename = "";
pathname = System::realpath(pathname_);
file_list.set_directory(pathname);
+ update_button_state();
}
void
@@ -134,20 +135,27 @@
void
FileLoadDialog::on_open()
{
- std::cout << "Open" << std::endl;
- hide();
+ if (!filename.empty())
+ {
+ Pathname file(pathname + "/" + filename, Pathname::SYSTEM_PATH);
+ std::cout << "Open: " << file << std::endl;
+ editor->load(file);
+ hide();
+ }
}
void
FileLoadDialog::on_up()
{
- std::cout << "Up" << std::endl;
+ file_list.prev_page();
+ update_button_state();
}
void
FileLoadDialog::on_down()
{
- std::cout << "Down" << std::endl;
+ file_list.next_page();
+ update_button_state();
}
void
@@ -178,6 +186,20 @@
{
}
+
+void
+FileLoadDialog::update_button_state()
+{
+ if (file_list.has_more_prev_pages())
+ up_button->enable();
+ else
+ up_button->disable();
+
+ if (file_list.has_more_next_pages())
+ down_button->enable();
+ else
+ down_button->disable();
+}
} // namespace Editor
Modified: trunk/pingus/src/editor/file_load_dialog.hpp
===================================================================
--- trunk/pingus/src/editor/file_load_dialog.hpp 2007-09-08 14:51:50 UTC
(rev 3110)
+++ trunk/pingus/src/editor/file_load_dialog.hpp 2007-09-08 15:52:02 UTC
(rev 3111)
@@ -67,7 +67,10 @@
void on_down();
void on_home();
+
private:
+ void update_button_state();
+
FileLoadDialog (const FileLoadDialog&);
FileLoadDialog& operator= (const FileLoadDialog&);
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3111 - trunk/pingus/src/editor,
grumbel at BerliOS <=