ge211
2021.5.1
A student game engine
ge211_resource.hxx
1
#pragma once
2
3
#include "ge211_forward.hxx"
4
#include "ge211_noexcept.hxx"
5
#include "ge211_util.hxx"
6
#include "ge211_error.hxx"
7
8
#include <SDL_rwops.h>
9
10
// Copied from SDL_ttf.h in order to avoid getting including all of
11
// SDL.h from the GE211 headers.
12
extern
"C"
{
13
extern
DECLSPEC
void
SDLCALL TTF_CloseFont(TTF_Font*);
14
}
15
16
#include <fstream>
17
#include <string>
18
#include <vector>
19
20
namespace
ge211
{
21
25
std::ifstream
26
open_resource_file
(
std::string
const
& filename);
27
31
std::ifstream
32
open_binary_resource_file
(
std::string
const
& filename);
33
34
namespace
detail {
35
36
class
File_resource
37
{
38
public
:
39
explicit
File_resource(
const
std::string
&);
40
41
Borrowed<SDL_RWops> get_raw() const NOEXCEPT {
return
ptr_.get(); }
42
43
Owned<SDL_RWops> release() && {
return
ptr_.release(); }
44
45
private
:
46
static
void
close_rwops_(Owned<SDL_RWops>);
47
48
delete_ptr<SDL_RWops, &close_rwops_> ptr_;
49
};
50
51
}
// end namespace detail
52
69
class
Font
70
{
71
public
:
74
Font
(
const
std::string
& filename,
int
size);
75
76
private
:
77
friend
Text_sprite
;
78
79
Borrowed<TTF_Font>
get_raw_()
const
NOEXCEPT {
return
ptr_.get(); }
80
81
detail::delete_ptr<TTF_Font, &TTF_CloseFont, true> ptr_;
82
};
83
84
}
std::string
ge211::open_binary_resource_file
std::ifstream open_binary_resource_file(std::string const &filename)
Opens a file in the Resources/ directory for input in binary mode.
Definition:
ge211_resource.cxx:75
ge211::Font::Font
Font(const std::string &filename, int size)
Loads a font from the specified TrueType font file, at the specified size.
Definition:
ge211_resource.cxx:121
ge211
The game engine namespace.
Definition:
ge211.hxx:4
ge211::open_resource_file
std::ifstream open_resource_file(std::string const &filename)
Opens a file in the Resources/ directory for input in text mode.
Definition:
ge211_resource.cxx:69
ge211::sprites::Text_sprite
A Sprite that displays text.
Definition:
ge211_sprites.hxx:232
ge211::Font
Represents a font that can be used to render a sprites::Text_sprite.
Definition:
ge211_resource.hxx:70
ge211::Borrowed
OBJECT_TYPE * Borrowed
Type alias to indicate that the given pointer does not own its object.
Definition:
ge211_util.hxx:19
std::ifstream
include
ge211_resource.hxx
Generated by
1.8.20