forked from info-beamer/package-bno055-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.lua
More file actions
147 lines (118 loc) · 3.67 KB
/
Copy pathnode.lua
File metadata and controls
147 lines (118 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- BNO055 demo: rotating video + rotating ticker (no logo)
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
local NW, NH = NATIVE_WIDTH, NATIVE_HEIGHT
-- Safe area (adjust scale if needed)
local SAFE_SCALE_W = 0.80
local SAFE_SCALE_H = 0.80
local SAFE_W = math.floor(NW * SAFE_SCALE_W)
local SAFE_H = math.floor(NH * SAFE_SCALE_H)
local OX = math.floor((NW - SAFE_W) / 2)
local OY = math.floor((NH - SAFE_H) / 2)
local angle = 0
local vid = nil
local font = resource.load_font "OpenSans-Bold.ttf"
local CONFIG = {}
local last_video_asset = nil
util.data_mapper{
rotate = function(new_angle)
angle = tonumber(new_angle) or 0
end
}
local function clamp(v, lo, hi)
if v < lo then return lo end
if v > hi then return hi end
return v
end
local function safe_load_video(asset)
local ok, v = pcall(resource.load_video, { file = asset, looped = true })
if ok then return v end
print("video load failed:", tostring(asset), tostring(v))
return nil
end
local function load_video()
local asset
if type(CONFIG.video) == "table" and CONFIG.video.asset_name then
asset = CONFIG.video.asset_name
else
asset = nil
end
if asset == last_video_asset and vid then return end
last_video_asset = asset
if vid then
vid:dispose()
vid = nil
end
if asset then
vid = safe_load_video(asset)
end
end
util.json_watch("config.json", function(config)
CONFIG = config or {}
load_video()
end)
local function draw_ticker()
if CONFIG.show_ticker == false then return end
local text = CONFIG.ticker_text or ""
if text == "" then return end
local size = tonumber(CONFIG.ticker_font_size) or 60
local speed = tonumber(CONFIG.ticker_speed) or 160
local gap = tonumber(CONFIG.ticker_gap) or 80
size = clamp(size, 12, math.floor(SAFE_H * 0.08))
-- position preset
local pos = CONFIG.ticker_pos or "bottom"
local y_local
if pos == "top" then
y_local = 20
elseif pos == "middle" then
y_local = (SAFE_H - size) / 2
else
y_local = SAFE_H - size - 20
end
-- offsets (px)
local ox = tonumber(CONFIG.ticker_offset_x) or 0
local oy = tonumber(CONFIG.ticker_offset_y) or 0
local y = y_local + OY + oy
local tw = font:width(text, size)
local x = SAFE_W - ((sys.now() * speed) % (tw + SAFE_W + gap))
x = x + OX + ox
-- color (rgba array 0..1)
-- color from setup (type "color")
local r,g,b,a = 1,1,1,1
local c = CONFIG.ticker_color
if type(c) == "table" then
-- most common: { rgba = {r,g,b,a}, ... }
if type(c.rgba) == "table" then
r = tonumber(c.rgba[1]) or r
g = tonumber(c.rgba[2]) or g
b = tonumber(c.rgba[3]) or b
a = tonumber(c.rgba[4]) or a
else
-- fallback: [r,g,b,a]
r = tonumber(c[1]) or r
g = tonumber(c[2]) or g
b = tonumber(c[3]) or b
a = tonumber(c[4]) or a
end
end
font:write(x, y, text, size, r,g,b,a)
font:write(x + tw + gap, y, text, size, r,g,b,a)
end
function node.render()
gl.clear(0, 0, 0, 1)
-- 1) VIDEO: rotates + scales (as before)
gl.pushMatrix()
gl.translate(OX + SAFE_W/2, OY + SAFE_H/2)
gl.rotate(angle, 0, 0, 1)
gl.scale(2, 2, 1)
if vid then
util.draw_correct(vid, -SAFE_W/2, -SAFE_H/2, SAFE_W/2, SAFE_H/2)
end
gl.popMatrix()
-- 2) TICKER: rotate with video, BUT DO NOT scale (keeps it visible/readable)
gl.pushMatrix()
gl.translate(OX + SAFE_W/2, OY + SAFE_H/2)
gl.rotate(angle, 0, 0, 1)
gl.translate(-(OX + SAFE_W/2), -(OY + SAFE_H/2))
pcall(draw_ticker)
gl.popMatrix()
end