PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PFont Class Reference

#include <PFont.h>

Inheritance diagram for PFont:
PEBLObjectBase PlatformFont PlatformFont PlatformFont

Public Member Functions

 PFont ()
 Standard constructors:
 
 PFont (const std::string &filename)
 
 PFont (const std::string &filename, int style, int size, PColor fgcolor, PColor bgcolor, bool aa)
 Convenience constructor of PFont:
 
 PFont (const PFont &font)
 Copy constructor of PFont:
 
virtual ~PFont ()
 Copy constructor.
 
virtual bool SetProperty (std::string, Variant v)
 Standard Destructors.
 
virtual Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
virtual std::string ObjectName () const
 
virtual void SetFontFileName (const std::string &name)
 Set methods for all of the data in font.
 
virtual void SetFontStyle (const int style)
 
virtual void SetFontSize (const int size)
 
virtual void SetFontColor (PColor color)
 
virtual void SetBackgroundColor (PColor color)
 
virtual void SetAntiAliased (const bool aa)
 
virtual std::string GetFontFileName () const
 
virtual int GetFontStyle () const
 
virtual int GetFontSize () const
 
virtual PColor GetFontColor () const
 
virtual PColor GetBackgroundColor () const
 
virtual bool GetAntiAliased () const
 
virtual bool IsNormalFont () const
 
virtual bool IsBoldFont () const
 
virtual bool IsItalicFont () const
 
virtual bool IsUnderlineFont () const
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 This sends the font descriptions to the specified stream.
 
PColorGetFontColorPtr () const
 
PColorGetBackgroundColorPtr () const
 

Protected Attributes

std::string mFontFileName
 
int mFontStyle
 
int mFontSize
 
bool mAntiAliased
 
- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 

Detailed Description

Definition at line 52 of file PFont.h.

Constructor & Destructor Documentation

◆ PFont() [1/4]

PFont::PFont ( )

Standard constructors:

Standard constructor of PFont.

Definition at line 39 of file PFont.cpp.

39 :
40 mFontFileName("Vera.ttf"),
42 mFontSize(16),
43 mAntiAliased(false)
44
45{
46 mCDT = CDT_FONT;
47
53 InitializeProperty("NAME", Variant("<FONT>"));
54
55 // Store colors ONLY in property map (like PDrawObject, PCanvas, PWindow)
56 // Create new color objects for property storage
57 counted_ptr<PEBLObjectBase> fgColor(new PColor(0,0,0,255));
58 PComplexData * pcd = new PComplexData(fgColor);
59 Variant col = Variant(pcd);
60 delete pcd;
61 pcd=NULL;
62 InitializeProperty("FGCOLOR", col);
63
64 counted_ptr<PEBLObjectBase> bgColor(new PColor(0,0,0,255));
65 pcd = new PComplexData(bgColor);
66 col = Variant(pcd);
67 delete pcd;
68 pcd=NULL;
69 InitializeProperty("BGCOLOR", col);
70
72}
#define NULL
Definition BinReloc.cpp:317
@ CDT_FONT
Definition PEBLObject.h:52
@ PFS_Normal
Definition PFont.h:45
virtual bool InitializeProperty(std::string name, Variant v)
ComplexDataType mCDT
Definition PEBLObject.h:109
int mFontStyle
Definition PFont.h:105
int mFontSize
Definition PFont.h:106
virtual bool IsItalicFont() const
Definition PFont.cpp:373
std::string mFontFileName
Definition PFont.h:104
virtual bool IsUnderlineFont() const
Definition PFont.cpp:379
virtual bool IsBoldFont() const
Definition PFont.cpp:367
bool mAntiAliased
Definition PFont.h:110

References CDT_FONT, PEBLObjectBase::InitializeProperty(), IsBoldFont(), IsItalicFont(), IsUnderlineFont(), mAntiAliased, PEBLObjectBase::mCDT, mFontFileName, mFontSize, and NULL.

◆ PFont() [2/4]

PFont::PFont ( const std::string &  filename)

◆ PFont() [3/4]

PFont::PFont ( const std::string &  filename,
int  style,
int  size,
PColor  fgcolor,
PColor  bgcolor,
bool  aa 
)

