hacked lines

This commit is contained in:
Jenny White 2018-04-30 18:41:36 +03:00
parent 58b10ada51
commit a5ee7537fa
2 changed files with 31 additions and 25 deletions

View File

@ -13,15 +13,15 @@
namespace glez::draw namespace glez::draw
{ {
void line(int x, int y, int dx, int dy, rgba color, int thickness); void line(float x, float y, float dx, float dy, rgba color, float thickness);
void rect(int x, int y, int w, int h, rgba color); void rect(float x, float y, float w, float h, rgba color);
void rect_outline(int x, int y, int w, int h, rgba color, int thickness); void rect_outline(float x, float y, float w, float h, rgba color, float thickness);
void rect_textured(int x, int y, int w, int h, rgba color, texture &texture, void rect_textured(float x, float y, float w, float h, rgba color, texture &texture,
int tx, int ty, int tw, int th, float angle); float tx, float ty, float tw, float th, float angle);
void circle(int x, int y, int radius, rgba color, int thickness, int steps); void circle(float x, float y, float radius, rgba color, float thickness, int steps);
void string(int x, int y, const std::string &string, font &font, rgba color, void string(float x, float y, const std::string &string, font &font, rgba color,
int *width, int *height); float *width, float *height);
void outlined_string(int x, int y, const std::string &string, font &font, void outlined_string(float x, float y, const std::string &string, font &font,
rgba color, rgba outline, int *width, int *height); rgba color, rgba outline, float *width, float *height);
} }

View File

@ -19,9 +19,9 @@ namespace indices
static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 }; static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 };
} }
void internal_draw_string(int x, int y, const std::string &string, void internal_draw_string(float x, float y, const std::string &string,
texture_font_t *fnt, glez::rgba color, int *width, texture_font_t *fnt, glez::rgba color, float *width,
int *height) float *height)
{ {
float pen_x = x; float pen_x = x;
float pen_y = y + fnt->height / 1.5f; float pen_y = y + fnt->height / 1.5f;
@ -108,8 +108,16 @@ void internal_draw_string(int x, int y, const std::string &string,
namespace glez::draw namespace glez::draw
{ {
void line(int x, int y, int dx, int dy, rgba color, int thickness) void line(float x, float y, float dx, float dy, rgba color, float thickness)
{ {
// Dirty
x += 0.5f;
y += 0.5f;
float length = sqrtf(dx * dx + dy * dy);
dx *= (length - 1.0f) / length;
dy *= (length - 1.0f) / length;
detail::render::vertex vertices[4]; detail::render::vertex vertices[4];
for (auto &vertex : vertices) for (auto &vertex : vertices)
@ -124,8 +132,6 @@ void line(int x, int y, int dx, int dy, rgba color, int thickness)
float ex = x + dx; float ex = x + dx;
float ey = y + dy; float ey = y + dy;
float length = sqrtf(nx * nx + ny * ny);
if (length == 0) if (length == 0)
return; return;
@ -149,7 +155,7 @@ void line(int x, int y, int dx, int dy, rgba color, int thickness)
indices::rectangle, 6); indices::rectangle, 6);
} }
void rect(int x, int y, int w, int h, rgba color) void rect(float x, float y, float w, float h, rgba color)
{ {
detail::render::vertex vertices[4]; detail::render::vertex vertices[4];
@ -168,7 +174,7 @@ void rect(int x, int y, int w, int h, rgba color)
indices::rectangle, 6); indices::rectangle, 6);
} }
void rect_outline(int x, int y, int w, int h, rgba color, int thickness) void rect_outline(float x, float y, float w, float h, rgba color, float thickness)
{ {
rect(x, y, w, 1, color); rect(x, y, w, 1, color);
rect(x, y, 1, h, color); rect(x, y, 1, h, color);
@ -176,7 +182,7 @@ void rect_outline(int x, int y, int w, int h, rgba color, int thickness)
rect(x, y + h - 1, w, 1, color); rect(x, y + h - 1, w, 1, color);
} }
void circle(int x, int y, int radius, rgba color, int thickness, int steps) void circle(float x, float y, float radius, rgba color, float thickness, int steps)
{ {
float px = 0; float px = 0;
float py = 0; float py = 0;
@ -193,8 +199,8 @@ void circle(int x, int y, int radius, rgba color, int thickness, int steps)
} }
} }
void string(int x, int y, const std::string &string, font &font, rgba color, void string(float x, float y, const std::string &string, font &font, rgba color,
int *width, int *height) float *width, float *height)
{ {
if (!font.isLoaded()) if (!font.isLoaded())
font.load(); font.load();
@ -205,8 +211,8 @@ void string(int x, int y, const std::string &string, font &font, rgba color,
internal_draw_string(x, y, string, fnt, color, width, height); internal_draw_string(x, y, string, fnt, color, width, height);
} }
void outlined_string(int x, int y, const std::string &string, font &font, void outlined_string(float x, float y, const std::string &string, font &font,
rgba color, rgba outline, int *width, int *height) rgba color, rgba outline, float *width, float *height)
{ {
if (!font.isLoaded()) if (!font.isLoaded())
font.load(); font.load();
@ -220,8 +226,8 @@ void outlined_string(int x, int y, const std::string &string, font &font,
internal_draw_string(x, y, string, fnt, color, width, height); internal_draw_string(x, y, string, fnt, color, width, height);
} }
void rect_textured(int x, int y, int w, int h, rgba color, texture &texture, void rect_textured(float x, float y, float w, float h, rgba color, texture &texture,
int tx, int ty, int tw, int th, float angle) float tx, float ty, float tw, float th, float angle)
{ {
if (!texture.isLoaded()) if (!texture.isLoaded())
texture.load(); texture.load();