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 */
31 class EXPCL_PANDA_PGUI PGSliderBar : public PGItem, public PGButtonNotify {
32PUBLISHED:
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
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
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
CullTraverser
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition cullTraverser.h:45
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::set_notify
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition pgItem.I:43
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:674
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::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:703
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:770
PGItem::set_active
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition pgItem.cxx:851
PGSliderBarNotify
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
Definition pgSliderBarNotify.h:26
PGSliderBar::setup_scroll_bar
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...
Definition pgSliderBar.cxx:250
PGSliderBar::get_scroll_size
PN_stdfloat get_scroll_size() const
Returns the value last set by set_scroll_size().
Definition pgSliderBar.I:113
PGSliderBar::set_resize_thumb
void set_resize_thumb(bool resize_thumb)
Sets the resize_thumb flag.
Definition pgSliderBar.I:197
PGSliderBar::cull_callback
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition pgSliderBar.cxx:177
PGSliderBar::clear_left_button
void clear_left_button()
Removes the left button object from control of the frame.
Definition pgSliderBar.I:303
PGSliderBar::get_axis
const LVector3 & get_axis() const
Returns the axis of the slider bar's motion.
Definition pgSliderBar.I:59
PGSliderBar::get_manage_pieces
bool get_manage_pieces() const
Returns the manage_pieces flag.
Definition pgSliderBar.I:230
PGSliderBar::is_button_down
bool is_button_down() const
Returns true if the user is currently holding down the mouse button to manipulate the slider.
Definition pgSliderBar.I:185
PGSliderBar::make_copy
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
Definition pgSliderBar.cxx:93
PGSliderBar::set_scroll_size
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.
Definition pgSliderBar.I:103
PGSliderBar::set_page_size
void set_page_size(PN_stdfloat page_size)
Specifies the amount of data contained in a single page.
Definition pgSliderBar.I:125
PGSliderBar::xform
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so.
Definition pgSliderBar.cxx:208
PGSliderBar::remanage
void remanage()
Manages the position and size of the scroll bars and the thumb.
Definition pgSliderBar.cxx:394
PGSliderBar::get_max_value
PN_stdfloat get_max_value() const
Returns the value when the slider is all the way to the right.
Definition pgSliderBar.I:93
PGSliderBar::setup_slider
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.
Definition pgSliderBar.cxx:321
PGSliderBar::set_thumb_button
void set_thumb_button(PGButton *thumb_button)
Sets the PGButton object that will serve as the thumb for this slider.
Definition pgSliderBar.I:244
PGSliderBar::adjust
virtual void adjust()
This is a callback hook function, called whenever the slider value is adjusted by the user or program...
Definition pgSliderBar.cxx:228
PGSliderBar::set_axis
void set_axis(const LVector3 &axis)
Specifies the axis of the slider bar's motion.
Definition pgSliderBar.I:48
PGSliderBar::get_value
PN_stdfloat get_value() const
Returns the current value of the slider.
Definition pgSliderBar.I:154
PGSliderBar::set_ratio
void set_ratio(PN_stdfloat ratio)
Sets the current value of the slider, expressed in the range 0 .
Definition pgSliderBar.I:163
PGSliderBar::get_thumb_button
PGButton * get_thumb_button() const
Returns the PGButton that serves as the thumb for this slider, or NULL if it is not set.
Definition pgSliderBar.I:271
PGSliderBar::get_adjust_prefix
static std::string get_adjust_prefix()
Returns the prefix that is used to define the adjust event for all PGSliderBars.
Definition pgSliderBar.I:364
PGSliderBar::set_left_button
void set_left_button(PGButton *left_button)
Sets the PGButton object that will serve as the left scroll button for this slider.
Definition pgSliderBar.I:285
PGSliderBar::get_right_button
PGButton * get_right_button() const
Returns the PGButton that serves as the right scroll button for this slider, if any,...
Definition pgSliderBar.I:353
PGSliderBar::clear_thumb_button
void clear_thumb_button()
Removes the thumb button object from control of the frame.
Definition pgSliderBar.I:262
PGSliderBar::get_page_size
PN_stdfloat get_page_size() const
Returns the value last set by set_page_size().
Definition pgSliderBar.I:135
PGSliderBar::get_ratio
PN_stdfloat get_ratio() const
Returns the current value of the slider, expressed in the range 0 .
Definition pgSliderBar.I:174
PGSliderBar::get_resize_thumb
bool get_resize_thumb() const
Returns the resize_thumb flag.
Definition pgSliderBar.I:207
PGSliderBar::set_range
void set_range(PN_stdfloat min_value, PN_stdfloat max_value)
Sets the minimum and maxmimum value for the slider.
Definition pgSliderBar.I:68
PGSliderBar::set_manage_pieces
void set_manage_pieces(bool manage_pieces)
Sets the manage_pieces flag.
Definition pgSliderBar.I:219
PGSliderBar::clear_right_button
void clear_right_button()
Removes the right button object from control of the frame.
Definition pgSliderBar.I:344
PGSliderBar::get_adjust_event
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...
Definition pgSliderBar.I:373
PGSliderBar::get_left_button
PGButton * get_left_button() const
Returns the PGButton that serves as the left scroll button for this slider, if any,...
Definition pgSliderBar.I:312
PGSliderBar::recompute
void recompute()
Recomputes the position and size of the thumb.
Definition pgSliderBar.cxx:442
PGSliderBar::set_right_button
void set_right_button(PGButton *right_button)
Sets the PGButton object that will serve as the right scroll button for this slider.
Definition pgSliderBar.I:326
PGSliderBar::set_value
void set_value(PN_stdfloat value)
Sets the current value of the slider programmatically.
Definition pgSliderBar.I:145
PGSliderBar::get_min_value
PN_stdfloat get_min_value() const
Returns the value when the slider is all the way to the left.
Definition pgSliderBar.I:84
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pgButtonNotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pgButton.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pgItem.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pgSliderBarNotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pgSliderBar.I
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