whee stuff

This commit is contained in:
Cary Sandvig 2001-02-07 01:34:05 +00:00
parent 5181ac7b13
commit 248a1af942
5 changed files with 106 additions and 9 deletions

View File

@ -9,10 +9,21 @@
TypeHandle GuiBackground::_type_handle; TypeHandle GuiBackground::_type_handle;
void GuiBackground::recompute_frame(void) { void GuiBackground::recompute_frame(void) {
_item->recompute();
_bg->recompute();
GuiItem::recompute_frame(); GuiItem::recompute_frame();
} }
GuiBackground::GuiBackground(const string& name) : GuiItem(name) { GuiBackground::GuiBackground(const string& name, GuiItem* item)
: GuiItem(name), _item(item) {
_bg = GuiLabel::make_simple_card_label();
_bg->set_depth(0.1);
}
GuiBackground::GuiBackground(const string& name, GuiItem* item, Texture* tex)
: GuiItem(name), _item(item) {
_bg = GuiLabel::make_simple_texture_label(tex);
_bg->set_depth(0.1);
} }
GuiBackground::~GuiBackground(void) { GuiBackground::~GuiBackground(void) {
@ -23,6 +34,8 @@ void GuiBackground::manage(GuiManager* mgr, EventHandler& eh) {
if (!_added_hooks) if (!_added_hooks)
_added_hooks = true; _added_hooks = true;
if (_mgr == (GuiManager*)0L) { if (_mgr == (GuiManager*)0L) {
_mgr->add_label(_bg);
_item->manage(mgr, eh);
GuiItem::manage(mgr, eh); GuiItem::manage(mgr, eh);
} else } else
gui_cat->warning() << "tried to manage background (0x" << (void*)this gui_cat->warning() << "tried to manage background (0x" << (void*)this
@ -30,23 +43,31 @@ void GuiBackground::manage(GuiManager* mgr, EventHandler& eh) {
} }
void GuiBackground::unmanage(void) { void GuiBackground::unmanage(void) {
if (_mgr != (GuiManager*)0L) {
_mgr->remove_label(_bg);
_item->unmanage();
}
GuiItem::unmanage(); GuiItem::unmanage();
} }
int GuiBackground::freeze(void) { int GuiBackground::freeze(void) {
return 0; return _item->freeze();
} }
int GuiBackground::thaw(void) { int GuiBackground::thaw(void) {
return 0; return _item->thaw();
} }
void GuiBackground::set_scale(float f) { void GuiBackground::set_scale(float f) {
_bg->set_scale(f);
_item->set_scale(f);
GuiItem::set_scale(f); GuiItem::set_scale(f);
recompute_frame(); recompute_frame();
} }
void GuiBackground::set_pos(const LVector3f& p) { void GuiBackground::set_pos(const LVector3f& p) {
_bg->set_pos(p);
_item->set_pos(p);
GuiItem::set_pos(p); GuiItem::set_pos(p);
recompute_frame(); recompute_frame();
} }
@ -54,6 +75,7 @@ void GuiBackground::set_pos(const LVector3f& p) {
void GuiBackground::output(ostream& os) const { void GuiBackground::output(ostream& os) const {
GuiItem::output(os); GuiItem::output(os);
os << " Background data:" << endl; os << " Background data:" << endl;
os << " item - 0x" << (void*)0L << endl; os << " bg - 0x" << (void*)_bg << endl;
// then output the item os << " item - 0x" << (void*)_item << endl;
os << *_item;
} }

View File

@ -11,10 +11,14 @@
class EXPCL_PANDA GuiBackground : public GuiItem { class EXPCL_PANDA GuiBackground : public GuiItem {
private: private:
PT(GuiLabel) _bg;
PT(GuiItem) _item;
INLINE GuiBackground(void); INLINE GuiBackground(void);
virtual void recompute_frame(void); virtual void recompute_frame(void);
PUBLISHED: PUBLISHED:
GuiBackground(const string&); GuiBackground(const string&, GuiItem*);
GuiBackground(const string&, GuiItem*, Texture*);
~GuiBackground(void); ~GuiBackground(void);
virtual void manage(GuiManager*, EventHandler&); virtual void manage(GuiManager*, EventHandler&);

View File

@ -6,13 +6,15 @@
INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE),
_arc((RenderRelation*)0L), _arc((RenderRelation*)0L),
_tex((Texture*)0L), _tex((Texture*)0L),
_internal((RenderRelation*)0L), _scale(1.), _internal((RenderRelation*)0L),
_gset((Geom*)0L), _scale(1.),
_pos(0., 0., 0.), _pos(0., 0., 0.),
_foreground(1., 1., 1., 1.), _foreground(1., 1., 1., 1.),
_have_background(false), _have_background(false),
_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.),
_depth(0.) {
} }
INLINE Node* GuiLabel::get_geometry(void) const { INLINE Node* GuiLabel::get_geometry(void) const {
@ -63,6 +65,18 @@ INLINE void GuiLabel::set_pos(const LVector3f& p) {
recompute_transform(); recompute_transform();
} }
INLINE void GuiLabel::set_depth(float x) {
float r = _pos.dot(_pos.right());
float u = _pos.dot(_pos.up());
_pos = LVector3f::rfu(r, x, u);
_depth = x;
recompute_transform();
}
INLINE float GuiLabel::get_depth(void) const {
return _pos.dot(_pos.forward());
}
INLINE float GuiLabel::get_scale(void) const { INLINE float GuiLabel::get_scale(void) const {
return _scale; return _scale;
} }

View File

@ -22,6 +22,7 @@ void GuiLabel::recompute_transform(void) {
} }
break; break;
case SIMPLE_TEXTURE: case SIMPLE_TEXTURE:
case SIMPLE_CARD:
{ {
LMatrix4f mat = LMatrix4f::scale_mat(_scale) * LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
LMatrix4f::translate_mat(_pos); LMatrix4f::translate_mat(_pos);
@ -85,6 +86,20 @@ void GuiLabel::set_properties(void) {
case SIMPLE_TEXTURE: case SIMPLE_TEXTURE:
_internal->set_transition(new ColorTransition(_foreground)); _internal->set_transition(new ColorTransition(_foreground));
break; break;
case SIMPLE_CARD:
_internal->set_transition(new ColorTransition(_foreground));
{
float w, h;
w = _have_width?(_width * 0.5):0.5;
h = _have_height?(_height * 0.5):0.5;
PTA_Vertexf verts;
verts.push_back(Vertexf::rfu(-w, 0., h));
verts.push_back(Vertexf::rfu(-w, 0., -h));
verts.push_back(Vertexf::rfu(w, 0., h));
verts.push_back(Vertexf::rfu(w, 0., -h));
_gset->set_coords(verts, G_PER_VERTEX);
}
break;
default: default:
gui_cat->warning() << "recompute_transform on invalid label type (" gui_cat->warning() << "recompute_transform on invalid label type ("
<< (int)_type << ")" << endl; << (int)_type << ")" << endl;
@ -150,6 +165,7 @@ GuiLabel* GuiLabel::make_simple_texture_label(Texture* texture) {
uvs.push_back(TexCoordf(1., 0.)); uvs.push_back(TexCoordf(1., 0.));
geoset->set_texcoords(uvs, G_PER_VERTEX); geoset->set_texcoords(uvs, G_PER_VERTEX);
n2->add_geom(geoset); n2->add_geom(geoset);
ret->_gset = geoset;
return ret; return ret;
} }
@ -176,6 +192,30 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font,
return ret; return ret;
} }
GuiLabel* GuiLabel::make_simple_card_label(void) {
GuiLabel* ret = new GuiLabel();
ret->_type = SIMPLE_CARD;
ret->_geom = new NamedNode("GUI label");
GeomNode* n2 = new GeomNode();
ret->_internal = new RenderRelation(ret->_geom, n2);
ret->_internal->set_transition(
new ColorTransition(Colorf(ret->_foreground)));
GeomTristrip *geoset = new GeomTristrip;
PTA_int lengths(0);
lengths.push_back(4);
PTA_Vertexf verts;
verts.push_back(Vertexf::rfu(-0.5, 0., 0.5));
verts.push_back(Vertexf::rfu(-0.5, 0., -0.5));
verts.push_back(Vertexf::rfu(0.5, 0., 0.5));
verts.push_back(Vertexf::rfu(0.5, 0., -0.5));
geoset->set_num_prims(1);
geoset->set_lengths(lengths);
geoset->set_coords(verts, G_PER_VERTEX);
n2->add_geom(geoset);
ret->_gset = geoset;
return ret;
}
int GuiLabel::freeze() { int GuiLabel::freeze() {
switch (_type) { switch (_type) {
case SIMPLE_TEXT: case SIMPLE_TEXT:
@ -255,6 +295,14 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
t = ul.dot(ul.up()); t = ul.dot(ul.up());
} }
break; break;
case SIMPLE_CARD:
{
l = _have_width?-(_width*0.5):-0.5;
r = _have_width?(_width*0.5):0.5;
b = _have_height?-(_height*0.5):-0.5;
t = _have_height?(_height*0.5):0.5;
}
break;
default: default:
gui_cat->warning() gui_cat->warning()
<< "trying to get extents from something I don't know how to" << endl; << "trying to get extents from something I don't know how to" << endl;
@ -311,6 +359,9 @@ void GuiLabel::set_text(const string& val) {
case SIMPLE_TEXTURE: case SIMPLE_TEXTURE:
gui_cat->warning() << "tried to set text on a texture label" << endl; gui_cat->warning() << "tried to set text on a texture label" << endl;
break; break;
case SIMPLE_CARD:
gui_cat->warning() << "tried to set text on a card label" << endl;
break;
default: default:
gui_cat->warning() << "trying to set text on an unknown label type (" gui_cat->warning() << "trying to set text on an unknown label type ("
<< (int)_type << ")" << endl; << (int)_type << ")" << endl;

View File

@ -14,6 +14,7 @@
#include <renderRelation.h> #include <renderRelation.h>
#include <texture.h> #include <texture.h>
#include <typedReferenceCount.h> #include <typedReferenceCount.h>
#include <geom.h>
// label-ish behavior for GUI objects (labels, buttons, rollovers) // label-ish behavior for GUI objects (labels, buttons, rollovers)
@ -21,12 +22,13 @@ class GuiManager;
class EXPCL_PANDA GuiLabel : public TypedReferenceCount { class EXPCL_PANDA GuiLabel : public TypedReferenceCount {
private: private:
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT }; enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT, SIMPLE_CARD };
LabelType _type; LabelType _type;
PT_Node _geom; PT_Node _geom;
RenderRelation* _arc; RenderRelation* _arc;
PT(Texture) _tex; PT(Texture) _tex;
RenderRelation* _internal; RenderRelation* _internal;
Geom* _gset;
float _scale; float _scale;
LVector3f _pos; LVector3f _pos;
@ -37,6 +39,7 @@ private:
float _width; float _width;
bool _have_height; bool _have_height;
float _height; float _height;
float _depth;
INLINE Node* get_geometry(void) const; INLINE Node* get_geometry(void) const;
INLINE void set_arc(RenderRelation*); INLINE void set_arc(RenderRelation*);
@ -54,6 +57,7 @@ PUBLISHED:
static GuiLabel* make_simple_texture_label(Texture*); static GuiLabel* make_simple_texture_label(Texture*);
static GuiLabel* make_simple_text_label(const string&, Node*, static GuiLabel* make_simple_text_label(const string&, Node*,
Texture* = (Texture*)0L); Texture* = (Texture*)0L);
static GuiLabel* make_simple_card_label(void);
int freeze(); int freeze();
int thaw(); int thaw();
@ -61,6 +65,7 @@ PUBLISHED:
void get_extents(float&, float&, float&, float&); void get_extents(float&, float&, float&, float&);
float get_width(void); float get_width(void);
float get_height(void); float get_height(void);
INLINE float get_depth(void) const;
INLINE void set_width(float); INLINE void set_width(float);
INLINE void set_height(float); INLINE void set_height(float);
@ -68,6 +73,7 @@ PUBLISHED:
INLINE void set_scale(float); INLINE void set_scale(float);
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 void set_depth(float);
INLINE float get_scale(void) const; INLINE float get_scale(void) const;
INLINE LVector3f get_pos(void) const; INLINE LVector3f get_pos(void) const;