15 #include "pgScrollFrame.h" 29 _needs_remanage =
false;
30 _needs_recompute_canvas =
false;
31 _needs_recompute_clip =
false;
32 _has_virtual_frame =
false;
33 _virtual_frame.set(0.0f, 0.0f, 0.0f, 0.0f);
34 _manage_pieces =
false;
36 _horizontal_slider = NULL;
37 _vertical_slider = NULL;
59 _has_virtual_frame(copy._has_virtual_frame),
60 _virtual_frame(copy._virtual_frame),
61 _manage_pieces(copy._manage_pieces),
62 _auto_hide(copy._auto_hide)
64 _needs_remanage =
false;
65 _needs_recompute_canvas =
true;
66 _needs_recompute_clip =
true;
111 if (_manage_pieces && _needs_remanage) {
114 if (_needs_recompute_clip) {
117 if (_needs_recompute_canvas) {
120 return PGVirtualFrame::cull_callback(trav, data);
135 _needs_remanage =
true;
136 _needs_recompute_clip =
true;
146 setup(PN_stdfloat width, PN_stdfloat height,
147 PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top,
148 PN_stdfloat slider_width, PN_stdfloat bevel) {
159 style.
set_type(PGFrameStyle::T_ridge);
163 bevel, height - bevel);
180 horizontal_slider->setup_scroll_bar(
false, width - slider_width - bevel * 2, slider_width, bevel);
181 horizontal_slider->set_transform(TransformState::make_pos(
LVector3::rfu(width / 2.0f - slider_width / 2.0f, 0, slider_width / 2.0f + bevel)));
182 add_child(horizontal_slider);
186 vertical_slider->setup_scroll_bar(
true, width - slider_width - bevel * 2, slider_width, bevel);
187 add_child(vertical_slider);
188 vertical_slider->set_transform(TransformState::make_pos(
LVector3::rfu(width - slider_width / 2.0f - bevel, 0, width / 2.0f + slider_width / 2.0f)));
204 _needs_remanage =
false;
211 bool got_horizontal =
false;
212 PN_stdfloat horizontal_width = 0.0f;
214 got_horizontal =
true;
215 const LVecBase4 &slider_frame = _horizontal_slider->get_frame();
216 horizontal_width = slider_frame[3] - slider_frame[2];
219 bool got_vertical =
false;
220 PN_stdfloat vertical_width = 0.0f;
223 const LVecBase4 &slider_frame = _vertical_slider->get_frame();
224 vertical_width = slider_frame[1] - slider_frame[0];
231 PN_stdfloat clip_width = clip[1] - clip[0];
232 PN_stdfloat clip_height = clip[3] - clip[2];
236 PN_stdfloat virtual_width = virtual_frame[1] - virtual_frame[0];
237 PN_stdfloat virtual_height = virtual_frame[3] - virtual_frame[2];
239 if (virtual_width <= clip_width &&
240 virtual_height <= clip_height) {
242 got_horizontal =
false;
243 got_vertical =
false;
246 if (virtual_width <= clip_width - vertical_width) {
248 got_horizontal =
false;
251 if (virtual_height <= clip_height - horizontal_width) {
253 got_vertical =
false;
256 if (virtual_width <= clip_width) {
257 got_horizontal =
false;
264 if (got_horizontal) {
265 _horizontal_slider->set_overall_hidden(
false);
267 _horizontal_slider->set_overall_hidden(
true);
268 _horizontal_slider->set_ratio(0.0f);
269 horizontal_width = 0.0f;
274 _vertical_slider->set_overall_hidden(
false);
276 _vertical_slider->set_overall_hidden(
true);
277 _vertical_slider->set_ratio(0.0f);
278 vertical_width = 0.0f;
285 _needs_remanage =
false;
289 if (got_horizontal && _horizontal_slider->is_overall_hidden()) {
290 got_horizontal =
false;
291 horizontal_width = 0.0f;
293 if (got_vertical && _vertical_slider->is_overall_hidden()) {
294 got_vertical =
false;
295 vertical_width = 0.0f;
298 if (got_horizontal) {
299 _horizontal_slider->set_frame(clip[0], clip[1] - vertical_width,
300 clip[2], clip[2] + horizontal_width);
301 _horizontal_slider->clear_transform();
304 _vertical_slider->set_frame(clip[1] - vertical_width, clip[1],
305 clip[2] + horizontal_width, clip[3]);
306 _vertical_slider->clear_transform();
321 PGVirtualFrame::frame_changed();
322 _needs_remanage =
true;
323 _needs_recompute_clip =
true;
333 item_transform_changed(
PGItem *) {
335 _needs_recompute_clip =
true;
345 item_frame_changed(
PGItem *) {
347 _needs_recompute_clip =
true;
357 item_draw_mask_changed(
PGItem *) {
359 _needs_remanage =
true;
360 _needs_recompute_clip =
true;
372 _needs_recompute_canvas =
true;
384 _needs_recompute_clip =
false;
385 _needs_recompute_canvas =
true;
389 reduce_region(clip, _horizontal_slider);
390 reduce_region(clip, _vertical_slider);
395 _horizontal_slider->set_page_size((clip[1] - clip[0]) / (_virtual_frame[1] - _virtual_frame[0]));
398 _vertical_slider->set_page_size((clip[3] - clip[2]) / (_virtual_frame[3] - _virtual_frame[2]));
412 _needs_recompute_canvas =
false;
416 PN_stdfloat x = interpolate_canvas(clip[0], clip[1],
417 _virtual_frame[0], _virtual_frame[1],
420 PN_stdfloat y = interpolate_canvas(clip[3], clip[2],
421 _virtual_frame[3], _virtual_frame[2],
434 PN_stdfloat PGScrollFrame::
435 interpolate_canvas(PN_stdfloat clip_min, PN_stdfloat clip_max,
436 PN_stdfloat canvas_min, PN_stdfloat canvas_max,
439 PN_stdfloat t = 0.0f;
444 PN_stdfloat min = clip_min - canvas_min;
445 PN_stdfloat max = clip_max - canvas_max;
447 return min + t * (max - min);
LVecBase4 get_internal_frame(const LVecBase4 &frame) const
Computes the size of the internal frame, given the indicated external frame, appropriate for this kin...
A basic node of the scene graph or data graph.
void set_width(PN_stdfloat x, PN_stdfloat y)
Sets the width parameter, which has meaning only for certain frame types.
PGFrameStyle get_frame_style(int state)
Returns the kind of frame that will be drawn behind the item when it is in the indicated state...
void remove_child(int child_index, Thread *current_thread=Thread::get_current_thread())
Removes the nth child from the node.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
This is the base class for all the various kinds of gui widget objects.
int get_state() const
Returns the "state" of this particular PGItem.
This represents a frame that is rendered as a window onto another (possibly much larger) canvas...
void set_clip_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Sets the bounding rectangle of the clip frame.
void set_type(Type type)
Sets the basic type of frame.
void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Sets the bounding rectangle of the item, in local coordinates.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
static LVector3f rfu(float right, float fwd, float up, CoordinateSystem cs=CS_default)
Returns a vector that is described by its right, forward, and up components, in whatever way the coor...
const LVecBase4 & get_clip_frame() const
Returns the bounding rectangle of the clip frame.
void set_frame_style(int state, const PGFrameStyle &style)
Changes the kind of frame that will be drawn behind the item when it is in the indicated state...
This is a 4-by-4 transform matrix.
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
Sets the dominant color of the frame.
Similar to MutexHolder, but for a light reentrant mutex.
PandaNode * get_canvas_node() const
Returns the special node that holds all of the children that appear in the virtual canvas...
This is the base class for all three-component vectors and points.
void set_state(int state)
Sets the "state" of this particular PGItem.
void clear_state_def(int state)
Resets the NodePath assigned to the indicated state to its initial default, with only a frame represe...
const LVecBase4 & get_frame() const
Returns the bounding rectangle of the item.
TypeHandle is the identifier used to differentiate C++ class types.
PN_stdfloat get_ratio() const
Returns the current value of the slider, expressed in the range 0 .
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Sets the transform that will be applied to this node and below.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
This is a particular kind of PGItem that draws a little bar with a slider that moves from left to rig...