From 5edbd93d26510ef62fccfe55e2e54d675dd4e20c Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 5 Oct 2019 23:59:35 -0700 Subject: [PATCH] Cleaning up euclidean space types; simplifying some rendering stuff --- 4ed.cpp | 4 +- 4ed_api_implementation.cpp | 72 ++++++----- 4ed_layout.cpp | 12 +- 4ed_render_target.cpp | 54 ++++---- 4ed_render_target.h | 4 +- custom/4coder_base_types.cpp | 146 ++++++++++++++++++++-- custom/4coder_base_types.h | 9 +- custom/4coder_default_hooks.cpp | 12 +- custom/4coder_helper.cpp | 31 ++--- custom/4coder_search.cpp | 6 +- custom/4coder_string_match.cpp | 4 +- custom/4coder_ui_helper.cpp | 30 +---- custom/generated/custom_api.cpp | 2 + custom/generated/custom_api.h | 23 ++-- custom/generated/custom_api_master_list.h | 7 +- platform_win32/win32_4ed.cpp | 24 +--- 16 files changed, 267 insertions(+), 173 deletions(-) diff --git a/4ed.cpp b/4ed.cpp index 3374cf51..602e5fb9 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1058,8 +1058,8 @@ App_Step_Sig(app_step){ input->keys.keys[input->keys.count++] = mouse_event; } if (input->mouse.p != models->prev_p){ - b32 was_in_window = rect_contains_point(i32R(0, 0, prev_dim.x, prev_dim.y), models->prev_p); - b32 is_in_window = rect_contains_point(i32R(0, 0, current_dim.x, current_dim.y), input->mouse.p); + b32 was_in_window = rect_contains_point(Ri32(0, 0, prev_dim.x, prev_dim.y), models->prev_p); + b32 is_in_window = rect_contains_point(Ri32(0, 0, current_dim.x, current_dim.y), input->mouse.p); if (is_in_window || was_in_window){ mouse_event.keycode = key_mouse_move; input->keys.keys[input->keys.count++] = mouse_event; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 331464f3..814f1327 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -272,7 +272,7 @@ buffer_seek_string(Application_Links *app, Buffer_ID buffer, String_Const_u8 nee if (api_check_buffer(file)){ if (needle.size == 0){ result.flags = StringMatch_CaseSensitive; - result.range = make_range_i64(start_pos); + result.range = Ii64(start_pos); } else{ Scratch_Block scratch(app); @@ -283,12 +283,12 @@ buffer_seek_string(Application_Links *app, Buffer_ID buffer, String_Const_u8 nee if (direction == Scan_Forward){ i64 adjusted_pos = start_pos + 1; start_pos = clamp_top(adjusted_pos, size); - range = make_range_i64(adjusted_pos, size); + range = Ii64(adjusted_pos, size); } else{ i64 adjusted_pos = start_pos - 1 + needle.size; start_pos = clamp_bot(0, adjusted_pos); - range = make_range_i64(0, adjusted_pos); + range = Ii64(0, adjusted_pos); } buffer_chunks_clamp(&chunks, range); if (chunks.first != 0){ @@ -348,13 +348,13 @@ buffer_seek_character_class(Application_Links *app, Buffer_ID buffer, Character_ break; } else if (past_end == 1){ - result.range = make_range_i64(size); + result.range = Ii64(size); break; } u8 v = chunks.vals[pos.chunk_index].str[pos.chunk_pos]; if (character_predicate_check_character(*predicate, v)){ result.buffer = buffer; - result.range = make_range_i64(pos.real_pos, pos.real_pos + 1); + result.range = Ii64(pos.real_pos, pos.real_pos + 1); break; } } @@ -1156,7 +1156,7 @@ view_get_screen_rect(Application_Links *app, View_ID view_id){ Rect_f32 result = {}; View *view = imp_get_view(models, view_id); if (api_check_view(view)){ - result = f32R(view->panel->rect_full); + result = Rf32(view->panel->rect_full); } return(result); } @@ -2713,8 +2713,8 @@ draw_helper__models_space_to_screen_space(Models *models, Vec2 point){ return(point + c); } -function f32_Rect -draw_helper__models_space_to_screen_space(Models *models, f32_Rect rect){ +function Rect_f32 +draw_helper__models_space_to_screen_space(Models *models, Rect_f32 rect){ Vec2 c = models_get_coordinate_center(models); rect.p0 += c; rect.p1 += c; @@ -2779,7 +2779,7 @@ draw_clip_push(Application_Links *app, Rect_f32 clip_box){ draw_push_clip(models->target, Ri32(clip_box)); } -api(custom) function f32_Rect +api(custom) function Rect_f32 draw_clip_pop(Application_Links *app){ Models *models = (Models*)app->cmd_context; return(Rf32(draw_pop_clip(models->target))); @@ -2848,14 +2848,24 @@ text_layout_create(Application_Links *app, Buffer_ID buffer_id, Rect_f32 rect, B return(result); } -api(custom) function b32 -text_layout_get_buffer(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID *buffer_id_out){ +api(custom) function Rect_f32 +text_layout_region(Application_Links *app, Text_Layout_ID text_layout_id){ Models *models = (Models*)app->cmd_context; - b32 result = false; + Rect_f32 result = {}; Text_Layout *layout = text_layout_get(&models->text_layouts, text_layout_id); if (layout != 0){ - *buffer_id_out = layout->buffer_id; - result = true; + result = layout->rect; + } + return(result); +} + +api(custom) function Buffer_ID +text_layout_get_buffer(Application_Links *app, Text_Layout_ID text_layout_id){ + Models *models = (Models*)app->cmd_context; + Buffer_ID result = 0; + Text_Layout *layout = text_layout_get(&models->text_layouts, text_layout_id); + if (layout != 0){ + result = layout->buffer_id; } return(result); } @@ -2871,41 +2881,43 @@ text_layout_get_visible_range(Application_Links *app, Text_Layout_ID text_layout return(result); } -api(custom) function Rect_f32 +api(custom) function Range_f32 text_layout_line_on_screen(Application_Links *app, Text_Layout_ID layout_id, i64 line_number){ Models *models = (Models*)app->cmd_context; - Rect_f32 result = {}; + Range_f32 result = {}; Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id); - if (layout != 0 && range_contains_inclusive(layout->visible_line_number_range, line_number)){ + if (layout == 0){ + return(result); + } + Rect_f32 rect = layout->rect; + if (range_contains_inclusive(layout->visible_line_number_range, line_number)){ Editing_File *file = imp_get_file(models, layout->buffer_id); if (api_check_buffer(file)){ - Rect_f32 rect = layout->rect; f32 width = rect_width(rect); Face *face = file_get_face(models, file); - f32 top = 0.f; - f32 bot = 0.f; for (i64 line_number_it = layout->visible_line_number_range.first;; line_number_it += 1){ Buffer_Layout_Item_List line = file_get_line_layout(models, file, width, face, line_number_it); - bot += line.height; + result.max += line.height; if (line_number_it == line_number){ break; } - top = bot; + result.min = result.max; } - top -= layout->point.pixel_shift.y; - bot -= layout->point.pixel_shift.y; - - result = Rf32(rect.x0, rect.y0 + top, rect.x1, rect.y0 + bot); - result = rect_intersect(rect, result); - + result -= layout->point.pixel_shift.y; + result = range_intersect(result, rect_range_y(rect)); Vec2_f32 coordinate_center = models_get_coordinate_center(models); - result.p0 -= coordinate_center; - result.p1 -= coordinate_center; + result -= coordinate_center.y; } } + else if (line_number < layout->visible_line_number_range.min){ + result = If32(rect.y0, rect.y0); + } + else if (line_number > layout->visible_line_number_range.max){ + result = If32(rect.y1, rect.y1); + } return(result); } diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 05d966b4..212a705d 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -51,7 +51,7 @@ layout__free_panel(Layout *layout, Panel *panel){ } internal void -layout__set_panel_rectangle(Layout *layout, Panel *panel, i32_Rect rect){ +layout__set_panel_rectangle(Layout *layout, Panel *panel, Rect_i32 rect){ panel->rect_full = rect; panel->rect_inner = rect_inner(rect, layout->margin); } @@ -86,8 +86,8 @@ layout_propogate_sizes_down_from_node(Layout *layout, Panel *panel){ Panel *tl_panel = panel->tl_panel; Panel *br_panel = panel->br_panel; - i32_Rect r1 = panel->rect_full; - i32_Rect r2 = panel->rect_full; + Rect_i32 r1 = panel->rect_full; + Rect_i32 r2 = panel->rect_full; if (panel->vertical_split){ i32 x_pos = layout__evaluate_split(panel->split, r1.x0, r1.x1); @@ -299,7 +299,7 @@ internal void layout_set_margin(Layout *layout, i32 margin){ if (layout->margin != margin){ layout->margin = margin; - layout__set_panel_rectangle(layout, layout->root, i32R(0, 0, layout->full_dim.x, layout->full_dim.y)); + layout__set_panel_rectangle(layout, layout->root, Ri32(0, 0, layout->full_dim.x, layout->full_dim.y)); layout_propogate_sizes_down_from_node(layout, layout->root); layout->panel_state_dirty = true; } @@ -309,7 +309,7 @@ internal void layout_set_root_size(Layout *layout, Vec2_i32 dim){ if (layout->full_dim != dim){ layout->full_dim = dim; - layout__set_panel_rectangle(layout, layout->root, i32R(0, 0, dim.x, dim.y)); + layout__set_panel_rectangle(layout, layout->root, Ri32(0, 0, dim.x, dim.y)); layout_propogate_sizes_down_from_node(layout, layout->root); layout->panel_state_dirty = true; } @@ -423,7 +423,7 @@ layout__reverse_evaluate_panel_split(Panel *panel, i32 position){ internal void layout__set_split_absolute_position_inner(Panel *panel){ if (panel->kind == PanelKind_Intermediate){ - i32_Rect r = panel->rect_full; + Rect_i32 r = panel->rect_full; i32 position = 0; if (panel->vertical_split){ position = layout__evaluate_split(panel->split, r.x0, r.x1); diff --git a/4ed_render_target.cpp b/4ed_render_target.cpp index 307d303b..587d8d4e 100644 --- a/4ed_render_target.cpp +++ b/4ed_render_target.cpp @@ -118,9 +118,9 @@ draw_push_clip(Render_Target *target, Rect_i32 clip_box){ internal Rect_i32 draw_pop_clip(Render_Target *target){ Assert(target->clip_top > 0); - i32_Rect result = target->clip_boxes[target->clip_top]; + Rect_i32 result = target->clip_boxes[target->clip_top]; --target->clip_top; - i32_Rect clip_box = target->clip_boxes[target->clip_top]; + Rect_i32 clip_box = target->clip_boxes[target->clip_top]; draw__set_clip_box(target, clip_box); return(result); } @@ -145,14 +145,8 @@ begin_frame(Render_Target *target, void *font_set){ internal void begin_render_section(Render_Target *target, i32 frame_index, f32 literal_dt, f32 animation_dt){ target->clip_top = -1; - - i32_Rect clip; - clip.x0 = 0; - clip.y0 = 0; - clip.x1 = target->width; - clip.y1 = target->height; + 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; @@ -196,7 +190,7 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, f32 x, f32 y, Render_Vertex vertices[6] = {}; if (!HasFlag(flags, GlyphFlag_Rotate90)){ - f32_Rect xy = Rf32(x + bounds.xy_off.x0, y + bounds.xy_off.y0, + Rect_f32 xy = Rf32(x + bounds.xy_off.x0, y + bounds.xy_off.y0, x + bounds.xy_off.x1, y + bounds.xy_off.y1); vertices[0].xy = V2(xy.x0, xy.y1); vertices[0].uvw = V3(uv.x0, uv.y1, bounds.w); @@ -205,7 +199,7 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, f32 x, f32 y, vertices[5].xy = V2(xy.x1, xy.y0); vertices[5].uvw = V3(uv.x1, uv.y0, bounds.w); } else{ - f32_Rect xy = Rf32(x - bounds.xy_off.y1, y + bounds.xy_off.x0, + Rect_f32 xy = Rf32(x - bounds.xy_off.y1, y + bounds.xy_off.x0, x - bounds.xy_off.y0, y + bounds.xy_off.x1); vertices[0].xy = V2(xy.x0, xy.y1); vertices[0].uvw = V3(uv.x1, uv.y1, bounds.w); @@ -228,7 +222,7 @@ draw_font_glyph(Render_Target *target, Face *face, u32 codepoint, f32 x, f32 y, //////////////////////////////// internal void -draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){ +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); @@ -238,40 +232,40 @@ draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){ //////////////////////////////// internal void -draw_rectangle(Render_Target *target, i32_Rect rect, u32 color){ - draw_rectangle(target, f32R(rect), color); +draw_rectangle(Render_Target *target, Rect_i32 rect, u32 color){ + draw_rectangle(target, Rf32(rect), color); } internal void -draw_rectangle_outline(Render_Target *target, i32_Rect rect, u32 color){ - draw_rectangle_outline(target, f32R(rect), color); +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, f32_Rect outer, f32_Rect inner, u32 color){ - draw_rectangle(target, f32R(outer.x0, outer.y0, outer.x1, inner.y0), color); - draw_rectangle(target, f32R(outer.x0, inner.y1, outer.x1, outer.y1), color); - draw_rectangle(target, f32R(outer.x0, inner.y0, inner.x0, inner.y1), color); - draw_rectangle(target, f32R(inner.x1, inner.y0, outer.x1, inner.y1), color); +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, f32_Rect outer, f32 width, u32 color){ - f32_Rect inner = rect_inner(outer, width); +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, i32_Rect outer, i32_Rect inner, u32 color){ - draw_rectangle(target, i32R(outer.x0, outer.y0, outer.x1, inner.y0), color); - draw_rectangle(target, i32R(outer.x0, inner.y1, outer.x1, outer.y1), color); - draw_rectangle(target, i32R(outer.x0, inner.y0, inner.x0, inner.y1), color); - draw_rectangle(target, i32R(inner.x1, inner.y0, outer.x1, inner.y1), color); +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, i32_Rect outer, i32 width, u32 color){ - i32_Rect inner = rect_inner(outer, width); +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); } diff --git a/4ed_render_target.h b/4ed_render_target.h index 91b1a0a4..7180b0ff 100644 --- a/4ed_render_target.h +++ b/4ed_render_target.h @@ -41,11 +41,11 @@ struct Render_Group{ Render_Vertex_List vertex_list; // parameters Face_ID face_id; - i32_Rect clip_box; + Rect_i32 clip_box; }; struct Render_Target{ - i32_Rect clip_boxes[5]; + Rect_i32 clip_boxes[5]; i32 clip_top; b8 clip_all; i32 width; diff --git a/custom/4coder_base_types.cpp b/custom/4coder_base_types.cpp index 69e3b2f0..0260ebf1 100644 --- a/custom/4coder_base_types.cpp +++ b/custom/4coder_base_types.cpp @@ -1758,11 +1758,81 @@ operator==(Interval_f32 a, Interval_f32 b){ return(a.min == b.min && a.max == b.max); } -#define make_range Ii32 -#define make_range_i32 Ii32 -#define make_range_i64 Ii64 -#define make_range_u64 Iu64 -#define make_range_f32 If32 +function Interval_i32 +operator+(Interval_i32 r, i32 s){ + return(Ii32(r.min + s, r.max + s)); +} +function Interval_i64 +operator+(Interval_i64 r, i64 s){ + return(Ii64(r.min + s, r.max + s)); +} +function Interval_u64 +operator+(Interval_u64 r, u64 s){ + return(Iu64(r.min + s, r.max + s)); +} +function Interval_f32 +operator+(Interval_f32 r, f32 s){ + return(If32(r.min + s, r.max + s)); +} + +function Interval_i32 +operator-(Interval_i32 r, i32 s){ + return(Ii32(r.min - s, r.max - s)); +} +function Interval_i64 +operator-(Interval_i64 r, i64 s){ + return(Ii64(r.min - s, r.max - s)); +} +function Interval_u64 +operator-(Interval_u64 r, u64 s){ + return(Iu64(r.min - s, r.max - s)); +} +function Interval_f32 +operator-(Interval_f32 r, f32 s){ + return(If32(r.min - s, r.max - s)); +} + +function Interval_i32& +operator+=(Interval_i32 &r, i32 s){ + r = r + s; + return(r); +} +function Interval_i64& +operator+=(Interval_i64 &r, i64 s){ + r = r + s; + return(r); +} +function Interval_u64& +operator+=(Interval_u64 &r, u64 s){ + r = r + s; + return(r); +} +function Interval_f32& +operator+=(Interval_f32 &r, f32 s){ + r = r + s; + return(r); +} + +function Interval_i32& +operator-=(Interval_i32 &r, i32 s){ + r = r - s; + return(r); +} +function Interval_i64& +operator-=(Interval_i64 &r, i64 s){ + r = r - s; + return(r); +} +function Interval_u64& +operator-=(Interval_u64 &r, u64 s){ + r = r - s; + return(r); +} +function Interval_f32& +operator-=(Interval_f32 &r, f32 s){ + r = r - s; + return(r); +} internal Interval_i32 range_margin(Interval_i32 range, i32 margin){ @@ -1806,6 +1876,56 @@ range_overlap(Interval_f32 a, Interval_f32 b){ return(a.min < b.max && b.min < a.max); } +internal Interval_i32 +range_intersect(Interval_i32 a, Interval_i32 b){ + Interval_i32 result = {}; + if (range_overlap(a, b)){ + result = Ii32(max(a.min, b.min), min(a.max, b.max)); + } + return(result); +} +internal Interval_i64 +range_intersect(Interval_i64 a, Interval_i64 b){ + Interval_i64 result = {}; + if (range_overlap(a, b)){ + result = Ii64(max(a.min, b.min), min(a.max, b.max)); + } + return(result); +} +internal Interval_u64 +range_intersect(Interval_u64 a, Interval_u64 b){ + Interval_u64 result = {}; + if (range_overlap(a, b)){ + result = Iu64(max(a.min, b.min), min(a.max, b.max)); + } + return(result); +} +internal Interval_f32 +range_intersect(Interval_f32 a, Interval_f32 b){ + Interval_f32 result = {}; + if (range_overlap(a, b)){ + result = If32(max(a.min, b.min), min(a.max, b.max)); + } + return(result); +} + +internal Interval_i32 +range_union(Interval_i32 a, Interval_i32 b){ + return(Ii32(min(a.min, b.min), max(a.max, b.max))); +} +internal Interval_i64 +range_union(Interval_i64 a, Interval_i64 b){ + return(Ii64(min(a.min, b.min), max(a.max, b.max))); +} +internal Interval_u64 +range_union(Interval_u64 a, Interval_u64 b){ + return(Iu64(min(a.min, b.min), max(a.max, b.max))); +} +internal Interval_f32 +range_union(Interval_f32 a, Interval_f32 b){ + return(If32(min(a.min, b.min), max(a.max, b.max))); +} + internal b32 range_contains_inclusive(Interval_i32 a, i32 p){ return(a.min <= p && p <= a.max); @@ -2093,9 +2213,6 @@ Rf32(Rect_i32 o){ return(rect); } -#define i32R Ri32 -#define f32R Rf32 - internal Rect_i32 Ri32_xy_wh(i32 x0, i32 y0, i32 w, i32 h){ Rect_i32 rect = {x0, y0, x0 + w, y0 + h}; @@ -2118,12 +2235,21 @@ Rf32_xy_wh(Vec2_f32 p0, Vec2_f32 d){ return(rect); } -#define i32R_xy_wh -#define f32R_xy_wh +function Rect_i32 +Ri32(Interval_i32 x, Interval_i32 y){ + return(Ri32(x.min, y.min, x.max, y.max)); +} +function Rect_f32 +Rf32(Interval_f32 x, Interval_f32 y){ + return(Rf32(x.min, y.min, x.max, y.max)); +} global_const Rect_f32 Rf32_infinity = {-max_f32, -max_f32, max_f32, max_f32}; global_const Rect_f32 Rf32_negative_infinity = { max_f32, max_f32, -max_f32, -max_f32}; +global_const Rect_i32 Ri32_infinity = {-max_i32, -max_i32, max_i32, max_i32}; +global_const Rect_i32 Ri32_negative_infinity = { max_i32, max_i32, -max_i32, -max_i32}; + internal b32 rect_equals(Rect_i32 a, Rect_i32 b){ return(a.x0 == b.x0 && a.y0 == b.y0 && a.x1 == b.x1 && a.y1 == b.y1); diff --git a/custom/4coder_base_types.h b/custom/4coder_base_types.h index 00ef1b80..af7bb16a 100644 --- a/custom/4coder_base_types.h +++ b/custom/4coder_base_types.h @@ -756,15 +756,10 @@ typedef Vec2_f32 Vec2; typedef Vec3_f32 Vec3; typedef Vec4_f32 Vec4; -typedef Rect_f32 f32_Rect; -typedef Rect_i32 i32_Rect; - -struct f32_Rect_Pair{ - f32_Rect E[2]; +struct Rect_f32_Pair{ + Rect_f32 e[2]; }; -typedef f32_Rect_Pair Rect_f32_Pair; - //////////////////////////////// struct i8_Array{ diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index d191f78c..8ee27192 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -101,7 +101,6 @@ internal void draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID buffer, i64 pos, u32 flags, Range_Highlight_Kind kind, int_color *back_colors, int_color *fore_colors, i32 color_count){ -#if 0 Scratch_Block scratch(app); Range_i64_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags); @@ -148,14 +147,13 @@ draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID draw_character_block(app, text_layout_id, range.max - 1, back_colors[color_index]); } if (fore_colors != 0){ - paint_text_color(app, text_layout_id, range.min, fore_colors[color_index]); - paint_text_color(app, text_layout_id, range.max - 1, fore_colors[color_index]); + paint_text_color_pos(app, text_layout_id, range.min, fore_colors[color_index]); + paint_text_color_pos(app, text_layout_id, range.max - 1, fore_colors[color_index]); } } color_index += 1; color_index = (color_index%color_count); } -#endif } static argb_color default_colors[Stag_COUNT] = {}; @@ -674,8 +672,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(visible_range.first)); for (;cursor.pos <= visible_range.one_past_last;){ - Rect_f32 line_rect = text_layout_line_on_screen(app, text_layout_id, cursor.line); - Vec2_f32 p = V2f32(left_margin.x1, line_rect.y0); + Range_f32 line_y = text_layout_line_on_screen(app, text_layout_id, cursor.line); + Vec2_f32 p = V2f32(left_margin.x1, line_y.min); Temp_Memory temp = begin_temp(scratch); Fancy_String *line_string = push_fancy_stringf(scratch, line_color, "%*lld", line_count_digit_count, cursor.line); draw_fancy_string(app, face_id, line_string, p, Stag_Margin_Active, 0); @@ -701,7 +699,7 @@ default_ui_render_caller(Application_Links *app, View_ID view_id, Rect_f32 rect_ for (UI_Item *item = ui_data->list.first; item != 0; item = item->next){ - Rect_f32 item_rect = f32R(item->rect_outer); + Rect_f32 item_rect = Rf32(item->rect_outer); switch (item->coordinates){ case UICoordinates_ViewSpace: diff --git a/custom/4coder_helper.cpp b/custom/4coder_helper.cpp index 6d1ad8cf..f0a84a49 100644 --- a/custom/4coder_helper.cpp +++ b/custom/4coder_helper.cpp @@ -2325,7 +2325,7 @@ draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 string, Vec } internal void -draw_margin(Application_Links *app, f32_Rect outer, f32_Rect inner, int_color color){ +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); @@ -2367,12 +2367,13 @@ draw_character_i_bar(Application_Links *app, Text_Layout_ID layout, i64 pos, int internal void draw_line_highlight(Application_Links *app, Text_Layout_ID layout, Range_i64 line_range, int_color color){ - Rect_f32 rect = text_layout_line_on_screen(app, layout, line_range.min); - for (i64 i = line_range.min + 1; i <= line_range.max; i += 1){ - Rect_f32 r = text_layout_line_on_screen(app, layout, i); - rect = rect_union(rect, r); + Range_f32 y1 = text_layout_line_on_screen(app, layout, line_range.min); + Range_f32 y2 = text_layout_line_on_screen(app, layout, line_range.max); + 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, rect, color); } internal void @@ -2387,20 +2388,20 @@ paint_text_color_pos(Application_Links *app, Text_Layout_ID layout, i64 pos, int //////////////////////////////// -internal f32_Rect_Pair -split_rect(f32_Rect rect, View_Split_Kind kind, Coordinate coord, Side from_side, f32 t){ - f32_Rect_Pair result = {}; +internal Rect_f32_Pair +split_rect(Rect_f32 rect, View_Split_Kind kind, Coordinate coord, Side from_side, f32 t){ + Rect_f32_Pair result = {}; if (kind == ViewSplitKind_FixedPixels){ - result.E[0] = rect; - result.E[1] = rect; + result.e[0] = rect; + result.e[1] = rect; if (coord == Coordinate_X){ - result.E[0].x1 = (from_side == Side_Max) ? (rect.x1 - t) : (rect.x0 + t); - result.E[1].x0 = result.E[0].x1; + result.e[0].x1 = (from_side == Side_Max) ? (rect.x1 - t) : (rect.x0 + t); + result.e[1].x0 = result.e[0].x1; } else{ Assert(coord == Coordinate_Y); - result.E[0].y1 = (from_side == Side_Max) ? (rect.y1 - t) : (rect.y0 + t); - result.E[1].y0 = result.E[0].y1; + result.e[0].y1 = (from_side == Side_Max) ? (rect.y1 - t) : (rect.y0 + t); + result.e[1].y0 = result.e[0].y1; } } else{ diff --git a/custom/4coder_search.cpp b/custom/4coder_search.cpp index 07d5f1ca..99debce3 100644 --- a/custom/4coder_search.cpp +++ b/custom/4coder_search.cpp @@ -235,7 +235,7 @@ get_word_complete_needle_range(Application_Links *app, Buffer_ID buffer, i64 pos needle_range.min = scan(app, boundary_alpha_numeric_underscore_utf8, buffer, Scan_Backward, pos); i64 e = scan(app, boundary_alpha_numeric_underscore_utf8, buffer, Scan_Forward, needle_range.min); if (needle_range.max > e){ - needle_range = make_range_i64(pos); + needle_range = Ii64(pos); } return(needle_range); } @@ -306,10 +306,10 @@ get_word_complete_match_list__unreduced(Application_Links *app, Arena *arena, Bu i64 size = buffer_get_size(app, buffer); String_Match_List up = buffer_find_all_matches(app, arena, buffer, 0, - make_range_i64(0, needle_range.min), + Ii64(0, needle_range.min), needle, pred, Scan_Backward); String_Match_List down = buffer_find_all_matches(app, arena, buffer, 0, - make_range_i64(needle_range.max, size), + Ii64(needle_range.max, size), needle, pred, Scan_Forward); string_match_list_filter_flags(&up, word_complete_must, word_complete_must_not); diff --git a/custom/4coder_string_match.cpp b/custom/4coder_string_match.cpp index 8d0483f0..7e4f981e 100644 --- a/custom/4coder_string_match.cpp +++ b/custom/4coder_string_match.cpp @@ -25,7 +25,7 @@ internal void string_match_list_push(Arena *arena, String_Match_List *list, Buffer_ID buffer, i32 string_id, String_Match_Flag flags, i64 start, i64 length){ string_match_list_push(arena, list, buffer, string_id, flags, - make_range_i64(start, start + length)); + Ii64(start, start + length)); } internal String_Match_List @@ -138,7 +138,7 @@ string_match_list_merge_nearest(String_Match_List *a, String_Match_List *b, Rang internal String_Match_List string_match_list_merge_front_to_back(String_Match_List *a, String_Match_List *b){ - return(string_match_list_merge_nearest(a, b, make_range_i64(0))); + return(string_match_list_merge_nearest(a, b, Ii64(0))); } // BOTTOM diff --git a/custom/4coder_ui_helper.cpp b/custom/4coder_ui_helper.cpp index f6841db4..8a21b6f9 100644 --- a/custom/4coder_ui_helper.cpp +++ b/custom/4coder_ui_helper.cpp @@ -83,34 +83,10 @@ ui_list_add_item(Arena *arena, UI_List *list, UI_Item item){ return(node); } -static i32_Rect -ui__rect_union(i32_Rect a, i32_Rect b){ - if (b.x1 > b.x0 && b.y1 > b.y0){ - if (a.x0 > b.x0){ - a.x0 = b.x0; - } - if (a.x1 < b.x1){ - a.x1 = b.x1; - } - if (a.y0 > b.y0){ - a.y0 = b.y0; - } - if (a.y1 < b.y1){ - a.y1 = b.y1; - } - } - return(a); -} - static void ui_data_compute_bounding_boxes(UI_Data *ui_data){ - i32_Rect neg_inf_rect = {}; - neg_inf_rect.x0 = INT32_MAX; - neg_inf_rect.y0 = INT32_MAX; - neg_inf_rect.x1 = INT32_MIN; - neg_inf_rect.y1 = INT32_MIN; for (u32 i = 0; i < UICoordinates_COUNT; ++i){ - ui_data->bounding_box[i] = neg_inf_rect; + ui_data->bounding_box[i] = Ri32_negative_infinity; } for (UI_Item *item = ui_data->list.first; item != 0; @@ -119,7 +95,7 @@ ui_data_compute_bounding_boxes(UI_Data *ui_data){ item->coordinates = UICoordinates_ViewSpace; } Rect_i32 *box = &ui_data->bounding_box[item->coordinates]; - *box = ui__rect_union(*box, item->rect_outer); + *box = rect_union(*box, item->rect_outer); } } @@ -448,7 +424,7 @@ lister_update_ui(Application_Links *app, View_ID view, Lister_State *state){ { // TODO(allen): switch to float - i32_Rect item_rect = {}; + Rect_i32 item_rect = {}; item_rect.x0 = (i32)x0; item_rect.y0 = 0; item_rect.x1 = (i32)x1; diff --git a/custom/generated/custom_api.cpp b/custom/generated/custom_api.cpp index 65801d7b..2af22333 100644 --- a/custom/generated/custom_api.cpp +++ b/custom/generated/custom_api.cpp @@ -171,6 +171,7 @@ vtable->draw_clip_pop = draw_clip_pop; vtable->draw_coordinate_center_push = draw_coordinate_center_push; vtable->draw_coordinate_center_pop = draw_coordinate_center_pop; vtable->text_layout_create = text_layout_create; +vtable->text_layout_region = text_layout_region; vtable->text_layout_get_buffer = text_layout_get_buffer; vtable->text_layout_get_visible_range = text_layout_get_visible_range; vtable->text_layout_line_on_screen = text_layout_line_on_screen; @@ -356,6 +357,7 @@ draw_clip_pop = vtable->draw_clip_pop; draw_coordinate_center_push = vtable->draw_coordinate_center_push; draw_coordinate_center_pop = vtable->draw_coordinate_center_pop; text_layout_create = vtable->text_layout_create; +text_layout_region = vtable->text_layout_region; text_layout_get_buffer = vtable->text_layout_get_buffer; text_layout_get_visible_range = vtable->text_layout_get_visible_range; text_layout_line_on_screen = vtable->text_layout_line_on_screen; diff --git a/custom/generated/custom_api.h b/custom/generated/custom_api.h index 4cd68ebc..37b7fc60 100644 --- a/custom/generated/custom_api.h +++ b/custom/generated/custom_api.h @@ -165,13 +165,14 @@ #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() f32_Rect custom_draw_clip_pop(Application_Links* app) +#define custom_draw_clip_pop_sig() Rect_f32 custom_draw_clip_pop(Application_Links* app) #define custom_draw_coordinate_center_push_sig() void custom_draw_coordinate_center_push(Application_Links* app, Vec2 point) #define custom_draw_coordinate_center_pop_sig() Vec2 custom_draw_coordinate_center_pop(Application_Links* app) #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_get_buffer_sig() b32 custom_text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id, Buffer_ID* buffer_id_out) +#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) #define custom_text_layout_get_visible_range_sig() Interval_i64 custom_text_layout_get_visible_range(Application_Links* app, Text_Layout_ID text_layout_id) -#define custom_text_layout_line_on_screen_sig() Rect_f32 custom_text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number) +#define custom_text_layout_line_on_screen_sig() Range_f32 custom_text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number) #define custom_text_layout_character_on_screen_sig() Rect_f32 custom_text_layout_character_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 pos) #define custom_paint_text_color_sig() void custom_paint_text_color(Application_Links* app, Text_Layout_ID layout_id, Interval_i64 range, int_color color) #define custom_text_layout_free_sig() b32 custom_text_layout_free(Application_Links* app, Text_Layout_ID text_layout_id) @@ -346,13 +347,14 @@ typedef f32 custom_get_string_advance_type(Application_Links* app, Face_ID font_ 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 f32_Rect custom_draw_clip_pop_type(Application_Links* app); +typedef Rect_f32 custom_draw_clip_pop_type(Application_Links* app); typedef void custom_draw_coordinate_center_push_type(Application_Links* app, Vec2 point); typedef Vec2 custom_draw_coordinate_center_pop_type(Application_Links* app); typedef Text_Layout_ID custom_text_layout_create_type(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point); -typedef b32 custom_text_layout_get_buffer_type(Application_Links* app, Text_Layout_ID text_layout_id, Buffer_ID* buffer_id_out); +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); typedef Interval_i64 custom_text_layout_get_visible_range_type(Application_Links* app, Text_Layout_ID text_layout_id); -typedef Rect_f32 custom_text_layout_line_on_screen_type(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); +typedef Range_f32 custom_text_layout_line_on_screen_type(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); typedef Rect_f32 custom_text_layout_character_on_screen_type(Application_Links* app, Text_Layout_ID layout_id, i64 pos); typedef void custom_paint_text_color_type(Application_Links* app, Text_Layout_ID layout_id, Interval_i64 range, int_color color); typedef b32 custom_text_layout_free_type(Application_Links* app, Text_Layout_ID text_layout_id); @@ -532,6 +534,7 @@ custom_draw_clip_pop_type *draw_clip_pop; custom_draw_coordinate_center_push_type *draw_coordinate_center_push; custom_draw_coordinate_center_pop_type *draw_coordinate_center_pop; 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; custom_text_layout_get_visible_range_type *text_layout_get_visible_range; custom_text_layout_line_on_screen_type *text_layout_line_on_screen; @@ -711,13 +714,14 @@ internal f32 get_string_advance(Application_Links* app, Face_ID font_id, String_ 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 f32_Rect draw_clip_pop(Application_Links* app); +internal Rect_f32 draw_clip_pop(Application_Links* app); internal void draw_coordinate_center_push(Application_Links* app, Vec2 point); internal Vec2 draw_coordinate_center_pop(Application_Links* app); internal Text_Layout_ID text_layout_create(Application_Links* app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point); -internal b32 text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id, Buffer_ID* buffer_id_out); +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); internal Interval_i64 text_layout_get_visible_range(Application_Links* app, Text_Layout_ID text_layout_id); -internal Rect_f32 text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); +internal Range_f32 text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); internal Rect_f32 text_layout_character_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 pos); internal void paint_text_color(Application_Links* app, Text_Layout_ID layout_id, Interval_i64 range, int_color color); internal b32 text_layout_free(Application_Links* app, Text_Layout_ID text_layout_id); @@ -898,6 +902,7 @@ global custom_draw_clip_pop_type *draw_clip_pop = 0; global custom_draw_coordinate_center_push_type *draw_coordinate_center_push = 0; global custom_draw_coordinate_center_pop_type *draw_coordinate_center_pop = 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; global custom_text_layout_get_visible_range_type *text_layout_get_visible_range = 0; global custom_text_layout_line_on_screen_type *text_layout_line_on_screen = 0; diff --git a/custom/generated/custom_api_master_list.h b/custom/generated/custom_api_master_list.h index f8936be3..8ac79eeb 100644 --- a/custom/generated/custom_api_master_list.h +++ b/custom/generated/custom_api_master_list.h @@ -165,13 +165,14 @@ api(custom) function f32 get_string_advance(Application_Links* app, Face_ID font 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 f32_Rect draw_clip_pop(Application_Links* app); +api(custom) function Rect_f32 draw_clip_pop(Application_Links* app); api(custom) function void draw_coordinate_center_push(Application_Links* app, Vec2 point); api(custom) function Vec2 draw_coordinate_center_pop(Application_Links* app); 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 b32 text_layout_get_buffer(Application_Links* app, Text_Layout_ID text_layout_id, Buffer_ID* buffer_id_out); +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); api(custom) function Interval_i64 text_layout_get_visible_range(Application_Links* app, Text_Layout_ID text_layout_id); -api(custom) function Rect_f32 text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); +api(custom) function Range_f32 text_layout_line_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 line_number); api(custom) function Rect_f32 text_layout_character_on_screen(Application_Links* app, Text_Layout_ID layout_id, i64 pos); api(custom) function void paint_text_color(Application_Links* app, Text_Layout_ID layout_id, Interval_i64 range, int_color color); api(custom) function b32 text_layout_free(Application_Links* app, Text_Layout_ID text_layout_id); diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index e2f7947c..d5ed3577 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -1858,26 +1858,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS POINT mouse_point; if (GetCursorPos(&mouse_point) && ScreenToClient(win32vars.window_handle, &mouse_point)){ - - i32_Rect screen; - screen.x0 = 0; - screen.y0 = 0; - screen.x1 = target.width; - screen.y1 = target.height; - - i32 mx = mouse_point.x; - i32 my = mouse_point.y; - - b32 is_hit = false; - if (mx >= screen.x0 && mx < screen.x1 && my >= screen.y0 && my < screen.y1){ - is_hit = true; - } - - if (!is_hit){ - win32vars.input_chunk.trans.out_of_window = true; - } - - win32vars.input_chunk.pers.mouse = V2i32(mouse_point.x, mouse_point.y); + Rect_i32 screen = Ri32(0, 0, target.width, target.height); + Vec2_i32 mp = V2i32(mouse_point.x, mouse_point.y); + win32vars.input_chunk.trans.out_of_window = (!rect_contains_point(screen, mp)); + win32vars.input_chunk.pers.mouse = mp; } else{ win32vars.input_chunk.trans.out_of_window = true;