summaryrefslogtreecommitdiff
path: root/Runtime/IMGUI/TextFormatting.h
blob: 3646692a017c3dc660a9dfdd412ff0b58f926a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef TEXTFORMATTING_H
#define TEXTFORMATTING_H

#include "TextUtil.h"
#include "Runtime/Math/Rect.h"

enum {
	kStyleDefault = 0,
	kStyleFlagBold = 1 << 0,
	kStyleFlagItalic = 1 << 1,
};

struct TextFormat
{
	int style;
	ColorRGBA32 color;
	int size;
	int material;
	Rectf imageRect;
	
	TextFormat () :
	style(0),
	color(0xff,0xff,0xff,0xff),
	size(0),
	material(0),
	imageRect(0,0,1,1)
	{
	}
};

enum FormatFlags {
	kFormatBold = 1 << 0,
	kFormatItalic = 1 << 1,
	kFormatColor = 1 << 2,
	kFormatSize = 1 << 3,
	kFormatMaterial = 1 << 4,
	kFormatImage = 1 << 5,
	kFormatPop = 1 << 15,
};

struct TextFormatChange
{
	int startPosition;
	int skipCharacters;
	TextFormat format;
	int flags;
};

class FormatStack : std::vector<TextFormat>
{
public:
	FormatStack (ColorRGBA32 _color, int _size, int _style)
	{
		push_back (TextFormat());
		back().color = _color;
		back().size = _size;
		back().style = _style;
	}
	
	void PushFormat (TextFormatChange &change)
	{
		if (change.flags & kFormatPop)
			pop_back();
		else
		{
			push_back(back());
			if (change.flags & kFormatBold)
				back().style |= kStyleFlagBold;
			if (change.flags & kFormatItalic)
				back().style |= kStyleFlagItalic;
			if (change.flags & kFormatColor)
				back().color = change.format.color;
			if (change.flags & kFormatSize)
				back().size = change.format.size;
			if (change.flags & kFormatMaterial)
				back().material = change.format.material;
		}			
	}
	
	TextFormat& Current() { return back(); }
};

void GetFormatString (UTF16String& input, std::vector<TextFormatChange> &format);

#endif