diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index d36ff3bc61..8b6487fe5d 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -267,6 +267,17 @@ remove_all_windows() { terminate_threads(); } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsEngine::is_empty +// Access: Published +// Description: Returns true if there are no windows managed by the +// engine, false if there is at least one. +//////////////////////////////////////////////////////////////////// +bool GraphicsEngine:: +is_empty() const { + return _windows.empty(); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsEngine::render_frame // Access: Published diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index 2e778dd595..613eeccdfc 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -64,6 +64,7 @@ PUBLISHED: const string &threading_model); bool remove_window(GraphicsWindow *window); void remove_all_windows(); + bool is_empty() const; void render_frame(); void sync_frame(); diff --git a/panda/src/egg/eggData.I b/panda/src/egg/eggData.I index 28396fc4bb..8063d8a616 100644 --- a/panda/src/egg/eggData.I +++ b/panda/src/egg/eggData.I @@ -95,13 +95,13 @@ get_coordinate_system() const { //////////////////////////////////////////////////////////////////// // Function: EggData::set_egg_filename // Access: Public -// Description: Sets the directory in which the egg file is -// considered to reside. This is also implicitly set by -// read(). +// Description: Sets the filename--especially the directory part--in +// which the egg file is considered to reside. This is +// also implicitly set by read(). //////////////////////////////////////////////////////////////////// INLINE void EggData:: -set_egg_filename(const Filename &directory) { - _egg_filename = directory; +set_egg_filename(const Filename &egg_filename) { + _egg_filename = egg_filename; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggData.h b/panda/src/egg/eggData.h index af72b873a9..20bdd289e4 100644 --- a/panda/src/egg/eggData.h +++ b/panda/src/egg/eggData.h @@ -69,7 +69,7 @@ public: void set_coordinate_system(CoordinateSystem coordsys); INLINE CoordinateSystem get_coordinate_system() const; - INLINE void set_egg_filename(const Filename &directory); + INLINE void set_egg_filename(const Filename &egg_filenamea); INLINE const Filename &get_egg_filename() const; INLINE void recompute_vertex_normals(double threshold); diff --git a/panda/src/event/eventParameter.I b/panda/src/event/eventParameter.I index 176301cb3b..26da0d4756 100644 --- a/panda/src/event/eventParameter.I +++ b/panda/src/event/eventParameter.I @@ -37,9 +37,15 @@ EventParameter() { // Description: Defines an EventParameter that stores a pointer to // any kind of TypedReferenceCount object. This is the // most general constructor. +// +// This accepts a const pointer, even though it stores +// (and eventually returns) a non-const pointer. This +// is just the simplest way to allow both const and +// non-const pointers to be stored, but it does lose the +// constness. Be careful. //////////////////////////////////////////////////////////////////// INLINE EventParameter:: -EventParameter(const TypedReferenceCount *ptr) : _ptr(ptr) { } +EventParameter(const TypedReferenceCount *ptr) : _ptr((TypedReferenceCount *)ptr) { } //////////////////////////////////////////////////////////////////// @@ -195,7 +201,7 @@ get_string_value() const { // contains. This is the only way to retrieve the value // when it is not one of the above predefined types. //////////////////////////////////////////////////////////////////// -INLINE const TypedReferenceCount *EventParameter:: +INLINE TypedReferenceCount *EventParameter:: get_ptr() const { return _ptr; } diff --git a/panda/src/event/eventParameter.h b/panda/src/event/eventParameter.h index 9d0fce7f29..90a408431c 100644 --- a/panda/src/event/eventParameter.h +++ b/panda/src/event/eventParameter.h @@ -60,12 +60,12 @@ PUBLISHED: INLINE bool is_string() const; INLINE string get_string_value() const; - INLINE const TypedReferenceCount *get_ptr() const; + INLINE TypedReferenceCount *get_ptr() const; void output(ostream &out) const; private: - CPT(TypedReferenceCount) _ptr; + PT(TypedReferenceCount) _ptr; }; INLINE ostream &operator << (ostream &out, const EventParameter ¶m); diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index dd73542997..1ffdecd7ce 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -205,6 +205,26 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe) { return wf; } +//////////////////////////////////////////////////////////////////// +// Function: PandaFramework::find_window +// Access: Public +// Description: Returns the index of the WindowFramework object that +// references the indicated GraphicsWindow pointer, or +// -1 if none do. +//////////////////////////////////////////////////////////////////// +int PandaFramework:: +find_window(const GraphicsWindow *win) const { + int n; + for (n = 0; n < (int)_windows.size(); n++) { + if (_windows[n]->get_graphics_window() == win) { + return n; + } + } + + return -1; +} + + //////////////////////////////////////////////////////////////////// // Function: PandaFramework::close_window // Access: Public @@ -587,13 +607,28 @@ do_enable_default_keys() { //////////////////////////////////////////////////////////////////// // Function: PandaFramework::event_esc // Access: Protected, Static -// Description: Default handler for ESC or q key: exit the -// application. +// Description: Default handler for ESC or q key: close the current +// window (and exit the application if that was the last +// window). //////////////////////////////////////////////////////////////////// void PandaFramework:: -event_esc(CPT_Event, void *data) { - PandaFramework *self = (PandaFramework *)data; - self->_exit_flag = true; +event_esc(CPT_Event event, void *data) { + if (event->get_num_parameters() == 1) { + EventParameter param = event->get_parameter(0); + GraphicsWindow *win; + DCAST_INTO_V(win, param.get_ptr()); + + PandaFramework *self = (PandaFramework *)data; + int n = self->find_window(win); + if (n >= 0) { + self->close_window(n); + } + + // If we closed the last window, shut down. + if (self->_windows.empty()) { + self->_exit_flag = true; + } + } } //////////////////////////////////////////////////////////////////// @@ -661,18 +696,23 @@ event_l(CPT_Event, void *data) { // the scene, or over the highlighted part of the scene. //////////////////////////////////////////////////////////////////// void PandaFramework:: -event_c(CPT_Event, void *data) { - PandaFramework *self = (PandaFramework *)data; +event_c(CPT_Event event, void *data) { + if (event->get_num_parameters() == 1) { + EventParameter param = event->get_parameter(0); + const GraphicsWindow *win; + DCAST_INTO_V(win, param.get_ptr()); - NodePath node = self->get_highlight(); - if (node.is_empty()) { - node = self->get_models(); - } + PandaFramework *self = (PandaFramework *)data; - Windows::iterator wi; - for (wi = self->_windows.begin(); wi != self->_windows.end(); ++wi) { - WindowFramework *wf = (*wi); - wf->center_trackball(node); + NodePath node = self->get_highlight(); + if (node.is_empty()) { + node = self->get_models(); + } + + int n = self->find_window(win); + if (n >= 0) { + self->_windows[n]->center_trackball(node); + } } } diff --git a/panda/src/framework/pandaFramework.h b/panda/src/framework/pandaFramework.h index 3815faa37b..515dad5821 100644 --- a/panda/src/framework/pandaFramework.h +++ b/panda/src/framework/pandaFramework.h @@ -60,6 +60,7 @@ public: INLINE int get_num_windows() const; INLINE WindowFramework *get_window(int n) const; + int find_window(const GraphicsWindow *win) const; void close_window(int n); void close_all_windows(); bool all_windows_closed() const; diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index 47450ec8a8..705989dafb 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -198,6 +198,7 @@ enable_keyboard() { NodePath mouse = get_mouse(); PT(ButtonThrower) bt = new ButtonThrower("kb-events"); + bt->add_parameter(EventParameter(_window)); ModifierButtons mods; mods.add_button(KeyboardButton::shift()); mods.add_button(KeyboardButton::control()); diff --git a/panda/src/tform/buttonThrower.cxx b/panda/src/tform/buttonThrower.cxx index 8b27f0071a..35a502470e 100644 --- a/panda/src/tform/buttonThrower.cxx +++ b/panda/src/tform/buttonThrower.cxx @@ -22,6 +22,7 @@ #include "buttonEventList.h" #include "dataNodeTransmit.h" #include "throw_event.h" +#include "event.h" #include "indent.h" #include "dcast.h" @@ -89,6 +90,44 @@ get_prefix() const { return _prefix; } +//////////////////////////////////////////////////////////////////// +// Function: ButtonThrower::add_parameter +// Access: Public +// Description: Adds the indicated parameter to the list of +// parameters that will be passed with each event +// generated by this ButtonThrower. +//////////////////////////////////////////////////////////////////// +void ButtonThrower:: +add_parameter(const EventParameter &obj) { + _parameters.push_back(obj); +} + + +//////////////////////////////////////////////////////////////////// +// Function: ButtonThrower::get_num_parameters +// Access: Public +// Description: Returns the number of parameters that have been added +// to the list of parameters to be passed with each +// event generated by this ButtonThrower. +//////////////////////////////////////////////////////////////////// +int ButtonThrower:: +get_num_parameters() const { + return _parameters.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ButtonThrower::get_parameter +// Access: Public +// Description: Returns the nth parameter that has been added to the +// list of parameters passed with each event generated +// by this ButtonThrower. +//////////////////////////////////////////////////////////////////// +EventParameter ButtonThrower:: +get_parameter(int n) const { + nassertr(n >= 0 && n < (int)_parameters.size(), EventParameter(0)); + return _parameters[n]; +} + //////////////////////////////////////////////////////////////////// // Function: ButtonThrower::get_modifier_buttons // Access: Published @@ -324,6 +363,24 @@ write(ostream &out, int indent_level) const { } } +//////////////////////////////////////////////////////////////////// +// Function: ButtonThrower::do_throw_event +// Access: Private +// Description: Generates an event of the indicated name, adding on +// all of the user-requested parameters. +//////////////////////////////////////////////////////////////////// +void ButtonThrower:: +do_throw_event(const string &event_name) { + Event *event = new Event(_prefix + event_name); + + ParameterList::const_iterator pi; + for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) { + event->add_parameter(*pi); + } + + throw_event(event); +} + //////////////////////////////////////////////////////////////////// // Function: ButtonThrower::do_transmit_data // Access: Protected, Virtual @@ -362,7 +419,7 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { if (!_throw_buttons_active || has_throw_button(_mods, be._button)) { // Process this button. - throw_event(_prefix + event_name); + do_throw_event(event_name); } else { // Don't process this button; instead, pass it down to future @@ -385,7 +442,7 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { // definition for the button at all, regardless of the state // of the modifier keys. if (!_throw_buttons_active || has_throw_button(be._button)) { - throw_event(_prefix + event_name + "-up"); + do_throw_event(event_name + "-up"); } if (_throw_buttons_active) { // Now pass the event on to future generations. We always diff --git a/panda/src/tform/buttonThrower.h b/panda/src/tform/buttonThrower.h index fc9bb18d80..e6b504dd82 100644 --- a/panda/src/tform/buttonThrower.h +++ b/panda/src/tform/buttonThrower.h @@ -26,6 +26,7 @@ #include "buttonEventList.h" #include "pvector.h" #include "pmap.h" +#include "eventParameter.h" //////////////////////////////////////////////////////////////////// // Class : ButtonThrower @@ -48,6 +49,10 @@ PUBLISHED: bool has_prefix() const; string get_prefix() const; + void add_parameter(const EventParameter &obj); + int get_num_parameters() const; + EventParameter get_parameter(int n) const; + const ModifierButtons &get_modifier_buttons() const; void set_modifier_buttons(const ModifierButtons &mods); @@ -63,10 +68,16 @@ PUBLISHED: public: virtual void write(ostream &out, int indent_level = 0) const; +private: + void do_throw_event(const string &event_name); + private: string _prefix; ModifierButtons _mods; + typedef pvector ParameterList; + ParameterList _parameters; + typedef pvector ThrowButtonDef; typedef pmap ThrowButtons; ThrowButtons _throw_buttons;