Skip to content

Commit 0c7630e

Browse files
committed
cursor trails
1 parent bc49b80 commit 0c7630e

File tree

7 files changed

+47
-8
lines changed

7 files changed

+47
-8
lines changed

src/draw/draw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ dr_rect(Rng2F32 dst, Vec4F32 color, F32 corner_radius, F32 border_thickness, F32
318318
inst->border_thickness = border_thickness;
319319
inst->edge_softness = edge_softness;
320320
inst->white_texture_override = 1.f;
321+
inst->shear = 0.f;
321322
bucket->last_cmd_stack_gen = bucket->stack_gen;
322323
return inst;
323324
}
@@ -363,6 +364,7 @@ dr_img(Rng2F32 dst, Rng2F32 src, R_Handle texture, Vec4F32 color, F32 corner_rad
363364
inst->border_thickness = border_thickness;
364365
inst->edge_softness = edge_softness;
365366
inst->white_texture_override = 0.f;
367+
inst->shear = 0.f;
366368
bucket->last_cmd_stack_gen = bucket->stack_gen;
367369
return inst;
368370
}

src/raddbg/generated/raddbg.meta.c

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/raddbg/raddbg.mdesk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ RD_VocabTable:
264264
@default(1) @display_name('Cursor Scope Lines') @description("Controls whether or not scopes containing the cursor in text views are drawn.")
265265
'cursor_scope_lines': bool,
266266

267+
//- rjf: cursor decorations
268+
@default(1) @display_name('Cursor Trail') @description("Controls whether or not a movement trail of the cursor is drawn.")
269+
'cursor_trail': bool,
270+
267271
//- rjf: thread & breakpoint decorations
268272
@default(1) @display_name('Thread Lines') @description("Controls whether or not a long horizontal line is drawn before the next line or instruction that the selected thread will execute in source and disassembly views.")
269273
'thread_lines': bool,

