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