Panda3D

textPropertiesManager.h

00001 // Filename: textPropertiesManager.h
00002 // Created by:  drose (07Apr04)
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 TEXTPROPERTIESMANAGER_H
00016 #define TEXTPROPERTIESMANAGER_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "config_text.h"
00021 #include "textProperties.h"
00022 #include "textGraphic.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : TextPropertiesManager
00026 // Description : This defines all of the TextProperties structures
00027 //               that might be referenced by name from an embedded
00028 //               text string.
00029 //
00030 //               A text string, as rendered by a TextNode, can contain
00031 //               embedded references to one of the TextProperties
00032 //               defined here, by enclosing the name between \1 (ASCII
00033 //               0x01) characters; this causes a "push" to the named
00034 //               state.  All text following the closing \1 character
00035 //               will then be rendered in the new state.  The next \2
00036 //               (ASCII 0x02) character will then restore the previous
00037 //               state for subsequent text.
00038 //
00039 //               For instance, "x\1up\1n\2 + y" indicates that the
00040 //               character "x" will be rendered in the normal state,
00041 //               the character "n" will be rendered in the "up" state,
00042 //               and then " + y" will be rendered in the normal state
00043 //               again.
00044 //
00045 //               This can also be used to define arbitrary models that
00046 //               can serve as embedded graphic images in a text
00047 //               paragraph.  This works similarly; the convention is
00048 //               to create a TextGraphic that describes the graphic
00049 //               image, and then associate it here via the
00050 //               set_graphic() call.  Then "\5name\5" will embed the
00051 //               named graphic.
00052 ////////////////////////////////////////////////////////////////////
00053 class EXPCL_PANDA_TEXT TextPropertiesManager {
00054 protected:
00055   TextPropertiesManager();
00056   ~TextPropertiesManager();
00057 
00058 PUBLISHED:
00059   void set_properties(const string &name, const TextProperties &properties);
00060   TextProperties get_properties(const string &name);
00061   bool has_properties(const string &name) const;
00062   void clear_properties(const string &name);
00063 
00064   void set_graphic(const string &name, const TextGraphic &graphic);
00065   void set_graphic(const string &name, const NodePath &model);
00066   TextGraphic get_graphic(const string &name);
00067   bool has_graphic(const string &name) const;
00068   void clear_graphic(const string &name);
00069 
00070   void write(ostream &out, int indent_level = 0) const;
00071 
00072   static TextPropertiesManager *get_global_ptr();
00073 
00074 public:
00075   const TextProperties *get_properties_ptr(const string &name);
00076   const TextGraphic *get_graphic_ptr(const string &name);
00077 
00078 private:
00079   typedef pmap<string, TextProperties> Properties;
00080   Properties _properties;
00081 
00082   typedef pmap<string, TextGraphic> Graphics;
00083   Graphics _graphics;
00084 
00085   static TextPropertiesManager *_global_ptr;
00086 };
00087 
00088 #include "textPropertiesManager.I"
00089 
00090 #endif
 All Classes Functions Variables Enumerations