mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-28 07:48:37 -04:00
some more functionality
This commit is contained in:
parent
8dbea4d196
commit
f13c786d61
@ -162,6 +162,39 @@ void GuiButton::recompute_frame(void) {
|
||||
_rgn->set_region(_left, _right, _bottom, _top);
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down)
|
||||
: GuiItem(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(""), _state(GuiButton::NONE) {
|
||||
GetExtents(up, down, _up_rollover, _down_rollover, _inactive, _left, _right,
|
||||
_bottom, _top);
|
||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||
buttons["gui-in-button-" + name] = this;
|
||||
buttons["gui-out-button-" + name] = this;
|
||||
buttons["gui-button-" + name + "-mouse1"] = this;
|
||||
buttons["gui-button-" + name + "-mouse2"] = this;
|
||||
buttons["gui-button-" + name + "-mouse3"] = this;
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down,
|
||||
GuiLabel* inactive)
|
||||
: GuiItem(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"), _state(GuiButton::NONE) {
|
||||
GetExtents(up, down, _up_rollover, _down_rollover, inactive, _left, _right,
|
||||
_bottom, _top);
|
||||
_rgn = new GuiRegion("button-" + name, _left, _right, _bottom, _top, true);
|
||||
buttons["gui-in-button-" + name] = this;
|
||||
buttons["gui-out-button-" + name] = this;
|
||||
buttons["gui-button-" + name + "-mouse1"] = this;
|
||||
buttons["gui-button-" + name + "-mouse2"] = this;
|
||||
buttons["gui-button-" + name + "-mouse3"] = this;
|
||||
}
|
||||
|
||||
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),
|
||||
|
@ -30,6 +30,8 @@ private:
|
||||
void switch_state(States);
|
||||
virtual void recompute_frame(void);
|
||||
public:
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*);
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*, GuiLabel*);
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*, GuiLabel*, GuiLabel*,
|
||||
GuiLabel*);
|
||||
virtual ~GuiButton(void);
|
||||
|
@ -140,7 +140,7 @@ void GuiFrame::add_item(GuiItem* item) {
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to) {
|
||||
void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to, float gap) {
|
||||
Boxes::iterator box = find_box(item);
|
||||
if (box == _items.end()) {
|
||||
gui_cat->warning() << "tried to pack an item we don't have yet" << endl;
|
||||
@ -152,10 +152,20 @@ void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to) {
|
||||
<< "tried to pack an item relative to something we don't have" << endl;
|
||||
return;
|
||||
}
|
||||
(*box).add_link(Connection(rel, to));
|
||||
(*box).add_link(Connection(rel, to, gap));
|
||||
this->recompute_frame();
|
||||
}
|
||||
|
||||
void GuiFrame::clear_packing(GuiItem* item) {
|
||||
Boxes::iterator box = find_box(item);
|
||||
(*box).erase_all_links();
|
||||
}
|
||||
|
||||
void GuiFrame::clear_all_packing(void) {
|
||||
for (Boxes::iterator i=_items.begin(); i!=_items.end(); ++i)
|
||||
(*i).erase_all_links();
|
||||
}
|
||||
|
||||
void GuiFrame::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
if (!_added_hooks) {
|
||||
_added_hooks = true;
|
||||
|
@ -18,17 +18,23 @@ private:
|
||||
private:
|
||||
Packing _how;
|
||||
GuiItem* _who;
|
||||
float _gap;
|
||||
public:
|
||||
inline Connection(void) : _how(NONE), _who((GuiItem*)0L) {}
|
||||
inline Connection(Packing how, GuiItem* who) : _how(how), _who(who) {}
|
||||
inline Connection(const Connection& c) : _how(c._how), _who(c._who) {}
|
||||
inline Connection(void) : _how(NONE), _who((GuiItem*)0L), _gap(0.) {}
|
||||
inline Connection(Packing how, GuiItem* who, float gap) : _how(how),
|
||||
_who(who),
|
||||
_gap(gap) {}
|
||||
inline Connection(const Connection& c) : _how(c._how), _who(c._who),
|
||||
_gap(c._gap) {}
|
||||
~Connection(void) {}
|
||||
|
||||
inline void set_how(Packing how) { _how = how; }
|
||||
inline void set_who(GuiItem* who) { _who = who; }
|
||||
inline void set_gap(float gap) { _gap = gap; }
|
||||
|
||||
inline Packing get_how(void) const { return _how; }
|
||||
inline GuiItem* get_who(void) const { return _who; }
|
||||
inline float get_gap(void) const { return _gap; }
|
||||
};
|
||||
typedef vector<Connection> Connections;
|
||||
class Box {
|
||||
@ -48,6 +54,9 @@ private:
|
||||
inline int get_num_links(void) const { return _links.size(); }
|
||||
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 void erase_nth_link(int n) { _links.erase(_links.begin() + n); }
|
||||
inline void erase_all_links(void) { _links.clear(); }
|
||||
};
|
||||
typedef vector<Box> Boxes;
|
||||
|
||||
@ -61,7 +70,9 @@ public:
|
||||
~GuiFrame(void);
|
||||
|
||||
void add_item(GuiItem*);
|
||||
void pack_item(GuiItem*, Packing, GuiItem*);
|
||||
void pack_item(GuiItem*, Packing, GuiItem*, float = 0.);
|
||||
void clear_packing(GuiItem*);
|
||||
void clear_all_packing(void);
|
||||
|
||||
virtual void manage(GuiManager*, EventHandler&);
|
||||
virtual void unmanage(void);
|
||||
|
@ -10,7 +10,9 @@ INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE),
|
||||
_pos(0., 0., 0.),
|
||||
_foreground(1., 1., 1., 1.),
|
||||
_have_background(false),
|
||||
_background(0., 0., 0., 0.) {
|
||||
_background(0., 0., 0., 0.),
|
||||
_have_width(false), _width(0.),
|
||||
_have_height(false), _height(0.) {
|
||||
}
|
||||
|
||||
INLINE Node* GuiLabel::get_geometry(void) const {
|
||||
@ -25,6 +27,28 @@ INLINE RenderRelation* GuiLabel::get_arc(void) const {
|
||||
return _arc;
|
||||
}
|
||||
|
||||
INLINE void GuiLabel::set_width(float f) {
|
||||
if (f <= 0.) {
|
||||
_have_width = false;
|
||||
_width = 0.;
|
||||
} else {
|
||||
_have_width = true;
|
||||
_width = f;
|
||||
}
|
||||
this->set_properties();
|
||||
}
|
||||
|
||||
INLINE void GuiLabel::set_height(float f) {
|
||||
if (f <= 0.) {
|
||||
_have_height = false;
|
||||
_height = 0.;
|
||||
} else {
|
||||
_have_height = true;
|
||||
_height = f;
|
||||
}
|
||||
this->set_properties();
|
||||
}
|
||||
|
||||
INLINE void GuiLabel::set_scale(float f) {
|
||||
_scale = f;
|
||||
recompute_transform();
|
||||
|
@ -45,7 +45,25 @@ void GuiLabel::set_properties(void) {
|
||||
gui_cat->debug() << "cleared card" << endl;
|
||||
} else {
|
||||
n->set_card_color(_background);
|
||||
n->set_card_as_margin(0., 0., 0., 0.);
|
||||
if (_have_width || _have_height) {
|
||||
LVecBase4f v = n->get_card_actual();
|
||||
float w = v[1] - v[0];
|
||||
float h = v[3] - v[2];
|
||||
if (_have_width) {
|
||||
w = _width - w;
|
||||
w *= 0.5;
|
||||
v[1] += w;
|
||||
v[0] -= w;
|
||||
}
|
||||
if (_have_height) {
|
||||
h = _height - h;
|
||||
h *= 0.5;
|
||||
v[3] += h;
|
||||
v[2] -= h;
|
||||
}
|
||||
n->set_card_actual(v[0], v[1], v[2], v[3]);
|
||||
} else
|
||||
n->set_card_as_margin(0., 0., 0., 0.);
|
||||
if (gui_cat->is_debug()) {
|
||||
gui_cat->debug() << "set card color" << endl;
|
||||
if (n->has_card())
|
||||
@ -193,6 +211,18 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
|
||||
}
|
||||
}
|
||||
|
||||
float GuiLabel::get_width(void) {
|
||||
float l, r, b, t;
|
||||
this->get_extents(l, r, b, t);
|
||||
return (r - l);
|
||||
}
|
||||
|
||||
float GuiLabel::get_height(void) {
|
||||
float l, r, b, t;
|
||||
this->get_extents(l, r, b, t);
|
||||
return (t - b);
|
||||
}
|
||||
|
||||
void GuiLabel::set_foreground_color(const Colorf& color) {
|
||||
_foreground = color;
|
||||
set_properties();
|
||||
|
@ -32,6 +32,10 @@ private:
|
||||
Colorf _foreground;
|
||||
bool _have_background;
|
||||
Colorf _background;
|
||||
bool _have_width;
|
||||
float _width;
|
||||
bool _have_height;
|
||||
float _height;
|
||||
|
||||
INLINE Node* get_geometry(void) const;
|
||||
INLINE void set_arc(RenderRelation*);
|
||||
@ -49,6 +53,11 @@ public:
|
||||
static GuiLabel* make_simple_text_label(const string&, Node*);
|
||||
|
||||
void get_extents(float&, float&, float&, float&);
|
||||
float get_width(void);
|
||||
float get_height(void);
|
||||
|
||||
INLINE void set_width(float);
|
||||
INLINE void set_height(float);
|
||||
|
||||
INLINE void set_scale(float);
|
||||
INLINE void set_pos(float, float, float);
|
||||
|
Loading…
x
Reference in New Issue
Block a user