Oxygine
1
2g game engine
oxygine
src
TextStyle.h
1
#pragma once
2
#include "oxygine-include.h"
3
#include "math/Color.h"
4
#include <string>
5
6
namespace
oxygine
7
{
8
class
TextStyle
9
{
10
public
:
11
enum
HorizontalAlign
12
{
13
HALIGN_DEFAULT,
14
HALIGN_LEFT,
15
HALIGN_MIDDLE,
16
HALIGN_RIGHT
17
};
18
19
enum
VerticalAlign
20
{
21
VALIGN_DEFAULT,
22
VALIGN_BASELINE,
23
VALIGN_TOP,
24
VALIGN_MIDDLE,
25
VALIGN_BOTTOM
26
};
27
28
29
TextStyle
(
const
ResFont
* rs = 0): font(rs),
30
hAlign(HALIGN_DEFAULT),
31
vAlign(VALIGN_DEFAULT),
32
linesOffset(0),
33
kerning(0),
34
multiline(
false
),
35
fontSize(0),
36
breakLongWords(
false
),
37
outline(0.0f),
38
outlineColor(Color::Black),
39
weight(0.5f),
40
baselineScale(1.0f),
41
options(0) {}
42
43
const
ResFont
* font;
44
45
HorizontalAlign hAlign;
46
VerticalAlign vAlign;
47
48
int
linesOffset;
//vertical distance offset between lines
49
int
kerning;
//horizontal distance
50
unsigned
int
options;
//additional flags could be used for generating custom glyphs
51
bool
multiline;
52
bool
breakLongWords;
//works with multiline flag. breakLongWords = false doesn't allow to break too long words
53
Color
color;
54
55
56
57
int
fontSize;
58
59
60
float
outline;
//works only with SD fonts, disabled by default = 0.0f, 0.5 - max outline
61
Color
outlineColor;
//works only with SD fonts
62
float
weight;
//works only with SD fonts, font weight, default = 0.5f, 0.0 - bold, 1.0 - thin
63
float
baselineScale;
//baseline distance multiplier
64
65
66
67
TextStyle
withFont(
const
ResFont
* f)
const
{
TextStyle
st = *
this
; st.font = f;
return
st; }
68
69
TextStyle
alignTop()
const
{
TextStyle
st = *
this
; st.vAlign = VALIGN_TOP;
return
st; }
70
TextStyle
alignBottom()
const
{
TextStyle
st = *
this
; st.vAlign = VALIGN_BOTTOM;
return
st; }
71
TextStyle
alignBaseline()
const
{
TextStyle
st = *
this
; st.vAlign = VALIGN_BASELINE;
return
st; }
72
TextStyle
alignMiddleV()
const
{
TextStyle
st = *
this
; st.vAlign = VALIGN_MIDDLE;
return
st; }
73
74
TextStyle
alignLeft()
const
{
TextStyle
st = *
this
; st.hAlign = HALIGN_LEFT;
return
st; }
75
TextStyle
alignRight()
const
{
TextStyle
st = *
this
; st.hAlign = HALIGN_RIGHT;
return
st; }
76
TextStyle
alignMiddleH()
const
{
TextStyle
st = *
this
; st.hAlign = HALIGN_MIDDLE;
return
st; }
77
78
TextStyle
alignMiddle()
const
{
TextStyle
st = *
this
; st.vAlign = VALIGN_MIDDLE; st.hAlign = HALIGN_MIDDLE;
return
st; }
79
80
TextStyle
withHOffset(
int
offset)
const
{
TextStyle
st = *
this
; st.linesOffset = offset;
return
st; }
81
TextStyle
withBaselineScale(
float
s)
const
{
TextStyle
st = *
this
; st.baselineScale = s;
return
st; }
82
83
TextStyle
withKerning(
int
kerning)
const
{
TextStyle
st = *
this
; st.kerning = kerning;
return
st; }
84
TextStyle
withMultiline(
bool
multiline =
true
)
const
{
TextStyle
st = *
this
; st.multiline = multiline;
return
st; }
85
TextStyle
withColor(
const
Color
& color)
const
{
TextStyle
st = *
this
; st.color = color;
return
st; }
86
87
TextStyle
withFontSize(
int
size)
const
{
TextStyle
st = *
this
; st.fontSize = size;
return
st; }
88
89
TextStyle
withOutline(
float
outline)
const
{
TextStyle
st = *
this
; st.outline = outline;
return
st; }
90
TextStyle
withOutlineColor(
const
Color
& color)
const
{
TextStyle
st = *
this
; st.outlineColor = color;
return
st; }
91
TextStyle
withWeight(
float
weight)
const
{
TextStyle
st = *
this
; st.weight = weight;
return
st; }
92
TextStyle
withOptions(
unsigned
int
opt)
const
{
TextStyle
st = *
this
; st.options = opt;
return
st; }
93
};
94
95
std::string dumpStyle(
const
TextStyle
& s,
bool
onlydiff);
96
}
oxygine::ResFont
Definition:
ResFont.h:8
oxygine
–oxgl-end–!
Definition:
Actor.h:14
oxygine::TextStyle
Definition:
TextStyle.h:8
oxygine::Color
Definition:
Color.h:8
Generated on Tue Feb 13 2018 05:01:17 for Oxygine by
1.8.14