Panda3D
 All Classes Functions Variables Enumerations
pgSliderBar.h
1 // Filename: pgSliderBar.h
2 // Created by: masad (19Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PGSLIDERBAR_H
16 #define PGSLIDERBAR_H
17 
18 #include "pandabase.h"
19 
20 #include "pgItem.h"
21 #include "pgSliderBarNotify.h"
22 #include "pgButtonNotify.h"
23 #include "pgButton.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : PGSliderBar
27 // Description : This is a particular kind of PGItem that draws a
28 // little bar with a slider that moves from left to
29 // right indicating a value between the ranges.
30 //
31 // This is used as an implementation for both
32 // DirectSlider and for DirectScrollBar.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PGUI PGSliderBar : public PGItem, public PGButtonNotify {
35 PUBLISHED:
36  PGSliderBar(const string &name = "");
37  virtual ~PGSliderBar();
38 
39 protected:
40  PGSliderBar(const PGSliderBar &copy);
41 
42 public:
43  virtual PandaNode *make_copy() const;
44  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
45  virtual void xform(const LMatrix4 &mat);
46 
47  virtual void press(const MouseWatcherParameter &param, bool background);
48  virtual void release(const MouseWatcherParameter &param, bool background);
49  virtual void move(const MouseWatcherParameter &param);
50 
51  virtual void adjust();
52 
53  INLINE void set_notify(PGSliderBarNotify *notify);
54  INLINE PGSliderBarNotify *get_notify() const;
55 
56 PUBLISHED:
57  void setup_scroll_bar(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel);
58  void setup_slider(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel);
59 
60  INLINE void set_axis(const LVector3 &axis);
61  INLINE const LVector3 &get_axis() const;
62 
63  INLINE void set_range(PN_stdfloat min_value, PN_stdfloat max_value);
64  INLINE PN_stdfloat get_min_value() const;
65  INLINE PN_stdfloat get_max_value() const;
66 
67  INLINE void set_scroll_size(PN_stdfloat scroll_size);
68  INLINE PN_stdfloat get_scroll_size() const;
69 
70  INLINE void set_page_size(PN_stdfloat page_size);
71  INLINE PN_stdfloat get_page_size() const;
72 
73  INLINE void set_value(PN_stdfloat value);
74  INLINE PN_stdfloat get_value() const;
75 
76  INLINE void set_ratio(PN_stdfloat ratio);
77  INLINE PN_stdfloat get_ratio() const;
78 
79  INLINE bool is_button_down() const;
80 
81  INLINE void set_resize_thumb(bool resize_thumb);
82  INLINE bool get_resize_thumb() const;
83 
84  INLINE void set_manage_pieces(bool manage_pieces);
85  INLINE bool get_manage_pieces() const;
86 
87  INLINE void set_thumb_button(PGButton *thumb_button);
88  INLINE void clear_thumb_button();
89  INLINE PGButton *get_thumb_button() const;
90 
91  INLINE void set_left_button(PGButton *left_button);
92  INLINE void clear_left_button();
93  INLINE PGButton *get_left_button() const;
94 
95  INLINE void set_right_button(PGButton *right_button);
96  INLINE void clear_right_button();
97  INLINE PGButton *get_right_button() const;
98 
99  INLINE static string get_adjust_prefix();
100  INLINE string get_adjust_event() const;
101 
102  virtual void set_active(bool active);
103 
104  void remanage();
105  void recompute();
106 
107 protected:
108  virtual void frame_changed();
109 
110  virtual void item_transform_changed(PGItem *item);
111  virtual void item_frame_changed(PGItem *item);
112  virtual void item_draw_mask_changed(PGItem *item);
113  virtual void item_press(PGItem *item, const MouseWatcherParameter &param);
114  virtual void item_release(PGItem *item, const MouseWatcherParameter &param);
115  virtual void item_move(PGItem *item, const MouseWatcherParameter &param);
116 
117 private:
118  INLINE void internal_set_ratio(PN_stdfloat ratio);
119 
120  void reposition();
121  void advance_scroll();
122  void advance_page();
123  void begin_drag();
124  void continue_drag();
125  void end_drag();
126 
127 private:
128  bool _needs_remanage;
129  bool _needs_recompute;
130  bool _needs_reposition;
131 
132  PN_stdfloat _min_value, _max_value;
133  PN_stdfloat _scroll_value, _scroll_ratio;
134  PN_stdfloat _page_value, _page_ratio;
135  PN_stdfloat _ratio;
136  bool _resize_thumb;
137  bool _manage_pieces;
138 
139  LVector3 _axis;
140 
141  PT(PGButton) _thumb_button;
142  PT(PGButton) _left_button;
143  PT(PGButton) _right_button;
144 
145  PN_stdfloat _min_x, _max_x, _thumb_width, _range_x;
146  LPoint3 _thumb_start;
147  PGItem *_scroll_button_held;
148  bool _mouse_button_page;
149  LPoint2 _mouse_pos;
150  double _next_advance_time;
151  bool _dragging;
152  PN_stdfloat _drag_start_x;
153 
154 public:
155  static TypeHandle get_class_type() {
156  return _type_handle;
157  }
158  static void init_type() {
159  PGItem::init_type();
160  register_type(_type_handle, "PGSliderBar",
161  PGItem::get_class_type());
162  }
163  virtual TypeHandle get_type() const {
164  return get_class_type();
165  }
166  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
167 
168 private:
169  static TypeHandle _type_handle;
170 
171  friend class PGButton;
172 };
173 
174 #include "pgSliderBar.I"
175 
176 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
Definition: pgItem.cxx:386
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:58
This is a particular kind of PGItem that is specialized to behave like a normal button object...
Definition: pgButton.h:32
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
PGItemNotify * get_notify() const
Returns the object which will be notified when the PGItem changes, if any.
Definition: pgItem.I:85
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
virtual void release(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button previously depressed wit...
Definition: pgItem.cxx:726
virtual void move(const MouseWatcherParameter &param)
This is a callback hook function, called whenever a mouse is moved while within the region...
Definition: pgItem.cxx:800
This is a two-component point in space.
Definition: lpoint2.h:92
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition: pgItem.cxx:890
virtual void press(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the m...
Definition: pgItem.cxx:694
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition: pgItem.I:54
This is a particular kind of PGItem that draws a little bar with a slider that moves from left to rig...
Definition: pgSliderBar.h:34