make priorities work

This commit is contained in:
Cary Sandvig 2001-02-20 01:18:30 +00:00
parent bfee93ce44
commit aa4010fe9c
22 changed files with 188 additions and 20 deletions

View File

@ -14,6 +14,10 @@ void GuiBackground::recompute_frame(void) {
GuiItem::recompute_frame(); GuiItem::recompute_frame();
} }
void GuiBackground::set_priority(GuiLabel* l, const GuiItem::Priority p) {
_bg->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
}
GuiBackground::GuiBackground(const string& name, GuiItem* item) GuiBackground::GuiBackground(const string& name, GuiItem* item)
: GuiItem(name), _item(item) { : GuiItem(name), _item(item) {
_bg = GuiLabel::make_simple_card_label(); _bg = GuiLabel::make_simple_card_label();
@ -72,6 +76,12 @@ void GuiBackground::set_pos(const LVector3f& p) {
recompute_frame(); recompute_frame();
} }
void GuiBackground::set_priority(GuiItem* it, const GuiItem::Priority p) {
_item->set_priority(it, p);
it->set_priority(_bg, ((p==P_Low)?P_High:P_Low));
GuiItem::set_priority(it, 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;

View File

@ -29,6 +29,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void output(ostream&) const; virtual void output(ostream&) const;

View File

@ -237,6 +237,21 @@ void GuiButton::recompute_frame(void) {
_rgn->set_region(_left, _right, _bottom, _top); _rgn->set_region(_left, _right, _bottom, _top);
} }
void GuiButton::set_priority(GuiLabel* l, GuiItem::Priority p) {
_up->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
_down->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
if (_up_rollover != (GuiLabel*)0L)
_up_rollover->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:
GuiLabel::P_HIGHER));
if (_down_rollover != (GuiLabel*)0L)
_down_rollover->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:
GuiLabel::P_HIGHER));
if (_inactive != (GuiLabel*)0L)
_inactive->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:
GuiLabel::P_HIGHER));
GuiItem::set_priority(l, p);
}
void GuiButton::behavior_up(CPT_Event, void* data) { void GuiButton::behavior_up(CPT_Event, void* data) {
GuiButton* button = (GuiButton*)data; GuiButton* button = (GuiButton*)data;
gui_cat->debug() << "behavior_up (0x" << data << ")" << endl; gui_cat->debug() << "behavior_up (0x" << data << ")" << endl;
@ -477,6 +492,18 @@ void GuiButton::reset_behavior(void) {
_eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this); _eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
} }
void GuiButton::set_priority(GuiItem* i, const GuiItem::Priority p) {
i->set_priority(_up, ((p==P_Low)?P_High:P_Low));
i->set_priority(_down, ((p==P_Low)?P_High:P_Low));
if (_up_rollover != (GuiLabel*)0L)
i->set_priority(_up_rollover, ((p==P_Low)?P_High:P_Low));
if (_down_rollover != (GuiLabel*)0L)
i->set_priority(_down_rollover, ((p==P_Low)?P_High:P_Low));
if (_inactive != (GuiLabel*)0L)
i->set_priority(_inactive, ((p==P_Low)?P_High:P_Low));
GuiBehavior::set_priority(i, p);
}
void GuiButton::output(ostream& os) const { void GuiButton::output(ostream& os) const {
GuiBehavior::output(os); GuiBehavior::output(os);
os << " Button data:" << endl; os << " Button data:" << endl;

View File

@ -91,6 +91,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void start_behavior(void); virtual void start_behavior(void);
virtual void stop_behavior(void); virtual void stop_behavior(void);

View File

@ -25,6 +25,9 @@ void GuiChooser::ChooseFunctor::doit(GuiBehavior* b) {
void GuiChooser::recompute_frame(void) { void GuiChooser::recompute_frame(void) {
} }
void GuiChooser::set_priority(GuiLabel*, GuiItem::Priority) {
}
GuiChooser::GuiChooser(const string& name, GuiButton* prev, GuiButton* next) GuiChooser::GuiChooser(const string& name, GuiButton* prev, GuiButton* next)
: GuiBehavior(name), _curr(-1), _loop(false), _prev_button(prev), : GuiBehavior(name), _curr(-1), _loop(false), _prev_button(prev),
_next_button(next), _prev_functor((GuiChooser::ChooseFunctor*)0L), _next_button(next), _prev_functor((GuiChooser::ChooseFunctor*)0L),
@ -225,6 +228,13 @@ void GuiChooser::reset_behavior(void) {
_next_button->reset_behavior(); _next_button->reset_behavior();
} }
void GuiChooser::set_priority(GuiItem* it, const GuiItem::Priority p) {
for (ItemVector::iterator i=_items.begin(); i!=_items.end(); ++i)
(*i)->set_priority(it, p);
_prev_button->set_priority(it, p);
_next_button->set_priority(it, p);
}
void GuiChooser::output(ostream& os) const { void GuiChooser::output(ostream& os) const {
GuiBehavior::output(os); GuiBehavior::output(os);
os << " Chooser data:" << endl; os << " Chooser data:" << endl;

View File

@ -57,6 +57,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void start_behavior(void); virtual void start_behavior(void);
virtual void stop_behavior(void); virtual void stop_behavior(void);

View File

@ -210,6 +210,9 @@ void GuiFrame::recompute_frame(void) {
thaw(); thaw();
} }
void GuiFrame::set_priority(GuiLabel*, const GuiItem::Priority) {
}
GuiFrame::GuiFrame(const string& name) : GuiItem(name), _align_to_left(false), GuiFrame::GuiFrame(const string& name) : GuiItem(name), _align_to_left(false),
_align_to_right(false), _align_to_right(false),
_align_to_top(false), _align_to_top(false),
@ -343,6 +346,15 @@ void GuiFrame::set_pos(const LVector3f& p) {
// this->recompute_frame(); // this->recompute_frame();
} }
void GuiFrame::set_priority(GuiItem* it, const GuiItem::Priority p) {
Boxes::iterator i;
for (i=_items.begin(); i!=_items.end(); ++i) {
GuiItem* here = (*i).get_item();
here->set_priority(it, p);
}
}
void GuiFrame::output(ostream& os) const { void GuiFrame::output(ostream& os) const {
GuiItem::output(os); GuiItem::output(os);
os << " Frame data:" << endl; os << " Frame data:" << endl;

View File

@ -119,6 +119,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void output(ostream&) const; virtual void output(ostream&) const;
public: public:

View File

@ -6,23 +6,6 @@
INLINE GuiItem::GuiItem(void) : Namable("fubar"), _left(-1.), _right(1.), INLINE GuiItem::GuiItem(void) : Namable("fubar"), _left(-1.), _right(1.),
_bottom(-1.), _top(1.), _pri(P_Normal) {} _bottom(-1.), _top(1.), _pri(P_Normal) {}
INLINE void GuiItem::set_priority(const GuiItem::Priority p) {
_pri = p;
float r = _pos.dot(LVector3f::rfu(1., 0., 0.));
float u = _pos.dot(LVector3f::rfu(0., 0., 1.));
switch (_pri) {
case P_Low:
this->set_pos(LVector3f::rfu(r, 0.5, u));
break;
case P_Normal:
this->set_pos(LVector3f::rfu(r, 0., u));
break;
case P_High:
this->set_pos(LVector3f::rfu(r, -0.5, u));
break;
}
}
INLINE float GuiItem::get_scale(void) const { INLINE float GuiItem::get_scale(void) const {
return _scale; return _scale;
} }

View File

@ -11,6 +11,9 @@ void GuiItem::recompute_frame(void) {
test_ref_count_integrity(); test_ref_count_integrity();
} }
void GuiItem::set_priority(GuiLabel*, const GuiItem::Priority) {
}
GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false), GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false),
_scale(1.), _left(-1.), _right(1.), _scale(1.), _left(-1.), _right(1.),
_bottom(-1.), _top(1.), _bottom(-1.), _top(1.),
@ -51,6 +54,11 @@ void GuiItem::set_pos(const LVector3f& p) {
_pos = p; _pos = p;
} }
void GuiItem::set_priority(GuiItem* i, const GuiItem::Priority p) {
if (_mgr != (GuiManager*)0L)
_mgr->recompute_priorities();
}
void GuiItem::output(ostream& os) const { void GuiItem::output(ostream& os) const {
os << "GuiItem (0x" << (void*)this << ")" << endl; os << "GuiItem (0x" << (void*)this << ")" << endl;
os << " name - '" << get_name() << "'" << endl; os << " name - '" << get_name() << "'" << endl;

View File

@ -36,7 +36,8 @@ PUBLISHED:
virtual void set_scale(float) = 0; virtual void set_scale(float) = 0;
virtual void set_pos(const LVector3f&) = 0; virtual void set_pos(const LVector3f&) = 0;
INLINE void set_priority(const Priority); virtual void set_priority(GuiLabel*, const Priority) = 0;
virtual void set_priority(GuiItem*, const Priority) = 0;
INLINE float get_scale(void) const; INLINE float get_scale(void) const;
INLINE LVector3f get_pos(void) const; INLINE LVector3f get_pos(void) const;

View File

@ -14,7 +14,7 @@ INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE),
_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.) { _depth(0.), _hard_pri(0) {
} }
INLINE Node* GuiLabel::get_geometry(void) const { INLINE Node* GuiLabel::get_geometry(void) const {
@ -106,3 +106,7 @@ INLINE Colorf GuiLabel::get_background_color(void) const {
INLINE void GuiLabel::recompute(void) { INLINE void GuiLabel::recompute(void) {
this->recompute_transform(); this->recompute_transform();
} }
INLINE void GuiLabel::set_priority(GuiLabel* l, const PriorityType t) {
this->_priorities[l] = t;
}

View File

@ -372,3 +372,15 @@ void GuiLabel::set_text(const string& val) {
} }
recompute(); recompute();
} }
bool GuiLabel::operator<(const GuiLabel& c) const {
PriorityMap::const_iterator pi;
pi = _priorities.find((GuiLabel*)(&c));
if (pi != _priorities.end()) {
if ((*pi).second == P_LOWER)
return true;
else
return false;
}
return ((void*)this) < ((void*)&c);
}

