texture label support

This commit is contained in:
Cary Sandvig 2000-11-06 22:59:30 +00:00
parent d2e0d89785
commit 7ecb711db6
3 changed files with 99 additions and 4 deletions

View File

@ -4,7 +4,9 @@
////////////////////////////////////////////////////////////////////
INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), _scale(1.),
_pos(0., 0., 0.) {
_pos(0., 0., 0.), _tex((Texture*)0L),
_arc((RenderRelation*)0L),
_internal((RenderRelation*)0L) {
}
INLINE Node* GuiLabel::get_geometry(void) const {

View File

@ -6,6 +6,7 @@
#include "guiLabel.h"
#include <textNode.h>
#include <transformTransition.h>
void GuiLabel::recompute_transform(void) {
switch (_type) {
@ -17,6 +18,13 @@ void GuiLabel::recompute_transform(void) {
n->set_transform(mat);
}
break;
case SIMPLE_TEXTURE:
{
LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
LMatrix4f::translate_mat(_pos);
_internal->set_transition(new TransformTransition(mat));
}
break;
default:
gui_cat->warning() << "recompute_transform on invalid label type ("
<< _type << ")" << endl;
@ -26,8 +34,60 @@ void GuiLabel::recompute_transform(void) {
GuiLabel::~GuiLabel(void) {
}
GuiLabel* GuiLabel::make_simple_texture_label(void) {
return new GuiLabel();
#include <textureTransition.h>
#include <geomTristrip.h>
GuiLabel* GuiLabel::make_simple_texture_label(Texture* texture) {
GuiLabel* ret = new GuiLabel();
ret->_type = SIMPLE_TEXTURE;
ret->_tex = texture;
ret->_geom = new NamedNode("GUI label");
GeomNode* n2 = new GeomNode();
ret->_internal = new RenderRelation(ret->_geom, n2);
ret->_internal->set_transition(new TextureTransition(texture));
GeomTristrip *geoset = new GeomTristrip;
PTA_int lengths(0);
lengths.push_back(4);
PTA_Vertexf verts;
float l, r, b, t;
{
// compute {l, r, b, t}
int xs = texture->_pbuffer->get_xsize();
int ys = texture->_pbuffer->get_ysize();
float ratio;
if (xs > ys) {
// horizontally dominant
ratio = ((float)ys) / ((float)xs);
ratio *= 0.5;
l = -0.5;
r = 0.5;
b = -ratio;
t = ratio;
} else {
// vertically dominant
ratio = ((float)xs) / ((float)ys);
ratio *= 0.5;
l = -ratio;
r = ratio;
b = -0.5;
t = 0.5;
}
}
verts.push_back(Vertexf::rfu(l, 0., t));
verts.push_back(Vertexf::rfu(l, 0., b));
verts.push_back(Vertexf::rfu(r, 0., t));
verts.push_back(Vertexf::rfu(r, 0., b));
geoset->set_num_prims(1);
geoset->set_lengths(lengths);
geoset->set_coords(verts, G_PER_VERTEX);
PTA_TexCoordf uvs;
uvs.push_back(TexCoordf(0., 1.));
uvs.push_back(TexCoordf(0., 0.));
uvs.push_back(TexCoordf(1., 1.));
uvs.push_back(TexCoordf(1., 0.));
geoset->set_texcoords(uvs, G_PER_VERTEX);
n2->add_geom(geoset);
}
GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font) {
@ -60,6 +120,36 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
t = ul.dot(up);
}
break;
case SIMPLE_TEXTURE:
{
float xs = _tex->_pbuffer->get_xsize();
float ys = _tex->_pbuffer->get_ysize();
float ratio;
LVector3f ul, lr;
if (xs > ys) {
// horizontally dominant
ratio = ((float)ys) / ((float)xs);
ratio *= 0.5;
ul = LVector3f::rfu(-0.5, 0., ratio);
lr = LVector3f::rfu(0.5, 0., -ratio);
} else {
// vertically dominant
ratio = ((float)xs) / ((float)ys);
ratio *= 0.5;
ul = LVector3f::rfu(-ratio, 0., 0.5);
lr = LVector3f::rfu(ratio, 0., -0.5);
}
LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
LMatrix4f::translate_mat(_pos);
ul = mat * ul;
lr = mat * lr;
l = ul.dot(ul.right());
r = lr.dot(lr.right());
b = lr.dot(lr.up());
t = ul.dot(ul.up());
}
break;
default:
gui_cat->warning()
<< "trying to get extents from something I don't know how to" << endl;

View File

@ -12,6 +12,7 @@
#include <node.h>
#include <pt_Node.h>
#include <renderRelation.h>
#include <texture.h>
// label-ish behavior for GUI objects (labels, buttons, rollovers)
@ -23,6 +24,8 @@ private:
LabelType _type;
PT_Node _geom;
RenderRelation* _arc;
Texture* _tex;
RenderRelation* _internal;
float _scale;
LVector3f _pos;
@ -38,7 +41,7 @@ public:
INLINE GuiLabel(void);
virtual ~GuiLabel(void);
static GuiLabel* make_simple_texture_label(void);
static GuiLabel* make_simple_texture_label(Texture*);
static GuiLabel* make_simple_text_label(const string&, Node*);
void get_extents(float&, float&, float&, float&);