first commit
166
lcdlib/LICENSE.txt
Normal file
@ -0,0 +1,166 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
13
lcdlib/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# LCD Lib
|
||||
|
||||
This LCD Lib is based on Display Lib and Font Lib from Pierre-Yves Rollo
|
||||
|
||||
**Dependancies**: default
|
||||
|
||||
**License**: LGPL
|
||||
|
||||
Code by Pierre-Yves Rollo (pyrollo)
|
||||
Textures by Vanessa Ezekowitz (VanessaE).
|
||||
(Default font taken from VanessaE's homedecor/signs_lib, originally under WTFPL)
|
||||
|
||||
|
2
lcdlib/copyright.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Code by Pierre-Yves Rollo (pyrollo)
|
||||
Textures by Vanessa Ezekowitz (VanessaE)
|
0
lcdlib/depends.txt
Normal file
229
lcdlib/display.lua
Normal file
@ -0,0 +1,229 @@
|
||||
--[[
|
||||
cldlib based on:
|
||||
|
||||
display_lib mod for Minetest - Library to add dynamic display
|
||||
capabilities to nodes
|
||||
(c) Pierre-Yves Rollo
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Miscelaneous values depending on wallmounted param2
|
||||
local wallmounted_values = {
|
||||
[0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used
|
||||
{dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5},
|
||||
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4},
|
||||
{dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2},
|
||||
{dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}
|
||||
}
|
||||
|
||||
-- Miscelaneous values depending on facedir param2
|
||||
local facedir_values = {
|
||||
[0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1},
|
||||
{dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2},
|
||||
{dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3},
|
||||
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0},
|
||||
-- Forbiden values :
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
|
||||
}
|
||||
|
||||
-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity,
|
||||
-- rotate = next facedir/wallmount on rotate
|
||||
|
||||
local function get_values(node)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" then
|
||||
return wallmounted_values[node.param2]
|
||||
end
|
||||
if ndef.paramtype2 == "facedir" then
|
||||
return facedir_values[node.param2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets the display entities attached with a node. Removes extra ones
|
||||
local function get_entities(pos)
|
||||
local objrefs = {}
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
if ndef and ndef.display_entities then
|
||||
for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
local entity = objref:get_luaentity()
|
||||
if entity and ndef.display_entities[entity.name] then
|
||||
if objrefs[entity.name] then
|
||||
objref:remove()
|
||||
else
|
||||
objrefs[entity.name] = objref
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return objrefs
|
||||
end
|
||||
|
||||
local function clip_pos_prop(posprop)
|
||||
if posprop then
|
||||
return math.max(-0.5, math.min(0.5, posprop))
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
--- (Create and) place display entities according to the node orientation
|
||||
local function place_entities(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
local values = get_values(node)
|
||||
local objrefs = get_entities(pos)
|
||||
|
||||
if values and ndef and ndef.display_entities then
|
||||
|
||||
for entity_name, props in pairs(ndef.display_entities) do
|
||||
local depth = clip_pos_prop(props.depth)
|
||||
local height = clip_pos_prop(props.height)
|
||||
local right = clip_pos_prop(props.right)
|
||||
if not objrefs[entity_name] then
|
||||
objrefs[entity_name] = minetest.add_entity(pos, entity_name)
|
||||
end
|
||||
|
||||
objrefs[entity_name]:setpos({
|
||||
x = pos.x - values.dx * depth + values.rx * right,
|
||||
y = pos.y + height,
|
||||
z = pos.z - values.dz * depth + values.rz * right})
|
||||
|
||||
objrefs[entity_name]:setyaw(values.yaw)
|
||||
end
|
||||
end
|
||||
return objrefs
|
||||
end
|
||||
|
||||
--- Call on_display_update callback of a node for one of its display entities
|
||||
local function call_node_on_display_update(pos, objref)
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
if ndef and ndef.display_entities and entity and ndef.display_entities[entity.name] then
|
||||
ndef.display_entities[entity.name].on_display_update(pos, objref)
|
||||
end
|
||||
end
|
||||
|
||||
--- Force entity update
|
||||
function lcdlib.update_entities(pos)
|
||||
local objrefs = place_entities(pos)
|
||||
for _, objref in pairs(objrefs) do
|
||||
call_node_on_display_update(pos, objref)
|
||||
end
|
||||
end
|
||||
|
||||
--- On_activate callback for lcdlib entities. Calls on_display_update callbacks
|
||||
--- of corresponding node for each entity.
|
||||
function lcdlib.on_activate(entity, staticdata)
|
||||
if entity then
|
||||
entity.object:set_armor_groups({immortal=1})
|
||||
call_node_on_display_update(entity.object:getpos(), entity.object)
|
||||
end
|
||||
end
|
||||
|
||||
--- On_place callback for lcdlib items. Does nothing more than preventing item
|
||||
--- from being placed on ceiling or ground
|
||||
function lcdlib.on_place(itemstack, placer, pointed_thing)
|
||||
local ndef = itemstack:get_definition()
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local dir = {x = under.x - above.x,
|
||||
y = under.y - above.y,
|
||||
z = under.z - above.z}
|
||||
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" then
|
||||
|
||||
local wdir = minetest.dir_to_wallmounted(dir)
|
||||
|
||||
if wdir == 0 or wdir == 1 then
|
||||
dir = placer:get_look_dir()
|
||||
dir.y = 0
|
||||
wdir = minetest.dir_to_wallmounted(dir)
|
||||
end
|
||||
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, wdir)
|
||||
else
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(dir))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- On_construct callback for lcdlib items. Creates entities and update them.
|
||||
function lcdlib.on_construct(pos)
|
||||
lcdlib.update_entities(pos)
|
||||
end
|
||||
|
||||
--- On_destruct callback for lcdlib items. Removes entities.
|
||||
function lcdlib.on_destruct(pos)
|
||||
local objrefs = get_entities(pos)
|
||||
|
||||
for _, objref in pairs(objrefs) do
|
||||
objref:remove()
|
||||
end
|
||||
end
|
||||
|
||||
-- On_rotate (screwdriver) callback for lcdlib items. Prevents axis rotation and reorients entities.
|
||||
function lcdlib.on_rotate(pos, node, user, mode, new_param2)
|
||||
if mode ~= 1 then return false end
|
||||
|
||||
local values = get_values(node)
|
||||
|
||||
if values then
|
||||
minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate})
|
||||
place_entities(pos)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Creates display entity with some fields and the on_activate callback
|
||||
function lcdlib.register_display_entity(entity_name)
|
||||
if not minetest.registered_entity then
|
||||
minetest.register_entity(':'..entity_name, {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {},
|
||||
on_activate = lcdlib.on_activate,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
12
lcdlib/font_default.lua
Normal file
@ -0,0 +1,12 @@
|
||||
--[[
|
||||
|
||||
generated by tools/make_font_lua.sh Thu Dec 21 21:45:53 CET 2017
|
||||
|
||||
--]]
|
||||
|
||||
lcdlib.register_font(
|
||||
'default',
|
||||
12,
|
||||
{ [0]=6, [32]=4, [33]=3, [34]=4, [35]=7, [36]=6, [37]=8, [38]=8, [39]=3, [40]=4, [41]=4, [42]=4, [43]=7, [44]=3, [45]=5, [46]=3, [47]=5, [48]=6, [49]=4, [50]=6, [51]=6, [52]=7, [53]=6, [54]=6, [55]=6, [56]=6, [57]=6, [58]=3, [59]=3, [60]=5, [61]=6, [62]=5, [63]=6, [64]=11, [65]=8, [66]=7, [67]=8, [68]=7, [69]=6, [70]=6, [71]=8, [72]=7, [73]=3, [74]=6, [75]=8, [76]=6, [77]=10, [78]=8, [79]=8, [80]=7, [81]=8, [82]=7, [83]=7, [84]=7, [85]=7, [86]=8, [87]=11, [88]=8, [89]=9, [90]=7, [91]=4, [92]=5, [93]=4, [94]=5, [95]=7, [96]=3, [97]=7, [98]=6, [99]=5, [100]=6, [101]=6, [102]=5, [103]=6, [104]=6, [105]=3, [106]=3, [107]=7, [108]=3, [109]=9, [110]=6, [111]=6, [112]=6, [113]=6, [114]=5, [115]=6, [116]=4, [117]=6, [118]=6, [119]=8, [120]=7, [121]=6, [122]=6, [123]=5, [124]=3, [125]=5, [126]=6, [138]=6, [141]=3, [161]=3, [177]=6, [191]=6, [192]=8, [193]=8, [194]=8, [195]=8, [196]=8, [197]=8, [198]=10, [199]=8, [200]=6, [201]=6, [202]=6, [203]=6, [204]=3, [205]=3, [206]=3, [207]=3, [208]=8, [209]=8, [210]=8, [211]=8, [212]=8, [213]=8, [214]=8, [215]=6, [216]=8, [217]=7, [218]=7, [219]=7, [220]=7, [221]=9, [224]=7, [225]=7, [226]=7, [227]=7, [228]=7, [229]=7, [230]=9, [231]=5, [232]=6, [233]=6, [234]=6, [235]=6, [236]=3, [237]=3, [238]=3, [239]=3, [242]=6, [244]=6, [245]=6, [246]=6, [247]=6, [249]=6, [250]=6, [251]=6, [252]=6, [253]=6, [255]=6 }
|
||||
);
|
||||
|
277
lcdlib/init.lua
Normal file
@ -0,0 +1,277 @@
|
||||
--[[
|
||||
lcdlib based on:
|
||||
|
||||
font_lib mod for Minetest - Library to add font display capability
|
||||
to display_lib mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Global variables
|
||||
lcdlib = {}
|
||||
lcdlib.registered_fonts = {}
|
||||
|
||||
-- Local functions
|
||||
------------------
|
||||
|
||||
-- Split multiline text into array of lines, with <maxlines> maximum lines.
|
||||
|
||||
local function split_lines(text, maxlines)
|
||||
local splits = text:split("\n")
|
||||
if maxlines then
|
||||
local lines = {}
|
||||
for num = 1,maxlines do
|
||||
lines[num] = splits[num]
|
||||
end
|
||||
return lines
|
||||
else
|
||||
return splits
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns next char, managing ascii and unicode plane 0 (0000-FFFF).
|
||||
|
||||
local function get_next_char(text, pos)
|
||||
pos = pos + 1
|
||||
local char = text:sub(pos, pos):byte()
|
||||
|
||||
-- 1 byte char
|
||||
if char < 0x80 then
|
||||
return char, pos
|
||||
end
|
||||
|
||||
-- 4 bytes char not managed
|
||||
if char >= 0xF0 then
|
||||
pos = pos + 3
|
||||
return 0, pos
|
||||
end
|
||||
|
||||
-- 3 bytes char not managed
|
||||
if char >= 0xE0 then
|
||||
pos = pos + 2
|
||||
return 0, pos
|
||||
end
|
||||
|
||||
-- 2 bytes char (little endian)
|
||||
if char >= 0xC2 then
|
||||
pos = pos + 1
|
||||
return (char - 0xC2) * 0x40 + text:sub(pos, pos):byte(), pos
|
||||
end
|
||||
|
||||
-- Not an UTF char
|
||||
return 0, pos
|
||||
|
||||
end
|
||||
|
||||
-- Returns font properties to be used according to font_name
|
||||
|
||||
local function get_font(font_name)
|
||||
local font = lcdlib.registered_fonts[font_name]
|
||||
|
||||
if font == nil then
|
||||
local message
|
||||
|
||||
if font_name == nil then
|
||||
message = "No font given"
|
||||
else
|
||||
message = "Font \""..font_name.."\" unregistered"
|
||||
end
|
||||
|
||||
if lcdlib.fallback_font == nil then
|
||||
minetest.log("error", message.." and no other font registered.")
|
||||
else
|
||||
minetest.log("info", message..", using font \""..lcdlib.fallback_font.."\".")
|
||||
font = lcdlib.registered_fonts[lcdlib.fallback_font]
|
||||
end
|
||||
end
|
||||
|
||||
return font
|
||||
end
|
||||
|
||||
-- API functions
|
||||
----------------
|
||||
|
||||
-- Computes text size for a given font and text (ignores new lines)
|
||||
-- @param font_name Font to be used
|
||||
-- @param text Text to be rendered
|
||||
-- @return Rendered text (width, height)
|
||||
|
||||
function lcdlib.get_text_size(font_name, text)
|
||||
local char
|
||||
local width = 0
|
||||
local pos = 0
|
||||
local font = get_font(font_name)
|
||||
|
||||
if font == nil then
|
||||
return 0, 0
|
||||
else
|
||||
while pos < #text do
|
||||
char, pos = get_next_char(text, pos)
|
||||
-- Ignore chars with no texture
|
||||
if font.widths[char] ~= nil then
|
||||
width = width + font.widths[char]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return width, font.height
|
||||
end
|
||||
|
||||
--- Builds texture part for a text line
|
||||
-- @param font_name Font to be used
|
||||
-- @param text Text to be rendered
|
||||
-- @param width Width of the texture (extra text is not rendered)
|
||||
-- @param x Starting x position in texture
|
||||
-- @param y Vertical position of the line in texture
|
||||
-- @return Texture string
|
||||
|
||||
--> ADD ALIGN
|
||||
function lcdlib.make_line_texture(font_name, text, width, x, y)
|
||||
local texture = ""
|
||||
local char
|
||||
local pos = 0
|
||||
local font = get_font(font_name)
|
||||
|
||||
if font ~= nil then
|
||||
while pos < #text do
|
||||
char, pos = get_next_char(text, pos)
|
||||
|
||||
-- Ignore chars with no texture
|
||||
if font.widths[char] ~= nil then
|
||||
-- Add image only if it is visible (at least partly)
|
||||
if x + font.widths[char] >= 0 and x <= width then
|
||||
texture = texture..
|
||||
string.format(":%d,%d=font_%s_%04x.png",
|
||||
x, y, font.name, char)
|
||||
end
|
||||
x = x + font.widths[char]
|
||||
else
|
||||
print(string.format("Missing char %d (%04x)",char,char))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return texture
|
||||
end
|
||||
|
||||
--- Builds texture for a multiline colored text
|
||||
-- @param font_name Font to be used
|
||||
-- @param text Text to be rendered
|
||||
-- @param texturew Width of the texture (extra text will be truncated)
|
||||
-- @param textureh Height of the texture
|
||||
-- @param maxlines Maximum number of lines
|
||||
-- @param valign Vertical text align ("top" or "center")
|
||||
-- @param color Color of the text
|
||||
-- @return Texture string
|
||||
|
||||
function lcdlib.make_multiline_texture(font_name, text, width, height,
|
||||
maxlines, valign, color)
|
||||
local texture = ""
|
||||
local lines = {}
|
||||
local textheight = 0
|
||||
local y, w, h
|
||||
|
||||
for num, line in pairs(split_lines(text, maxlines)) do
|
||||
w, h = lcdlib.get_text_size(font_name, line)
|
||||
lines[num] = { text = line, width = w, height = h, }
|
||||
textheight = textheight + h
|
||||
end
|
||||
|
||||
if #lines then
|
||||
if valign == "top" then
|
||||
y = 0
|
||||
elseif valign == "bottom" then
|
||||
y = height - textheight
|
||||
else
|
||||
y = (height - textheight) / 2
|
||||
end
|
||||
end
|
||||
|
||||
for _, line in pairs(lines) do
|
||||
texture = texture..
|
||||
lcdlib.make_line_texture(font_name, line.text, width,
|
||||
(width - line.width) / 2, y)
|
||||
y = y + line.height
|
||||
end
|
||||
|
||||
texture = string.format("[combine:%dx%d", width, height)..texture
|
||||
if color then texture = texture.."^[colorize:"..color end
|
||||
|
||||
return texture
|
||||
end
|
||||
|
||||
--- Register a new font
|
||||
-- Textures corresponding to the font should be named after following patern :
|
||||
-- font_<name>_<code>.png
|
||||
-- <name> : name of the font
|
||||
-- <code> : 4 digit hexadecimal unicode of the char
|
||||
-- If registering different sizes, add size in the font name (e.g. times_10, times_12...)
|
||||
-- @param height Font height in pixels
|
||||
-- @param widths Array of character widths in pixel, indexed by unicode number.
|
||||
|
||||
function lcdlib.register_font(font_name, height, widths)
|
||||
if lcdlib.registered_fonts[font_name] ~= nil then
|
||||
minetest.log("error", "Font \""..font_name.."\" already registered.")
|
||||
return
|
||||
end
|
||||
|
||||
lcdlib.registered_fonts[font_name] =
|
||||
{ name = font_name, height = height, widths = widths }
|
||||
|
||||
-- If no fallback font, set it (so, first font registered will be the default fallback font)
|
||||
if lcdlib.fallback_font == nil then
|
||||
lcdlib.fallback_font = font_name
|
||||
end
|
||||
end
|
||||
|
||||
--- Define the fallback font
|
||||
-- This font will be used instead of given font if not registered.
|
||||
-- @param font_name Name of the font to be used as fallback font (has to be registered).
|
||||
|
||||
function lcdlib.set_fallback_font(font_name)
|
||||
if lcdlib.registered_fonts[font_name] == nil then
|
||||
minetest.log("error", "Fallback font \""..font_name.."\" not registered.")
|
||||
else
|
||||
lcdlib.fallback_font = font_name
|
||||
end
|
||||
end
|
||||
|
||||
--- Standard on_display_update entity callback.
|
||||
-- Node should have a corresponding display_entity with size, resolution and maxlines fields and
|
||||
-- optionally valign and color fields
|
||||
-- @param pos Node position
|
||||
-- @param objref Object reference of entity
|
||||
|
||||
function lcdlib.on_display_update(pos, objref)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local text = meta:get_string("display_text")
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
|
||||
if entity and ndef.display_entities[entity.name] then
|
||||
local def = ndef.display_entities[entity.name]
|
||||
|
||||
objref:set_properties({
|
||||
textures={lcdlib.make_multiline_texture(
|
||||
def.font_name, text, def.size.x*def.resolution.x, def.size.y*def.resolution.y,
|
||||
def.maxlines, def.valign, def.color)},
|
||||
visual_size = def.size
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("lcdlib").."/font_default.lua")
|
||||
dofile(minetest.get_modpath("lcdlib").."/display.lua")
|
||||
|
BIN
lcdlib/textures/font_default_0000.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
lcdlib/textures/font_default_0020.png
Normal file
After Width: | Height: | Size: 281 B |
BIN
lcdlib/textures/font_default_0021.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
lcdlib/textures/font_default_0022.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
lcdlib/textures/font_default_0023.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
lcdlib/textures/font_default_0024.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0025.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
lcdlib/textures/font_default_0026.png
Normal file
After Width: | Height: | Size: 319 B |
BIN
lcdlib/textures/font_default_0027.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
lcdlib/textures/font_default_0028.png
Normal file
After Width: | Height: | Size: 303 B |
BIN
lcdlib/textures/font_default_0029.png
Normal file
After Width: | Height: | Size: 301 B |
BIN
lcdlib/textures/font_default_002a.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
lcdlib/textures/font_default_002b.png
Normal file
After Width: | Height: | Size: 297 B |
BIN
lcdlib/textures/font_default_002c.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
lcdlib/textures/font_default_002d.png
Normal file
After Width: | Height: | Size: 287 B |
BIN
lcdlib/textures/font_default_002e.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
lcdlib/textures/font_default_002f.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
lcdlib/textures/font_default_0030.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
lcdlib/textures/font_default_0031.png
Normal file
After Width: | Height: | Size: 300 B |
BIN
lcdlib/textures/font_default_0032.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
lcdlib/textures/font_default_0033.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
lcdlib/textures/font_default_0034.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0035.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
lcdlib/textures/font_default_0036.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
lcdlib/textures/font_default_0037.png
Normal file
After Width: | Height: | Size: 308 B |
BIN
lcdlib/textures/font_default_0038.png
Normal file
After Width: | Height: | Size: 300 B |
BIN
lcdlib/textures/font_default_0039.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
lcdlib/textures/font_default_003a.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
lcdlib/textures/font_default_003b.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
lcdlib/textures/font_default_003c.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
lcdlib/textures/font_default_003d.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
lcdlib/textures/font_default_003e.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
lcdlib/textures/font_default_003f.png
Normal file
After Width: | Height: | Size: 310 B |
BIN
lcdlib/textures/font_default_0040.png
Normal file
After Width: | Height: | Size: 323 B |
BIN
lcdlib/textures/font_default_0041.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
lcdlib/textures/font_default_0042.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
lcdlib/textures/font_default_0043.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
lcdlib/textures/font_default_0044.png
Normal file
After Width: | Height: | Size: 308 B |
BIN
lcdlib/textures/font_default_0045.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
lcdlib/textures/font_default_0046.png
Normal file
After Width: | Height: | Size: 305 B |
BIN
lcdlib/textures/font_default_0047.png
Normal file
After Width: | Height: | Size: 327 B |
BIN
lcdlib/textures/font_default_0048.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
lcdlib/textures/font_default_0049.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
lcdlib/textures/font_default_004a.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
lcdlib/textures/font_default_004b.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
lcdlib/textures/font_default_004c.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
lcdlib/textures/font_default_004d.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
lcdlib/textures/font_default_004e.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
lcdlib/textures/font_default_004f.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0050.png
Normal file
After Width: | Height: | Size: 309 B |
BIN
lcdlib/textures/font_default_0051.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
lcdlib/textures/font_default_0052.png
Normal file
After Width: | Height: | Size: 303 B |
BIN
lcdlib/textures/font_default_0053.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
lcdlib/textures/font_default_0054.png
Normal file
After Width: | Height: | Size: 301 B |
BIN
lcdlib/textures/font_default_0055.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
lcdlib/textures/font_default_0056.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_0057.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
lcdlib/textures/font_default_0058.png
Normal file
After Width: | Height: | Size: 308 B |
BIN
lcdlib/textures/font_default_0059.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_005a.png
Normal file
After Width: | Height: | Size: 307 B |
BIN
lcdlib/textures/font_default_005b.png
Normal file
After Width: | Height: | Size: 297 B |
BIN
lcdlib/textures/font_default_005c.png
Normal file
After Width: | Height: | Size: 297 B |
BIN
lcdlib/textures/font_default_005d.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
lcdlib/textures/font_default_005e.png
Normal file
After Width: | Height: | Size: 303 B |
BIN
lcdlib/textures/font_default_005f.png
Normal file
After Width: | Height: | Size: 286 B |
BIN
lcdlib/textures/font_default_0060.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
lcdlib/textures/font_default_0061.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
lcdlib/textures/font_default_0062.png
Normal file
After Width: | Height: | Size: 307 B |
BIN
lcdlib/textures/font_default_0063.png
Normal file
After Width: | Height: | Size: 307 B |
BIN
lcdlib/textures/font_default_0064.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0065.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
lcdlib/textures/font_default_0066.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_0067.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0068.png
Normal file
After Width: | Height: | Size: 305 B |
BIN
lcdlib/textures/font_default_0069.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
lcdlib/textures/font_default_006a.png
Normal file
After Width: | Height: | Size: 293 B |
BIN
lcdlib/textures/font_default_006b.png
Normal file
After Width: | Height: | Size: 311 B |
BIN
lcdlib/textures/font_default_006c.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
lcdlib/textures/font_default_006d.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_006e.png
Normal file
After Width: | Height: | Size: 308 B |
BIN
lcdlib/textures/font_default_006f.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
lcdlib/textures/font_default_0070.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
lcdlib/textures/font_default_0071.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
lcdlib/textures/font_default_0072.png
Normal file
After Width: | Height: | Size: 303 B |
BIN
lcdlib/textures/font_default_0073.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_0074.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
lcdlib/textures/font_default_0075.png
Normal file
After Width: | Height: | Size: 295 B |
BIN
lcdlib/textures/font_default_0076.png
Normal file
After Width: | Height: | Size: 300 B |
BIN
lcdlib/textures/font_default_0077.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
lcdlib/textures/font_default_0078.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
lcdlib/textures/font_default_0079.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
lcdlib/textures/font_default_007a.png
Normal file
After Width: | Height: | Size: 296 B |
BIN
lcdlib/textures/font_default_007b.png
Normal file
After Width: | Height: | Size: 297 B |