A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 74 lines 2.5 kB view raw
1--[[ Lua Draw Text function 2/*************************************************************************** 3 * __________ __ ___. 4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 8 * \/ \/ \/ \/ \/ 9 * $Id$ 10 * 11 * Copyright (C) 2017 William Wilgus 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 2 16 * of the License, or (at your option) any later version. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ****************************************************************************/ 22]] 23-- draw text onto image if width/height are supplied text is centered 24 25if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end 26do 27 -- Internal Constants 28 local rocklib_image = getmetatable(rb.lcd_framebuffer()) 29 local _LCD = rb.lcd_framebuffer() 30 local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT 31 local BSAND = 8 -- blits color to dst if src <> 0 32 local _NIL = nil -- nil placeholder 33 34 local _clear = rocklib_image.clear 35 local _copy = rocklib_image.copy 36 local _newimg = rb.new_image 37 38 39 return function(img, x, y, width, height, font, color, text) 40 font = font or rb.FONT_UI 41 42 43 if rb.lcd_rgbpack ~= _NIL then -- Color target 44 rb.set_viewport(img, {fg_pattern = color, font = font, drawmode = 2})--DRMODE_FG 45 else 46 if color ~= 0 then color = 3 end--DRMODE_SOLID 47 rb.set_viewport(img, {font = font, drawmode = color}) 48 end 49 50 if width or height then 51 local res, w, h = rb.font_getstringsize(text, font) 52 53 if not width then 54 width = 0 55 else 56 width = (width - w) / 2 57 end 58 59 if not height then 60 height = 0 61 else 62 height = (height - h) / 2 63 end 64 x = width + x 65 y = height + y 66 67 end 68 69 rb.lcd_putsxy(x, y, text) 70 71 rb.set_viewport() -- set viewport default 72 return res, w, h 73 end 74end