Files
biomed/GUIDraw.cpp
2026-02-12 10:51:02 +01:00

76 lines
2.2 KiB
C++

#include "GUIDraw.h"
#include <SDL2/SDL_opengl.h>
#include "renderer.h"
namespace GUIDraw
{
void DrawLine(const Vector2& a, const Vector2& b, const Color& color)
{
Renderer::SetState(RENDER_BLEND);
glColor4ub(color.r, color.g, color.b, color.a);
glBegin(GL_LINES);
glVertex2i(a.x, a.y);
glVertex2i(b.x, b.y);
glEnd();
}
void DrawRect(const Vector4& rect, const Color& color)
{
Renderer::SetState(RENDER_BLEND);
glColor4ub(color.r, color.g, color.b, color.a);
glBegin(GL_LINE_LOOP);
glVertex2i(rect.x, rect.y);
glVertex2i(rect.x, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y);
glEnd();
}
void DrawRect(const Vector4& rect, const Color* colors)
{
Renderer::SetState(RENDER_BLEND);
glBegin(GL_LINES);
glColor4ub(colors[0].r, colors[0].g, colors[0].b, colors[0].a);
glVertex2i(rect.x, rect.y);
glVertex2i(rect.x, rect.y+rect.w);
glColor4ub(colors[1].r, colors[1].g, colors[1].b, colors[1].a);
glVertex2i(rect.x, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y+rect.w);
glColor4ub(colors[2].r, colors[2].g, colors[2].b, colors[2].a);
glVertex2i(rect.x+rect.z, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y);
glColor4ub(colors[3].r, colors[3].g, colors[3].b, colors[3].a);
glVertex2i(rect.x+rect.z, rect.y);
glVertex2i(rect.x, rect.y);
glEnd();
}
void FillRect(const Vector4& rect, const Color& color)
{
Renderer::SetState(RENDER_BLEND | RENDER_FILL);
glColor4ub(color.r, color.g, color.b, color.a);
glBegin(GL_QUADS);
glVertex2i(rect.x, rect.y);
glVertex2i(rect.x, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y+rect.w);
glVertex2i(rect.x+rect.z, rect.y);
glEnd();
}
void FillRect(const Vector4& rect, const Color* colors)
{
Renderer::SetState(RENDER_BLEND | RENDER_FILL);
glBegin(GL_QUADS);
glColor4ub(colors[0].r, colors[0].g, colors[0].b, colors[0].a);
glVertex2i(rect.x, rect.y);
glColor4ub(colors[1].r, colors[1].g, colors[1].b, colors[1].a);
glVertex2i(rect.x, rect.y+rect.w);
glColor4ub(colors[2].r, colors[2].g, colors[2].b, colors[2].a);
glVertex2i(rect.x+rect.z, rect.y+rect.w);
glColor4ub(colors[3].r, colors[3].g, colors[3].b, colors[3].a);
glVertex2i(rect.x+rect.z, rect.y);
glEnd();
}
}