Panda3D

pgEntry.h

00001 // Filename: pgEntry.h
00002 // Created by:  drose (13Mar02)
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 PGENTRY_H
00016 #define PGENTRY_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pgItem.h"
00021 
00022 #include "textNode.h"
00023 #include "pointerTo.h"
00024 #include "pvector.h"
00025 #include "clockObject.h"
00026 #include "textAssembler.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : PGEntry
00030 // Description : This is a particular kind of PGItem that handles
00031 //               simple one-line or short multi-line text entries, of
00032 //               the sort where the user can type any string.
00033 //
00034 //               A PGEntry does all of its internal manipulation on a
00035 //               wide string, so it can store the full Unicode
00036 //               character set.  The interface can support either the
00037 //               wide string getters and setters, or the normal 8-bit
00038 //               string getters and setters, which use whatever
00039 //               encoding method is specified by the associated
00040 //               TextNode.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDA_PGUI PGEntry : public PGItem {
00043 PUBLISHED:
00044   PGEntry(const string &name);
00045   virtual ~PGEntry();
00046 
00047 protected:
00048   PGEntry(const PGEntry &copy);
00049 
00050 public:
00051   virtual PandaNode *make_copy() const; 
00052   virtual void xform(const LMatrix4 &mat);
00053   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00054 
00055   virtual void press(const MouseWatcherParameter &param, bool background);
00056   virtual void keystroke(const MouseWatcherParameter &param, bool background);
00057   virtual void candidate(const MouseWatcherParameter &param, bool background);
00058 
00059   virtual void accept(const MouseWatcherParameter &param);
00060   virtual void accept_failed(const MouseWatcherParameter &param);
00061   virtual void overflow(const MouseWatcherParameter &param);
00062   virtual void type(const MouseWatcherParameter &param);
00063   virtual void erase(const MouseWatcherParameter &param);
00064   virtual void cursormove();
00065 
00066 PUBLISHED:
00067   enum State {
00068     S_focus = 0,
00069     S_no_focus,
00070     S_inactive
00071   };
00072 
00073   void setup(PN_stdfloat width, int num_lines);
00074   void setup_minimal(PN_stdfloat width, int num_lines);
00075 
00076   INLINE bool set_text(const string &text);
00077   INLINE string get_plain_text() const;
00078   INLINE string get_text() const;
00079 
00080   INLINE int get_num_characters() const;
00081   INLINE wchar_t get_character(int n) const;
00082   INLINE const TextGraphic *get_graphic(int n) const;
00083   INLINE const TextProperties &get_properties(int n) const;
00084 
00085   INLINE void set_cursor_position(int position);
00086   INLINE int get_cursor_position() const;
00087   
00088   INLINE PN_stdfloat get_cursor_X() const;
00089   INLINE PN_stdfloat get_cursor_Y() const;
00090 
00091   INLINE void set_max_chars(int max_chars);
00092   INLINE int get_max_chars() const;
00093   INLINE void set_max_width(PN_stdfloat max_width);
00094   INLINE PN_stdfloat get_max_width() const;
00095   INLINE void set_num_lines(int num_lines);
00096   INLINE int get_num_lines() const;
00097 
00098   INLINE void set_blink_rate(PN_stdfloat blink_rate);
00099   INLINE PN_stdfloat get_blink_rate() const;
00100 
00101   INLINE NodePath get_cursor_def();
00102   INLINE void clear_cursor_def();
00103 
00104   INLINE void set_cursor_keys_active(bool flag);
00105   INLINE bool get_cursor_keys_active() const;
00106 
00107   INLINE void set_obscure_mode(bool flag);
00108   INLINE bool get_obscure_mode() const;
00109 
00110   INLINE void set_overflow_mode(bool flag);
00111   INLINE bool get_overflow_mode() const;
00112 
00113   INLINE void set_candidate_active(const string &candidate_active);
00114   INLINE const string &get_candidate_active() const;
00115 
00116   INLINE void set_candidate_inactive(const string &candidate_inactive);
00117   INLINE const string &get_candidate_inactive() const;
00118 
00119   void set_text_def(int state, TextNode *node);
00120   TextNode *get_text_def(int state) const;
00121 
00122   virtual void set_active(bool active);
00123   virtual void set_focus(bool focus);
00124 
00125   INLINE static string get_accept_prefix();
00126   INLINE static string get_accept_failed_prefix();
00127   INLINE static string get_overflow_prefix();
00128   INLINE static string get_type_prefix();
00129   INLINE static string get_erase_prefix();
00130   INLINE static string get_cursormove_prefix();
00131 
00132   INLINE string get_accept_event(const ButtonHandle &button) const;
00133   INLINE string get_accept_failed_event(const ButtonHandle &button) const;
00134   INLINE string get_overflow_event() const;
00135   INLINE string get_type_event() const;
00136   INLINE string get_erase_event() const;
00137   INLINE string get_cursormove_event() const;
00138   
00139 
00140   INLINE bool set_wtext(const wstring &wtext);
00141   INLINE wstring get_plain_wtext() const;
00142   INLINE wstring get_wtext() const;
00143   INLINE void set_accept_enabled(bool enabled);
00144   bool is_wtext() const;
00145 
00146 
00147 private:
00148   void slot_text_def(int state);
00149   void update_text();
00150   void update_cursor();
00151   void show_hide_cursor(bool visible);
00152   void update_state();
00153 
00154   TextAssembler _text;
00155   TextAssembler _obscure_text;
00156   int _cursor_position;
00157   bool _cursor_stale;
00158   bool _cursor_visible;
00159 
00160   wstring _candidate_wtext;
00161   size_t _candidate_highlight_start;
00162   size_t _candidate_highlight_end;
00163   size_t _candidate_cursor_pos;
00164 
00165   int _max_chars;
00166   PN_stdfloat _max_width;
00167   int _num_lines;
00168 
00169   bool _accept_enabled;
00170 
00171   string _candidate_active;
00172   string _candidate_inactive;
00173 
00174   typedef pvector< PT(TextNode) > TextDefs;
00175   TextDefs _text_defs;
00176 
00177   // This is the subgraph that renders both the text and the cursor.
00178   NodePath _text_render_root;
00179 
00180   // This is the node for rendering the actual text that is parented
00181   // to the above node when the text is generated.
00182   NodePath _current_text;
00183   TextNode *_last_text_def;
00184   bool _text_geom_stale;
00185   bool _text_geom_flattened;
00186 
00187   // This is the node that represents the cursor geometry.  It is also
00188   // attached to the above node, and is transformed around and/or
00189   // hidden according to the cursor's position and blink state.
00190   NodePath _cursor_scale;
00191   NodePath _cursor_def;
00192 
00193   double _blink_start;
00194   double _blink_rate;
00195 
00196   bool _cursor_keys_active;
00197   bool _obscure_mode;
00198   bool _overflow_mode;
00199 
00200   PN_stdfloat _current_padding;
00201 
00202 public:
00203   static TypeHandle get_class_type() {
00204     return _type_handle;
00205   }
00206   static void init_type() {
00207     PGItem::init_type();
00208     register_type(_type_handle, "PGEntry",
00209                   PGItem::get_class_type());
00210   }
00211   virtual TypeHandle get_type() const {
00212     return get_class_type();
00213   }
00214   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00215 
00216 private:
00217   static TypeHandle _type_handle;
00218 };
00219 
00220 #include "pgEntry.I"
00221 
00222 #endif
 All Classes Functions Variables Enumerations