Panda3D
Loading...
Searching...
No Matches
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 */
31class EXPCL_PANDA_PGUI PGSliderBar : public PGItem, public PGButtonNotify {
32PUBLISHED:
33 explicit PGSliderBar(const std::string &name = "");
34 virtual ~PGSliderBar();
35
36protected:
37 PGSliderBar(const PGSliderBar &copy);
38
39public:
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
53PUBLISHED:
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
104protected:
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
114private:
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
124private:
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
151public:
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
165private:
166 static TypeHandle _type_handle;
167
168 friend class PGButton;
169};
170
171#include "pgSliderBar.I"
172
173#endif
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition pgItem.I:43
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:674
PGItemNotify * get_notify() const
Returns the object which will be notified when the PGItem changes, if any.
Definition pgItem.I:69
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:703
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:770
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition pgItem.cxx:851
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
void setup_scroll_bar(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel)
Creates PGSliderBar that represents a vertical or horizontal scroll bar (if vertical is true or false...
PN_stdfloat get_scroll_size() const
Returns the value last set by set_scroll_size().
void set_resize_thumb(bool resize_thumb)
Sets the resize_thumb flag.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
void clear_left_button()
Removes the left button object from control of the frame.
const LVector3 & get_axis() const
Returns the axis of the slider bar's motion.
Definition pgSliderBar.I:59
bool get_manage_pieces() const
Returns the manage_pieces flag.
bool is_button_down() const
Returns true if the user is currently holding down the mouse button to manipulate the slider.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
void set_scroll_size(PN_stdfloat scroll_size)
Specifies the amount the slider will move when the user clicks on the left or right buttons.
void set_page_size(PN_stdfloat page_size)
Specifies the amount of data contained in a single page.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so.
void remanage()
Manages the position and size of the scroll bars and the thumb.
PN_stdfloat get_max_value() const
Returns the value when the slider is all the way to the right.
Definition pgSliderBar.I:93
void setup_slider(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel)
Creates PGSliderBar that represents a slider that the user can use to control an analog quantity.
void set_thumb_button(PGButton *thumb_button)
Sets the PGButton object that will serve as the thumb for this slider.
virtual void adjust()
This is a callback hook function, called whenever the slider value is adjusted by the user or program...
void set_axis(const LVector3 &axis)
Specifies the axis of the slider bar's motion.
Definition pgSliderBar.I:48
PN_stdfloat get_value() const
Returns the current value of the slider.
void set_ratio(PN_stdfloat ratio)
Sets the current value of the slider, expressed in the range 0 .
PGButton * get_thumb_button() const
Returns the PGButton that serves as the thumb for this slider, or NULL if it is not set.
static std::string get_adjust_prefix()
Returns the prefix that is used to define the adjust event for all PGSliderBars.
void set_left_button(PGButton *left_button)
Sets the PGButton object that will serve as the left scroll button for this slider.
PGButton * get_right_button() const
Returns the PGButton that serves as the right scroll button for this slider, if any,...
void clear_thumb_button()
Removes the thumb button object from control of the frame.
PN_stdfloat get_page_size() const
Returns the value last set by set_page_size().
PN_stdfloat get_ratio() const
Returns the current value of the slider, expressed in the range 0 .
bool get_resize_thumb() const
Returns the resize_thumb flag.
void set_range(PN_stdfloat min_value, PN_stdfloat max_value)
Sets the minimum and maxmimum value for the slider.
Definition pgSliderBar.I:68
void set_manage_pieces(bool manage_pieces)
Sets the manage_pieces flag.
void clear_right_button()
Removes the right button object from control of the frame.
std::string get_adjust_event() const
Returns the event name that will be thrown when the slider bar value is adjusted by the user or progr...
PGButton * get_left_button() const
Returns the PGButton that serves as the left scroll button for this slider, if any,...
void recompute()
Recomputes the position and size of the thumb.
void set_right_button(PGButton *right_button)
Sets the PGButton object that will serve as the right scroll button for this slider.
void set_value(PN_stdfloat value)
Sets the current value of the slider programmatically.
PN_stdfloat get_min_value() const
Returns the value when the slider is all the way to the left.
Definition pgSliderBar.I:84
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...