Convenience constructor of PFont:

Definition at line 76 of file PFont.cpp.

76 :
77 mFontFileName(filename),
78 mFontStyle(style),
79 mFontSize(size),
80 mAntiAliased(aa)
81{
82 mCDT = CDT_FONT;
83
84 InitializeProperty("NAME", Variant("<FONT>"));
90
91 // Store colors ONLY in property map
92 counted_ptr<PEBLObjectBase> fgColorPtr(new PColor(fgcolor));
93 PComplexData * pcd = new PComplexData(fgColorPtr);
94 Variant col = Variant(pcd);
95 delete pcd;
96 pcd=NULL;
97 InitializeProperty("FGCOLOR", col);
98
99 counted_ptr<PEBLObjectBase> bgColorPtr(new PColor(bgcolor));
100 pcd = new PComplexData(bgColorPtr);
101 col = Variant(pcd);
102 delete pcd;
103 pcd=NULL;
104 InitializeProperty("BGCOLOR", col);
105
106 InitializeProperty("ANTIALIASED", Variant(mAntiAliased));
107}

References CDT_FONT, PEBLObjectBase::InitializeProperty(), IsBoldFont(), IsItalicFont(), IsUnderlineFont(), mAntiAliased, PEBLObjectBase::mCDT, mFontFileName, mFontSize, and NULL.

◆ PFont() [4/4]

PFont::PFont ( const PFont font)

Copy constructor of PFont:

Definition at line 111 of file PFont.cpp.

113{
114 mCDT = CDT_FONT;
115
117 mFontStyle = font.GetFontStyle();
118 mFontSize = font.GetFontSize();
120
126 InitializeProperty("NAME", Variant("<FONT>"));
127
128 // Store colors ONLY in property map - copy from source font
129 PColor fgcolor = font.GetFontColor();
130 PColor bgcolor = font.GetBackgroundColor();
131
132 counted_ptr<PEBLObjectBase> fgColorPtr(new PColor(fgcolor));
133 PComplexData * pcd = new PComplexData(fgColorPtr);
134 Variant col = Variant(pcd);
135 delete pcd;
136 pcd=NULL;
137 InitializeProperty("FGCOLOR", col);
138
139 counted_ptr<PEBLObjectBase> bgColorPtr(new PColor(bgcolor));
140 pcd = new PComplexData(bgColorPtr);
141 col = Variant(pcd);
142 delete pcd;
143 pcd=NULL;
144 InitializeProperty("BGCOLOR", col);
145
146 InitializeProperty("ANTIALIASED", Variant(mAntiAliased));
147}
virtual PColor GetBackgroundColor() const
Definition PFont.cpp:296
virtual int GetFontStyle() const
Definition PFont.h:84
virtual PColor GetFontColor() const
Definition PFont.cpp:289
virtual std::string GetFontFileName() const
Definition PFont.h:83
virtual bool GetAntiAliased() const
Definition PFont.h:88
virtual int GetFontSize() const
Definition PFont.h:85

References CDT_FONT, GetAntiAliased(), GetBackgroundColor(), GetFontColor(), GetFontFileName(), GetFontSize(), GetFontStyle(), PEBLObjectBase::InitializeProperty(), IsBoldFont(), IsItalicFont(), IsUnderlineFont(), mAntiAliased, PEBLObjectBase::mCDT, mFontFileName, mFontSize, mFontStyle, and NULL.

◆ ~PFont()

PFont::~PFont ( )
virtual

Copy constructor.

Standard destructor of PFont.

Definition at line 151 of file PFont.cpp.

152{
153
154}

Member Function Documentation

◆ GetAntiAliased()

virtual bool PFont::GetAntiAliased ( ) const
inlinevirtual

◆ GetBackgroundColor()

PColor PFont::GetBackgroundColor ( ) const
virtual

Definition at line 296 of file PFont.cpp.

297{
299 if(ptr) return *ptr;
300 return PColor(0,0,0,255); // default black
301}
PColor * GetBackgroundColorPtr() const
Definition PFont.cpp:280

References GetBackgroundColorPtr().

