[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2620 - in trunk/src: . editor gui input
From: |
jave27 |
Subject: |
[Pingus-CVS] r2620 - in trunk/src: . editor gui input |
Date: |
Mon, 23 Jan 2006 05:48:34 +0100 |
Author: jave27
Date: 2006-01-23 05:48:15 +0100 (Mon, 23 Jan 2006)
New Revision: 2620
Added:
trunk/src/gui/input_box.cxx
trunk/src/gui/input_box.hxx
Modified:
trunk/src/SConscript
trunk/src/client.hxx
trunk/src/editor/level_objs.cxx
trunk/src/file_dialog.cxx
trunk/src/file_dialog.hxx
trunk/src/gui/Makefile.am
trunk/src/gui/component.hxx
trunk/src/gui/gui_manager.cxx
trunk/src/gui/gui_manager.hxx
trunk/src/gui/gui_screen.cxx
trunk/src/input/controller.cxx
trunk/src/input/controller.hxx
trunk/src/input/event.hxx
Log:
Added preliminary keyboard input ability. Isn't working very well
yet, but keys are being caught at least. We need this for the editor
and the file dialog box.
Modified: trunk/src/SConscript
===================================================================
--- trunk/src/SConscript 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/SConscript 2006-01-23 04:48:15 UTC (rev 2620)
@@ -131,6 +131,7 @@
'gui/display.cxx',
'gui/gui_manager.cxx',
'gui/gui_screen.cxx',
+'gui/input_box.cxx',
'gui/input_debug_screen.cxx',
'gui/root_gui_manager.cxx',
'gui/screen.cxx',
Modified: trunk/src/client.hxx
===================================================================
--- trunk/src/client.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/client.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -35,6 +35,7 @@
struct PointerEvent;
struct ScrollEvent;
struct AxisEvent;
+struct KeyboardEvent;
} // namespace Input
namespace GUI {
Modified: trunk/src/editor/level_objs.cxx
===================================================================
--- trunk/src/editor/level_objs.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/editor/level_objs.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -35,6 +35,8 @@
// Default constructor
LevelObj::LevelObj(std::string obj_name, LevelImpl* level_) :
level(level_),
+ pos(Vector(0,0,0)),
+ translated_pos(Vector(0,0,0)),
section_name(obj_name),
speed(0),
parallax(0.0),
Modified: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/file_dialog.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -24,6 +24,7 @@
#include "resource.hxx"
#include "gui/surface_button.hxx"
#include "gui/gui_manager.hxx"
+#include "gui/input_box.hxx"
#include "sound/sound.hxx"
#include "file_dialog.hxx"
#include "file_dialog_item.hxx"
@@ -254,13 +255,16 @@
gui_manager->add(up_button, true);
gui_manager->add(down_button, true);
gui_manager->add(new FileDialogCancelButton(this), true);
- gui_manager->add(new FileDialogParentFolderButton(this));
+ gui_manager->add(new FileDialogParentFolderButton(this));
// FIXME: Ugly - hardcoded values for items in file dialog.
Should be dynamic.
// Create 8 FileDialogItems and add them to the gui_manager.
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));
+ gui_manager->add((GUI::Component*)inputbox);
+
file_dialog_items.push_back(new FileDialogItem(this,
Vector(center_x - 280, center_y - 140)));
file_dialog_items.push_back(new FileDialogItem(this,
Modified: trunk/src/file_dialog.hxx
===================================================================
--- trunk/src/file_dialog.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/file_dialog.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -32,6 +32,10 @@
class FileDialogOkButton;
class FileDialogScrollButton;
class FileDialogListener;
+
+ namespace GUI {
+ class InputBox;
+ }
struct FileItem {
std::string name;
@@ -66,6 +70,9 @@
/** The owner of this file dialog */
FileDialogListener* listener;
+ /** Box to take the keyboard input */
+ GUI::InputBox* inputbox;
+
/** Should this dialog box be used for loading? True for load, false
for saving */
bool for_loading;
Modified: trunk/src/gui/Makefile.am
===================================================================
--- trunk/src/gui/Makefile.am 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/Makefile.am 2006-01-23 04:48:15 UTC (rev 2620)
@@ -46,6 +46,8 @@
combobox_listener.hxx \
checkbox.cxx \
checkbox.hxx \
- checkbox_listener.hxx
+ checkbox_listener.hxx \
+ input_box.cxx \
+ input_box.hxx
# EOF #
Modified: trunk/src/gui/component.hxx
===================================================================
--- trunk/src/gui/component.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/component.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -73,7 +73,7 @@
/** Emitted whenever a keyboard character is pressed. Only certain
components should implement this */
- void key_pressed(const char c) { UNUSED_ARG(c); }
+ virtual void on_key_pressed(const char c) { UNUSED_ARG(c); }
// status functions for use in the update() function
/** return true if currently pressed */
Modified: trunk/src/gui/gui_manager.cxx
===================================================================
--- trunk/src/gui/gui_manager.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/gui_manager.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -80,6 +80,10 @@
// AxisEvents can be ignored in the GUI, they are handled elsewhere
pout (PINGUS_DEBUG_GUI) << "GUIManager: AxisEvent: " << i->axis.dir
<< std::endl;
break;
+
+ case Input::KeyboardEventType:
+ process_keyboard_event(i->keyboard);
+ break;
default:
pwarn (PINGUS_DEBUG_GUI) << "GUIManager: unhandled event type " <<
i->type << std::endl;
@@ -268,6 +272,14 @@
UNUSED_ARG(time_stamp);
}
+void
+GUIManager::process_keyboard_event (const Input::KeyboardEvent &event)
+{
+ // Pass key value to last pressed component.
+ if (primary_pressed_component)
+ primary_pressed_component->on_key_pressed(event.key);
+}
+
} // namespace Pingus
/* EOF */
Modified: trunk/src/gui/gui_manager.hxx
===================================================================
--- trunk/src/gui/gui_manager.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/gui_manager.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -61,7 +61,7 @@
void process_input (const GameDelta& delta);
void process_pointer_event (const Input::PointerEvent& event);
void process_button_event (unsigned int time_stamp, const
Input::ButtonEvent& event);
- void key_pressed(const char c);
+ void process_keyboard_event (const Input::KeyboardEvent& event);
public:
GUIManager ();
Modified: trunk/src/gui/gui_screen.cxx
===================================================================
--- trunk/src/gui/gui_screen.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/gui_screen.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -84,6 +84,12 @@
}
break;
+
+ case Input::KeyboardEventType:
+ {
+
+ }
+ break;
default:
std::cout << "GUIScreen::update (): unhandled event type: " <<
i->type << std::endl;
Added: trunk/src/gui/input_box.cxx
===================================================================
--- trunk/src/gui/input_box.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/input_box.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -0,0 +1,59 @@
+// $Id: input_box.cxx,v 1.16 2006/1/21 21:37:06 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2006 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include "input_box.hxx"
+#include "../display/drawing_context.hxx"
+#include "../vector.hxx"
+#include "../fonts.hxx"
+
+namespace Pingus {
+namespace GUI {
+
+InputBox::InputBox(float width_, Vector p, const std::string& default_value)
+ : str(default_value),
+ pos(p),
+ width(width_),
+ height(Fonts::pingus_small.get_height())
+{
+
+}
+
+void
+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);
+
+ // If there is text, draw it:
+ if (str != std::string())
+ gc.print_left(Fonts::pingus_small, pos.x, pos.y, str);
+}
+
+bool
+InputBox::is_at(int x, int y)
+{
+ return (x > pos.x && x < pos.x + width &&
+ y > pos.y && y < pos.y + height);
+}
+
+} // GUI
+} // Pingus
+
+/* EOF */
Added: trunk/src/gui/input_box.hxx
===================================================================
--- trunk/src/gui/input_box.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/gui/input_box.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -0,0 +1,64 @@
+// $Id: input_box.hxx,v 1.16 2006/1/21 21:37:06 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2006 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_PINGUS_GUI_INPUTBOX_HXX
+#define HEADER_PINGUS_GUI_INPUTBOX_HXX
+
+#include "component.hxx"
+#include "../vector.hxx"
+#include <string>
+
+namespace Pingus {
+
+ class DrawingContext;
+
+namespace GUI {
+
+/** This class allows keyboard input to be displayed in a box */
+class InputBox : public GUI::Component {
+protected:
+ std::string str;
+ Vector pos;
+ float width;
+ float height;
+
+public:
+ InputBox(float width_, Vector p, const std::string&
+ default_value = std::string());
+
+ void set_string(const std::string& s) { str = s; }
+ std::string get_string() { return str; }
+
+ void on_key_pressed(const char c) { str += c; }
+
+ /// GUI Component functions:
+ ///
+ void update(float delta) { }
+
+ bool is_at(int x, int y);
+
+ void draw(DrawingContext &gc);
+}; // InputBox class
+
+} // GUI namespace
+} // Pingus namespace
+
+#endif
+
+/* EOF */
Modified: trunk/src/input/controller.cxx
===================================================================
--- trunk/src/input/controller.cxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/input/controller.cxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -21,6 +21,8 @@
#include "../pingus_error.hxx"
#include <ClanLib/core.h>
+#include <ClanLib/display.h>
+#include <ClanLib/signals.h>
#include "controller.hxx"
#include "axes/dummy_axis.hxx"
#include "buttons/dummy_button.hxx"
@@ -171,6 +173,10 @@
slots.push_back(it->second->sig_button_down().connect(this,
&Controller::on_button_down, it->first));
slots.push_back(it->second->sig_button_up().connect(this,
&Controller::on_button_up, it->first));
}
+
+ // Catch all keyboard input
+ CL_InputDevice keyboard =
CL_Display::get_current_window()->get_ic()->get_keyboard();
+ slots.push_back(keyboard.sig_key_down().connect(this,
&Controller::key_pressed));
}
Controller::~Controller ()
@@ -223,6 +229,12 @@
// FIXME: Busy checking of button status and other events is *VERY EVIL*
if (scroller->get_x_delta() || scroller->get_y_delta())
events.push_back(makeScrollEvent(scroller->get_x_delta(),
scroller->get_y_delta()));
+
+ std::string keys_pressed = get_keys_pressed();
+ for (unsigned i = 0; i < (unsigned)keys_pressed.length(); i++)
+ {
+ events.push_back(makeKeyboardEvent( keys_pressed[i] ));
+ }
}
void
@@ -252,6 +264,12 @@
events.push_back(makeButtonEvent(name, released));
}
+void
+Controller::key_pressed(const CL_InputEvent &event)
+{
+ keys += event.str;
+}
+
} // namespace Input
} // namespace Pingus
Modified: trunk/src/input/controller.hxx
===================================================================
--- trunk/src/input/controller.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/input/controller.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -25,8 +25,8 @@
#include <string>
#include <vector>
#include <ClanLib/signals.h>
+#include <ClanLib/display.h>
#include "../file_reader.hxx"
-
#include "event.hxx"
namespace Pingus {
@@ -57,7 +57,7 @@
~Controller ();
std::vector<Event>& get_events () { return events; }
-
+
const Pointer * get_pointer () const { return standard_pointer; }
const Scroller* get_scroller () const { return scroller; }
@@ -69,14 +69,20 @@
static void set_current(Controller* controller) { current_controller =
controller; }
static Controller* get_current() { return current_controller; }
-
+
private:
static Controller* current_controller;
void on_button_down(ButtonName name);
void on_button_up(ButtonName name);
void create_action_buttons (FileReader reader);
+ void key_pressed(const CL_InputEvent &event);
+/** Get keyboard keys pressed to handle general keyboard input */
+ std::string get_keys_pressed() { return keys; keys.clear(); }
+
+ std::string keys;
+
Controller (const Controller&);
Controller& operator= (const Controller&);
};
Modified: trunk/src/input/event.hxx
===================================================================
--- trunk/src/input/event.hxx 2006-01-23 02:35:52 UTC (rev 2619)
+++ trunk/src/input/event.hxx 2006-01-23 04:48:15 UTC (rev 2620)
@@ -21,12 +21,13 @@
#define HEADER_PINGUS_INPUT_EVENT_HXX
#include <vector>
+#include <string>
#include "../pingus.hxx"
namespace Pingus {
namespace Input {
-enum EventType { ButtonEventType, PointerEventType, AxisEventType,
ScrollEventType };
+enum EventType { ButtonEventType, PointerEventType, AxisEventType,
ScrollEventType, KeyboardEventType };
enum ButtonName { primary, secondary, pause, fast_forward, armageddon, escape,
action_1, action_2,
action_3, action_4, action_5, action_6, action_7, action_8,
action_9, action_10,
@@ -63,15 +64,21 @@
float y_delta;
};
+struct KeyboardEvent
+{
+ char key;
+};
+
struct Event
{
EventType type;
union {
- ButtonEvent button;
- PointerEvent pointer;
- AxisEvent axis;
- ScrollEvent scroll;
+ ButtonEvent button;
+ PointerEvent pointer;
+ AxisEvent axis;
+ ScrollEvent scroll;
+ KeyboardEvent keyboard;
};
};
@@ -122,6 +129,16 @@
return event;
}
+inline Event makeKeyboardEvent (char c)
+{
+ Event event;
+
+ event.type = KeyboardEventType;
+ event.keyboard.key = c;
+
+ return event;
+}
+
} // namespace Input
} // namespace Pingus
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2620 - in trunk/src: . editor gui input,
jave27 <=