00001
00008 #ifndef DEFAULT3DMENU_H
00009 #define DEFAULT3DMENU_H
00010
00011 #include <VRG3D.H>
00012 #include "Widget.H"
00013
00014 class BBox
00015 {
00016 public:
00017 BBox() { _initialized = false; }
00018 BBox(const AABox &aabox) {
00019 _initialized = false;
00020 _box = aabox;
00021 }
00022
00023 virtual ~BBox() {}
00024
00025 inline void addPoint(const Vector3 &p) {
00026 if (!_initialized)
00027 _box = AABox(p);
00028 else {
00029 Vector3 low = _box.low().min(p);
00030 Vector3 high = _box.high().max(p);
00031 _box = AABox(low,high);
00032 }
00033 _initialized = true;
00034 }
00035
00036 inline void addAABox(const AABox &b) {
00037 if (!_initialized)
00038 _box = b;
00039 else {
00040 Vector3 low = _box.low().min(b.low());
00041 Vector3 high = _box.high().max(b.high());
00042 _box = AABox(low,high);
00043 }
00044 _initialized = true;
00045 }
00046
00047 inline void addBBox(const BBox &b) {
00048 addAABox(b.getAABox());
00049 }
00050
00051 inline AABox getAABox() const { return _box; }
00052
00053 inline bool getInitialized() const { return _initialized; }
00054
00055 protected:
00056 bool _initialized;
00057 AABox _box;
00058 };
00059
00060
00061 typedef ReferenceCountedPointer<class Default3DMenu> Default3DMenuRef;
00064 class Default3DMenu : public Widget
00065 {
00066 public:
00067
00068 Default3DMenu(const std::string &menuTitle,
00069 const Array<std::string> &menuItemNames,
00070 const Array<std::string> &eventsToGenerate,
00071 const std::string &trackerEventToListenFor,
00072 const std::string &buttonEventToListenFor,
00073 const CoordinateFrame &initialFrame,
00074 double itemHeight,
00075 WidgetMgrRef widgetMgr);
00076
00077 virtual ~Default3DMenu();
00078
00079 void processEvent(EventRef event, Array<EventRef> &generatedEvents);
00080 void doGraphics(RenderDevice *rd);
00081 bool pointerOverWidget(Vector3 pointerPosRoomSpace);
00082 bool canReleaseFocus();
00083
00084 enum ItemState {ENABLED, DISABLED, HIGHLIGHTED, ACTIVATED};
00085 ItemState getItemState(const int i) { return _states[i]; }
00086 void setItemState(const int i, ItemState s) { _states[i] = s; }
00087
00088 protected:
00089
00090 void menuBtnOn(Array<EventRef> &generatedEvents);
00091 void menuBtnOff();
00092 void trackerMove(EventRef e);
00093 void trackerMoveBtnDown(EventRef e);
00094
00095 void drawTextOnBox(RenderDevice *rd, const std::string &str, AABox box,
00096 Color4 color, Color4 outline);
00097
00098 std::string _title;
00099 Array<std::string> _items;
00100 Array<ItemState> _states;
00101 Array<AABox> _boxes;
00102 GFontRef _font;
00103 double _textHeight;
00104 double _padding;
00105 Color4 _outlineCol;
00106 Color4 _titleFG, _titleBG;
00107 Color4 _itemFG, _itemBG;
00108 Color4 _disabledFG, _disabledBG;
00109 Color4 _highltFG, _highltBG;
00110 Color4 _activatedFG, _activatedBG;
00111 CoordinateFrame _dragOffset;
00112 bool _firstDrag;
00113 bool _btnDown;
00114 std::string _trackerEvent;
00115 std::string _btnEvent;
00116 Array<std::string> _events;
00117 BBox _bbox;
00118 CoordinateFrame _frame;
00119 };
00120
00121 #endif