src/raddbg/raddbg_widgets.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
12771277
B32 do_bp_lines = rd_setting_b32_from_name(str8_lit("breakpoint_lines"));
12781278
B32 do_bp_glow = rd_setting_b32_from_name(str8_lit("breakpoint_glow"));
12791279
B32 do_scope_lines = rd_setting_b32_from_name(str8_lit("cursor_scope_lines"));
1280+
B32 do_cursor_trail = rd_setting_b32_from_name(str8_lit("cursor_trail"));
12801281
Vec4F32 pop_color = {0};
12811282
UI_TagF("pop")
12821283
{
@@ -2775,7 +2776,10 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
27752776
{
27762777
S64 column = cursor->column;
27772778
Vec2F32 advance = fnt_dim_from_tag_size_string(line_box->font, line_box->font_size, 0, params->tab_size, str8_prefix(line_string, column-1));
2779+
F32 cursor_y = line_box->rect.y0-params->font_size*0.125f;
2780+
F32 cursor_y__animated = ui_anim(ui_key_from_stringf(text_container_box->key, "cursor_y_px"), cursor_y);
27782781
F32 cursor_off_pixels = advance.x;
2782+
F32 cursor_off_pixels__animated = ui_anim(ui_key_from_stringf(text_container_box->key, "cursor_off_px"), cursor_off_pixels);
27792783
F32 cursor_thickness = ClampBot(1.f, floor_f32(line_box->font_size/10.f));
27802784
Rng2F32 cursor_rect =
27812785
{
@@ -2784,12 +2788,39 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe
27842788
ui_box_text_position(line_box).x+cursor_off_pixels+cursor_thickness,
27852789
line_box->rect.y1+params->font_size*0.125f,
27862790
};
2791+
Rng1F32 trail_off_span = r1f32(cursor_off_pixels__animated, cursor_off_pixels);
2792+
Rng2F32 trail_rect =
2793+
{
2794+
ui_box_text_position(line_box).x+trail_off_span.min,
2795+
line_box->rect.y0-params->font_size*0.125f,
2796+
ui_box_text_position(line_box).x+trail_off_span.max,
2797+
line_box->rect.y1+params->font_size*0.125f,
2798+
};
27872799
Vec4F32 cursor_color = ui_color_from_name(str8_lit("cursor"));
2800+
Vec4F32 trail_color = cursor_color;
27882801
if(!is_focused)
27892802
{
27902803
cursor_color.w *= 0.5f;
27912804
}
2805+
trail_color.w *= 0.25f;
27922806
dr_rect(cursor_rect, cursor_color, 1.f, 0, 0.f);
2807+
if(do_cursor_trail)
2808+
{
2809+
R_Rect2DInst *trail_inst = dr_rect(trail_rect, trail_color, ui_top_font_size()*0.2f, 0, 1.f);
2810+
trail_inst->shear = cursor_y - cursor_y__animated;
2811+
if(cursor_off_pixels > cursor_off_pixels__animated)
2812+
{
2813+
trail_inst->dst = shift_2f32(trail_inst->dst, v2f32(0, -trail_inst->shear));
2814+
trail_inst->colors[Corner_00].w *= 0.1f;
2815+
trail_inst->colors[Corner_01].w *= 0.1f;
2816+
}
2817+
else
2818+
{
2819+
trail_inst->shear *= -1;
2820+
trail_inst->colors[Corner_10].w *= 0.1f;
2821+
trail_inst->colors[Corner_11].w *= 0.1f;
2822+
}
2823+
}
27932824
}
27942825

27952826
// rjf: extra rendering for lines with line-info that match the hovered

src/render/d3d11/generated/render_d3d11.meta.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ str8_lit_comp(
5858
" float4 color10 : COL2;\n"
5959
" float4 color11 : COL3;\n"
6060
" float4 corner_radii_px : CRAD;\n"
61-
" float4 style_params : STY; // x: border_thickness_px, y: softness_px, z: omit_texture, w: unused\n"
61+
" float4 style_params : STY; // x: border_thickness_px, y: softness_px, z: omit_texture, w: shear\n"
6262
" uint vertex_id : SV_VertexID;\n"
6363
"};\n"
6464
"\n"
@@ -113,14 +113,15 @@ str8_lit_comp(
113113
" float border_thickness_px = cpu2vertex.style_params.x;\n"
114114
" float softness_px = cpu2vertex.style_params.y;\n"
115115
" float omit_texture = cpu2vertex.style_params.z;\n"
116+
" float shear_px = cpu2vertex.style_params.w;\n"
116117
" \n"
117118
" //- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)\n"
118119
" float2 dst_p_verts_px[] =\n"
119120
" {\n"
120121
" float2(dst_p0_px.x, dst_p1_px.y),\n"
121122
" float2(dst_p0_px.x, dst_p0_px.y),\n"
122-
" float2(dst_p1_px.x, dst_p1_px.y),\n"
123-
" float2(dst_p1_px.x, dst_p0_px.y),\n"
123+
" float2(dst_p1_px.x, dst_p1_px.y + shear_px),\n"
124+
" float2(dst_p1_px.x, dst_p0_px.y + shear_px),\n"
124125
" };\n"
125126
" float2 src_p_verts_px[] =\n"
126127
" {\n"

src/render/d3d11/render_d3d11.mdesk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct CPU2Vertex
5656
float4 color10 : COL2;
5757
float4 color11 : COL3;
5858
float4 corner_radii_px : CRAD;
59-
float4 style_params : STY; // x: border_thickness_px, y: softness_px, z: omit_texture, w: unused
59+
float4 style_params : STY; // x: border_thickness_px, y: softness_px, z: omit_texture, w: shear
6060
uint vertex_id : SV_VertexID;
6161
};
6262

@@ -111,14 +111,15 @@ vs_main(CPU2Vertex cpu2vertex)
111111
float border_thickness_px = cpu2vertex.style_params.x;
112112
float softness_px = cpu2vertex.style_params.y;
113113
float omit_texture = cpu2vertex.style_params.z;
114+
float shear_px = cpu2vertex.style_params.w;
114115

115116
//- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)
116117
float2 dst_p_verts_px[] =
117118
{
118119
float2(dst_p0_px.x, dst_p1_px.y),
119120
float2(dst_p0_px.x, dst_p0_px.y),
120-
float2(dst_p1_px.x, dst_p1_px.y),
121-
float2(dst_p1_px.x, dst_p0_px.y),
121+
float2(dst_p1_px.x, dst_p1_px.y + shear_px),
122+
float2(dst_p1_px.x, dst_p0_px.y + shear_px),
122123
};
123124
float2 src_p_verts_px[] =
124125
{

src/render/render_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct R_Rect2DInst
103103
F32 border_thickness;
104104
F32 edge_softness;
105105
F32 white_texture_override;
106-
F32 _unused_[1];
106+
F32 shear;
107107
};
108108

109109
typedef struct R_Mesh3DInst R_Mesh3DInst;

0 commit comments

Comments
 (0)