mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
fix frame packing calculation
This commit is contained in:
parent
8ba886192d
commit
675a62e6cf
@ -231,3 +231,21 @@ void GuiButton::set_pos(const LVector3f& p) {
|
|||||||
GuiItem::set_pos(p);
|
GuiItem::set_pos(p);
|
||||||
this->recompute_frame();
|
this->recompute_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiButton::output(ostream& os) const {
|
||||||
|
GuiItem::output(os);
|
||||||
|
os << " Button data:" << endl;
|
||||||
|
os << " up - 0x" << (void*)_up << endl;
|
||||||
|
os << " up_rollover - 0x" << (void*)_up_rollover << endl;
|
||||||
|
os << " down - 0x" << (void*)_down << endl;
|
||||||
|
os << " down_rollover - 0x" << (void*)_down_rollover << endl;
|
||||||
|
os << " inactive - 0x" << (void*)_inactive << endl;
|
||||||
|
os << " up event - '" << _up_event << "'" << endl;
|
||||||
|
os << " up_rollover event - '" << _up_rollover_event << "'" << endl;
|
||||||
|
os << " down event - '" << _down_event << "'" << endl;
|
||||||
|
os << " down_rollover event - '" << _down_rollover_event << "'" << endl;
|
||||||
|
os << " inactive event - '" << _inactive_event << "'" << endl;
|
||||||
|
os << " rgn - 0x" << (void*)_rgn << endl;
|
||||||
|
os << " frame - " << _rgn->get_frame() << endl;
|
||||||
|
os << " state - " << _state << endl;
|
||||||
|
}
|
||||||
|
@ -61,6 +61,8 @@ public:
|
|||||||
|
|
||||||
virtual void set_scale(float);
|
virtual void set_scale(float);
|
||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
|
virtual void output(ostream&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "guiButton.I"
|
#include "guiButton.I"
|
||||||
|
@ -30,51 +30,52 @@ void GuiFrame::recompute_frame(void) {
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
GuiItem* here = (*i).get_item();
|
GuiItem* here = (*i).get_item();
|
||||||
LVector4f ext_h = here->get_frame();
|
LVector4f ext_h = here->get_frame();
|
||||||
float x_h = (ext_h[0] + ext_h[1]) / 2.;
|
LVector3f pos_h = here->get_pos();
|
||||||
float y_h = (ext_h[2] + ext_h[3]) / 2.;
|
|
||||||
for (int j=0; j<n; ++j) {
|
for (int j=0; j<n; ++j) {
|
||||||
Packing pack = (*i).get_nth_packing(j);
|
Packing pack = (*i).get_nth_packing(j);
|
||||||
if (pack == NONE)
|
if (pack == NONE)
|
||||||
continue;
|
continue;
|
||||||
GuiItem* to = (*i).get_nth_to(j);
|
GuiItem* to = (*i).get_nth_to(j);
|
||||||
LVector4f ext_t = to->get_frame();
|
LVector4f ext_t = to->get_frame();
|
||||||
float x_t = (ext_t[0] + ext_h[1]) / 2.;
|
|
||||||
float y_t = (ext_t[2] + ext_h[3]) / 2.;
|
|
||||||
switch (pack) {
|
switch (pack) {
|
||||||
case ABOVE:
|
case ABOVE:
|
||||||
{
|
{
|
||||||
// to(top) - here(bottom)
|
// to(top) - here(bottom)
|
||||||
float diff = ext_t[3] - ext_h[2];
|
float diff = ext_t[3] - ext_h[2];
|
||||||
y_h += diff;
|
LVector3f move = LVector3f::rfu(0., 0., diff);
|
||||||
here->set_pos(LVector3f::rfu(x_h, 0., y_h));
|
here->set_pos(pos_h + move);
|
||||||
ext_h = here->get_frame();
|
ext_h = here->get_frame();
|
||||||
|
pos_h = here->get_pos();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNDER:
|
case UNDER:
|
||||||
{
|
{
|
||||||
// to(bottom) - here(top)
|
// to(bottom) - here(top)
|
||||||
float diff = ext_t[2] - ext_h[3];
|
float diff = ext_t[2] - ext_h[3];
|
||||||
y_h += diff;
|
LVector3f move = LVector3f::rfu(0., 0., diff);
|
||||||
here->set_pos(LVector3f::rfu(x_h, 0., y_h));
|
here->set_pos(pos_h + move);
|
||||||
ext_h = here->get_frame();
|
ext_h = here->get_frame();
|
||||||
|
pos_h = here->get_pos();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
{
|
{
|
||||||
// to(left) - here(right)
|
// to(left) - here(right)
|
||||||
float diff = ext_t[0] - ext_h[1];
|
float diff = ext_t[0] - ext_h[1];
|
||||||
x_h += diff;
|
LVector3f move = LVector3f::rfu(diff, 0., 0.);
|
||||||
here->set_pos(LVector3f::rfu(x_h, 0., y_h));
|
here->set_pos(pos_h + move);
|
||||||
ext_h = here->get_frame();
|
ext_h = here->get_frame();
|
||||||
|
pos_h = here->get_pos();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
{
|
{
|
||||||
// to(right) - here(left)
|
// to(right) - here(left)
|
||||||
float diff = ext_t[1] - ext_h[0];
|
float diff = ext_t[1] - ext_h[0];
|
||||||
x_h += diff;
|
LVector3f move = LVector3f::rfu(diff, 0., 0.);
|
||||||
here->set_pos(LVector3f::rfu(x_h, 0., y_h));
|
here->set_pos(pos_h + move);
|
||||||
ext_h = here->get_frame();
|
ext_h = here->get_frame();
|
||||||
|
pos_h = here->get_pos();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -151,7 +152,7 @@ void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to) {
|
|||||||
<< "tried to pack an item relative to something we don't have" << endl;
|
<< "tried to pack an item relative to something we don't have" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(*box).add_link(Connection(rel, (*tobox).get_item()));
|
(*box).add_link(Connection(rel, to));
|
||||||
this->recompute_frame();
|
this->recompute_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,3 +188,21 @@ void GuiFrame::set_pos(const LVector3f& p) {
|
|||||||
GuiItem::set_pos(p);
|
GuiItem::set_pos(p);
|
||||||
this->recompute_frame();
|
this->recompute_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiFrame::output(ostream& os) const {
|
||||||
|
GuiItem::output(os);
|
||||||
|
os << " Frame data:" << endl;
|
||||||
|
Boxes::const_iterator i;
|
||||||
|
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||||
|
os << " box - 0x" << (void*)((*i).get_item()) << endl;
|
||||||
|
int n = (*i).get_num_links();
|
||||||
|
if (n > 0) {
|
||||||
|
for (int j=0; j<n; ++j)
|
||||||
|
os << " linked by " << (*i).get_nth_packing(j) << " to 0x"
|
||||||
|
<< (void*)((*i).get_nth_to(j)) << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||||
|
os << *((*i).get_item());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -68,6 +68,8 @@ public:
|
|||||||
|
|
||||||
virtual void set_scale(float);
|
virtual void set_scale(float);
|
||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
|
virtual void output(ostream&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "guiFrame.I"
|
#include "guiFrame.I"
|
||||||
|
@ -33,3 +33,8 @@ INLINE float GuiItem::get_top(void) const {
|
|||||||
INLINE LVector4f GuiItem::get_frame(void) const {
|
INLINE LVector4f GuiItem::get_frame(void) const {
|
||||||
return LVector4f(_left, _right, _bottom, _top);
|
return LVector4f(_left, _right, _bottom, _top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE ostream& operator<<(ostream& os, GuiItem& item) {
|
||||||
|
item.output(os);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
@ -9,7 +9,9 @@ void GuiItem::recompute_frame(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false),
|
GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false),
|
||||||
_mgr((GuiManager*)0L) {
|
_mgr((GuiManager*)0L), _scale(1.),
|
||||||
|
_pos(0., 0., 0.), _left(-1.),
|
||||||
|
_right(1.), _bottom(-1.), _top(1.) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiItem::~GuiItem(void) {
|
GuiItem::~GuiItem(void) {
|
||||||
@ -30,3 +32,14 @@ void GuiItem::set_scale(float f) {
|
|||||||
void GuiItem::set_pos(const LVector3f& p) {
|
void GuiItem::set_pos(const LVector3f& p) {
|
||||||
_pos = p;
|
_pos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiItem::output(ostream& os) const {
|
||||||
|
os << "GuiItem (0x" << (void*)this << ")" << endl;
|
||||||
|
os << " name - '" << get_name() << "'" << endl;
|
||||||
|
os << " hooks have" << (_added_hooks?" ":" not ") << "been added" << endl;
|
||||||
|
os << " scale - " << _scale << endl;
|
||||||
|
os << " pos - " << _pos << endl;
|
||||||
|
os << " mgr - 0x" << (void*)_mgr << endl;
|
||||||
|
os << " frame - (" << _left << ", " << _right << ", " << _bottom << ", "
|
||||||
|
<< _top << ")" << endl;
|
||||||
|
}
|
||||||
|
@ -36,6 +36,8 @@ public:
|
|||||||
INLINE float get_bottom(void) const;
|
INLINE float get_bottom(void) const;
|
||||||
INLINE float get_top(void) const;
|
INLINE float get_top(void) const;
|
||||||
INLINE LVector4f get_frame(void) const;
|
INLINE LVector4f get_frame(void) const;
|
||||||
|
|
||||||
|
virtual void output(ostream&) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "guiItem.I"
|
#include "guiItem.I"
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE) {
|
INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), _scale(1.),
|
||||||
|
_pos(0., 0., 0.) {
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE Node* GuiLabel::get_geometry(void) const {
|
INLINE Node* GuiLabel::get_geometry(void) const {
|
||||||
|
@ -39,6 +39,9 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font) {
|
|||||||
n->set_align(TM_ALIGN_CENTER);
|
n->set_align(TM_ALIGN_CENTER);
|
||||||
n->set_text_color(1., 1., 1., 1.);
|
n->set_text_color(1., 1., 1., 1.);
|
||||||
n->set_text(text);
|
n->set_text(text);
|
||||||
|
ret->set_scale(1.);
|
||||||
|
ret->set_pos(LVector3f(0., 0., 0.));
|
||||||
|
ret->recompute_transform();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,4 +25,12 @@ INLINE void GuiRegion::trap_clicks(bool t) {
|
|||||||
INLINE void GuiRegion::set_region(float left, float right, float bottom,
|
INLINE void GuiRegion::set_region(float left, float right, float bottom,
|
||||||
float top) {
|
float top) {
|
||||||
_region->set_frame(left, right, bottom, top);
|
_region->set_frame(left, right, bottom, top);
|
||||||
|
_left = left;
|
||||||
|
_right = right;
|
||||||
|
_bottom = bottom;
|
||||||
|
_top = top;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE LVector4f GuiRegion::get_frame(void) const {
|
||||||
|
return LVector4f(_left, _right, _bottom, _top);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
INLINE void trap_clicks(bool);
|
INLINE void trap_clicks(bool);
|
||||||
|
|
||||||
INLINE void set_region(float, float, float, float);
|
INLINE void set_region(float, float, float, float);
|
||||||
|
INLINE LVector4f get_frame(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "guiRegion.I"
|
#include "guiRegion.I"
|
||||||
|
@ -86,3 +86,13 @@ void GuiRollover::set_pos(const LVector3f& p) {
|
|||||||
GuiItem::set_pos(p);
|
GuiItem::set_pos(p);
|
||||||
recompute_frame();
|
recompute_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiRollover::output(ostream& os) const {
|
||||||
|
GuiItem::output(os);
|
||||||
|
os << " Rollover data:" << endl;
|
||||||
|
os << " off - 0x" << (void*)_off << endl;
|
||||||
|
os << " on - 0x" << (void*)_on << endl;
|
||||||
|
os << " region - 0x" << (void*)_rgn << endl;
|
||||||
|
os << " frame - " << _rgn->get_frame() << endl;
|
||||||
|
os << " state - " << _state << endl;
|
||||||
|
}
|
||||||
|
@ -34,6 +34,8 @@ public:
|
|||||||
|
|
||||||
virtual void set_scale(float);
|
virtual void set_scale(float);
|
||||||
virtual void set_pos(const LVector3f&);
|
virtual void set_pos(const LVector3f&);
|
||||||
|
|
||||||
|
virtual void output(ostream&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "guiRollover.I"
|
#include "guiRollover.I"
|
||||||
|
@ -157,6 +157,7 @@ static void setup_gui(void) {
|
|||||||
f1->set_scale(0.1);
|
f1->set_scale(0.1);
|
||||||
f1->set_pos(LVector3f::rfu(0., 0., -0.25));
|
f1->set_pos(LVector3f::rfu(0., 0., -0.25));
|
||||||
f1->manage(mgr, event_handler);
|
f1->manage(mgr, event_handler);
|
||||||
|
cerr << *f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_2(CPT_Event) {
|
static void event_2(CPT_Event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user