Browse Source

add mirroring and fix set_width/height for model labels

Cary Sandvig 25 years ago
parent
commit
bded9a817d
3 changed files with 37 additions and 2 deletions
  1. 25 2
      panda/src/gui/guiLabel.I
  2. 6 0
      panda/src/gui/guiLabel.cxx
  3. 6 0
      panda/src/gui/guiLabel.h

+ 25 - 2
panda/src/gui/guiLabel.I

@@ -15,6 +15,7 @@ INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE),
 				  _background(0., 0., 0., 0.),
 				  _background(0., 0., 0., 0.),
 				  _have_width(false), _width(0.),
 				  _have_width(false), _width(0.),
 				  _have_height(false), _height(0.),
 				  _have_height(false), _height(0.),
+				  _mirror_x(false), _mirror_y(false),
 				  _hard_pri(0), _highest_pri(false) {
 				  _hard_pri(0), _highest_pri(false) {
 }
 }
 
 
@@ -35,8 +36,11 @@ INLINE void GuiLabel::set_width(float f) {
     _have_width = false;
     _have_width = false;
     _width = 0.;
     _width = 0.;
   } else {
   } else {
+    if (_type == MODEL)
+      _width = f / this->get_width();
+    else
+      _width = f;
     _have_width = true;
     _have_width = true;
-    _width = f;
   }
   }
   this->set_properties();
   this->set_properties();
 }
 }
@@ -46,8 +50,11 @@ INLINE void GuiLabel::set_height(float f) {
     _have_height = false;
     _have_height = false;
     _height = 0.;
     _height = 0.;
   } else {
   } else {
+    if (_type == MODEL)
+      _height = f / this->get_height();
+    else
+      _height = f;
     _have_height = true;
     _have_height = true;
-    _height = f;
   }
   }
   this->set_properties();
   this->set_properties();
 }
 }
@@ -57,6 +64,14 @@ INLINE void GuiLabel::set_scale(float f) {
   recompute_transform();
   recompute_transform();
 }
 }
 
 
+INLINE void GuiLabel::set_mirror_x(bool b) {
+  _mirror_x = b;
+}
+
+INLINE void GuiLabel::set_mirror_y(bool b) {
+  _mirror_y = b;
+}
+
 INLINE void GuiLabel::set_pos(float x, float y, float z) {
 INLINE void GuiLabel::set_pos(float x, float y, float z) {
   this->set_pos(LVector3f(x, y, z));
   this->set_pos(LVector3f(x, y, z));
 }
 }
@@ -70,6 +85,14 @@ INLINE float GuiLabel::get_scale(void) const {
   return _scale;
   return _scale;
 }
 }
 
 
+INLINE bool GuiLabel::get_mirror_x(void) const {
+  return _mirror_x;
+}
+
+INLINE bool GuiLabel::get_mirror_y(void) const {
+  return _mirror_y;
+}
+
 INLINE LVector3f GuiLabel::get_pos(void) const {
 INLINE LVector3f GuiLabel::get_pos(void) const {
   return _pos;
   return _pos;
 }
 }

+ 6 - 0
panda/src/gui/guiLabel.cxx

@@ -16,6 +16,8 @@ void GuiLabel::recompute_transform(void) {
   case SIMPLE_TEXT:
   case SIMPLE_TEXT:
     {
     {
       LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
       LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
+	LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
+					    (_mirror_y?-1.:1.))) *
 	LMatrix4f::translate_mat(_pos);
 	LMatrix4f::translate_mat(_pos);
       TextNode* n = DCAST(TextNode, _geom);
       TextNode* n = DCAST(TextNode, _geom);
       n->set_transform(mat);
       n->set_transform(mat);
@@ -25,6 +27,8 @@ void GuiLabel::recompute_transform(void) {
   case SIMPLE_CARD:
   case SIMPLE_CARD:
     {
     {
       LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
       LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
+	LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
+					    (_mirror_y?-1.:1.))) *
 	LMatrix4f::translate_mat(_pos);
 	LMatrix4f::translate_mat(_pos);
       _internal->set_transition(new TransformTransition(mat));
       _internal->set_transition(new TransformTransition(mat));
     }
     }
@@ -34,6 +38,8 @@ void GuiLabel::recompute_transform(void) {
       float w=_have_width?_scale*_width:_scale;
       float w=_have_width?_scale*_width:_scale;
       float h=_have_height?_scale*_height:_scale;
       float h=_have_height?_scale*_height:_scale;
       LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(w, 1., h)) *
       LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(w, 1., h)) *
+	LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
+					    (_mirror_y?-1.:1.))) *
 	LMatrix4f::translate_mat(_pos);
 	LMatrix4f::translate_mat(_pos);
       _internal->set_transition(new TransformTransition(mat));
       _internal->set_transition(new TransformTransition(mat));
     }
     }

+ 6 - 0
panda/src/gui/guiLabel.h

@@ -44,6 +44,8 @@ private:
   float _width;
   float _width;
   bool _have_height;
   bool _have_height;
   float _height;
   float _height;
+  bool _mirror_x;
+  bool _mirror_y;
 
 
   PriorityMap _priorities;
   PriorityMap _priorities;
   int _hard_pri;
   int _hard_pri;
@@ -79,10 +81,14 @@ PUBLISHED:
   INLINE void set_height(float);
   INLINE void set_height(float);
 
 
   INLINE void set_scale(float);
   INLINE void set_scale(float);
+  INLINE void set_mirror_x(bool);
+  INLINE void set_mirror_y(bool);
   INLINE void set_pos(float, float, float);
   INLINE void set_pos(float, float, float);
   INLINE void set_pos(const LVector3f&);
   INLINE void set_pos(const LVector3f&);
 
 
   INLINE float get_scale(void) const;
   INLINE float get_scale(void) const;
+  INLINE bool get_mirror_x(void) const;
+  INLINE bool get_mirror_y(void) const;
   INLINE LVector3f get_pos(void) const;
   INLINE LVector3f get_pos(void) const;
 
 
   INLINE void set_foreground_color(float, float, float, float);
   INLINE void set_foreground_color(float, float, float, float);