Gosu
Font.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/Color.hpp>
8 #include <Gosu/GraphicsBase.hpp>
9 #include <Gosu/Platform.hpp>
10 #include <Gosu/Text.hpp>
11 #include <memory>
12 #include <string>
13 
14 namespace Gosu
15 {
18  class Font
19  {
20  struct Impl;
21  std::shared_ptr<Impl> pimpl;
22 
23  public:
30  Font(int height, const std::string& name = default_font_name(), unsigned flags = 0);
31 
33  const std::string& name() const;
34 
36  int height() const;
37 
39  unsigned flags() const;
40 
42  double text_width(const std::string& text) const;
44  double markup_width(const std::string& markup) const;
45 
47  void draw_text(const std::string& text, double x, double y, ZPos z,
48  double scale_x = 1, double scale_y = 1, Color c = Color::WHITE,
49  AlphaMode mode = AM_DEFAULT) const;
51  void draw_markup(const std::string& markup, double x, double y, ZPos z,
52  double scale_x = 1, double scale_y = 1, Color c = Color::WHITE,
53  AlphaMode mode = AM_DEFAULT) const;
54 
61  void draw_text_rel(const std::string& text, double x, double y, ZPos z,
62  double rel_x, double rel_y, double scale_x = 1, double scale_y = 1,
63  Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
70  void draw_markup_rel(const std::string& markup, double x, double y, ZPos z,
71  double rel_x, double rel_y, double scale_x = 1, double scale_y = 1,
72  Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
73 
76  void set_image(std::string codepoint, unsigned font_flags, const Gosu::Image& image);
78  void set_image(std::string codepoint, const Gosu::Image& image);
79  };
80 }
Definition: Audio.hpp:12
double markup_width(const std::string &markup) const
Returns the width, in pixels, the given markup would occupy if drawn.
void set_image(std::string codepoint, unsigned font_flags, const Gosu::Image &image)
Maps a letter to a specific image, instead of generating one using Gosu&#39;s built-in text rendering...
const std::string & name() const
Returns the name of the font that was used to create it.
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:16
void draw_text_rel(const std::string &text, double x, double y, ZPos z, double rel_x, double rel_y, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws text at a position relative to (x; y).
double ZPos
Represents the Z position of something drawn with Gosu&#39;s graphics system.
void draw_markup_rel(const std::string &markup, double x, double y, ZPos z, double rel_x, double rel_y, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws text at a position relative to (x; y).
Functions to output text on bitmaps.
Fonts are ideal for drawing short, dynamic strings.
Definition: Font.hpp:18
double text_width(const std::string &text) const
Returns the width, in pixels, the given text would occupy if drawn.
void draw_markup(const std::string &markup, double x, double y, ZPos z, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws markup so the top left corner of the text is at (x; y).
int height() const
Returns the height of the font, in pixels.
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
unsigned flags() const
Returns the flags used to create the font characters.
AlphaMode
Determines the way colors are combined when one is drawn onto another.
std::string default_font_name()
Returns the name of a neutral font that is available on the current platform.
void draw_text(const std::string &text, double x, double y, ZPos z, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws text so the top left corner of the text is at (x; y).
Interface of the Color class.
Provides functionality for drawing rectangular images.
Definition: Image.hpp:16
static const Color WHITE
Definition: Color.hpp:136
Font(int height, const std::string &name=default_font_name(), unsigned flags=0)
Constructs a font that can be drawn onto the graphics object.
Contains general typedefs and enums related to graphics.