Dragonfly 4.20
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
16namespace df {
17
18/// Categories of ViewObject attributes that indicate modification.
19enum class ViewObjectAttribute : unsigned int {
20 VALUE = 1 << (ObjectAttributeMax + 0), // 01
21 APPEARANCE = 1 << (ObjectAttributeMax + 1), // 10
22};
23const int ViewObjectAttributeMax = ObjectAttributeMax + 2;
24
25/// General location on screen.
27 UNDEFINED=-1,
28 TOP_LEFT,
29 TOP_CENTER,
30 TOP_RIGHT,
31 CENTER_LEFT,
32 CENTER_CENTER,
33 CENTER_RIGHT,
34 BOTTOM_LEFT,
35 BOTTOM_CENTER,
36 BOTTOM_RIGHT,
37};
38
39class ViewObject : public Object {
40
41 private:
42 std::string m_view_string; ///< Label for value (e.g., "Points").
43 int m_value; ///< Value displayed (e.g., points).
44 bool m_draw_value; ///< True if should draw value.
45 bool m_border; ///< True if border around display.
46 Color m_color; ///< Color for text (and border).
47 ViewObjectLocation m_location; ///< Location of ViewObject.
48
49 public:
50 /// Construct ViewObject.
51 /// Object settings: SPECTRAL, max altitude.
52 /// ViewObject defaults: border, top_center, default color, draw_value.
54
55 /// Draw view string (and value).
56 /// Return 0 if ok, negative if not.
57 virtual int draw() override;
58
59 /// Handle "view" event if tag matches view_string (others ignored).
60 /// Return 0 if ignored, else 1.
61 virtual int eventHandler(const Event *p_e) override;
62
63 /// Set general location of ViewObject on screen.
64 virtual void setLocation(ViewObjectLocation new_location);
65
66 /// Get general location of ViewObject on screen.
68
69 /// Set true to draw value with display string.
70 virtual void setDrawValue(bool new_draw_value = true);
71
72 /// Get draw value (true if draw value with display string).
73 bool getDrawValue() const;
74
75 /// Set view value.
76 virtual void setValue(int new_value);
77
78 /// Get view value.
79 int getValue() const;
80
81 /// Set view border (true = display border).
82 virtual void setBorder(bool new_border);
83
84 /// Get view border (true = display border).
85 bool getBorder() const;
86
87 /// Set view color.
88 virtual void setColor(Color new_color);
89
90 /// Get view color.
91 Color getColor() const;
92
93 /// Set view display string.
94 virtual void setViewString(std::string new_view_string);
95
96 /// Get view display string.
97 std::string getViewString() const;
98
99 /// Set position of ViewObject, with setting "location" to UNDEFINED.
100 virtual int setPosition(Vector new_pos) override;
101
102 /// Serialize modified attributes to stream.
103 /// Can specify individual attribute(s) to force (modified or not).
104 /// Default is only modified attributes.
105 /// Clears modified bits for attributes serialized.
106 /// Return 0 if ok, else -1.
107 virtual int serialize(std::stringstream *p_ss, unsigned int attr=0) override;
108
109 /// Deserialize stream to attributes and apply.
110 /// p_ss - incoming stream to deserialize.
111 /// p_a - outgoing bitmask of attributes modified (NULL means no outgoing).
112 /// Return 0 if ok, else -1.
113 virtual int deserialize(std::stringstream *p_ss, unsigned int *p_a=NULL) override;
114
115 /// Return base attributes as string.
116 std::string toString() const;
117
118 /// Compare two ViewObjects.
119 bool operator==(const ViewObject &vo);
120 bool operator!=(const ViewObject &vo);
121};
122
123} // end of namespace df
124#endif // __VIEW_OBJECT_H__
Definition: Event.h:15
Definition: Object.h:57
Definition: Vector.h:12
Definition: ViewObject.h:39
virtual int draw() override
Draw view string (and value).
virtual int setPosition(Vector new_pos) override
Set position of ViewObject, with setting "location" to UNDEFINED.
virtual int eventHandler(const Event *p_e) override
Handle "view" event if tag matches view_string (others ignored).
bool m_draw_value
True if should draw value.
Definition: ViewObject.h:44
bool operator==(const ViewObject &vo)
Compare two ViewObjects.
virtual void setDrawValue(bool new_draw_value=true)
Set true to draw value with display string.
bool getDrawValue() const
Get draw value (true if draw value with display string).
virtual void setLocation(ViewObjectLocation new_location)
Set general location of ViewObject on screen.
int getValue() const
Get view value.
std::string getViewString() const
Get view display string.
virtual void setViewString(std::string new_view_string)
Set view display string.
virtual int deserialize(std::stringstream *p_ss, unsigned int *p_a=NULL) override
Deserialize stream to attributes and apply.
ViewObject()
Construct ViewObject.
virtual void setBorder(bool new_border)
Set view border (true = display border).
std::string m_view_string
Label for value (e.g., "Points").
Definition: ViewObject.h:42
int m_value
Value displayed (e.g., points).
Definition: ViewObject.h:43
virtual int serialize(std::stringstream *p_ss, unsigned int attr=0) override
Serialize modified attributes to stream.
std::string toString() const
Return base attributes as string.
bool getBorder() const
Get view border (true = display border).
bool m_border
True if border around display.
Definition: ViewObject.h:45
ViewObjectLocation m_location
Location of ViewObject.
Definition: ViewObject.h:47
Color getColor() const
Get view color.
ViewObjectLocation getLocation() const
Get general location of ViewObject on screen.
virtual void setValue(int new_value)
Set view value.
Color m_color
Color for text (and border).
Definition: ViewObject.h:46
virtual void setColor(Color new_color)
Set view color.
An animation for a sprite.
Definition: Animation.h:15
Color
Colors Dragonfly recognizes.
Definition: Color.h:11
ViewObjectAttribute
Categories of ViewObject attributes that indicate modification.
Definition: ViewObject.h:19
ViewObjectLocation
General location on screen.
Definition: ViewObject.h:26