First version of rounded rectangles (bad)

This commit is contained in:
Allen Webster 2019-10-08 10:18:20 -07:00
parent 0a55db9c1c
commit dba56df420
12 changed files with 374 additions and 186 deletions

View File

@ -2621,37 +2621,35 @@ get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str)
}
api(custom) function void
draw_rectangle(Application_Links *app, Rect_f32 rect, int_color color){
draw_rectangle(Application_Links *app, Rect_f32 rect, f32 roundness, int_color color){
Models *models = (Models*)app->cmd_context;
if (models->in_render_mode){
Color_Table color_table = models->color_table;
u32 actual_color = finalize_color(color_table, color);
draw_rectangle(models->target, rect, actual_color);
f32 scale = system_get_screen_scale_factor();
roundness *= scale;
draw_rectangle(models->target, rect, roundness, actual_color);
}
}
api(custom) function void
draw_rectangle_outline(Application_Links *app, Rect_f32 rect, int_color color)
draw_rectangle_outline(Application_Links *app, Rect_f32 rect, f32 roundness, f32 thickness, int_color color)
{
Models *models = (Models*)app->cmd_context;
if (models->in_render_mode){
Color_Table color_table = models->color_table;
u32 actual_color = finalize_color(color_table, color);
draw_rectangle_outline(models->target, rect, actual_color);
f32 scale = system_get_screen_scale_factor();
roundness *= scale;
thickness *= scale;
draw_rectangle_outline(models->target, rect, roundness, thickness, actual_color);
}
}
api(custom) function void
draw_clip_push(Application_Links *app, Rect_f32 clip_box){
Models *models = (Models*)app->cmd_context;
//clip_box = draw_helper__models_space_to_screen_space(models, clip_box);
draw_push_clip(models->target, Ri32(clip_box));
}
api(custom) function Rect_f32
draw_clip_pop(Application_Links *app){
draw_set_clip(Application_Links *app, Rect_f32 new_clip){
Models *models = (Models*)app->cmd_context;
return(Rf32(draw_pop_clip(models->target)));
return(draw_set_clip(models->target, new_clip));
}
api(custom) function Text_Layout_ID

View File

@ -77,14 +77,6 @@ draw__write_vertices_in_current_group(Render_Target *target, Render_Vertex *vert
}
}
internal void
draw__set_clip_box(Render_Target *target, Rect_i32 clip_box){
if (target->current_clip_box != clip_box){
target->current_clip_box = clip_box;
draw__begin_new_group(target);
}
}
internal void
draw__set_face_id(Render_Target *target, Face_ID face_id){
if (target->current_face_id != face_id){
@ -105,48 +97,28 @@ draw__set_face_id(Render_Target *target, Face_ID face_id){
////////////////////////////////
internal void
draw_push_clip(Render_Target *target, Rect_i32 clip_box){
if (target->clip_top != -1){
clip_box = intersection_of(clip_box, target->clip_boxes[target->clip_top]);
internal Rect_f32
draw_set_clip(Render_Target *target, Rect_f32 clip_box){
Rect_f32 result = target->current_clip_box;
if (target->current_clip_box != clip_box){
target->current_clip_box = clip_box;
draw__begin_new_group(target);
}
Assert(target->clip_top + 1 < ArrayCount(target->clip_boxes));
target->clip_boxes[++target->clip_top] = clip_box;
draw__set_clip_box(target, clip_box);
}
internal Rect_i32
draw_pop_clip(Render_Target *target){
Assert(target->clip_top > 0);
Rect_i32 result = target->clip_boxes[target->clip_top];
--target->clip_top;
Rect_i32 clip_box = target->clip_boxes[target->clip_top];
draw__set_clip_box(target, clip_box);
return(result);
}
internal void
draw_change_clip(Render_Target *target, Rect_i32 clip_box){
Assert(target->clip_top > -1);
target->clip_boxes[target->clip_top] = clip_box;
draw__set_clip_box(target, clip_box);
}
internal void
begin_frame(Render_Target *target, void *font_set){
linalloc_clear(&target->arena);
target->group_first = 0;
target->group_last = 0;
target->current_face_id = 0;
target->current_clip_box = Ri32(0, 0, target->width, target->height);
target->current_clip_box = Rf32(0, 0, (f32)target->width, (f32)target->height);
target->font_set = font_set;
}
internal void
begin_render_section(Render_Target *target, i32 frame_index, f32 literal_dt, f32 animation_dt){
target->clip_top = -1;
Rect_i32 clip = Ri32(0, 0, target->width, target->height);
draw_push_clip(target, clip);
target->frame_index = frame_index;
target->literal_dt = literal_dt;
target->animation_dt = animation_dt;
@ -154,13 +126,12 @@ begin_render_section(Render_Target *target, i32 frame_index, f32 literal_dt, f32
internal void
end_render_section(Render_Target *target){
Assert(target->clip_top == 0);
}
////////////////////////////////
internal void
draw_rectangle(Render_Target *target, Rect_f32 rect, u32 color){
draw_rectangle_sharp(Render_Target *target, Rect_f32 rect, u32 color){
Render_Vertex vertices[6] = {};
vertices[0].xy = V2(rect.x0, rect.y0);
vertices[1].xy = V2(rect.x1, rect.y0);
@ -168,13 +139,247 @@ draw_rectangle(Render_Target *target, Rect_f32 rect, u32 color){
vertices[3].xy = V2(rect.x1, rect.y0);
vertices[4].xy = V2(rect.x0, rect.y1);
vertices[5].xy = V2(rect.x1, rect.y1);
Vec4 c = unpack_color4(color);
Vec4_f32 c = unpack_color4(color);
for (i32 i = 0; i < 6; i += 1){
vertices[i].color = c;
}
draw__write_vertices_in_current_group(target, vertices, 6);
}
global b32 filled_round_corner = false;
global_const i32 baked_tri_count = 12;
global Vec2_f32 baked_round_corner[baked_tri_count + 1] = {};
internal void
bake_round_corner(void){
if (!filled_round_corner){
filled_round_corner = true;
Range_f32 theta = If32(0.f, half_pi_f32);
for (i32 k = 0; k < baked_tri_count + 1; k += 1){
f32 t = ((f32)k)/((f32)baked_tri_count);
f32 theta1 = lerp(t, theta);
baked_round_corner[k] = V2f32(cos_f32(theta1), sin_f32(theta1));
}
}
}
internal void
draw_round_corners(Render_Target *target, Rect_f32 mid, f32 roundness, u32 color){
bake_round_corner();
for (i32 i = 0; i < 2; i += 1){
for (i32 j = 0; j < 2; j += 1){
Vec2_f32 d = {};
Vec2_f32 p = {};
if (i == 0){
if (j == 0){
p = V2f32(mid.x0, mid.y0);
d = V2f32(-1.f, -1.f);
}
else{
p = V2f32(mid.x1, mid.y0);
d = V2f32( 1.f, -1.f);
}
}
else{
if (j == 0){
p = V2f32(mid.x0, mid.y1);
d = V2f32(-1.f, 1.f);
}
else{
p = V2f32(mid.x1, mid.y1);
d = V2f32( 1.f, 1.f);
}
}
d *= roundness;
Render_Vertex vertices[baked_tri_count*3] = {};
i32 m = 0;
for (i32 k = 0; k < baked_tri_count; k += 1){
Vec2_f32 p0 = baked_round_corner[k + 0];
Vec2_f32 p1 = baked_round_corner[k + 1];
vertices[m].xy = p;
m += 1;
vertices[m].xy = p + hadamard(p0, d);
m += 1;
vertices[m].xy = p + hadamard(p1, d);
m += 1;
}
Vec4_f32 c = unpack_color4(color);
for (i32 k = 0; k < ArrayCount(vertices); k += 1){
vertices[k].color = c;
}
draw__write_vertices_in_current_group(target, vertices, ArrayCount(vertices));
}
}
}
internal void
draw_rectangle(Render_Target *target, Rect_f32 rect, f32 roundness, u32 color){
if (roundness < epsilon_f32){
draw_rectangle_sharp(target, rect, color);
}
else{
Vec2_f32 dim = rect_dim(rect);
Vec2_f32 half_dim = dim*0.5f;
roundness = min(roundness, half_dim.x);
roundness = min(roundness, half_dim.y);
Rect_f32 mid = rect_inner(rect, roundness);
b32 has_x = (mid.x1 > mid.x0);
b32 has_y = (mid.y1 > mid.y0);
if (has_x && has_y){
draw_rectangle_sharp(target, mid, color);
}
if (has_x){
draw_rectangle_sharp(target,
Rf32(mid.x0, rect.y0, mid.x1, mid.y0),
color);
draw_rectangle_sharp(target,
Rf32(mid.x0, mid.y0, mid.x1, rect.y1),
color);
}
if (has_y){
draw_rectangle_sharp(target,
Rf32(rect.x0, mid.y0, mid.x0, mid.y1),
color);
draw_rectangle_sharp(target,
Rf32(mid.x1, mid.y0, rect.x1, mid.y1),
color);
}
draw_round_corners(target, mid, roundness, color);
}
}
internal void
draw_rectangle_outline(Render_Target *target, Rect_f32 rect, f32 roundness, f32 thickness, u32 color){
Vec2_f32 dim = rect_dim(rect);
Vec2_f32 half_dim = dim*0.5f;
f32 max_thickness = min(half_dim.x, half_dim.y);
thickness = clamp(1.f, thickness, max_thickness);
Rect_f32 inner = rect_inner(rect, thickness);
if (roundness < epsilon_f32){
Render_Vertex vertices[24] = {};
vertices[ 0].xy = V2(rect.x0, rect.y0);
vertices[ 1].xy = V2(inner.x0, inner.y0);
vertices[ 2].xy = V2(rect.x1, rect.y0);
vertices[ 3].xy = V2(inner.x0, inner.y0);
vertices[ 4].xy = V2(rect.x1, rect.y0);
vertices[ 5].xy = V2(inner.x1, inner.y0);
vertices[ 6].xy = V2(rect.x1, rect.y0);
vertices[ 7].xy = V2(inner.x1, inner.y0);
vertices[ 8].xy = V2(rect.x1, rect.y1);
vertices[ 9].xy = V2(inner.x1, inner.y0);
vertices[10].xy = V2(rect.x1, rect.y1);
vertices[11].xy = V2(inner.x1, inner.y1);
vertices[12].xy = V2(rect.x1, rect.y1);
vertices[13].xy = V2(inner.x1, inner.y1);
vertices[14].xy = V2(rect.x0, rect.y1);
vertices[15].xy = V2(inner.x1, inner.y1);
vertices[16].xy = V2(rect.x0, rect.y1);
vertices[17].xy = V2(inner.x0, inner.y1);
vertices[18].xy = V2(rect.x0, rect.y1);
vertices[19].xy = V2(inner.x0, inner.y1);
vertices[20].xy = V2(rect.x0, rect.y0);
vertices[21].xy = V2(inner.x0, inner.y1);
vertices[22].xy = V2(rect.x0, rect.y0);
vertices[23].xy = V2(inner.x0, inner.y0);
Vec4_f32 c = unpack_color4(color);
for (i32 i = 0; i < ArrayCount(vertices); i += 1){
vertices[i].color = c;
}
draw__write_vertices_in_current_group(target, vertices, ArrayCount(vertices));
}
else{
roundness = min(roundness, half_dim.x);
roundness = min(roundness, half_dim.y);
Rect_f32 mid = rect_inner(rect, roundness);
b32 has_x = (mid.x1 > mid.x0);
b32 has_y = (mid.y1 > mid.y0);
if (has_x){
draw_rectangle_sharp(target,
Rf32(mid.x0, rect.y0, mid.x1, inner.y0),
color);
draw_rectangle_sharp(target,
Rf32(mid.x0, inner.y1, mid.x1, rect.y1),
color);
}
if (has_y){
draw_rectangle_sharp(target,
Rf32(rect.x0, mid.y0, inner.x0, mid.y1),
color);
draw_rectangle_sharp(target,
Rf32(inner.x1, mid.y0, rect.x1, mid.y1),
color);
}
if (roundness <= thickness){
draw_round_corners(target, mid, roundness, color);
}
else{
bake_round_corner();
for (i32 i = 0; i < 2; i += 1){
for (i32 j = 0; j < 2; j += 1){
Vec2_f32 d = {};
Vec2_f32 p = {};
if (i == 0){
if (j == 0){
p = V2f32(mid.x0, mid.y0);
d = V2f32(-1.f, -1.f);
}
else{
p = V2f32(mid.x1, mid.y0);
d = V2f32( 1.f, -1.f);
}
}
else{
if (j == 0){
p = V2f32(mid.x0, mid.y1);
d = V2f32(-1.f, 1.f);
}
else{
p = V2f32(mid.x1, mid.y1);
d = V2f32( 1.f, 1.f);
}
}
Vec2_f32 d1 = d*roundness;
Vec2_f32 d2 = d*(roundness - thickness);
Render_Vertex vertices[baked_tri_count*6] = {};
i32 m = 0;
for (i32 k = 0; k < baked_tri_count; k += 1){
Vec2_f32 p0 = baked_round_corner[k + 0];
Vec2_f32 p1 = baked_round_corner[k + 1];
vertices[m].xy = p + hadamard(p0, d1);
m += 1;
vertices[m].xy = p + hadamard(p0, d2);
m += 1;
vertices[m].xy = p + hadamard(p1, d1);
m += 1;
vertices[m].xy = p + hadamard(p0, d2);
m += 1;
vertices[m].xy = p + hadamard(p1, d1);
m += 1;
vertices[m].xy = p + hadamard(p1, d2);
m += 1;
}
Vec4_f32 c = unpack_color4(color);
for (i32 k = 0; k < ArrayCount(vertices); k += 1){
vertices[k].color = c;
}
draw__write_vertices_in_current_group(target, vertices, ArrayCount(vertices));
}
}
}
}
}
internal void
draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, f32 x, f32 y, u32 color, u32 flags){
draw__set_face_id(target, face->id);
@ -221,54 +426,6 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, f32 x, f32 y,
////////////////////////////////
internal void
draw_rectangle_outline(Render_Target *target, Rect_f32 rect, u32 color){
draw_rectangle(target, Rf32(rect.x0, rect.y0, rect.x1, rect.y0 + 1), color);
draw_rectangle(target, Rf32(rect.x1 - 1, rect.y0, rect.x1, rect.y1), color);
draw_rectangle(target, Rf32(rect.x0, rect.y1 - 1, rect.x1, rect.y1), color);
draw_rectangle(target, Rf32(rect.x0, rect.y0, rect.x0 + 1, rect.y1), color);
}
////////////////////////////////
internal void
draw_rectangle(Render_Target *target, Rect_i32 rect, u32 color){
draw_rectangle(target, Rf32(rect), color);
}
internal void
draw_rectangle_outline(Render_Target *target, Rect_i32 rect, u32 color){
draw_rectangle_outline(target, Rf32(rect), color);
}
internal void
draw_margin(Render_Target *target, Rect_f32 outer, Rect_f32 inner, u32 color){
draw_rectangle(target, Rf32(outer.x0, outer.y0, outer.x1, inner.y0), color);
draw_rectangle(target, Rf32(outer.x0, inner.y1, outer.x1, outer.y1), color);
draw_rectangle(target, Rf32(outer.x0, inner.y0, inner.x0, inner.y1), color);
draw_rectangle(target, Rf32(inner.x1, inner.y0, outer.x1, inner.y1), color);
}
internal void
draw_margin(Render_Target *target, Rect_f32 outer, f32 width, u32 color){
Rect_f32 inner = rect_inner(outer, width);
draw_margin(target, outer, inner, color);
}
internal void
draw_margin(Render_Target *target, Rect_i32 outer, Rect_i32 inner, u32 color){
draw_rectangle(target, Ri32(outer.x0, outer.y0, outer.x1, inner.y0), color);
draw_rectangle(target, Ri32(outer.x0, inner.y1, outer.x1, outer.y1), color);
draw_rectangle(target, Ri32(outer.x0, inner.y0, inner.x0, inner.y1), color);
draw_rectangle(target, Ri32(inner.x1, inner.y0, outer.x1, inner.y1), color);
}
internal void
draw_margin(Render_Target *target, Rect_i32 outer, i32 width, u32 color){
Rect_i32 inner = rect_inner(outer, width);
draw_margin(target, outer, inner, color);
}
internal Vec2
snap_point_to_boundary(Vec2 point){
point.x = (f32)(floor32(point.x));

View File

@ -41,12 +41,10 @@ struct Render_Group{
Render_Vertex_List vertex_list;
// parameters
Face_ID face_id;
Rect_i32 clip_box;
Rect_f32 clip_box;
};
struct Render_Target{
Rect_i32 clip_boxes[5];
i32 clip_top;
b8 clip_all;
i32 width;
i32 height;
@ -66,7 +64,7 @@ struct Render_Target{
i32 group_count;
Face_ID current_face_id;
Rect_i32 current_clip_box;
Rect_f32 current_clip_box;
void *font_set;
u32 fallback_texture_id;
};

View File

@ -322,6 +322,16 @@ mod_f32(f32 x, i32 m){
f32 r = ((i32)(whole) % m) + frac;
return(r);
}
internal f32
sin_f32(f32 x){
return(sinf(x));
}
internal f32
cos_f32(f32 x){
return(cosf(x));
}
#endif
////////////////////////////////
@ -1480,24 +1490,17 @@ near_zero(Vec3_f32 p){ return(near_zero(p, epsilon_f32)); }
internal b32
near_zero(Vec4_f32 p){ return(near_zero(p, epsilon_f32)); }
////////////////////////////////
internal b32
operator==(Rect_i32 a, Rect_i32 b){
return(a.p0 == b.p0 && a.p1 == b.p1);
internal Vec2_f32
hadamard(Vec2_f32 a, Vec2_f32 b){
return(V2f32(a.x*b.x, a.y*b.y));
}
internal b32
operator==(Rect_f32 a, Rect_f32 b){
return(a.p0 == b.p0 && a.p1 == b.p1);
internal Vec3_f32
hadamard(Vec3_f32 a, Vec3_f32 b){
return(V3f32(a.x*b.x, a.y*b.y, a.z*b.z));
}
internal b32
operator!=(Rect_i32 a, Rect_i32 b){
return(!(a == b));
}
internal b32
operator!=(Rect_f32 a, Rect_f32 b){
return(!(a == b));
internal Vec4_f32
hadamard(Vec4_f32 a, Vec4_f32 b){
return(V4f32(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w));
}
////////////////////////////////
@ -1507,6 +1510,11 @@ lerp(f32 a, f32 t, f32 b){
return(a + (b-a)*t);
}
internal f32
lerp(f32 t, Interval_f32 x){
return(x.min + (x.max - x.min)*t);
}
internal i32
lerp(i32 a, f32 t, i32 b){
return((i32)(lerp((f32)a, t, (f32)b)));
@ -1538,6 +1546,26 @@ unlerp(f32 a, f32 x, f32 b){
////////////////////////////////
internal b32
operator==(Rect_i32 a, Rect_i32 b){
return(a.p0 == b.p0 && a.p1 == b.p1);
}
internal b32
operator==(Rect_f32 a, Rect_f32 b){
return(a.p0 == b.p0 && a.p1 == b.p1);
}
internal b32
operator!=(Rect_i32 a, Rect_i32 b){
return(!(a == b));
}
internal b32
operator!=(Rect_f32 a, Rect_f32 b){
return(!(a == b));
}
////////////////////////////////
// TODO(allen): Convert colors to Vec4
internal u32
color_blend(u32 a, f32 t, u32 b){

View File

@ -284,6 +284,9 @@ global_const f32 min_f32 = -max_f32;
global_const f32 smallest_positive_f32 = 1.1754943508e-38f;
global_const f32 epsilon_f32 = 5.96046448e-8f;
global_const f32 pi_f32 = 3.14159265359f;
global_const f32 half_pi_f32 = 1.5707963267f;
#define clamp_signed_to_i8(x) (i8)(clamp((i64)i8_min, (i64)(x), (i64)i8_max))
#define clamp_signed_to_i16(x) (i16)(clamp((i64)i16_min, (i64)(x), (i64)i16_max))
#define clamp_signed_to_i32(x) (i32)(clamp((i64)i32_min, (i64)(x), (i64)i32_max))

View File

@ -143,8 +143,8 @@ draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID
}
else{
if (back_colors != 0){
draw_character_block(app, text_layout_id, range.min, back_colors[color_index]);
draw_character_block(app, text_layout_id, range.max - 1, back_colors[color_index]);
draw_character_block(app, text_layout_id, range.min, 0.f, back_colors[color_index]);
draw_character_block(app, text_layout_id, range.max - 1, 0.f, back_colors[color_index]);
}
if (fore_colors != 0){
paint_text_color_pos(app, text_layout_id, range.min, fore_colors[color_index]);
@ -440,6 +440,10 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
draw_line_highlight(app, text_layout_id, line_number, Stag_Highlight_Cursor_Line);
}
// NOTE(allen): Roundness
f32 cursor_roundness = 0.f;
f32 mark_thickness = 0.f;
// NOTE(allen): Highlight range
b32 has_highlight_range = false;
{
@ -455,7 +459,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Marker marker_range[2];
if (managed_object_load_data(app, *highlight, 0, 2, marker_range)){
Range_i64 range = Ii64(marker_range[0].pos, marker_range[1].pos);
draw_character_block(app, text_layout_id, range, Stag_Highlight);
draw_character_block(app, text_layout_id, range, cursor_roundness, Stag_Highlight);
paint_text_color(app, text_layout_id, range, Stag_At_Highlight);
}
}
@ -469,13 +473,21 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
case FCoderMode_Original:
{
if (is_active_view){
draw_character_block(app, text_layout_id, cursor_pos, Stag_Cursor);
paint_text_color_pos(app, text_layout_id, cursor_pos, Stag_At_Cursor);
draw_character_wire_frame(app, text_layout_id, mark_pos, Stag_Mark);
draw_character_block(app, text_layout_id, cursor_pos,
cursor_roundness, Stag_Cursor);
paint_text_color_pos(app, text_layout_id, cursor_pos,
Stag_At_Cursor);
draw_character_wire_frame(app, text_layout_id, mark_pos,
cursor_roundness, mark_thickness,
Stag_Mark);
}
else{
draw_character_wire_frame(app, text_layout_id, mark_pos, Stag_Mark);
draw_character_wire_frame(app, text_layout_id, cursor_pos, Stag_Cursor);
draw_character_wire_frame(app, text_layout_id, mark_pos,
cursor_roundness, mark_thickness,
Stag_Mark);
draw_character_wire_frame(app, text_layout_id, cursor_pos,
cursor_roundness, mark_thickness,
Stag_Cursor);
}
}break;
@ -483,7 +495,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
{
if (cursor_pos != mark_pos){
Range_i64 range = Ii64(cursor_pos, mark_pos);
draw_character_block(app, text_layout_id, range, Stag_Highlight);
draw_character_block(app, text_layout_id, range,
cursor_roundness, Stag_Highlight);
paint_text_color(app, text_layout_id, range, Stag_At_Highlight);
}
draw_character_i_bar(app, text_layout_id, cursor_pos, Stag_Cursor);
@ -491,9 +504,11 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
}
}
draw_clip_push(app, buffer_rect);
{
Rect_f32 prev_clip = draw_set_clip(app, buffer_rect);
draw_text_layout(app, text_layout_id);
draw_clip_pop(app);
draw_set_clip(app, prev_clip);
}
// NOTE(allen): FPS HUD
if (show_fps_hud){
@ -509,8 +524,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Rect_f32 hud_rect = view_get_screen_rect(app, view_id);
hud_rect.y0 = hud_rect.y1 - line_height*(f32)(history_depth);
draw_rectangle(app, hud_rect, 0xFF000000);
draw_rectangle_outline(app, hud_rect, 0xFFFFFFFF);
draw_rectangle(app, hud_rect, 0.f, 0xFF000000);
draw_rectangle_outline(app, hud_rect, 0.f, 1.f, 0xFFFFFFFF);
Vec2 p = hud_rect.p0;
@ -561,7 +576,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
bar.y1 = bar.y0 + line_height + 2.f;
r_cursor.y0 = bar.y1;
draw_rectangle(app, bar, Stag_Bar);
draw_rectangle(app, bar, 0.f, Stag_Bar);
Fancy_Color base_color = fancy_id(Stag_Base);
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
@ -653,10 +668,9 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
left_margin.x1 = left_margin.x0 + margin_width + 2.f;
r_cursor.x0 = left_margin.x1;
draw_rectangle(app, left_margin, Stag_Line_Numbers_Back);
draw_rectangle(app, left_margin, 0.f, Stag_Line_Numbers_Back);
Rect_f32 clip_region = left_margin;
draw_clip_push(app, clip_region);
Rect_f32 prev_clip = draw_set_clip(app, left_margin);
Fancy_Color line_color = fancy_id(Stag_Line_Numbers_Text);
@ -674,7 +688,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
line_number += 1;
}
draw_clip_pop(app);
draw_set_clip(app, prev_clip);
}
text_layout_free(app, text_layout_id);
@ -711,8 +725,8 @@ default_ui_render_caller(Application_Links *app, View_ID view_id, Rect_f32 rect,
f32 line_height = metrics.line_height;
f32 info_height = (f32)item->line_count*line_height;
draw_rectangle(app, inner, Stag_Back);
Vec2 p = V2(inner.x0 + 3.f, (f32)(round32((inner.y0 + inner.y1 - info_height)*0.5f)));
draw_rectangle(app, inner, 0.f, Stag_Back);
Vec2_f32 p = V2f32(inner.x0 + 3.f, (f32)(round32((inner.y0 + inner.y1 - info_height)*0.5f)));
for (i32 i = 0; i < item->line_count; i += 1){
draw_fancy_string(app, face_id, item->lines[i].first, p, Stag_Default, 0, 0, V2(1.f, 0));
p.y += line_height;
@ -735,9 +749,9 @@ internal void
default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view, b32 is_active){
Rect_f32 view_rect = view_get_screen_rect(app, view);
Rect_f32 inner = rect_inner(view_rect, 3);
draw_rectangle(app, view_rect, get_margin_color(is_active?UIActivation_Active:UIActivation_None));
draw_rectangle(app, inner, Stag_Back);
draw_clip_push(app, inner);
draw_rectangle(app, view_rect, 0.f, get_margin_color(is_active?UIActivation_Active:UIActivation_None));
draw_rectangle(app, inner, 0.f, Stag_Back);
Rect_f32 prev_clip = draw_set_clip(app, inner);
Managed_Scope scope = view_get_managed_scope(app, view);
View_Render_Hook **hook_ptr = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
@ -755,7 +769,7 @@ default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view,
hook(app, view, frame_info, inner);
}
draw_clip_pop(app);
draw_set_clip(app, prev_clip);
}
RENDER_CALLER_SIG(default_render_caller){

View File

@ -242,7 +242,7 @@ get_fancy_string_advance(Application_Links *app, Face_ID font_id, Fancy_String *
static void
draw_rectangle_fancy(Application_Links *app, Rect_f32 rect, Fancy_Color fancy_color){
int_color color = int_color_from(app, fancy_color);
draw_rectangle(app, rect, color);
draw_rectangle(app, rect, 0.f, color);
}
////////////////////////////////

View File

@ -2326,35 +2326,35 @@ draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 string, Vec
internal void
draw_margin(Application_Links *app, Rect_f32 outer, Rect_f32 inner, int_color color){
draw_rectangle(app, Rf32(outer.x0, outer.y0, outer.x1, inner.y0), color);
draw_rectangle(app, Rf32(outer.x0, inner.y1, outer.x1, outer.y1), color);
draw_rectangle(app, Rf32(outer.x0, inner.y0, inner.x0, inner.y1), color);
draw_rectangle(app, Rf32(inner.x1, inner.y0, outer.x1, inner.y1), color);
draw_rectangle(app, Rf32(outer.x0, outer.y0, outer.x1, inner.y0), 0.f, color);
draw_rectangle(app, Rf32(outer.x0, inner.y1, outer.x1, outer.y1), 0.f, color);
draw_rectangle(app, Rf32(outer.x0, inner.y0, inner.x0, inner.y1), 0.f, color);
draw_rectangle(app, Rf32(inner.x1, inner.y0, outer.x1, inner.y1), 0.f, color);
}
internal void
draw_character_block(Application_Links *app, Text_Layout_ID layout, i64 pos, int_color color){
draw_character_block(Application_Links *app, Text_Layout_ID layout, i64 pos, f32 roundness, int_color color){
Rect_f32 rect = text_layout_character_on_screen(app, layout, pos);
draw_rectangle(app, rect, color);
draw_rectangle(app, rect, roundness, color);
}
internal void
draw_character_block(Application_Links *app, Text_Layout_ID layout, Range_i64 range, int_color color){
draw_character_block(Application_Links *app, Text_Layout_ID layout, Range_i64 range, f32 roundness, int_color color){
for (i64 i = range.first; i < range.one_past_last; i += 1){
draw_character_block(app, layout, i, color);
draw_character_block(app, layout, i, roundness, color);
}
}
internal void
draw_character_wire_frame(Application_Links *app, Text_Layout_ID layout, i64 pos, int_color color){
draw_character_wire_frame(Application_Links *app, Text_Layout_ID layout, i64 pos, f32 roundness, f32 thickness, int_color color){
Rect_f32 rect = text_layout_character_on_screen(app, layout, pos);
draw_rectangle_outline(app, rect, color);
draw_rectangle_outline(app, rect, roundness, thickness, color);
}
internal void
draw_character_wire_frame(Application_Links *app, Text_Layout_ID layout, Range_i64 range, int_color color){
draw_character_wire_frame(Application_Links *app, Text_Layout_ID layout, Range_i64 range, f32 roundness, f32 thickness, int_color color){
for (i64 i = range.first; i < range.one_past_last; i += 1){
draw_character_wire_frame(app, layout, i, color);
draw_character_wire_frame(app, layout, i, roundness, thickness, color);
}
}
@ -2362,7 +2362,7 @@ internal void
draw_character_i_bar(Application_Links *app, Text_Layout_ID layout, i64 pos, int_color color){
Rect_f32 rect = text_layout_character_on_screen(app, layout, pos);
rect.x1 = rect.x0 + 1.f;
draw_rectangle(app, rect, color);
draw_rectangle(app, rect, 0.f, color);
}
internal void
@ -2372,7 +2372,7 @@ draw_line_highlight(Application_Links *app, Text_Layout_ID layout, Range_i64 lin
Range_f32 y = range_union(y1, y2);
if (range_size(y) > 0.f){
Rect_f32 region = text_layout_region(app, layout);
draw_rectangle(app, Rf32(rect_range_x(region), y), color);
draw_rectangle(app, Rf32(rect_range_x(region), y), 0.f, color);
}
}

View File

@ -157,8 +157,7 @@ vtable->draw_string_oriented = draw_string_oriented;
vtable->get_string_advance = get_string_advance;
vtable->draw_rectangle = draw_rectangle;
vtable->draw_rectangle_outline = draw_rectangle_outline;
vtable->draw_clip_push = draw_clip_push;
vtable->draw_clip_pop = draw_clip_pop;
vtable->draw_set_clip = draw_set_clip;
vtable->text_layout_create = text_layout_create;
vtable->text_layout_region = text_layout_region;
vtable->text_layout_get_buffer = text_layout_get_buffer;
@ -332,8 +331,7 @@ draw_string_oriented = vtable->draw_string_oriented;
get_string_advance = vtable->get_string_advance;
draw_rectangle = vtable->draw_rectangle;
draw_rectangle_outline = vtable->draw_rectangle_outline;
draw_clip_push = vtable->draw_clip_push;
draw_clip_pop = vtable->draw_clip_pop;
draw_set_clip = vtable->draw_set_clip;
text_layout_create = vtable->text_layout_create;
text_layout_region = vtable->text_layout_region;
text_layout_get_buffer = vtable->text_layout_get_buffer;

View File

@ -153,10 +153,9 @@
#define custom_set_window_title_sig() b32 custom_set_window_title(Application_Links* app, String_Const_u8 title)
#define custom_draw_string_oriented_sig() Vec2 custom_draw_string_oriented(Application_Links* app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta)
#define custom_get_string_advance_sig() f32 custom_get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str)
#define custom_draw_rectangle_sig() void custom_draw_rectangle(Application_Links* app, Rect_f32 rect, int_color color)
#define custom_draw_rectangle_outline_sig() void custom_draw_rectangle_outline(Application_Links* app, Rect_f32 rect, int_color color)
#define custom_draw_clip_push_sig() void custom_draw_clip_push(Application_Links* app, Rect_f32 clip_box)
#define custom_draw_clip_pop_sig() Rect_f32 custom_draw_clip_pop(Application_Links* app)
#define custom_draw_rectangle_sig() void custom_draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, int_color color)
#define custom_draw_rectangle_outline_sig() void custom_draw_rectangle_outline(Application_Links* app, Rect_f32 rect, f32 roundness, f32 thickness, int_color color)
#define custom_draw_set_clip_sig() Rect_f32 custom_draw_set_clip(Application_Links* app, Rect_f32 new_clip)
#define custom_text_layout_create_sig() Text_Layout_ID custom_text_layout_create(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point)
#define custom_text_layout_region_sig() Rect_f32 custom_text_layout_region(Application_Links* app, Text_Layout_ID text_layout_id)
#define custom_text_layout_get_buffer_sig() Buffer_ID custom_text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id)
@ -324,10 +323,9 @@ typedef void custom_send_exit_signal_type(Application_Links* app);
typedef b32 custom_set_window_title_type(Application_Links* app, String_Const_u8 title);
typedef Vec2 custom_draw_string_oriented_type(Application_Links* app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta);
typedef f32 custom_get_string_advance_type(Application_Links* app, Face_ID font_id, String_Const_u8 str);
typedef void custom_draw_rectangle_type(Application_Links* app, Rect_f32 rect, int_color color);
typedef void custom_draw_rectangle_outline_type(Application_Links* app, Rect_f32 rect, int_color color);
typedef void custom_draw_clip_push_type(Application_Links* app, Rect_f32 clip_box);
typedef Rect_f32 custom_draw_clip_pop_type(Application_Links* app);
typedef void custom_draw_rectangle_type(Application_Links* app, Rect_f32 rect, f32 roundness, int_color color);
typedef void custom_draw_rectangle_outline_type(Application_Links* app, Rect_f32 rect, f32 roundness, f32 thickness, int_color color);
typedef Rect_f32 custom_draw_set_clip_type(Application_Links* app, Rect_f32 new_clip);
typedef Text_Layout_ID custom_text_layout_create_type(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point);
typedef Rect_f32 custom_text_layout_region_type(Application_Links* app, Text_Layout_ID text_layout_id);
typedef Buffer_ID custom_text_layout_get_buffer_type(Application_Links* app, Text_Layout_ID text_layout_id);
@ -498,8 +496,7 @@ custom_draw_string_oriented_type *draw_string_oriented;
custom_get_string_advance_type *get_string_advance;
custom_draw_rectangle_type *draw_rectangle;
custom_draw_rectangle_outline_type *draw_rectangle_outline;
custom_draw_clip_push_type *draw_clip_push;
custom_draw_clip_pop_type *draw_clip_pop;
custom_draw_set_clip_type *draw_set_clip;
custom_text_layout_create_type *text_layout_create;
custom_text_layout_region_type *text_layout_region;
custom_text_layout_get_buffer_type *text_layout_get_buffer;
@ -669,10 +666,9 @@ internal void send_exit_signal(Application_Links* app);
internal b32 set_window_title(Application_Links* app, String_Const_u8 title);
internal Vec2 draw_string_oriented(Application_Links* app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta);
internal f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str);
internal void draw_rectangle(Application_Links* app, Rect_f32 rect, int_color color);
internal void draw_rectangle_outline(Application_Links* app, Rect_f32 rect, int_color color);
internal void draw_clip_push(Application_Links* app, Rect_f32 clip_box);
internal Rect_f32 draw_clip_pop(Application_Links* app);
internal void draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, int_color color);
internal void draw_rectangle_outline(Application_Links* app, Rect_f32 rect, f32 roundness, f32 thickness, int_color color);
internal Rect_f32 draw_set_clip(Application_Links* app, Rect_f32 new_clip);
internal Text_Layout_ID text_layout_create(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point);
internal Rect_f32 text_layout_region(Application_Links* app, Text_Layout_ID text_layout_id);
internal Buffer_ID text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id);
@ -844,8 +840,7 @@ global custom_draw_string_oriented_type *draw_string_oriented = 0;
global custom_get_string_advance_type *get_string_advance = 0;
global custom_draw_rectangle_type *draw_rectangle = 0;
global custom_draw_rectangle_outline_type *draw_rectangle_outline = 0;
global custom_draw_clip_push_type *draw_clip_push = 0;
global custom_draw_clip_pop_type *draw_clip_pop = 0;
global custom_draw_set_clip_type *draw_set_clip = 0;
global custom_text_layout_create_type *text_layout_create = 0;
global custom_text_layout_region_type *text_layout_region = 0;
global custom_text_layout_get_buffer_type *text_layout_get_buffer = 0;

View File

@ -153,10 +153,9 @@ api(custom) function void send_exit_signal(Application_Links* app);
api(custom) function b32 set_window_title(Application_Links* app, String_Const_u8 title);
api(custom) function Vec2 draw_string_oriented(Application_Links* app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta);
api(custom) function f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str);
api(custom) function void draw_rectangle(Application_Links* app, Rect_f32 rect, int_color color);
api(custom) function void draw_rectangle_outline(Application_Links* app, Rect_f32 rect, int_color color);
api(custom) function void draw_clip_push(Application_Links* app, Rect_f32 clip_box);
api(custom) function Rect_f32 draw_clip_pop(Application_Links* app);
api(custom) function void draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, int_color color);
api(custom) function void draw_rectangle_outline(Application_Links* app, Rect_f32 rect, f32 roundness, f32 thickness, int_color color);
api(custom) function Rect_f32 draw_set_clip(Application_Links* app, Rect_f32 new_clip);
api(custom) function Text_Layout_ID text_layout_create(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point);
api(custom) function Rect_f32 text_layout_region(Application_Links* app, Text_Layout_ID text_layout_id);
api(custom) function Buffer_ID text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id);

View File

@ -9,8 +9,6 @@
// TOP
//#define GL_FUNC(N,R,P) typedef R (N##_Function) P; N##_Function *P = 0;
//#include "4ed_opengl_funcs.h"
#include "4ed_opengl_defines.h"
internal void
@ -241,7 +239,7 @@ gl_render(Render_Target *t){
for (Render_Group *group = t->group_first;
group != 0;
group = group->next){
Rect_i32 box = group->clip_box;
Rect_i32 box = Ri32(group->clip_box);
glScissor(box.x0, height - box.y1, box.x1 - box.x0, box.y1 - box.y0);
i32 vertex_count = group->vertex_list.vertex_count;