1 // This is core/vgui/vgui_wrapper_tableau.h 2 #ifndef vgui_wrapper_tableau_h_ 3 #define vgui_wrapper_tableau_h_ 4 //: 5 // \file 6 // \author fsm 7 // \brief Base class tableau for tableau who want only a single child. 8 // 9 // Contains classes: vgui_wrapper_tableau vgui_wrapper_tableau_new 10 11 #include "vgui_wrapper_tableau_sptr.h" 12 #include "vgui_tableau.h" 13 #include "vgui_parent_child_link.h" 14 15 //: Base class tableau for tableau who want only a single child. 16 // 17 // Q: So what does a vgui_wrapper_tableau do, then? 18 // A: It's a convenient base class for tableaux who want only a single child, 19 // providing mixin code for adding and removing children, and handling the 20 // popup menu. 21 // To pass on an event to (the child of) a slot use 22 // return child.handle(e); 23 // which will work even if the slot is empty (returns false). 24 // 25 // Q: Why does it have such a silly name? 26 // A: Because it is a tableau which "wraps" itself around another tableau. 27 // "vgui_parent" was too vague and it was needed for something else anyway. 28 // I would welcome suggestions for a better name. 29 class vgui_wrapper_tableau : public vgui_tableau 30 { 31 public: 32 //: Constructor - don't use this, use vgui_wrapper_tableau_new. 33 // The child tableau is added later using add_child. 34 vgui_wrapper_tableau(); 35 36 //: Constructor - don't use this, use vgui_wrapper_tableau_new. 37 // Takes the single child tableau for this tableau. 38 vgui_wrapper_tableau(vgui_tableau_sptr const&); 39 40 //: Adds given tableau as child if none exists, else causes error. 41 bool add_child(vgui_tableau_sptr const&); 42 43 //: The child tableau is removed if it is the same as the given tableau. 44 bool remove_child(vgui_tableau_sptr const&); 45 46 //: Returns the child's file_name if it exists. 47 std::string file_name() const; 48 49 //: Returns nice version of the name which also includes details of the child. 50 std::string pretty_name() const; 51 52 //: Returns the type of tableau ('vgui_wrapper_tableau'). 53 std::string type_name() const; 54 55 //: Handle all events sent to this tableau. 56 // It is pointless to derive from vgui_wrapper_tableau 57 // unless this method is also overridden! 58 bool handle(vgui_event const &); 59 60 //: Get the bounding box for this tableau. 61 // Defaults to getting the bounding box of the child. 62 bool get_bounding_box(float low[3], float high[3]) const; 63 64 //: The single child of this tableau. 65 vgui_parent_child_link child; 66 67 protected: 68 // Destructor - called by vgui_wrapper_tableau_sptr. 69 ~vgui_wrapper_tableau(); 70 }; 71 72 //: Create a smart-pointer to a vgui_wrapper_tableau. 73 struct vgui_wrapper_tableau_new : public vgui_wrapper_tableau_sptr { 74 typedef vgui_wrapper_tableau_sptr base; 75 76 //: Constructor - creates a default vgui_wrapper_tableau. vgui_wrapper_tableau_newvgui_wrapper_tableau_new77 vgui_wrapper_tableau_new() : base(new vgui_wrapper_tableau()) { } 78 79 //: Constructor - takes the single child for the vgui_wrapper_tableau. vgui_wrapper_tableau_newvgui_wrapper_tableau_new80 vgui_wrapper_tableau_new(vgui_tableau_sptr const&b) : base(new vgui_wrapper_tableau(b)) { } 81 }; 82 83 #endif // vgui_wrapper_tableau_h_ 84