dymokomi/luced-3d
Source of release 0.11.8
0.11.8 / src / context_display.luc
## The context display mode (docs/NETWORK-LEVELS.md): while the network view
## is inside a container, how the viewport draws the rest of the scene around
## it. All draws it as it is, Greyed draws it faded (desaturated and
## see-through, after the context), Hidden leaves it out. A view setting
## (ViewState.context_mode), neither undone nor saved.
##
## Its button sits top right, left of the shading button: a click steps to
## the next mode; a long press, or a right click, opens the modes' menu.
from luce_ui.ui import Painter
from luce_ui import ui
from luce_gpu.gpu import Rect
import theme
from luce_std import math
pub let all = 0
pub let greyed = 1
pub let hidden = 2
## How far Greyed fades a surface (luce-3d's Material.fade).
pub let fade = 0.85
pub func names() -> list[str]:
return ["All", "Greyed", "Hidden"]
## Each mode's icon (luce-ui's set).
pub func icons() -> list[str]:
return ["visible", "ghosted", "hidden"]
## What each mode does, for the button's tip.
pub func tips() -> list[str]:
return ["Other objects: all, as they are", "Other objects: greyed", "Other objects: hidden"]
## The button, left of the shading button `shading` (viewport_chrome's).
pub func button(shading: Rect) -> Rect:
return Rect(shading.x - 38.0, shading.y, shading.width, shading.height)
pub func on_button(x: float, y: float, shading: Rect) -> bool:
let r = button(shading)
return x >= r.x and x <= r.x + r.width and y >= r.y and y <= r.y + r.height
## Draw the button for `mode`: lit while the network view is inside a
## container (`inside`), when the mode matters; its tip while `hovered`.
pub func draw_button(painter: Painter, shading: Rect, mode: int, inside: bool, hovered: bool) -> unit!:
draw_at(painter, button(shading), mode, inside, hovered)
## Draw the button at `r` (docked over four panes, beside the levels).
pub func draw_at(painter: Painter, r: Rect, mode: int, inside: bool, hovered: bool) -> unit!:
painter.rounded_rectangle(r, theme.surface(), 4.0)
let ink = theme.accent() if hovered else (theme.text() if inside else theme.text_muted())
ui.draw_icon(painter.target(), icons()[mode], Rect(r.x + 5.0, r.y + 4.0, 22.0, 22.0), ink)
# A held press opens the menu, as on the shading button.
painter.rectangle(Rect(r.x + 28.0, 34.0, 3.0, 3.0), theme.accent())
if hovered:
let text = tips()[mode] + " (hold for the menu)"
let tip_width = float(text.length) * 7.5 + 16.0
let x = math.max(4.0, r.x + r.width - tip_width)
painter.rounded_rectangle(Rect(x, r.y + 36.0, tip_width, 30.0), theme.surface(), 4.0)
painter.text(text, x + 8.0, r.y + 42.0, theme.text())