PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
sdl/PlatformFont.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/platforms/sdl/PlatformFont.h
4// Purpose: Contains platform-specific font class.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PLATFORMFONT_H__
28#define __PLATFORMFONT_H__
29
30#include "../../objects/PFont.h"
31#include "../../objects/PColor.h"
32#include "../../utility/rc_ptrs.h"
33#include "../../base/PEBLObject.h"
34#include "../../utility/FontCache.h"
35
36#include "SDLUtility.h"
37
38#ifdef PEBL_OSX
39#include "SDL.h"
40#include "SDL_ttf.h"
41#else
42#include "SDL.h"
43#include "SDL_ttf.h"
44#endif
45
46
51
52class PlatformFont: virtual public PFont
53{
54
55public:
56 // PlatformFont();
57 PlatformFont(const std::string & filename);
58 PlatformFont(const std::string & filename, int style, int size, PColor fgcolor, PColor bgcolor, bool aa);
60 virtual ~PlatformFont();
61
62 virtual void SetFontColor (PColor color);
63 virtual void SetBackgroundColor (PColor color);
64 virtual void SetFontSize (const int size);
65 virtual void SetFontStyle (const int style);
66// virtual PColor GetFontColor () const {return SDLUtility::SDLColorToPColor(mSDL_FGColor);}
67// virtual PColor GetBackgroundColor() const {return SDLUtility::SDLColorToPColor(mSDL_BGColor);}
68
70 SDL_Surface * RenderText(const std::string & text);
71
72 unsigned int GetTextWidth(const std::string & text);
73 unsigned int GetTextHeight(const std::string & text);
74 unsigned int GetPosition(const std::string & text, unsigned int x);
75 virtual std::string ObjectName() const{return "Platform Font";};
76
77 // Access to underlying TTF_Font for baseline alignment
78 TTF_Font* GetTTFFont() const { return mTTF_Font; }
79
80 // Change detection for triggering re-renders
81 bool HasChanged(); // Checks mChanged flag AND if colors changed
82 void ClearChanged();
83 void UpdateSDLColors(); // Update SDL color cache if PColor objects changed
84
85protected:
86 virtual std::ostream & SendToStream(std::ostream& out) const;
87
88private:
89
90 std::string StripText(const std::string & text);
91
92 char* mBuffer; // Kept for binary compatibility, always NULL with FontCache
93 TTF_Font * mTTF_Font; // Now shared via FontCache, not owned
94 FontCache::FontCacheKey mCacheKey; // Cache key for this font
95 SDL_Color mSDL_FGColor;
96 SDL_Color mSDL_BGColor;
97 bool mChanged; // Flag indicating font properties have changed
98};
99
100
101#endif
Definition PFont.h:53
unsigned int GetTextHeight(const std::string &text)
SDL_Surface * RenderText(const std::string &text)
This takes care of all the busy work of rendering the text.
virtual std::ostream & SendToStream(std::ostream &out) const
This sends the font descriptions to the specified stream.
virtual std::string ObjectName() const
unsigned int GetTextWidth(const std::string &text)
TTF_Font * GetTTFFont() const
unsigned int GetPosition(const std::string &text, unsigned int x)
virtual void SetBackgroundColor(PColor color)
Set*Color needs to be overridden because it doesn't change the SDL_Color data.
virtual void SetFontColor(PColor color)
Set*Color needs to be overridden because it doesn't change the SDL_Color data.
void UpdateSDLColors()
Update SDL color cache from PColor objects.
void ClearChanged()
Clear all changed flags.
virtual void SetFontStyle(const int style)
Override SetFontStyle to update TTF font and mark as changed.
virtual ~PlatformFont()
Copy constructor.
bool HasChanged()
Check if font or its colors have changed.
virtual void SetFontSize(const int size)
Override SetFontSize to update TTF font and mark as changed.