MCPcopy Create free account
hub / github.com/PerroEngine/Perro / rotate_doc_ui_node

Function rotate_doc_ui_node

perro_editor/res/scripts/scene/editor_viewport.rs:2418–2484  ·  view source on GitHub ↗
(
    ctx: &mut ScriptContext<'_, API>,
    key: u32,
    root_delta: Vector2,
    snap: bool,
)

Source from the content-addressed store, hash-verified

2416 "Camera2D" => {
2417 let global = get_global_transform_2d!(ctx.run, id);
2418 let (position, zoom) = with_node!(ctx.run, Camera2D, id, |node| {
2419 let global = global.unwrap_or(node.transform);
2420 (global.position, node.zoom.max(0.001))
2421 }).unwrap_or_default();
2422 let size = Vector2::new(960.0 / zoom, 540.0 / zoom);
2423 ctx.res
2424 .Draw2D()
2425 .rect_stroke(position, size, [0.35, 0.65, 1.0, 1.0], 2.0);
2426 }
2427 "CollisionShape2D" => {
2428 let global = get_global_transform_2d!(ctx.run, id);
2429 let (position, scale, shape) = with_node!(ctx.run, CollisionShape2D, id, |node| {
2430 let global = global.unwrap_or(node.transform);
2431 (global.position, global.scale, node.shape)
2432 }).unwrap_or_default();
2433 draw_collision_shape_2d(ctx, position, scale, shape);
2434 }
2435 _ => {}
2436 }
2437 }
2438}
2439
2440fn draw_collision_shape_2d<API: ScriptAPI + ?Sized>(
2441 ctx: &mut ScriptContext<'_, API>,
2442 center: Vector2,
2443 scale: Vector2,
2444 shape: Shape2D,
2445) {
2446 let fill = [0.12, 0.95, 0.95, 0.22];
2447 let line = [0.12, 0.95, 0.95, 0.95];
2448 match shape {
2449 Shape2D::Quad { width, height } => {
2450 let size = Vector2::new(width.abs() * scale.x.abs(), height.abs() * scale.y.abs());
2451 ctx.res.Draw2D().rect(center, size, fill);
2452 ctx.res.Draw2D().rect_stroke(center, size, line, 2.0);
2453 let hx = size.x * 0.5;
2454 let hy = size.y * 0.5;
2455 for point in [
2456 center + Vector2::new(-hx, -hy),
2457 center + Vector2::new(hx, -hy),
2458 center + Vector2::new(hx, hy),
2459 center + Vector2::new(-hx, hy),
2460 ] {
2461 ctx.res.Draw2D().circle(point, 4.0, [0.84, 1.0, 1.0, 1.0]);
2462 }
2463 }
2464 Shape2D::Circle { radius } => {
2465 let r = radius.abs() * scale.x.abs().max(scale.y.abs());
2466 ctx.res.Draw2D().circle(center, r, fill);
2467 ctx.res.Draw2D().ring(center, r, line, 2.0);
2468 for point in [
2469 center + Vector2::new(r, 0.0),
2470 center + Vector2::new(-r, 0.0),
2471 center + Vector2::new(0.0, r),
2472 center + Vector2::new(0.0, -r),
2473 ] {
2474 ctx.res.Draw2D().circle(point, 4.0, [0.84, 1.0, 1.0, 1.0]);
2475 }

Callers 1

update_ui_dragFunction · 0.85

Calls 3

rebuild_previewFunction · 0.85
refresh_allFunction · 0.85

Tested by

no test coverage detected