Mercurial
comparison infinite_canvas/canvas.c @ 281:c57149ad216e default tip
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Tue, 18 Aug 2026 22:18:15 -0700 |
| parents | 49e9e591c9bb |
| children |
comparison
equal
deleted
inserted
replaced
| 280:49e9e591c9bb | 281:c57149ad216e |
|---|---|
| 266 origin.y + p_segment->y2 * scale, | 266 origin.y + p_segment->y2 * scale, |
| 267 }, | 267 }, |
| 268 line_thickness, | 268 line_thickness, |
| 269 color); | 269 color); |
| 270 } | 270 } |
| 271 | |
| 272 } | |
| 273 | |
| 274 void Canvas_Draw_Lucide_Icon( | |
| 275 const char *p_name, | |
| 276 Vector2 origin, | |
| 277 float scale, | |
| 278 float line_thickness, | |
| 279 Color color) | |
| 280 { | |
| 281 Canvas_Lucide_Draw_Icon( | |
| 282 Canvas_Lucide_Find_Icon(p_name), | |
| 283 origin, | |
| 284 scale, | |
| 285 line_thickness, | |
| 286 color); | |
| 271 } | 287 } |
| 272 | 288 |
| 273 static Rectangle Canvas_Web_Toolbar_Bounds( | 289 static Rectangle Canvas_Web_Toolbar_Bounds( |
| 274 const Canvas_Camera *p_camera, | 290 const Canvas_Camera *p_camera, |
| 275 const Canvas_Entity *p_entity) | 291 const Canvas_Entity *p_entity) |
| 1631 default: | 1647 default: |
| 1632 return FALSE; | 1648 return FALSE; |
| 1633 } | 1649 } |
| 1634 } | 1650 } |
| 1635 | 1651 |
| 1636 static boolean Canvas_Web_Resize_Handle_Contains( | 1652 Rectangle Canvas_Entity_Resize_Handle_Bounds( |
| 1653 const Canvas_Entity *p_entity, | |
| 1654 float zoom) | |
| 1655 { | |
| 1656 float handle_size = CANVAS_WEB_RESIZE_HANDLE / zoom; | |
| 1657 return (Rectangle){ | |
| 1658 p_entity->position.x + p_entity->size.x - handle_size, | |
| 1659 p_entity->position.y + p_entity->size.y - handle_size, | |
| 1660 handle_size, | |
| 1661 handle_size, | |
| 1662 }; | |
| 1663 } | |
| 1664 | |
| 1665 static boolean Canvas_Entity_Resize_Handle_Contains( | |
| 1637 const Canvas_Entity *p_entity, | 1666 const Canvas_Entity *p_entity, |
| 1638 Vector2 point, | 1667 Vector2 point, |
| 1639 float zoom) | 1668 float zoom) |
| 1640 { | 1669 { |
| 1641 if (p_entity->type != CANVAS_ENTITY_WEB_CONTENT && | 1670 if (p_entity->type != CANVAS_ENTITY_WEB_CONTENT && |
| 1642 p_entity->type != CANVAS_ENTITY_IMAGE) { | 1671 p_entity->type != CANVAS_ENTITY_IMAGE && |
| 1672 p_entity->type != CANVAS_ENTITY_TEXT_AREA) { | |
| 1643 return FALSE; | 1673 return FALSE; |
| 1644 } | 1674 } |
| 1645 float handle_size = CANVAS_WEB_RESIZE_HANDLE / zoom; | |
| 1646 return CheckCollisionPointRec( | 1675 return CheckCollisionPointRec( |
| 1647 point, | 1676 point, |
| 1648 (Rectangle){ | 1677 Canvas_Entity_Resize_Handle_Bounds(p_entity, zoom)) ? TRUE : FALSE; |
| 1649 p_entity->position.x + p_entity->size.x - handle_size, | |
| 1650 p_entity->position.y + p_entity->size.y - handle_size, | |
| 1651 handle_size, | |
| 1652 handle_size, | |
| 1653 }) ? TRUE : FALSE; | |
| 1654 } | 1678 } |
| 1655 | 1679 |
| 1656 int32 Canvas_Scene_Pick( | 1680 int32 Canvas_Scene_Pick( |
| 1657 const Canvas_Scene *p_scene, | 1681 const Canvas_Scene *p_scene, |
| 1658 Vector2 world_pointer, | 1682 Vector2 world_pointer, |
| 2601 if (p_entity->type == CANVAS_ENTITY_LUCIDE_GALLERY) { | 2625 if (p_entity->type == CANVAS_ENTITY_LUCIDE_GALLERY) { |
| 2602 p_entity->active = CheckCollisionPointRec( | 2626 p_entity->active = CheckCollisionPointRec( |
| 2603 world_pointer, | 2627 world_pointer, |
| 2604 Canvas_Lucide_Search_Bounds(p_entity)) ? TRUE : FALSE; | 2628 Canvas_Lucide_Search_Bounds(p_entity)) ? TRUE : FALSE; |
| 2605 } | 2629 } |
| 2630 p_scene->resizing = Canvas_Entity_Resize_Handle_Contains( | |
| 2631 p_entity, | |
| 2632 world_pointer, | |
| 2633 p_camera->zoom); | |
| 2606 p_scene->selecting_text = FALSE; | 2634 p_scene->selecting_text = FALSE; |
| 2607 if (p_entity->type == CANVAS_ENTITY_TEXT_AREA) { | 2635 if (p_entity->type == CANVAS_ENTITY_TEXT_AREA) { |
| 2608 boolean inside_content = CheckCollisionPointRec( | 2636 boolean inside_content = |
| 2609 world_pointer, | 2637 !p_scene->resizing && |
| 2610 Canvas_Text_Area_Content_Bounds(p_entity)) ? TRUE : FALSE; | 2638 CheckCollisionPointRec( |
| 2639 world_pointer, | |
| 2640 Canvas_Text_Area_Content_Bounds(p_entity)); | |
| 2611 p_entity->active = inside_content; | 2641 p_entity->active = inside_content; |
| 2612 if (inside_content) { | 2642 if (inside_content) { |
| 2613 int32 cursor = Canvas_Text_Cursor_At_Point( | 2643 int32 cursor = Canvas_Text_Cursor_At_Point( |
| 2614 font, | 2644 font, |
| 2615 p_entity, | 2645 p_entity, |
| 2621 p_scene->selecting_text = TRUE; | 2651 p_scene->selecting_text = TRUE; |
| 2622 } | 2652 } |
| 2623 } | 2653 } |
| 2624 p_scene->pressed_index = p_scene->selected_index; | 2654 p_scene->pressed_index = p_scene->selected_index; |
| 2625 p_scene->dragging = FALSE; | 2655 p_scene->dragging = FALSE; |
| 2626 p_scene->resizing = Canvas_Web_Resize_Handle_Contains( | |
| 2627 p_entity, | |
| 2628 world_pointer, | |
| 2629 p_camera->zoom); | |
| 2630 p_scene->pointer_start = world_pointer; | 2656 p_scene->pointer_start = world_pointer; |
| 2631 p_scene->entity_start = p_entity->position; | 2657 p_scene->entity_start = p_entity->position; |
| 2632 p_scene->entity_size_start = p_entity->size; | 2658 p_scene->entity_size_start = p_entity->size; |
| 2633 } | 2659 } |
| 2634 } | 2660 } |
| 2661 if (p_scene->dragging) { | 2687 if (p_scene->dragging) { |
| 2662 Canvas_Entity *p_entity = p_pressed; | 2688 Canvas_Entity *p_entity = p_pressed; |
| 2663 if (p_entity->type == CANVAS_ENTITY_NOTIFICATION) { | 2689 if (p_entity->type == CANVAS_ENTITY_NOTIFICATION) { |
| 2664 p_scene->dragging = FALSE; | 2690 p_scene->dragging = FALSE; |
| 2665 } else if (p_scene->resizing) { | 2691 } else if (p_scene->resizing) { |
| 2692 float min_width = | |
| 2693 p_entity->type == CANVAS_ENTITY_TEXT_AREA | |
| 2694 ? CANVAS_TEXT_AREA_MIN_WIDTH | |
| 2695 : CANVAS_WEB_MIN_WIDTH; | |
| 2696 float min_height = | |
| 2697 p_entity->type == CANVAS_ENTITY_TEXT_AREA | |
| 2698 ? CANVAS_TEXT_AREA_MIN_HEIGHT | |
| 2699 : CANVAS_WEB_MIN_HEIGHT; | |
| 2666 p_entity->size = (Vector2){ | 2700 p_entity->size = (Vector2){ |
| 2667 fmaxf(CANVAS_WEB_MIN_WIDTH, p_scene->entity_size_start.x + delta.x), | 2701 fmaxf( |
| 2668 fmaxf(CANVAS_WEB_MIN_HEIGHT, p_scene->entity_size_start.y + delta.y), | 2702 min_width, |
| 2703 p_scene->entity_size_start.x + delta.x), | |
| 2704 fmaxf( | |
| 2705 min_height, | |
| 2706 p_scene->entity_size_start.y + delta.y), | |
| 2669 }; | 2707 }; |
| 2708 if (p_entity->type == CANVAS_ENTITY_TEXT_AREA) { | |
| 2709 Canvas_Text_Ensure_Cursor_Visible(p_entity, font); | |
| 2710 } | |
| 2670 } else { | 2711 } else { |
| 2671 p_entity->position = (Vector2){ | 2712 p_entity->position = (Vector2){ |
| 2672 p_scene->entity_start.x + delta.x, | 2713 p_scene->entity_start.x + delta.x, |
| 2673 p_scene->entity_start.y + delta.y, | 2714 p_scene->entity_start.y + delta.y, |
| 2674 }; | 2715 }; |
| 3057 }, | 3098 }, |
| 3058 0.04f, | 3099 0.04f, |
| 3059 10, | 3100 10, |
| 3060 line, | 3101 line, |
| 3061 selection); | 3102 selection); |
| 3062 DrawRectangleRec( | |
| 3063 (Rectangle){ | |
| 3064 p_entity->position.x + p_entity->size.x - | |
| 3065 CANVAS_WEB_RESIZE_HANDLE / zoom, | |
| 3066 p_entity->position.y + p_entity->size.y - | |
| 3067 CANVAS_WEB_RESIZE_HANDLE / zoom, | |
| 3068 CANVAS_WEB_RESIZE_HANDLE / zoom, | |
| 3069 CANVAS_WEB_RESIZE_HANDLE / zoom, | |
| 3070 }, | |
| 3071 Canvas_Color_Fade(selection, 0.18f)); | |
| 3072 DrawLineEx( | |
| 3073 (Vector2){ | |
| 3074 p_entity->position.x + p_entity->size.x - 11.0f / zoom, | |
| 3075 p_entity->position.y + p_entity->size.y - 4.0f / zoom, | |
| 3076 }, | |
| 3077 (Vector2){ | |
| 3078 p_entity->position.x + p_entity->size.x - 4.0f / zoom, | |
| 3079 p_entity->position.y + p_entity->size.y - 11.0f / zoom, | |
| 3080 }, | |
| 3081 1.5f / zoom, | |
| 3082 selection); | |
| 3083 break; | 3103 break; |
| 3084 default: | 3104 default: |
| 3085 break; | 3105 break; |
| 3086 } | 3106 } |
| 3087 | 3107 |
| 3108 if (p_entity->type == CANVAS_ENTITY_TEXT_AREA || | |
| 3109 p_entity->type == CANVAS_ENTITY_IMAGE || | |
| 3110 p_entity->type == CANVAS_ENTITY_WEB_CONTENT) { | |
| 3111 Rectangle handle = | |
| 3112 Canvas_Entity_Resize_Handle_Bounds(p_entity, zoom); | |
| 3113 DrawRectangleRec( | |
| 3114 handle, | |
| 3115 Canvas_Color_Fade(selection, 0.18f)); | |
| 3116 DrawLineEx( | |
| 3117 (Vector2){ | |
| 3118 handle.x + handle.width - 11.0f / zoom, | |
| 3119 handle.y + handle.height - 4.0f / zoom, | |
| 3120 }, | |
| 3121 (Vector2){ | |
| 3122 handle.x + handle.width - 4.0f / zoom, | |
| 3123 handle.y + handle.height - 11.0f / zoom, | |
| 3124 }, | |
| 3125 1.5f / zoom, | |
| 3126 selection); | |
| 3127 } | |
| 3088 } | 3128 } |
| 3089 | 3129 |
| 3090 static void Canvas_Draw_Text_Area_Content( | 3130 static void Canvas_Draw_Text_Area_Content( |
| 3091 const Canvas_Entity *p_entity, | 3131 const Canvas_Entity *p_entity, |
| 3092 Font font, | 3132 Font font, |