summaryrefslogtreecommitdiff
path: root/dalos.lua
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-26 20:15:19 +0100
committerPixel <pixel@nobis-crew.org>2009-12-26 20:15:19 +0100
commitef0404604e36a45ea950439c2396eb0ea3b5bdf9 (patch)
treec272438ed960ab16ffe3fb521ab88675668d4d4f /dalos.lua
parent1325aa091d6061913969d6e45775cf5d032c833b (diff)
Template system rework.
Diffstat (limited to 'dalos.lua')
-rw-r--r--dalos.lua51
1 files changed, 49 insertions, 2 deletions
diff --git a/dalos.lua b/dalos.lua
index c13ffd3..047a54f 100644
--- a/dalos.lua
+++ b/dalos.lua
@@ -35,11 +35,11 @@ dalosp.cross = { }
dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" }
dalos.version.string = dalos.version.MAJOR .. "." .. dalos.version.MINOR .. dalos.version.suffix
-function dalos:register_obj(name, constructor, category)
+function dalos:register_obj(name, constructor, category, registertemplate)
if self.objectstypes_by_name[name] then
error("An object type of that name already exists: " .. name)
end
- table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category })
+ table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category, registertemplate = registertemplate })
self.objectstypes_by_name[name] = #self.objectstypes
if self.active_menu then
self.active_menu:update_objects()
@@ -672,6 +672,7 @@ dalosp.menu = {
tobj = dalos.objectstypes[tobj]
dalos:register_obj(otype .. "::" .. tname, function(d, tab) tobj.constructor(d, tab, data) end, "Template")
+ if tobj.registertemplate then tobj.registertemplate(data, tname) end
local d = dalos.active_canvas
d:setstatus(dalos.stypes.INFO, "Template properly loaded")
@@ -816,6 +817,50 @@ dalosp.menu = {
}
dalosp.object = {
+ use_template = function (self)
+ local templates = dalosp.luafilter.templates
+ local ttpllst = {}
+ for n, v in pairs(templates) do
+ table.insert(ttpllst, n)
+ end
+ if #ttpllst == 0 then
+ local dlg = iup.messagedlg {
+ dialogtype = "Warning",
+ title = "No template",
+ value = "There's no template to use.\nPlease load templates from the main menu first.",
+ }
+ dlg:popup()
+ return iup.DEFAULT
+ end
+ table.sort(ttpllst)
+ local tpllst = "|"
+ for i, n in ipairs(ttpllst) do
+ tpllst = tpllst .. n .. "|"
+ end
+ local s, tind = iup.GetParam("Use Template", nil, "Template: %i" .. tpllst .. "\n", 0)
+ if not s then return iup.DEFAULT end
+ self:apply_template(dalosp.luafilter.templates[ttpllst[tind]])
+ end,
+
+ load_template = function (self)
+ local dlg = iup.filedlg {
+ dialogtype = "Open",
+ filter = "*.dtpl",
+ }
+ iup.Popup(dlg)
+ if (dlg.status + 0) == -1 then return end
+
+ local s, v = pcall(Input, dlg.value)
+ if not s then error("Problem loading file " .. dlg.value) end
+ local f = preload(v)
+ v:destroy()
+ if not f then error("Syntax error loading file " .. dlg.value) end
+ local data, otype, tname = f()
+ if otype ~= self.ntype then error("Wrong template type: " .. otype) end
+
+ self:apply_template(data.template)
+ end,
+
default_draw = function (self, cv, x, y, w, h)
local x1, x2, y1, y2 = x, x + w, y, y + h
y1, y2 = cv:InvertYAxis(y2), cv:InvertYAxis(y1)
@@ -955,6 +1000,8 @@ dalosp.object = {
houtputs = {},
get_linked_input = dalosp.object.get_linked_input,
save_template = dalosp.object.save_template,
+ load_template = dalosp.object.load_template,
+ use_template = dalosp.object.use_template,
dcanvas = dcanvas,
}