Panda3D

pgSliderBar.h

00001 // Filename: pgSliderBar.h
00002 // Created by:  masad (19Oct04)
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 PGSLIDERBAR_H
00016 #define PGSLIDERBAR_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pgItem.h"
00021 #include "pgSliderBarNotify.h"
00022 #include "pgButtonNotify.h"
00023 #include "pgButton.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : PGSliderBar
00027 // Description : This is a particular kind of PGItem that draws a
00028 //               little bar with a slider that moves from left to 
00029 //               right indicating a value between the ranges.
00030 //
00031 //               This is used as an implementation for both
00032 //               DirectSlider and for DirectScrollBar.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_PGUI PGSliderBar : public PGItem, public PGButtonNotify {
00035 PUBLISHED:
00036   PGSliderBar(const string &name = "");
00037   virtual ~PGSliderBar();
00038 
00039 protected:
00040   PGSliderBar(const PGSliderBar &copy);
00041 
00042 public:
00043   virtual PandaNode *make_copy() const;
00044   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00045   virtual void xform(const LMatrix4 &mat);
00046 
00047   virtual void press(const MouseWatcherParameter &param, bool background);
00048   virtual void release(const MouseWatcherParameter &param, bool background);
00049   virtual void move(const MouseWatcherParameter &param);
00050 
00051   virtual void adjust();
00052 
00053   INLINE void set_notify(PGSliderBarNotify *notify);
00054   INLINE PGSliderBarNotify *get_notify() const;
00055 
00056 PUBLISHED:
00057   void setup_scroll_bar(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel);
00058   void setup_slider(bool vertical, PN_stdfloat length, PN_stdfloat width, PN_stdfloat bevel);
00059 
00060   INLINE void set_axis(const LVector3 &axis);
00061   INLINE const LVector3 &get_axis() const;
00062 
00063   INLINE void set_range(PN_stdfloat min_value, PN_stdfloat max_value);
00064   INLINE PN_stdfloat get_min_value() const;
00065   INLINE PN_stdfloat get_max_value() const;
00066 
00067   INLINE void set_scroll_size(PN_stdfloat scroll_size);
00068   INLINE PN_stdfloat get_scroll_size() const;
00069 
00070   INLINE void set_page_size(PN_stdfloat page_size);
00071   INLINE PN_stdfloat get_page_size() const;
00072 
00073   INLINE void set_value(PN_stdfloat value);
00074   INLINE PN_stdfloat get_value() const;
00075 
00076   INLINE void set_ratio(PN_stdfloat ratio);
00077   INLINE PN_stdfloat get_ratio() const;
00078 
00079   INLINE bool is_button_down() const;
00080 
00081   INLINE void set_resize_thumb(bool resize_thumb);
00082   INLINE bool get_resize_thumb() const;
00083 
00084   INLINE void set_manage_pieces(bool manage_pieces);
00085   INLINE bool get_manage_pieces() const;
00086 
00087   INLINE void set_thumb_button(PGButton *thumb_button);
00088   INLINE void clear_thumb_button();
00089   INLINE PGButton *get_thumb_button() const;
00090 
00091   INLINE void set_left_button(PGButton *left_button);
00092   INLINE void clear_left_button();
00093   INLINE PGButton *get_left_button() const;
00094 
00095   INLINE void set_right_button(PGButton *right_button);
00096   INLINE void clear_right_button();
00097   INLINE PGButton *get_right_button() const;
00098 
00099   INLINE static string get_adjust_prefix();
00100   INLINE string get_adjust_event() const;
00101 
00102   virtual void set_active(bool active);
00103 
00104   void remanage();
00105   void recompute();
00106 
00107 protected:
00108   virtual void frame_changed();
00109 
00110   virtual void item_transform_changed(PGItem *item);
00111   virtual void item_frame_changed(PGItem *item);
00112   virtual void item_draw_mask_changed(PGItem *item);
00113   virtual void item_press(PGItem *item, const MouseWatcherParameter &param);
00114   virtual void item_release(PGItem *item, const MouseWatcherParameter &param);
00115   virtual void item_move(PGItem *item, const MouseWatcherParameter &param);
00116 
00117 private:
00118   INLINE void internal_set_ratio(PN_stdfloat ratio);
00119 
00120   void reposition();
00121   void advance_scroll();
00122   void advance_page();
00123   void begin_drag();
00124   void continue_drag();
00125   void end_drag();
00126 
00127 private:
00128   bool _needs_remanage;
00129   bool _needs_recompute;
00130   bool _needs_reposition;
00131 
00132   PN_stdfloat _min_value, _max_value;
00133   PN_stdfloat _scroll_value, _scroll_ratio;
00134   PN_stdfloat _page_value, _page_ratio;
00135   PN_stdfloat _ratio;
00136   bool _resize_thumb;
00137   bool _manage_pieces;
00138 
00139   LVector3 _axis;
00140 
00141   PT(PGButton) _thumb_button;
00142   PT(PGButton) _left_button;
00143   PT(PGButton) _right_button;
00144 
00145   PN_stdfloat _min_x, _max_x, _thumb_width, _range_x;
00146   LPoint3 _thumb_start;
00147   PGItem *_scroll_button_held;
00148   bool _mouse_button_page;
00149   LPoint2 _mouse_pos;
00150   double _next_advance_time;
00151   bool _dragging;
00152   PN_stdfloat _drag_start_x;
00153 
00154 public:
00155   static TypeHandle get_class_type() {
00156     return _type_handle;
00157   }
00158   static void init_type() {
00159     PGItem::init_type();
00160     register_type(_type_handle, "PGSliderBar",
00161                   PGItem::get_class_type());
00162   }
00163   virtual TypeHandle get_type() const {
00164     return get_class_type();
00165   }
00166   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00167 
00168 private:
00169   static TypeHandle _type_handle;
00170 
00171   friend class PGButton;
00172 };
00173 
00174 #include "pgSliderBar.I"
00175 
00176 #endif
 All Classes Functions Variables Enumerations