mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
PandaFramework should respect per-window keypresses
This commit is contained in:
parent
1749f817c2
commit
74a704440e
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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<EventParameter> ParameterList;
|
||||
ParameterList _parameters;
|
||||
|
||||
typedef pvector<ModifierButtons> ThrowButtonDef;
|
||||
typedef pmap<ButtonHandle, ThrowButtonDef> ThrowButtons;
|
||||
ThrowButtons _throw_buttons;
|
||||
|
Loading…
x
Reference in New Issue
Block a user