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 <dconfig.h>
#include "dconfig.h"
#include "windowFramework.h"
Configure(config_framework);
NotifyCategoryDef(framework, "");
ConfigureFn(config_framework) {
WindowFramework::init_type();
}
const int win_width = config_framework.GetInt("win-width", 640);

View File

@ -86,6 +86,20 @@ get_window(int n) const {
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
// Access: Public

View File

@ -192,7 +192,7 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe) {
}
nassertr(_is_open, NULL);
WindowFramework *wf = make_window_framework();
PT(WindowFramework) wf = make_window_framework();
wf->set_wireframe(get_wireframe());
wf->set_texture(get_texture());
wf->set_two_sided(get_two_sided());
@ -224,6 +224,25 @@ find_window(const GraphicsWindow *win) const {
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
@ -241,7 +260,6 @@ close_window(int n) {
}
wf->close_window();
delete wf;
_windows.erase(_windows.begin() + n);
}
@ -263,7 +281,6 @@ close_all_windows() {
}
wf->close_window();
delete wf;
}
_windows.clear();
@ -551,7 +568,7 @@ main_loop() {
// provided as a hook so derived PandaFramework classes
// can create custom WindowFramework objects.
////////////////////////////////////////////////////////////////////
WindowFramework *PandaFramework::
PT(WindowFramework) PandaFramework::
make_window_framework() {
return new WindowFramework(this);
}
@ -615,14 +632,11 @@ void PandaFramework::
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());
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
PandaFramework *self = (PandaFramework *)data;
int n = self->find_window(win);
if (n >= 0) {
self->close_window(n);
}
self->close_window(wf);
// If we closed the last window, shut down.
if (self->_windows.empty()) {
@ -650,9 +664,14 @@ event_f(CPT_Event, void *data) {
// Description: Default handler for w key: toggle wireframe.
////////////////////////////////////////////////////////////////////
void PandaFramework::
event_w(CPT_Event, void *data) {
PandaFramework *self = (PandaFramework *)data;
self->set_wireframe(!self->get_wireframe());
event_w(CPT_Event event, void *) {
if (event->get_num_parameters() == 1) {
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.
////////////////////////////////////////////////////////////////////
void PandaFramework::
event_t(CPT_Event, void *data) {
PandaFramework *self = (PandaFramework *)data;
self->set_texture(!self->get_texture());
event_t(CPT_Event event, void *) {
if (event->get_num_parameters() == 1) {
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).
////////////////////////////////////////////////////////////////////
void PandaFramework::
event_b(CPT_Event, void *data) {
PandaFramework *self = (PandaFramework *)data;
self->set_two_sided(!self->get_two_sided());
event_b(CPT_Event event, void *) {
if (event->get_num_parameters() == 1) {
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.
////////////////////////////////////////////////////////////////////
void PandaFramework::
event_l(CPT_Event, void *data) {
PandaFramework *self = (PandaFramework *)data;
self->set_lighting(!self->get_lighting());
event_l(CPT_Event event, void *) {
if (event->get_num_parameters() == 1) {
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) {
if (event->get_num_parameters() == 1) {
EventParameter param = event->get_parameter(0);
const GraphicsWindow *win;
DCAST_INTO_V(win, param.get_ptr());
WindowFramework *wf;
DCAST_INTO_V(wf, param.get_ptr());
PandaFramework *self = (PandaFramework *)data;
@ -708,11 +742,7 @@ event_c(CPT_Event event, void *data) {
if (node.is_empty()) {
node = self->get_models();
}
int n = self->find_window(win);
if (n >= 0) {
self->_windows[n]->center_trackball(node);
}
wf->center_trackball(node);
}
}
@ -899,19 +929,23 @@ event_S(CPT_Event, void *data) {
// Description: Default handler for comma key: rotate background color.
////////////////////////////////////////////////////////////////////
void PandaFramework::
event_comma(CPT_Event, void *data) {
PandaFramework *self = (PandaFramework *)data;
event_comma(CPT_Event event, void *) {
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()) {
case WindowFramework::BT_other:
break;
case WindowFramework::BT_none:
self->set_background_type(WindowFramework::BT_default);
break;
default:
self->set_background_type((WindowFramework::BackgroundType)(self->get_background_type() + 1));
switch (wf->get_background_type()) {
case WindowFramework::BT_other:
break;
case WindowFramework::BT_none:
wf->set_background_type(WindowFramework::BT_default);
break;
default:
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) {
PandaFramework *self = (PandaFramework *)data;
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);
const GraphicsWindow *win;
DCAST_INTO_V(win, param.get_ptr());

View File

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

View File

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

View File

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