View File

@ -21,8 +21,12 @@
class GuiManager; class GuiManager;
class EXPCL_PANDA GuiLabel : public TypedReferenceCount { class EXPCL_PANDA GuiLabel : public TypedReferenceCount {
PUBLISHED:
enum PriorityType { P_NONE, P_LOWER, P_HIGHER };
private: private:
typedef map<GuiLabel*, PriorityType> PriorityMap;
enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT, SIMPLE_CARD }; enum LabelType { NONE, SIMPLE_TEXTURE, SIMPLE_TEXT, SIMPLE_CARD };
LabelType _type; LabelType _type;
PT_Node _geom; PT_Node _geom;
RenderRelation* _arc; RenderRelation* _arc;
@ -41,6 +45,9 @@ private:
float _height; float _height;
float _depth; float _depth;
PriorityMap _priorities;
int _hard_pri;
INLINE Node* get_geometry(void) const; INLINE Node* get_geometry(void) const;
INLINE void set_arc(RenderRelation*); INLINE void set_arc(RenderRelation*);
INLINE RenderRelation* get_arc(void) const; INLINE RenderRelation* get_arc(void) const;
@ -90,6 +97,10 @@ PUBLISHED:
INLINE void recompute(void); INLINE void recompute(void);
// used for the priority system
bool operator<(const GuiLabel&) const;
INLINE void set_priority(GuiLabel*, const PriorityType);
public: public:
// type interface // type interface
static TypeHandle get_class_type(void) { static TypeHandle get_class_type(void) {

View File

@ -125,6 +125,9 @@ void GuiListBox::visible_patching(void) {
this->reset_behavior(); this->reset_behavior();
} }
void GuiListBox::set_priority(GuiLabel* l, const GuiItem::Priority p) {
}
GuiListBox::GuiListBox(const string& name, int N, GuiItem* up, GuiItem* down) GuiListBox::GuiListBox(const string& name, int N, GuiItem* up, GuiItem* down)
: GuiBehavior(name), _arrow_top(false), _arrow_bottom(false), _up_arrow(up), : GuiBehavior(name), _arrow_top(false), _arrow_bottom(false), _up_arrow(up),
_down_arrow(down), _n_visible(N), _down_arrow(down), _n_visible(N),
@ -430,6 +433,35 @@ void GuiListBox::reset_behavior(void) {
} }
} }
void GuiListBox::set_priority(GuiItem* it, const GuiItem::Priority p) {
ItemVector::iterator i;
ItemDeque::iterator j;
for (i=_top_stack.begin(); i!=_top_stack.end(); ++i) {
if (*i == _up_arrow)
continue;
if (*i == _down_arrow)
continue;
(*i)->set_priority(it, p);
}
for (i=_visible.begin(); i!=_visible.end(); ++i) {
if (*i == _up_arrow)
continue;
if (*i == _down_arrow)
continue;
(*i)->set_priority(it, p);
}
for (j=_bottom_stack.begin(); j!=_bottom_stack.end(); ++j) {
if (*j == _up_arrow)
continue;
if (*j == _down_arrow)
continue;
(*j)->set_priority(it, p);
}
_up_arrow->set_priority(it, p);
_down_arrow->set_priority(it, p);
}
void GuiListBox::output(ostream& os) const { void GuiListBox::output(ostream& os) const {
GuiBehavior::output(os); GuiBehavior::output(os);
os << " Listbox data:" << endl; os << " Listbox data:" << endl;

View File

@ -60,6 +60,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void start_behavior(void); virtual void start_behavior(void);
virtual void stop_behavior(void); virtual void stop_behavior(void);

View File

@ -176,3 +176,16 @@ void GuiManager::remove_label(GuiLabel* label) {
_labels.erase(li); _labels.erase(li);
} }
} }
#include <geomBinTransition.h>
void GuiManager::recompute_priorities(void) {
_sorts.clear();
for (LabelSet::iterator i=_labels.begin(); i!=_labels.end(); ++i)
_sorts.insert(*i);
int p=0;
for (SortSet::iterator j=_sorts.begin(); j!=_sorts.end(); ++j, ++p) {
(*j)->_hard_pri = p;
(*j)->get_arc()->set_transition(new GeomBinTransition("fixed", p));
}
}