Referenced by PlatformTextBox::Draw(), main(), PFont(), PlatformLabel::RenderText(), and PlatformTextBox::RenderText().

◆ GetBackgroundColorPtr()

PColor * PFont::GetBackgroundColorPtr ( ) const
protected

◆ GetFontColor()

PColor PFont::GetFontColor ( ) const
virtual

Definition at line 289 of file PFont.cpp.

290{
291 PColor* ptr = GetFontColorPtr();
292 if(ptr) return *ptr;
293 return PColor(0,0,0,255); // default black
294}
PColor * GetFontColorPtr() const
Definition PFont.cpp:272

References GetFontColorPtr().

Referenced by PlatformTextBox::Draw(), main(), PFont(), PlatformLabel::RenderText(), and PlatformTextBox::RenderText().

◆ GetFontColorPtr()

◆ GetFontFileName()

virtual std::string PFont::GetFontFileName ( ) const
inlinevirtual

◆ GetFontSize()

virtual int PFont::GetFontSize ( ) const
inlinevirtual

◆ GetFontStyle()

virtual int PFont::GetFontStyle ( ) const
inlinevirtual

Definition at line 84 of file PFont.h.

84{return mFontStyle;};

References mFontStyle.

Referenced by PlatformTextBox::Draw(), main(), PFont(), and PlatformFont::PlatformFont().

◆ GetProperty()

Variant PFont::GetProperty ( std::string  name) const
virtual

Definition at line 228 of file PFont.cpp.

229{
230 return PEBLObjectBase::GetProperty(name);
231}

References PEBLObjectBase::GetProperty().

◆ IsBoldFont()

bool PFont::IsBoldFont ( ) const
virtual

Definition at line 367 of file PFont.cpp.

368{
369 //The PFS_Bold acts as a bit filter, if it isn't bold the & should be 0.
370 return (mFontStyle & PFS_Bold);
371}
@ PFS_Bold
Definition PFont.h:46

References mFontStyle, and PFS_Bold.

Referenced by main(), PFont(), PFont(), PFont(), SetFontStyle(), and SetProperty().

◆ IsItalicFont()

bool PFont::IsItalicFont ( ) const
virtual

Definition at line 373 of file PFont.cpp.

374{
375 //The PFS_Italic acts as a bit filter, if it isn't bold the & should be 0.
376 return (mFontStyle & PFS_Italic);
377}
@ PFS_Italic
Definition PFont.h:47

References mFontStyle, and PFS_Italic.

Referenced by main(), PFont(), PFont(), PFont(), SetFontStyle(), and SetProperty().

◆ IsNormalFont()

bool PFont::IsNormalFont ( ) const
virtual

Definition at line 362 of file PFont.cpp.

363{
364 return mFontStyle == 0;
365}

References mFontStyle.

Referenced by main().

◆ IsUnderlineFont()

bool PFont::IsUnderlineFont ( ) const
virtual

Definition at line 379 of file PFont.cpp.

380{
381 //The PFS_Underline acts as a bit filter, if it isn't bold the & should be 0.
382 return (mFontStyle & PFS_Underline);
383}
@ PFS_Underline
Definition PFont.h:48

References mFontStyle, and PFS_Underline.

Referenced by main(), PFont(), PFont(), PFont(), SetFontStyle(), and SetProperty().

◆ ObjectName()

std::string PFont::ObjectName ( ) const
virtual

Reimplemented from PEBLObjectBase.

Reimplemented in PlatformFont, and PlatformFont.

Definition at line 243 of file PFont.cpp.

244{
245 return "PFont";
246}

◆ SendToStream()

std::ostream & PFont::SendToStream ( std::ostream &  out) const
protectedvirtual

This sends the font descriptions to the specified stream.

Reimplemented from PEBLObjectBase.

Reimplemented in PlatformFont, PlatformFont, and PlatformFont.

Definition at line 336 of file PFont.cpp.

