31 lines
1.4 KiB
Text
31 lines
1.4 KiB
Text
# render3d_nine.ludic - border-image for the render3d backend: a nine-slice of a texture
|
|
module ludic_ui
|
|
# border-image: the texture's `slice`-pixel corners kept, the rest stretched, drawn `dst` wide (at
|
|
# most half the box each way, ui_nine_cuts); the slice is a share of the texture's own width across
|
|
# and its own height down, so it need not be square
|
|
function r3u_nine(render3d_st: mut Render3dState, ui_st: mut UiState, src: string, slice: float, x: float, y: float, w: float, h: float, dst: float, c: int, a: float) -> void {
|
|
let t = r3u_tex(render3d_st, ui_st, src)
|
|
if t == 0 { return }
|
|
let su = slice / float(Math.max(tex_width(render3d_st, t), 1))
|
|
let sv = slice / float(Math.max(tex_height(render3d_st, t), 1))
|
|
let cut = ui_nine_cuts_into(ui_st.r3n_cut, x, y, w, h, dst)
|
|
let xs = r3u_four(ui_st.r3n_xs, cut[0], cut[1], cut[2], cut[3])
|
|
let ys = r3u_four(ui_st.r3n_ys, cut[4], cut[5], cut[6], cut[7])
|
|
let us = r3u_four(ui_st.r3n_us, 0.0, su, 1.0 - su, 1.0)
|
|
let vs = r3u_four(ui_st.r3n_vs, 0.0, sv, 1.0 - sv, 1.0)
|
|
for j in 0 .. 3 {
|
|
for i in 0 .. 3 {
|
|
let x0 = int(xs[i])
|
|
let y0 = int(ys[j])
|
|
ov_sub(render3d_st, t, x0, y0, int(xs[i + 1]) - x0, int(ys[j + 1]) - y0, us[i], vs[j], us[i + 1], vs[j + 1], r3u_r(c), r3u_g(c), r3u_b(c), a)
|
|
}
|
|
}
|
|
}
|
|
function r3u_four(out: []float, a: float, b: float, c: float, d: float) -> []float {
|
|
List.clear(out)
|
|
push(out, a)
|
|
push(out, b)
|
|
push(out, c)
|
|
push(out, d)
|
|
return out
|
|
}
|