View File

@ -25,12 +25,19 @@ private:
RegionSet _regions; RegionSet _regions;
typedef set<GuiLabel*> LabelSet; typedef set<GuiLabel*> LabelSet;
LabelSet _labels; LabelSet _labels;
class SortComp {
public:
inline bool operator()(GuiLabel* a, GuiLabel* b) const {
return (*a) < (*b);
}
};
typedef set<GuiLabel*, SortComp> SortSet;
SortSet _sorts;
Node* _root; Node* _root;
MouseWatcher* _watcher; MouseWatcher* _watcher;
INLINE GuiManager(MouseWatcher*, Node*); INLINE GuiManager(MouseWatcher*, Node*);
PUBLISHED: PUBLISHED:
static GuiManager* get_ptr(GraphicsWindow*, MouseAndKeyboard*, Node *root2d); static GuiManager* get_ptr(GraphicsWindow*, MouseAndKeyboard*, Node *root2d);
@ -39,6 +46,8 @@ PUBLISHED:
void remove_region(GuiRegion*); void remove_region(GuiRegion*);
void remove_label(GuiLabel*); void remove_label(GuiLabel*);
void recompute_priorities(void);
}; };
#include "guiManager.I" #include "guiManager.I"

View File

@ -67,6 +67,12 @@ void GuiRollover::recompute_frame(void) {
_rgn->set_region(_left, _right, _bottom, _top); _rgn->set_region(_left, _right, _bottom, _top);
} }
void GuiRollover::set_priority(GuiLabel* l, const GuiItem::Priority p) {
_off->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
_on->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
GuiItem::set_priority(l, p);
}
GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on) GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on)
: GuiItem(name), _off(off), _on(on), _off_scale(off->get_scale()), : GuiItem(name), _off(off), _on(on), _off_scale(off->get_scale()),
_on_scale(on->get_scale()), _state(false) { _on_scale(on->get_scale()), _state(false) {
@ -138,6 +144,12 @@ void GuiRollover::set_pos(const LVector3f& p) {
recompute_frame(); recompute_frame();
} }
void GuiRollover::set_priority(GuiItem* i, const GuiItem::Priority p) {
i->set_priority(_off, ((p==P_Low)?P_High:P_Low));
i->set_priority(_on, ((p==P_Low)?P_High:P_Low));
GuiItem::set_priority(i, p);
}
void GuiRollover::output(ostream& os) const { void GuiRollover::output(ostream& os) const {
GuiItem::output(os); GuiItem::output(os);
os << " Rollover data:" << endl; os << " Rollover data:" << endl;

View File

@ -42,6 +42,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void output(ostream&) const; virtual void output(ostream&) const;

View File

@ -14,6 +14,11 @@ void GuiSign::recompute_frame(void) {
_sign->get_extents(_left, _right, _bottom, _top); _sign->get_extents(_left, _right, _bottom, _top);
} }
void GuiSign::set_priority(GuiLabel* l, const GuiItem::Priority p) {
_sign->set_priority(l, ((p==P_Low)?GuiLabel::P_LOWER:GuiLabel::P_HIGHER));
GuiItem::set_priority(l, p);
}
GuiSign::GuiSign(const string& name, GuiLabel* sign) GuiSign::GuiSign(const string& name, GuiLabel* sign)
: GuiItem(name), _sign(sign), _sign_scale(sign->get_scale()) { : GuiItem(name), _sign(sign), _sign_scale(sign->get_scale()) {
_sign->get_extents(_left, _right, _bottom, _top); _sign->get_extents(_left, _right, _bottom, _top);
@ -62,6 +67,11 @@ void GuiSign::set_pos(const LVector3f& p) {
recompute_frame(); recompute_frame();
} }
void GuiSign::set_priority(GuiItem* i, const GuiItem::Priority p) {
i->set_priority(_sign, ((p==P_Low)?P_High:P_Low));
GuiItem::set_priority(i, p);
}
void GuiSign::output(ostream& os) const { void GuiSign::output(ostream& os) const {
GuiItem::output(os); GuiItem::output(os);
os << " Sign data:" << endl; os << " Sign data:" << endl;

View File

@ -30,6 +30,8 @@ PUBLISHED:
virtual void set_scale(float); virtual void set_scale(float);
virtual void set_pos(const LVector3f&); virtual void set_pos(const LVector3f&);
virtual void set_priority(GuiLabel*, const Priority);
virtual void set_priority(GuiItem*, const Priority);
virtual void output(ostream&) const; virtual void output(ostream&) const;