summaryrefslogtreecommitdiff
path: root/dalos.lua
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-15 18:29:12 -0800
committerPixel <pixel@nobis-crew.org>2009-12-15 18:29:12 -0800
commite977437210d18847a404d68dc495dc8f45ecc46a (patch)
tree00322b452fe87fc990dd1e72ff187315ca6e592c /dalos.lua
parent5a1ff8177da1cba4eccc006ffb8c3ba78065ef97 (diff)
Almost there with a working simple hexviewer.
Diffstat (limited to 'dalos.lua')
-rw-r--r--dalos.lua73
1 files changed, 62 insertions, 11 deletions
diff --git a/dalos.lua b/dalos.lua
index cd2c849..237252c 100644
--- a/dalos.lua
+++ b/dalos.lua
@@ -33,12 +33,8 @@ dalosp.canvas = {
v.obj:draw(cvdb, self.origin.x + v.x, self.origin.y + v.y, v.w, v.h)
for oi = 1, v.obj.noutputs do
local dest = v.obj.outputs[oi]
- if dest then
- for ii = 1, dest.obj.ninputs do
- if dest.obj.inputs[ii] == v then
- self:drawlink(v, dest, oi, ii)
- end
- end
+ if dest and dest.obj then
+ self:drawlink(v, dest.obj, oi, dest.ind)
end
end
end
@@ -148,8 +144,18 @@ dalosp.canvas = {
end,
createlink = function (self, src, dst)
- src.obj.outputs[src.obj.curoutput + 0] = dst
- dst.obj.inputs[dst.obj.curinput + 0] = src
+ local oldsrc = src.obj.outputs[src.obj.curoutput]
+ local olddst = dst.obj.inputs[dst.obj.curinput]
+ if oldsrc then
+ oldsrc.obj.obj.inputs[oldsrc.ind] = nil
+ oldsrc.obj.obj:input_change(oldsrc.ind)
+ end
+ if olddst then
+ olddst.obj.obj.outputs[olddst.ind] = nil
+ end
+ src.obj.outputs[src.obj.curoutput] = { obj = dst, ind = dst.obj.curinput }
+ dst.obj.inputs[dst.obj.curinput] = { obj = src, ind = src.obj.curoutput }
+ dst.obj:input_change(dst.obj.curinput)
end,
button_cb = function (self, button, pressed, x, y, status)
@@ -347,6 +353,18 @@ dalosp.object = {
default_change_quicksetting = function (self, delta)
end,
+ default_getoutput = function (self, ind)
+ return self.houtputs[ind]
+ end,
+
+ default_inputchange = function (self, ind)
+ end,
+
+ set_houtput = function (self, h, ind)
+ if not ind then ind = 1 end
+ self.houtputs[ind] = h
+ end,
+
create = function (dcanvas, tab, extra)
if not tab then tab = {} end
local obj = {
@@ -359,7 +377,7 @@ dalosp.object = {
outputs = {},
curinput = 1,
curoutput = 1,
- quicksetting = nil,
+ quicksetting = tab.quicksetting,
otype = tab.otype or dalos.objtype.DUMMY,
activate = tab.activate or dalosp.object.default_activate,
configure = tab.configure or dalosp.object.default_configure,
@@ -367,6 +385,11 @@ dalosp.object = {
change_curoutput = dalosp.object.change_curoutput,
change_quicksetting = tab.change_quicksetting or dalosp.object.default_change_quicksetting,
extra = extra,
+ get_output = tab.getoutput or dalosp.object.default_getoutput,
+ input_change = tab.input_change or dalosp.object.default_inputchange,
+ set_houtput = dalosp.object.set_houtput,
+ get_outputx = nil,
+ houtputs = {},
}
if tab.otype and not tab.c then
@@ -374,6 +397,8 @@ dalosp.object = {
obj.color = cd.GRAY
elseif tab.otype == dalos.objtype.HANDLE then
obj.color = cd.CYAN
+ elseif tab.otype == dalos.objtype.LUA_VIEWER then
+ obj.color = cd.MAGENTA
elseif tab.otype == dalos.objtype.LUA_FILTER then
obj.color = cd.YELLOW
else
@@ -382,6 +407,8 @@ dalosp.object = {
end
dcanvas:addobj(obj, tab.x or 0, tab.y or 0, tab.w or 50, tab.h or 50)
+
+ return obj
end,
}
@@ -394,14 +421,38 @@ dalos.objtype = {
DUMMY = 1,
HANDLE = 2,
LUA_FILTER = 3,
+ LUA_VIEWER = 4,
}
----------------
d = dalos.canvas {}
m = dalos.menu {}
-o = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "An output" })
-o2 = dalos.object(d, { y = 30, x = 100, ninputs = 1, name = "An input" })
+
+b1 = Buffer(true)
+b1:write("Buffer 1 contents")
+b2 = Buffer(true)
+b2:write("Buffer 2 contents")
+
+function activate_hv(self)
+ self.extra.hvdlg:show()
+end
+
+function input_change_hv(self, ind)
+ self.extra.hv:updatehandle(self.inputs[ind].obj.obj:getoutput(self.inputs[ind].ind))
+end
+
+extra = {
+ hv = iupe.hexview { },
+ hvdlg = iup.dialog { iup.hbox{ iup.frame { hv }, iup.sbox { direction = "WEST", iupe.hexview_toolbox { hexview = hv, }, }, }, title = "Hexview" }
+}
+
+o1 = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "Buffer 1", otype = dalos.objtype.HANDLE })
+o2 = dalos.object(d, { y = 30, x = 90, noutputs = 1, name = "Buffer 2", otype = dalos.objtype.HANDLE })
+h = dalos.object(d, { y = 120, x = 50, ninputs = 1, name = "Hexview", otype = dalos.objtype.LUA_VIEWER, activate = activate_hv, input_change = input_change_hv }, extra)
+
+o1:set_houtput(b1)
+o2:set_houtput(b2)
dlg = iup.dialog { d, title = "Dalos", menu = m }