337{
338 out << "<PFont: Name: [" << mFontFileName << "]\n";
339 out << " Style: ["<< mFontStyle<< "]\n";
340 out << " Size: ["<< mFontSize << "]\n";
341
342 PColor* fgColor = GetFontColorPtr();
343 PColor* bgColor = GetBackgroundColorPtr();
344
345 if(fgColor)
346 out << " Color: ["<< *fgColor << "]\n";
347 else
348 out << " Color: [NULL]\n";
349
350 if(bgColor)
351 out << " BGColor: ["<< *bgColor<< "]\n";
352 else
353 out << " BGColor: [NULL]\n";
354
355 out << " Antialiased: ["<< mAntiAliased << "]>\n";
356
357 return out;
358}

References GetBackgroundColorPtr(), GetFontColorPtr(), mAntiAliased, mFontFileName, mFontSize, and mFontStyle.

◆ SetAntiAliased()

void PFont::SetAntiAliased ( const bool  aa)
virtual

Definition at line 327 of file PFont.cpp.

328{
329 mAntiAliased = aa;
331}
virtual bool SetProperty(std::string name, Variant v)

References mAntiAliased, and PEBLObjectBase::SetProperty().

Referenced by SetProperty().

◆ SetBackgroundColor()

void PFont::SetBackgroundColor ( PColor  color)
virtual

Reimplemented in PlatformFont, and PlatformFont.

Definition at line 315 of file PFont.cpp.

316{
317 // Update individual color components to avoid problematic copy assignment
319 if(ptr) {
320 ptr->SetRed(color.GetRed());
321 ptr->SetGreen(color.GetGreen());
322 ptr->SetBlue(color.GetBlue());
323 ptr->SetAlpha(color.GetAlpha());
324 }
325}
void SetRed(int color)
Definition PColor.cpp:197
int GetRed() const
Definition PColor.cpp:226
int GetAlpha() const
Definition PColor.cpp:229
int GetBlue() const
Definition PColor.cpp:228
int GetGreen() const
Definition PColor.cpp:227
void SetGreen(int color)
Definition PColor.cpp:204
void SetBlue(int color)
Definition PColor.cpp:211
void SetAlpha(int color)
Definition PColor.cpp:218

References PColor::GetAlpha(), GetBackgroundColorPtr(), PColor::GetBlue(), PColor::GetGreen(), PColor::GetRed(), PColor::SetAlpha(), PColor::SetBlue(), PColor::SetGreen(), and PColor::SetRed().

Referenced by PlatformFont::SetBackgroundColor(), and SetProperty().

◆ SetFontColor()

void PFont::SetFontColor ( PColor  color)
virtual

Reimplemented in PlatformFont, and PlatformFont.

Definition at line 303 of file PFont.cpp.

304{
305 // Update individual color components to avoid problematic copy assignment
306 PColor* ptr = GetFontColorPtr();
307 if(ptr) {
308 ptr->SetRed(color.GetRed());
309 ptr->SetGreen(color.GetGreen());
310 ptr->SetBlue(color.GetBlue());
311 ptr->SetAlpha(color.GetAlpha());
312 }
313}

References PColor::GetAlpha(), PColor::GetBlue(), GetFontColorPtr(), PColor::GetGreen(), PColor::GetRed(), PColor::SetAlpha(), PColor::SetBlue(), PColor::SetGreen(), and PColor::SetRed().

Referenced by PlatformFont::SetFontColor(), and SetProperty().

◆ SetFontFileName()

void PFont::SetFontFileName ( const std::string &  name)
virtual

Set methods for all of the data in font.

Definition at line 251 of file PFont.cpp.

252{
253 mFontFileName = name;
255}

References mFontFileName, and PEBLObjectBase::SetProperty().

Referenced by SetProperty().

◆ SetFontSize()

void PFont::SetFontSize ( const int  size)
virtual

Reimplemented in PlatformFont.

Definition at line 265 of file PFont.cpp.

266{
267 mFontSize = size;
269}

References mFontSize, and PEBLObjectBase::SetProperty().

Referenced by PlatformFont::SetFontSize(), and SetProperty().

◆ SetFontStyle()

void PFont::SetFontStyle ( const int  style)
virtual

◆ SetProperty()

bool PFont::SetProperty ( std::string  name,
Variant  v 
)
virtual

Standard Destructors.

Reimplemented from PEBLObjectBase.

