mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
update some stuff
This commit is contained in:
parent
31d42e69c3
commit
c43c1e1347
@ -41,9 +41,11 @@ INLINE void GuiButton::exit(void) {
|
||||
INLINE void GuiButton::up(void) {
|
||||
switch (_state) {
|
||||
case DOWN:
|
||||
case INACTIVE:
|
||||
switch_state(UP);
|
||||
break;
|
||||
case DOWN_ROLLOVER:
|
||||
case INACTIVE_ROLLOVER:
|
||||
switch_state(UP_ROLLOVER);
|
||||
break;
|
||||
default:
|
||||
@ -55,9 +57,11 @@ INLINE void GuiButton::up(void) {
|
||||
INLINE void GuiButton::down(void) {
|
||||
switch (_state) {
|
||||
case UP:
|
||||
case INACTIVE:
|
||||
switch_state(DOWN);
|
||||
break;
|
||||
case UP_ROLLOVER:
|
||||
case INACTIVE_ROLLOVER:
|
||||
switch_state(DOWN_ROLLOVER);
|
||||
break;
|
||||
default:
|
||||
|
@ -4,3 +4,83 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE GuiFrame::GuiFrame(void) {}
|
||||
|
||||
INLINE bool GuiFrame::is_aligned_left(void) const {
|
||||
return _align_to_left;
|
||||
}
|
||||
|
||||
INLINE bool GuiFrame::is_aligned_right(void) const {
|
||||
return _align_to_right;
|
||||
}
|
||||
|
||||
INLINE bool GuiFrame::is_aligned_top(void) const {
|
||||
return _align_to_top;
|
||||
}
|
||||
|
||||
INLINE bool GuiFrame::is_aligned_bottom(void) const {
|
||||
return _align_to_bottom;
|
||||
}
|
||||
|
||||
INLINE float GuiFrame::get_left_gap(void) const {
|
||||
return _left_gap;
|
||||
}
|
||||
|
||||
INLINE float GuiFrame::get_right_gap(void) const {
|
||||
return _right_gap;
|
||||
}
|
||||
|
||||
INLINE float GuiFrame::get_top_gap(void) const {
|
||||
return _top_gap;
|
||||
}
|
||||
|
||||
INLINE float GuiFrame::get_bottom_gap(void) const {
|
||||
return _bottom_gap;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::clear_left_alignment(void) {
|
||||
_align_to_left = false;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::clear_right_alignment(void) {
|
||||
_align_to_right = false;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::clear_top_alignment(void) {
|
||||
_align_to_top = false;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::clear_bottom_alignment(void) {
|
||||
_align_to_bottom = false;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::clear_all_alignment(void) {
|
||||
clear_left_alignment();
|
||||
clear_right_alignment();
|
||||
clear_top_alignment();
|
||||
clear_bottom_alignment();
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::align_to_left(float g) {
|
||||
_align_to_right = false;
|
||||
_align_to_left = true;
|
||||
_left_gap = g;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::align_to_right(float g) {
|
||||
_align_to_left = false;
|
||||
_align_to_right = true;
|
||||
_right_gap = g;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::align_to_top(float g) {
|
||||
_align_to_bottom = false;
|
||||
_align_to_top = true;
|
||||
_top_gap = g;
|
||||
}
|
||||
|
||||
INLINE void GuiFrame::align_to_bottom(float g) {
|
||||
_align_to_top = false;
|
||||
_align_to_bottom = true;
|
||||
_bottom_gap = g;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ void GuiFrame::recompute_frame(void) {
|
||||
// go thru and make sure everything is packed correctly. This is a stupid
|
||||
// and brute-force algorithm. Hopefully it will be replaced with something
|
||||
// more ellegant later
|
||||
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||
GuiItem* here = (*i).get_item();
|
||||
here->recompute();
|
||||
int n = (*i).get_num_links();
|
||||
@ -39,8 +39,8 @@ void GuiFrame::recompute_frame(void) {
|
||||
if (pack == NONE)
|
||||
continue;
|
||||
GuiItem* to = (*i).get_nth_to(j);
|
||||
float gap = (*i).get_nth_gap(j);
|
||||
LVector4f ext_t = to->get_frame();
|
||||
float gap = (*i).get_nth_gap(j);
|
||||
switch (pack) {
|
||||
case ABOVE:
|
||||
{
|
||||
@ -152,6 +152,43 @@ void GuiFrame::recompute_frame(void) {
|
||||
GuiItem* foo = (*i).get_item();
|
||||
foo->set_pos(foo->get_pos() + delta);
|
||||
}
|
||||
// get the bounds again
|
||||
_left = _bottom = 10000000.;
|
||||
_right = _top = -10000000.;
|
||||
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||
float tmp = (*i).get_item()->get_left();
|
||||
_left = (_left<tmp)?_left:tmp;
|
||||
tmp = (*i).get_item()->get_right();
|
||||
_right = (_right<tmp)?tmp:_right;
|
||||
tmp = (*i).get_item()->get_bottom();
|
||||
_bottom = (_bottom<tmp)?_bottom:tmp;
|
||||
tmp = (*i).get_item()->get_top();
|
||||
_top = (_top<tmp)?tmp:_top;
|
||||
}
|
||||
// check for alignment to the DisplayRegion
|
||||
LVector3f move_left, move_right, move_top, move_bottom;
|
||||
move_left = move_right = move_top = move_bottom = LVector3f(0., 0., 0.);
|
||||
if (_align_to_left) {
|
||||
float diff = -1. - _left;
|
||||
move_left = LVector3f::rfu(diff, 0., 0.);
|
||||
}
|
||||
if (_align_to_right) {
|
||||
float diff = 1. - _right;
|
||||
move_right = LVector3f::rfu(diff, 0., 0.);
|
||||
}
|
||||
if (_align_to_top) {
|
||||
float diff = 1. - _top;
|
||||
move_top = LVector3f::rfu(0., 0., diff);
|
||||
}
|
||||
if (_align_to_bottom) {
|
||||
float diff = -1. - _bottom;
|
||||
move_bottom = LVector3f::rfu(0., 0., diff);
|
||||
}
|
||||
LVector3f move = move_left + move_right + move_top + move_bottom;
|
||||
for (i=_items.begin(); i!=_items.end(); ++i) {
|
||||
GuiItem* foo = (*i).get_item();
|
||||
foo->set_pos(foo->get_pos() + move);
|
||||
}
|
||||
// lastly, get the finial bounds
|
||||
_left = _bottom = 10000000.;
|
||||
_right = _top = -10000000.;
|
||||
@ -167,7 +204,10 @@ void GuiFrame::recompute_frame(void) {
|
||||
}
|
||||
}
|
||||
|
||||
GuiFrame::GuiFrame(const string& name) : GuiItem(name) {
|
||||
GuiFrame::GuiFrame(const string& name) : GuiItem(name), _align_to_left(false),
|
||||
_align_to_right(false),
|
||||
_align_to_top(false),
|
||||
_align_to_bottom(false) {
|
||||
}
|
||||
|
||||
GuiFrame::~GuiFrame(void) {
|
||||
|
@ -67,6 +67,14 @@ private:
|
||||
typedef vector<Box> Boxes;
|
||||
|
||||
Boxes _items;
|
||||
bool _align_to_left;
|
||||
bool _align_to_right;
|
||||
bool _align_to_top;
|
||||
bool _align_to_bottom;
|
||||
float _left_gap;
|
||||
float _right_gap;
|
||||
float _top_gap;
|
||||
float _bottom_gap;
|
||||
|
||||
INLINE GuiFrame(void);
|
||||
Boxes::iterator find_box(GuiItem*);
|
||||
@ -82,6 +90,27 @@ PUBLISHED:
|
||||
void clear_packing(GuiItem*);
|
||||
void clear_all_packing(void);
|
||||
|
||||
INLINE bool is_aligned_left(void) const;
|
||||
INLINE bool is_aligned_right(void) const;
|
||||
INLINE bool is_aligned_top(void) const;
|
||||
INLINE bool is_aligned_bottom(void) const;
|
||||
|
||||
INLINE float get_left_gap(void) const;
|
||||
INLINE float get_right_gap(void) const;
|
||||
INLINE float get_top_gap(void) const;
|
||||
INLINE float get_bottom_gap(void) const;
|
||||
|
||||
INLINE void clear_left_alignment(void);
|
||||
INLINE void clear_right_alignment(void);
|
||||
INLINE void clear_top_alignment(void);
|
||||
INLINE void clear_bottom_alignment(void);
|
||||
INLINE void clear_all_alignment(void);
|
||||
|
||||
INLINE void align_to_left(float = 0.);
|
||||
INLINE void align_to_right(float = 0.);
|
||||
INLINE void align_to_top(float = 0.);
|
||||
INLINE void align_to_bottom(float = 0.);
|
||||
|
||||
virtual void manage(GuiManager*, EventHandler&);
|
||||
virtual void unmanage(void);
|
||||
|
||||
|
@ -63,14 +63,18 @@ static void event_frame(CPT_Event) {
|
||||
send(add_pos(d));
|
||||
}
|
||||
|
||||
enum MotionType { M_None, M_Line, M_SLine, M_Box, M_Circle, M_Random };
|
||||
enum MotionType { M_None, M_Line, M_SLine, M_Box, M_SBox, M_Circle, M_SCircle,
|
||||
M_Random, M_SRandom };
|
||||
PT(AutonomousLerp) curr_lerp;
|
||||
MotionType curr_type;
|
||||
PT(GuiButton) lineButton;
|
||||
PT(GuiButton) slineButton;
|
||||
PT(GuiButton) boxButton;
|
||||
PT(GuiButton) sboxButton;
|
||||
PT(GuiButton) circleButton;
|
||||
PT(GuiButton) scircleButton;
|
||||
PT(GuiButton) randomButton;
|
||||
PT(GuiButton) srandomButton;
|
||||
|
||||
// the various motion generators
|
||||
|
||||
@ -109,10 +113,48 @@ private:
|
||||
};
|
||||
TypeHandle MyPosFunctor::_type_handle;
|
||||
|
||||
class MyRotFunctor : public FloatLerpFunctor {
|
||||
public:
|
||||
MyRotFunctor(float start, float end) : FloatLerpFunctor(start, end) {}
|
||||
MyRotFunctor(const MyRotFunctor& p) : FloatLerpFunctor(p) {}
|
||||
virtual ~MyRotFunctor(void) {}
|
||||
virtual void operator()(float t) {
|
||||
float p = interpolate(t);
|
||||
LVector3f tmp = my_pos;
|
||||
float x, y;
|
||||
x = 10. * cos(p);
|
||||
y = 10. * sin(p);
|
||||
my_pos = LVector3f::rfu(x, 0., y);
|
||||
my_vel = my_pos - tmp;
|
||||
update_smiley();
|
||||
}
|
||||
public:
|
||||
// type stuff
|
||||
static TypeHandle get_class_type(void) { return _type_handle; }
|
||||
static void init_type(void) {
|
||||
FloatLerpFunctor::init_type();
|
||||
register_type(_type_handle, "MyRotFunctor",
|
||||
FloatLerpFunctor::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type(void) const { return get_class_type(); }
|
||||
virtual TypeHandle force_init_type(void) {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
TypeHandle MyRotFunctor::_type_handle;
|
||||
|
||||
inline float unit_rand(void) {
|
||||
return ((float)rand() / (float)RAND_MAX);
|
||||
}
|
||||
|
||||
static void init_funcs(void) {
|
||||
static bool inited = false;
|
||||
if (!inited) {
|
||||
MyPosFunctor::init_type();
|
||||
MyRotFunctor::init_type();
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
@ -190,11 +232,34 @@ static void run_box(bool smooth) {
|
||||
}
|
||||
|
||||
static void run_circle(bool smooth) {
|
||||
LerpBlendType* blend;
|
||||
|
||||
init_funcs();
|
||||
if (smooth)
|
||||
blend = new EaseInOutBlendType();
|
||||
else
|
||||
blend = new NoBlendType();
|
||||
curr_lerp = new AutonomousLerp(new MyRotFunctor(0., 6.283185), 5., blend,
|
||||
&event_handler);
|
||||
curr_lerp->set_end_event("lerp_done");
|
||||
curr_lerp->start();
|
||||
}
|
||||
|
||||
static void run_random(bool smooth) {
|
||||
LerpBlendType* blend;
|
||||
|
||||
init_funcs();
|
||||
if (smooth)
|
||||
blend = new EaseInOutBlendType();
|
||||
else
|
||||
blend = new NoBlendType();
|
||||
float x = (20. * unit_rand()) - 10.;
|
||||
float y = (20. * unit_rand()) - 10.;
|
||||
LVector3f p = LVector3f::rfu(x, 0., y);
|
||||
curr_lerp = new AutonomousLerp(new MyPosFunctor(my_pos, p), 5., blend,
|
||||
&event_handler);
|
||||
curr_lerp->set_end_event("lerp_done");
|
||||
curr_lerp->start();
|
||||
}
|
||||
|
||||
static void handle_lerp(void) {
|
||||
@ -213,12 +278,21 @@ static void handle_lerp(void) {
|
||||
case M_Box:
|
||||
run_box(false);
|
||||
break;
|
||||
case M_SBox:
|
||||
run_box(true);
|
||||
break;
|
||||
case M_Circle:
|
||||
run_circle(false);
|
||||
break;
|
||||
case M_SCircle:
|
||||
run_circle(true);
|
||||
break;
|
||||
case M_Random:
|
||||
run_random(false);
|
||||
break;
|
||||
case M_SRandom:
|
||||
run_random(true);
|
||||
break;
|
||||
default:
|
||||
deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")"
|
||||
<< endl;
|
||||
@ -238,12 +312,21 @@ static void make_active(void) {
|
||||
case M_Box:
|
||||
boxButton->up();
|
||||
break;
|
||||
case M_SBox:
|
||||
sboxButton->up();
|
||||
break;
|
||||
case M_Circle:
|
||||
circleButton->up();
|
||||
break;
|
||||
case M_SCircle:
|
||||
scircleButton->up();
|
||||
break;
|
||||
case M_Random:
|
||||
randomButton->up();
|
||||
break;
|
||||
case M_SRandom:
|
||||
srandomButton->up();
|
||||
break;
|
||||
default:
|
||||
deadrec_cat->error() <<" unknown motion type (" << (int)curr_type << ")"
|
||||
<< endl;
|
||||
@ -274,6 +357,13 @@ static void event_button_down(CPT_Event e) {
|
||||
handle_lerp();
|
||||
boxButton->inactive();
|
||||
}
|
||||
} else if (s == "s-box") {
|
||||
if (curr_type != M_SBox) {
|
||||
make_active();
|
||||
curr_type = M_SBox;
|
||||
handle_lerp();
|
||||
sboxButton->inactive();
|
||||
}
|
||||
} else if (s == "circle") {
|
||||
if (curr_type != M_Circle) {
|
||||
make_active();
|
||||
@ -281,6 +371,13 @@ static void event_button_down(CPT_Event e) {
|
||||
handle_lerp();
|
||||
circleButton->inactive();
|
||||
}
|
||||
} else if (s == "s-circle") {
|
||||
if (curr_type != M_SCircle) {
|
||||
make_active();
|
||||
curr_type = M_SCircle;
|
||||
handle_lerp();
|
||||
scircleButton->inactive();
|
||||
}
|
||||
} else if (s == "random") {
|
||||
if (curr_type != M_Random) {
|
||||
make_active();
|
||||
@ -288,6 +385,13 @@ static void event_button_down(CPT_Event e) {
|
||||
handle_lerp();
|
||||
randomButton->inactive();
|
||||
}
|
||||
} else if (s == "s-random") {
|
||||
if (curr_type != M_SRandom) {
|
||||
make_active();
|
||||
curr_type = M_SRandom;
|
||||
handle_lerp();
|
||||
srandomButton->inactive();
|
||||
}
|
||||
} else {
|
||||
deadrec_cat->error() << "got invalid button event '" << s << "'" << endl;
|
||||
}
|
||||
@ -359,23 +463,39 @@ static void deadrec_setup(EventHandler& eh) {
|
||||
boxButton = make_button("box", font, eh);
|
||||
boxButton->set_scale(0.08);
|
||||
f1->add_item(boxButton);
|
||||
sboxButton = make_button("s-box", font, eh);
|
||||
sboxButton->set_scale(0.08);
|
||||
f1->add_item(sboxButton);
|
||||
circleButton = make_button("circle", font, eh);
|
||||
circleButton->set_scale(0.08);
|
||||
f1->add_item(circleButton);
|
||||
scircleButton = make_button("s-circle", font, eh);
|
||||
scircleButton->set_scale(0.08);
|
||||
f1->add_item(scircleButton);
|
||||
randomButton = make_button("random", font, eh);
|
||||
randomButton->set_scale(0.08);
|
||||
f1->add_item(randomButton);
|
||||
srandomButton = make_button("s-random", font, eh);
|
||||
srandomButton->set_scale(0.08);
|
||||
f1->add_item(srandomButton);
|
||||
f1->pack_item(lineButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(lineButton, GuiFrame::ALIGN_LEFT, s1);
|
||||
f1->pack_item(slineButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(slineButton, GuiFrame::RIGHT, lineButton, 0.02);
|
||||
f1->pack_item(boxButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(boxButton, GuiFrame::RIGHT, slineButton, 0.02);
|
||||
f1->pack_item(sboxButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(sboxButton, GuiFrame::RIGHT, boxButton, 0.02);
|
||||
f1->pack_item(circleButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(circleButton, GuiFrame::RIGHT, boxButton, 0.02);
|
||||
f1->pack_item(circleButton, GuiFrame::RIGHT, sboxButton, 0.02);
|
||||
f1->pack_item(scircleButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(scircleButton, GuiFrame::RIGHT, circleButton, 0.02);
|
||||
f1->pack_item(randomButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(randomButton, GuiFrame::RIGHT, circleButton, 0.02);
|
||||
f1->set_pos(LVector3f::rfu(-0.1, 0., 0.9));
|
||||
f1->pack_item(randomButton, GuiFrame::RIGHT, scircleButton, 0.02);
|
||||
f1->pack_item(srandomButton, GuiFrame::UNDER, s1);
|
||||
f1->pack_item(srandomButton, GuiFrame::RIGHT, randomButton, 0.02);
|
||||
f1->align_to_left(0.05);
|
||||
f1->align_to_top(0.05);
|
||||
f1->recompute();
|
||||
f1->manage(mgr, eh);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user