-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloatingtext.cpp
178 lines (154 loc) · 5.18 KB
/
floatingtext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/////////////////////////////////////////////////////////////////////////////
// Name: FloatingText.cpp
// Purpose: Stores and renders text annotations
// Author: Brad Larsen
// Modified by:
// Created: Sat Nov 27 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "floatingtext.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Default constants
const wxChar* FloatingText::DEFAULT_TEXT = wxT("Text");
const wxRect FloatingText::DEFAULT_RECT = wxRect(0,0,0,0);
const wxByte FloatingText::DEFAULT_FLAGS = DEFAULT_ALIGNMENT;
const wxByte FloatingText::DEFAULT_ALIGNMENT = FloatingText::alignLeft;
// Constructor/Destructor
/// Default Constructor
FloatingText::FloatingText() :
m_text(DEFAULT_TEXT), m_rect(DEFAULT_RECT), m_flags(DEFAULT_FLAGS)
{
//------Last Checked------//
// - Dec 7, 2004
}
/// Primary Constructor
/// @param text Text to set
/// @param rect Bounding rect for the text, in logical co-ordinates
/// @param flags Flags to set (see flags enum)
/// @param fontSetting FontSetting object to set
FloatingText::FloatingText(const wxChar* text, wxRect rect, wxByte flags,
const FontSetting& fontSetting) : m_text(text), m_rect(rect),
m_flags(flags), m_fontSetting(fontSetting)
{
//------Last Checked------//
// - Dec 7, 2004
wxASSERT(text != NULL);
}
/// Copy Constructor
FloatingText::FloatingText(const FloatingText& floatingText) :
m_text(DEFAULT_TEXT), m_rect(DEFAULT_RECT), m_flags(DEFAULT_FLAGS)
{
//------Last Checked------//
// - Dec 7, 2004
*this = floatingText;
}
/// Destructor
FloatingText::~FloatingText()
{
//------Last Checked------//
// - Dec 7, 2004
}
// Operators
/// Assignment Operator
const FloatingText& FloatingText::operator=(const FloatingText& floatingText)
{
//------Last Checked------//
// - Dec 7, 2004
// Check for assignment to self
if (this != &floatingText)
{
m_text = floatingText.m_text;
m_rect = floatingText.m_rect;
m_flags = floatingText.m_flags;
m_fontSetting = floatingText.m_fontSetting;
}
return (*this);
}
/// Equality Operator
bool FloatingText::operator==(const FloatingText& floatingText) const
{
//------Last Checked------//
// - Dec 6, 2004
return (
(m_text == floatingText.m_text) &&
(m_rect == floatingText.m_rect) &&
(m_flags == floatingText.m_flags) &&
(m_fontSetting == floatingText.m_fontSetting)
);
}
/// Inequality Operator
bool FloatingText::operator!=(const FloatingText& floatingText) const
{
//------Last Checked------//
// - Dec 6, 2004
return (!operator==(floatingText));
}
/// Performs serialization for the class
/// @param stream Power Tab output stream to serialize to
/// @return True if the object was serialized, false if not
bool FloatingText::DoSerialize(PowerTabOutputStream & stream)
{
//------Last Checked------//
// - Dec 7, 2004
stream.WriteMFCString(m_text);
wxCHECK(stream.CheckState(), false);
stream.WriteMFCRect(m_rect);
wxCHECK(stream.CheckState(), false);
stream << m_flags;
wxCHECK(stream.CheckState(), false);
m_fontSetting.Serialize(stream);
wxCHECK(stream.CheckState(), false);
return (stream.CheckState());
}
/// Performs deserialization for the class
/// @param stream Power Tab input stream to load from
/// @param version File version
/// @return True if the object was deserialized, false if not
bool FloatingText::DoDeserialize(PowerTabInputStream & stream, wxWord version)
{
//------Last Checked------//
// - Dec 7, 2004
stream.ReadMFCString(m_text);
wxCHECK(stream.CheckState(), false);
stream.ReadMFCRect(m_rect);
wxCHECK(stream.CheckState(), false);
stream >> m_flags;
wxCHECK(stream.CheckState(), false);
m_fontSetting.Deserialize(stream, version);
wxCHECK(stream.CheckState(), false);
return (stream.CheckState());
}
// Flag Functions
/// Sets a flag used by the FloatingText object
/// @param flag The flag to set
void FloatingText::SetFlag(wxByte flag)
{
//------Last Checked------//
// - Dec 7, 2004
// Clear old alignment flag if new flag is alignment flag
if (((flag & alignLeft) == alignLeft) |
((flag & alignCenter) == alignCenter) |
((flag & alignRight) == alignRight))
{
ClearFlag(alignMask);
}
m_flags |= flag;
}
/// Gets the rect used to draw the border surrounding the text
/// @return The rect used to draw the border surrounding the text
wxRect FloatingText::GetBorderRect() const
{
//------Last Checked------//
// - Dec 7, 2004
wxRect returnValue;
returnValue.SetLeft(m_rect.GetLeft() - 2);
returnValue.SetTop(m_rect.GetTop() - 1);
returnValue.SetRight(m_rect.GetRight() + 1);
returnValue.SetBottom(m_rect.GetBottom() + 1);
return (returnValue);
}