update some stuff

This commit is contained in:
Cary Sandvig 2000-11-28 23:56:18 +00:00
parent 31d42e69c3
commit c43c1e1347
5 changed files with 280 additions and 7 deletions

View File

@ -41,9 +41,11 @@ INLINE void GuiButton::exit(void) {
INLINE void GuiButton::up(void) { INLINE void GuiButton::up(void) {
switch (_state) { switch (_state) {
case DOWN: case DOWN:
case INACTIVE:
switch_state(UP); switch_state(UP);
break; break;
case DOWN_ROLLOVER: case DOWN_ROLLOVER:
case INACTIVE_ROLLOVER:
switch_state(UP_ROLLOVER); switch_state(UP_ROLLOVER);
break; break;
default: default:
@ -55,9 +57,11 @@ INLINE void GuiButton::up(void) {
INLINE void GuiButton::down(void) { INLINE void GuiButton::down(void) {
switch (_state) { switch (_state) {
case UP: case UP:
case INACTIVE:
switch_state(DOWN); switch_state(DOWN);
break; break;
case UP_ROLLOVER: case UP_ROLLOVER:
case INACTIVE_ROLLOVER:
switch_state(DOWN_ROLLOVER); switch_state(DOWN_ROLLOVER);
break; break;
default: default:

View File

@ -4,3 +4,83 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE GuiFrame::GuiFrame(void) {} 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;
}

View File

@ -27,7 +27,7 @@ void GuiFrame::recompute_frame(void) {
// go thru and make sure everything is packed correctly. This is a stupid // go thru and make sure everything is packed correctly. This is a stupid
// and brute-force algorithm. Hopefully it will be replaced with something // and brute-force algorithm. Hopefully it will be replaced with something
// more ellegant later // more ellegant later
for (i=_items.begin(); i!=_items.end(); ++i) { for (i=_items.begin(); i!=_items.end(); ++i) {
GuiItem* here = (*i).get_item(); GuiItem* here = (*i).get_item();
here->recompute(); here->recompute();
int n = (*i).get_num_links(); int n = (*i).get_num_links();
@ -39,8 +39,8 @@ void GuiFrame::recompute_frame(void) {
if (pack == NONE) if (pack == NONE)
continue; continue;
GuiItem* to = (*i).get_nth_to(j); GuiItem* to = (*i).get_nth_to(j);
float gap = (*i).get_nth_gap(j);
LVector4f ext_t = to->get_frame(); LVector4f ext_t = to->get_frame();
float gap = (*i).get_nth_gap(j);
switch (pack) { switch (pack) {
case ABOVE: case ABOVE:
{ {
@ -152,6 +152,43 @@ void GuiFrame::recompute_frame(void) {
GuiItem* foo = (*i).get_item(); GuiItem* foo = (*i).get_item();
foo->set_pos(foo->get_pos() + delta); 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 // lastly, get the finial bounds
_left = _bottom = 10000000.; _left = _bottom = 10000000.;
_right = _top = -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) { GuiFrame::~GuiFrame(void) {

View File

@ -67,6 +67,14 @@ private:
typedef vector<Box> Boxes; typedef vector<Box> Boxes;
Boxes _items; 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); INLINE GuiFrame(void);
Boxes::iterator find_box(GuiItem*); Boxes::iterator find_box(GuiItem*);
@ -82,6 +90,27 @@ PUBLISHED:
void clear_packing(GuiItem*); void clear_packing(GuiItem*);
void clear_all_packing(void); 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 manage(GuiManager*, EventHandler&);
virtual void unmanage(void); virtual void unmanage(void);

View File

@ -63,14 +63,18 @@ static void event_frame(CPT_Event) {
send(add_pos(d)); 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; PT(AutonomousLerp) curr_lerp;
MotionType curr_type; MotionType curr_type;
PT(GuiButton) lineButton; PT(GuiButton) lineButton;
PT(GuiButton) slineButton; PT(GuiButton) slineButton;
PT(GuiButton) boxButton; PT(GuiButton) boxButton;
PT(GuiButton) sboxButton;
PT(GuiButton) circleButton; PT(GuiButton) circleButton;
PT(GuiButton) scircleButton;
PT(GuiButton) randomButton; PT(GuiButton) randomButton;
PT(GuiButton) srandomButton;
// the various motion generators // the various motion generators
@ -109,10 +113,48 @@ private:
}; };
TypeHandle MyPosFunctor::_type_handle; 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 void init_funcs(void) {
static bool inited = false; static bool inited = false;
if (!inited) { if (!inited) {
MyPosFunctor::init_type(); MyPosFunctor::init_type();
MyRotFunctor::init_type();
inited = true; inited = true;
} }
} }
@ -190,11 +232,34 @@ static void run_box(bool smooth) {
} }
static void run_circle(bool smooth) { static void run_circle(bool smooth) {
LerpBlendType* blend;
init_funcs(); 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) { static void run_random(bool smooth) {
LerpBlendType* blend;
init_funcs(); 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) { static void handle_lerp(void) {
@ -213,12 +278,21 @@ static void handle_lerp(void) {
case M_Box: case M_Box:
run_box(false); run_box(false);
break; break;
case M_SBox:
run_box(true);
break;
case M_Circle: case M_Circle:
run_circle(false); run_circle(false);
break; break;
case M_SCircle:
run_circle(true);
break;
case M_Random: case M_Random:
run_random(false); run_random(false);
break; break;
case M_SRandom:
run_random(true);
break;
default: default:
deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")" deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")"
<< endl; << endl;
@ -238,12 +312,21 @@ static void make_active(void) {
case M_Box: case M_Box:
boxButton->up(); boxButton->up();
break; break;
case M_SBox:
sboxButton->up();
break;
case M_Circle: case M_Circle:
circleButton->up(); circleButton->up();
break; break;
case M_SCircle:
scircleButton->up();
break;
case M_Random: case M_Random:
randomButton->up(); randomButton->up();
break; break;
case M_SRandom:
srandomButton->up();
break;
default: default:
deadrec_cat->error() <<" unknown motion type (" << (int)curr_type << ")" deadrec_cat->error() <<" unknown motion type (" << (int)curr_type << ")"
<< endl; << endl;
@ -274,6 +357,13 @@ static void event_button_down(CPT_Event e) {
handle_lerp(); handle_lerp();
boxButton->inactive(); 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") { } else if (s == "circle") {
if (curr_type != M_Circle) { if (curr_type != M_Circle) {
make_active(); make_active();
@ -281,6 +371,13 @@ static void event_button_down(CPT_Event e) {
handle_lerp(); handle_lerp();
circleButton->inactive(); 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") { } else if (s == "random") {
if (curr_type != M_Random) { if (curr_type != M_Random) {
make_active(); make_active();
@ -288,6 +385,13 @@ static void event_button_down(CPT_Event e) {
handle_lerp(); handle_lerp();
randomButton->inactive(); randomButton->inactive();
} }
} else if (s == "s-random") {
if (curr_type != M_SRandom) {
make_active();
curr_type = M_SRandom;
handle_lerp();
srandomButton->inactive();
}
} else { } else {
deadrec_cat->error() << "got invalid button event '" << s << "'" << endl; 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 = make_button("box", font, eh);
boxButton->set_scale(0.08); boxButton->set_scale(0.08);
f1->add_item(boxButton); 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 = make_button("circle", font, eh);
circleButton->set_scale(0.08); circleButton->set_scale(0.08);
f1->add_item(circleButton); 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 = make_button("random", font, eh);
randomButton->set_scale(0.08); randomButton->set_scale(0.08);
f1->add_item(randomButton); 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::UNDER, s1);
f1->pack_item(lineButton, GuiFrame::ALIGN_LEFT, s1); f1->pack_item(lineButton, GuiFrame::ALIGN_LEFT, s1);
f1->pack_item(slineButton, GuiFrame::UNDER, s1); f1->pack_item(slineButton, GuiFrame::UNDER, s1);
f1->pack_item(slineButton, GuiFrame::RIGHT, lineButton, 0.02); f1->pack_item(slineButton, GuiFrame::RIGHT, lineButton, 0.02);
f1->pack_item(boxButton, GuiFrame::UNDER, s1); f1->pack_item(boxButton, GuiFrame::UNDER, s1);
f1->pack_item(boxButton, GuiFrame::RIGHT, slineButton, 0.02); 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::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::UNDER, s1);
f1->pack_item(randomButton, GuiFrame::RIGHT, circleButton, 0.02); f1->pack_item(randomButton, GuiFrame::RIGHT, scircleButton, 0.02);
f1->set_pos(LVector3f::rfu(-0.1, 0., 0.9)); 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->recompute();
f1->manage(mgr, eh); f1->manage(mgr, eh);
} }