-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGLDraw.cs
More file actions
88 lines (76 loc) · 3.14 KB
/
GLDraw.cs
File metadata and controls
88 lines (76 loc) · 3.14 KB
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
using System;
using System.Drawing;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace GLGUI
{
public static class GLDraw
{
public static Rectangle CurrentScreenRect { get { return ControlRect; } }
internal static GLGui CurrentGui;
internal static Rectangle ControlRect;
internal static Rectangle ScissorRect;
public static void PrepareCustomDrawing()
{
GL.Scissor(ScissorRect.X, CurrentGui.Outer.Height - ScissorRect.Bottom, ScissorRect.Width, ScissorRect.Height);
}
public static void Fill(ref Color4 color)
{
if (color.A == 0.0f)
return;
GL.ClearColor(color);
GL.Scissor(ScissorRect.X, CurrentGui.Outer.Height - ScissorRect.Bottom, ScissorRect.Width, ScissorRect.Height);
GL.Clear(ClearBufferMask.ColorBufferBit);
}
public static void FillRect(Rectangle rect, ref Color4 color)
{
FillRect(ref rect, ref color);
}
public static void FillRect(ref Rectangle rect, ref Color4 color)
{
if (color.A == 0.0f)
return;
int w = Math.Min(rect.Width, ScissorRect.Width - rect.X);
int h = Math.Min(rect.Height, ScissorRect.Height - rect.Y);
if (w > 0 && h > 0)
{
GL.ClearColor(color);
GL.Scissor(ScissorRect.X + rect.X, CurrentGui.Outer.Height - (ScissorRect.Y + rect.Y + h), w, h);
GL.Clear(ClearBufferMask.ColorBufferBit);
}
}
public static void Text(GLFontText processedText, Rectangle rect, ref Color4 color)
{
Text(processedText, ref rect, ref color);
}
public static void Text(GLFontText processedText, ref Rectangle rect, ref Color4 color)
{
if (color.A == 0.0f)
return;
int w = Math.Min(rect.Width, ScissorRect.Width - rect.X);
int h = Math.Min(rect.Height, ScissorRect.Height - rect.Y);
if (w > 0 && h > 0)
{
GL.Scissor(ScissorRect.X + rect.X, CurrentGui.Outer.Height - (ScissorRect.Y + rect.Y + h), w, h);
GL.PushMatrix();
switch(processedText.alignment)
{
case GLFontAlignment.Left:
case GLFontAlignment.Justify:
GL.Translate(ControlRect.X + rect.X, ControlRect.Y + rect.Y, 0.0f);
break;
case GLFontAlignment.Centre:
GL.Translate(ControlRect.X + rect.X + rect.Width / 2, ControlRect.Y + rect.Y, 0.0f);
break;
case GLFontAlignment.Right:
GL.Translate(ControlRect.X + rect.X + rect.Width, ControlRect.Y + rect.Y, 0.0f);
break;
}
GL.Color4(color);
for (int i = 0; i < processedText.VertexBuffers.Length; i++)
processedText.VertexBuffers[i].Draw();
GL.PopMatrix();
}
}
}
}