split out per-window operations some more

This commit is contained in:
David Rose 2003-02-15 14:14:39 +00:00
parent 74a704440e
commit ed77186e26
6 changed files with 125 additions and 48 deletions

View File

@ -18,12 +18,14 @@
#include "config_framework.h" #include "config_framework.h"
#include <dconfig.h> #include "dconfig.h"
#include "windowFramework.h"
Configure(config_framework); Configure(config_framework);
NotifyCategoryDef(framework, ""); NotifyCategoryDef(framework, "");
ConfigureFn(config_framework) { ConfigureFn(config_framework) {
WindowFramework::init_type();
} }
const int win_width = config_framework.GetInt("win-width", 640); const int win_width = config_framework.GetInt("win-width", 640);

View File

@ -86,6 +86,20 @@ get_window(int n) const {
return _windows[n]; return _windows[n];
} }
////////////////////////////////////////////////////////////////////
// Function: PandaFramework::close_window
// Access: Public
// Description: Closes the indicated WindowFramework window and
// removes it from the list.
////////////////////////////////////////////////////////////////////
void PandaFramework::
close_window(WindowFramework *wf) {
int n = find_window(wf);
if (n >= 0) {
close_window(n);
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PandaFramework::get_wireframe // Function: PandaFramework::get_wireframe
// Access: Public // Access: Public

View File

@ -192,7 +192,7 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe) {
} }
nassertr(_is_open, NULL); nassertr(_is_open, NULL);
WindowFramework *wf = make_window_framework(); PT(WindowFramework) wf = make_window_framework();
wf->set_wireframe(get_wireframe()); wf->set_wireframe(get_wireframe());
wf->set_texture(get_texture()); wf->set_texture(get_texture());
wf->set_two_sided(get_two_sided()); wf->set_two_sided(get_two_sided());
@ -224,6 +224,25 @@ find_window(const GraphicsWindow *win) const {
return -1; return -1;
} }
////////////////////////////////////////////////////////////////////
// Function: PandaFramework::find_window
// Access: Public
// Description: Returns the index of the given WindowFramework
// object, or -1 if the object does not represent a
// window opened with this PandaFramework.
////////////////////////////////////////////////////////////////////
int PandaFramework::
find_window(const WindowFramework *wf) const {
int n;
for (n = 0; n < (int)_windows.size(); n++) {
if (_windows[n] == wf) {
return n;
}
}
return -1;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PandaFramework::close_window // Function: PandaFramework::close_window
@ -241,7 +260,6 @@ close_window(int n) {
} }
wf->close_window(); wf->close_window();
delete wf;
_windows.erase(_windows.begin() + n); _windows.erase(_windows.begin() + n);
} }
@ -263,7 +281,6 @@ close_all_windows() {
} }
wf->close_window(); wf->close_window();
delete wf;
} }
_windows.clear(); _windows.clear();
@ -551,7 +568,7 @@ main_loop() {
// provided as a hook so derived PandaFramework classes // provided as a hook so derived PandaFramework classes
// can create custom WindowFramework objects. // can create custom WindowFramework objects.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
WindowFramework *PandaFramework:: PT(WindowFramework) PandaFramework::
make_window_framework() { make_window_framework() {
return new WindowFramework(this); return new WindowFramework(this);
} }
@ -615,14 +632,11 @@ void PandaFramework::
event_esc(CPT_Event event, void *data) { event_esc(CPT_Event event, void *data) {
if (event->get_num_parameters() == 1) { if (event->get_num_parameters() == 1) {
EventParameter param = event->get_parameter(0); EventParameter param = event->get_parameter(0);
GraphicsWindow *win; WindowFramework *wf;
DCAST_INTO_V(win, param.get_ptr()); DCAST_INTO_V(wf, param.get_ptr());
PandaFramework *self = (PandaFramework *)data; PandaFramework *self = (PandaFramework *)data;
int n = self->find_window(win); self->close_window(wf);
if (n >= 0) {
self->close_window(n);
}
// If we closed the last window, shut down. // If we closed the last window, shut down.
if (self->_windows.empty()) { if (self->_windows.empty()) {
@ -650,9 +664,14 @@ event_f(CPT_Event, void *data) {
// Description: Default handler for w key: toggle wireframe. // Description: Default handler for w key: toggle wireframe.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
event_w(CPT_Event, void *data) { event_w(CPT_Event event, void *) {
PandaFramework *self = (PandaFramework *)data; if (event->get_num_parameters() == 1) {
self->set_wireframe(!self->get_wireframe()); EventParameter param = event->get_parameter(0);
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
wf->set_wireframe(!wf->get_wireframe());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -661,9 +680,14 @@ event_w(CPT_Event, void *data) {
// Description: Default handler for t key: toggle texture. // Description: Default handler for t key: toggle texture.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
event_t(CPT_Event, void *data) { event_t(CPT_Event event, void *) {
PandaFramework *self = (PandaFramework *)data; if (event->get_num_parameters() == 1) {
self->set_texture(!self->get_texture()); EventParameter param = event->get_parameter(0);
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
wf->set_texture(!wf->get_texture());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -673,9 +697,14 @@ event_t(CPT_Event, void *data) {
// rendering). // rendering).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
event_b(CPT_Event, void *data) { event_b(CPT_Event event, void *) {
PandaFramework *self = (PandaFramework *)data; if (event->get_num_parameters() == 1) {
self->set_two_sided(!self->get_two_sided()); EventParameter param = event->get_parameter(0);
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
wf->set_two_sided(!wf->get_two_sided());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -684,9 +713,14 @@ event_b(CPT_Event, void *data) {
// Description: Default handler for l key: toggle lighting. // Description: Default handler for l key: toggle lighting.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
event_l(CPT_Event, void *data) { event_l(CPT_Event event, void *) {
PandaFramework *self = (PandaFramework *)data; if (event->get_num_parameters() == 1) {
self->set_lighting(!self->get_lighting()); EventParameter param = event->get_parameter(0);
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
wf->set_lighting(!wf->get_lighting());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -699,8 +733,8 @@ void PandaFramework::
event_c(CPT_Event event, void *data) { event_c(CPT_Event event, void *data) {
if (event->get_num_parameters() == 1) { if (event->get_num_parameters() == 1) {
EventParameter param = event->get_parameter(0); EventParameter param = event->get_parameter(0);
const GraphicsWindow *win; WindowFramework *wf;
DCAST_INTO_V(win, param.get_ptr()); DCAST_INTO_V(wf, param.get_ptr());
PandaFramework *self = (PandaFramework *)data; PandaFramework *self = (PandaFramework *)data;
@ -708,11 +742,7 @@ event_c(CPT_Event event, void *data) {
if (node.is_empty()) { if (node.is_empty()) {
node = self->get_models(); node = self->get_models();
} }
wf->center_trackball(node);
int n = self->find_window(win);
if (n >= 0) {
self->_windows[n]->center_trackball(node);
}
} }
} }
@ -899,19 +929,23 @@ event_S(CPT_Event, void *data) {
// Description: Default handler for comma key: rotate background color. // Description: Default handler for comma key: rotate background color.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PandaFramework:: void PandaFramework::
event_comma(CPT_Event, void *data) { event_comma(CPT_Event event, void *) {
PandaFramework *self = (PandaFramework *)data; if (event->get_num_parameters() == 1) {
EventParameter param = event->get_parameter(0);
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
switch (self->get_background_type()) { switch (wf->get_background_type()) {
case WindowFramework::BT_other: case WindowFramework::BT_other:
break; break;
case WindowFramework::BT_none: case WindowFramework::BT_none:
self->set_background_type(WindowFramework::BT_default); wf->set_background_type(WindowFramework::BT_default);
break; break;
default: default:
self->set_background_type((WindowFramework::BackgroundType)(self->get_background_type() + 1)); wf->set_background_type((WindowFramework::BackgroundType)(wf->get_background_type() + 1));
}
} }
} }
@ -925,6 +959,9 @@ void PandaFramework::
event_window_event(CPT_Event event, void *data) { event_window_event(CPT_Event event, void *data) {
PandaFramework *self = (PandaFramework *)data; PandaFramework *self = (PandaFramework *)data;
if (event->get_num_parameters() == 1) { if (event->get_num_parameters() == 1) {
// The parameter of the window event is the window itself, rather
// than the window framework object (which is the parameter of all
// of the keyboard events).
EventParameter param = event->get_parameter(0); EventParameter param = event->get_parameter(0);
const GraphicsWindow *win; const GraphicsWindow *win;
DCAST_INTO_V(win, param.get_ptr()); DCAST_INTO_V(win, param.get_ptr());

View File

@ -56,12 +56,14 @@ public:
WindowFramework *open_window(GraphicsPipe *pipe = NULL); WindowFramework *open_window(GraphicsPipe *pipe = NULL);
WindowFramework *open_window(const WindowProperties &props, WindowFramework *open_window(const WindowProperties &props,
GraphicsPipe *pipe = NULL); GraphicsPipe *pipe = NULL);
INLINE int get_num_windows() const; INLINE int get_num_windows() const;
INLINE WindowFramework *get_window(int n) const; INLINE WindowFramework *get_window(int n) const;
int find_window(const GraphicsWindow *win) const; int find_window(const GraphicsWindow *win) const;
int find_window(const WindowFramework *wf) const;
void close_window(int n); void close_window(int n);
INLINE void close_window(WindowFramework *wf);
void close_all_windows(); void close_all_windows();
bool all_windows_closed() const; bool all_windows_closed() const;
@ -98,7 +100,7 @@ public:
INLINE void set_exit_flag(); INLINE void set_exit_flag();
protected: protected:
virtual WindowFramework *make_window_framework(); virtual PT(WindowFramework) make_window_framework();
virtual void make_default_pipe(); virtual void make_default_pipe();
virtual void do_enable_default_keys(); virtual void do_enable_default_keys();
@ -134,7 +136,7 @@ private:
NodePath _data_root; NodePath _data_root;
EventHandler _event_handler; EventHandler _event_handler;
typedef pvector<WindowFramework *> Windows; typedef pvector< PT(WindowFramework) > Windows;
Windows _windows; Windows _windows;
NodePath _models; NodePath _models;

View File

@ -41,6 +41,8 @@
// files. // files.
static const int override_priority = 100; static const int override_priority = 100;
TypeHandle WindowFramework::_type_handle;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WindowFramework::Constructor // Function: WindowFramework::Constructor
// Access: Protected // Access: Protected
@ -64,7 +66,7 @@ WindowFramework(PandaFramework *panda_framework) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WindowFramework::Destructor // Function: WindowFramework::Destructor
// Access: Protected, Virtual // Access: Public, Virtual
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
WindowFramework:: WindowFramework::
@ -198,7 +200,7 @@ enable_keyboard() {
NodePath mouse = get_mouse(); NodePath mouse = get_mouse();
PT(ButtonThrower) bt = new ButtonThrower("kb-events"); PT(ButtonThrower) bt = new ButtonThrower("kb-events");
bt->add_parameter(EventParameter(_window)); bt->add_parameter(EventParameter(this));
ModifierButtons mods; ModifierButtons mods;
mods.add_button(KeyboardButton::shift()); mods.add_button(KeyboardButton::shift());
mods.add_button(KeyboardButton::control()); mods.add_button(KeyboardButton::control());

View File

@ -28,6 +28,7 @@
#include "filename.h" #include "filename.h"
#include "pointerTo.h" #include "pointerTo.h"
#include "pvector.h" #include "pvector.h"
#include "typedReferenceCount.h"
class PandaFramework; class PandaFramework;
class AmbientLight; class AmbientLight;
@ -40,11 +41,13 @@ class GraphicsPipe;
// Description : This encapsulates the data that is normally // Description : This encapsulates the data that is normally
// associated with a single window that we've opened. // associated with a single window that we've opened.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_FRAMEWORK WindowFramework { class EXPCL_FRAMEWORK WindowFramework : public TypedReferenceCount {
protected: protected:
WindowFramework(PandaFramework *panda_framework); WindowFramework(PandaFramework *panda_framework);
public:
virtual ~WindowFramework(); virtual ~WindowFramework();
protected:
GraphicsWindow *open_window(const WindowProperties &props, GraphicsWindow *open_window(const WindowProperties &props,
GraphicsEngine *engine, GraphicsPipe *pipe); GraphicsEngine *engine, GraphicsPipe *pipe);
void close_window(); void close_window();
@ -126,6 +129,23 @@ private:
BackgroundType _background_type; BackgroundType _background_type;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "WindowFramework",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
friend class PandaFramework; friend class PandaFramework;
}; };