Porting focus based features and fix rendering
This commit is contained in:
@@ -76,7 +76,7 @@ void EndFrameRender(Color color) {
|
||||
GLint y = (GLint)rect.min.y;
|
||||
GLsizei w = (GLsizei)(rect.max.x - rect.min.x);
|
||||
GLsizei h = (GLsizei)(rect.max.y - rect.min.y);
|
||||
glScissor(x, (GLint)WindowSize.y - h, w, h);
|
||||
glScissor(x, (GLint)WindowSize.y - (GLint)rect.max.y, w, h);
|
||||
glNamedBufferSubData(VBO, 0, it->count * sizeof(Vertex2D), it->vertices);
|
||||
glBindVertexArray(VAO);
|
||||
GLint s_texture = 0; // texture unit that sampler2D will use in GLSL code
|
||||
@@ -229,6 +229,8 @@ void SetScissor(Rect2 rect) {
|
||||
}
|
||||
}
|
||||
|
||||
void SetScissor(Rect2I rect) { SetScissor(ToRect2(rect)); }
|
||||
|
||||
Vertex2D *AllocVertex2D(Allocator allocator, VertexList2D *list, int count) {
|
||||
VertexNode2D *node = list->last;
|
||||
if (node == 0 || node->count + count > Lengthof(node->vertices)) {
|
||||
@@ -293,6 +295,9 @@ void PushQuad2D(Allocator arena, VertexList2D *list, Rect2 rect, Rect2 tex, Colo
|
||||
void DrawRect(Rect2 rect, Color color) {
|
||||
PushQuad2D(RenderArena, &Vertices, rect, MainFont.white_texture_bounding_box, color);
|
||||
}
|
||||
void DrawRect(Rect2I rect, Color color) {
|
||||
PushQuad2D(RenderArena, &Vertices, ToRect2(rect), MainFont.white_texture_bounding_box, color);
|
||||
}
|
||||
|
||||
Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw = true) {
|
||||
pos.y += font->ascent - font->descent;
|
||||
@@ -309,6 +314,38 @@ Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw =
|
||||
return result;
|
||||
}
|
||||
|
||||
#define PI32 3.14159265359f
|
||||
void DrawCircle(Vec2 pos, float radius, Color color) {
|
||||
const int segment_count = 16;
|
||||
const int vertex_count = segment_count * 3;
|
||||
Vec2 points[segment_count + 1];
|
||||
for (int i = 0; i < Lengthof(points); i += 1) {
|
||||
float radians = 2.0f * PI32 * float(i) / float(segment_count);
|
||||
float x = radius * cosf(radians);
|
||||
float y = radius * sinf(radians);
|
||||
points[i] = {x, y};
|
||||
}
|
||||
points[segment_count] = points[0]; // wrap around
|
||||
|
||||
Vertex2D *vertices = AllocVertex2D(RenderArena, &Vertices, vertex_count);
|
||||
int point_i = 0;
|
||||
int segment_i = 0;
|
||||
for (; segment_i < vertex_count; segment_i += 3, point_i += 1) {
|
||||
Rect2 tex = MainFont.white_texture_bounding_box;
|
||||
Vertex2D *it = vertices + segment_i;
|
||||
it[0].color = color;
|
||||
it[1].color = color;
|
||||
it[2].color = color;
|
||||
it[0].tex = {tex.min.x, tex.max.y};
|
||||
it[1].tex = {tex.max.x, tex.max.y};
|
||||
it[2].tex = {tex.min.x, tex.min.y};
|
||||
|
||||
it[0].pos = {pos + points[point_i]};
|
||||
it[1].pos = {pos + points[point_i + 1]};
|
||||
it[2].pos = {pos};
|
||||
}
|
||||
}
|
||||
|
||||
Vec2 GetStringSize(Font *font, String16 string) {
|
||||
return DrawString(font, string, {}, {}, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user