//- infinite Vulkan 2D diagram canvas internal inline Vec2f canvas_w2s(View *view, Rect rect, f32 wx, f32 wy) { f32 cx = rect.x0 + rect_w(rect) * 0.5f; f32 cy = rect.y0 + rect_h(rect) * 0.5f; return Vec2f{cx + (wx - view->cam_x) * view->cam_zoom, cy + (wy - view->cam_y) * view->cam_zoom}; } internal inline Vec2f canvas_s2w(View *view, Rect rect, f32 sx, f32 sy) { f32 cx = rect.x0 + rect_w(rect) * 0.5f; f32 cy = rect.y0 + rect_h(rect) * 0.5f; f32 z = Max(view->cam_zoom, 0.01f); return Vec2f{view->cam_x + (sx - cx) / z, view->cam_y + (sy - cy) / z}; } internal void canvas_fit_view(App *app, View *view, b32 selection_only) { Diagram *d = app->diagram; f32 x0 = 1e9f, y0 = 1e9f, x1 = -1e9f, y1 = -1e9f; u32 found = 0; for(u32 i = 0; i < d->node_count; ++i) { DiagramNode *n = &d->nodes[i]; if(!n->alive || diagram_node_hidden(d, (s32)i)) continue; if(selection_only && !n->selected && (s32)i != app->active_node) continue; x0 = Min(x0, n->x); y0 = Min(y0, n->y); x1 = Max(x1, n->x + n->w); y1 = Max(y1, n->y + n->h); ++found; } if(!found) { Rect b = diagram_bounds(d); x0 = b.x0; y0 = b.y0; x1 = b.x1; y1 = b.y1; } view->cam_target_x = (x0 + x1) * 0.5f; view->cam_target_y = (y0 + y1) * 0.5f; // find the panel rect that holds this view f32 vw = 760.0f, vh = 560.0f; s32 vi = (s32)(view - app->layout.views); for(s32 i = 0; i < UI_MAX_PANELS; ++i) { Panel *p = &app->layout.panels[i]; if(p->kind == PANEL_LEAF && panel_active_view(&app->layout, i) == vi) { vw = Max(rect_w(p->rect) - 48.0f, 160.0f); vh = Max(rect_h(p->rect) - UI_TAB_H - 48.0f, 120.0f); break; } } f32 bw = Max(x1 - x0 + 80.0f, 200.0f); f32 bh = Max(y1 - y0 + 80.0f, 160.0f); view->cam_target_zoom = Clamp(Min(vw / bw, vh / bh), 0.12f, 1.35f); if(!view->cam_init) { view->cam_x = view->cam_target_x; view->cam_y = view->cam_target_y; view->cam_zoom = view->cam_target_zoom; view->cam_init = true; } view->cam_fit_pending = false; } internal void canvas_pan_to_node(App *app, View *view, s32 node_index) { Diagram *d = app->diagram; if(!view || node_index < 0 || node_index >= (s32)d->node_count || !d->nodes[node_index].alive) return; DiagramNode *n = &d->nodes[node_index]; view->cam_target_x = n->x + n->w * 0.5f; view->cam_target_y = n->y + n->h * 0.5f; if(view->cam_target_zoom < 0.55f) view->cam_target_zoom = 0.85f; } // NOTE: subtle archetype accent tint derived from the theme so every color scheme stays cohesive internal u32 node_accent_color(DiagramNode *n) { if(n->color) return n->color; switch(n->kind) { case NODE_STRUCT: return COLOR_ACCENT; case NODE_CLASS: return color_lerp(COLOR_ACCENT, COLOR_TEXT, 0.35f); case NODE_INTERFACE: return color_lerp(COLOR_ACCENT, COLOR_TEXT_DIM, 0.45f); case NODE_ENUM: return color_lerp(COLOR_ACCENT, COLOR_TEXT_DIM, 0.25f); case NODE_MODULE: return COLOR_FOCUS_EDGE; case NODE_SYSTEM: return COLOR_ACCENT; case NODE_STORAGE: return color_lerp(COLOR_ACCENT, COLOR_TEXT, 0.2f); case NODE_STATE: return COLOR_ACCENT; case NODE_NOTE: return COLOR_TEXT_DIM; } return COLOR_ACCENT; } internal void draw_dashed_rect_border(DrawList *d, Rect r, f32 thick, f32 period, u32 color) { draw_line_dashed(d, r.x0, r.y0, r.x1, r.y0, thick, period, 0.0f, color); draw_line_dashed(d, r.x1, r.y0, r.x1, r.y1, thick, period, 0.0f, color); draw_line_dashed(d, r.x1, r.y1, r.x0, r.y1, thick, period, 0.0f, color); draw_line_dashed(d, r.x0, r.y1, r.x0, r.y0, thick, period, 0.0f, color); } internal void draw_canvas_grid(App *app, View *view, Rect rect) { if(ui_theme.grid_style == GRID_OFF) return; DrawList *d = &app->draw; f32 step = (f32)Max(ui_theme.grid_size, 8u); while(step * view->cam_zoom < 14.0f) step *= 2.0f; while(step * view->cam_zoom > 96.0f) step *= 0.5f; Vec2f w0 = canvas_s2w(view, rect, rect.x0, rect.y0); Vec2f w1 = canvas_s2w(view, rect, rect.x1, rect.y1); f32 gx0 = floorf(w0.x / step) * step; f32 gy0 = floorf(w0.y / step) * step; u32 minor = color_alpha(COLOR_TEXT_FAINT, ui_theme.grid_style == GRID_DOTS ? 0.34f : 0.14f); u32 major = color_alpha(COLOR_TEXT_FAINT, ui_theme.grid_style == GRID_DOTS ? 0.58f : 0.26f); if(ui_theme.grid_style == GRID_LINES) { for(f32 wx = gx0; wx <= w1.x; wx += step) { Vec2f p = canvas_w2s(view, rect, wx, 0); b32 m = ((s32)roundf(wx / step) % 4) == 0; draw_rect(d, Rect{floorf(p.x), rect.y0, floorf(p.x) + 1.0f, rect.y1}, m ? major : minor, 0); } for(f32 wy = gy0; wy <= w1.y; wy += step) { Vec2f p = canvas_w2s(view, rect, 0, wy); b32 m = ((s32)roundf(wy / step) % 4) == 0; draw_rect(d, Rect{rect.x0, floorf(p.y), rect.x1, floorf(p.y) + 1.0f}, m ? major : minor, 0); } } else { f32 r = Clamp(view->cam_zoom * 1.15f, 0.75f, 1.6f); u32 guard = 0; for(f32 wy = gy0; wy <= w1.y && guard < 12000; wy += step) { b32 my = ((s32)roundf(wy / step) % 4) == 0; Vec2f py = canvas_w2s(view, rect, 0, wy); for(f32 wx = gx0; wx <= w1.x && guard < 12000; wx += step) { b32 mx = ((s32)roundf(wx / step) % 4) == 0; Vec2f px = canvas_w2s(view, rect, wx, 0); draw_square(d, px.x, py.y, (mx && my) ? r * 1.15f : r * 0.75f, (mx && my) ? major : minor); ++guard; } } } } internal void draw_canvas_edge(App *app, View *view, Rect rect, s32 edge_index, f32 alpha_scale) { Diagram *dia = app->diagram; DiagramEdge *e = &dia->edges[edge_index]; EdgePath ep; if(!diagram_edge_route(dia, edge_index, &ep)) return; // frustum cull against canvas viewport Vec2f sb0 = canvas_w2s(view, rect, ep.bounds.x0, ep.bounds.y0); Vec2f sb1 = canvas_w2s(view, rect, ep.bounds.x1, ep.bounds.y1); if(sb1.x < rect.x0 || sb0.x > rect.x1 || sb1.y < rect.y0 || sb0.y > rect.y1) return; ++dia->visible_edges; DrawList *d = &app->draw; FontSystem *fonts = &app->fonts; f32 z = view->cam_zoom; b32 sel = e->selected || (app->active_edge == edge_index); b32 hov = (app->canvas_hover_edge == edge_index); u32 base_col = e->color ? e->color : ((e->kind == EDGE_DATAFLOW) ? COLOR_ACCENT : COLOR_TEXT_DIM); if(sel) base_col = COLOR_ACCENT; else if(hov) base_col = COLOR_TEXT; u32 col = color_alpha(base_col, alpha_scale); f32 thick = ((e->kind == EDGE_DATAFLOW) ? 2.2f : 1.35f) * Clamp(z, 0.55f, 1.4f); if(sel) thick += 0.8f; b32 dashed = (e->kind == EDGE_DEPENDENCY || e->kind == EDGE_IMPLEMENTS || e->kind == EDGE_ASYNC); f32 period = dashed ? 10.0f * Clamp(z, 0.6f, 1.5f) : 0.0f; f32 phase = 0.0f; // pull endpoint slightly back from arrowhead tip for hollow triangles / diamonds f32 src_trim = (e->kind == EDGE_COMPOSITION || e->kind == EDGE_AGGREGATION) ? 14.0f : 0.0f; f32 dst_trim = (e->kind == EDGE_INHERITANCE || e->kind == EDGE_IMPLEMENTS) ? 12.0f : ((e->kind == EDGE_DATAFLOW || e->kind == EDGE_ASYNC) ? 8.0f : 0.0f); if(ep.routing == ROUTE_BEZIER) { Vec2f p0 = canvas_w2s(view, rect, ep.points[0].x + ep.src_dir.x * src_trim, ep.points[0].y + ep.src_dir.y * src_trim); Vec2f p1 = canvas_w2s(view, rect, ep.points[1].x - ep.dst_dir.x * dst_trim, ep.points[1].y - ep.dst_dir.y * dst_trim); Vec2f c0 = canvas_w2s(view, rect, ep.c0.x, ep.c0.y); Vec2f c1 = canvas_w2s(view, rect, ep.c1.x, ep.c1.y); draw_bezier(d, p0.x, p0.y, c0.x, c0.y, c1.x, c1.y, p1.x, p1.y, thick, period, phase, col); } else { f32 accum = 0.0f; for(u32 i = 0; i + 1 < ep.point_count; ++i) { Vec2f a = ep.points[i]; Vec2f b = ep.points[i + 1]; if(i == 0 && src_trim > 0.0f) { a.x += ep.src_dir.x * src_trim; a.y += ep.src_dir.y * src_trim; } if(i + 2 == ep.point_count && dst_trim > 0.0f) { b.x -= ep.dst_dir.x * dst_trim; b.y -= ep.dst_dir.y * dst_trim; } Vec2f sa = canvas_w2s(view, rect, a.x, a.y); Vec2f sb = canvas_w2s(view, rect, b.x, b.y); f32 ph = (period > 0.5f) ? (phase - accum / period) : 0.0f; draw_line_dashed(d, sa.x, sa.y, sb.x, sb.y, thick, period, ph, col); accum += sqrtf((sb.x - sa.x) * (sb.x - sa.x) + (sb.y - sa.y) * (sb.y - sa.y)); } } // Arrowheads & UML diamonds (skipped only when zoomed extremely far out) if(z >= 0.22f) { f32 alen = 11.5f * Clamp(z, 0.55f, 1.35f); f32 ahw = 5.5f * Clamp(z, 0.55f, 1.35f); // Source marker: composition/aggregation diamond or bidir chevron Vec2f s0 = canvas_w2s(view, rect, ep.points[0].x, ep.points[0].y); if(e->kind == EDGE_COMPOSITION || e->kind == EDGE_AGGREGATION) { f32 dlen = 14.0f * Clamp(z, 0.55f, 1.35f); Vec2f stail = {s0.x + ep.src_dir.x * dlen, s0.y + ep.src_dir.y * dlen}; if(e->kind == EDGE_AGGREGATION) { draw_arrow(d, stail.x, stail.y, s0.x, s0.y, ahw, 0.0f, DRAW_ARROW_DIAMOND, color_alpha(COLOR_BG, alpha_scale)); draw_arrow(d, stail.x, stail.y, s0.x, s0.y, ahw, 1.5f, DRAW_ARROW_DIAMOND, col); } else { draw_arrow(d, stail.x, stail.y, s0.x, s0.y, ahw, 0.0f, DRAW_ARROW_DIAMOND, col); } } else if(e->kind == EDGE_BIDIR) { Vec2f stail = {s0.x + ep.src_dir.x * alen, s0.y + ep.src_dir.y * alen}; draw_arrow(d, stail.x, stail.y, s0.x, s0.y, ahw, thick, DRAW_ARROW_CHEVRON, col); } // Target marker Vec2f s1 = canvas_w2s(view, rect, ep.points[ep.point_count - 1].x, ep.points[ep.point_count - 1].y); Vec2f ttail = {s1.x - ep.dst_dir.x * alen, s1.y - ep.dst_dir.y * alen}; switch(e->kind) { case EDGE_ASSOCIATION: case EDGE_DEPENDENCY: case EDGE_COMPOSITION: case EDGE_AGGREGATION: case EDGE_BIDIR: draw_arrow(d, ttail.x, ttail.y, s1.x, s1.y, ahw, thick, DRAW_ARROW_CHEVRON, col); break; case EDGE_INHERITANCE: case EDGE_IMPLEMENTS: draw_arrow(d, ttail.x, ttail.y, s1.x, s1.y, ahw * 1.15f, 0.0f, DRAW_ARROW_TRIANGLE, color_alpha(COLOR_BG, alpha_scale)); draw_arrow(d, ttail.x, ttail.y, s1.x, s1.y, ahw * 1.15f, 1.5f, DRAW_ARROW_TRIANGLE, col); break; case EDGE_DATAFLOW: case EDGE_ASYNC: draw_arrow(d, ttail.x, ttail.y, s1.x, s1.y, ahw, 0.0f, DRAW_ARROW_TRIANGLE, col); break; default: break; } } // Edge label & multiplicities (full LOD) if(ui_theme.show_edge_labels && z >= 0.30f) { f32 fsize = Clamp(floorf(UI_FONT_SMALL * z + 0.5f), 8.0f, 18.0f); if(e->label[0]) { String8 lbl = str8(e->label); f32 tw = font_measure(fonts, FONT_MONO, fsize, lbl); f32 lh = font_line_height(fonts, FONT_MONO, fsize) + 4.0f; Vec2f lp = canvas_w2s(view, rect, ep.label_pos.x, ep.label_pos.y); Rect pill = {lp.x - tw * 0.5f - 6.0f, lp.y - lh * 0.5f, lp.x + tw * 0.5f + 6.0f, lp.y + lh * 0.5f}; draw_rect(d, pill, color_alpha(COLOR_BG, 0.90f * alpha_scale), 0); if(sel) draw_border(d, pill, color_alpha(COLOR_ACCENT, 0.65f), 0, 1.0f); draw_text(d, fonts, FONT_MONO, fsize, pill.x0 + 6.0f, ui_baseline(app, FONT_MONO, fsize, pill.y0, lh), lbl, color_alpha(sel ? COLOR_ACCENT : COLOR_TEXT_DIM, alpha_scale)); } if(e->src_mult[0]) { Vec2f mp = canvas_w2s(view, rect, ep.src_mult_pos.x, ep.src_mult_pos.y); draw_text(d, fonts, FONT_MONO, fsize * 0.9f, mp.x, mp.y, str8(e->src_mult), color_alpha(COLOR_TEXT_FAINT, alpha_scale)); } if(e->dst_mult[0]) { Vec2f mp = canvas_w2s(view, rect, ep.dst_mult_pos.x, ep.dst_mult_pos.y); draw_text(d, fonts, FONT_MONO, fsize * 0.9f, mp.x, mp.y, str8(e->dst_mult), color_alpha(COLOR_TEXT_FAINT, alpha_scale)); } } } internal void draw_canvas_node(App *app, View *view, Rect rect, s32 node_index, f32 alpha_scale) { Diagram *dia = app->diagram; DiagramNode *n = &dia->nodes[node_index]; Vec2f p0 = canvas_w2s(view, rect, n->x, n->y); Vec2f p1 = canvas_w2s(view, rect, n->x + n->w, n->y + n->h); Rect nr = {p0.x, p0.y, p1.x, p1.y}; if(nr.x1 < rect.x0 - 20.0f || nr.x0 > rect.x1 + 20.0f || nr.y1 < rect.y0 - 20.0f || nr.y0 > rect.y1 + 20.0f) return; ++dia->visible_nodes; DrawList *d = &app->draw; FontSystem *fonts = &app->fonts; f32 z = view->cam_zoom; b32 sel = n->selected || (app->active_node == node_index); b32 hov = (app->canvas_hover_node == node_index); u32 accent = node_accent_color(n); f32 rad = (n->kind == NODE_STATE) ? 14.0f * z : 0.0f; // Macro LOD when zoomed very far out (240fps on 1,000+ node graphs) if(ui_theme.lod_enabled && z < 0.22f) { u32 fill = (n->kind == NODE_MODULE) ? color_alpha(COLOR_PANEL, 0.28f * alpha_scale) : color_alpha(COLOR_PANEL, alpha_scale); draw_rect(d, nr, fill, rad); draw_border(d, nr, color_alpha(sel ? COLOR_ACCENT : accent, (sel ? 1.0f : 0.55f) * alpha_scale), rad, sel ? 1.8f : 1.0f); return; } //- shadow if(ui_theme.show_shadows && n->kind != NODE_MODULE && alpha_scale > 0.5f) { draw_shadow(d, Rect{nr.x0 + 2.0f * z, nr.y0 + 3.0f * z, nr.x1 + 2.0f * z, nr.y1 + 3.0f * z}, 0x00000055u, rad, 10.0f * z); } //- container (NODE_MODULE) if(n->kind == NODE_MODULE) { draw_rect(d, nr, color_alpha(COLOR_PANEL, 0.42f * alpha_scale), 0); f32 hh = n->header_h * z; Rect hdr = {nr.x0, nr.y0, nr.x1, Min(nr.y0 + hh, nr.y1)}; draw_rect(d, hdr, color_alpha(COLOR_TAB, 0.85f * alpha_scale), 0); draw_rect(d, Rect{nr.x0, nr.y0, nr.x0 + 3.0f, hdr.y1}, color_alpha(accent, alpha_scale), 0); u32 bcol = color_alpha(sel ? COLOR_ACCENT : (hov ? COLOR_FOCUS_EDGE : COLOR_PANEL_EDGE), alpha_scale); if(n->border_style == BORDER_DASHED) draw_dashed_rect_border(d, nr, sel ? 1.6f : 1.1f, 10.0f * Clamp(z, 0.6f, 1.4f), bcol); else draw_border(d, nr, bcol, 0, sel ? 1.6f : 1.1f); if(z >= 0.30f) { f32 fsize = Clamp(floorf(UI_FONT * z + 0.5f), 8.0f, 22.0f); f32 sfont = Clamp(floorf(UI_FONT_SMALL * z + 0.5f), 7.5f, 18.0f); f32 base = ui_baseline(app, FONT_SEMIBOLD, fsize, hdr.y0, rect_h(hdr)); f32 x = hdr.x0 + 10.0f * z; draw_text(d, fonts, FONT_MONO, sfont, x, base, str8(n->collapsed ? "[+]" : "[-]"), color_alpha(COLOR_TEXT_DIM, alpha_scale)); x += 24.0f * z; draw_text_fit(d, fonts, FONT_SEMIBOLD, fsize, x, base, rect_w(hdr) - 76.0f * z, str8(n->name), color_alpha(COLOR_TEXT, alpha_scale)); String8 badge = str8("MODULE"); f32 bw = font_measure(fonts, FONT_MONO, sfont * 0.88f, badge); draw_text(d, fonts, FONT_MONO, sfont * 0.88f, hdr.x1 - bw - 8.0f * z, base, badge, color_alpha(COLOR_TEXT_FAINT, alpha_scale)); } if(sel) { draw_square(d, nr.x1 - 4.0f, nr.y1 - 4.0f, 3.5f, COLOR_ACCENT); } return; } //- regular software structure node u32 bg_col = (n->kind == NODE_NOTE) ? color_lerp(COLOR_PANEL, COLOR_TAB, 0.5f) : COLOR_PANEL; u32 hdr_col = (n->kind == NODE_INTERFACE) ? COLOR_TAB : ((n->kind == NODE_NOTE) ? bg_col : COLOR_TAB_ACTIVE); draw_rect(d, nr, color_alpha(bg_col, alpha_scale), rad); f32 hh = Min(n->header_h * z, rect_h(nr)); Rect hdr = {nr.x0, nr.y0, nr.x1, nr.y0 + hh}; draw_rect(d, hdr, color_alpha(hdr_col, alpha_scale), rad); if(rad > 0.5f && rect_h(nr) > hh + 2.0f) { // square off bottom corners of header strip when body follows draw_rect(d, Rect{hdr.x0, hdr.y1 - rad, hdr.x1, hdr.y1}, color_alpha(hdr_col, alpha_scale), 0); } // Kind-specific visual signifiers (crisp, minimalist, unmistakable) if(n->kind == NODE_STORAGE) { // top slab cap bar for storage/ring/arena/db draw_rect(d, Rect{nr.x0, nr.y0, nr.x1, nr.y0 + 3.0f * Clamp(z, 0.7f, 1.5f)}, color_alpha(accent, alpha_scale), 0); } else if(n->kind == NODE_ENUM) { // double left bar for tagged union / enum draw_rect(d, Rect{nr.x0, nr.y0, nr.x0 + 2.5f * Clamp(z, 0.7f, 1.4f), nr.y1}, color_alpha(accent, alpha_scale), 0); draw_rect(d, Rect{nr.x0 + 4.5f * Clamp(z, 0.7f, 1.4f), nr.y0, nr.x0 + 6.0f * Clamp(z, 0.7f, 1.4f), hdr.y1}, color_alpha(accent, 0.55f * alpha_scale), 0); } else if(n->kind != NODE_STATE && n->kind != NODE_NOTE) { draw_rect(d, Rect{nr.x0, nr.y0, nr.x0 + 2.5f * Clamp(z, 0.7f, 1.4f), hdr.y1}, color_alpha(accent, alpha_scale), 0); } if(n->kind == NODE_NOTE) { f32 f = 10.0f * z; draw_triangle(d, Rect{nr.x1 - f, nr.y0, nr.x1, nr.y0 + f}, color_alpha(COLOR_FOCUS_EDGE, 0.5f * alpha_scale)); } // Header text & badge f32 fsize = Clamp(floorf(UI_FONT * z + 0.5f), 8.0f, 22.0f); f32 sfont = Clamp(floorf(UI_FONT_SMALL * z + 0.5f), 7.5f, 18.0f); { String8 badge = str8(node_kind_badge(n->kind)); f32 bw = font_measure(fonts, FONT_MONO, sfont * 0.85f, badge); f32 pad = 9.0f * z; f32 title_h = n->stereotype[0] ? (24.0f * z) : hh; f32 tbase = ui_baseline(app, FONT_SEMIBOLD, fsize, hdr.y0 + (n->stereotype[0] ? 2.0f * z : 0.0f), title_h); draw_text_fit(d, fonts, FONT_SEMIBOLD, fsize, hdr.x0 + pad + (n->kind == NODE_ENUM ? 4.0f * z : 0.0f), tbase, rect_w(hdr) - bw - pad * 2.5f, str8(n->name), color_alpha(sel ? COLOR_ACCENT : COLOR_TEXT, alpha_scale)); draw_text(d, fonts, FONT_MONO, sfont * 0.85f, hdr.x1 - bw - pad * 0.8f, tbase, badge, color_alpha(accent, 0.85f * alpha_scale)); if(n->stereotype[0] && z >= 0.30f) { f32 sbase = ui_baseline(app, FONT_MONO, sfont * 0.88f, hdr.y0 + 22.0f * z, 18.0f * z); draw_text_fit(d, fonts, FONT_MONO, sfont * 0.88f, hdr.x0 + pad, sbase, rect_w(hdr) - pad * 2.0f, str8(n->stereotype), color_alpha(COLOR_TEXT_DIM, alpha_scale)); } } // Compact LOD: stop before compartments b32 full_lod = (!ui_theme.lod_enabled || z >= 0.28f); if(!n->collapsed && full_lod) { f32 y = hdr.y1; f32 pad = 9.0f * z; if(n->note[0]) { draw_rect(d, Rect{nr.x0, y, nr.x1, y + 1.0f}, color_alpha(COLOR_PANEL_EDGE, alpha_scale), 0); f32 nh = 24.0f * z; draw_text_fit(d, fonts, FONT_REGULAR, sfont, nr.x0 + pad, ui_baseline(app, FONT_REGULAR, sfont, y, nh), rect_w(nr) - pad * 2.0f, str8(n->note), color_alpha(COLOR_TEXT_DIM, alpha_scale)); y += nh; } for(s32 s = n->first_section; s >= 0; s = dia->sections[s].next) { NodeSection *sec = &dia->sections[s]; f32 sh = 20.0f * z; draw_rect(d, Rect{nr.x0, y, nr.x1, y + 1.0f}, color_alpha(COLOR_PANEL_EDGE, alpha_scale), 0); draw_rect(d, Rect{nr.x0 + 1.0f, y + 1.0f, nr.x1 - 1.0f, y + sh}, color_alpha(COLOR_HEADER, 0.75f * alpha_scale), 0); f32 sb = ui_baseline(app, FONT_MONO, sfont * 0.85f, y, sh); draw_text(d, fonts, FONT_MONO, sfont * 0.85f, nr.x0 + pad, sb, str8(sec->collapsed ? "+" : "-"), color_alpha(COLOR_TEXT_FAINT, alpha_scale)); draw_text_fit(d, fonts, FONT_MONO, sfont * 0.85f, nr.x0 + pad + 11.0f * z, sb, rect_w(nr) - pad * 2.0f - 12.0f * z, str8(sec->title), color_alpha(COLOR_TEXT_DIM, alpha_scale)); y += sh; if(!sec->collapsed) { f32 mh = 20.0f * z; for(s32 m = sec->first_member; m >= 0; m = dia->members[m].next) { NodeMember *mem = &dia->members[m]; f32 mb = ui_baseline(app, FONT_MONO, sfont, y, mh); f32 mx = nr.x0 + pad; if(mem->visibility) { char vbuf[2] = {mem->visibility, 0}; u32 vcol = (mem->visibility == '+') ? accent : ((mem->visibility == '-') ? COLOR_TEXT_FAINT : COLOR_TEXT_DIM); draw_text(d, fonts, FONT_MONO, sfont, mx, mb, str8(vbuf), color_alpha(vcol, alpha_scale)); mx += 12.0f * z; } // badge on the right if present f32 right_limit = nr.x1 - pad; if(mem->badge[0]) { String8 bg = str8(mem->badge); f32 gw = font_measure(fonts, FONT_MONO, sfont * 0.82f, bg) + 8.0f * z; Rect br = {right_limit - gw, y + 3.0f * z, right_limit, y + mh - 3.0f * z}; draw_rect(d, br, color_alpha(COLOR_TRACK, alpha_scale), 0); draw_text(d, fonts, FONT_MONO, sfont * 0.82f, br.x0 + 4.0f * z, ui_baseline(app, FONT_MONO, sfont * 0.82f, br.y0, rect_h(br)), bg, color_alpha(COLOR_TEXT_DIM, alpha_scale)); right_limit = br.x0 - 6.0f * z; } f32 nw = draw_text_fit(d, fonts, FONT_MONO, sfont, mx, mb, Max(right_limit - mx, 10.0f), str8(mem->name), color_alpha(COLOR_TEXT, alpha_scale)); if(mem->type[0] && mx + nw + 10.0f * z < right_limit) { f32 tx = mx + nw + 6.0f * z; draw_text_fit(d, fonts, FONT_MONO, sfont * 0.92f, tx, mb, right_limit - tx, str8(mem->type), color_alpha(COLOR_TEXT_DIM, alpha_scale)); } y += mh; } y += 4.0f * z; } } } // Node border u32 bcol = color_alpha(sel ? COLOR_ACCENT : (hov ? COLOR_FOCUS_EDGE : COLOR_PANEL_EDGE), alpha_scale); f32 bw = sel ? 1.8f : (hov ? 1.4f : 1.0f); if(n->border_style == BORDER_DASHED && rad < 0.5f) { draw_dashed_rect_border(d, nr, bw, 8.0f * Clamp(z, 0.6f, 1.4f), bcol); } else if(n->border_style == BORDER_DOUBLE && rad < 0.5f) { draw_border(d, nr, bcol, 0, bw); draw_border(d, rect_shrink(nr, 3.0f), color_alpha(bcol, 0.55f), 0, 1.0f); } else { draw_border(d, nr, bcol, rad, bw); } // Port handles (drag to connect!) and bottom-right resize handle b32 show_ports = (ui_theme.port_visibility == PORT_VIS_ALWAYS) || (ui_theme.port_visibility == PORT_VIS_HOVER && (hov || sel || app->canvas_drag == CANVAS_DRAG_CONNECT)); if(show_ports && z >= 0.40f && alpha_scale > 0.5f) { f32 pr = 3.5f; Vec2f ports[4] = { {(nr.x0 + nr.x1) * 0.5f, nr.y0}, {(nr.x0 + nr.x1) * 0.5f, nr.y1}, {nr.x1, (nr.y0 + nr.y1) * 0.5f}, {nr.x0, (nr.y0 + nr.y1) * 0.5f}, }; for(u32 pi = 0; pi < 4; ++pi) { draw_circle(d, ports[pi].x, ports[pi].y, pr, COLOR_BG); draw_ring(d, ports[pi].x, ports[pi].y, pr, 1.4f, sel ? COLOR_ACCENT : COLOR_FOCUS_EDGE); } } if(sel && z >= 0.35f) { draw_square(d, nr.x1 - 3.5f, nr.y1 - 3.5f, 3.5f, COLOR_ACCENT); } } internal void draw_canvas_minimap(App *app, PlatformInput *input, View *view, Rect rect, b32 modal) { if(!ui_theme.show_minimap || rect_w(rect) < 280.0f || rect_h(rect) < 220.0f) return; DrawList *d = &app->draw; Diagram *dia = app->diagram; f32 mw = 156.0f, mh = 104.0f; Rect mm = {rect.x1 - mw - 10.0f, rect.y1 - mh - 10.0f, rect.x1 - 10.0f, rect.y1 - 10.0f}; draw_rect(d, mm, color_alpha(COLOR_BG, 0.88f), 0); draw_border(d, mm, COLOR_PANEL_EDGE, 0, 1.0f); Rect wb = diagram_bounds(dia); f32 pad = 80.0f; wb.x0 -= pad; wb.y0 -= pad; wb.x1 += pad; wb.y1 += pad; f32 sx = (mw - 12.0f) / Max(rect_w(wb), 1.0f); f32 sy = (mh - 12.0f) / Max(rect_h(wb), 1.0f); f32 s = Min(sx, sy); f32 ox = mm.x0 + (mw - rect_w(wb) * s) * 0.5f; f32 oy = mm.y0 + (mh - rect_h(wb) * s) * 0.5f; draw_clip_push(d, rect_shrink(mm, 2.0f)); for(u32 i = 0; i < dia->node_count; ++i) { DiagramNode *n = &dia->nodes[i]; if(!n->alive || diagram_node_hidden(dia, (s32)i)) continue; Rect r = {ox + (n->x - wb.x0) * s, oy + (n->y - wb.y0) * s, ox + (n->x + n->w - wb.x0) * s, oy + (n->y + n->h - wb.y0) * s}; if(rect_w(r) < 2.0f) r.x1 = r.x0 + 2.0f; if(rect_h(r) < 1.5f) r.y1 = r.y0 + 1.5f; u32 col = (n->selected || (s32)i == app->active_node) ? COLOR_ACCENT : ((n->kind == NODE_MODULE) ? color_alpha(COLOR_PANEL_EDGE, 0.5f) : COLOR_TEXT_DIM); draw_rect(d, r, col, 0); } // Current camera viewport box Vec2f v0 = canvas_s2w(view, rect, rect.x0, rect.y0); Vec2f v1 = canvas_s2w(view, rect, rect.x1, rect.y1); Rect vp = {ox + (v0.x - wb.x0) * s, oy + (v0.y - wb.y0) * s, ox + (v1.x - wb.x0) * s, oy + (v1.y - wb.y0) * s}; draw_rect(d, vp, color_alpha(COLOR_ACCENT, 0.12f), 0); draw_border(d, vp, COLOR_ACCENT, 0, 1.0f); draw_clip_pop(d); // Click or drag inside minimap to jump camera s32 vi = (s32)(view - app->layout.views); if(!modal && ui_hovered(input, mm) && ButtonPressed(input->mouse[0])) { app->canvas_drag = CANVAS_DRAG_MINIMAP; app->canvas_drag_view = vi; } if(app->canvas_drag == CANVAS_DRAG_MINIMAP && app->canvas_drag_view == vi) { if(input->mouse[0].ended_down) { view->cam_target_x = wb.x0 + (input->mouse_x - ox) / Max(s, 1e-4f); view->cam_target_y = wb.y0 + (input->mouse_y - oy) / Max(s, 1e-4f); view->cam_x = view->cam_target_x; view->cam_y = view->cam_target_y; } else { app->canvas_drag = CANVAS_DRAG_NONE; } } } internal void draw_canvas(App *app, PlatformInput *input, s32 panel, View *view, Rect rect, b32 focused) { Diagram *dia = app->diagram; DrawList *d = &app->draw; FontSystem *fonts = &app->fonts; b32 modal = (app->overlay != UI_OVERLAY_NONE); s32 vi = (s32)(view - app->layout.views); if(!view->cam_init || view->cam_fit_pending) { canvas_fit_view(app, view, false); } if(app->pan_to_active && app->active_node >= 0) { canvas_pan_to_node(app, view, app->active_node); } // Instant camera update (static, zero lingering glide animations) view->cam_x = view->cam_target_x; view->cam_y = view->cam_target_y; view->cam_zoom = view->cam_target_zoom; //- background & grid draw_rect(d, rect, COLOR_BG, 0); draw_canvas_grid(app, view, rect); //- mouse interaction on canvas b32 over = ui_hovered(input, rect) && !modal && app->drag_view < 0 && app->resize_panel < 0; Vec2f mworld = canvas_s2w(view, rect, input->mouse_x, input->mouse_y); if(over) { app->canvas_last_wx = mworld.x; app->canvas_last_wy = mworld.y; } // Check minimap hit so clicking minimap doesn't also click canvas behind it Rect mm_rect = {rect.x1 - 166.0f, rect.y1 - 114.0f, rect.x1 - 10.0f, rect.y1 - 10.0f}; b32 over_mm = ui_theme.show_minimap && ui_hovered(input, mm_rect); if(over && !over_mm) { // Wheel zoom to cursor (or horizontal pan) if(input->scroll_y != 0.0f || input->scroll_x != 0.0f) { app->layout.focused = panel; if(input->mods & PLATFORM_MOD_SHIFT) { view->cam_target_x += (input->scroll_y * 48.0f) / Max(view->cam_zoom, 0.1f); view->cam_x = view->cam_target_x; } else if(input->scroll_y != 0.0f) { f32 factor = expf(-input->scroll_y * 0.14f); f32 new_zoom = Clamp(view->cam_target_zoom * factor, 0.08f, 4.0f); // keep world point under cursor fixed! Vec2f before = canvas_s2w(view, rect, input->mouse_x, input->mouse_y); view->cam_target_zoom = new_zoom; f32 cx = rect.x0 + rect_w(rect) * 0.5f; f32 cy = rect.y0 + rect_h(rect) * 0.5f; view->cam_target_x = before.x - (input->mouse_x - cx) / new_zoom; view->cam_target_y = before.y - (input->mouse_y - cy) / new_zoom; view->cam_x = view->cam_target_x; view->cam_y = view->cam_target_y; view->cam_zoom = view->cam_target_zoom; } if(input->scroll_x != 0.0f) { view->cam_target_x += (input->scroll_x * 48.0f) / Max(view->cam_zoom, 0.1f); view->cam_x = view->cam_target_x; } } // Hover hit test s32 hit_node = diagram_hit_test_node(dia, mworld.x, mworld.y); s32 hit_edge = (hit_node < 0) ? diagram_hit_test_edge(dia, mworld.x, mworld.y, 9.0f / Max(view->cam_zoom, 0.25f)) : -1; app->canvas_hover_node = hit_node; app->canvas_hover_edge = hit_edge; // Check if hovering a port dot or resize handle of hit_node / active_node s32 port_node = -1; s32 resize_node = -1; for(s32 cand_i = 0; cand_i < 2; ++cand_i) { s32 cand = (cand_i == 0) ? hit_node : app->active_node; if(cand < 0 || cand >= (s32)dia->node_count || !dia->nodes[cand].alive || diagram_node_hidden(dia, cand)) continue; DiagramNode *cn = &dia->nodes[cand]; Vec2f sp0 = canvas_w2s(view, rect, cn->x, cn->y); Vec2f sp1 = canvas_w2s(view, rect, cn->x + cn->w, cn->y + cn->h); if(fabsf(input->mouse_x - (sp1.x - 3.5f)) < 8.0f && fabsf(input->mouse_y - (sp1.y - 3.5f)) < 8.0f) { resize_node = cand; break; } if(cn->kind != NODE_MODULE && ui_theme.port_visibility != PORT_VIS_OFF) { Vec2f ports[4] = { {(sp0.x + sp1.x) * 0.5f, sp0.y}, {(sp0.x + sp1.x) * 0.5f, sp1.y}, {sp1.x, (sp0.y + sp1.y) * 0.5f}, {sp0.x, (sp0.y + sp1.y) * 0.5f}, }; for(u32 pi = 0; pi < 4; ++pi) { if(fabsf(input->mouse_x - ports[pi].x) < 8.0f && fabsf(input->mouse_y - ports[pi].y) < 8.0f) { port_node = cand; break; } } if(port_node >= 0) break; } } if(resize_node >= 0) app->canvas_cursor = PLATFORM_CURSOR_RESIZE_NWSE; else if(port_node >= 0) app->canvas_cursor = PLATFORM_CURSOR_CROSSHAIR; else if(hit_node >= 0) app->canvas_cursor = PLATFORM_CURSOR_MOVE; else if(hit_edge >= 0) app->canvas_cursor = PLATFORM_CURSOR_POINTER; // Middle button or Right-button on empty space = pan; Right-button on node = quick connect edge! if(ButtonPressed(input->mouse[2]) || (ButtonPressed(input->mouse[1]) && hit_node < 0)) { app->layout.focused = panel; app->canvas_drag = CANVAS_DRAG_PAN; app->canvas_drag_view = vi; app->canvas_drag_start_x = input->mouse_x; app->canvas_drag_start_y = input->mouse_y; } else if(ButtonPressed(input->mouse[1]) && hit_node >= 0) { app->layout.focused = panel; app->active_node = hit_node; app->active_edge = -1; app->canvas_drag = CANVAS_DRAG_CONNECT; app->canvas_drag_view = vi; app->canvas_drag_node = hit_node; } else if(ButtonPressed(input->mouse[0])) { app->layout.focused = panel; u64 now = time_now_ns(); b32 twice = (now - app->last_click_ns < (u64)ui_theme.double_click_ms * 1000000ull) && fabsf(input->mouse_x - app->last_click_x) < 5.0f && fabsf(input->mouse_y - app->last_click_y) < 5.0f; if(resize_node >= 0) { diagram_push_undo(dia); app->active_node = resize_node; app->canvas_drag = CANVAS_DRAG_RESIZE; app->canvas_drag_view = vi; app->canvas_drag_node = resize_node; app->canvas_drag_last_wx = mworld.x; app->canvas_drag_last_wy = mworld.y; } else if(port_node >= 0) { app->active_node = port_node; app->canvas_drag = CANVAS_DRAG_CONNECT; app->canvas_drag_view = vi; app->canvas_drag_node = port_node; } else if(hit_node >= 0) { DiagramNode *hn = &dia->nodes[hit_node]; // check click on collapse toggle (module [-] or section header) b32 toggled = false; if(hn->kind == NODE_MODULE && mworld.y < hn->y + hn->header_h && mworld.x < hn->x + 36.0f) { diagram_push_undo(dia); hn->collapsed = !hn->collapsed; toggled = true; } else if(!hn->collapsed && view->cam_zoom >= 0.44f && mworld.y > hn->y + hn->header_h) { f32 sy = hn->y + hn->header_h + (hn->note[0] ? 24.0f : 0.0f); for(s32 s = hn->first_section; s >= 0; s = dia->sections[s].next) { if(mworld.y >= sy && mworld.y <= sy + 20.0f) { diagram_push_undo(dia); dia->sections[s].collapsed = !dia->sections[s].collapsed; diagram_measure_node(dia, hit_node); toggled = true; break; } sy += 20.0f + (dia->sections[s].collapsed ? 0.0f : (f32)dia->sections[s].member_count * 20.0f + 4.0f); } } if(!toggled) { if(input->mods & PLATFORM_MOD_SHIFT) { hn->selected = !hn->selected; } else if(!hn->selected) { diagram_clear_selection(dia); hn->selected = true; } app->active_node = hit_node; app->active_edge = -1; if(twice) { // double-click opens inline rename! app->edit_kind = EDIT_NODE_NAME; app->edit_index = hit_node; app->overlay = UI_OVERLAY_EDIT; app->overlay_opened = true; snprintf(app->input, sizeof(app->input), "%s", hn->name); app->input_size = (u32)strlen(app->input); now = 0; } else { diagram_push_undo(dia); app->canvas_drag = CANVAS_DRAG_NODES; app->canvas_drag_view = vi; app->canvas_drag_node = hit_node; app->canvas_drag_last_wx = mworld.x; app->canvas_drag_last_wy = mworld.y; } } } else if(hit_edge >= 0) { if(!(input->mods & PLATFORM_MOD_SHIFT)) diagram_clear_selection(dia); dia->edges[hit_edge].selected = true; app->active_edge = hit_edge; app->active_node = -1; if(twice) { app->edit_kind = EDIT_EDGE_LABEL; app->edit_index = hit_edge; app->overlay = UI_OVERLAY_EDIT; app->overlay_opened = true; snprintf(app->input, sizeof(app->input), "%s", dia->edges[hit_edge].label); app->input_size = (u32)strlen(app->input); now = 0; } } else { if(!(input->mods & PLATFORM_MOD_SHIFT)) { diagram_clear_selection(dia); app->active_node = -1; app->active_edge = -1; } app->canvas_drag = CANVAS_DRAG_MARQUEE; app->canvas_drag_view = vi; app->canvas_marquee_x0 = mworld.x; app->canvas_marquee_y0 = mworld.y; app->canvas_marquee_x1 = mworld.x; app->canvas_marquee_y1 = mworld.y; } app->last_click_ns = now; app->last_click_x = input->mouse_x; app->last_click_y = input->mouse_y; } } //- ongoing drags for this canvas view b32 guide_has_x = false, guide_has_y = false; f32 guide_x = 0.0f, guide_y = 0.0f; if(app->canvas_drag != CANVAS_DRAG_NONE && app->canvas_drag_view == vi) { switch(app->canvas_drag) { case CANVAS_DRAG_PAN: { b32 held = input->mouse[2].ended_down || input->mouse[1].ended_down; if(held) { f32 dx = (input->mouse_x - app->canvas_drag_start_x) / Max(view->cam_zoom, 0.05f); f32 dy = (input->mouse_y - app->canvas_drag_start_y) / Max(view->cam_zoom, 0.05f); view->cam_x -= dx; view->cam_y -= dy; view->cam_target_x = view->cam_x; view->cam_target_y = view->cam_y; app->canvas_drag_start_x = input->mouse_x; app->canvas_drag_start_y = input->mouse_y; app->canvas_cursor = PLATFORM_CURSOR_GRABBING; } else { app->canvas_drag = CANVAS_DRAG_NONE; } } break; case CANVAS_DRAG_NODES: { if(input->mouse[0].ended_down) { f32 dx = mworld.x - app->canvas_drag_last_wx; f32 dy = mworld.y - app->canvas_drag_last_wy; if(fabsf(dx) > 0.01f || fabsf(dy) > 0.01f) { for(u32 i = 0; i < dia->node_count; ++i) { if(!dia->nodes[i].alive || !dia->nodes[i].selected) continue; // avoid double-moving child if parent module is also selected if(dia->nodes[i].parent >= 0 && dia->nodes[dia->nodes[i].parent].selected) continue; diagram_move_node(dia, (s32)i, dx, dy); } app->canvas_drag_last_wx = mworld.x; app->canvas_drag_last_wy = mworld.y; } // Smart alignment guides for active node if(ui_theme.smart_guides && app->canvas_drag_node >= 0 && dia->nodes[app->canvas_drag_node].alive) { DiagramNode *dn = &dia->nodes[app->canvas_drag_node]; f32 thresh = 6.0f / Max(view->cam_zoom, 0.3f); for(u32 i = 0; i < dia->node_count; ++i) { DiagramNode *o = &dia->nodes[i]; if(!o->alive || o->selected || o->kind == NODE_MODULE || diagram_node_hidden(dia, (s32)i)) continue; if(!guide_has_x && fabsf(dn->x - o->x) < thresh) { guide_has_x = true; guide_x = o->x; } else if(!guide_has_x && fabsf((dn->x + dn->w * 0.5f) - (o->x + o->w * 0.5f)) < thresh) { guide_has_x = true; guide_x = o->x + o->w * 0.5f; } if(!guide_has_y && fabsf(dn->y - o->y) < thresh) { guide_has_y = true; guide_y = o->y; } else if(!guide_has_y && fabsf((dn->y + dn->h * 0.5f) - (o->y + o->h * 0.5f)) < thresh) { guide_has_y = true; guide_y = o->y + o->h * 0.5f; } } } app->canvas_cursor = PLATFORM_CURSOR_GRABBING; } else { // snap to grid on release if(ui_theme.snap_to_grid && ui_theme.grid_size >= 8) { f32 g = (f32)ui_theme.grid_size; for(u32 i = 0; i < dia->node_count; ++i) { if(!dia->nodes[i].alive || !dia->nodes[i].selected) continue; dia->nodes[i].x = roundf(dia->nodes[i].x / g) * g; dia->nodes[i].y = roundf(dia->nodes[i].y / g) * g; } } diagram_fit_containers(dia); ++dia->version; app->canvas_drag = CANVAS_DRAG_NONE; } } break; case CANVAS_DRAG_RESIZE: { if(input->mouse[0].ended_down && app->canvas_drag_node >= 0 && dia->nodes[app->canvas_drag_node].alive) { DiagramNode *rn = &dia->nodes[app->canvas_drag_node]; rn->manual_size = true; rn->w = Max(rn->min_w, mworld.x - rn->x); rn->h = Max(rn->min_h, mworld.y - rn->y); app->canvas_cursor = PLATFORM_CURSOR_RESIZE_NWSE; } else { ++dia->version; app->canvas_drag = CANVAS_DRAG_NONE; } } break; case CANVAS_DRAG_CONNECT: { b32 held = input->mouse[0].ended_down || input->mouse[1].ended_down; app->canvas_cursor = PLATFORM_CURSOR_CROSSHAIR; if(!held) { s32 target = diagram_hit_test_node(dia, mworld.x, mworld.y); if(target >= 0 && app->canvas_drag_node >= 0) { diagram_push_undo(dia); s32 ei = diagram_add_edge(dia, app->canvas_drag_node, target, (EdgeKind)app->canvas_connect_kind, ""); if(ei >= 0) { diagram_clear_selection(dia); dia->edges[ei].selected = true; app->active_edge = ei; app->active_node = -1; app_message(app, "connected %s %s %s", dia->nodes[app->canvas_drag_node].name, edge_kind_symbol(app->canvas_connect_kind), dia->nodes[target].name); } } app->canvas_drag = CANVAS_DRAG_NONE; } } break; case CANVAS_DRAG_MARQUEE: { if(input->mouse[0].ended_down) { app->canvas_marquee_x1 = mworld.x; app->canvas_marquee_y1 = mworld.y; f32 mx0 = Min(app->canvas_marquee_x0, app->canvas_marquee_x1); f32 my0 = Min(app->canvas_marquee_y0, app->canvas_marquee_y1); f32 mx1 = Max(app->canvas_marquee_x0, app->canvas_marquee_x1); f32 my1 = Max(app->canvas_marquee_y0, app->canvas_marquee_y1); for(u32 i = 0; i < dia->node_count; ++i) { DiagramNode *n = &dia->nodes[i]; if(!n->alive || n->kind == NODE_MODULE || diagram_node_hidden(dia, (s32)i)) continue; b32 inside = (n->x + n->w > mx0 && n->x < mx1 && n->y + n->h > my0 && n->y < my1); n->selected = inside; } } else { app->canvas_drag = CANVAS_DRAG_NONE; } } break; default: break; } } //- render diagram layers: 1. containers -> 2. edges -> 3. nodes -> 4. overlays (guides/rubberband/marquee/minimap/hud) dia->visible_nodes = 0; dia->visible_edges = 0; // 1. Containers for(u32 i = 0; i < dia->node_count; ++i) { if(!dia->nodes[i].alive || dia->nodes[i].kind != NODE_MODULE || diagram_node_hidden(dia, (s32)i)) continue; f32 a = (diagram_tag_dimmed(dia, dia->nodes[i].tag) || !diagram_node_in_focus(dia, (s32)i, app->active_node)) ? 0.25f : 1.0f; draw_canvas_node(app, view, rect, (s32)i, a); } // 2. Edges for(u32 i = 0; i < dia->edge_count; ++i) { if(!dia->edges[i].alive || diagram_edge_hidden(dia, (s32)i)) continue; b32 in_focus = !dia->focus_mode || app->active_node < 0 || (diagram_node_in_focus(dia, dia->edges[i].src, app->active_node) && diagram_node_in_focus(dia, dia->edges[i].dst, app->active_node)); f32 a = (diagram_tag_dimmed(dia, dia->edges[i].tag) || !in_focus) ? 0.16f : 1.0f; draw_canvas_edge(app, view, rect, (s32)i, a); } // 3. Regular nodes for(u32 i = 0; i < dia->node_count; ++i) { if(!dia->nodes[i].alive || dia->nodes[i].kind == NODE_MODULE || diagram_node_hidden(dia, (s32)i)) continue; f32 a = (diagram_tag_dimmed(dia, dia->nodes[i].tag) || !diagram_node_in_focus(dia, (s32)i, app->active_node)) ? 0.22f : 1.0f; draw_canvas_node(app, view, rect, (s32)i, a); } // 4. Smart alignment guides if(guide_has_x) { Vec2f g = canvas_w2s(view, rect, guide_x, 0); draw_line_dashed(d, g.x, rect.y0, g.x, rect.y1, 1.0f, 8.0f, 0.0f, color_alpha(COLOR_ACCENT, 0.7f)); } if(guide_has_y) { Vec2f g = canvas_w2s(view, rect, 0, guide_y); draw_line_dashed(d, rect.x0, g.y, rect.x1, g.y, 1.0f, 8.0f, 0.0f, color_alpha(COLOR_ACCENT, 0.7f)); } // Rubber-band edge while dragging a connection if(app->canvas_drag == CANVAS_DRAG_CONNECT && app->canvas_drag_view == vi && app->canvas_drag_node >= 0 && dia->nodes[app->canvas_drag_node].alive) { DiagramNode *sn = &dia->nodes[app->canvas_drag_node]; Vec2f from = canvas_w2s(view, rect, sn->x + sn->w * 0.5f, sn->y + sn->h * 0.5f); Vec2f to = {input->mouse_x, input->mouse_y}; draw_line_dashed(d, from.x, from.y, to.x, to.y, 1.8f, 8.0f, 0.0f, COLOR_ACCENT); f32 dx = to.x - from.x, dy = to.y - from.y; f32 len = Max(sqrtf(dx * dx + dy * dy), 1.0f); draw_arrow(d, to.x - dx / len * 12.0f, to.y - dy / len * 12.0f, to.x, to.y, 6.0f, 1.8f, DRAW_ARROW_CHEVRON, COLOR_ACCENT); } // Marquee selection rectangle if(app->canvas_drag == CANVAS_DRAG_MARQUEE && app->canvas_drag_view == vi) { Vec2f s0 = canvas_w2s(view, rect, Min(app->canvas_marquee_x0, app->canvas_marquee_x1), Min(app->canvas_marquee_y0, app->canvas_marquee_y1)); Vec2f s1 = canvas_w2s(view, rect, Max(app->canvas_marquee_x0, app->canvas_marquee_x1), Max(app->canvas_marquee_y0, app->canvas_marquee_y1)); Rect mr = {s0.x, s0.y, s1.x, s1.y}; draw_rect(d, mr, COLOR_DROP, 0); draw_border(d, mr, COLOR_ACCENT, 0, 1.0f); } // Compact canvas HUD strip (top-right inside canvas) { ScratchArena scratch = ScratchGet(); String8 hud = ui_format(scratch.arena, "%.0f%% %s%s%s %un %ue", view->cam_zoom * 100.0f, edge_routing_name(dia->default_routing), ui_theme.snap_to_grid ? " snap" : "", dia->focus_mode ? " FOCUS" : "", dia->live_nodes, dia->live_edges); f32 tw = font_measure(fonts, FONT_MONO, UI_FONT_SMALL, hud); Rect pill = {rect.x1 - tw - 22.0f, rect.y0 + 8.0f, rect.x1 - 8.0f, rect.y0 + 28.0f}; draw_rect(d, pill, color_alpha(COLOR_PANEL, 0.88f), 0); draw_border(d, pill, COLOR_PANEL_EDGE, 0, 1.0f); draw_text(d, fonts, FONT_MONO, UI_FONT_SMALL, pill.x0 + 7.0f, ui_baseline(app, FONT_MONO, UI_FONT_SMALL, pill.y0, 20.0f), hud, COLOR_TEXT_DIM); // Title badge top-left inside canvas if(dia->title[0]) { String8 title = ui_format(scratch.arena, "%s%s", dia->title, dia->dirty ? " *" : ""); f32 ttw = font_measure(fonts, FONT_SEMIBOLD, UI_FONT_SMALL, title); Rect tpill = {rect.x0 + 8.0f, rect.y0 + 8.0f, rect.x0 + ttw + 24.0f, rect.y0 + 28.0f}; draw_rect(d, tpill, color_alpha(COLOR_PANEL, 0.88f), 0); draw_border(d, tpill, focused ? COLOR_FOCUS_EDGE : COLOR_PANEL_EDGE, 0, 1.0f); draw_text(d, fonts, FONT_SEMIBOLD, UI_FONT_SMALL, tpill.x0 + 8.0f, ui_baseline(app, FONT_SEMIBOLD, UI_FONT_SMALL, tpill.y0, 20.0f), title, COLOR_TEXT); } scratch_end(&scratch); } // Minimap (bottom-right) draw_canvas_minimap(app, input, view, rect, modal); }