Panda3D

pgScrollFrame.h

00001 // Filename: pgScrollFrame.h
00002 // Created by:  drose (17Aug05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PGSCROLLFRAME_H
00016 #define PGSCROLLFRAME_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pgVirtualFrame.h"
00021 #include "pgSliderBarNotify.h"
00022 #include "pgSliderBar.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : PGScrollFrame
00026 // Description : This is a special kind of frame that pretends to be
00027 //               much larger than it actually is.  You can scroll
00028 //               through the frame, as if you're looking through a
00029 //               window at the larger frame beneath.  All children of
00030 //               this frame node are scrolled and clipped as if they
00031 //               were children of the larger, virtual frame.
00032 //
00033 //               This is implemented as a specialization of
00034 //               PGVirtualFrame, which handles the meat of the virtual
00035 //               canvas.  This class adds automatic support for scroll
00036 //               bars, and restricts the virtual transform to
00037 //               translate only (no scale or rotate).
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_PGUI PGScrollFrame : public PGVirtualFrame, public PGSliderBarNotify {
00040 PUBLISHED:
00041   PGScrollFrame(const string &name = "");
00042   virtual ~PGScrollFrame();
00043 
00044 protected:
00045   PGScrollFrame(const PGScrollFrame &copy);
00046 
00047 public:
00048   virtual PandaNode *make_copy() const;
00049   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00050   virtual void xform(const LMatrix4 &mat);
00051 
00052 PUBLISHED:
00053   void setup(PN_stdfloat width, PN_stdfloat height,
00054              PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top,
00055              PN_stdfloat slider_width, PN_stdfloat bevel);
00056 
00057   INLINE void set_virtual_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top);
00058   INLINE void set_virtual_frame(const LVecBase4 &virtual_frame);
00059   INLINE const LVecBase4 &get_virtual_frame() const;
00060   INLINE bool has_virtual_frame() const;
00061   INLINE void clear_virtual_frame();
00062 
00063   INLINE void set_manage_pieces(bool manage_pieces);
00064   INLINE bool get_manage_pieces() const;
00065 
00066   INLINE void set_auto_hide(bool auto_hide);
00067   INLINE bool get_auto_hide() const;
00068 
00069   INLINE void set_horizontal_slider(PGSliderBar *horizontal_slider);
00070   INLINE void clear_horizontal_slider();
00071   INLINE PGSliderBar *get_horizontal_slider() const;
00072 
00073   INLINE void set_vertical_slider(PGSliderBar *vertical_slider);
00074   INLINE void clear_vertical_slider();
00075   INLINE PGSliderBar *get_vertical_slider() const;
00076 
00077   void remanage();
00078   INLINE void recompute();
00079 
00080 protected:
00081   virtual void frame_changed();
00082 
00083   virtual void item_transform_changed(PGItem *item);
00084   virtual void item_frame_changed(PGItem *item);
00085   virtual void item_draw_mask_changed(PGItem *item);
00086   virtual void slider_bar_adjust(PGSliderBar *slider_bar);
00087 
00088 private:
00089   void recompute_clip();
00090 
00091   void recompute_canvas();
00092   PN_stdfloat interpolate_canvas(PN_stdfloat clip_min, PN_stdfloat clip_max, 
00093                            PN_stdfloat canvas_min, PN_stdfloat canvas_max,
00094                            PGSliderBar *slider_bar);
00095 
00096 private:
00097   bool _needs_remanage;
00098   bool _needs_recompute_clip;
00099   bool _needs_recompute_canvas;
00100 
00101   LVecBase4 _orig_clip_frame;
00102 
00103   bool _has_virtual_frame;
00104   LVecBase4 _virtual_frame;
00105 
00106   bool _manage_pieces;
00107   bool _auto_hide;
00108 
00109   PT(PGSliderBar) _horizontal_slider;
00110   PT(PGSliderBar) _vertical_slider;
00111 
00112 public:
00113   static TypeHandle get_class_type() {
00114     return _type_handle;
00115   }
00116   static void init_type() {
00117     PGVirtualFrame::init_type();
00118     register_type(_type_handle, "PGScrollFrame",
00119                   PGVirtualFrame::get_class_type());
00120   }
00121   virtual TypeHandle get_type() const {
00122     return get_class_type();
00123   }
00124   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00125 
00126 private:
00127   static TypeHandle _type_handle;
00128 };
00129 
00130 #include "pgScrollFrame.I"
00131 
00132 #endif
 All Classes Functions Variables Enumerations