1212
1313#include " StdInc.h"
1414
15- unsigned long ulUniqueId = 0 ;
15+ static unsigned long ulUniqueId = 0 ;
1616
1717CTextItem::CTextItem ( const char * szText, const CVector2D& vecPosition, eTextPriority Priority, const SColor color, float fScale , unsigned char ucFormat, unsigned char ucShadowAlpha )
1818{
1919 // Assign us an unique ID
2020 m_ulUniqueId = ulUniqueId++;
2121
2222 // Copy the text
23- if ( szText )
24- {
25- m_szText = new char [ strlen ( szText ) + 1 ];
26- strcpy ( m_szText, szText );
27- }
28- else
29- {
30- m_szText = new char [1 ];
31- m_szText [0 ] = 0 ;
32- }
23+ m_strText = szText ? szText : " " ;
3324
3425 // Assign the properties
3526 m_vecPosition = vecPosition;
@@ -45,16 +36,7 @@ CTextItem::CTextItem ( const char* szText, const CVector2D& vecPosition, eTextPr
4536CTextItem::CTextItem ( const CTextItem& TextItem )
4637{
4738 // Copy the tex
48- if ( TextItem.m_szText )
49- {
50- m_szText = new char [strlen ( TextItem.m_szText ) + 1 ];
51- strcpy ( m_szText, TextItem.m_szText );
52- }
53- else
54- {
55- m_szText = new char [1 ];
56- m_szText [0 ] = 0 ;
57- }
39+ m_strText = TextItem.m_strText ;
5840
5941 // Copy over the properties
6042 m_ulUniqueId = TextItem.m_ulUniqueId ;
@@ -70,19 +52,8 @@ CTextItem::CTextItem ( const CTextItem& TextItem )
7052
7153bool CTextItem::operator = ( const CTextItem& TextItem )
7254{
73- // Delete the previous title buffer and copy the buffer in the text item given
74- if ( m_szText ) delete [] m_szText;
75-
76- if ( TextItem.m_szText )
77- {
78- m_szText = new char [strlen ( TextItem.m_szText ) + 1 ];
79- strcpy ( m_szText, TextItem.m_szText );
80- }
81- else
82- {
83- m_szText = new char [1 ];
84- m_szText [0 ] = 0 ;
85- }
55+ // Copy the new text
56+ m_strText = TextItem.m_strText ;
8657
8758 // Copy the properties
8859 m_ulUniqueId = TextItem.m_ulUniqueId ;
@@ -104,13 +75,6 @@ CTextItem::~CTextItem ( )
10475 // Tell all our observers about it
10576 m_bDeletable = true ;
10677 NotifyObservers ();
107-
108- // Delete our text
109- if ( m_szText )
110- {
111- delete [] m_szText;
112- m_szText = NULL ;
113- }
11478}
11579
11680
@@ -137,31 +101,15 @@ void CTextItem::NotifyObservers ( void )
137101
138102void CTextItem::SetText ( const char * szText )
139103{
140- // If the text is the same, don't bother
141- if ( m_szText && strcmp ( m_szText, szText ) == 0 )
104+ // If the text has changed
105+ if ( m_strText != szText )
142106 {
143- return ;
144- }
107+ // Update
108+ m_strText = szText;
145109
146- // Delete the previous buffer if neccessary
147- if ( m_szText )
148- {
149- delete [] m_szText;
110+ // Tell the text displays
111+ NotifyObservers ();
150112 }
151-
152- // Allocate and copy the new text
153- m_szText = new char [strlen ( szText ) + 1 ];
154- strcpy ( m_szText, szText );
155-
156- // Tell the text displays
157- NotifyObservers ();
158- }
159-
160-
161- char * CTextItem::GetText ( char * pBuffer, size_t bufferSize )
162- {
163- strncpy ( pBuffer, m_szText, bufferSize );
164- return pBuffer;
165113}
166114
167115
@@ -193,7 +141,6 @@ void CTextItem::SetColor ( const SColor color )
193141}
194142
195143
196-
197144void CTextItem::SetScale ( float fScale )
198145{
199146 // If the scale has changed
0 commit comments