mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 16:20:11 -04:00
add position and scale setting
This commit is contained in:
parent
65b5240293
commit
9a24491c0e
@ -157,3 +157,37 @@ INLINE const string& GuiButton::get_down_rollover_event(void) const {
|
||||
INLINE const string& GuiButton::get_inactive_event(void) const {
|
||||
return _inactive_event;
|
||||
}
|
||||
|
||||
INLINE void GuiButton::set_scale(float f) {
|
||||
_up->set_scale(f);
|
||||
_down->set_scale(f);
|
||||
if (_up_rollover != (GuiLabel*)0L)
|
||||
_up_rollover->set_scale(f);
|
||||
if (_down_rollover != (GuiLabel*)0L)
|
||||
_down_rollover->set_scale(f);
|
||||
if (_inactive != (GuiLabel*)0L)
|
||||
_inactive->set_scale(f);
|
||||
_scale = f;
|
||||
recompute_frame();
|
||||
}
|
||||
|
||||
INLINE void GuiButton::set_pos(const LVector3f& p) {
|
||||
_up->set_pos(p);
|
||||
_down->set_pos(p);
|
||||
if (_up_rollover != (GuiLabel*)0L)
|
||||
_up_rollover->set_pos(p);
|
||||
if (_down_rollover != (GuiLabel*)0L)
|
||||
_down_rollover->set_pos(p);
|
||||
if (_inactive != (GuiLabel*)0L)
|
||||
_inactive->set_pos(p);
|
||||
_pos = p;
|
||||
recompute_frame();
|
||||
}
|
||||
|
||||
INLINE float GuiButton::get_scale(void) const {
|
||||
return _scale;
|
||||
}
|
||||
|
||||
INLINE LVector3f GuiButton::get_pos(void) const {
|
||||
return _pos;
|
||||
}
|
||||
|
@ -155,6 +155,14 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
}
|
||||
}
|
||||
|
||||
void GuiButton::recompute_frame(void) {
|
||||
float left, right, bottom, top;
|
||||
|
||||
GetExtents(_up, _down, _up_rollover, _down_rollover, _inactive, left, right,
|
||||
bottom, top);
|
||||
_rgn->set_region(left, right, bottom, top);
|
||||
}
|
||||
|
||||
GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* up_roll,
|
||||
GuiLabel* down, GuiLabel* down_roll, GuiLabel* inactive)
|
||||
: Namable(name), _up(up), _up_rollover(up_roll), _down(down),
|
||||
|
@ -27,10 +27,13 @@ private:
|
||||
INACTIVE_ROLLOVER };
|
||||
States _state;
|
||||
bool _added_hooks;
|
||||
float _scale;
|
||||
LVector3f _pos;
|
||||
GuiManager* _mgr;
|
||||
|
||||
INLINE GuiButton(void);
|
||||
void switch_state(States);
|
||||
void recompute_frame(void);
|
||||
public:
|
||||
GuiButton(const string&, GuiLabel*, GuiLabel*, GuiLabel*, GuiLabel*,
|
||||
GuiLabel*);
|
||||
@ -60,6 +63,12 @@ public:
|
||||
INLINE const string& get_down_event(void) const;
|
||||
INLINE const string& get_down_rollover_event(void) const;
|
||||
INLINE const string& get_inactive_event(void) const;
|
||||
|
||||
INLINE void set_scale(float);
|
||||
INLINE void set_pos(const LVector3f&);
|
||||
|
||||
INLINE float get_scale(void) const;
|
||||
INLINE LVector3f get_pos(void) const;
|
||||
};
|
||||
|
||||
#include "guiButton.I"
|
||||
|
@ -17,3 +17,21 @@ INLINE void GuiLabel::set_arc(RenderRelation* r) {
|
||||
INLINE RenderRelation* GuiLabel::get_arc(void) const {
|
||||
return _arc;
|
||||
}
|
||||
|
||||
INLINE void GuiLabel::set_scale(float f) {
|
||||
_scale = f;
|
||||
recompute_transform();
|
||||
}
|
||||
|
||||
INLINE void GuiLabel::set_pos(const LVector3f& p) {
|
||||
_pos = p;
|
||||
recompute_transform();
|
||||
}
|
||||
|
||||
INLINE float GuiLabel::get_scale(void) const {
|
||||
return _scale;
|
||||
}
|
||||
|
||||
INLINE LVector3f GuiLabel::get_pos(void) const {
|
||||
return _pos;
|
||||
}
|
||||
|
@ -5,6 +5,24 @@
|
||||
|
||||
#include "guiLabel.h"
|
||||
|
||||
#include <textNode.h>
|
||||
|
||||
void GuiLabel::recompute_transform(void) {
|
||||
switch (_type) {
|
||||
case SIMPLE_TEXT:
|
||||
{
|
||||
LMatrix4f mat = LMatrix4f::scale_mat(_scale) *
|
||||
LMatrix4f::translate_mat(_pos);
|
||||
TextNode* n = DCAST(TextNode, _geom);
|
||||
n->set_transform(mat);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gui_cat->warning() << "recompute_transform on invalid label type ("
|
||||
<< _type << ")" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
GuiLabel::~GuiLabel(void) {
|
||||
}
|
||||
|
||||
@ -12,17 +30,12 @@ GuiLabel* GuiLabel::make_simple_texture_label(void) {
|
||||
return new GuiLabel();
|
||||
}
|
||||
|
||||
#include <textNode.h>
|
||||
|
||||
GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font) {
|
||||
GuiLabel* ret = new GuiLabel();
|
||||
ret->_type = SIMPLE_TEXT;
|
||||
TextNode* n = new TextNode("GUI label");
|
||||
ret->_geom = n;
|
||||
LMatrix4f mat = LMatrix4f::scale_mat(0.1);
|
||||
n->set_transform(mat);
|
||||
n->set_font(font);
|
||||
// n->set_card_color(1., 1., 1., 0.);
|
||||
n->set_align(TM_ALIGN_CENTER);
|
||||
n->set_text_color(1., 1., 1., 1.);
|
||||
n->set_text(text);
|
||||
|
@ -24,11 +24,16 @@ private:
|
||||
PT_Node _geom;
|
||||
RenderRelation* _arc;
|
||||
|
||||
float _scale;
|
||||
LVector3f _pos;
|
||||
|
||||
INLINE Node* get_geometry(void) const;
|
||||
INLINE void set_arc(RenderRelation*);
|
||||
INLINE RenderRelation* get_arc(void) const;
|
||||
|
||||
friend GuiManager;
|
||||
|
||||
void recompute_transform(void);
|
||||
public:
|
||||
INLINE GuiLabel(void);
|
||||
virtual ~GuiLabel(void);
|
||||
@ -37,6 +42,12 @@ public:
|
||||
static GuiLabel* make_simple_text_label(const string&, Node*);
|
||||
|
||||
void get_extents(float&, float&, float&, float&);
|
||||
|
||||
INLINE void set_scale(float);
|
||||
INLINE void set_pos(const LVector3f&);
|
||||
|
||||
INLINE float get_scale(void) const;
|
||||
INLINE LVector3f get_pos(void) const;
|
||||
};
|
||||
|
||||
#include "guiLabel.I"
|
||||
|
@ -21,3 +21,8 @@ INLINE MouseWatcherRegion* GuiRegion::get_region(void) const {
|
||||
INLINE void GuiRegion::trap_clicks(bool t) {
|
||||
_region->set_suppress_below(t);
|
||||
}
|
||||
|
||||
INLINE void GuiRegion::set_region(float left, float right, float bottom,
|
||||
float top) {
|
||||
_region->set_frame(left, right, bottom, top);
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public:
|
||||
~GuiRegion(void);
|
||||
|
||||
INLINE void trap_clicks(bool);
|
||||
|
||||
INLINE void set_region(float, float, float, float);
|
||||
};
|
||||
|
||||
#include "guiRegion.I"
|
||||
|
@ -33,3 +33,25 @@ INLINE void GuiRollover::exit(void) {
|
||||
INLINE bool GuiRollover::is_over(void) const {
|
||||
return _state;
|
||||
}
|
||||
|
||||
INLINE void GuiRollover::set_scale(float f) {
|
||||
_on->set_scale(f);
|
||||
_off->set_scale(f);
|
||||
recompute_frame();
|
||||
_scale = f;
|
||||
}
|
||||
|
||||
INLINE void GuiRollover::set_pos(const LVector3f& p) {
|
||||
_on->set_pos(p);
|
||||
_off->set_pos(p);
|
||||
recompute_frame();
|
||||
_pos = p;
|
||||
}
|
||||
|
||||
INLINE float GuiRollover::get_scale(void) const {
|
||||
return _scale;
|
||||
}
|
||||
|
||||
INLINE LVector3f GuiRollover::get_pos(void) const {
|
||||
return _pos;
|
||||
}
|
||||
|
@ -32,6 +32,13 @@ static void exit_rollover(CPT_Event e) {
|
||||
val->exit();
|
||||
}
|
||||
|
||||
void GuiRollover::recompute_frame(void) {
|
||||
float left, right, bottom, top;
|
||||
|
||||
GetExtents(_off, _on, left, right, bottom, top);
|
||||
_rgn->set_region(left, right, bottom, top);
|
||||
}
|
||||
|
||||
GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on)
|
||||
: Namable(name), _off(off), _on(on), _state(false), _added_hooks(false) {
|
||||
float left, right, bottom, top;
|
||||
|
@ -22,7 +22,11 @@ private:
|
||||
bool _added_hooks;
|
||||
GuiManager* _mgr;
|
||||
|
||||
float _scale;
|
||||
LVector3f _pos;
|
||||
|
||||
INLINE GuiRollover(void);
|
||||
void recompute_frame(void);
|
||||
public:
|
||||
GuiRollover(const string&, GuiLabel*, GuiLabel*);
|
||||
~GuiRollover(void);
|
||||
@ -33,6 +37,12 @@ public:
|
||||
INLINE void exit(void);
|
||||
|
||||
INLINE bool is_over(void) const;
|
||||
|
||||
INLINE void set_scale(float);
|
||||
INLINE void set_pos(const LVector3f&);
|
||||
|
||||
INLINE float get_scale(void) const;
|
||||
INLINE LVector3f get_pos(void) const;
|
||||
};
|
||||
|
||||
#include "guiRollover.I"
|
||||
|
@ -60,6 +60,8 @@ static void setup_gui(void) {
|
||||
// GuiLabel* l1 = GuiLabel::make_simple_text_label("off", font);
|
||||
// GuiLabel* l2 = GuiLabel::make_simple_text_label("on", font);
|
||||
// GuiRollover* r1 = new GuiRollover("test2", l1, l2);
|
||||
// r1->set_scale(0.1);
|
||||
// r1->set_pos(LVector3f::rfu(0.25, 0., 0.25));
|
||||
// r1->manage(mgr, event_handler);
|
||||
// test 3
|
||||
GuiLabel* l1 = GuiLabel::make_simple_text_label("up", font);
|
||||
@ -68,6 +70,8 @@ static void setup_gui(void) {
|
||||
GuiLabel* l4 = GuiLabel::make_simple_text_label("downr", font);
|
||||
GuiLabel* l5 = GuiLabel::make_simple_text_label("none", font);
|
||||
GuiButton* b1 = new GuiButton("test3", l1, l2, l3, l4, l5);
|
||||
b1->set_scale(0.1);
|
||||
b1->set_pos(LVector3f::rfu(-0.25, 0., 0.25));
|
||||
b1->manage(mgr, event_handler);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user