Definition at line 158 of file PFont.cpp.

159{
160 if(name == "FILENAME") SetFontFileName(v);
161 else if (name == "BOLD" )
162 {
163 int b,u,i;
164 if(v.GetInteger()) b = PFS_Bold;
165 else b = PFS_Normal;
166
167 if(IsItalicFont()) i = PFS_Italic;
168 else i = PFS_Normal;
169
171 else u = PFS_Normal;
172
173 SetFontStyle( b | i | u);
174
175 }
176 else if (name == "ITALIC" )
177 {
178 int b,u,i;
179 if(IsBoldFont()) b = PFS_Bold;
180 else b = PFS_Normal;
181
182 if(v.GetInteger()) i = PFS_Italic;
183 else i = PFS_Normal;
184
186 else u = PFS_Normal;
187
188 SetFontStyle( b | i | u);
189
190 }
191 else if (name == "UNDERLINE" )
192 {
193 int b,u,i;
194 if(IsBoldFont()) b = PFS_Bold;
195 else b = PFS_Normal;
196
197 if(IsItalicFont()) i = PFS_Italic;
198 else i = PFS_Normal;
199
200 if(v.GetInteger()) u = PFS_Underline;
201 else u = PFS_Normal;
202
203 SetFontStyle( b | i | u);
204 }
205 else if (name == "SIZE") SetFontSize(v) ;
206
207
208 else if (name == "FGCOLOR")
209 {
210 // Extract the new color and update our internal color object
211 // Don't call PEBLObjectBase::SetProperty - the property map already points to mFontColor
212 PColor newColor = *(dynamic_cast<PColor*>(v.GetComplexData()->GetObject().get()));
213 SetFontColor(newColor);
214 }
215 else if (name == "BGCOLOR")
216 {
217 // Extract the new color and update our internal color object
218 // Don't call PEBLObjectBase::SetProperty - the property map already points to mBackgroundColor
219 PColor newColor = *(dynamic_cast<PColor*>(v.GetComplexData()->GetObject().get()));
220 SetBackgroundColor(newColor);
221 }
222 else if (name == "ANTIALIASED")SetAntiAliased(v.GetInteger());
223 else return false;
224
225 return true;
226}
virtual void SetFontColor(PColor color)
Definition PFont.cpp:303
virtual void SetFontStyle(const int style)
Definition PFont.cpp:257
virtual void SetBackgroundColor(PColor color)
Definition PFont.cpp:315
virtual void SetFontSize(const int size)
Definition PFont.cpp:265
virtual void SetAntiAliased(const bool aa)
Definition PFont.cpp:327
virtual void SetFontFileName(const std::string &name)
Set methods for all of the data in font.
Definition PFont.cpp:251
pInt GetInteger() const
Definition Variant.cpp:997

References counted_ptr< X >::get(), Variant::GetComplexData(), Variant::GetInteger(), PComplexData::GetObject(), IsBoldFont(), IsItalicFont(), IsUnderlineFont(), PFS_Bold, PFS_Italic, PFS_Normal, PFS_Underline, SetAntiAliased(), SetBackgroundColor(), SetFontColor(), SetFontFileName(), SetFontSize(), and SetFontStyle().

◆ ValidateProperty() [1/2]

ObjectValidationError PFont::ValidateProperty ( std::string  name) const
virtual

Reimplemented from PEBLObjectBase.

Definition at line 238 of file PFont.cpp.

239{
240 return OVE_SUCCESS;
241}
@ OVE_SUCCESS
Definition PEBLObject.h:38

References OVE_SUCCESS.

◆ ValidateProperty() [2/2]

ObjectValidationError PFont::ValidateProperty ( std::string  name,
Variant  v 
) const
virtual

Reimplemented from PEBLObjectBase.

Definition at line 234 of file PFont.cpp.

235{
236 return ValidateProperty(name);
237}
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PFont.cpp:234

References ValidateProperty().

Referenced by ValidateProperty().

Member Data Documentation

◆ mAntiAliased

bool PFont::mAntiAliased
protected

◆ mFontFileName

◆ mFontSize

◆ mFontStyle


The documentation for this class was generated from the following files: