Dragonfly  4.3
A text-based game engine
ViewObject.h
1 ///
2 /// The view object
3 ///
4 
5 #ifndef __VIEW_OBJECT_H__
6 #define __VIEW_OBJECT_H__
7 
8 // System includes.
9 #include <string>
10 
11 // Engine includes.
12 #include "Color.h"
13 #include "Event.h"
14 #include "Object.h"
15 
16 namespace df {
17 
18 /// Count of number of view object modified attribute categories.
19 const int VATTR_COUNT = 6;
20 
21 /// Categories of view object attributes that indicate modification.
23  VIEW_STRING,
24  VALUE,
25  BORDER,
26  COLOR,
27  LOCATION,
28  DRAW_VALUE,
29 };
30 
31 /// General location of ViewObject on screen.
33  UNDEFINED=-1,
34  TOP_LEFT,
35  TOP_CENTER,
36  TOP_RIGHT,
37  CENTER_LEFT,
38  CENTER_CENTER,
39  CENTER_RIGHT,
40  BOTTOM_LEFT,
41  BOTTOM_CENTER,
42  BOTTOM_RIGHT,
43 };
44 
45 class ViewObject : public Object {
46 
47  private:
48  std::string m_view_string; ///< Label for value (e.g., "Points").
49  int m_value; ///< Value displayed (e.g., points).
50  bool m_draw_value; ///< True if should draw value.
51  bool m_border; ///< True if border around display.
52  Color m_color; ///< Color for text (and border).
53  ViewObjectLocation m_location; ///< Location of ViewObject.
54  bool m_vmodified[VATTR_COUNT]; ///< Mod. attrib. since serialize().
55 
56  public:
57  /// Construct ViewObject.
58  /// Object settings: SPECTRAL, max altitude.
59  /// ViewObject defaults: border, top_center, default color, draw_value.
60  ViewObject();
61 
62  /// Draw view string (and value).
63  virtual void draw();
64 
65  /// Handle "view" event if tag matches view_string (others ignored).
66  /// Return 0 if ignored, else 1.
67  virtual int eventHandler(const Event *p_e);
68 
69  /// Set general location of ViewObject on screen.
70  void setLocation(ViewObjectLocation new_location);
71 
72  /// Get general location of ViewObject on screen.
74 
75  /// Set true to draw value with display string.
76  void setDrawValue(bool new_draw_value = true);
77 
78  /// Get draw value (true if draw value with display string).
79  bool getDrawValue() const;
80 
81  /// Set view value.
82  void setValue(int new_value);
83 
84  /// Get view value.
85  int getValue() const;
86 
87  /// Set view border (true = display border).
88  void setBorder(bool new_border);
89 
90  /// Get view border (true = display border).
91  bool getBorder() const;
92 
93  /// Set view color.
94  void setColor(Color new_color);
95 
96  /// Get view color.
97  Color getColor() const;
98 
99  /// Set view display string.
100  void setViewString(std::string new_view_string);
101 
102  /// Get view display string.
103  std::string getViewString() const;
104 
105  /// Set position of ViewObject, with setting "location" to UNDEFINED.
106  void setPosition(Vector new_pos);
107 
108  /// Serialize ViewObject attributes to single string.
109  /// Only modified attributes (unless all is true).
110  virtual std::string serialize(bool all = false);
111 
112  /// Deserialize string to become attributes.
113  /// Rerturn 0 if no errors, else -1.
114  virtual int deserialize(std::string s);
115 
116  /// Return true if attribute modified since last serialize.
117  virtual bool isModified(enum ViewObjectAttribute attribute) const;
118 
119  /// Return true if any attribute modified since last serialize.
120  virtual bool isModified() const;
121 };
122 
123 } // end of namespace df
124 #endif // __VIEW_OBJECT_H__
Definition: ViewObject.h:45
void setDrawValue(bool new_draw_value=true)
Set true to draw value with display string.
ViewObjectLocation m_location
Location of ViewObject.
Definition: ViewObject.h:53
virtual int eventHandler(const Event *p_e)
Handle "view" event if tag matches view_string (others ignored).
void setValue(int new_value)
Set view value.
std::string getViewString() const
Get view display string.
Definition: Event.h:15
bool m_draw_value
True if should draw value.
Definition: ViewObject.h:50
A 2-d bounding box.
Definition: Box.h:10
void setLocation(ViewObjectLocation new_location)
Set general location of ViewObject on screen.
Color getColor() const
Get view color.
bool m_border
True if border around display.
Definition: ViewObject.h:51
int getValue() const
Get view value.
void setViewString(std::string new_view_string)
Set view display string.
void setBorder(bool new_border)
Set view border (true = display border).
virtual bool isModified() const
Return true if any attribute modified since last serialize.
Definition: Object.h:59
ViewObjectLocation
General location of ViewObject on screen.
Definition: ViewObject.h:32
bool getBorder() const
Get view border (true = display border).
std::string m_view_string
Label for value (e.g., "Points").
Definition: ViewObject.h:48
int m_value
Value displayed (e.g., points).
Definition: ViewObject.h:49
ViewObjectAttribute
Categories of view object attributes that indicate modification.
Definition: ViewObject.h:22
Color
Colors Dragonfly recognizes.
Definition: Color.h:11
ViewObjectLocation getLocation() const
Get general location of ViewObject on screen.
void setPosition(Vector new_pos)
Set position of ViewObject, with setting "location" to UNDEFINED.
Color m_color
Color for text (and border).
Definition: ViewObject.h:52
bool getDrawValue() const
Get draw value (true if draw value with display string).
virtual int deserialize(std::string s)
Deserialize string to become attributes.
bool m_vmodified[VATTR_COUNT]
Mod. attrib. since serialize().
Definition: ViewObject.h:54
void setColor(Color new_color)
Set view color.
const int VATTR_COUNT
Count of number of view object modified attribute categories.
Definition: ViewObject.h:19
ViewObject()
Construct ViewObject.
Definition: Vector.h:10
virtual std::string serialize(bool all=false)
Serialize ViewObject attributes to single string.
virtual void draw()
Draw view string (and value).