mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
whee stuff
This commit is contained in:
parent
5181ac7b13
commit
248a1af942
@ -9,10 +9,21 @@
|
||||
TypeHandle GuiBackground::_type_handle;
|
||||
|
||||
void GuiBackground::recompute_frame(void) {
|
||||
_item->recompute();
|
||||
_bg->recompute();
|
||||
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) {
|
||||
@ -23,6 +34,8 @@ void GuiBackground::manage(GuiManager* mgr, EventHandler& eh) {
|
||||
if (!_added_hooks)
|
||||
_added_hooks = true;
|
||||
if (_mgr == (GuiManager*)0L) {
|
||||
_mgr->add_label(_bg);
|
||||
_item->manage(mgr, eh);
|
||||
GuiItem::manage(mgr, eh);
|
||||
} else
|
||||
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) {
|
||||
if (_mgr != (GuiManager*)0L) {
|
||||
_mgr->remove_label(_bg);
|
||||
_item->unmanage();
|
||||
}
|
||||
GuiItem::unmanage();
|
||||
}
|
||||
|
||||
int GuiBackground::freeze(void) {
|
||||
return 0;
|
||||
return _item->freeze();
|
||||
}
|
||||
|
||||
int GuiBackground::thaw(void) {
|
||||
return 0;
|
||||
return _item->thaw();
|
||||
}
|
||||
|
||||
void GuiBackground::set_scale(float f) {
|
||||
_bg->set_scale(f);
|
||||
_item->set_scale(f);
|
||||
GuiItem::set_scale(f);
|
||||
recompute_frame();
|
||||
}
|
||||
|
||||
void GuiBackground::set_pos(const LVector3f& p) {
|
||||
_bg->set_pos(p);
|
||||
_item->set_pos(p);
|
||||
GuiItem::set_pos(p);
|
||||
recompute_frame();
|
||||
}
|
||||
@ -54,6 +75,7 @@ void GuiBackground::set_pos(const LVector3f& p) {
|
||||
void GuiBackground::output(ostream& os) const {
|
||||
GuiItem::output(os);
|
||||
os << " Background data:" << endl;
|
||||
os << " item - 0x" << (void*)0L << endl;
|
||||
// then output the item
|
||||
os << " bg - 0x" << (void*)_bg << endl;
|
||||
os << " item - 0x" << (void*)_item << endl;
|
||||
os << *_item;
|
||||
}
|
||||
|
@ -11,10 +11,14 @@
|
||||
|
||||
class EXPCL_PANDA GuiBackground : public GuiItem {
|
||||
private:
|
||||
PT(GuiLabel) _bg;
|
||||
PT(GuiItem) _item;
|
||||
|
||||
INLINE GuiBackground(void);
|
||||
virtual void recompute_frame(void);
|
||||
PUBLISHED:
|
||||
GuiBackground(const string&);
|
||||
GuiBackground(const string&, GuiItem*);
|
||||
GuiBackground(const string&, GuiItem*, Texture*);
|
||||
~GuiBackground(void);
|
||||
|
||||
virtual void manage(GuiManager*, EventHandler&);
|
||||
|
@ -6,13 +6,15 @@
|
||||
INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE),
|
||||
_arc((RenderRelation*)0L),
|
||||
_tex((Texture*)0L),
|
||||
_internal((RenderRelation*)0L), _scale(1.),
|
||||
_internal((RenderRelation*)0L),
|
||||
_gset((Geom*)0L), _scale(1.),
|
||||
_pos(0., 0., 0.),
|
||||
_foreground(1., 1., 1., 1.),
|
||||
_have_background(false),
|
||||
_background(0., 0., 0., 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 {
|
||||
@ -63,6 +65,18 @@ INLINE void GuiLabel::set_pos(const LVector3f& p) {
|
||||
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 {
|
||||
return _scale;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ void GuiLabel::recompute_transform(void) {
|
||||
}
|
||||
break;
|
||||
case SIMPLE_TEXTURE:
|
||||
case SIMPLE_CARD:
|
||||
{
|
||||
LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
|
||||
LMatrix4f::translate_mat(_pos);
|
||||
@ -85,6 +86,20 @@ void GuiLabel::set_properties(void) {
|
||||
case SIMPLE_TEXTURE:
|
||||
_internal->set_transition(new ColorTransition(_foreground));
|
||||
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:
|
||||
gui_cat->warning() << "recompute_transform on invalid label type ("
|
||||
<< (int)_type << ")" << endl;
|
||||
@ -150,6 +165,7 @@ GuiLabel* GuiLabel::make_simple_texture_label(Texture* texture) {
|
||||
uvs.push_back(TexCoordf(1., 0.));
|
||||
geoset->set_texcoords(uvs, G_PER_VERTEX);
|
||||
n2->add_geom(geoset);
|
||||
ret->_gset = geoset;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -176,6 +192,30 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font,
|
||||
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() {
|
||||
switch (_type) {
|
||||
case SIMPLE_TEXT:
|
||||
@ -255,6 +295,14 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
|
||||
t = ul.dot(ul.up());
|
||||
}
|
||||
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:
|
||||
gui_cat->warning()
|
||||
<< "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:
|
||||
gui_cat->warning() << "tried to set text on a texture label" << endl;
|
||||
break;
|
||||
case SIMPLE_CARD:
|
||||
gui_cat->warning() << "tried to set text on a card label" << endl;
|
||||
break;
|
||||
default:
|
||||
gui_cat->warning() << "trying to set text on an unknown label type ("
|
||||
<< (int)_type << ")" << endl;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <renderRelation.h>
|
||||
#include <texture.h>
|
||||
#include <typedReferenceCount.h>
|
||||
#include <geom.h>
|
||||
|
||||
// label-ish behavior for GUI objects (labels, buttons, rollovers)
|
||||
|
||||
@ -21,12 +22,13 @@ class GuiManager;
|
||||
|
||||
class EXPCL_PANDA GuiLabel : public TypedReferenceCount {
|
||||
private:
|
||||
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT };
|
||||
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT, SIMPLE_CARD };
|
||||
LabelType _type;
|
||||
PT_Node _geom;
|
||||
RenderRelation* _arc;
|
||||
PT(Texture) _tex;
|
||||
RenderRelation* _internal;
|
||||
Geom* _gset;
|
||||
|
||||
float _scale;
|
||||
LVector3f _pos;
|
||||
@ -37,6 +39,7 @@ private:
|
||||
float _width;
|
||||
bool _have_height;
|
||||
float _height;
|
||||
float _depth;
|
||||
|
||||
INLINE Node* get_geometry(void) const;
|
||||
INLINE void set_arc(RenderRelation*);
|
||||
@ -54,6 +57,7 @@ PUBLISHED:
|
||||
static GuiLabel* make_simple_texture_label(Texture*);
|
||||
static GuiLabel* make_simple_text_label(const string&, Node*,
|
||||
Texture* = (Texture*)0L);
|
||||
static GuiLabel* make_simple_card_label(void);
|
||||
|
||||
int freeze();
|
||||
int thaw();
|
||||
@ -61,6 +65,7 @@ PUBLISHED:
|
||||
void get_extents(float&, float&, float&, float&);
|
||||
float get_width(void);
|
||||
float get_height(void);
|
||||
INLINE float get_depth(void) const;
|
||||
|
||||
INLINE void set_width(float);
|
||||
INLINE void set_height(float);
|
||||
@ -68,6 +73,7 @@ PUBLISHED:
|
||||
INLINE void set_scale(float);
|
||||
INLINE void set_pos(float, float, float);
|
||||
INLINE void set_pos(const LVector3f&);
|
||||
INLINE void set_depth(float);
|
||||
|
||||
INLINE float get_scale(void) const;
|
||||
INLINE LVector3f get_pos(void) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user