Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgui/pgEntry.h

Go to the documentation of this file.
00001 // Filename: pgEntry.h
00002 // Created by:  drose (13Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef PGENTRY_H
00020 #define PGENTRY_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pgItem.h"
00025 
00026 #include "textNode.h"
00027 #include "pointerTo.h"
00028 #include "pvector.h"
00029 #include "clockObject.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : PGEntry
00033 // Description : This is a particular kind of PGItem that handles
00034 //               simple one-line text entries, of the sort where the
00035 //               user can type any string.
00036 //
00037 //               A PGEntry does all of its internal manipulation on a
00038 //               wide string, so it can store the full Unicode
00039 //               character set.  The interface can support either the
00040 //               wide string getters and setters, or the normal 8-bit
00041 //               string getters and setters, which use whatever
00042 //               encoding method is specified by the associated
00043 //               TextNode.
00044 ////////////////////////////////////////////////////////////////////
00045 class EXPCL_PANDA PGEntry : public PGItem {
00046 PUBLISHED:
00047   PGEntry(const string &name);
00048   virtual ~PGEntry();
00049 
00050 protected:
00051   PGEntry(const PGEntry &copy);
00052 
00053 public:
00054   virtual PandaNode *make_copy() const;
00055   virtual bool has_cull_callback() const;
00056   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00057 
00058   virtual void press(const MouseWatcherParameter &param, bool background);
00059   virtual void keystroke(const MouseWatcherParameter &param, bool background);
00060 
00061   virtual void accept(const MouseWatcherParameter &param);
00062   virtual void overflow(const MouseWatcherParameter &param);
00063   virtual void type(const MouseWatcherParameter &param);
00064   virtual void erase(const MouseWatcherParameter &param);
00065 
00066 PUBLISHED:
00067   enum State {
00068     S_focus = 0,
00069     S_no_focus,
00070     S_inactive
00071   };
00072 
00073   void setup(float width, int num_lines);
00074 
00075   INLINE void set_text(const string &text);
00076   INLINE string get_text() const;
00077 
00078   INLINE void set_cursor_position(int position);
00079   INLINE int get_cursor_position() const;
00080 
00081   INLINE void set_max_chars(int max_chars);
00082   INLINE int get_max_chars() const;
00083   INLINE void set_max_width(float max_width);
00084   INLINE float get_max_width() const;
00085   INLINE void set_num_lines(int num_lines);
00086   INLINE int get_num_lines() const;
00087 
00088   INLINE void set_blink_rate(float blink_rate);
00089   INLINE float get_blink_rate() const;
00090 
00091   INLINE const NodePath &get_cursor_def();
00092   INLINE void clear_cursor_def();
00093 
00094   INLINE void set_cursor_keys_active(bool flag);
00095   INLINE bool get_cursor_keys_active() const;
00096 
00097   INLINE void set_obscure_mode(bool flag);
00098   INLINE bool get_obscure_mode() const;
00099 
00100   void set_text_def(int state, TextNode *node);
00101   TextNode *get_text_def(int state) const;
00102 
00103   virtual void set_active(bool active);
00104   virtual void set_focus(bool focus);
00105 
00106   INLINE static string get_accept_prefix();
00107   INLINE static string get_overflow_prefix();
00108   INLINE static string get_type_prefix();
00109   INLINE static string get_erase_prefix();
00110 
00111   INLINE string get_accept_event(const ButtonHandle &button) const;
00112   INLINE string get_overflow_event() const;
00113   INLINE string get_type_event() const;
00114   INLINE string get_erase_event() const;
00115 
00116 public:
00117   INLINE void set_wtext(const wstring &wtext);
00118   INLINE const wstring &get_wtext() const;
00119 
00120 
00121 private:
00122   const wstring &get_display_wtext();
00123   void slot_text_def(int state);
00124   void update_text();
00125   void update_cursor();
00126   void show_hide_cursor(bool visible);
00127   void update_state();
00128 
00129   wstring _wtext;
00130   wstring _obscured_wtext;
00131   int _cursor_position;
00132   bool _cursor_stale;
00133   bool _cursor_visible;
00134 
00135   int _max_chars;
00136   float _max_width;
00137   int _num_lines;
00138 
00139   typedef pvector< PT(TextNode) > TextDefs;
00140   TextDefs _text_defs;
00141 
00142   // This is the subgraph that renders both the text and the cursor.
00143   NodePath _text_render_root;
00144 
00145   // This is the node for rendering the actual text that is parented
00146   // to the above node when the text is generated.
00147   NodePath _current_text;
00148   TextNode *_last_text_def;
00149   bool _text_geom_stale;
00150 
00151   // This is a list of each row of text in the entry, after it has
00152   // been wordwrapped by update_text().  It's used by update_cursor()
00153   // to compute the correct cursor position.
00154   class WWLine {
00155   public:
00156     wstring _str;
00157     float _left;
00158   };
00159   typedef pvector<WWLine> WWLines;
00160   WWLines _ww_lines;
00161 
00162   // This is the node that represents the cursor geometry.  It is also
00163   // attached to the above node, and is transformed around and/or
00164   // hidden according to the cursor's position and blink state.
00165   NodePath _cursor_def;
00166 
00167   double _blink_start;
00168   double _blink_rate;
00169 
00170   bool _cursor_keys_active;
00171   bool _obscure_mode;
00172 
00173 public:
00174   static TypeHandle get_class_type() {
00175     return _type_handle;
00176   }
00177   static void init_type() {
00178     PGItem::init_type();
00179     register_type(_type_handle, "PGEntry",
00180                   PGItem::get_class_type());
00181   }
00182   virtual TypeHandle get_type() const {
00183     return get_class_type();
00184   }
00185   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00186 
00187 private:
00188   static TypeHandle _type_handle;
00189 };
00190 
00191 #include "pgEntry.I"
00192 
00193 #endif

Generated on Fri May 2 00:42:38 2003 for Panda by doxygen1.3