mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
fix get/set width/heigh interface
This commit is contained in:
parent
2b36b8e1a6
commit
c5a1d30385
@ -36,6 +36,9 @@ INLINE void GuiLabel::set_width(float f) {
|
|||||||
_width = 0.;
|
_width = 0.;
|
||||||
} else {
|
} else {
|
||||||
_have_width = true;
|
_have_width = true;
|
||||||
|
if (_type == MODEL)
|
||||||
|
_width = f / _model_width;
|
||||||
|
else
|
||||||
_width = f;
|
_width = f;
|
||||||
}
|
}
|
||||||
this->set_properties();
|
this->set_properties();
|
||||||
@ -47,6 +50,9 @@ INLINE void GuiLabel::set_height(float f) {
|
|||||||
_height = 0.;
|
_height = 0.;
|
||||||
} else {
|
} else {
|
||||||
_have_height = true;
|
_have_height = true;
|
||||||
|
if (_type == MODEL)
|
||||||
|
_height = f / _model_height;
|
||||||
|
else
|
||||||
_height = f;
|
_height = f;
|
||||||
}
|
}
|
||||||
this->set_properties();
|
this->set_properties();
|
||||||
|
@ -363,25 +363,63 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
|
|||||||
|
|
||||||
float GuiLabel::get_width(void) {
|
float GuiLabel::get_width(void) {
|
||||||
float w;
|
float w;
|
||||||
|
switch (_type) {
|
||||||
|
case SIMPLE_TEXT:
|
||||||
|
{
|
||||||
TextNode* n = DCAST(TextNode, _geom);
|
TextNode* n = DCAST(TextNode, _geom);
|
||||||
if (n->has_card()) {
|
if (n->has_card()) {
|
||||||
LVecBase4f v = n->get_card_actual();
|
LVecBase4f v = n->get_card_actual();
|
||||||
w = v[1] - v[0];
|
w = v[1] - v[0];
|
||||||
} else {
|
} else
|
||||||
w = n->get_width();
|
w = n->get_width();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case SIMPLE_TEXTURE:
|
||||||
|
gui_cat->warning() << "tried to get width from a texture label" << endl;
|
||||||
|
w = 1.;
|
||||||
|
break;
|
||||||
|
case SIMPLE_CARD:
|
||||||
|
w = _have_width?_width:1.;
|
||||||
|
break;
|
||||||
|
case MODEL:
|
||||||
|
w = _have_width?(_width*_model_width):_model_width;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gui_cat->warning()
|
||||||
|
<< "trying to get width from something I don't know how to" << endl;
|
||||||
|
w = 1.;
|
||||||
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GuiLabel::get_height(void) {
|
float GuiLabel::get_height(void) {
|
||||||
float h;
|
float h;
|
||||||
|
switch (_type) {
|
||||||
|
case SIMPLE_TEXT:
|
||||||
|
{
|
||||||
TextNode* n = DCAST(TextNode, _geom);
|
TextNode* n = DCAST(TextNode, _geom);
|
||||||
if (n->has_card()) {
|
if (n->has_card()) {
|
||||||
LVecBase4f v = n->get_card_actual();
|
LVecBase4f v = n->get_card_actual();
|
||||||
h = v[3] - v[2];
|
h = v[3] - v[2];
|
||||||
} else {
|
} else
|
||||||
h = n->get_width();
|
h = n->get_width();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case SIMPLE_TEXTURE:
|
||||||
|
gui_cat->warning() << "tried to get height from a texture label" << endl;
|
||||||
|
h = 1.;
|
||||||
|
break;
|
||||||
|
case SIMPLE_CARD:
|
||||||
|
h = _have_height?_height:1.;
|
||||||
|
break;
|
||||||
|
case MODEL:
|
||||||
|
h = _have_height?(_height*_model_height):_model_height;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gui_cat->warning()
|
||||||
|
<< "trying to get height from something I don't know how to" << endl;
|
||||||
|
h = 1.;
|
||||||
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user