mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-17 12:12:10 -04:00
one step closer
This commit is contained in:
parent
7ba27990ef
commit
e4ef1283aa
@ -18,7 +18,8 @@
|
||||
guiFrame.h guiFrame.I guiFrame.cxx \
|
||||
guiSign.h guiSign.I guiSign.cxx \
|
||||
guiListBox.h guiListBox.I guiListBox.cxx \
|
||||
guiBackground.h guiBackground.I guiBackground.cxx
|
||||
guiBackground.h guiBackground.I guiBackground.cxx \
|
||||
guiBehavior.h guiBehavior.I guiBehavior.cxx
|
||||
|
||||
#define INSTALL_HEADERS \
|
||||
guiManager.h guiManager.I \
|
||||
@ -30,7 +31,8 @@
|
||||
guiFrame.h guiFrame.I \
|
||||
guiSign.h guiSign.I \
|
||||
guiListBox.h guiListBox.I \
|
||||
guiBackground.h guiBackground.I
|
||||
guiBackground.h guiBackground.I \
|
||||
guiBehavior.h guiBehavior.I
|
||||
|
||||
#define IGATESCAN \
|
||||
guiManager.h guiManager.I \
|
||||
@ -42,6 +44,7 @@
|
||||
guiFrame.h guiFrame.I \
|
||||
guiSign.h guiSign.I \
|
||||
guiListBox.h guiListBox.I \
|
||||
guiBackground.h guiBackground.I
|
||||
guiBackground.h guiBackground.I \
|
||||
guiBehavior.h guiBehavior.I
|
||||
|
||||
#end lib_target
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "guiButton.h"
|
||||
#include "guiFrame.h"
|
||||
#include "guiListBox.h"
|
||||
#include "guiBehavior.h"
|
||||
#include "guiBackground.h"
|
||||
|
||||
#include <dconfig.h>
|
||||
|
||||
@ -22,11 +24,13 @@ ConfigureFn(config_gui) {
|
||||
GuiLabel::init_type();
|
||||
GuiRegion::init_type();
|
||||
GuiItem::init_type();
|
||||
GuiBehavior::init_type();
|
||||
GuiSign::init_type();
|
||||
GuiRollover::init_type();
|
||||
GuiButton::init_type();
|
||||
GuiFrame::init_type();
|
||||
GuiListBox::init_type();
|
||||
GuiBackground::init_type();
|
||||
}
|
||||
|
||||
float simple_text_margin_top =
|
||||
|
@ -7,6 +7,15 @@
|
||||
|
||||
TypeHandle GuiBehavior::_type_handle;
|
||||
|
||||
GuiBehavior::BehaviorFunctor::BehaviorFunctor(void) {
|
||||
}
|
||||
|
||||
GuiBehavior::BehaviorFunctor::~BehaviorFunctor(void) {
|
||||
}
|
||||
|
||||
void GuiBehavior::BehaviorFunctor::doit(GuiBehavior*) {
|
||||
}
|
||||
|
||||
GuiBehavior::GuiBehavior(const string& name) : GuiItem(name),
|
||||
_eh((EventHandler*)0L) {
|
||||
}
|
||||
@ -22,7 +31,7 @@ void GuiBehavior::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
void GuiBehavior::unmanage(void) {
|
||||
if (_behavior_running)
|
||||
this->stop_behavior();
|
||||
_eh = (EventHandler)0L;
|
||||
_eh = (EventHandler*)0L;
|
||||
GuiItem::unmanage();
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,19 @@
|
||||
|
||||
#include "guiItem.h"
|
||||
|
||||
claas EXPCL_PANDA GuiBehavior : public GuiItem {
|
||||
class EXPCL_PANDA GuiBehavior : public GuiItem {
|
||||
protected:
|
||||
EventHandler* _eh;
|
||||
bool _behavior_running;
|
||||
|
||||
INLINE GuiBehavior(void);
|
||||
PUBLISHED:
|
||||
class EXPCL_PANDA BehaviorFunctor {
|
||||
public:
|
||||
BehaviorFunctor(void);
|
||||
~BehaviorFunctor(void);
|
||||
virtual void doit(GuiBehavior*) = 0;
|
||||
};
|
||||
PUBLISHED:
|
||||
GuiBehavior(const string&);
|
||||
virtual ~GuiBehavior(void);
|
||||
@ -20,6 +30,30 @@ PUBLISHED:
|
||||
|
||||
virtual void start_behavior(void) = 0;
|
||||
virtual void stop_behavior(void) = 0;
|
||||
virtual void reset_behavior(void) = 0;
|
||||
|
||||
virtual void output(ostream&) const = 0;
|
||||
public:
|
||||
// type interface
|
||||
static TypeHandle get_class_type(void) {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type(void) {
|
||||
GuiItem::init_type();
|
||||
register_type(_type_handle, "GuiItem",
|
||||
GuiItem::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type(void) const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type(void) {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "guiBehavior.I"
|
||||
|
||||
#endif /* __GUIBEHAVIOR_H__ */
|
||||
|
@ -194,7 +194,7 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
}
|
||||
|
||||
void GuiButton::recompute_frame(void) {
|
||||
GuiItem::recompute_frame();
|
||||
GuiBehavior::recompute_frame();
|
||||
_up->recompute();
|
||||
_down->recompute();
|
||||
if (_up_rollover != (GuiLabel*)0L)
|
||||
@ -208,14 +208,43 @@ void GuiButton::recompute_frame(void) {
|
||||
_rgn->set_region(_left, _right, _bottom, _top);
|
||||
}
|
||||
|
||||
void GuiButton::behavior_up(CPT_Event, void* data) {
|
||||
GuiButton* button = (GuiButton*)data;
|
||||
button->run_button_up();
|
||||
}
|
||||
|
||||
void GuiButton::behavior_down(CPT_Event, void* data) {
|
||||
GuiButton* button = (GuiButton*)data;
|
||||
button->run_button_down();
|
||||
}
|
||||
|
||||
void GuiButton::run_button_up(void) {
|
||||
if (_eh == (EventHandler*)0L)
|
||||
return;
|
||||
_eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this);
|
||||
_eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
|
||||
if (!_behavior_event.empty())
|
||||
throw_event(_behavior_event);
|
||||
if (_behavior_functor != (GuiBehavior::BehaviorFunctor*)0L)
|
||||
_behavior_functor->doit(this);
|
||||
}
|
||||
|
||||
void GuiButton::run_button_down(void) {
|
||||
if (_eh == (EventHandler*)0L)
|
||||
return;
|
||||
_eh->add_hook(_up_event, GuiButton::behavior_up, (void*)this);
|
||||
_eh->add_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down)
|
||||
: GuiItem(name), _up(up), _up_rollover((GuiLabel*)0L), _down(down),
|
||||
: GuiBehavior(name), _up(up), _up_rollover((GuiLabel*)0L), _down(down),
|
||||
_down_rollover((GuiLabel*)0L), _inactive((GuiLabel*)0L),
|
||||
_up_event(name + "-up"), _up_rollover_event(""),
|
||||
_down_event(name +"-down"), _down_rollover_event(""),
|
||||
_inactive_event(""), _up_scale(up->get_scale()), _upr_scale(1.),
|
||||
_down_scale(down->get_scale()), _downr_scale(1.), _inactive_scale(1.),
|
||||
_state(GuiButton::NONE) {
|
||||
_state(GuiButton::NONE),
|
||||
_behavior_functor((GuiBehavior::BehaviorFunctor*)0L) {
|
||||
GetExtents(up, down, _up_rollover, _down_rollover, _inactive, _left, _right,
|
||||
_bottom, _top);
|
||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||
@ -228,13 +257,14 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down)
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down,
|
||||
GuiLabel* inactive)
|
||||
: GuiItem(name), _up(up), _up_rollover((GuiLabel*)0L), _down(down),
|
||||
: GuiBehavior(name), _up(up), _up_rollover((GuiLabel*)0L), _down(down),
|
||||
_down_rollover((GuiLabel*)0L), _inactive(inactive),
|
||||
_up_event(name + "-up"), _up_rollover_event(""),
|
||||
_down_event(name +"-down"), _down_rollover_event(""),
|
||||
_inactive_event(name + "-inactive"), _up_scale(up->get_scale()),
|
||||
_upr_scale(1.), _down_scale(down->get_scale()), _downr_scale(1.),
|
||||
_inactive_scale(inactive->get_scale()), _state(GuiButton::NONE) {
|
||||
_inactive_scale(inactive->get_scale()), _state(GuiButton::NONE),
|
||||
_behavior_functor((GuiBehavior::BehaviorFunctor*)0L) {
|
||||
GetExtents(up, down, _up_rollover, _down_rollover, inactive, _left, _right,
|
||||
_bottom, _top);
|
||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||
@ -247,14 +277,15 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down,
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* up_roll,
|
||||
GuiLabel* down, GuiLabel* down_roll, GuiLabel* inactive)
|
||||
: GuiItem(name), _up(up), _up_rollover(up_roll), _down(down),
|
||||
: GuiBehavior(name), _up(up), _up_rollover(up_roll), _down(down),
|
||||
_down_rollover(down_roll), _inactive(inactive), _up_event(name + "-up"),
|
||||
_up_rollover_event(name + "-up-rollover"), _down_event(name +"-down"),
|
||||
_down_rollover_event(name + "-down-rollover"),
|
||||
_inactive_event(name + "-inactive"), _up_scale(up->get_scale()),
|
||||
_upr_scale(up_roll->get_scale()), _down_scale(down->get_scale()),
|
||||
_downr_scale(down_roll->get_scale()),
|
||||
_inactive_scale(inactive->get_scale()), _state(GuiButton::NONE) {
|
||||
_inactive_scale(inactive->get_scale()), _state(GuiButton::NONE),
|
||||
_behavior_functor((GuiBehavior::BehaviorFunctor*)0L) {
|
||||
GetExtents(up, down, up_roll, down_roll, inactive, _left, _right, _bottom,
|
||||
_top);
|
||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||
@ -276,6 +307,9 @@ GuiButton::~GuiButton(void) {
|
||||
buttons.erase("gui-button-" + name + "-mouse1");
|
||||
buttons.erase("gui-button-" + name + "-mouse2");
|
||||
buttons.erase("gui-button-" + name + "-mouse3");
|
||||
|
||||
if (_behavior_functor != (GuiBehavior::BehaviorFunctor*)0L)
|
||||
delete _behavior_functor;
|
||||
}
|
||||
|
||||
void GuiButton::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
@ -289,7 +323,9 @@ void GuiButton::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
}
|
||||
if (_mgr == (GuiManager*)0L) {
|
||||
mgr->add_region(_rgn);
|
||||
GuiItem::manage(mgr, eh);
|
||||
GuiBehavior::manage(mgr, eh);
|
||||
if (_behavior_running)
|
||||
this->start_behavior();
|
||||
switch_state(UP);
|
||||
} else
|
||||
gui_cat->warning() << "tried to manage button (0x" << (void*)this
|
||||
@ -299,8 +335,10 @@ void GuiButton::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
void GuiButton::unmanage(void) {
|
||||
if (_mgr != (GuiManager*)0L)
|
||||
_mgr->remove_region(_rgn);
|
||||
if (_behavior_running)
|
||||
this->stop_behavior();
|
||||
switch_state(NONE);
|
||||
GuiItem::unmanage();
|
||||
GuiBehavior::unmanage();
|
||||
}
|
||||
|
||||
int GuiButton::freeze() {
|
||||
@ -338,7 +376,7 @@ void GuiButton::set_scale(float f) {
|
||||
_down_rollover->set_scale(f * _downr_scale);
|
||||
if (_inactive != (GuiLabel*)0L)
|
||||
_inactive->set_scale(f * _inactive_scale);
|
||||
GuiItem::set_scale(f);
|
||||
GuiBehavior::set_scale(f);
|
||||
this->recompute_frame();
|
||||
}
|
||||
|
||||
@ -351,12 +389,24 @@ void GuiButton::set_pos(const LVector3f& p) {
|
||||
_down_rollover->set_pos(p);
|
||||
if (_inactive != (GuiLabel*)0L)
|
||||
_inactive->set_pos(p);
|
||||
GuiItem::set_pos(p);
|
||||
GuiBehavior::set_pos(p);
|
||||
this->recompute_frame();
|
||||
}
|
||||
|
||||
void GuiButton::start_behavior(void) {
|
||||
GuiBehavior::start_behavior();
|
||||
}
|
||||
|
||||
void GuiButton::stop_behavior(void) {
|
||||
GuiBehavior::stop_behavior();
|
||||
}
|
||||
|
||||
void GuiButton::reset_behavior(void) {
|
||||
GuiBehavior::reset_behavior();
|
||||
}
|
||||
|
||||
void GuiButton::output(ostream& os) const {
|
||||
GuiItem::output(os);
|
||||
GuiBehavior::output(os);
|
||||
os << " Button data:" << endl;
|
||||
os << " up - 0x" << (void*)_up << endl;
|
||||
os << " up_rollover - 0x" << (void*)_up_rollover << endl;
|
||||
|
@ -6,12 +6,12 @@
|
||||
#ifndef __GUIBUTTON_H__
|
||||
#define __GUIBUTTON_H__
|
||||
|
||||
#include "guiItem.h"
|
||||
#include "guiBehavior.h"
|
||||
#include "guiRegion.h"
|
||||
#include "guiLabel.h"
|
||||
#include "guiManager.h"
|
||||
|
||||
class EXPCL_PANDA GuiButton : public GuiItem {
|
||||
class EXPCL_PANDA GuiButton : public GuiBehavior {
|
||||
private:
|
||||
PT(GuiLabel) _up;
|
||||
PT(GuiLabel) _up_rollover;
|
||||
@ -32,10 +32,17 @@ private:
|
||||
INACTIVE_ROLLOVER };
|
||||
States _state;
|
||||
|
||||
string _behavior_event;
|
||||
GuiBehavior::BehaviorFunctor* _behavior_functor;
|
||||
|
||||
INLINE GuiButton(void);
|
||||
void switch_state(States);
|
||||
virtual void recompute_frame(void);
|
||||
|
||||
static void behavior_up(CPT_Event, void*);
|
||||
static void behavior_down(CPT_Event, void*);
|
||||
void run_button_up(void);
|
||||
void run_button_down(void);
|
||||
PUBLISHED:
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*);
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*, GuiLabel*);
|
||||
@ -80,6 +87,10 @@ PUBLISHED:
|
||||
virtual void set_scale(float);
|
||||
virtual void set_pos(const LVector3f&);
|
||||
|
||||
virtual void start_behavior(void);
|
||||
virtual void stop_behavior(void);
|
||||
virtual void reset_behavior(void);
|
||||
|
||||
virtual void output(ostream&) const;
|
||||
|
||||
public:
|
||||
@ -88,9 +99,9 @@ public:
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type(void) {
|
||||
GuiItem::init_type();
|
||||
GuiBehavior::init_type();
|
||||
register_type(_type_handle, "GuiButton",
|
||||
GuiItem::get_class_type());
|
||||
GuiBehavior::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type(void) const {
|
||||
return get_class_type();
|
||||
|
@ -8,7 +8,7 @@
|
||||
TypeHandle GuiListBox::_type_handle;
|
||||
|
||||
void GuiListBox::recompute_frame(void) {
|
||||
GuiItem::recompute_frame();
|
||||
GuiBehavior::recompute_frame();
|
||||
LVector3f p = _pos;
|
||||
float lft = 100000.;
|
||||
float rgt = -100000.;
|
||||
@ -91,7 +91,7 @@ void GuiListBox::visible_patching(void) {
|
||||
}
|
||||
|
||||
GuiListBox::GuiListBox(const string& name, int N, GuiItem* up, GuiItem* down)
|
||||
: GuiItem(name), _arrow_top(false), _arrow_bottom(false), _up_arrow(up),
|
||||
: GuiBehavior(name), _arrow_top(false), _arrow_bottom(false), _up_arrow(up),
|
||||
_down_arrow(down), _n_visible(N) {
|
||||
if (N < 4) {
|
||||
gui_cat->warning() << "ListBoxes should have at least 4 visible slots"
|
||||
@ -199,7 +199,7 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i)
|
||||
(*i)->manage(mgr, eh);
|
||||
_eh = &eh;
|
||||
GuiItem::manage(mgr, eh);
|
||||
GuiBehavior::manage(mgr, eh);
|
||||
} else
|
||||
gui_cat->warning() << "tried to manage listbox (0x" << (void*)this
|
||||
<< ") that is already managed" << endl;
|
||||
@ -208,7 +208,7 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
void GuiListBox::unmanage(void) {
|
||||
for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i)
|
||||
(*i)->unmanage();
|
||||
GuiItem::unmanage();
|
||||
GuiBehavior::unmanage();
|
||||
}
|
||||
|
||||
void GuiListBox::set_scale(float f) {
|
||||
@ -220,7 +220,7 @@ void GuiListBox::set_scale(float f) {
|
||||
for (ItemDeque::iterator j=_bottom_stack.begin(); j!=_bottom_stack.end();
|
||||
++j)
|
||||
(*j)->set_scale(f);
|
||||
GuiItem::set_scale(f);
|
||||
GuiBehavior::set_scale(f);
|
||||
}
|
||||
|
||||
void GuiListBox::set_pos(const LVector3f& p) {
|
||||
@ -232,11 +232,23 @@ void GuiListBox::set_pos(const LVector3f& p) {
|
||||
for (ItemDeque::iterator j=_bottom_stack.begin(); j!=_bottom_stack.end();
|
||||
++j)
|
||||
(*j)->set_pos(p);
|
||||
GuiItem::set_pos(p);
|
||||
GuiBehavior::set_pos(p);
|
||||
}
|
||||
|
||||
void GuiListBox::start_behavior(void) {
|
||||
GuiBehavior::start_behavior();
|
||||
}
|
||||
|
||||
void GuiListBox::stop_behavior(void) {
|
||||
GuiBehavior::stop_behavior();
|
||||
}
|
||||
|
||||
void GuiListBox::reset_behavior(void) {
|
||||
GuiBehavior::reset_behavior();
|
||||
}
|
||||
|
||||
void GuiListBox::output(ostream& os) const {
|
||||
GuiItem::output(os);
|
||||
GuiBehavior::output(os);
|
||||
os << " Listbox data:" << endl;
|
||||
os << " There is ";
|
||||
if (!_arrow_top)
|
||||
|
@ -6,12 +6,12 @@
|
||||
#ifndef __GUILISTBOX_H__
|
||||
#define __GUILISTBOX_H__
|
||||
|
||||
#include "guiItem.h"
|
||||
#include "guiBehavior.h"
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
class EXPCL_PANDA GuiListBox : public GuiItem {
|
||||
class EXPCL_PANDA GuiListBox : public GuiBehavior {
|
||||
private:
|
||||
typedef vector< PT(GuiItem) > ItemVector;
|
||||
typedef deque< PT(GuiItem) > ItemDeque;
|
||||
@ -46,6 +46,10 @@ PUBLISHED:
|
||||
virtual void set_scale(float);
|
||||
virtual void set_pos(const LVector3f&);
|
||||
|
||||
virtual void start_behavior(void);
|
||||
virtual void stop_behavior(void);
|
||||
virtual void reset_behavior(void);
|
||||
|
||||
virtual void output(ostream&) const;
|
||||
public:
|
||||
// type interface
|
||||
@ -53,9 +57,9 @@ public:
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type(void) {
|
||||
GuiItem::init_type();
|
||||
GuiBehavior::init_type();
|
||||
register_type(_type_handle, "GuiListBox",
|
||||
GuiItem::get_class_type());
|
||||
GuiBehavior::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type(void) const {
|
||||
return get_class_type();
|
||||
|
Loading…
x
Reference in New Issue
Block a user