Changeset View
Changeset View
Standalone View
Standalone View
stand/lua/drawer.lua
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | |||||
local function defaultframe() | local function defaultframe() | ||||
if core.isSerialConsole() then | if core.isSerialConsole() then | ||||
return "ascii" | return "ascii" | ||||
end | end | ||||
return "double" | return "double" | ||||
end | end | ||||
local function drawbox() | local function drawframe() | ||||
local x = menu_position.x - 3 | local x = menu_position.x - 3 | ||||
local y = menu_position.y - 1 | local y = menu_position.y - 1 | ||||
local w = frame_size.w | local w = frame_size.w | ||||
local h = frame_size.h | local h = frame_size.h | ||||
local framestyle = loader.getenv("loader_menu_frame") or defaultframe() | local framestyle = loader.getenv("loader_menu_frame") or defaultframe() | ||||
local framespec = drawer.frame_styles[framestyle] | local framespec = drawer.frame_styles[framestyle] | ||||
-- If we don't have a framespec for the current frame style, just don't | -- If we don't have a framespec for the current frame style, just don't | ||||
-- draw a box. | -- draw a box. | ||||
if framespec == nil then | if framespec == nil then | ||||
return | return false | ||||
end | end | ||||
local hl = framespec.horizontal | local hl = framespec.horizontal | ||||
local vl = framespec.vertical | local vl = framespec.vertical | ||||
local tl = framespec.top_left | local tl = framespec.top_left | ||||
local bl = framespec.bottom_left | local bl = framespec.bottom_left | ||||
local tr = framespec.top_right | local tr = framespec.top_right | ||||
local br = framespec.bottom_right | local br = framespec.bottom_right | ||||
x = x + shift.x | x = x + shift.x | ||||
y = y + shift.y | y = y + shift.y | ||||
if core.isFramebufferConsole() and loader.term_drawrect ~= nil then | |||||
loader.term_drawrect(x, y, x + w, y + h) | |||||
return true | |||||
end | |||||
screen.setcursor(x, y); printc(tl) | screen.setcursor(x, y); printc(tl) | ||||
screen.setcursor(x, y + h); printc(bl) | screen.setcursor(x, y + h); printc(bl) | ||||
screen.setcursor(x + w, y); printc(tr) | screen.setcursor(x + w, y); printc(tr) | ||||
screen.setcursor(x + w, y + h); printc(br) | screen.setcursor(x + w, y + h); printc(br) | ||||
screen.setcursor(x + 1, y) | screen.setcursor(x + 1, y) | ||||
for _ = 1, w - 1 do | for _ = 1, w - 1 do | ||||
printc(hl) | printc(hl) | ||||
end | end | ||||
screen.setcursor(x + 1, y + h) | screen.setcursor(x + 1, y + h) | ||||
for _ = 1, w - 1 do | for _ = 1, w - 1 do | ||||
printc(hl) | printc(hl) | ||||
end | end | ||||
for i = 1, h - 1 do | for i = 1, h - 1 do | ||||
screen.setcursor(x, y + i) | screen.setcursor(x, y + i) | ||||
printc(vl) | printc(vl) | ||||
screen.setcursor(x + w, y + i) | screen.setcursor(x + w, y + i) | ||||
printc(vl) | printc(vl) | ||||
end | end | ||||
return true | |||||
end | |||||
local function drawbox() | |||||
local x = menu_position.x - 3 | |||||
local y = menu_position.y - 1 | |||||
local w = frame_size.w | |||||
local menu_header = loader.getenv("loader_menu_title") or | local menu_header = loader.getenv("loader_menu_title") or | ||||
"Welcome to FreeBSD" | "Welcome to FreeBSD" | ||||
local menu_header_align = loader.getenv("loader_menu_title_align") | local menu_header_align = loader.getenv("loader_menu_title_align") | ||||
local menu_header_x | local menu_header_x | ||||
x = x + shift.x | |||||
y = y + shift.y | |||||
if drawframe(x, y, w) == false then | |||||
return | |||||
end | |||||
if menu_header_align ~= nil then | if menu_header_align ~= nil then | ||||
menu_header_align = menu_header_align:lower() | menu_header_align = menu_header_align:lower() | ||||
if menu_header_align == "left" then | if menu_header_align == "left" then | ||||
-- Just inside the left border on top | -- Just inside the left border on top | ||||
menu_header_x = x + 1 | menu_header_x = x + 1 | ||||
elseif menu_header_align == "right" then | elseif menu_header_align == "right" then | ||||
-- Just inside the right border on top | -- Just inside the right border on top | ||||
menu_header_x = x + w - #menu_header | menu_header_x = x + w - #menu_header | ||||
Show All 17 Lines | local function drawbrand() | ||||
if branddef == nil then | if branddef == nil then | ||||
branddef = getBranddef(drawer.default_brand) | branddef = getBranddef(drawer.default_brand) | ||||
end | end | ||||
local graphic = branddef.graphic | local graphic = branddef.graphic | ||||
x = x + shift.x | x = x + shift.x | ||||
y = y + shift.y | y = y + shift.y | ||||
if core.isFramebufferConsole() and | |||||
loader.term_putimage ~= nil and | |||||
branddef.image ~= nil then | |||||
if loader.term_putimage(branddef.image, 0, 0, 0, 7, 0) | |||||
then | |||||
return true | |||||
end | |||||
end | |||||
draw(x, y, graphic) | draw(x, y, graphic) | ||||
end | end | ||||
local function drawlogo() | local function drawlogo() | ||||
local x = tonumber(loader.getenv("loader_logo_x")) or | local x = tonumber(loader.getenv("loader_logo_x")) or | ||||
logo_position.x | logo_position.x | ||||
local y = tonumber(loader.getenv("loader_logo_y")) or | local y = tonumber(loader.getenv("loader_logo_y")) or | ||||
logo_position.y | logo_position.y | ||||
Show All 27 Lines | local function drawlogo() | ||||
x = x + shift.x | x = x + shift.x | ||||
y = y + shift.y | y = y + shift.y | ||||
if logodef ~= nil and logodef.shift ~= nil then | if logodef ~= nil and logodef.shift ~= nil then | ||||
x = x + logodef.shift.x | x = x + logodef.shift.x | ||||
y = y + logodef.shift.y | y = y + logodef.shift.y | ||||
end | end | ||||
if core.isFramebufferConsole() and | |||||
loader.term_putimage ~= nil and | |||||
logodef.image ~= nil then | |||||
local y1 = 15 | |||||
if logodef.image_rl ~= nil then | |||||
y1 = logodef.image_rl | |||||
end | |||||
if loader.term_putimage(logodef.image, x, y, 0, y + y1, 0) | |||||
then | |||||
return true | |||||
end | |||||
end | |||||
draw(x, y, logodef.graphic) | draw(x, y, logodef.graphic) | ||||
end | end | ||||
local function drawitem(func) | |||||
local console = loader.getenv("console") | |||||
local c | |||||
for c in string.gmatch(console, "%w+") do | |||||
loader.setenv("console", c) | |||||
func() | |||||
end | |||||
loader.setenv("console", console) | |||||
end | |||||
fbsd_brand = { | fbsd_brand = { | ||||
" ______ ____ _____ _____ ", | " ______ ____ _____ _____ ", | ||||
" | ____| | _ \\ / ____| __ \\ ", | " | ____| | _ \\ / ____| __ \\ ", | ||||
" | |___ _ __ ___ ___ | |_) | (___ | | | |", | " | |___ _ __ ___ ___ | |_) | (___ | | | |", | ||||
" | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |", | " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |", | ||||
" | | | | | __/ __/| |_) |____) | |__| |", | " | | | | | __/ __/| |_) |____) | |__| |", | ||||
" | | | | | | || | | |", | " | | | | | | || | | |", | ||||
" |_| |_| \\___|\\___||____/|_____/|_____/ " | " |_| |_| \\___|\\___||____/|_____/|_____/ " | ||||
Show All 29 Lines | menu_name_handlers = { | ||||
end, | end, | ||||
} | } | ||||
branddefs = { | branddefs = { | ||||
-- Indexed by valid values for loader_brand in loader.conf(5). Valid | -- Indexed by valid values for loader_brand in loader.conf(5). Valid | ||||
-- keys are: graphic (table depicting graphic) | -- keys are: graphic (table depicting graphic) | ||||
["fbsd"] = { | ["fbsd"] = { | ||||
graphic = fbsd_brand, | graphic = fbsd_brand, | ||||
image = "/boot/images/freebsd-brand-rev.png", | |||||
}, | }, | ||||
["none"] = { | ["none"] = { | ||||
graphic = none, | graphic = none, | ||||
}, | }, | ||||
} | } | ||||
logodefs = { | logodefs = { | ||||
-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys | -- Indexed by valid values for loader_logo in loader.conf(5). Valid keys | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | ["double"] = { | ||||
top_right = "\xE2\x95\x97", | top_right = "\xE2\x95\x97", | ||||
bottom_right = "\xE2\x95\x9D", | bottom_right = "\xE2\x95\x9D", | ||||
}, | }, | ||||
} | } | ||||
function drawer.drawscreen(menudef) | function drawer.drawscreen(menudef) | ||||
-- drawlogo() must go first. | -- drawlogo() must go first. | ||||
-- it determines the positions of other elements | -- it determines the positions of other elements | ||||
drawlogo() | drawitem(drawlogo) | ||||
drawbrand() | drawitem(drawbrand) | ||||
drawbox() | drawitem(drawbox) | ||||
return drawmenu(menudef) | return drawmenu(menudef) | ||||
end | end | ||||
return drawer | return drawer |