Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 679a76e1c838833e2af9c20a6513f0fe02c82252 (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
86
87
88
89
90
91
92
93
94
95
96
/*
   render/primitives.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_RENDER_PRIMITIVES_H__
#define __INCLUDED_RENDER_PRIMITIVES_H__

#include "auxiliary/functions.h"
#include "math/vector2f.h"
#include "render/gl.h"
#include "render/text.h"
#include "render/textures.h"

namespace render
{

/// drawing primitives for the user interface
namespace primitives
{

/// draw a border
inline void border(math::Vector2f const &location, math::Vector2f const &size)
{
	using namespace render::gl;

	begin(LineLoop);
	vertex(location.x +1 , location.y);
	vertex(location.x + size.x, location.y);
	vertex(location.x + size.x, location.y + size.y -1);
	vertex(location.x +1, location.y + size.y - 1);
	end();
}

/// draw a rectangle
inline void rectangle(math::Vector2f const &location, math::Vector2f const &size)
{
	using namespace render::gl;

	begin(Quads);
	vertex(location.x +1 , location.y);
	vertex(location.x + size.x, location.y);
	vertex(location.x + size.x, location.y + size.y -1);
	vertex(location.x +1, location.y + size.y - 1);
	end();
}

/// draw a rectangular bitmap
inline void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::string const &texture)
{

	using namespace render::gl;
	
	render::Textures::bind("bitmaps/" + texture);
	gl::enable(GL_TEXTURE_2D);

	begin(Quads);

	glTexCoord2f(0.0f, 0.0f);
	vertex(location.x +1 , location.y);

	glTexCoord2f(1.0f, 0.0f);
	vertex(location.x + size.x, location.y);

	glTexCoord2f(1.0f, 1.0f);
	vertex(location.x + size.x, location.y + size.y -1);

	glTexCoord2f(0.0f, 1.0f);
	vertex(location.x +1, location.y + size.y - 1);
	end();

	gl::disable(GL_TEXTURE_2D);
}

/// draw one line of centered text
inline void text_centered(math::Vector2f const &location, math::Vector2f const &size, std::string const &text)
{
	Text::setfont("gui", 14, 24);
	gl::enable(GL_TEXTURE_2D);
	
	math::Vector2f v(location);

	v.x += (size.x - aux::text_strip(text).size() * Text::fontwidth()) /2.0f;
	v.y += (size.y - Text::fontheight()) / 2.0f;

	Text::draw(v.x, v.y, text);

	gl::disable(GL_TEXTURE_2D);
}

}

}

#endif // __INCLUDED_RENDER_PRIMITIVES_H__