IFont.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_IFONT_HPP
30 #define NOMLIB_SDL2_IFONT_HPP
31 
32 #include <iostream>
33 #include <memory>
34 
35 #include "nomlib/config.hpp"
36 #include "nomlib/math/Color.hpp"
37 #include "nomlib/math/Coords.hpp"
38 #include "nomlib/graphics/Texture.hpp"
39 #include "nomlib/graphics/IDrawable.hpp"
40 
41 namespace nom {
42 
43 class IFont:
44  public IDrawable
45 {
46  public:
48  enum FontStyle
49  {
50  Regular = 0,
51  Bold = 1,
52  Italic = 2,
53  Underlined = 3,
54  Faded = 4
55  };
56 
57  enum TextAlignment
58  {
59  TopLeft = 0,
60  TopCenter,
61  TopRight,
62  MiddleLeft,
63  MiddleCenter,
64  MiddleRight,
65  BottomLeft,
66  BottomCenter,
67  BottomRight
68  };
69 
72  {
73  NotImplemented = 0,
74  Solid,
75  Shaded,
76  Blended
77  };
78 
79  typedef IFont* RawPtr;
80  typedef std::unique_ptr<IFont> UniquePtr;
81  typedef std::shared_ptr<IFont> SharedPtr;
82 
83  IFont ( void ) {}
84  virtual ~IFont ( void ) {}
85 
86  virtual IFont::SharedPtr clone ( void ) const = 0;
87 
88  virtual bool load (
89  const std::string& filename, const Color& colorkey,
90  bool use_cache = false
91  ) = 0;
92 
93  virtual const std::string& getText ( void ) const = 0;
94  virtual int32 getFontWidth ( void ) const = 0;
95  virtual int32 getFontHeight ( void ) const = 0;
96  virtual IFont::FontStyle getFontStyle ( void ) const = 0;
97  virtual const Coords& getPosition ( void ) const = 0;
98  virtual const Color& getColor ( void ) const = 0;
99  virtual uint32 getNewline ( void ) const = 0;
100  virtual uint32 getSpacing ( void ) const = 0;
101  virtual IFont::TextAlignment getTextJustification ( void ) const = 0;
102 
103 
104  virtual void setText ( const std::string& text ) = 0;
105 
109  virtual void setFontSize ( int32 point_size )
110  {
111 NOM_LOG_ERR ( NOM, "Method not implemented." );
112  }
113 
114  virtual void setFontStyle ( int32 style, uint8 options = 150 ) = 0;
115  virtual void setColor ( const Color& color ) = 0;
116  virtual void setPosition ( const Coords& coords ) = 0;
117  virtual void setSpacing ( uint32 spaces ) = 0;
118  virtual void setTextJustification ( IFont::TextAlignment alignment ) = 0;
119 
120  virtual IFont::RenderStyle getRenderingStyle ( void ) const
121  {
122 NOM_LOG_ERR ( NOM, "Method not implemented." );
123  return IFont::RenderStyle::Solid;
124  }
125 
126  virtual void setRenderingStyle ( IFont::RenderStyle )
127  {
128 NOM_LOG_ERR ( NOM, "Method not implemented." );
129  }
130 
136  virtual bool resize ( enum ResizeAlgorithm scaling_algorithm )
137  {
138 NOM_LOG_ERR ( NOM, "Method not implemented." );
139  return false;
140  }
141 };
142 
143 } // namespace nom
144 
145 #endif // include guard defined
RenderStyle
Text rendering qualities.
Definition: IFont.hpp:71
Base interface class for grouping objects under a united front.
Definition: IDrawable.hpp:43
virtual bool resize(enum ResizeAlgorithm scaling_algorithm)
Definition: IFont.hpp:136
FontStyle
Text effect styling.
Definition: IFont.hpp:48
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
virtual void setFontSize(int32 point_size)
Definition: IFont.hpp:109
Utility class container for RGBA colors.
Definition: Color.hpp:43