summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE24
-rw-r--r--depends.txt1
-rw-r--r--init.lua91
-rw-r--r--textures/sdl_display_sides.pngbin0 -> 168 bytes
4 files changed, 116 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..da1d119
--- /dev/null
+++ b/depends.txt
@@ -0,0 +1 @@
+digilines
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..338800f
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,91 @@
+local sdl = require("SDL")
+sdl.init({sdl.flags.video})
+local windows = {}
+local renderers = {}
+
+local function drawrect(renderer,x,y,color,scale)
+ x = x - 1
+ y = y - 1
+ local rect = {x=x*scale,y=y*scale,w=scale,h=scale}
+ if string.sub(color,1,1) == "#" then color = string.sub(color,2,-1) end
+ renderer:setDrawColor(tonumber(color,16))
+ renderer:fillRect(rect)
+end
+
+minetest.register_node("sdl_display:display",{
+ description = "SDL Display",
+ groups = {dig_immediate=2},
+ tiles = {"sdl_display_sides.png"},
+ digiline =
+ {
+ receptor = {},
+ effector = {
+ action = function(pos,node,channel,msg)
+ local meta = minetest.get_meta(pos)
+ if (not msg) or channel ~= meta:get_string("channel") then
+ return
+ end
+ local w = meta:get_int("width")
+ local h = meta:get_int("height")
+ local scale = meta:get_int("scale")
+ local hash = minetest.hash_node_position(pos)
+ if not windows[hash] then
+ windows[hash] = sdl.createWindow({
+ title = meta:get_string("windowtitle"),
+ width = w*scale,
+ height = h*scale,
+ })
+ renderers[hash] = sdl.createRenderer(windows[hash],0,0)
+ end
+ renderers[hash]:clear()
+ for y=1,h,1 do
+ if type(msg[y]) == "table" then
+ for x=1,w,1 do
+ if type(msg[y][x]) =="string" and string.len(msg[y][x]) >= 6 then
+ drawrect(renderers[hash],x,y,msg[y][x],scale)
+ end
+ end
+ end
+ end
+ renderers[hash]:present()
+ end,
+ },
+ },
+ on_destruct = function(pos)
+ local hash = minetest.hash_node_position(pos)
+ if windows[hash] then windows[hash]:hide() end
+ windows[hash] = nil
+ renderers[hash] = nil
+ end,
+ after_place_node = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("channel","display")
+ meta:set_int("width",10)
+ meta:set_int("height",10)
+ meta:set_string("windowtitle","Display")
+ meta:set_int("scale",40)
+ local fs = "size[3,6.5]"
+ fs = fs.."field[0,0.5;3,1;channel;Channel;${channel}]"
+ fs = fs.."field[0,1.5;3,1;title;Window Title;${windowtitle}]"
+ fs = fs.."field[0,2.5;3,1;width;Width;${width}]"
+ fs = fs.."field[0,3.5;3,1;height;Height;${height}]"
+ fs = fs.."field[0,4.5;3,1;scale;Scale;${scale}]"
+ fs = fs.."button[0,5.5;3,1;save;Save]"
+ meta:set_string("formspec",fs)
+ meta:set_string("infotext","SDL Display (\"Display\")")
+ end,
+ on_receive_fields = function(pos,_,fields)
+ if not fields.save then return end
+ local meta = minetest.get_meta(pos)
+ meta:set_string("channel",fields.channel)
+ meta:set_string("windowtitle",fields.title)
+ meta:set_int("width",fields.width)
+ meta:set_int("height",fields.height)
+ meta:set_int("scale",fields.scale)
+ meta:set_string("infotext",string.format("SDL Display (\"%s\")",fields.title))
+ local hash = minetest.hash_node_position(pos)
+ if windows[hash] then windows[hash]:hide() end
+ windows[hash] = nil
+ renderers[hash] = nil
+ end,
+})
diff --git a/textures/sdl_display_sides.png b/textures/sdl_display_sides.png
new file mode 100644
index 0000000..1adb34f
--- /dev/null
+++ b/textures/sdl_display_sides.png
Binary files differ