guiFrame.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Filename: guiFrame.h
  2. // Created by: cary (01Nov00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef __GUIFRAME_H__
  19. #define __GUIFRAME_H__
  20. #include "guiItem.h"
  21. #include "pvector.h"
  22. class EXPCL_PANDA GuiFrame : public GuiItem {
  23. PUBLISHED:
  24. enum Packing { NONE, ABOVE, UNDER, LEFT, RIGHT, ALIGN_ABOVE, ALIGN_UNDER,
  25. ALIGN_LEFT, ALIGN_RIGHT };
  26. private:
  27. class Connection {
  28. private:
  29. Packing _how;
  30. GuiItem* _who;
  31. float _gap;
  32. public:
  33. inline Connection(void) : _how(NONE), _who((GuiItem*)0L), _gap(0.) {}
  34. inline Connection(Packing how, GuiItem* who, float gap) : _how(how),
  35. _who(who),
  36. _gap(gap) {}
  37. inline Connection(const Connection& c) : _how(c._how), _who(c._who),
  38. _gap(c._gap) {}
  39. ~Connection(void) {}
  40. inline void set_how(Packing how) { _how = how; }
  41. inline void set_who(GuiItem* who) { _who = who; }
  42. inline void set_gap(float gap) { _gap = gap; }
  43. inline Packing get_how(void) const { return _how; }
  44. inline GuiItem* get_who(void) const { return _who; }
  45. inline float get_gap(void) const { return _gap; }
  46. };
  47. typedef pvector<Connection> Connections;
  48. class Box {
  49. private:
  50. PT(GuiItem) _thing;
  51. float _scale;
  52. Connections _links;
  53. public:
  54. inline Box(void) : _thing((GuiItem*)0L), _scale(1.) {}
  55. inline Box(GuiItem* i) : _thing(i), _scale(i->get_scale()) {}
  56. inline Box(const Box& c) : _thing(c._thing), _scale(c._scale),
  57. _links(c._links) {}
  58. ~Box(void) {}
  59. inline void set_item(GuiItem* i) { _thing = i; }
  60. inline void set_scale(float f) { _scale = f; }
  61. inline void add_link(Connection c) { _links.push_back(c); }
  62. inline GuiItem* get_item(void) const { return _thing; }
  63. inline float get_scale(void) const { return _scale; }
  64. inline int get_num_links(void) const { return _links.size(); }
  65. inline Packing get_nth_packing(int n) const { return _links[n].get_how(); }
  66. inline GuiItem* get_nth_to(int n) const { return _links[n].get_who(); }
  67. inline float get_nth_gap(int n) const { return _links[n].get_gap(); }
  68. inline void erase_nth_link(int n) { _links.erase(_links.begin() + n); }
  69. inline void erase_all_links(void) { _links.clear(); }
  70. };
  71. typedef pvector<Box> Boxes;
  72. Boxes _items;
  73. bool _align_to_left;
  74. bool _align_to_right;
  75. bool _align_to_top;
  76. bool _align_to_bottom;
  77. float _left_gap;
  78. float _right_gap;
  79. float _top_gap;
  80. float _bottom_gap;
  81. INLINE GuiFrame(void);
  82. Boxes::iterator find_box(GuiItem*);
  83. virtual void recompute_frame(void);
  84. PUBLISHED:
  85. GuiFrame(const string&);
  86. ~GuiFrame(void);
  87. virtual int freeze();
  88. virtual int thaw();
  89. void add_item(GuiItem*);
  90. void remove_item(GuiItem*);
  91. void pack_item(GuiItem*, Packing, GuiItem*, float = 0.);
  92. void clear_packing(GuiItem*);
  93. void clear_all_packing(void);
  94. INLINE bool is_aligned_left(void) const;
  95. INLINE bool is_aligned_right(void) const;
  96. INLINE bool is_aligned_top(void) const;
  97. INLINE bool is_aligned_bottom(void) const;
  98. INLINE float get_left_gap(void) const;
  99. INLINE float get_right_gap(void) const;
  100. INLINE float get_top_gap(void) const;
  101. INLINE float get_bottom_gap(void) const;
  102. INLINE void clear_left_alignment(void);
  103. INLINE void clear_right_alignment(void);
  104. INLINE void clear_top_alignment(void);
  105. INLINE void clear_bottom_alignment(void);
  106. INLINE void clear_all_alignment(void);
  107. INLINE void align_to_left(float = 0.);
  108. INLINE void align_to_right(float = 0.);
  109. INLINE void align_to_top(float = 0.);
  110. INLINE void align_to_bottom(float = 0.);
  111. virtual void manage(GuiManager*, EventHandler&);
  112. virtual void manage(GuiManager*, EventHandler&, Node*);
  113. virtual void unmanage(void);
  114. virtual void set_scale(float);
  115. virtual void set_scale(float, float, float);
  116. virtual void set_pos(const LVector3f&);
  117. virtual void set_priority(GuiLabel*, const Priority);
  118. virtual void set_priority(GuiItem*, const Priority);
  119. virtual int set_draw_order(int);
  120. virtual void output(ostream&) const;
  121. public:
  122. // type interface
  123. static TypeHandle get_class_type(void) {
  124. return _type_handle;
  125. }
  126. static void init_type(void) {
  127. GuiItem::init_type();
  128. register_type(_type_handle, "GuiFrame",
  129. GuiItem::get_class_type());
  130. }
  131. virtual TypeHandle get_type(void) const {
  132. return get_class_type();
  133. }
  134. virtual TypeHandle force_init_type(void) {
  135. init_type();
  136. return get_class_type();
  137. }
  138. private:
  139. static TypeHandle _type_handle;
  140. };
  141. #include "guiFrame.I"
  142. #endif /* __GUIFRAME_H__ */