[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2623 - in trunk/src: . gui
From: |
jave27 |
Subject: |
[Pingus-CVS] r2623 - in trunk/src: . gui |
Date: |
Tue, 24 Jan 2006 00:55:37 +0100 |
Author: jave27
Date: 2006-01-24 00:55:24 +0100 (Tue, 24 Jan 2006)
New Revision: 2623
Modified:
trunk/src/file_dialog.cxx
trunk/src/gui/component.hxx
trunk/src/gui/gui_manager.cxx
trunk/src/gui/gui_manager.hxx
trunk/src/gui/input_box.cxx
trunk/src/gui/input_box.hxx
Log:
Making the file dialog box better by hacking up the input box.
Modified: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/file_dialog.cxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -94,7 +94,7 @@
public:
FileDialogCancelButton (FileDialog* f)
- : GUI::SurfaceButton(CL_Display::get_width()/2 - 250,
+ : GUI::SurfaceButton(CL_Display::get_width()/2 - 280,
CL_Display::get_height()/2 + 160,
ResDescriptor("core/menu/exit_button_normal"),
ResDescriptor("core/menu/exit_button_pressed"),
@@ -262,7 +262,7 @@
float center_x = (float)CL_Display::get_width()/2;
float center_y = (float)CL_Display::get_height()/2;
- inputbox = new GUI::InputBox(300, Vector(center_x - 150,
center_y + 200));
+ inputbox = new GUI::InputBox(450, Vector(center_x - 225,
center_y - 170));
gui_manager->add((GUI::Component*)inputbox);
file_dialog_items.push_back(new FileDialogItem(this,
@@ -400,7 +400,13 @@
{
current_file = f;
if (current_file.name != "")
- ok_button->show();
+ {
+ ok_button->show();
+ if (!current_file.is_directory)
+ inputbox->set_string(current_file.name);
+ else
+ inputbox->set_string("");
+ }
else
ok_button->hide();
Modified: trunk/src/gui/component.hxx
===================================================================
--- trunk/src/gui/component.hxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/gui/component.hxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -33,11 +33,16 @@
class Component
{
private:
+
+protected:
+ bool has_focus;
public:
- Component () { }
+ Component () : has_focus(false) { }
virtual ~Component() {}
+ virtual void set_focus(bool val) { has_focus = val; }
+
virtual void draw (DrawingContext& gc) =0;
virtual void update (float delta) { UNUSED_ARG(delta);}
Modified: trunk/src/gui/gui_manager.cxx
===================================================================
--- trunk/src/gui/gui_manager.cxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/gui/gui_manager.cxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -188,7 +188,7 @@
if (event.name == primary && event.state == Input::pressed)
{
primary_pressed_component = comp;
- focussed_component = comp;
+ change_focussed_comp(comp);
comp->on_primary_button_press (x_pos, y_pos);
// FIXME: add double click detection here
@@ -228,7 +228,7 @@
if (event.name == secondary && event.state == Input::pressed)
{
secondary_pressed_component = comp;
- focussed_component = comp;
+ change_focussed_comp(comp);
comp->on_secondary_button_press (x_pos, y_pos);
}
else if (event.name == secondary && event.state == Input::released)
@@ -283,6 +283,16 @@
focussed_component->on_key_pressed(event.key);
}
+void
+GUIManager::change_focussed_comp(Component* c)
+{
+ if (focussed_component)
+ focussed_component->set_focus(false);
+ focussed_component = c;
+ if (focussed_component)
+ focussed_component->set_focus(true);
+}
+
} // namespace Pingus
/* EOF */
Modified: trunk/src/gui/gui_manager.hxx
===================================================================
--- trunk/src/gui/gui_manager.hxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/gui/gui_manager.hxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -66,6 +66,9 @@
void process_button_event (unsigned int time_stamp, const
Input::ButtonEvent& event);
void process_keyboard_event (const Input::KeyboardEvent& event);
+ /** Change which component has the focus and notify the component */
+ void change_focussed_comp(Component* c);
+
public:
GUIManager ();
virtual ~GUIManager () {}
Modified: trunk/src/gui/input_box.cxx
===================================================================
--- trunk/src/gui/input_box.cxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/gui/input_box.cxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -17,6 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <algorithm>
#include "input_box.hxx"
#include "../display/drawing_context.hxx"
#include "../vector.hxx"
@@ -38,12 +39,18 @@
InputBox::draw(DrawingContext &gc)
{
// Draw the rectangle and border
- gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + height,
CL_Color::azure);
- gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + height,
CL_Color::black);
+ gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + height,
+ CL_Color::black);
+ gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + height,
CL_Color::white);
// If there is text, draw it:
if (str != std::string())
- gc.print_left(Fonts::pingus_small, pos.x, pos.y, str);
+ gc.print_left(Fonts::pingus_small, pos.x + 10, pos.y,
shrink_string(str));
+
+ if (has_focus)
+ gc.draw_line(pos.x +
Fonts::pingus_small.get_size(shrink_string(str)).width + 12,
+ pos.y, pos.x +
Fonts::pingus_small.get_size(shrink_string(str)).width + 12,
+ pos.y + height, CL_Color::yellow);
}
bool
@@ -53,6 +60,21 @@
y > pos.y && y < pos.y + height);
}
+std::string
+InputBox::shrink_string(const std::string& s) const
+{
+ std::string ret_string;
+ int w = (int)width / Fonts::pingus_small.get_width('W');
+
+ if (s.length() > w - 1)
+ ret_string = s.substr(std::max(0, (int)s.length()-w), w - 1);
+ else
+ ret_string = s;
+
+ return ret_string;
+}
+
+
} // GUI
} // Pingus
Modified: trunk/src/gui/input_box.hxx
===================================================================
--- trunk/src/gui/input_box.hxx 2006-01-23 18:22:04 UTC (rev 2622)
+++ trunk/src/gui/input_box.hxx 2006-01-23 23:55:24 UTC (rev 2623)
@@ -38,6 +38,9 @@
float width;
float height;
+ /** Shrink the string to fit in the box */
+ std::string shrink_string(const std::string& s) const;
+
public:
InputBox(float width_, Vector p, const std::string&
default_value = std::string());
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2623 - in trunk/src: . gui,
jave27 <=