mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
make things typed and ref counted, and possibly fix scaling bug
This commit is contained in:
parent
fa8f38d8d6
commit
39f7645641
@ -4,6 +4,13 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "config_gui.h"
|
#include "config_gui.h"
|
||||||
|
#include "guiLabel.h"
|
||||||
|
#include "guiRegion.h"
|
||||||
|
#include "guiItem.h"
|
||||||
|
#include "guiSign.h"
|
||||||
|
#include "guiRollover.h"
|
||||||
|
#include "guiButton.h"
|
||||||
|
#include "guiFrame.h"
|
||||||
|
|
||||||
#include <dconfig.h>
|
#include <dconfig.h>
|
||||||
|
|
||||||
@ -11,4 +18,11 @@ Configure(config_gui);
|
|||||||
NotifyCategoryDef(gui, "");
|
NotifyCategoryDef(gui, "");
|
||||||
|
|
||||||
ConfigureFn(config_gui) {
|
ConfigureFn(config_gui) {
|
||||||
|
GuiLabel::init_type();
|
||||||
|
GuiRegion::init_type();
|
||||||
|
GuiItem::init_type();
|
||||||
|
GuiSign::init_type();
|
||||||
|
GuiRollover::init_type();
|
||||||
|
GuiButton::init_type();
|
||||||
|
GuiFrame::init_type();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
typedef map<string, GuiButton*> ButtonMap;
|
typedef map<string, GuiButton*> ButtonMap;
|
||||||
static ButtonMap buttons;
|
static ButtonMap buttons;
|
||||||
|
|
||||||
|
TypeHandle GuiButton::_type_handle;
|
||||||
|
|
||||||
inline void GetExtents(GuiLabel* v, GuiLabel* w, GuiLabel* x, GuiLabel* y,
|
inline void GetExtents(GuiLabel* v, GuiLabel* w, GuiLabel* x, GuiLabel* y,
|
||||||
GuiLabel* z, float& l, float& r, float& b, float& t) {
|
GuiLabel* z, float& l, float& r, float& b, float& t) {
|
||||||
float l1, l2, r1, r2, b1, b2, t1, t2;
|
float l1, l2, r1, r2, b1, b2, t1, t2;
|
||||||
@ -167,7 +169,9 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down)
|
|||||||
_down_rollover((GuiLabel*)0L), _inactive((GuiLabel*)0L),
|
_down_rollover((GuiLabel*)0L), _inactive((GuiLabel*)0L),
|
||||||
_up_event(name + "-up"), _up_rollover_event(""),
|
_up_event(name + "-up"), _up_rollover_event(""),
|
||||||
_down_event(name +"-down"), _down_rollover_event(""),
|
_down_event(name +"-down"), _down_rollover_event(""),
|
||||||
_inactive_event(""), _state(GuiButton::NONE) {
|
_inactive_event(""), _up_scale(up->get_scale()), _upr_scale(1.),
|
||||||
|
_down_scale(down->get_scale()), _downr_scale(1.), _inactive_scale(1.),
|
||||||
|
_state(GuiButton::NONE) {
|
||||||
GetExtents(up, down, _up_rollover, _down_rollover, _inactive, _left, _right,
|
GetExtents(up, down, _up_rollover, _down_rollover, _inactive, _left, _right,
|
||||||
_bottom, _top);
|
_bottom, _top);
|
||||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||||
@ -184,7 +188,9 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down,
|
|||||||
_down_rollover((GuiLabel*)0L), _inactive(inactive),
|
_down_rollover((GuiLabel*)0L), _inactive(inactive),
|
||||||
_up_event(name + "-up"), _up_rollover_event(""),
|
_up_event(name + "-up"), _up_rollover_event(""),
|
||||||
_down_event(name +"-down"), _down_rollover_event(""),
|
_down_event(name +"-down"), _down_rollover_event(""),
|
||||||
_inactive_event(name + "-inactive"), _state(GuiButton::NONE) {
|
_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) {
|
||||||
GetExtents(up, down, _up_rollover, _down_rollover, inactive, _left, _right,
|
GetExtents(up, down, _up_rollover, _down_rollover, inactive, _left, _right,
|
||||||
_bottom, _top);
|
_bottom, _top);
|
||||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||||
@ -201,7 +207,10 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* up_roll,
|
|||||||
_down_rollover(down_roll), _inactive(inactive), _up_event(name + "-up"),
|
_down_rollover(down_roll), _inactive(inactive), _up_event(name + "-up"),
|
||||||
_up_rollover_event(name + "-up-rollover"), _down_event(name +"-down"),
|
_up_rollover_event(name + "-up-rollover"), _down_event(name +"-down"),
|
||||||
_down_rollover_event(name + "-down-rollover"),
|
_down_rollover_event(name + "-down-rollover"),
|
||||||
_inactive_event(name + "-inactive"), _state(GuiButton::NONE) {
|
_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) {
|
||||||
GetExtents(up, down, up_roll, down_roll, inactive, _left, _right, _bottom,
|
GetExtents(up, down, up_roll, down_roll, inactive, _left, _right, _bottom,
|
||||||
_top);
|
_top);
|
||||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||||
@ -235,20 +244,21 @@ void GuiButton::manage(GuiManager* mgr, EventHandler& eh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::unmanage(void) {
|
void GuiButton::unmanage(void) {
|
||||||
_mgr->remove_region(_rgn);
|
if (_mgr != (GuiManager*)0L)
|
||||||
|
_mgr->remove_region(_rgn);
|
||||||
switch_state(NONE);
|
switch_state(NONE);
|
||||||
GuiItem::unmanage();
|
GuiItem::unmanage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiButton::set_scale(float f) {
|
void GuiButton::set_scale(float f) {
|
||||||
_up->set_scale(f);
|
_up->set_scale(f * _up_scale);
|
||||||
_down->set_scale(f);
|
_down->set_scale(f * _down_scale);
|
||||||
if (_up_rollover != (GuiLabel*)0L)
|
if (_up_rollover != (GuiLabel*)0L)
|
||||||
_up_rollover->set_scale(f);
|
_up_rollover->set_scale(f * _upr_scale);
|
||||||
if (_down_rollover != (GuiLabel*)0L)
|
if (_down_rollover != (GuiLabel*)0L)
|
||||||
_down_rollover->set_scale(f);
|
_down_rollover->set_scale(f * _downr_scale);
|
||||||
if (_inactive != (GuiLabel*)0L)
|
if (_inactive != (GuiLabel*)0L)
|
||||||
_inactive->set_scale(f);
|
_inactive->set_scale(f * _inactive_scale);
|
||||||
GuiItem::set_scale(f);
|
GuiItem::set_scale(f);
|
||||||
this->recompute_frame();
|
this->recompute_frame();
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,20 @@
|
|||||||
|
|
||||||
class EXPCL_PANDA GuiButton : public GuiItem {
|
class EXPCL_PANDA GuiButton : public GuiItem {
|
||||||
private:
|
private:
|
||||||
GuiLabel* _up;
|
PT(GuiLabel) _up;
|
||||||
GuiLabel* _up_rollover;
|
PT(GuiLabel) _up_rollover;
|
||||||
GuiLabel* _down;
|
PT(GuiLabel) _down;
|
||||||
GuiLabel* _down_rollover;
|
PT(GuiLabel) _down_rollover;
|
||||||
GuiLabel* _inactive;
|
PT(GuiLabel) _inactive;
|
||||||
string _up_event, _up_rollover_event, _down_event, _down_rollover_event;
|
string _up_event, _up_rollover_event, _down_event, _down_rollover_event;
|
||||||
string _inactive_event;
|
string _inactive_event;
|
||||||
GuiRegion* _rgn;
|
PT(GuiRegion) _rgn;
|
||||||
|
|
||||||
|
float _up_scale;
|
||||||
|
float _upr_scale;
|
||||||
|
float _down_scale;
|
||||||
|
float _downr_scale;
|
||||||
|
float _inactive_scale;
|
||||||
|
|
||||||
enum States { NONE, UP, UP_ROLLOVER, DOWN, DOWN_ROLLOVER, INACTIVE,
|
enum States { NONE, UP, UP_ROLLOVER, DOWN, DOWN_ROLLOVER, INACTIVE,
|
||||||
INACTIVE_ROLLOVER };
|
INACTIVE_ROLLOVER };
|
||||||
@ -65,6 +71,25 @@ public:
|
|||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
virtual void output(ostream&) const;
|
virtual void output(ostream&) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
GuiItem::init_type();
|
||||||
|
register_type(_type_handle, "GuiButton",
|
||||||
|
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 "guiButton.I"
|
#include "guiButton.I"
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "guiFrame.h"
|
#include "guiFrame.h"
|
||||||
|
|
||||||
|
TypeHandle GuiFrame::_type_handle;
|
||||||
|
|
||||||
GuiFrame::Boxes::iterator GuiFrame::find_box(GuiItem* item) {
|
GuiFrame::Boxes::iterator GuiFrame::find_box(GuiItem* item) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Boxes::iterator ret = _items.end();
|
Boxes::iterator ret = _items.end();
|
||||||
@ -190,7 +192,7 @@ void GuiFrame::unmanage(void) {
|
|||||||
|
|
||||||
void GuiFrame::set_scale(float f) {
|
void GuiFrame::set_scale(float f) {
|
||||||
for (Boxes::iterator i=_items.begin(); i!=_items.end(); ++i)
|
for (Boxes::iterator i=_items.begin(); i!=_items.end(); ++i)
|
||||||
(*i).get_item()->set_scale(f);
|
(*i).get_item()->set_scale(f * (*i).get_scale());
|
||||||
GuiItem::set_scale(f);
|
GuiItem::set_scale(f);
|
||||||
this->recompute_frame();
|
this->recompute_frame();
|
||||||
}
|
}
|
||||||
|
@ -39,18 +39,22 @@ private:
|
|||||||
typedef vector<Connection> Connections;
|
typedef vector<Connection> Connections;
|
||||||
class Box {
|
class Box {
|
||||||
private:
|
private:
|
||||||
GuiItem* _thing;
|
PT(GuiItem) _thing;
|
||||||
|
float _scale;
|
||||||
Connections _links;
|
Connections _links;
|
||||||
public:
|
public:
|
||||||
inline Box(void) : _thing((GuiItem*)0L) {}
|
inline Box(void) : _thing((GuiItem*)0L), _scale(1.) {}
|
||||||
inline Box(GuiItem* i) : _thing(i) {}
|
inline Box(GuiItem* i) : _thing(i), _scale(i->get_scale()) {}
|
||||||
inline Box(const Box& c) : _thing(c._thing), _links(c._links) {}
|
inline Box(const Box& c) : _thing(c._thing), _scale(c._scale),
|
||||||
|
_links(c._links) {}
|
||||||
~Box(void) {}
|
~Box(void) {}
|
||||||
|
|
||||||
inline void set_item(GuiItem* i) { _thing = i; }
|
inline void set_item(GuiItem* i) { _thing = i; }
|
||||||
|
inline void set_scale(float f) { _scale = f; }
|
||||||
inline void add_link(Connection c) { _links.push_back(c); }
|
inline void add_link(Connection c) { _links.push_back(c); }
|
||||||
|
|
||||||
inline GuiItem* get_item(void) const { return _thing; }
|
inline GuiItem* get_item(void) const { return _thing; }
|
||||||
|
inline float get_scale(void) const { return _scale; }
|
||||||
inline int get_num_links(void) const { return _links.size(); }
|
inline int get_num_links(void) const { return _links.size(); }
|
||||||
inline Packing get_nth_packing(int n) const { return _links[n].get_how(); }
|
inline Packing get_nth_packing(int n) const { return _links[n].get_how(); }
|
||||||
inline GuiItem* get_nth_to(int n) const { return _links[n].get_who(); }
|
inline GuiItem* get_nth_to(int n) const { return _links[n].get_who(); }
|
||||||
@ -81,6 +85,25 @@ public:
|
|||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
virtual void output(ostream&) const;
|
virtual void output(ostream&) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
GuiItem::init_type();
|
||||||
|
register_type(_type_handle, "GuiFrame",
|
||||||
|
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 "guiFrame.I"
|
#include "guiFrame.I"
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "guiItem.h"
|
#include "guiItem.h"
|
||||||
|
|
||||||
|
TypeHandle GuiItem::_type_handle;
|
||||||
|
|
||||||
void GuiItem::recompute_frame(void) {
|
void GuiItem::recompute_frame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,6 +18,8 @@ GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false),
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiItem::~GuiItem(void) {
|
GuiItem::~GuiItem(void) {
|
||||||
|
if (gui_cat->is_debug())
|
||||||
|
gui_cat->debug() << "deleting item '" << this->get_name() << "'" << endl;
|
||||||
this->unmanage();
|
this->unmanage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <eventHandler.h>
|
#include <eventHandler.h>
|
||||||
|
|
||||||
class EXPCL_PANDA GuiItem : public Namable {
|
class EXPCL_PANDA GuiItem : public TypedReferenceCount, public Namable {
|
||||||
protected:
|
protected:
|
||||||
bool _added_hooks;
|
bool _added_hooks;
|
||||||
float _scale, _left, _right, _bottom, _top;
|
float _scale, _left, _right, _bottom, _top;
|
||||||
@ -38,6 +38,25 @@ public:
|
|||||||
INLINE LVector4f get_frame(void) const;
|
INLINE LVector4f get_frame(void) const;
|
||||||
|
|
||||||
virtual void output(ostream&) const = 0;
|
virtual void output(ostream&) const = 0;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
TypedReferenceCount::init_type();
|
||||||
|
register_type(_type_handle, "GuiItem",
|
||||||
|
TypedReferenceCount::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 "guiItem.I"
|
#include "guiItem.I"
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <transformTransition.h>
|
#include <transformTransition.h>
|
||||||
#include <colorTransition.h>
|
#include <colorTransition.h>
|
||||||
|
|
||||||
|
TypeHandle GuiLabel::_type_handle;
|
||||||
|
|
||||||
void GuiLabel::recompute_transform(void) {
|
void GuiLabel::recompute_transform(void) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case SIMPLE_TEXT:
|
case SIMPLE_TEXT:
|
||||||
@ -92,6 +94,8 @@ void GuiLabel::set_properties(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiLabel::~GuiLabel(void) {
|
GuiLabel::~GuiLabel(void) {
|
||||||
|
if (gui_cat->is_debug())
|
||||||
|
gui_cat->debug() << "deleting label (0x" << (void*)this << ")" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <textureTransition.h>
|
#include <textureTransition.h>
|
||||||
@ -220,15 +224,27 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float GuiLabel::get_width(void) {
|
float GuiLabel::get_width(void) {
|
||||||
float l, r, b, t;
|
float w;
|
||||||
this->get_extents(l, r, b, t);
|
TextNode* n = DCAST(TextNode, _geom);
|
||||||
return (r - l);
|
if (n->has_card()) {
|
||||||
|
LVecBase4f v = n->get_card_actual();
|
||||||
|
w = v[1] - v[0];
|
||||||
|
} else {
|
||||||
|
w = n->get_width();
|
||||||
|
}
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GuiLabel::get_height(void) {
|
float GuiLabel::get_height(void) {
|
||||||
float l, r, b, t;
|
float h;
|
||||||
this->get_extents(l, r, b, t);
|
TextNode* n = DCAST(TextNode, _geom);
|
||||||
return (t - b);
|
if (n->has_card()) {
|
||||||
|
LVecBase4f v = n->get_card_actual();
|
||||||
|
h = v[3] - v[2];
|
||||||
|
} else {
|
||||||
|
h = n->get_width();
|
||||||
|
}
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiLabel::set_foreground_color(const Colorf& color) {
|
void GuiLabel::set_foreground_color(const Colorf& color) {
|
||||||
|
@ -13,18 +13,19 @@
|
|||||||
#include <pt_Node.h>
|
#include <pt_Node.h>
|
||||||
#include <renderRelation.h>
|
#include <renderRelation.h>
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
|
#include <typedReferenceCount.h>
|
||||||
|
|
||||||
// label-ish behavior for GUI objects (labels, buttons, rollovers)
|
// label-ish behavior for GUI objects (labels, buttons, rollovers)
|
||||||
|
|
||||||
class GuiManager;
|
class GuiManager;
|
||||||
|
|
||||||
class EXPCL_PANDA GuiLabel {
|
class EXPCL_PANDA GuiLabel : public TypedReferenceCount {
|
||||||
private:
|
private:
|
||||||
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT };
|
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT };
|
||||||
LabelType _type;
|
LabelType _type;
|
||||||
PT_Node _geom;
|
PT_Node _geom;
|
||||||
RenderRelation* _arc;
|
RenderRelation* _arc;
|
||||||
Texture* _tex;
|
PT(Texture) _tex;
|
||||||
RenderRelation* _internal;
|
RenderRelation* _internal;
|
||||||
|
|
||||||
float _scale;
|
float _scale;
|
||||||
@ -73,6 +74,25 @@ public:
|
|||||||
|
|
||||||
INLINE Colorf get_foreground_color(void) const;
|
INLINE Colorf get_foreground_color(void) const;
|
||||||
INLINE Colorf get_background_color(void) const;
|
INLINE Colorf get_background_color(void) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
TypedReferenceCount::init_type();
|
||||||
|
register_type(_type_handle, "GuiLabel",
|
||||||
|
TypedReferenceCount::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 "guiLabel.I"
|
#include "guiLabel.I"
|
||||||
|
@ -3,7 +3,12 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "config_gui.h"
|
||||||
#include "guiRegion.h"
|
#include "guiRegion.h"
|
||||||
|
|
||||||
|
TypeHandle GuiRegion::_type_handle;
|
||||||
|
|
||||||
GuiRegion::~GuiRegion(void) {
|
GuiRegion::~GuiRegion(void) {
|
||||||
|
if (gui_cat->is_debug())
|
||||||
|
gui_cat->debug() << "deleting region '" << *this << "'" << endl;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,13 @@
|
|||||||
#include <pandabase.h>
|
#include <pandabase.h>
|
||||||
#include <mouseWatcherRegion.h>
|
#include <mouseWatcherRegion.h>
|
||||||
#include <pointerTo.h>
|
#include <pointerTo.h>
|
||||||
|
#include <typedReferenceCount.h>
|
||||||
|
|
||||||
// container for active regions of a GUI
|
// container for active regions of a GUI
|
||||||
|
|
||||||
class GuiManager;
|
class GuiManager;
|
||||||
|
|
||||||
class EXPCL_PANDA GuiRegion : public Namable {
|
class EXPCL_PANDA GuiRegion : public TypedReferenceCount, public Namable {
|
||||||
private:
|
private:
|
||||||
float _left, _right, _bottom, _top;
|
float _left, _right, _bottom, _top;
|
||||||
PT(MouseWatcherRegion) _region;
|
PT(MouseWatcherRegion) _region;
|
||||||
@ -32,6 +33,25 @@ public:
|
|||||||
|
|
||||||
INLINE void set_region(float, float, float, float);
|
INLINE void set_region(float, float, float, float);
|
||||||
INLINE LVector4f get_frame(void) const;
|
INLINE LVector4f get_frame(void) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
TypedReferenceCount::init_type();
|
||||||
|
register_type(_type_handle, "GuiRegion",
|
||||||
|
TypedReferenceCount::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 "guiRegion.I"
|
#include "guiRegion.I"
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
typedef map<string, GuiRollover*> RolloverMap;
|
typedef map<string, GuiRollover*> RolloverMap;
|
||||||
static RolloverMap rollovers;
|
static RolloverMap rollovers;
|
||||||
|
|
||||||
|
TypeHandle GuiRollover::_type_handle;
|
||||||
|
|
||||||
inline void GetExtents(GuiLabel* x, GuiLabel* y, float& l, float& r, float& b,
|
inline void GetExtents(GuiLabel* x, GuiLabel* y, float& l, float& r, float& b,
|
||||||
float& t) {
|
float& t) {
|
||||||
float l1, l2, r1, r2, b1, b2, t1, t2;
|
float l1, l2, r1, r2, b1, b2, t1, t2;
|
||||||
@ -39,7 +41,8 @@ void GuiRollover::recompute_frame(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on)
|
GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on)
|
||||||
: GuiItem(name), _off(off), _on(on), _state(false) {
|
: GuiItem(name), _off(off), _on(on), _off_scale(off->get_scale()),
|
||||||
|
_on_scale(on->get_scale()), _state(false) {
|
||||||
GetExtents(off, on, _left, _right, _bottom, _top);
|
GetExtents(off, on, _left, _right, _bottom, _top);
|
||||||
_rgn = new GuiRegion("rollover-" + name, _left, _right, _bottom, _top,
|
_rgn = new GuiRegion("rollover-" + name, _left, _right, _bottom, _top,
|
||||||
false);
|
false);
|
||||||
@ -68,15 +71,17 @@ void GuiRollover::manage(GuiManager* mgr, EventHandler& eh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GuiRollover::unmanage(void) {
|
void GuiRollover::unmanage(void) {
|
||||||
_mgr->remove_region(_rgn);
|
if (_mgr != (GuiManager*)0L) {
|
||||||
_mgr->remove_label(_off);
|
_mgr->remove_region(_rgn);
|
||||||
_mgr->remove_label(_on);
|
_mgr->remove_label(_off);
|
||||||
|
_mgr->remove_label(_on);
|
||||||
|
}
|
||||||
GuiItem::unmanage();
|
GuiItem::unmanage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiRollover::set_scale(float f) {
|
void GuiRollover::set_scale(float f) {
|
||||||
_on->set_scale(f);
|
_on->set_scale(f * _on_scale);
|
||||||
_off->set_scale(f);
|
_off->set_scale(f * _off_scale);
|
||||||
GuiItem::set_scale(f);
|
GuiItem::set_scale(f);
|
||||||
recompute_frame();
|
recompute_frame();
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,12 @@
|
|||||||
|
|
||||||
class EXPCL_PANDA GuiRollover : public GuiItem {
|
class EXPCL_PANDA GuiRollover : public GuiItem {
|
||||||
private:
|
private:
|
||||||
GuiLabel* _off;
|
PT(GuiLabel) _off;
|
||||||
GuiLabel* _on;
|
PT(GuiLabel) _on;
|
||||||
GuiRegion* _rgn;
|
PT(GuiRegion) _rgn;
|
||||||
|
|
||||||
|
float _off_scale;
|
||||||
|
float _on_scale;
|
||||||
|
|
||||||
bool _state;
|
bool _state;
|
||||||
|
|
||||||
@ -36,6 +39,25 @@ public:
|
|||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
virtual void output(ostream&) const;
|
virtual void output(ostream&) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
GuiItem::init_type();
|
||||||
|
register_type(_type_handle, "GuiRollover",
|
||||||
|
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 "guiRollover.I"
|
#include "guiRollover.I"
|
||||||
|
@ -6,13 +6,15 @@
|
|||||||
#include "guiSign.h"
|
#include "guiSign.h"
|
||||||
#include "config_gui.h"
|
#include "config_gui.h"
|
||||||
|
|
||||||
|
TypeHandle GuiSign::_type_handle;
|
||||||
|
|
||||||
void GuiSign::recompute_frame(void) {
|
void GuiSign::recompute_frame(void) {
|
||||||
GuiItem::recompute_frame();
|
GuiItem::recompute_frame();
|
||||||
_sign->get_extents(_left, _right, _bottom, _top);
|
_sign->get_extents(_left, _right, _bottom, _top);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiSign::GuiSign(const string& name, GuiLabel* sign) : GuiItem(name),
|
GuiSign::GuiSign(const string& name, GuiLabel* sign)
|
||||||
_sign(sign) {
|
: GuiItem(name), _sign(sign), _sign_scale(sign->get_scale()) {
|
||||||
_sign->get_extents(_left, _right, _bottom, _top);
|
_sign->get_extents(_left, _right, _bottom, _top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,12 +34,13 @@ void GuiSign::manage(GuiManager* mgr, EventHandler& eh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GuiSign::unmanage(void) {
|
void GuiSign::unmanage(void) {
|
||||||
_mgr->remove_label(_sign);
|
if (_mgr != (GuiManager*)0L)
|
||||||
|
_mgr->remove_label(_sign);
|
||||||
GuiSign::unmanage();
|
GuiSign::unmanage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSign::set_scale(float f) {
|
void GuiSign::set_scale(float f) {
|
||||||
_sign->set_scale(f);
|
_sign->set_scale(f * _sign_scale);
|
||||||
GuiItem::set_scale(f);
|
GuiItem::set_scale(f);
|
||||||
recompute_frame();
|
recompute_frame();
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
class EXPCL_PANDA GuiSign : public GuiItem {
|
class EXPCL_PANDA GuiSign : public GuiItem {
|
||||||
private:
|
private:
|
||||||
GuiLabel* _sign;
|
PT(GuiLabel) _sign;
|
||||||
|
float _sign_scale;
|
||||||
|
|
||||||
INLINE GuiSign(void);
|
INLINE GuiSign(void);
|
||||||
virtual void recompute_frame(void);
|
virtual void recompute_frame(void);
|
||||||
@ -27,6 +28,25 @@ public:
|
|||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
virtual void output(ostream&) const;
|
virtual void output(ostream&) const;
|
||||||
|
public:
|
||||||
|
// type interface
|
||||||
|
static TypeHandle get_class_type(void) {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type(void) {
|
||||||
|
GuiItem::init_type();
|
||||||
|
register_type(_type_handle, "GuiSign",
|
||||||
|
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 "guiSign.I"
|
#include "guiSign.I"
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
extern PT(GeomNode) geomnode;
|
extern PT(GeomNode) geomnode;
|
||||||
extern RenderRelation* first_arc;
|
extern RenderRelation* first_arc;
|
||||||
|
|
||||||
static GuiFrame* global_frame;
|
static PT(GuiFrame) global_frame;
|
||||||
|
|
||||||
static void setup_gui(void) {
|
static void setup_gui(void) {
|
||||||
GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
|
GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
|
||||||
@ -205,7 +205,7 @@ static void event_2(CPT_Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void event_3(CPT_Event) {
|
static void event_3(CPT_Event) {
|
||||||
delete global_frame;
|
global_frame = (GuiFrame*)0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
void demo_keys(EventHandler&) {
|
void demo_keys(EventHandler&) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user