| 1657 | } |
| 1658 | |
| 1659 | static inline void CalcMiniMapLayout() |
| 1660 | { |
| 1661 | ImNodesEditorContext& editor = EditorContextGet(); |
| 1662 | const ImVec2 offset = GImNodes->Style.MiniMapOffset; |
| 1663 | const ImVec2 border = GImNodes->Style.MiniMapPadding; |
| 1664 | const ImRect editor_rect = GImNodes->CanvasRectScreenSpace; |
| 1665 | |
| 1666 | // Compute the size of the mini-map area |
| 1667 | ImVec2 mini_map_size; |
| 1668 | float mini_map_scaling; |
| 1669 | { |
| 1670 | const ImVec2 max_size = |
| 1671 | ImFloor(editor_rect.GetSize() * editor.MiniMapSizeFraction - border * 2.0f); |
| 1672 | const float max_size_aspect_ratio = max_size.x / max_size.y; |
| 1673 | const ImVec2 grid_content_size = editor.GridContentBounds.IsInverted() |
| 1674 | ? max_size |
| 1675 | : ImFloor(editor.GridContentBounds.GetSize()); |
| 1676 | const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; |
| 1677 | mini_map_size = ImFloor( |
| 1678 | grid_content_aspect_ratio > max_size_aspect_ratio |
| 1679 | ? ImVec2(max_size.x, max_size.x / grid_content_aspect_ratio) |
| 1680 | : ImVec2(max_size.y * grid_content_aspect_ratio, max_size.y)); |
| 1681 | mini_map_scaling = mini_map_size.x / grid_content_size.x; |
| 1682 | } |
| 1683 | |
| 1684 | // Compute location of the mini-map |
| 1685 | ImVec2 mini_map_pos; |
| 1686 | { |
| 1687 | ImVec2 align; |
| 1688 | |
| 1689 | switch (editor.MiniMapLocation) |
| 1690 | { |
| 1691 | case ImNodesMiniMapLocation_BottomRight: |
| 1692 | align.x = 1.0f; |
| 1693 | align.y = 1.0f; |
| 1694 | break; |
| 1695 | case ImNodesMiniMapLocation_BottomLeft: |
| 1696 | align.x = 0.0f; |
| 1697 | align.y = 1.0f; |
| 1698 | break; |
| 1699 | case ImNodesMiniMapLocation_TopRight: |
| 1700 | align.x = 1.0f; |
| 1701 | align.y = 0.0f; |
| 1702 | break; |
| 1703 | case ImNodesMiniMapLocation_TopLeft: // [[fallthrough]] |
| 1704 | default: |
| 1705 | align.x = 0.0f; |
| 1706 | align.y = 0.0f; |
| 1707 | break; |
| 1708 | } |
| 1709 | |
| 1710 | const ImVec2 top_left_pos = editor_rect.Min + offset + border; |
| 1711 | const ImVec2 bottom_right_pos = editor_rect.Max - offset - border - mini_map_size; |
| 1712 | mini_map_pos = ImFloor(ImLerp(top_left_pos, bottom_right_pos, align)); |
| 1713 | } |
| 1714 | |
| 1715 | editor.MiniMapRectScreenSpace = |
| 1716 | ImRect(mini_map_pos - border, mini_map_pos + mini_map_size + border); |