From ed1edc28c6ff280976e3ca07ed1dae6c20b5001c Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 17 Dec 2009 23:43:10 -0800 Subject: Fixing panning. --- dalos.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dalos.lua b/dalos.lua index 3400aaa..0747073 100644 --- a/dalos.lua +++ b/dalos.lua @@ -253,10 +253,10 @@ dalosp.canvas = { self.stateful.leftclk = obj table.remove(self.objects, ind) table.insert(self.objects, obj) - self.ox, self.oy = x, y - self.bx, self.by = x, y - self:draw() end + self.ox, self.oy = x, y + self.bx, self.by = x, y + self:draw() end else if not self.stateful.linking and self.stateful.leftclk and not self.stateful.dragging then @@ -294,10 +294,10 @@ dalosp.canvas = { self.stateful.rghtclk = obj table.remove(self.objects, ind) table.insert(self.objects, obj) - self.ox, self.oy = x, y - self.bx, self.by = x, y - self:draw() end + self.ox, self.oy = x, y + self.bx, self.by = x, y + self:draw() end else if not self.stateful.moving and self.stateful.rghtclk and not self.stateful.dragging then -- cgit v1.2.3 From 4456d2f6ca62fe69e058dd3f5bc4c1b087afc9a1 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 18 Dec 2009 07:49:16 -0800 Subject: Adding fast dummy support for the X-menu text. --- dalos.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dalos.lua b/dalos.lua index 0747073..b3b4ed3 100644 --- a/dalos.lua +++ b/dalos.lua @@ -85,6 +85,22 @@ dalosp.canvas = { cv:Line(x1, iy(y1), x2, iy(y1)) cv:Line(x1 + 1, iy(y1 + 1), x2 - 1, iy(y1 + 1)) cv:Line(x1 + 2, iy(y1 + 2), x2 - 2, iy(y1 + 2)) + + local f, st, si = cv:GetFont() + cv:Font("Helvetica", cd.PLAIN, 10) + + cv:Foreground(cd.BLACK) + cv:TextOrientation(0) + cv:TextAlignment(cd.NORTH) + cv:Text(x, iy(y1 + 3), "North") + cv:TextAlignment(cd.SOUTH) + cv:Text(x, iy(y2 - 3), "South") + cv:TextOrientation(270) + cv:Text(x1 + 3, iy(y), "West") + cv:TextOrientation(90) + cv:Text(x2 - 3, iy(y), "East") + + cv:Font(f, st, si) end, draw = function (self) @@ -740,8 +756,8 @@ b2:write("Buffer 2 contents") o1 = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "Buffer 1", otype = dalos.objtype.HANDLE }) o2 = dalos.object(d, { y = 120, x = 10, noutputs = 1, name = "Buffer 2", otype = dalos.objtype.HANDLE }) -h1 = dalos.hexview(d, { y = 60, x = 100, name = "Hexview 1" }) -h2 = dalos.hexview(d, { y = 60, x = 200, name = "Hexview 2" }) +--h1 = dalos.hexview(d, { y = 60, x = 100, name = "Hexview 1" }) +--h2 = dalos.hexview(d, { y = 60, x = 200, name = "Hexview 2" }) o1:set_houtput(b1) o2:set_houtput(b2) -- cgit v1.2.3 From 442c3b3ce4c431f2a9760000f56c86f239728225 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 16:44:45 -0800 Subject: All menus should be working now. --- dalos.lua | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 17 deletions(-) diff --git a/dalos.lua b/dalos.lua index b3b4ed3..d4cb5ad 100644 --- a/dalos.lua +++ b/dalos.lua @@ -10,9 +10,20 @@ load "iupe-tview.lua" if not dalosp then dalosp = {} end if not dalos then dalos = {} end dalos.objects = {} +dalos.objects_by_name = {} + +dalosp.NORTH = 1 +dalosp.SOUTH = 2 +dalosp.WEST = 3 +dalosp.EAST = 4 +dalosp.cross = { } function dalos:register_obj(name, constructor) - table.insert(self.objects, { name = name, constructor = constructor }) + if self.objects_by_name[name] then + error("An object of that name already exists: " .. name) + end + table.insert(self.objects, { name = name, constructor = constructor, counter = 1 }) + self.objects_by_name[name] = #self.objects if self.activemenu then self.activemenu:update_objects() end @@ -91,14 +102,24 @@ dalosp.canvas = { cv:Foreground(cd.BLACK) cv:TextOrientation(0) - cv:TextAlignment(cd.NORTH) - cv:Text(x, iy(y1 + 3), "North") - cv:TextAlignment(cd.SOUTH) - cv:Text(x, iy(y2 - 3), "South") - cv:TextOrientation(270) - cv:Text(x1 + 3, iy(y), "West") - cv:TextOrientation(90) - cv:Text(x2 - 3, iy(y), "East") + if dalosp.cross.north then + cv:TextAlignment(cd.NORTH) + cv:Text(x, iy(y1 + 3), dalosp.cross.north.name) + end + if dalosp.cross.south then + cv:TextAlignment(cd.SOUTH) + cv:Text(x, iy(y2 - 3), dalosp.cross.south.name) + end + if dalosp.cross.west then + cv:TextAlignment(cd.SOUTH) + cv:TextOrientation(270) + cv:Text(x1 + 3, iy(y), dalosp.cross.west.name) + end + if dalosp.cross.east then + cv:TextAlignment(cd.SOUTH) + cv:TextOrientation(90) + cv:Text(x2 - 3, iy(y), dalosp.cross.east.name) + end cv:Font(f, st, si) end, @@ -320,7 +341,22 @@ dalosp.canvas = { self.stateful.rghtclk.obj:configure() self:draw() elseif self.menu.x then - -- activate X menu operation + local dx, dy = x - self.menu.x, y - self.menu.y + local obj + if math.abs(dx) > math.abs(dy) then + if dx < 0 then + obj = dalosp.cross.west + else + obj = dalosp.cross.east + end + else + if dy < 0 then + obj = dalosp.cross.north + else + obj = dalosp.cross.south + end + end + if obj then dalosp.menu.add_object(self, obj) end self.menu.x = nil self.menu.y = nil self:draw() @@ -415,7 +451,24 @@ dalosp.menu = { end end, - create = function (tab) + add_object = function (canvas, object) + object.constructor(canvas, { counter = object.counter, x = 25, y = 25 }) + object.counter = object.counter + 1 + end, + + set_cross = function (canvas, object, dir) + if dir == dalosp.NORTH then + dalosp.cross.north = object + elseif dir == dalosp.SOUTH then + dalosp.cross.south = object + elseif dir == dalosp.EAST then + dalosp.cross.east = object + elseif dir == dalosp.WEST then + dalosp.cross.west = object + end + end, + + create = function (canvas, tab) local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } @@ -429,14 +482,19 @@ dalosp.menu = { local item for k, v in ipairs(dalos.objects) do item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.add_object(canvas, v) end table.insert(add_menu, item) item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end table.insert(north_menu, item) item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end table.insert(east_menu, item) item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end table.insert(west_menu, item) item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end table.insert(south_menu, item) end end @@ -539,6 +597,12 @@ dalosp.object = { create = function (dcanvas, tab, extra) if not tab then tab = {} end + if not tab.name then + tab.name = tab.default_name + if tab.counter then + tab.name = tab.name .. " " .. tab.counter + end + end local obj = { draw = dalosp.object.default_draw, name = tab.name or "NoName", @@ -716,7 +780,6 @@ dalosp.hexview = { end, create = function (d, tab) - if not tab.name then tab.name = "Hexview" end tab.otype = dalos.objtype.LUA_FILTER tab.activate = dalosp.hexview.activate tab.input_change = dalosp.hexview.input_change @@ -724,12 +787,20 @@ dalosp.hexview = { tab.configure = dalosp.hexview.configure tab.ninputs = 1 tab.noutputs = 12 + tab.default_name = "Hexview" + + local extra = { } + local obj = dalos.object(d, tab, extra) + local hv = iupe.hexview { } local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = tab.name } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name } + + extra.hv = hv + extra.hvtb = hvtb + extra.hvdlg = hvdlg - local obj = dalos.object(d, tab, { hv = hv, hvtb = hvtb, hvdlg = hvdlg }) obj.oldcursors = { } obj.watchees = { } obj.update_houtput = dalosp.hexview.update_houtput @@ -747,7 +818,7 @@ dalos:register_obj("Hexview", dalos.hexview) ---------------- d = dalos.canvas {} -m = dalos.menu {} +m = dalos.menu(d) b1 = Buffer(true) b1:write("Buffer 1 contents") @@ -756,8 +827,6 @@ b2:write("Buffer 2 contents") o1 = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "Buffer 1", otype = dalos.objtype.HANDLE }) o2 = dalos.object(d, { y = 120, x = 10, noutputs = 1, name = "Buffer 2", otype = dalos.objtype.HANDLE }) ---h1 = dalos.hexview(d, { y = 60, x = 100, name = "Hexview 1" }) ---h2 = dalos.hexview(d, { y = 60, x = 200, name = "Hexview 2" }) o1:set_houtput(b1) o2:set_houtput(b2) -- cgit v1.2.3 From b95784072d8e65763785fbbb5fff2df308e37708 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 16:49:01 -0800 Subject: Actually spawning the objects added by the cross menu where the cross menu is. --- dalos.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dalos.lua b/dalos.lua index d4cb5ad..ff55f20 100644 --- a/dalos.lua +++ b/dalos.lua @@ -356,7 +356,7 @@ dalosp.canvas = { obj = dalosp.cross.south end end - if obj then dalosp.menu.add_object(self, obj) end + if obj then dalosp.menu.add_object(self, obj, self.menu.x, self.menu.y) end self.menu.x = nil self.menu.y = nil self:draw() @@ -451,8 +451,8 @@ dalosp.menu = { end end, - add_object = function (canvas, object) - object.constructor(canvas, { counter = object.counter, x = 25, y = 25 }) + add_object = function (canvas, object, x, y) + object.constructor(canvas, { counter = object.counter, x = (x or 25) + 0, y = (y or 25) + 0}) object.counter = object.counter + 1 end, -- cgit v1.2.3 From 41b76a159954d1f47eb4937ded57c58cb3522f96 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 16:53:45 -0800 Subject: Splitting dalos's hexviewer out, in a separate file. --- dalos-hexview.lua | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 153 +----------------------------------------------------- 2 files changed, 154 insertions(+), 152 deletions(-) create mode 100644 dalos-hexview.lua diff --git a/dalos-hexview.lua b/dalos-hexview.lua new file mode 100644 index 0000000..7e46ed6 --- /dev/null +++ b/dalos-hexview.lua @@ -0,0 +1,153 @@ +load "iupe-hexview.lua" +load "iupe-hexview-toolbox.lua" + +dalosp.hexview = { + activate = function (self) + self.extra.hvdlg:show() + end, + + input_change = function (self, ind) + local extra = self.extra + local hv = extra.hv + local h = self:get_linked_input(ind) + if not h then + self.color = cd.YELLOW + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + if not h:canread() or not h:canseek() then + self.color = cd.RED + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + self.color = cd.GREEN + for i = 1, 12 do + self:set_houtput(nil, i) + self.oldcursors[i] = -1 + end + hv:updatehandle(h) + self.dcanvas:draw() + end, + + configure = function (self) + end, + + output_change = function (self, ind) + self.watchees[ind] = self.outputs[ind] and true or false + end, + + update_houtput = function (self, ind, cursor) + local h = self:get_linked_input(1) + if h and self.watchees[ind] then + local obj = { + h = h, + hvo = self, + ind = ind, + origin = cursor, + offset = 0, + size = h:getsize() - cursor, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return self.h:canwatch() end, + getname = function (self) return self.hvo.name .. ":" .. self.ind end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return self.hvo:getmodif() end, + flush = function (self) return self.hvo:flush() end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + self.h:seek(self.offset + self.origin) + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r = self.h:read(count, userdata) + self.offset = self.offset + r + if r == 0 then self.got_eof = true end + return r + end, + } + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh, ind) + end + end, + + dalos_hv_cb = function (self, hv, reset) + local m + for i = 1, 10 do + m = hv.markers[i] + if self.oldcursors[i] ~= m then + self:update_houtput(i, m) + self.oldcursors[i] = m + end + end + + m = hv.kcursor + if self.oldcursors[11] ~= m then + self:update_houtput(11, m) + self.oldcursors[11] = m + end + + m = hv.mcursor + if self.oldcursors[12] ~= m then + self:update_houtput(12, m) + self.oldcursors[12] = m + end + end, + + create = function (d, tab) + tab.otype = dalos.objtype.LUA_FILTER + tab.activate = dalosp.hexview.activate + tab.input_change = dalosp.hexview.input_change + tab.output_change = dalosp.hexview.output_change + tab.configure = dalosp.hexview.configure + tab.ninputs = 1 + tab.noutputs = 12 + tab.default_name = "Hexview" + + local extra = { } + + local obj = dalos.object(d, tab, extra) + + local hv = iupe.hexview { } + local hvtb = iupe.hexview_toolbox { hexview = hv } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name } + + extra.hv = hv + extra.hvtb = hvtb + extra.hvdlg = hvdlg + + obj.oldcursors = { } + obj.watchees = { } + obj.update_houtput = dalosp.hexview.update_houtput + for i = 1, 12 do obj.oldcursors[i] = -1 end + + hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + + return obj + end, +} + +dalos.hexview = dalosp.hexview.create +dalos:register_obj("Hexview", dalos.hexview) diff --git a/dalos.lua b/dalos.lua index ff55f20..fe94973 100644 --- a/dalos.lua +++ b/dalos.lua @@ -3,8 +3,6 @@ loadmodule "luahandle" loadmodule "lualibs" load "iupe-dbuffer.lua" -load "iupe-hexview.lua" -load "iupe-hexview-toolbox.lua" load "iupe-tview.lua" if not dalosp then dalosp = {} end @@ -664,156 +662,7 @@ dalos.objtype = { ---------------- -dalosp.hexview = { - activate = function (self) - self.extra.hvdlg:show() - end, - - input_change = function (self, ind) - local extra = self.extra - local hv = extra.hv - local h = self:get_linked_input(ind) - if not h then - self.color = cd.YELLOW - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - if not h:canread() or not h:canseek() then - self.color = cd.RED - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - self.color = cd.GREEN - for i = 1, 12 do - self:set_houtput(nil, i) - self.oldcursors[i] = -1 - end - hv:updatehandle(h) - self.dcanvas:draw() - end, - - configure = function (self) - end, - - output_change = function (self, ind) - self.watchees[ind] = self.outputs[ind] and true or false - end, - - update_houtput = function (self, ind, cursor) - local h = self:get_linked_input(1) - if h and self.watchees[ind] then - local obj = { - h = h, - hvo = self, - ind = ind, - origin = cursor, - offset = 0, - size = h:getsize() - cursor, - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return self.h:canwatch() end, - getname = function (self) return self.hvo.name .. ":" .. self.ind end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, - getmodif = function (self) return self.hvo:getmodif() end, - flush = function (self) return self.hvo:flush() end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - self.h:seek(self.offset + self.origin) - return self.offset - end, - read = function (self, userdata, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - - local r = self.h:read(count, userdata) - self.offset = self.offset + r - if r == 0 then self.got_eof = true end - return r - end, - } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh, ind) - end - end, - - dalos_hv_cb = function (self, hv, reset) - local m - for i = 1, 10 do - m = hv.markers[i] - if self.oldcursors[i] ~= m then - self:update_houtput(i, m) - self.oldcursors[i] = m - end - end - - m = hv.kcursor - if self.oldcursors[11] ~= m then - self:update_houtput(11, m) - self.oldcursors[11] = m - end - - m = hv.mcursor - if self.oldcursors[12] ~= m then - self:update_houtput(12, m) - self.oldcursors[12] = m - end - end, - - create = function (d, tab) - tab.otype = dalos.objtype.LUA_FILTER - tab.activate = dalosp.hexview.activate - tab.input_change = dalosp.hexview.input_change - tab.output_change = dalosp.hexview.output_change - tab.configure = dalosp.hexview.configure - tab.ninputs = 1 - tab.noutputs = 12 - tab.default_name = "Hexview" - - local extra = { } - - local obj = dalos.object(d, tab, extra) - - local hv = iupe.hexview { } - local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name } - - extra.hv = hv - extra.hvtb = hvtb - extra.hvdlg = hvdlg - - obj.oldcursors = { } - obj.watchees = { } - obj.update_houtput = dalosp.hexview.update_houtput - for i = 1, 12 do obj.oldcursors[i] = -1 end - - hv:registercb(dalosp.hexview.dalos_hv_cb, obj) - - return obj - end, -} - -dalos.hexview = dalosp.hexview.create -dalos:register_obj("Hexview", dalos.hexview) +load "dalos-hexview.lua" ---------------- -- cgit v1.2.3 From 9ce69b6bc34655e437feccd89354730c91e5677b Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 17:44:13 -0800 Subject: Adding a first stub for binary ops, and fixing hexviewer's ability to destroy its input when going too far in the file. --- dalos-binaryops.lua | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos-hexview.lua | 2 + dalos.lua | 1 + 3 files changed, 130 insertions(+) create mode 100644 dalos-binaryops.lua diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua new file mode 100644 index 0000000..db6a39e --- /dev/null +++ b/dalos-binaryops.lua @@ -0,0 +1,127 @@ +-- bit.tobit bit.tohex bit.bnot bit.band bit.bor bit.bxor +-- bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap + +dalosp.binaryops = { + operations = { + XOR = 1, + AND = 2, + OR = 3, + ADD = 4, + SUB = 5, + }, + + opnames = { + "xor", + "and", + "or", + "add", + "sub", + }, + + configure = function (self) +-- local accept = iup.GetParam + end, + + input_change = function (self, ind) + local h1 = self:get_linked_input(1) + local h2 = self:get_linked_input(1) + local op = self.extra.op or dalosp.binaryops.XOR + if h1 and h2 then + local obj = { + h1 = h1, + h2 = h2, + op = op, + maximize = self.extra.maximize, + offset = 0, + size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + getname = function (self) return end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + return self.offset + end, + read = function (self, dummy, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + self.h1:seek(self.offset) + self.h2:seek(self.offset) + +---- maximizing work to do here... + local r1, t1 = self.h1:read(count) + local r2, t2 = self.h2:read(count) + local r = math.min(r1, r2) + self.offset = self.offset + r + if r == 0 then self.got_eof = true return 0 end + local t = {} + local op + if self.op == dalosp.binaryops.operations.XOR then + op = bit.bxor + elseif self.op == dalosp.binaryops.operations.AND then + op = bit.band + elseif self.op == dalosp.binaryops.operations.OR then + op = bit.bor + elseif self.op == dalosp.binaryops.operations.ADD then + op = function(a, b) return a + b end + elseif self.op == dalosp.binaryops.operations.SUB then + op = function(a, b) return a - b end + end + for i = 0, r - 1 do + t[i] = bit.band(op(t1[i], t2[i]), 255) + end + return r, t + end, + } + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh) + else + self:set_houtput(nil) + end + end, + + draw = function (self, cv, x, y, w, h) + dalosp.object.default_draw(self, cv, x, y, w, h) + -- add status display + end, + + create = function (d, tab) + tab.ninputs = 2 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.binaryops.configure + tab.input_change = dalosp.binaryops.input_change + tab.default_name = "Binary Ops" + tab.draw = dalosp.binaryops.draw + local extra = { } + + local obj = dalos.object(d, tab, extra) + end, +} + +dalos.binaryops = dalosp.binaryops.create +dalos:register_obj("Binary Ops", dalos.binaryops) \ No newline at end of file diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 7e46ed6..b085f12 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -67,6 +67,8 @@ dalosp.hexview = { else error "Unknown wheel" end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end self.h:seek(self.offset + self.origin) return self.offset end, diff --git a/dalos.lua b/dalos.lua index fe94973..d5dfe85 100644 --- a/dalos.lua +++ b/dalos.lua @@ -663,6 +663,7 @@ dalos.objtype = { ---------------- load "dalos-hexview.lua" +load "dalos-binaryops.lua" ---------------- -- cgit v1.2.3 From de77b17f6a1ec46f9e9386e604d138152108e708 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:44:37 -0800 Subject: Fixing "getting out of focus" double clic. Properly allowing objects to overload their :draw method. --- dalos.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dalos.lua b/dalos.lua index d5dfe85..4e61c2e 100644 --- a/dalos.lua +++ b/dalos.lua @@ -187,7 +187,7 @@ dalosp.canvas = { end, focus_cb = function (self, focus) - if focus == 0 then self:button_cb() end + if focus == 0 and not self.stateful.rghtbutton and not self.stateful.leftbutton then self:button_cb() end end, stypes = { @@ -602,7 +602,7 @@ dalosp.object = { end end local obj = { - draw = dalosp.object.default_draw, + draw = tab.draw or dalosp.object.default_draw, name = tab.name or "NoName", color = tab.color or cd.GRAY, ninputs = tab.ninputs or 0, -- cgit v1.2.3 From 7f80551cc6dc74fe6cc2af1b6b107fc88d9ab5dc Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:45:08 -0800 Subject: Disabling hexview's output if cursor is past filesize. --- dalos-hexview.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index b085f12..f14e1e0 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -40,14 +40,18 @@ dalosp.hexview = { update_houtput = function (self, ind, cursor) local h = self:get_linked_input(1) + local maxsixe = h:getsize() if h and self.watchees[ind] then + if cursor < maxsize then + self:set_houtput(nil, ind) + end local obj = { h = h, hvo = self, ind = ind, origin = cursor, offset = 0, - size = h:getsize() - cursor, + size = maxsize - cursor, canread = function (self) return true end, canwrite = function (self) return false end, canseek = function (self) return true end, -- cgit v1.2.3 From 0a81101b5d00d5a12d105454a0941edc4b2da32b Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:45:27 -0800 Subject: The binaryops should be working now. Should. --- dalos-binaryops.lua | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index db6a39e..f128ab0 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -3,30 +3,38 @@ dalosp.binaryops = { operations = { - XOR = 1, - AND = 2, - OR = 3, - ADD = 4, - SUB = 5, + XOR = 0, + AND = 1, + OR = 2, + ADD = 3, + SUB = 4, }, opnames = { - "xor", - "and", - "or", - "add", - "sub", + [0] = "XOR", + [1] = "AND", + [2] = "OR", + [3] = "ADD", + [4] = "SUB", }, configure = function (self) --- local accept = iup.GetParam + local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[ +Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} +Maximize: %b[No,Yes]{Check if you want to maximize the output} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.op = operation + self.maximize = maximize == 1 + end end, input_change = function (self, ind) local h1 = self:get_linked_input(1) local h2 = self:get_linked_input(1) - local op = self.extra.op or dalosp.binaryops.XOR + local op = self.extra.op or dalosp.binaryops.operations.XOR if h1 and h2 then + self.color = cd.GREEN local obj = { h1 = h1, h2 = h2, @@ -71,10 +79,9 @@ dalosp.binaryops = { self.h1:seek(self.offset) self.h2:seek(self.offset) ----- maximizing work to do here... local r1, t1 = self.h1:read(count) local r2, t2 = self.h2:read(count) - local r = math.min(r1, r2) + local r = self.maximize and math.max(r1, r2) or math.min(r1, r2) self.offset = self.offset + r if r == 0 then self.got_eof = true return 0 end local t = {} @@ -91,7 +98,7 @@ dalosp.binaryops = { op = function(a, b) return a - b end end for i = 0, r - 1 do - t[i] = bit.band(op(t1[i], t2[i]), 255) + t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255) end return r, t end, @@ -100,13 +107,19 @@ dalosp.binaryops = { obj.lh = newh self:set_houtput(newh) else + self.color = cd.YELLOW self:set_houtput(nil) end end, draw = function (self, cv, x, y, w, h) dalosp.object.default_draw(self, cv, x, y, w, h) - -- add status display + local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) + local op = self.extra.op or dalosp.binaryops.operations.XOR + print(op) + cv:TextAlignment(cd.CENTER) + cv:Foreground(cd.BLACK) + cv:Text(cx, cy, dalosp.binaryops.opnames[op]) end, create = function (d, tab) -- cgit v1.2.3 From dcfd1cd1761b117007a931929956c54841e9904e Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:46:43 -0800 Subject: Disabling draw spam. Forcing a redraw when status changes. --- dalos-binaryops.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index f128ab0..886f153 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -106,9 +106,11 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} local newh = HandleLua(obj) obj.lh = newh self:set_houtput(newh) + self.dcanvas:draw() else self.color = cd.YELLOW self:set_houtput(nil) + self.dcanvas:draw() end end, @@ -116,7 +118,6 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} dalosp.object.default_draw(self, cv, x, y, w, h) local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) local op = self.extra.op or dalosp.binaryops.operations.XOR - print(op) cv:TextAlignment(cd.CENTER) cv:Foreground(cd.BLACK) cv:Text(cx, cy, dalosp.binaryops.opnames[op]) -- cgit v1.2.3 From 41ed35236818d3f08b468e30add7ccfd05cde2c5 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:47:31 -0800 Subject: Avoiding using twice the same input... --- dalos-binaryops.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 886f153..6949524 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -31,7 +31,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} input_change = function (self, ind) local h1 = self:get_linked_input(1) - local h2 = self:get_linked_input(1) + local h2 = self:get_linked_input(2) local op = self.extra.op or dalosp.binaryops.operations.XOR if h1 and h2 then self.color = cd.GREEN -- cgit v1.2.3 From af5acc8f85b110afdaf1ae4ddd63fd3a6c2bfef6 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:51:10 -0800 Subject: hexview shouldn't crash if it has no real input. --- dalos-hexview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index f14e1e0..8aa53bb 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -40,7 +40,7 @@ dalosp.hexview = { update_houtput = function (self, ind, cursor) local h = self:get_linked_input(1) - local maxsixe = h:getsize() + local maxsixe = h and h:getsize() or -1 if h and self.watchees[ind] then if cursor < maxsize then self:set_houtput(nil, ind) -- cgit v1.2.3 From 51ba447736a750739a168bc3fed480ff9304c8c0 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:55:51 -0800 Subject: Fixed binary ops by swapping its :read results, and forcing a recomputation if configuration occured. --- dalos-binaryops.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 6949524..cdc54e0 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -26,6 +26,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} if accept then self.op = operation self.maximize = maximize == 1 + self:input_change() end end, @@ -79,8 +80,8 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} self.h1:seek(self.offset) self.h2:seek(self.offset) - local r1, t1 = self.h1:read(count) - local r2, t2 = self.h2:read(count) + local t1, r1 = self.h1:read(count) + local t2, r2 = self.h2:read(count) local r = self.maximize and math.max(r1, r2) or math.min(r1, r2) self.offset = self.offset + r if r == 0 then self.got_eof = true return 0 end -- cgit v1.2.3 From 01cde00a913188efe5f17b0fa65556d29557a6de Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 20:58:26 -0800 Subject: Properly saving configuration in the extra array, and using it. --- dalos-binaryops.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index cdc54e0..91e1d04 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -24,8 +24,8 @@ Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} Maximize: %b[No,Yes]{Check if you want to maximize the output} ]], self.op or 0, self.maximize and 1 or 0) if accept then - self.op = operation - self.maximize = maximize == 1 + self.extra.op = operation + self.extra.maximize = maximize == 1 self:input_change() end end, @@ -82,7 +82,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} local t1, r1 = self.h1:read(count) local t2, r2 = self.h2:read(count) - local r = self.maximize and math.max(r1, r2) or math.min(r1, r2) + local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) self.offset = self.offset + r if r == 0 then self.got_eof = true return 0 end local t = {} -- cgit v1.2.3 From 25b0166dca330f1bce022e015e04965220ea0a01 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 21:05:48 -0800 Subject: Removing useless comment. --- dalos-binaryops.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 91e1d04..356a58b 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -1,6 +1,3 @@ --- bit.tobit bit.tohex bit.bnot bit.band bit.bor bit.bxor --- bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap - dalosp.binaryops = { operations = { XOR = 0, -- cgit v1.2.3 From 1eef19bf7577799096f9133f38e8a9c8f0d65248 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 21:08:42 -0800 Subject: Adding limiter. --- dalos-limiter.lua | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 87 insertions(+) create mode 100644 dalos-limiter.lua diff --git a/dalos-limiter.lua b/dalos-limiter.lua new file mode 100644 index 0000000..8f1a863 --- /dev/null +++ b/dalos-limiter.lua @@ -0,0 +1,86 @@ +dalosp.limiter = { + configure = function (self) + local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[ +Limit: %i{The actual size this limiter is going to produce} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.extra.limit = limit + self:input_change() + end + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local obj = { + h = h, + offset = 0, + size = math.max(h:getsize(), self.limit), + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + getname = function (self) return end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + self.h:seek(self.offset) + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r = self.h:read(count, userdata) + self.offset = self.offset + r + return r + end, + } + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + + create = function (d, tab) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.limiter.configure + tab.input_change = dalosp.limiter.input_change + tab.default_name = "Limiter" + local extra = { } + + local obj = dalos.object(d, tab, extra) + end, +} + +dalos.limiter = dalosp.limiter.create +dalos:register_obj("Limiter", dalos.limiter) diff --git a/dalos.lua b/dalos.lua index 4e61c2e..b0b9aee 100644 --- a/dalos.lua +++ b/dalos.lua @@ -664,6 +664,7 @@ dalos.objtype = { load "dalos-hexview.lua" load "dalos-binaryops.lua" +load "dalos-limiter.lua" ---------------- -- cgit v1.2.3 From cb7c8031ced6e9a393e8bdc3f409687741ef9feb Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 03:02:33 -0800 Subject: Factorizing some bits of code. --- dalos-binaryops.lua | 40 +++------------------------------------- dalos-hexview.lua | 43 ++++--------------------------------------- dalos-limiter.lua | 48 ++++++------------------------------------------ dalos-luahandle.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 5 +++-- 5 files changed, 67 insertions(+), 120 deletions(-) create mode 100644 dalos-luahandle.lua diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 356a58b..eda76e5 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -40,40 +40,8 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} maximize = self.extra.maximize, offset = 0, size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - getname = function (self) return end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, - getmodif = function (self) return 0 end, - flush = function (self) return true end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - if self.offset < 0 then self.offset = 0 end - if self.offset >= self.size then self.offset = self.size end - return self.offset - end, - read = function (self, dummy, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - + getname = function () return self.name end, + do_read = function (self, dummy, count) self.h1:seek(self.offset) self.h2:seek(self.offset) @@ -101,9 +69,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} return r, t end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh) + self:set_houtput(dalos.luahandle(obj)) self.dcanvas:draw() else self.color = cd.YELLOW diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 8aa53bb..381ffd4 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -50,52 +50,17 @@ dalosp.hexview = { hvo = self, ind = ind, origin = cursor, - offset = 0, size = maxsize - cursor, - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return self.h:canwatch() end, getname = function (self) return self.hvo.name .. ":" .. self.ind end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, getmodif = function (self) return self.hvo:getmodif() end, - flush = function (self) return self.hvo:flush() end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - if self.offset < 0 then self.offset = 0 end - if self.offset >= self.size then self.offset = self.size end + do_seek = function (self) self.h:seek(self.offset + self.origin) - return self.offset end, - read = function (self, userdata, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - - local r = self.h:read(count, userdata) - self.offset = self.offset + r - if r == 0 then self.got_eof = true end - return r + do_read = function (self, userdata, count) + return self.h:read(count, userdata) end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh, ind) + self:set_houtput(dalos.luahandle(obj), ind) end end, diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 8f1a863..b423d7a 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -15,51 +15,16 @@ Limit: %i{The actual size this limiter is going to produce} self.color = cd.GREEN local obj = { h = h, - offset = 0, size = math.max(h:getsize(), self.limit), - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - getname = function (self) return end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, - getmodif = function (self) return 0 end, - flush = function (self) return true end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - if self.offset < 0 then self.offset = 0 end - if self.offset >= self.size then self.offset = self.size end - self.h:seek(self.offset) - return self.offset + getname = function () return self.name end, + do_read = function (self, userdata, count) + return self.h:read(count, userdata) end, - read = function (self, userdata, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - - local r = self.h:read(count, userdata) - self.offset = self.offset + r - return r + do_seek = function (self) + self.h:seek(self.offset, SEEK_SET) end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh) + self:set_houtput(dalos.luahandle(obj)) self.dcanvas:draw() else self.color = cd.YELLOW @@ -68,7 +33,6 @@ Limit: %i{The actual size this limiter is going to produce} end end, - create = function (d, tab) tab.ninputs = 1 tab.noutputs = 1 diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua new file mode 100644 index 0000000..3254490 --- /dev/null +++ b/dalos-luahandle.lua @@ -0,0 +1,51 @@ +dalosp.luahandle = { + create = function (tab) + local obj = { + offset = 0, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + if self.do_seek then self:do_seek() end + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r, t = self:do_read(count, userdata) + self.offset = self.offset + r + return r, t + end, + } + for k, v in pairs(tab) do obj[k] = v end + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh) + end, +} + +dalos.luahandle = dalosp.luahandle.create diff --git a/dalos.lua b/dalos.lua index b0b9aee..07b534f 100644 --- a/dalos.lua +++ b/dalos.lua @@ -550,11 +550,11 @@ dalosp.object = { end, default_activate = function (self) - print "activate" + print "default activate" end, default_configure = function (self) - print "configure" + print "default configure" end, change_curinput = function (self, delta) @@ -662,6 +662,7 @@ dalos.objtype = { ---------------- +load "dalos-luahandle.lua" load "dalos-hexview.lua" load "dalos-binaryops.lua" load "dalos-limiter.lua" -- cgit v1.2.3 From 775500b709be0d14ad89f63970bf971d68c89407 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 16:38:06 +0100 Subject: Introducing serialization / deserialization mechanism. --- dalos-binaryops.lua | 8 +++++++- dalos-hexview.lua | 32 +++++++++++++++++++++++++++++++- dalos-limiter.lua | 8 +++++++- dalos.lua | 5 +++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index eda76e5..095e7eb 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -27,6 +27,10 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} end end, + get_settings = function (self) + return { op = self.extra.op, maximize = self.extra.maximize } + end, + input_change = function (self, ind) local h1 = self:get_linked_input(1) local h2 = self:get_linked_input(2) @@ -87,7 +91,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} cv:Text(cx, cy, dalosp.binaryops.opnames[op]) end, - create = function (d, tab) + create = function (d, tab, settings) tab.ninputs = 2 tab.noutputs = 1 tab.otype = dalos.objtype.LUA_FILTER @@ -95,7 +99,9 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} tab.input_change = dalosp.binaryops.input_change tab.default_name = "Binary Ops" tab.draw = dalosp.binaryops.draw + tab.get_settings = dalosp.binaryops.get_settings local extra = { } + if settings then extra.op = settings.op extra.maximize = settings.maximize end local obj = dalos.object(d, tab, extra) end, diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 381ffd4..f3111d7 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -34,6 +34,22 @@ dalosp.hexview = { configure = function (self) end, + get_settings = function (self) + local hv = extra.hv + local r = { + mcursor = hv.mcursor + 0, + kcursor = hv.kcursor + 0, + markers = {}, + filecursor = hv.filecursor + 0, + nbbytes = hv.nbbytes + 0, + nblines = hv.nblines + 0, + } + for i = 1, 10 do + rmarkers[i] = hv.markers[i] + 0 + end + return r + end, + output_change = function (self, ind) self.watchees[ind] = self.outputs[ind] and true or false end, @@ -87,12 +103,13 @@ dalosp.hexview = { end end, - create = function (d, tab) + create = function (d, tab, settings) tab.otype = dalos.objtype.LUA_FILTER tab.activate = dalosp.hexview.activate tab.input_change = dalosp.hexview.input_change tab.output_change = dalosp.hexview.output_change tab.configure = dalosp.hexview.configure + tab.get_settings = dalosp.get_settings tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" @@ -114,6 +131,19 @@ dalosp.hexview = { obj.update_houtput = dalosp.hexview.update_houtput for i = 1, 12 do obj.oldcursors[i] = -1 end + if settings then + if settings.markers then + for i = 1, 10 do + hv.markers[i] = settings.markers[i] + end + end + hv.mcursor = settings.mcursor + hv.kcursor = settings.kcursor + hv.filecursor = settings.filecursor + hv.nbbytes = settings.nbbytes + hv.nblines = settings.nblines + end + hv:registercb(dalosp.hexview.dalos_hv_cb, obj) return obj diff --git a/dalos-limiter.lua b/dalos-limiter.lua index b423d7a..8454775 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -9,6 +9,10 @@ Limit: %i{The actual size this limiter is going to produce} end end, + get_settings = function (self) + return { limit = self.extra.limit } + end, + input_change = function (self, ind) local h = self:get_linked_input(1) if h then @@ -33,14 +37,16 @@ Limit: %i{The actual size this limiter is going to produce} end end, - create = function (d, tab) + create = function (d, tab, settings) tab.ninputs = 1 tab.noutputs = 1 tab.otype = dalos.objtype.LUA_FILTER tab.configure = dalosp.limiter.configure tab.input_change = dalosp.limiter.input_change tab.default_name = "Limiter" + tab.get_settings = dalosp.limiter.get_settings local extra = { } + if settings then extra.limit = settings.limit end local obj = dalos.object(d, tab, extra) end, diff --git a/dalos.lua b/dalos.lua index 07b534f..0b94d53 100644 --- a/dalos.lua +++ b/dalos.lua @@ -593,6 +593,10 @@ dalosp.object = { end end, + default_get_settings = function (self) + return {} + end, + create = function (dcanvas, tab, extra) if not tab then tab = {} end if not tab.name then @@ -623,6 +627,7 @@ dalosp.object = { input_change = tab.input_change or dalosp.object.default_inputchange, output_change = tab.output_change or dalosp.object.default_outputchange, set_houtput = dalosp.object.set_houtput, + get_settings = tab.get_setings or dalosp.object.default_get_settings, houtputs = {}, get_linked_input = dalosp.object.get_linked_input, dcanvas = dcanvas, -- cgit v1.2.3 From 0a82bfbeffd17236ce8a63251a95f05effd9ec91 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 16:42:40 +0100 Subject: Optimization tentative. --- dalos.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dalos.lua b/dalos.lua index 0b94d53..0e18535 100644 --- a/dalos.lua +++ b/dalos.lua @@ -104,17 +104,15 @@ dalosp.canvas = { cv:TextAlignment(cd.NORTH) cv:Text(x, iy(y1 + 3), dalosp.cross.north.name) end + cv:TextAlignment(cd.SOUTH) if dalosp.cross.south then - cv:TextAlignment(cd.SOUTH) cv:Text(x, iy(y2 - 3), dalosp.cross.south.name) end if dalosp.cross.west then - cv:TextAlignment(cd.SOUTH) cv:TextOrientation(270) cv:Text(x1 + 3, iy(y), dalosp.cross.west.name) end if dalosp.cross.east then - cv:TextAlignment(cd.SOUTH) cv:TextOrientation(90) cv:Text(x2 - 3, iy(y), dalosp.cross.east.name) end -- cgit v1.2.3 From f2d8c3a51f11bd63547d0b6de9c16f297a17001f Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 16:51:53 +0100 Subject: Adding load and save stubs. --- dalos.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dalos.lua b/dalos.lua index 0e18535..c2279db 100644 --- a/dalos.lua +++ b/dalos.lua @@ -423,6 +423,12 @@ dalosp.canvas = { } dalosp.menu = { + action_load = function (self) + end, + + action_save = function(self) + end, + action_exit = function (self) return iup.CLOSE end, @@ -465,6 +471,10 @@ dalosp.menu = { end, create = function (canvas, tab) + local item_load = iup.item { title = "Load" } + item_load.action = dalosp.menu.action_load + local item_save = iup.item { title = "Save" } + item_save.action = dalosp.menu.action_save local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } @@ -494,7 +504,7 @@ dalosp.menu = { table.insert(south_menu, item) end end - local menu_file = iup.submenu { iup.menu { item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, -- cgit v1.2.3 From e35ec05baf3d3f8d490d9f2781f602499551a350 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 16:58:11 +0100 Subject: Adding the textbuffer object. --- dalos-textbuffer.lua | 32 ++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 33 insertions(+) create mode 100644 dalos-textbuffer.lua diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua new file mode 100644 index 0000000..b1e3c03 --- /dev/null +++ b/dalos-textbuffer.lua @@ -0,0 +1,32 @@ +dalosp.textbuffer = { + get_settings = function (self) + return { text = extra.text } + end, + + activate = function (self) + local text = self.extra.text or "" + text = iup.GetText(self.name, text) + if text then + self.extra.text = text + local b = Buffer(true) + b:write(text) + self.set_houtput(b) + end + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.activate = dalosp.textbuffer.activate + tab.default_name = "Text Buffer" + tab.get_settings = dalosp.textbuffer.get_settings + local extra = { } + if settings then extra.text = settings.text end + + local obj = dalos.object(d, tab, extra) + end, +} + +dalos.textbuffer = dalosp.textbuffer.create +dalos:register_obj("Text Buffer", dalos.textbuffer) diff --git a/dalos.lua b/dalos.lua index c2279db..5d13283 100644 --- a/dalos.lua +++ b/dalos.lua @@ -679,6 +679,7 @@ load "dalos-luahandle.lua" load "dalos-hexview.lua" load "dalos-binaryops.lua" load "dalos-limiter.lua" +load "dalos-textbuffer.lua" ---------------- -- cgit v1.2.3 From 1f84bc289695a02a503ff18d0611d2e20127ac9f Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 17:03:21 +0100 Subject: Fixing a typo in the textbuffer, and removing the "prototypes" buffers from the main file. Dalos is now "complete". --- dalos-textbuffer.lua | 2 +- dalos.lua | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index b1e3c03..5b15e5f 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -10,7 +10,7 @@ dalosp.textbuffer = { self.extra.text = text local b = Buffer(true) b:write(text) - self.set_houtput(b) + self:set_houtput(b) end end, diff --git a/dalos.lua b/dalos.lua index 5d13283..d0c1545 100644 --- a/dalos.lua +++ b/dalos.lua @@ -683,24 +683,17 @@ load "dalos-textbuffer.lua" ---------------- -d = dalos.canvas {} -m = dalos.menu(d) +function dalos:main() + d = self.canvas {} + m = self.menu(d) -b1 = Buffer(true) -b1:write("Buffer 1 contents") -b2 = Buffer(true) -b2:write("Buffer 2 contents") + dlg = iup.dialog { d, title = "Dalos", menu = m } -o1 = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "Buffer 1", otype = dalos.objtype.HANDLE }) -o2 = dalos.object(d, { y = 120, x = 10, noutputs = 1, name = "Buffer 2", otype = dalos.objtype.HANDLE }) + self.dialog = dlg -o1:set_houtput(b1) -o2:set_houtput(b2) - -dlg = iup.dialog { d, title = "Dalos", menu = m } - -dalos.dialog = dlg + dlg:show() + iup.MainLoop() + dlg:hide() +end -dlg:show() -iup.MainLoop() -dlg:hide() +dalos:main() -- cgit v1.2.3 From 054083c8bcc6fc4f9085023d5c55c4214d0faf6b Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 17:13:59 +0100 Subject: Adding the Input object. --- dalos-input.lua | 41 +++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 42 insertions(+) create mode 100644 dalos-input.lua diff --git a/dalos-input.lua b/dalos-input.lua new file mode 100644 index 0000000..1061619 --- /dev/null +++ b/dalos-input.lua @@ -0,0 +1,41 @@ +dalosp.input = { + get_settings = function (self) + return { filename = extra.filename } + end, + + configure = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + file = self.extra.filename, + } + iup.Popup(dlg) + if dlg.status ~= -1 then + local s, v = pcall(Input, dlg.value) + if s then + obj:set_houtput(v) + return + end + end + obj:set_houtput(nil) + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.configure = dalosp.input.configure + tab.default_name = "Input" + tab.get_settings = dalosp.input.get_settings + local extra = { } + if settings then extra.filename = settings.filename end + local obj = dalos.object(d, tab, extra) + + if extra.filename then + local s, v = pcall(Input, extra.filename) + if s then obj:set_houtput(v) end + end + end, +} + +dalos.input = dalosp.input.create +dalos:register_obj("Input", dalos.input) diff --git a/dalos.lua b/dalos.lua index d0c1545..1b64704 100644 --- a/dalos.lua +++ b/dalos.lua @@ -680,6 +680,7 @@ load "dalos-hexview.lua" load "dalos-binaryops.lua" load "dalos-limiter.lua" load "dalos-textbuffer.lua" +load "dalos-input.lua" ---------------- -- cgit v1.2.3 From 9e4d6af65641703b1451a31d973d7b6b5b23cc65 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 17:17:18 +0100 Subject: Typo in the input object. --- dalos-input.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dalos-input.lua b/dalos-input.lua index 1061619..7588046 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -12,11 +12,11 @@ dalosp.input = { if dlg.status ~= -1 then local s, v = pcall(Input, dlg.value) if s then - obj:set_houtput(v) + self:set_houtput(v) return end end - obj:set_houtput(nil) + self:set_houtput(nil) end, create = function (d, tab, settings) -- cgit v1.2.3 From 3bf6f4ddfbcd61b28e918312090db8322d7ecc91 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 17:57:53 +0100 Subject: Save is almost done. --- dalos-binaryops.lua | 3 +- dalos-hexview.lua | 1 + dalos-input.lua | 3 +- dalos-limiter.lua | 1 + dalos-textbuffer.lua | 3 +- dalos.lua | 82 ++++++++++++++++++++++++++++++++++++---------------- 6 files changed, 65 insertions(+), 28 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 095e7eb..17c9b63 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -100,6 +100,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} tab.default_name = "Binary Ops" tab.draw = dalosp.binaryops.draw tab.get_settings = dalosp.binaryops.get_settings + tab.ntype = "Binary Ops" local extra = { } if settings then extra.op = settings.op extra.maximize = settings.maximize end @@ -108,4 +109,4 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} } dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) \ No newline at end of file +dalos:register_obj("Binary Ops", dalos.binaryops) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index f3111d7..26eaa77 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -113,6 +113,7 @@ dalosp.hexview = { tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" + tab.ntype = "Hexview" local extra = { } diff --git a/dalos-input.lua b/dalos-input.lua index 7588046..86dce5a 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -1,6 +1,6 @@ dalosp.input = { get_settings = function (self) - return { filename = extra.filename } + return { filename = self.extra.filename } end, configure = function (self) @@ -25,6 +25,7 @@ dalosp.input = { tab.otype = dalos.objtype.HANDLE tab.configure = dalosp.input.configure tab.default_name = "Input" + tab.ntype = "Input" tab.get_settings = dalosp.input.get_settings local extra = { } if settings then extra.filename = settings.filename end diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 8454775..d27c0b5 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -44,6 +44,7 @@ Limit: %i{The actual size this limiter is going to produce} tab.configure = dalosp.limiter.configure tab.input_change = dalosp.limiter.input_change tab.default_name = "Limiter" + tab.ntype = "Limiter" tab.get_settings = dalosp.limiter.get_settings local extra = { } if settings then extra.limit = settings.limit end diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index 5b15e5f..d52bb76 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -1,6 +1,6 @@ dalosp.textbuffer = { get_settings = function (self) - return { text = extra.text } + return { text = self.extra.text } end, activate = function (self) @@ -20,6 +20,7 @@ dalosp.textbuffer = { tab.otype = dalos.objtype.HANDLE tab.activate = dalosp.textbuffer.activate tab.default_name = "Text Buffer" + tab.ntype = "Text Buffer" tab.get_settings = dalosp.textbuffer.get_settings local extra = { } if settings then extra.text = settings.text end diff --git a/dalos.lua b/dalos.lua index 1b64704..e226faf 100644 --- a/dalos.lua +++ b/dalos.lua @@ -7,8 +7,8 @@ load "iupe-tview.lua" if not dalosp then dalosp = {} end if not dalos then dalos = {} end -dalos.objects = {} -dalos.objects_by_name = {} +dalos.objectstypes = {} +dalos.objectstypes_by_name = {} dalosp.NORTH = 1 dalosp.SOUTH = 2 @@ -17,11 +17,11 @@ dalosp.EAST = 4 dalosp.cross = { } function dalos:register_obj(name, constructor) - if self.objects_by_name[name] then + if self.objectstypes_by_name[name] then error("An object of that name already exists: " .. name) end - table.insert(self.objects, { name = name, constructor = constructor, counter = 1 }) - self.objects_by_name[name] = #self.objects + table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1 }) + self.objectstypes_by_name[name] = #self.objectstypes if self.activemenu then self.activemenu:update_objects() end @@ -427,6 +427,39 @@ dalosp.menu = { end, action_save = function(self) + local s_obj = { } + if not dalos.active_canvas then return end + local d = dalos.active_canvas + for i, v in ipairs(d.objects) do + s_obj[i] = { x = v.x, y = v.y, name = v.obj.name, ntype = v.obj.ntype, settings = v.obj:get_settings(), lookup = v } + end + local s_links = { } + for iobj, obj in ipairs(d.objects) do + for iout, out in pairs(obj.obj.outputs) do + for ilookup, lobj in ipairs(s_obj) do + if lobj.lookup == out.obj then + table.insert(s_links, { src = iobj, dst = ilookup, isrc = iout, idst = out.ind }) + end + end + end + end + for i, v in ipairs(s_obj) do + v.lookup = nil + end + local save = { objects = s_obj, links = s_links } + local dlg = iup.filedlg { + dialogtype = "Save", + } + iup.Popup(dlg) + if dlg.status ~= -1 then + print(dlg.value) + local s, v = pcall(Output, dlg.value) + if s then + v:write "local " + dumpvars(v, save, "save") + v:write "return save" + end + end end, action_exit = function (self) @@ -484,25 +517,23 @@ dalosp.menu = { local east_menu = { radio = "1" } local west_menu = { radio = "1" } local south_menu = { radio = "1" } - if type(dalos.objects) == "table" then - local item - for k, v in ipairs(dalos.objects) do - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.add_object(canvas, v) end - table.insert(add_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end - table.insert(north_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end - table.insert(east_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end - table.insert(west_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end - table.insert(south_menu, item) - end + local item + for k, v in ipairs(dalos.objectstypes) do + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.add_object(canvas, v) end + table.insert(add_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end + table.insert(north_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end + table.insert(east_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end + table.insert(west_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end + table.insert(south_menu, item) end local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } @@ -623,6 +654,7 @@ dalosp.object = { outputs = {}, curinput = 1, curoutput = 1, + ntype = tab.ntype, quicksetting = tab.quicksetting, otype = tab.otype or dalos.objtype.DUMMY, activate = tab.activate or dalosp.object.default_activate, @@ -635,7 +667,7 @@ dalosp.object = { input_change = tab.input_change or dalosp.object.default_inputchange, output_change = tab.output_change or dalosp.object.default_outputchange, set_houtput = dalosp.object.set_houtput, - get_settings = tab.get_setings or dalosp.object.default_get_settings, + get_settings = tab.get_settings or dalosp.object.default_get_settings, houtputs = {}, get_linked_input = dalosp.object.get_linked_input, dcanvas = dcanvas, -- cgit v1.2.3 From 85d327879aafffcf0f3c811195cbdd07aa6eda7b Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 00:18:36 +0100 Subject: Fixing and finishing up serialization. --- dalos-binaryops.lua | 2 ++ dalos-hexview.lua | 16 ++++++------ dalos-input.lua | 4 ++- dalos-limiter.lua | 2 ++ dalos-textbuffer.lua | 2 ++ dalos.lua | 73 ++++++++++++++++++++++++++++++++++++++++++---------- 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 17c9b63..022020c 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -105,6 +105,8 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} if settings then extra.op = settings.op extra.maximize = settings.maximize end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 26eaa77..a302d39 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -45,7 +45,7 @@ dalosp.hexview = { nblines = hv.nblines + 0, } for i = 1, 10 do - rmarkers[i] = hv.markers[i] + 0 + r.markers[i] = hv.markers[i] + 0 end return r end, @@ -109,7 +109,7 @@ dalosp.hexview = { tab.input_change = dalosp.hexview.input_change tab.output_change = dalosp.hexview.output_change tab.configure = dalosp.hexview.configure - tab.get_settings = dalosp.get_settings + tab.get_settings = dalosp.hexview.get_settings tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" @@ -135,14 +135,14 @@ dalosp.hexview = { if settings then if settings.markers then for i = 1, 10 do - hv.markers[i] = settings.markers[i] + if settings.markers[i] then hv.markers[i] = settings.markers[i] end end end - hv.mcursor = settings.mcursor - hv.kcursor = settings.kcursor - hv.filecursor = settings.filecursor - hv.nbbytes = settings.nbbytes - hv.nblines = settings.nblines + if settings.mcursor then hv.mcursor = settings.mcursor end + if settings.kcursor then hv.kcursor = settings.kcursor end + if settings.filecursor then hv.filecursor = settings.filecursor end + if settings.nbbytes then hv.nbbytes = settings.nbbytes end + if settings.nblines then hv.nblines = settings.nblines end end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) diff --git a/dalos-input.lua b/dalos-input.lua index 86dce5a..be2cf75 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -34,7 +34,9 @@ dalosp.input = { if extra.filename then local s, v = pcall(Input, extra.filename) if s then obj:set_houtput(v) end - end + end + + return obj end, } diff --git a/dalos-limiter.lua b/dalos-limiter.lua index d27c0b5..ee9b106 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -50,6 +50,8 @@ Limit: %i{The actual size this limiter is going to produce} if settings then extra.limit = settings.limit end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index d52bb76..cd91689 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -26,6 +26,8 @@ dalosp.textbuffer = { if settings then extra.text = settings.text end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos.lua b/dalos.lua index e226faf..7f554d1 100644 --- a/dalos.lua +++ b/dalos.lua @@ -18,7 +18,7 @@ dalosp.cross = { } function dalos:register_obj(name, constructor) if self.objectstypes_by_name[name] then - error("An object of that name already exists: " .. name) + error("An object type of that name already exists: " .. name) end table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1 }) self.objectstypes_by_name[name] = #self.objectstypes @@ -27,6 +27,18 @@ function dalos:register_obj(name, constructor) end end +function dalos:clean() + local d = dalos.active_canvas + for k, v in ipairs(d.objects) do + for ind = 1, v.obj.noutputs do + d:destroylink(v, ind) + end + end + + while #d.objects ~= 0 do table.remove(d.objects) end + d.objects = {} +end + dalosp.canvas = { DARK_WHITE = cd.EncodeColor(224, 224, 224), BEZIER_CTRL_LEN = 40, @@ -243,9 +255,11 @@ dalosp.canvas = { end end, - createlink = function (self, src, dst) - local oldsrc = src.obj.outputs[src.obj.curoutput] - local olddst = dst.obj.inputs[dst.obj.curinput] + createlink = function (self, src, dst, srcind, dstind) + if not srcind then srcind = src.obj.curoutput end + if not dstind then dstind = dst.obj.curinput end + local oldsrc = src.obj.outputs[srcind] + local olddst = dst.obj.inputs[dstind] if oldsrc then oldsrc.obj.obj.inputs[oldsrc.ind] = nil oldsrc.obj.obj:input_change(oldsrc.ind) @@ -254,17 +268,18 @@ dalosp.canvas = { olddst.obj.obj.outputs[olddst.ind] = nil olddst.obj.obj:output_change(olddst.ind) 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 } - src.obj:output_change(src.obj.curoutput) - dst.obj:input_change(dst.obj.curinput) + src.obj.outputs[src.obj.curoutput] = { obj = dst, ind = dstind } + dst.obj.inputs[dst.obj.curinput] = { obj = src, ind = srcind } + src.obj:output_change(srcind) + dst.obj:input_change(dstind) end, - destroylink = function (self, src) - local oldsrc = src.obj.outputs[src.obj.curoutput] + destroylink = function (self, src, ind) + if not ind then ind = src.obj.curoutput end + local oldsrc = src.obj.outputs[ind] if oldsrc then - src.obj.outputs[src.obj.curoutput] = nil - src.obj:output_change(src.obj.curoutput) + src.obj.outputs[ind] = nil + src.obj:output_change(ind) oldsrc.obj.obj.inputs[oldsrc.ind] = nil oldsrc.obj.obj:input_change(oldsrc.ind) @@ -424,6 +439,39 @@ dalosp.canvas = { dalosp.menu = { action_load = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + } + iup.Popup(dlg) + if dlg.status == -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) + if not f then error("Syntax error loading file " .. dlg.value) end + local data = f() + local tlup = dalos.objectstypes_by_name + local ot = dalos.objectstypes + local d = dalos.active_canvas + local lup = {} + for k, v in ipairs(data.objects) do + if not tlup[v.ntype] then error("Object " .. v.ntype .. " isn't declared") end + end + dalos:clean() + for k, v in ipairs(data.objects) do + local tab = { x = v.x, y = v.y, name = v.name } + local o = ot[tlup[v.ntype]].constructor(d, tab, v.settings) + for iobj, obj in ipairs(d.objects) do + if obj.obj == o then + lup[iobj] = obj + end + end + end + for k, v in ipairs(data.links) do + if not lup[v.src] then error("Can't find object for id src " .. v.src) end + if not lup[v.dst] then error("Can't find object for id dst " .. v.dst) end + d:createlink(lup[v.src], lup[v.dst], v.isrc, v.idst) + end end, action_save = function(self) @@ -452,7 +500,6 @@ dalosp.menu = { } iup.Popup(dlg) if dlg.status ~= -1 then - print(dlg.value) local s, v = pcall(Output, dlg.value) if s then v:write "local " -- cgit v1.2.3 From e294e63159e9596dd23bdb33e6ac3c574c32289f Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 21:22:38 +0100 Subject: Various fixes. --- dalos-binaryops.lua | 2 +- dalos-hexview.lua | 17 +++++++++++------ dalos-limiter.lua | 2 +- dalos-luahandle.lua | 2 +- dalos.lua | 8 ++++++-- iupe-hexview.lua | 30 ++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 022020c..1ced26f 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -45,7 +45,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} offset = 0, size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), getname = function () return self.name end, - do_read = function (self, dummy, count) + do_read = function (self, count) self.h1:seek(self.offset) self.h2:seek(self.offset) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index a302d39..ee9412e 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -52,12 +52,16 @@ dalosp.hexview = { output_change = function (self, ind) self.watchees[ind] = self.outputs[ind] and true or false + self:set_houtput(nil, ind) + self.oldcursors[ind] = -1 + self:dalos_hv_cb(self.extra.hv) end, update_houtput = function (self, ind, cursor) local h = self:get_linked_input(1) - local maxsixe = h and h:getsize() or -1 - if h and self.watchees[ind] then + local maxsize = h and h:getsize() or -1 + cursor = cursor + 0 + if cursor >= 0 and h and self.watchees[ind] then if cursor < maxsize then self:set_houtput(nil, ind) end @@ -72,7 +76,7 @@ dalosp.hexview = { do_seek = function (self) self.h:seek(self.offset + self.origin) end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, } @@ -84,20 +88,20 @@ dalosp.hexview = { local m for i = 1, 10 do m = hv.markers[i] - if self.oldcursors[i] ~= m then + if m and self.oldcursors[i] ~= m then self:update_houtput(i, m) self.oldcursors[i] = m end end m = hv.kcursor - if self.oldcursors[11] ~= m then + if m and self.oldcursors[11] ~= m then self:update_houtput(11, m) self.oldcursors[11] = m end m = hv.mcursor - if self.oldcursors[12] ~= m then + if m and self.oldcursors[12] ~= m then self:update_houtput(12, m) self.oldcursors[12] = m end @@ -146,6 +150,7 @@ dalosp.hexview = { end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb return obj end, diff --git a/dalos-limiter.lua b/dalos-limiter.lua index ee9b106..99bd07f 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -21,7 +21,7 @@ Limit: %i{The actual size this limiter is going to produce} h = h, size = math.max(h:getsize(), self.limit), getname = function () return self.name end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, do_seek = function (self) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 3254490..332a90e 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -44,7 +44,7 @@ dalosp.luahandle = { for k, v in pairs(tab) do obj[k] = v end local newh = HandleLua(obj) obj.lh = newh - self:set_houtput(newh) + return newh end, } diff --git a/dalos.lua b/dalos.lua index 7f554d1..06058de 100644 --- a/dalos.lua +++ b/dalos.lua @@ -16,6 +16,8 @@ dalosp.WEST = 3 dalosp.EAST = 4 dalosp.cross = { } +dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" } + function dalos:register_obj(name, constructor) if self.objectstypes_by_name[name] then error("An object type of that name already exists: " .. name) @@ -502,7 +504,9 @@ dalosp.menu = { if dlg.status ~= -1 then local s, v = pcall(Output, dlg.value) if s then - v:write "local " + v:write "---- Dalos save\nlocal " + dumpvars(v, dalos.version, "version") + v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, save, "save") v:write "return save" end @@ -519,7 +523,7 @@ dalosp.menu = { ButtonDefault = "1", Buttons = "OK", Title = "About", - Value = 'DALOS (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', + Value = 'DALOS ' .. dalos.version.MAJOR .. '.' .. dalos.version.MINOR .. dalos.version.suffix .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', } dlg:popup() return iup.DEFAULT diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 0567cd0..4b135f0 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -340,6 +340,36 @@ iupep.hexview = { elseif c == iup.K_m0 then kaction = true self.markers[10] = kcursor + elseif c == iup.K_c1 then + kaction = true + self.markers[1] = nil + elseif c == iup.K_c2 then + kaction = true + self.markers[2] = nil + elseif c == iup.K_c3 then + kaction = true + self.markers[3] = nil + elseif c == iup.K_c4 then + kaction = true + self.markers[4] = nil + elseif c == iup.K_c5 then + kaction = true + self.markers[5] = nil + elseif c == iup.K_c6 then + kaction = true + self.markers[6] = nil + elseif c == iup.K_c7 then + kaction = true + self.markers[7] = nil + elseif c == iup.K_c8 then + kaction = true + self.markers[8] = nil + elseif c == iup.K_c9 then + kaction = true + self.markers[9] = nil + elseif c == iup.K_c0 then + kaction = true + self.markers[10] = nil elseif c == iup.K_SP then kaction = true end -- cgit v1.2.3 From 08dc3021d7769d60131668ff98166a4280eec1da Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 23:22:35 +0100 Subject: Adding import, and saving / loading more stuff. --- dalos.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/dalos.lua b/dalos.lua index 06058de..3b53b72 100644 --- a/dalos.lua +++ b/dalos.lua @@ -459,6 +459,11 @@ dalosp.menu = { for k, v in ipairs(data.objects) do if not tlup[v.ntype] then error("Object " .. v.ntype .. " isn't declared") end end + if data.imports then + for i, v in ipairs(data.imports) do + dalosp.menu.load_file(v) + end + end dalos:clean() for k, v in ipairs(data.objects) do local tab = { x = v.x, y = v.y, name = v.name } @@ -474,6 +479,13 @@ dalosp.menu = { if not lup[v.dst] then error("Can't find object for id dst " .. v.dst) end d:createlink(lup[v.src], lup[v.dst], v.isrc, v.idst) end + if data.cross then + dalosp.cross = {} + if data.cross.north then dalosp.cross.north = tlup[data.cross.north] end + if data.cross.south then dalosp.cross.south = tlup[data.cross.south] end + if data.cross.west then dalosp.cross.west = tlup[data.cross.west] end + if data.cross.east then dalosp.cross.east = tlup[data.cross.east] end + end end, action_save = function(self) @@ -496,7 +508,12 @@ dalosp.menu = { for i, v in ipairs(s_obj) do v.lookup = nil end - local save = { objects = s_obj, links = s_links } + local s_cross = { } + if dalosp.cross.north then s_cross.north = dalosp.cross.north.name end + if dalosp.cross.sorth then s_cross.sorth = dalosp.cross.sorth.name end + if dalosp.cross.west then s_cross.west = dalosp.cross.west.name end + if dalosp.cross.east then s_cross.east = dalosp.cross.east.name end + local save = { objects = s_obj, links = s_links, cross = s_cross, imports = dalosp.imports } local dlg = iup.filedlg { dialogtype = "Save", } @@ -513,6 +530,34 @@ dalosp.menu = { end end, + load_file = function (file) + local s, v = pcall(load, file) + if not s then return end + if not dalosp.imports then dalosp.imports = {} end + for i, v in ipairs(dalosp.imports) do + if v == file then return end + end + table.insert(dalosp.imports, file) + end, + + action_import = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + } + iup.Popup(dlg) + if dlg.status == -1 then return end + + dalosp.menu.load_file(dlg.value) + end, + + action_reload = function (self) + if not dalosp.imports then return end + + for i, v in ipairs(dalosp.imports) do + pcall(load, v) + end + end, + action_exit = function (self) return iup.CLOSE end, @@ -559,6 +604,10 @@ dalosp.menu = { item_load.action = dalosp.menu.action_load local item_save = iup.item { title = "Save" } item_save.action = dalosp.menu.action_save + local item_import = iup.item { title = "Import" } + item_import.action = dalosp.menu.action_import + local item_reload = iup.item { title = "Reload all" } + item_reload.action = dalosp.menu.action_reload local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } @@ -586,7 +635,7 @@ dalosp.menu = { item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end table.insert(south_menu, item) end - local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, -- cgit v1.2.3 From 5d600b135fee0fd3f2ccbc9ee37ffd4e37cad7ac Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 23:40:31 +0100 Subject: Adding the Tee object. --- dalos-tee.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 51 insertions(+) create mode 100644 dalos-tee.lua diff --git a/dalos-tee.lua b/dalos-tee.lua new file mode 100644 index 0000000..5c9b26a --- /dev/null +++ b/dalos-tee.lua @@ -0,0 +1,50 @@ +dalosp.tee = { + NTEE = 16, + + set_out = function (self, h, ind) + local name = h:getname() + local obj = { + h = h, + size = h:getsize(), + getname = function () return name end, + do_read = function (self, count, userdata) + self.h:seek(self.offset, SEEK_SET) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), ind) + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + for ind = 1, 16 do self:set_out(h, ind) end + self.dcanvas:draw() + else + self.color = cd.YELLOW + for i = 1, dalosp.tee.NTEE do + self:set_houtput(nil, i) + end + self.dcanvas:draw() + end + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = dalosp.tee.NTEE + tab.otype = dalos.objtype.LUA_FILTER + tab.input_change = dalosp.tee.input_change + tab.default_name = "Tee" + tab.ntype = "Tee" + + local obj = dalos.object(d, tab) + + obj.set_out = dalosp.tee.set_out + + return obj + end, +} + +dalos.tee = dalosp.tee.create +dalos:register_obj("Tee", dalos.tee) diff --git a/dalos.lua b/dalos.lua index 3b53b72..32a8bca 100644 --- a/dalos.lua +++ b/dalos.lua @@ -813,6 +813,7 @@ load "dalos-binaryops.lua" load "dalos-limiter.lua" load "dalos-textbuffer.lua" load "dalos-input.lua" +load "dalos-tee.lua" ---------------- -- cgit v1.2.3 From a984dff9f2c8be16ad392e864c13de08fe729204 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 22 Dec 2009 00:19:22 +0100 Subject: Fixing wheel setting. --- dalos.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dalos.lua b/dalos.lua index 32a8bca..399fff3 100644 --- a/dalos.lua +++ b/dalos.lua @@ -388,6 +388,8 @@ dalosp.canvas = { wheel_cb = function (self, delta, x, y, status) local obj = self:findobj(x, y) + if delta > 0 then delta = math.floor(delta + 0.5) else delta = -math.floor(-delta + 0.5) end + if obj then if iup.isshift(status) then obj.obj:change_curoutput(delta) -- cgit v1.2.3 From 781be3edac2cd5e05df401f6eebb5b75660b99d0 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 22 Dec 2009 05:16:33 +0100 Subject: Adding the 'Buffer' object. --- dalos-buffer.lua | 30 ++++++++++++++++++++++++++++++ dalos.lua | 5 +++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 dalos-buffer.lua diff --git a/dalos-buffer.lua b/dalos-buffer.lua new file mode 100644 index 0000000..ecab2ed --- /dev/null +++ b/dalos-buffer.lua @@ -0,0 +1,30 @@ +dalosp.buffer = { + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local b = Buffer(true) + b:copyfrom(self:get_linked_input(1)) + self:set_houtput(b) + else + self:set_houtput(nil) + self.color = cd.YELLOW + end + self.dcanvas:draw() + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.default_name = "Buffer" + tab.input_change = dalosp.buffer.input_change + tab.ntype = "Buffer" + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.buffer = dalosp.buffer.create +dalos:register_obj("Buffer", dalos.buffer) diff --git a/dalos.lua b/dalos.lua index 399fff3..deea0fa 100644 --- a/dalos.lua +++ b/dalos.lua @@ -18,11 +18,11 @@ dalosp.cross = { } dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" } -function dalos:register_obj(name, constructor) +function dalos:register_obj(name, constructor, category) 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 }) + table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category or "Basic" }) self.objectstypes_by_name[name] = #self.objectstypes if self.activemenu then self.activemenu:update_objects() @@ -816,6 +816,7 @@ load "dalos-limiter.lua" load "dalos-textbuffer.lua" load "dalos-input.lua" load "dalos-tee.lua" +load "dalos-buffer.lua" ---------------- -- cgit v1.2.3 From f65c63f2db769bbc39e7941b3e1572b69e544971 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 22 Dec 2009 05:19:01 +0100 Subject: Adding some sizes... --- dalos-hexview.lua | 2 +- dalos.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index ee9412e..a4915f4 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -125,7 +125,7 @@ dalosp.hexview = { local hv = iupe.hexview { } local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } extra.hv = hv extra.hvtb = hvtb diff --git a/dalos.lua b/dalos.lua index deea0fa..4b2eb80 100644 --- a/dalos.lua +++ b/dalos.lua @@ -824,7 +824,7 @@ function dalos:main() d = self.canvas {} m = self.menu(d) - dlg = iup.dialog { d, title = "Dalos", menu = m } + dlg = iup.dialog { d, title = "Dalos", menu = m, size = "200x120" } self.dialog = dlg -- cgit v1.2.3 From 1a74fe712bb4d1c3f968e943b2f8de89420a6a3f Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 22 Dec 2009 08:41:00 +0100 Subject: Adding luafilter! --- dalos-luafilter.lua | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 62 ++++++++++++++++++++++- 2 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 dalos-luafilter.lua diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua new file mode 100644 index 0000000..b267142 --- /dev/null +++ b/dalos-luafilter.lua @@ -0,0 +1,138 @@ +dalosp.luafilter = { + default_code = [[ +-- available globals: + +-- ninputs, noutputs: numbers + +-- get_input(ind): handle +-- del_output(ind): nil +-- new_output(ind): nil +-- set_color(c) : nil + +function activate() +end + +function read(ind, count, userdata, offset) +end + +function seek(ind, offset) +end + +function input_change(ind) +end +]], + + get_settings = function (self) + return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code } + end, + + run_in_localenv = function (self, f, ...) + local localenv = self.extra.localenv + local metatable = getmetatable(_G) + if not metatable then metatable = {} end + local oldni, oldi = metatable.__newindex, metatable.__index + metatable.__newindex = function (table, key, value) +-- print("Setting _G[" .. key .. "] = " .. tostring(value)) + localenv[key] = value + end + metatable.__index = function (table, key) +-- print("Getting _G[" .. key .. "]") + local l = localenv[key] + if l then return localenv[key] end + return rawget(_G, key) + end + setmetatable(_G, metatable) + + if type(f) ~= "function" then f = localenv[f] end + local rets = { true } + if f then rets = { pcall(f, ...) } end + + metatable.__newindex, metatable.__index = oldni, oldi + setmetatable(_G, metatable) + + if not rets[1] then error(rets[2]) end + table.remove(rets, 1) + return unpack(rets) + end, + + load_code = function (self, code) + self.extra.localenv = { + ninputs = self.ninputs + 0, + noutputs = self.noutputs + 0, + get_input = function(ind) return self:get_linked_input(ind) end, + del_output = function(ind) self:set_houtput(nil, ind) end, + new_output = function(ind, size, name) + self:set_houtput(dalos.luahandle{ + size = size, + getname = function () + return name + end, + do_read = function (lh, count, userdata) + return self:run_in_localenv("read", ind, count, userdata, lh.offset) + end, + do_seek = function (lh) + return self:run_in_localenv("seek", ind, lh.offset) + end, + }, ind) + end, + set_color = function(c) self.color = c self:draw() end, + } + if code and code ~= "" then + local f = loadstring(code) + if f then self:run_in_localenv(f) end + end + end, + + input_change = function (self, ind) + self:run_in_localenv("input_change", ind) + end, + + configure = function (self) + local okay = false + local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } + local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } + local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local r = dlg:popup() +-- if r ~= iup.NOERROR then return end + local newcode = text.value + if newcode and okay then + self.extra.code = newcode + self:load_code(newcode) + end + end, + + activate = function (self) + self:run_in_localenv "activate" + end, + + create = function (d, tab, settings) + tab.ninputs = settings and settings.ninputs + tab.noutputs = settings and settings.noutputs + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.luafilter.configure + tab.activate = dalosp.luafilter.activate + tab.input_change = dalosp.luafilter.input_change + tab.default_name = "Lua Filter" + tab.get_settings = dalosp.luafilter.get_settings + tab.ntype = "Lua Filter" + local extra = { localenv = {} } + extra.code = settings and settings.code + if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end + local s = true + while not s and not tab.ninputs or not tab.noutputs do + s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1) + end + + local obj = dalos.object(d, tab, extra) + + obj.load_code = dalosp.luafilter.load_code + obj.run_in_localenv = dalosp.luafilter.run_in_localenv + obj:load_code(extra.code) + + return obj + end, +} + +dalos.luafilter = dalosp.luafilter.create +dalos:register_obj("Lua Filter", dalos.luafilter) diff --git a/dalos.lua b/dalos.lua index 4b2eb80..d8169e5 100644 --- a/dalos.lua +++ b/dalos.lua @@ -2,6 +2,22 @@ loadmodule "luaiup" loadmodule "luahandle" loadmodule "lualibs" +--[[ +load "indent.lua" + +function testIndenter(i) + local lib = IndentationLib + local str = "" + local inp = Input "dalos.lua" + str = inp:readfile() + + local colorTable = lib.defaultColorTable + print(lib.indentCode(str, 4, colorTable, i)) +end + +testIndenter() +]]-- + load "iupe-dbuffer.lua" load "iupe-tview.lua" @@ -167,6 +183,18 @@ dalosp.canvas = { self:draw() end, + delobj = function (self, ind) + local obj = self.objects[ind] + for i = 1, obj.obj.noutputs do + self:destroylink(obj, i) + end + for i = 1, obj.obj.ninputs do + self:destroylink_dst(obj, i) + end + table.remove(self.objects, ind) + self:draw() + end, + findobj = function (self, x, y) local obj, ind @@ -213,6 +241,7 @@ dalosp.canvas = { end, motion_cb = function (self, x, y, status) + self.stateful.mousepos = { x = x, y = y } if self.stateful.panning then local ox, oy = self.ox, self.oy local dx, dy = x - ox, y - oy @@ -288,6 +317,18 @@ dalosp.canvas = { end end, + destroylink_dst = function (self, dst, ind) + if not ind then ind = dst.obj.curinput end + local olddst = dst.obj.inputs[ind] + if olddst then + dst.obj.inputs[ind] = nil + dst.obj:input_change(ind) + + olddst.obj.obj.outputs[olddst.ind] = nil + olddst.obj.obj:output_change(olddst.ind) + end + end, + button_cb = function (self, button, pressed, x, y, status) if not pressed then pressed = 0 end if not x then x = self.ox end @@ -374,7 +415,7 @@ dalosp.canvas = { self.menu.y = nil self:draw() elseif self.stateful.moving then - -- check for the trash can + -- dropped somewhere... do something useful here ? end self.stateful.panning = nil self.stateful.moving = nil @@ -403,6 +444,19 @@ dalosp.canvas = { self:draw() end, + keypress_cb = function (self, c, press) + if press ~= 1 then return end + local obj, ind = self:findobj(self.stateful.mousepos.x, self.stateful.mousepos.y) + if c == iup.K_cS then + if obj then self:delobj(ind) end + elseif c == iup.K_n then + if not obj then return end + local s, newname = iup.GetParam("Renaming", nil, "Set name: %s\n", obj.obj.name) + if s and newname then obj.obj.name = newname end + self:draw() + end + end, + create = function (tab) tab.border = "No" tab.expand = "Yes" @@ -419,7 +473,9 @@ dalosp.canvas = { r.motion_cb = dalosp.canvas.motion_cb r.button_cb = dalosp.canvas.button_cb r.wheel_cb = dalosp.canvas.wheel_cb + r.keypress_cb = dalosp.canvas.keypress_cb r.addobj = dalosp.canvas.addobj + r.delobj = dalosp.canvas.delobj r.findobj = dalosp.canvas.findobj r.moveobj = dalosp.canvas.moveobj r.setobjplace = dalosp.canvas.setobjplace @@ -427,6 +483,7 @@ dalosp.canvas = { r.setstatus = dalosp.canvas.setstatus r.createlink = dalosp.canvas.createlink r.destroylink = dalosp.canvas.destroylink + r.destroylink_dst = dalosp.canvas.destroylink_dst r.drawlink = dalosp.canvas.drawlink r.drawxmenu = dalosp.canvas.drawxmenu r.origin = { x = 0, y = 0 } @@ -817,6 +874,7 @@ load "dalos-textbuffer.lua" load "dalos-input.lua" load "dalos-tee.lua" load "dalos-buffer.lua" +load "dalos-luafilter.lua" ---------------- @@ -833,4 +891,4 @@ function dalos:main() dlg:hide() end -dalos:main() +if not archive_main then dalos:main() end -- cgit v1.2.3 From 95b71cfc474f247e7e1081ea67c7a2166ddd3805 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:02:53 +0100 Subject: Fixing the markers bug --- iupe-hexview.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 4b135f0..1d5f9e3 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -118,8 +118,9 @@ iupep.hexview = { local marker for i = 0, 10 do - marker = self.markers[i] - if marker ~= -1 then + marker = self.markers[i] or -1 + marker = marker - filecursor + if marker >= 0 and marker < nbbytes then mline = math.floor(marker / columns) mcolumn = marker % columns self:colorgrid(markercolors[i], 2, mline, mcolumn * 3 + 10) -- cgit v1.2.3 From f6ac50837aabd69c6ea5892a858359f51f40ee03 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:11:30 +0100 Subject: Mbmbmlmlm \r is evil. --- dalos-binaryops.lua | 228 ++++++++++++++++++------------------ dalos-buffer.lua | 60 +++++----- dalos-hexview.lua | 320 +++++++++++++++++++++++++-------------------------- dalos-input.lua | 88 +++++++------- dalos-limiter.lua | 118 +++++++++---------- dalos-luafilter.lua | 276 ++++++++++++++++++++++---------------------- dalos-luahandle.lua | 102 ++++++++-------- dalos-tee.lua | 100 ++++++++-------- dalos-textbuffer.lua | 70 +++++------ 9 files changed, 681 insertions(+), 681 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 1ced26f..59e8361 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -1,114 +1,114 @@ -dalosp.binaryops = { - operations = { - XOR = 0, - AND = 1, - OR = 2, - ADD = 3, - SUB = 4, - }, - - opnames = { - [0] = "XOR", - [1] = "AND", - [2] = "OR", - [3] = "ADD", - [4] = "SUB", - }, - - configure = function (self) - local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[ -Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} -Maximize: %b[No,Yes]{Check if you want to maximize the output} -]], self.op or 0, self.maximize and 1 or 0) - if accept then - self.extra.op = operation - self.extra.maximize = maximize == 1 - self:input_change() - end - end, - - get_settings = function (self) - return { op = self.extra.op, maximize = self.extra.maximize } - end, - - input_change = function (self, ind) - local h1 = self:get_linked_input(1) - local h2 = self:get_linked_input(2) - local op = self.extra.op or dalosp.binaryops.operations.XOR - if h1 and h2 then - self.color = cd.GREEN - local obj = { - h1 = h1, - h2 = h2, - op = op, - maximize = self.extra.maximize, - offset = 0, - size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), - getname = function () return self.name end, - do_read = function (self, count) - self.h1:seek(self.offset) - self.h2:seek(self.offset) - - local t1, r1 = self.h1:read(count) - local t2, r2 = self.h2:read(count) - local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) - self.offset = self.offset + r - if r == 0 then self.got_eof = true return 0 end - local t = {} - local op - if self.op == dalosp.binaryops.operations.XOR then - op = bit.bxor - elseif self.op == dalosp.binaryops.operations.AND then - op = bit.band - elseif self.op == dalosp.binaryops.operations.OR then - op = bit.bor - elseif self.op == dalosp.binaryops.operations.ADD then - op = function(a, b) return a + b end - elseif self.op == dalosp.binaryops.operations.SUB then - op = function(a, b) return a - b end - end - for i = 0, r - 1 do - t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255) - end - return r, t - end, - } - self:set_houtput(dalos.luahandle(obj)) - self.dcanvas:draw() - else - self.color = cd.YELLOW - self:set_houtput(nil) - self.dcanvas:draw() - end - end, - - draw = function (self, cv, x, y, w, h) - dalosp.object.default_draw(self, cv, x, y, w, h) - local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) - local op = self.extra.op or dalosp.binaryops.operations.XOR - cv:TextAlignment(cd.CENTER) - cv:Foreground(cd.BLACK) - cv:Text(cx, cy, dalosp.binaryops.opnames[op]) - end, - - create = function (d, tab, settings) - tab.ninputs = 2 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.binaryops.configure - tab.input_change = dalosp.binaryops.input_change - tab.default_name = "Binary Ops" - tab.draw = dalosp.binaryops.draw - tab.get_settings = dalosp.binaryops.get_settings - tab.ntype = "Binary Ops" - local extra = { } - if settings then extra.op = settings.op extra.maximize = settings.maximize end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) +dalosp.binaryops = { + operations = { + XOR = 0, + AND = 1, + OR = 2, + ADD = 3, + SUB = 4, + }, + + opnames = { + [0] = "XOR", + [1] = "AND", + [2] = "OR", + [3] = "ADD", + [4] = "SUB", + }, + + configure = function (self) + local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[ +Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} +Maximize: %b[No,Yes]{Check if you want to maximize the output} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.extra.op = operation + self.extra.maximize = maximize == 1 + self:input_change() + end + end, + + get_settings = function (self) + return { op = self.extra.op, maximize = self.extra.maximize } + end, + + input_change = function (self, ind) + local h1 = self:get_linked_input(1) + local h2 = self:get_linked_input(2) + local op = self.extra.op or dalosp.binaryops.operations.XOR + if h1 and h2 then + self.color = cd.GREEN + local obj = { + h1 = h1, + h2 = h2, + op = op, + maximize = self.extra.maximize, + offset = 0, + size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), + getname = function () return self.name end, + do_read = function (self, count) + self.h1:seek(self.offset) + self.h2:seek(self.offset) + + local t1, r1 = self.h1:read(count) + local t2, r2 = self.h2:read(count) + local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) + self.offset = self.offset + r + if r == 0 then self.got_eof = true return 0 end + local t = {} + local op + if self.op == dalosp.binaryops.operations.XOR then + op = bit.bxor + elseif self.op == dalosp.binaryops.operations.AND then + op = bit.band + elseif self.op == dalosp.binaryops.operations.OR then + op = bit.bor + elseif self.op == dalosp.binaryops.operations.ADD then + op = function(a, b) return a + b end + elseif self.op == dalosp.binaryops.operations.SUB then + op = function(a, b) return a - b end + end + for i = 0, r - 1 do + t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255) + end + return r, t + end, + } + self:set_houtput(dalos.luahandle(obj)) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + draw = function (self, cv, x, y, w, h) + dalosp.object.default_draw(self, cv, x, y, w, h) + local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) + local op = self.extra.op or dalosp.binaryops.operations.XOR + cv:TextAlignment(cd.CENTER) + cv:Foreground(cd.BLACK) + cv:Text(cx, cy, dalosp.binaryops.opnames[op]) + end, + + create = function (d, tab, settings) + tab.ninputs = 2 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.binaryops.configure + tab.input_change = dalosp.binaryops.input_change + tab.default_name = "Binary Ops" + tab.draw = dalosp.binaryops.draw + tab.get_settings = dalosp.binaryops.get_settings + tab.ntype = "Binary Ops" + local extra = { } + if settings then extra.op = settings.op extra.maximize = settings.maximize end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.binaryops = dalosp.binaryops.create +dalos:register_obj("Binary Ops", dalos.binaryops) diff --git a/dalos-buffer.lua b/dalos-buffer.lua index ecab2ed..8abcadc 100644 --- a/dalos-buffer.lua +++ b/dalos-buffer.lua @@ -1,30 +1,30 @@ -dalosp.buffer = { - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - local b = Buffer(true) - b:copyfrom(self:get_linked_input(1)) - self:set_houtput(b) - else - self:set_houtput(nil) - self.color = cd.YELLOW - end - self.dcanvas:draw() - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.default_name = "Buffer" - tab.input_change = dalosp.buffer.input_change - tab.ntype = "Buffer" - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.buffer = dalosp.buffer.create -dalos:register_obj("Buffer", dalos.buffer) +dalosp.buffer = { + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local b = Buffer(true) + b:copyfrom(self:get_linked_input(1)) + self:set_houtput(b) + else + self:set_houtput(nil) + self.color = cd.YELLOW + end + self.dcanvas:draw() + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.default_name = "Buffer" + tab.input_change = dalosp.buffer.input_change + tab.ntype = "Buffer" + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.buffer = dalosp.buffer.create +dalos:register_obj("Buffer", dalos.buffer) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index a4915f4..cfd8652 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -1,160 +1,160 @@ -load "iupe-hexview.lua" -load "iupe-hexview-toolbox.lua" - -dalosp.hexview = { - activate = function (self) - self.extra.hvdlg:show() - end, - - input_change = function (self, ind) - local extra = self.extra - local hv = extra.hv - local h = self:get_linked_input(ind) - if not h then - self.color = cd.YELLOW - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - if not h:canread() or not h:canseek() then - self.color = cd.RED - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - self.color = cd.GREEN - for i = 1, 12 do - self:set_houtput(nil, i) - self.oldcursors[i] = -1 - end - hv:updatehandle(h) - self.dcanvas:draw() - end, - - configure = function (self) - end, - - get_settings = function (self) - local hv = extra.hv - local r = { - mcursor = hv.mcursor + 0, - kcursor = hv.kcursor + 0, - markers = {}, - filecursor = hv.filecursor + 0, - nbbytes = hv.nbbytes + 0, - nblines = hv.nblines + 0, - } - for i = 1, 10 do - r.markers[i] = hv.markers[i] + 0 - end - return r - end, - - output_change = function (self, ind) - self.watchees[ind] = self.outputs[ind] and true or false - self:set_houtput(nil, ind) - self.oldcursors[ind] = -1 - self:dalos_hv_cb(self.extra.hv) - end, - - update_houtput = function (self, ind, cursor) - local h = self:get_linked_input(1) - local maxsize = h and h:getsize() or -1 - cursor = cursor + 0 - if cursor >= 0 and h and self.watchees[ind] then - if cursor < maxsize then - self:set_houtput(nil, ind) - end - local obj = { - h = h, - hvo = self, - ind = ind, - origin = cursor, - size = maxsize - cursor, - getname = function (self) return self.hvo.name .. ":" .. self.ind end, - getmodif = function (self) return self.hvo:getmodif() end, - do_seek = function (self) - self.h:seek(self.offset + self.origin) - end, - do_read = function (self, count, userdata) - return self.h:read(count, userdata) - end, - } - self:set_houtput(dalos.luahandle(obj), ind) - end - end, - - dalos_hv_cb = function (self, hv, reset) - local m - for i = 1, 10 do - m = hv.markers[i] - if m and self.oldcursors[i] ~= m then - self:update_houtput(i, m) - self.oldcursors[i] = m - end - end - - m = hv.kcursor - if m and self.oldcursors[11] ~= m then - self:update_houtput(11, m) - self.oldcursors[11] = m - end - - m = hv.mcursor - if m and self.oldcursors[12] ~= m then - self:update_houtput(12, m) - self.oldcursors[12] = m - end - end, - - create = function (d, tab, settings) - tab.otype = dalos.objtype.LUA_FILTER - tab.activate = dalosp.hexview.activate - tab.input_change = dalosp.hexview.input_change - tab.output_change = dalosp.hexview.output_change - tab.configure = dalosp.hexview.configure - tab.get_settings = dalosp.hexview.get_settings - tab.ninputs = 1 - tab.noutputs = 12 - tab.default_name = "Hexview" - tab.ntype = "Hexview" - - local extra = { } - - local obj = dalos.object(d, tab, extra) - - local hv = iupe.hexview { } - local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } - - extra.hv = hv - extra.hvtb = hvtb - extra.hvdlg = hvdlg - - obj.oldcursors = { } - obj.watchees = { } - obj.update_houtput = dalosp.hexview.update_houtput - for i = 1, 12 do obj.oldcursors[i] = -1 end - - if settings then - if settings.markers then - for i = 1, 10 do - if settings.markers[i] then hv.markers[i] = settings.markers[i] end - end - end - if settings.mcursor then hv.mcursor = settings.mcursor end - if settings.kcursor then hv.kcursor = settings.kcursor end - if settings.filecursor then hv.filecursor = settings.filecursor end - if settings.nbbytes then hv.nbbytes = settings.nbbytes end - if settings.nblines then hv.nblines = settings.nblines end - end - - hv:registercb(dalosp.hexview.dalos_hv_cb, obj) - obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb - - return obj - end, -} - -dalos.hexview = dalosp.hexview.create -dalos:register_obj("Hexview", dalos.hexview) +load "iupe-hexview.lua" +load "iupe-hexview-toolbox.lua" + +dalosp.hexview = { + activate = function (self) + self.extra.hvdlg:show() + end, + + input_change = function (self, ind) + local extra = self.extra + local hv = extra.hv + local h = self:get_linked_input(ind) + if not h then + self.color = cd.YELLOW + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + if not h:canread() or not h:canseek() then + self.color = cd.RED + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + self.color = cd.GREEN + for i = 1, 12 do + self:set_houtput(nil, i) + self.oldcursors[i] = -1 + end + hv:updatehandle(h) + self.dcanvas:draw() + end, + + configure = function (self) + end, + + get_settings = function (self) + local hv = extra.hv + local r = { + mcursor = hv.mcursor + 0, + kcursor = hv.kcursor + 0, + markers = {}, + filecursor = hv.filecursor + 0, + nbbytes = hv.nbbytes + 0, + nblines = hv.nblines + 0, + } + for i = 1, 10 do + r.markers[i] = hv.markers[i] + 0 + end + return r + end, + + output_change = function (self, ind) + self.watchees[ind] = self.outputs[ind] and true or false + self:set_houtput(nil, ind) + self.oldcursors[ind] = -1 + self:dalos_hv_cb(self.extra.hv) + end, + + update_houtput = function (self, ind, cursor) + local h = self:get_linked_input(1) + local maxsize = h and h:getsize() or -1 + cursor = cursor + 0 + if cursor >= 0 and h and self.watchees[ind] then + if cursor < maxsize then + self:set_houtput(nil, ind) + end + local obj = { + h = h, + hvo = self, + ind = ind, + origin = cursor, + size = maxsize - cursor, + getname = function (self) return self.hvo.name .. ":" .. self.ind end, + getmodif = function (self) return self.hvo:getmodif() end, + do_seek = function (self) + self.h:seek(self.offset + self.origin) + end, + do_read = function (self, count, userdata) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), ind) + end + end, + + dalos_hv_cb = function (self, hv, reset) + local m + for i = 1, 10 do + m = hv.markers[i] + if m and self.oldcursors[i] ~= m then + self:update_houtput(i, m) + self.oldcursors[i] = m + end + end + + m = hv.kcursor + if m and self.oldcursors[11] ~= m then + self:update_houtput(11, m) + self.oldcursors[11] = m + end + + m = hv.mcursor + if m and self.oldcursors[12] ~= m then + self:update_houtput(12, m) + self.oldcursors[12] = m + end + end, + + create = function (d, tab, settings) + tab.otype = dalos.objtype.LUA_FILTER + tab.activate = dalosp.hexview.activate + tab.input_change = dalosp.hexview.input_change + tab.output_change = dalosp.hexview.output_change + tab.configure = dalosp.hexview.configure + tab.get_settings = dalosp.hexview.get_settings + tab.ninputs = 1 + tab.noutputs = 12 + tab.default_name = "Hexview" + tab.ntype = "Hexview" + + local extra = { } + + local obj = dalos.object(d, tab, extra) + + local hv = iupe.hexview { } + local hvtb = iupe.hexview_toolbox { hexview = hv } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } + + extra.hv = hv + extra.hvtb = hvtb + extra.hvdlg = hvdlg + + obj.oldcursors = { } + obj.watchees = { } + obj.update_houtput = dalosp.hexview.update_houtput + for i = 1, 12 do obj.oldcursors[i] = -1 end + + if settings then + if settings.markers then + for i = 1, 10 do + if settings.markers[i] then hv.markers[i] = settings.markers[i] end + end + end + if settings.mcursor then hv.mcursor = settings.mcursor end + if settings.kcursor then hv.kcursor = settings.kcursor end + if settings.filecursor then hv.filecursor = settings.filecursor end + if settings.nbbytes then hv.nbbytes = settings.nbbytes end + if settings.nblines then hv.nblines = settings.nblines end + end + + hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb + + return obj + end, +} + +dalos.hexview = dalosp.hexview.create +dalos:register_obj("Hexview", dalos.hexview) diff --git a/dalos-input.lua b/dalos-input.lua index be2cf75..625dcab 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -1,44 +1,44 @@ -dalosp.input = { - get_settings = function (self) - return { filename = self.extra.filename } - end, - - configure = function (self) - local dlg = iup.filedlg { - dialogtype = "Open", - file = self.extra.filename, - } - iup.Popup(dlg) - if dlg.status ~= -1 then - local s, v = pcall(Input, dlg.value) - if s then - self:set_houtput(v) - return - end - end - self:set_houtput(nil) - end, - - create = function (d, tab, settings) - tab.ninputs = 0 - tab.noutputs = 1 - tab.otype = dalos.objtype.HANDLE - tab.configure = dalosp.input.configure - tab.default_name = "Input" - tab.ntype = "Input" - tab.get_settings = dalosp.input.get_settings - local extra = { } - if settings then extra.filename = settings.filename end - local obj = dalos.object(d, tab, extra) - - if extra.filename then - local s, v = pcall(Input, extra.filename) - if s then obj:set_houtput(v) end - end - - return obj - end, -} - -dalos.input = dalosp.input.create -dalos:register_obj("Input", dalos.input) +dalosp.input = { + get_settings = function (self) + return { filename = self.extra.filename } + end, + + configure = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + file = self.extra.filename, + } + iup.Popup(dlg) + if dlg.status ~= -1 then + local s, v = pcall(Input, dlg.value) + if s then + self:set_houtput(v) + return + end + end + self:set_houtput(nil) + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.configure = dalosp.input.configure + tab.default_name = "Input" + tab.ntype = "Input" + tab.get_settings = dalosp.input.get_settings + local extra = { } + if settings then extra.filename = settings.filename end + local obj = dalos.object(d, tab, extra) + + if extra.filename then + local s, v = pcall(Input, extra.filename) + if s then obj:set_houtput(v) end + end + + return obj + end, +} + +dalos.input = dalosp.input.create +dalos:register_obj("Input", dalos.input) diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 99bd07f..b8387e3 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -1,59 +1,59 @@ -dalosp.limiter = { - configure = function (self) - local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[ -Limit: %i{The actual size this limiter is going to produce} -]], self.op or 0, self.maximize and 1 or 0) - if accept then - self.extra.limit = limit - self:input_change() - end - end, - - get_settings = function (self) - return { limit = self.extra.limit } - end, - - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - local obj = { - h = h, - size = math.max(h:getsize(), self.limit), - getname = function () return self.name end, - do_read = function (self, count, userdata) - return self.h:read(count, userdata) - end, - do_seek = function (self) - self.h:seek(self.offset, SEEK_SET) - end, - } - self:set_houtput(dalos.luahandle(obj)) - self.dcanvas:draw() - else - self.color = cd.YELLOW - self:set_houtput(nil) - self.dcanvas:draw() - end - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.limiter.configure - tab.input_change = dalosp.limiter.input_change - tab.default_name = "Limiter" - tab.ntype = "Limiter" - tab.get_settings = dalosp.limiter.get_settings - local extra = { } - if settings then extra.limit = settings.limit end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.limiter = dalosp.limiter.create -dalos:register_obj("Limiter", dalos.limiter) +dalosp.limiter = { + configure = function (self) + local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[ +Limit: %i{The actual size this limiter is going to produce} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.extra.limit = limit + self:input_change() + end + end, + + get_settings = function (self) + return { limit = self.extra.limit } + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local obj = { + h = h, + size = math.max(h:getsize(), self.limit), + getname = function () return self.name end, + do_read = function (self, count, userdata) + return self.h:read(count, userdata) + end, + do_seek = function (self) + self.h:seek(self.offset, SEEK_SET) + end, + } + self:set_houtput(dalos.luahandle(obj)) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.limiter.configure + tab.input_change = dalosp.limiter.input_change + tab.default_name = "Limiter" + tab.ntype = "Limiter" + tab.get_settings = dalosp.limiter.get_settings + local extra = { } + if settings then extra.limit = settings.limit end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.limiter = dalosp.limiter.create +dalos:register_obj("Limiter", dalos.limiter) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index b267142..20f4f99 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -1,138 +1,138 @@ -dalosp.luafilter = { - default_code = [[ --- available globals: - --- ninputs, noutputs: numbers - --- get_input(ind): handle --- del_output(ind): nil --- new_output(ind): nil --- set_color(c) : nil - -function activate() -end - -function read(ind, count, userdata, offset) -end - -function seek(ind, offset) -end - -function input_change(ind) -end -]], - - get_settings = function (self) - return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code } - end, - - run_in_localenv = function (self, f, ...) - local localenv = self.extra.localenv - local metatable = getmetatable(_G) - if not metatable then metatable = {} end - local oldni, oldi = metatable.__newindex, metatable.__index - metatable.__newindex = function (table, key, value) --- print("Setting _G[" .. key .. "] = " .. tostring(value)) - localenv[key] = value - end - metatable.__index = function (table, key) --- print("Getting _G[" .. key .. "]") - local l = localenv[key] - if l then return localenv[key] end - return rawget(_G, key) - end - setmetatable(_G, metatable) - - if type(f) ~= "function" then f = localenv[f] end - local rets = { true } - if f then rets = { pcall(f, ...) } end - - metatable.__newindex, metatable.__index = oldni, oldi - setmetatable(_G, metatable) - - if not rets[1] then error(rets[2]) end - table.remove(rets, 1) - return unpack(rets) - end, - - load_code = function (self, code) - self.extra.localenv = { - ninputs = self.ninputs + 0, - noutputs = self.noutputs + 0, - get_input = function(ind) return self:get_linked_input(ind) end, - del_output = function(ind) self:set_houtput(nil, ind) end, - new_output = function(ind, size, name) - self:set_houtput(dalos.luahandle{ - size = size, - getname = function () - return name - end, - do_read = function (lh, count, userdata) - return self:run_in_localenv("read", ind, count, userdata, lh.offset) - end, - do_seek = function (lh) - return self:run_in_localenv("seek", ind, lh.offset) - end, - }, ind) - end, - set_color = function(c) self.color = c self:draw() end, - } - if code and code ~= "" then - local f = loadstring(code) - if f then self:run_in_localenv(f) end - end - end, - - input_change = function (self, ind) - self:run_in_localenv("input_change", ind) - end, - - configure = function (self) - local okay = false - local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } - local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } - local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } - local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } - local r = dlg:popup() --- if r ~= iup.NOERROR then return end - local newcode = text.value - if newcode and okay then - self.extra.code = newcode - self:load_code(newcode) - end - end, - - activate = function (self) - self:run_in_localenv "activate" - end, - - create = function (d, tab, settings) - tab.ninputs = settings and settings.ninputs - tab.noutputs = settings and settings.noutputs - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.luafilter.configure - tab.activate = dalosp.luafilter.activate - tab.input_change = dalosp.luafilter.input_change - tab.default_name = "Lua Filter" - tab.get_settings = dalosp.luafilter.get_settings - tab.ntype = "Lua Filter" - local extra = { localenv = {} } - extra.code = settings and settings.code - if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end - local s = true - while not s and not tab.ninputs or not tab.noutputs do - s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1) - end - - local obj = dalos.object(d, tab, extra) - - obj.load_code = dalosp.luafilter.load_code - obj.run_in_localenv = dalosp.luafilter.run_in_localenv - obj:load_code(extra.code) - - return obj - end, -} - -dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter) +dalosp.luafilter = { + default_code = [[ +-- available globals: + +-- ninputs, noutputs: numbers + +-- get_input(ind): handle +-- del_output(ind): nil +-- new_output(ind): nil +-- set_color(c) : nil + +function activate() +end + +function read(ind, count, userdata, offset) +end + +function seek(ind, offset) +end + +function input_change(ind) +end +]], + + get_settings = function (self) + return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code } + end, + + run_in_localenv = function (self, f, ...) + local localenv = self.extra.localenv + local metatable = getmetatable(_G) + if not metatable then metatable = {} end + local oldni, oldi = metatable.__newindex, metatable.__index + metatable.__newindex = function (table, key, value) +-- print("Setting _G[" .. key .. "] = " .. tostring(value)) + localenv[key] = value + end + metatable.__index = function (table, key) +-- print("Getting _G[" .. key .. "]") + local l = localenv[key] + if l then return localenv[key] end + return rawget(_G, key) + end + setmetatable(_G, metatable) + + if type(f) ~= "function" then f = localenv[f] end + local rets = { true } + if f then rets = { pcall(f, ...) } end + + metatable.__newindex, metatable.__index = oldni, oldi + setmetatable(_G, metatable) + + if not rets[1] then error(rets[2]) end + table.remove(rets, 1) + return unpack(rets) + end, + + load_code = function (self, code) + self.extra.localenv = { + ninputs = self.ninputs + 0, + noutputs = self.noutputs + 0, + get_input = function(ind) return self:get_linked_input(ind) end, + del_output = function(ind) self:set_houtput(nil, ind) end, + new_output = function(ind, size, name) + self:set_houtput(dalos.luahandle{ + size = size, + getname = function () + return name + end, + do_read = function (lh, count, userdata) + return self:run_in_localenv("read", ind, count, userdata, lh.offset) + end, + do_seek = function (lh) + return self:run_in_localenv("seek", ind, lh.offset) + end, + }, ind) + end, + set_color = function(c) self.color = c self:draw() end, + } + if code and code ~= "" then + local f = loadstring(code) + if f then self:run_in_localenv(f) end + end + end, + + input_change = function (self, ind) + self:run_in_localenv("input_change", ind) + end, + + configure = function (self) + local okay = false + local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } + local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } + local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local r = dlg:popup() +-- if r ~= iup.NOERROR then return end + local newcode = text.value + if newcode and okay then + self.extra.code = newcode + self:load_code(newcode) + end + end, + + activate = function (self) + self:run_in_localenv "activate" + end, + + create = function (d, tab, settings) + tab.ninputs = settings and settings.ninputs + tab.noutputs = settings and settings.noutputs + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.luafilter.configure + tab.activate = dalosp.luafilter.activate + tab.input_change = dalosp.luafilter.input_change + tab.default_name = "Lua Filter" + tab.get_settings = dalosp.luafilter.get_settings + tab.ntype = "Lua Filter" + local extra = { localenv = {} } + extra.code = settings and settings.code + if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end + local s = true + while not s and not tab.ninputs or not tab.noutputs do + s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1) + end + + local obj = dalos.object(d, tab, extra) + + obj.load_code = dalosp.luafilter.load_code + obj.run_in_localenv = dalosp.luafilter.run_in_localenv + obj:load_code(extra.code) + + return obj + end, +} + +dalos.luafilter = dalosp.luafilter.create +dalos:register_obj("Lua Filter", dalos.luafilter) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 332a90e..952f856 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -1,51 +1,51 @@ -dalosp.luahandle = { - create = function (tab) - local obj = { - offset = 0, - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, - getmodif = function (self) return 0 end, - flush = function (self) return true end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - if self.offset < 0 then self.offset = 0 end - if self.offset >= self.size then self.offset = self.size end - if self.do_seek then self:do_seek() end - return self.offset - end, - read = function (self, userdata, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - - local r, t = self:do_read(count, userdata) - self.offset = self.offset + r - return r, t - end, - } - for k, v in pairs(tab) do obj[k] = v end - local newh = HandleLua(obj) - obj.lh = newh - return newh - end, -} - -dalos.luahandle = dalosp.luahandle.create +dalosp.luahandle = { + create = function (tab) + local obj = { + offset = 0, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + if self.do_seek then self:do_seek() end + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r, t = self:do_read(count, userdata) + self.offset = self.offset + r + return r, t + end, + } + for k, v in pairs(tab) do obj[k] = v end + local newh = HandleLua(obj) + obj.lh = newh + return newh + end, +} + +dalos.luahandle = dalosp.luahandle.create diff --git a/dalos-tee.lua b/dalos-tee.lua index 5c9b26a..1d75fb2 100644 --- a/dalos-tee.lua +++ b/dalos-tee.lua @@ -1,50 +1,50 @@ -dalosp.tee = { - NTEE = 16, - - set_out = function (self, h, ind) - local name = h:getname() - local obj = { - h = h, - size = h:getsize(), - getname = function () return name end, - do_read = function (self, count, userdata) - self.h:seek(self.offset, SEEK_SET) - return self.h:read(count, userdata) - end, - } - self:set_houtput(dalos.luahandle(obj), ind) - end, - - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - for ind = 1, 16 do self:set_out(h, ind) end - self.dcanvas:draw() - else - self.color = cd.YELLOW - for i = 1, dalosp.tee.NTEE do - self:set_houtput(nil, i) - end - self.dcanvas:draw() - end - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = dalosp.tee.NTEE - tab.otype = dalos.objtype.LUA_FILTER - tab.input_change = dalosp.tee.input_change - tab.default_name = "Tee" - tab.ntype = "Tee" - - local obj = dalos.object(d, tab) - - obj.set_out = dalosp.tee.set_out - - return obj - end, -} - -dalos.tee = dalosp.tee.create -dalos:register_obj("Tee", dalos.tee) +dalosp.tee = { + NTEE = 16, + + set_out = function (self, h, ind) + local name = h:getname() + local obj = { + h = h, + size = h:getsize(), + getname = function () return name end, + do_read = function (self, count, userdata) + self.h:seek(self.offset, SEEK_SET) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), ind) + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + for ind = 1, 16 do self:set_out(h, ind) end + self.dcanvas:draw() + else + self.color = cd.YELLOW + for i = 1, dalosp.tee.NTEE do + self:set_houtput(nil, i) + end + self.dcanvas:draw() + end + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = dalosp.tee.NTEE + tab.otype = dalos.objtype.LUA_FILTER + tab.input_change = dalosp.tee.input_change + tab.default_name = "Tee" + tab.ntype = "Tee" + + local obj = dalos.object(d, tab) + + obj.set_out = dalosp.tee.set_out + + return obj + end, +} + +dalos.tee = dalosp.tee.create +dalos:register_obj("Tee", dalos.tee) diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index cd91689..a5a4f40 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -1,35 +1,35 @@ -dalosp.textbuffer = { - get_settings = function (self) - return { text = self.extra.text } - end, - - activate = function (self) - local text = self.extra.text or "" - text = iup.GetText(self.name, text) - if text then - self.extra.text = text - local b = Buffer(true) - b:write(text) - self:set_houtput(b) - end - end, - - create = function (d, tab, settings) - tab.ninputs = 0 - tab.noutputs = 1 - tab.otype = dalos.objtype.HANDLE - tab.activate = dalosp.textbuffer.activate - tab.default_name = "Text Buffer" - tab.ntype = "Text Buffer" - tab.get_settings = dalosp.textbuffer.get_settings - local extra = { } - if settings then extra.text = settings.text end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.textbuffer = dalosp.textbuffer.create -dalos:register_obj("Text Buffer", dalos.textbuffer) +dalosp.textbuffer = { + get_settings = function (self) + return { text = self.extra.text } + end, + + activate = function (self) + local text = self.extra.text or "" + text = iup.GetText(self.name, text) + if text then + self.extra.text = text + local b = Buffer(true) + b:write(text) + self:set_houtput(b) + end + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.activate = dalosp.textbuffer.activate + tab.default_name = "Text Buffer" + tab.ntype = "Text Buffer" + tab.get_settings = dalosp.textbuffer.get_settings + local extra = { } + if settings then extra.text = settings.text end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.textbuffer = dalosp.textbuffer.create +dalos:register_obj("Text Buffer", dalos.textbuffer) -- cgit v1.2.3 From 86df190bee91eb38038a39b98448dd1623db1b6f Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:25:32 +0100 Subject: Fixing limiter. --- dalos-limiter.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dalos-limiter.lua b/dalos-limiter.lua index b8387e3..5badfbb 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -19,7 +19,7 @@ Limit: %i{The actual size this limiter is going to produce} self.color = cd.GREEN local obj = { h = h, - size = math.max(h:getsize(), self.limit), + size = math.min(h:getsize(), self.extra.limit), getname = function () return self.name end, do_read = function (self, count, userdata) return self.h:read(count, userdata) @@ -47,7 +47,8 @@ Limit: %i{The actual size this limiter is going to produce} tab.ntype = "Limiter" tab.get_settings = dalosp.limiter.get_settings local extra = { } - if settings then extra.limit = settings.limit end + if not settings then settings = {} end + extra.limit = settings.limit or 0 local obj = dalos.object(d, tab, extra) -- cgit v1.2.3 From 7fea58bef326515437b3729c749fd22d85c62aaa Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 01:13:20 +0100 Subject: Adding category menus system. --- dalos-binaryops.lua | 2 +- dalos-buffer.lua | 2 +- dalos-hexview.lua | 2 +- dalos-input.lua | 2 +- dalos-limiter.lua | 2 +- dalos-luafilter.lua | 2 +- dalos-tee.lua | 2 +- dalos-textbuffer.lua | 2 +- dalos.lua | 49 +++++++++++++++++++++++++++++++++++++++++++------ 9 files changed, 51 insertions(+), 14 deletions(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 59e8361..c739450 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -111,4 +111,4 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} } dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) +dalos:register_obj("Binary Ops", dalos.binaryops, "Basic Filters") diff --git a/dalos-buffer.lua b/dalos-buffer.lua index 8abcadc..3743f46 100644 --- a/dalos-buffer.lua +++ b/dalos-buffer.lua @@ -27,4 +27,4 @@ dalosp.buffer = { } dalos.buffer = dalosp.buffer.create -dalos:register_obj("Buffer", dalos.buffer) +dalos:register_obj("Buffer", dalos.buffer, "Basic Filters") diff --git a/dalos-hexview.lua b/dalos-hexview.lua index cfd8652..79f2a08 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -157,4 +157,4 @@ dalosp.hexview = { } dalos.hexview = dalosp.hexview.create -dalos:register_obj("Hexview", dalos.hexview) +dalos:register_obj("Hexview", dalos.hexview, "Basic Viewers") diff --git a/dalos-input.lua b/dalos-input.lua index 625dcab..bf37b9d 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -41,4 +41,4 @@ dalosp.input = { } dalos.input = dalosp.input.create -dalos:register_obj("Input", dalos.input) +dalos:register_obj("Input", dalos.input, "Basic Inputs") diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 5badfbb..5643f30 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -57,4 +57,4 @@ Limit: %i{The actual size this limiter is going to produce} } dalos.limiter = dalosp.limiter.create -dalos:register_obj("Limiter", dalos.limiter) +dalos:register_obj("Limiter", dalos.limiter, "Basic Filters") diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 20f4f99..8181442 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -135,4 +135,4 @@ end } dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter) +dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable") diff --git a/dalos-tee.lua b/dalos-tee.lua index 1d75fb2..b5193c0 100644 --- a/dalos-tee.lua +++ b/dalos-tee.lua @@ -47,4 +47,4 @@ dalosp.tee = { } dalos.tee = dalosp.tee.create -dalos:register_obj("Tee", dalos.tee) +dalos:register_obj("Tee", dalos.tee, "Basic Filters") diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index a5a4f40..2bda77f 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -32,4 +32,4 @@ dalosp.textbuffer = { } dalos.textbuffer = dalosp.textbuffer.create -dalos:register_obj("Text Buffer", dalos.textbuffer) +dalos:register_obj("Text Buffer", dalos.textbuffer, "Basic Inputs") diff --git a/dalos.lua b/dalos.lua index d8169e5..8e95028 100644 --- a/dalos.lua +++ b/dalos.lua @@ -38,7 +38,7 @@ function dalos:register_obj(name, constructor, category) 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 or "Basic" }) + table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category }) self.objectstypes_by_name[name] = #self.objectstypes if self.activemenu then self.activemenu:update_objects() @@ -677,22 +677,59 @@ dalosp.menu = { local west_menu = { radio = "1" } local south_menu = { radio = "1" } local item + local add_submenus = { } + local north_submenus = { } + local east_submenus = { } + local west_submenus = { } + local south_submenus = { } + local category + local add_smenu, north_smenu, east_smenu, west_smenu, south_smenu + local categories = {} for k, v in ipairs(dalos.objectstypes) do + category = v.category + if category then + if not add_submenus[category] then + add_submenus[category] = { } + north_submenus[category] = { } + south_submenus[category] = { } + east_submenus[category] = { } + west_submenus[category] = { } + table.insert(categories, 1, category) + end + add_smenu = add_submenus[category] + north_smenu = north_submenus[category] + east_smenu = east_submenus[category] + west_smenu = west_submenus[category] + south_smenu = south_submenus[category] + else + add_smenu = add_menu + north_smenu = north_menu + east_smenu = east_menu + west_smenu = west_menu + south_smenu = south_menu + end item = iup.item { title = v.name } item.action = function (self) dalosp.menu.add_object(canvas, v) end - table.insert(add_menu, item) + table.insert(add_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end - table.insert(north_menu, item) + table.insert(north_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end - table.insert(east_menu, item) + table.insert(east_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end - table.insert(west_menu, item) + table.insert(west_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end - table.insert(south_menu, item) + table.insert(south_smenu, item) + end + for i, v in ipairs(categories) do + table.insert(add_menu, 1, iup.submenu { iup.menu(add_submenus[v]), title = v }) + table.insert(north_menu, 1, iup.submenu { iup.menu(north_submenus[v]), title = v }) + table.insert(south_menu, 1, iup.submenu { iup.menu(south_submenus[v]), title = v }) + table.insert(east_menu, 1, iup.submenu { iup.menu(east_submenus[v]), title = v }) + table.insert(west_menu, 1, iup.submenu { iup.menu(west_submenus[v]), title = v }) end local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } -- cgit v1.2.3 From 5fad64d07b6f28605c6f7c40cd65a04167186ae7 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 01:14:32 +0100 Subject: Inverting wheel behavior. --- dalos.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/dalos.lua b/dalos.lua index 8e95028..bf54c04 100644 --- a/dalos.lua +++ b/dalos.lua @@ -429,6 +429,7 @@ dalosp.canvas = { wheel_cb = function (self, delta, x, y, status) local obj = self:findobj(x, y) + delta = -delta if delta > 0 then delta = math.floor(delta + 0.5) else delta = -math.floor(-delta + 0.5) end if obj then -- cgit v1.2.3 From 0e6559318d7fafe1cc677e3a62e41666228d253b Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 12:10:41 +0100 Subject: Fixing the 'lost focus then click' issues. --- dalos.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dalos.lua b/dalos.lua index bf54c04..5cbe5d9 100644 --- a/dalos.lua +++ b/dalos.lua @@ -351,6 +351,7 @@ dalosp.canvas = { end else if not self.stateful.linking and self.stateful.leftclk and not self.stateful.dragging then + self.stateful.leftbutton = nil self.stateful.leftclk.obj:activate() elseif self.stateful.linking then local dest = self:findobj(x,y) @@ -392,6 +393,7 @@ dalosp.canvas = { end else if not self.stateful.moving and self.stateful.rghtclk and not self.stateful.dragging then + self.stateful.rghtbutton = nil self.stateful.rghtclk.obj:configure() self:draw() elseif self.menu.x then -- cgit v1.2.3 From 331a9e3c1153b49b5a6bd7246a0b600ab3b11db8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 14:14:50 +0100 Subject: Adding a status line, and a bunch of new status line displays. --- dalos.lua | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/dalos.lua b/dalos.lua index 5cbe5d9..c8d04df 100644 --- a/dalos.lua +++ b/dalos.lua @@ -33,6 +33,7 @@ dalosp.EAST = 4 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) if self.objectstypes_by_name[name] then @@ -237,7 +238,16 @@ dalosp.canvas = { }, setstatus = function (self, stype, msg) - -- todo: add a status line + local s = dalos.active_status + if not s then return end + if stype == dalos.stypes.INFO then + s.square.bgcolor = "0 255 0" + elseif stype == dalos.stypes.WARNING then + s.square.bgcolor = "255 255 0" + elseif stype == dalos.stypes.ERROR then + s.square.bgcolor = "255 0 0" + end + s.label.title = msg end, motion_cb = function (self, x, y, status) @@ -256,7 +266,7 @@ dalosp.canvas = { if linking.obj.noutputs >= 1 then self.stateful.linking = linking else - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: origin object doesn't have any output") + self:setstatus(dalos.stypes.ERROR, "Can't link: origin object doesn't have any output") self.stateful.leftclk = nil linking = nil got_error = true @@ -358,10 +368,11 @@ dalosp.canvas = { if not dest then self:destroylink(self.stateful.linking) elseif dest == self.stateful.linking then - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: origin is the same as destination") + self:setstatus(dalos.stypes.ERROR, "Can't link: origin is the same as destination") elseif dest.obj.ninputs <= 0 then - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: destination has no input") + self:setstatus(dalos.stypes.ERROR, "Can't link: destination has no input") else + self:setstatus(dalos.stypes.INFO, "Linking '" .. self.stateful.linking.name .. "' and '" .. dest.name .. "'") self:createlink(self.stateful.linking, dest) end self.stateful.linking = nil @@ -502,6 +513,13 @@ dalosp.canvas = { } dalosp.menu = { + action_new = function (self) + local d = dalos.active_canvas + dalos:clean() + + d:setstatus(dalos.stypes.INFO, "Workspace cleaned") + end, + action_load = function (self) local dlg = iup.filedlg { dialogtype = "Open", @@ -548,6 +566,8 @@ dalosp.menu = { if data.cross.west then dalosp.cross.west = tlup[data.cross.west] end if data.cross.east then dalosp.cross.east = tlup[data.cross.east] end end + + d:setstatus(dalos.stypes.INFO, "Properly loaded") end, action_save = function(self) @@ -590,6 +610,8 @@ dalosp.menu = { v:write "return save" end end + + d:setstatus(dalos.stypes.INFO, "Properly saved") end, load_file = function (file) @@ -610,6 +632,7 @@ dalosp.menu = { if dlg.status == -1 then return end dalosp.menu.load_file(dlg.value) + d:setstatus(dalos.stypes.INFO, "Properly imported") end, action_reload = function (self) @@ -618,6 +641,7 @@ dalosp.menu = { for i, v in ipairs(dalosp.imports) do pcall(load, v) end + d:setstatus(dalos.stypes.INFO, "Properly reloaded all imported files") end, action_exit = function (self) @@ -630,7 +654,7 @@ dalosp.menu = { ButtonDefault = "1", Buttons = "OK", Title = "About", - Value = 'DALOS ' .. dalos.version.MAJOR .. '.' .. dalos.version.MINOR .. dalos.version.suffix .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', + Value = 'DALOS ' .. dalos.version.string .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', } dlg:popup() return iup.DEFAULT @@ -662,6 +686,8 @@ dalosp.menu = { end, create = function (canvas, tab) + local item_new = iup.item { title = "New" } + item_new.action = dalosp.menu.action_new local item_load = iup.item { title = "Load" } item_load.action = dalosp.menu.action_load local item_save = iup.item { title = "Save" } @@ -734,7 +760,7 @@ dalosp.menu = { table.insert(east_menu, 1, iup.submenu { iup.menu(east_submenus[v]), title = v }) table.insert(west_menu, 1, iup.submenu { iup.menu(west_submenus[v]), title = v }) end - local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_new, item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, @@ -892,9 +918,36 @@ dalosp.object = { end, } +dalosp.status = { + create = function () + local r + + local s_square = iup.canvas { size = "10x", expand = "Vertical", border = "No", bgcolor = "0 255 0", } + local s_label = iup.label { expand = "Horizontal" } + + r = iup.frame { + iup.hbox { + s_square, + iup.label { separator = "Vertical" }, + s_label, + }, + expand = "Horizontal", + } + + r.square = s_square + r.label = s_label + + dalos.active_status = r + + return r + end, +} + dalos.canvas = dalosp.canvas.create dalos.menu = dalosp.menu.create dalos.object = dalosp.object.create +dalos.status = dalosp.status.create +dalos.stypes = dalosp.canvas.stypes dalos.objtype = { UNKNOWN = 0, @@ -919,13 +972,21 @@ load "dalos-luafilter.lua" ---------------- function dalos:main() + local d, m, s + d = self.canvas {} m = self.menu(d) + s = self.status() - dlg = iup.dialog { d, title = "Dalos", menu = m, size = "200x120" } + dlg = iup.dialog { iup.vbox { d, s }, title = "Dalos", menu = m, size = "400x250" } self.dialog = dlg + d:setstatus(dalos.stypes.INFO, "Dalos version " .. dalos.version.string .. " started") + + local old_error = error + error = function(...) d:setstatus(dalos.stypes.ERROR, "Got a Lua error") old_error(...) end + dlg:show() iup.MainLoop() dlg:hide() -- cgit v1.2.3 From f045d8db17b4c7c2ecfec2ef24039fdb350bab07 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 14:17:16 +0100 Subject: Second part of the "Focus click" issue. --- dalos.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos.lua b/dalos.lua index c8d04df..c966436 100644 --- a/dalos.lua +++ b/dalos.lua @@ -228,7 +228,7 @@ dalosp.canvas = { end, focus_cb = function (self, focus) - if focus == 0 and not self.stateful.rghtbutton and not self.stateful.leftbutton then self:button_cb() end + if focus == 0 and (self.stateful.rghtbutton or self.stateful.leftbutton) then self:button_cb() end end, stypes = { -- cgit v1.2.3 From c36c9d0a335f9dffd1baddced837557b4a669a79 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 17:17:07 +0100 Subject: A few bugfixes, and adding the template system. --- dalos-luafilter.lua | 25 ++++++++++++++++--- dalos.lua | 70 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 10 deletions(-) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 8181442..0abf40a 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -32,11 +32,9 @@ end if not metatable then metatable = {} end local oldni, oldi = metatable.__newindex, metatable.__index metatable.__newindex = function (table, key, value) --- print("Setting _G[" .. key .. "] = " .. tostring(value)) localenv[key] = value end metatable.__index = function (table, key) --- print("Getting _G[" .. key .. "]") local l = localenv[key] if l then return localenv[key] end return rawget(_G, key) @@ -87,12 +85,32 @@ end self:run_in_localenv("input_change", ind) end, + load_template = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + filter = "*.dtpl", + } + iup.Popup(dlg) + if dlg.status == -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) + if not f then error("Syntax error loading file " .. dlg.value) end + local data, otype, tname = f() + if otype ~= "Lua Filter" then error("Wrong template type: " .. otype) end + + self.extra.code = data.template.code + end, + configure = function (self) local okay = false local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } + local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end } + local bexport = iup.button { title = "Export", action = function() self:save_template{ code = self.extra.code } end } local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } - local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } local r = dlg:popup() -- if r ~= iup.NOERROR then return end local newcode = text.value @@ -128,6 +146,7 @@ end obj.load_code = dalosp.luafilter.load_code obj.run_in_localenv = dalosp.luafilter.run_in_localenv + obj.load_template = dalosp.luafilter.load_template obj:load_code(extra.code) return obj diff --git a/dalos.lua b/dalos.lua index c966436..cfe96c0 100644 --- a/dalos.lua +++ b/dalos.lua @@ -41,8 +41,8 @@ function dalos:register_obj(name, constructor, category) end table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category }) self.objectstypes_by_name[name] = #self.objectstypes - if self.activemenu then - self.activemenu:update_objects() + if self.active_menu then + self.active_menu:update_objects() end end @@ -523,6 +523,7 @@ dalosp.menu = { action_load = function (self) local dlg = iup.filedlg { dialogtype = "Open", + filter = "*.dalos" } iup.Popup(dlg) if dlg.status == -1 then return end @@ -598,6 +599,7 @@ dalosp.menu = { local save = { objects = s_obj, links = s_links, cross = s_cross, imports = dalosp.imports } local dlg = iup.filedlg { dialogtype = "Save", + dalos = "*.dalos", } iup.Popup(dlg) if dlg.status ~= -1 then @@ -608,6 +610,8 @@ dalosp.menu = { v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, save, "save") v:write "return save" + else + error("Failed opening " .. dlg.value .. " for writing") end end @@ -627,10 +631,12 @@ dalosp.menu = { action_import = function (self) local dlg = iup.filedlg { dialogtype = "Open", + filter = "*.lua", } iup.Popup(dlg) if dlg.status == -1 then return end + local d = dalos.active_canvas dalosp.menu.load_file(dlg.value) d:setstatus(dalos.stypes.INFO, "Properly imported") end, @@ -644,6 +650,30 @@ dalosp.menu = { d:setstatus(dalos.stypes.INFO, "Properly reloaded all imported files") end, + action_load_template = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + filter = "*.dtpl", + } + iup.Popup(dlg) + if dlg.status == -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) + if not f then error("Syntax error loading file " .. dlg.value) end + local data, otype, tname = f() + + local tobj = dalos.objectstypes_by_name[otype] + if not tobj then error("Unknown template object type: " .. otype) end + tobj = dalos.objectstypes[tobj] + + dalos:register_obj(otype .. "::" .. tname, function(d, tab) tobj.constructor(d, tab, data) end, "Template") + local d = dalos.active_canvas + + d:setstatus(dalos.stypes.INFO, "Template properly loaded") + end, + action_exit = function (self) return iup.CLOSE end, @@ -661,10 +691,11 @@ dalosp.menu = { end, update_objects = function (self) - if dalos.dlg then - local newmenu = dalos.menu {} + local d = dalos.active_canvas + if d and d.dialog then + local newmenu = dalos.menu(dalos.active_canvas) -- copy anything from self to newmenu ? *shrug* - dalos.dlg.menu = newmenu + d.dialog.menu = newmenu end end, @@ -696,6 +727,8 @@ dalosp.menu = { item_import.action = dalosp.menu.action_import local item_reload = iup.item { title = "Reload all" } item_reload.action = dalosp.menu.action_reload + local item_load_template = iup.item { title = "Load Template" } + item_load_template.action = dalosp.menu.action_load_template local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } @@ -760,7 +793,7 @@ dalosp.menu = { table.insert(east_menu, 1, iup.submenu { iup.menu(east_submenus[v]), title = v }) table.insert(west_menu, 1, iup.submenu { iup.menu(west_submenus[v]), title = v }) end - local menu_file = iup.submenu { iup.menu { item_new, item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_new, item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_load_template, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, @@ -861,6 +894,28 @@ dalosp.object = { return {} end, + save_template = function (self, template) + local dlg = iup.filedlg { + dialogtype = "Save", + filter = "*.dtpl", + } + iup.Popup(dlg) + if dlg.status == -1 then return end + local s, name, v + s, name = iup.GetParam("Export template", nil, "Template name: %s\n", "") + if not s then return end + s, v = pcall(Output, dlg.value) + if s then + v:write "---- Dalos template\nlocal " + dumpvars(v, dalos.version, "version") + v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " + dumpvars(v, template, "template") + v:write("return template, '" .. self.ntype .. "', '" .. name .. "'") + else + error("Failed opening " .. dlg.value .. " for writing") + end + end, + create = function (dcanvas, tab, extra) if not tab then tab = {} end if not tab.name then @@ -895,6 +950,7 @@ dalosp.object = { get_settings = tab.get_settings or dalosp.object.default_get_settings, houtputs = {}, get_linked_input = dalosp.object.get_linked_input, + save_template = dalosp.object.save_template, dcanvas = dcanvas, } @@ -980,7 +1036,7 @@ function dalos:main() dlg = iup.dialog { iup.vbox { d, s }, title = "Dalos", menu = m, size = "400x250" } - self.dialog = dlg + d.dialog = dlg d:setstatus(dalos.stypes.INFO, "Dalos version " .. dalos.version.string .. " started") -- cgit v1.2.3 From c050ff847539caa3c227ae5f703a3ca178b9979e Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 18:38:08 +0100 Subject: Trying to be a little bit nicer with the ressources. --- dalos-luafilter.lua | 1 + dalos.lua | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 0abf40a..c0b307e 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -96,6 +96,7 @@ 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 ~= "Lua Filter" then error("Wrong template type: " .. otype) end diff --git a/dalos.lua b/dalos.lua index cfe96c0..d1c4008 100644 --- a/dalos.lua +++ b/dalos.lua @@ -531,6 +531,7 @@ dalosp.menu = { 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 = f() local tlup = dalos.objectstypes_by_name @@ -610,6 +611,7 @@ dalosp.menu = { v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, save, "save") v:write "return save" + v:destroy() else error("Failed opening " .. dlg.value .. " for writing") end @@ -661,6 +663,7 @@ dalosp.menu = { 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() @@ -911,6 +914,7 @@ dalosp.object = { v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, template, "template") v:write("return template, '" .. self.ntype .. "', '" .. name .. "'") + v:destroy() else error("Failed opening " .. dlg.value .. " for writing") end -- cgit v1.2.3 From 00bd9d1299f954b6776429e6b91159649fa1ccf9 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 24 Dec 2009 00:16:39 +0100 Subject: Small bugfix. --- dalos.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos.lua b/dalos.lua index d1c4008..bd0e2a7 100644 --- a/dalos.lua +++ b/dalos.lua @@ -372,7 +372,7 @@ dalosp.canvas = { elseif dest.obj.ninputs <= 0 then self:setstatus(dalos.stypes.ERROR, "Can't link: destination has no input") else - self:setstatus(dalos.stypes.INFO, "Linking '" .. self.stateful.linking.name .. "' and '" .. dest.name .. "'") + self:setstatus(dalos.stypes.INFO, "Linking '" .. self.stateful.linking.obj.name .. "' and '" .. dest.obj.name .. "'") self:createlink(self.stateful.linking, dest) end self.stateful.linking = nil -- cgit v1.2.3 From dc22c96581d74e353b722edd903ee1c5eeb67414 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 24 Dec 2009 19:24:55 +0100 Subject: Adding more hexview configuration items, and adding the ability of the hexviewer to display read limits, somehow. --- dalos-hexview.lua | 49 +++++++++++++++++++++++++++++++++++++++++++------ dalos-luahandle.lua | 1 + iupe-hexview.lua | 23 ++++++++++++++++++----- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 79f2a08..0ee8a8c 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -32,17 +32,38 @@ dalosp.hexview = { end, configure = function (self) + local s, newname, gsx, gsy, dgsx, dgsy, dl, ml = + iup.GetParam(self.name .. " properties", nil, [[ +Name: %s +Gridsize X: %i +Gridsize Y: %i +Default gridsize X: %i +Default gridsize Y: %i +Lines: %i +Marker lengths: %b +]], + self.name, self.extra.hv.gridsize.x, self.extra.hv.gridsize.y, iupep.hexview.gridsize.x, iupep.hexview.gridsize.y, + self.extra.hv.displaylines, self.extra.hv.showmarkerslengths and 1 or 0) + if not s then return end + self.name = newname + self.extra.hv.gridsize.x = gsx + self.extra.hv.gridsize.y = gsy + iupep.hexview.gridsize.x = dgsx + iupep.hexview.gridsize.y = dgsy + self.extra.hv.displaylines = dl + self.extra.hv.showmarkerslengths = ml == 1 end, get_settings = function (self) - local hv = extra.hv + local hv = self.extra.hv local r = { mcursor = hv.mcursor + 0, kcursor = hv.kcursor + 0, markers = {}, filecursor = hv.filecursor + 0, - nbbytes = hv.nbbytes + 0, - nblines = hv.nblines + 0, + displaylines = hv.displaylines + 0, + gridsize = hv.gridsize, + showmarkerslengths = hv.showmarkerslengths, } for i = 1, 10 do r.markers[i] = hv.markers[i] + 0 @@ -51,6 +72,7 @@ dalosp.hexview = { end, output_change = function (self, ind) + self.extra.hv.markerslengths[ind] = 0 self.watchees[ind] = self.outputs[ind] and true or false self:set_houtput(nil, ind) self.oldcursors[ind] = -1 @@ -58,13 +80,16 @@ dalosp.hexview = { end, update_houtput = function (self, ind, cursor) + local hv = self.extra.hv local h = self:get_linked_input(1) local maxsize = h and h:getsize() or -1 cursor = cursor + 0 if cursor >= 0 and h and self.watchees[ind] then - if cursor < maxsize then + if cursor >= maxsize then self:set_houtput(nil, ind) + return end + h:seek(cursor) local obj = { h = h, hvo = self, @@ -75,10 +100,21 @@ dalosp.hexview = { getmodif = function (self) return self.hvo:getmodif() end, do_seek = function (self) self.h:seek(self.offset + self.origin) + self:post_read() end, do_read = function (self, count, userdata) return self.h:read(count, userdata) end, + post_read = function (self, count) + local ol = hv.markerslengths[ind] + local nl = self.offset + if nl > ol then + hv.markerslengths[ind] = nl + if hv.showmarkerslengths then + hv:draw() + end + end + end, } self:set_houtput(dalos.luahandle(obj), ind) end @@ -145,8 +181,9 @@ dalosp.hexview = { if settings.mcursor then hv.mcursor = settings.mcursor end if settings.kcursor then hv.kcursor = settings.kcursor end if settings.filecursor then hv.filecursor = settings.filecursor end - if settings.nbbytes then hv.nbbytes = settings.nbbytes end - if settings.nblines then hv.nblines = settings.nblines end + if settings.displaylines then hv.displaylines = settings.displaylines end + if settings.gridsize then hv.gridsize.x, hv.gridsize.y = settings.gridsize.x, settings.gridsize.y end + if settings.showmarkerslengths then hv.showmarkerslengths = settings.showmarkerslengths end end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 952f856..d3615fc 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -38,6 +38,7 @@ dalosp.luahandle = { local r, t = self:do_read(count, userdata) self.offset = self.offset + r + if self.post_read then self:post_read(r) end return r, t end, } diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 1d5f9e3..fb02b68 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -34,6 +34,8 @@ markercolors = { } iupep.hexview = { + gridsize = { x = 8, y = 14 }, + printgrid = function (self, msg, y, x) local cvdb = self.cvdb if not x then x = self.textcursor.x end @@ -116,15 +118,24 @@ iupep.hexview = { self:colorgrid(cursorcolors.GREEN, 2, kline, kcolumn * 3 + 10) self:colorgrid(cursorcolors.GREEN, 1, kline, kcolumn + 12 + columns * 3) - local marker + local marker, len, mlen for i = 0, 10 do marker = self.markers[i] or -1 marker = marker - filecursor - if marker >= 0 and marker < nbbytes then + mlen = self.markerslengths[i] + if marker >= 0 and self.showmarkerslengths and mlen and mlen > 0 then + len = math.min(mlen, nbbytes - marker) + elseif marker >= 0 and marker < nbbytes then + len = 1 + else + len = 0 + end + for j = 1, len do mline = math.floor(marker / columns) mcolumn = marker % columns self:colorgrid(markercolors[i], 2, mline, mcolumn * 3 + 10) self:colorgrid(markercolors[i], 1, mline, mcolumn + 12 + columns * 3) + marker = marker + 1 end end @@ -522,7 +533,7 @@ iupep.hexview = { end, updategridsize = function (self, gridsize) - self.gridsize = gridsize or { x = 8, y = 14 } + self.gridsize = gridsize or iupep.hexview.gridsize self:resize_cb(self.width, self.height) end, @@ -575,9 +586,11 @@ iupep.hexview = { r.filesize = handle and handle:getsize() or 0 r.mcursor = -1 r.markers = {} - r.displaylines = -1 + r.markerslengths = {} + r.showmarkerslengths = false + r.displaylines = 0 for i = 0, 10 do r.markers[i] = -1 end - r.gridsize = gridsize or { x = 8, y = 14 } + r.gridsize = gridsize or iupep.hexview.gridsize r.textcursor = { x = 0, y = 0 } return r end, -- cgit v1.2.3 From b4d032edc4aabbb80b8bc3386a820848df3391ac Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 24 Dec 2009 23:04:39 +0100 Subject: Adding a few pictures. --- 12-em-cross.tga | Bin 0 -> 462 bytes 12-em-down.tga | Bin 0 -> 356 bytes 12-em-plus.tga | Bin 0 -> 342 bytes 12-em-up.tga | Bin 0 -> 334 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 12-em-cross.tga create mode 100644 12-em-down.tga create mode 100644 12-em-plus.tga create mode 100644 12-em-up.tga diff --git a/12-em-cross.tga b/12-em-cross.tga new file mode 100644 index 0000000..06f0531 Binary files /dev/null and b/12-em-cross.tga differ diff --git a/12-em-down.tga b/12-em-down.tga new file mode 100644 index 0000000..3416152 Binary files /dev/null and b/12-em-down.tga differ diff --git a/12-em-plus.tga b/12-em-plus.tga new file mode 100644 index 0000000..337e3c5 Binary files /dev/null and b/12-em-plus.tga differ diff --git a/12-em-up.tga b/12-em-up.tga new file mode 100644 index 0000000..2ca9149 Binary files /dev/null and b/12-em-up.tga differ -- cgit v1.2.3 From 4a5125c1ccb121bfe739c26926fe8ed7de634d32 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 25 Dec 2009 15:17:18 +0100 Subject: Fixing the binary ops output. --- dalos-binaryops.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index c739450..e4c6ed9 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -51,7 +51,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} local t1, r1 = self.h1:read(count) local t2, r2 = self.h2:read(count) - local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) + local r = self.maximize and math.max(r1, r2) or math.min(r1, r2) self.offset = self.offset + r if r == 0 then self.got_eof = true return 0 end local t = {} -- cgit v1.2.3 From c267d9769c2bf5fd56684b51b7e90f1d7093614c Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 25 Dec 2009 21:03:28 +0100 Subject: Switching template generation to a more generic system. --- dalos-luafilter.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index c0b307e..0d83fb4 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -104,12 +104,16 @@ end self.extra.code = data.template.code end, + gen_template = function (self) + return { code = self.extra.close } + end, + configure = function (self) local okay = false local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end } - local bexport = iup.button { title = "Export", action = function() self:save_template{ code = self.extra.code } end } + local bexport = iup.button { title = "Export", action = function() self:save_template(self:gen_template()) end } local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } local r = dlg:popup() @@ -148,6 +152,7 @@ end obj.load_code = dalosp.luafilter.load_code obj.run_in_localenv = dalosp.luafilter.run_in_localenv obj.load_template = dalosp.luafilter.load_template + obj.gen_template = dalosp.luafilter.gen_template obj:load_code(extra.code) return obj -- cgit v1.2.3 From dc20bb4220f59f32309388de0edc6ebf41ab3e35 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 25 Dec 2009 21:04:27 +0100 Subject: Adding struct skeleton. --- dalos-struct.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 70 insertions(+) create mode 100644 dalos-struct.lua diff --git a/dalos-struct.lua b/dalos-struct.lua new file mode 100644 index 0000000..3451319 --- /dev/null +++ b/dalos-struct.lua @@ -0,0 +1,69 @@ +dalosp.struct = { + images = { + up = iup.LoadImage "12-em-up.tga", + down = iup.LoadImage "12-em-down.tga", + cross = iup.LoadImage "12-em-cross.tga", + plus = iup.LoadImage "12-em-plus.tga", + }, + + get_settings = function (self) + end, + + configure = function (self) + self.cfg_dlg:popup() + end, + + activate = function (self) + self.actv_dlg:show() + end, + + input_change = function (self) + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 0 + tab.otype = dalos.objtype.LUA_VIEWER + tab.configure = dalosp.struct.configure + tab.activate = dalosp.struct.activate + tab.input_change = dalosp.struct.input_change + tab.get_settings = dalosp.struct.get_settings + tab.default_name = "Struct" + tab.ntype = "Struct" + + local extra = { } + if not settings then settings = {} end + + local obj = dalos.object(d, tab, extra) + + local cmx = iup.matrix {} + cmx.draw_cb = dalosp.struct.cfg_draw_cb + + obj.cfg_dlg = iup.dialog { + iup.vbox { + cmx, + iup.hbox { + iup.fill {}, + iup.button { + title = "Ok", + action = function (self) return iup.CLOSE end + }, + iup.fill {}, + }, + }, + } + + obj.cfg_dlg.mx = cmx + + local amx = iup.matrix {} + + obj.actv_dlg = iup.dialog { + amx, + } + + return obj + end, +} + +dalos.struct = dalosp.struct.create +dalos:register_obj("Struct", dalos.struct, "Programmable") diff --git a/dalos.lua b/dalos.lua index bd0e2a7..9846f72 100644 --- a/dalos.lua +++ b/dalos.lua @@ -1028,6 +1028,7 @@ load "dalos-input.lua" load "dalos-tee.lua" load "dalos-buffer.lua" load "dalos-luafilter.lua" +load "dalos-struct.lua" ---------------- -- cgit v1.2.3 From 92cdbe1ba01767bc95358696cc7a741a67b2c889 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 26 Dec 2009 01:11:16 +0100 Subject: Adding a little bit more output on the configuration matrix. --- dalos-struct.lua | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 8 deletions(-) diff --git a/dalos-struct.lua b/dalos-struct.lua index 3451319..350e329 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -1,9 +1,31 @@ +local function imLoadImage(fname) + local f = im.FileOpen(fname) + local r = f:LoadImage() + f:Close() + return r +end + dalosp.struct = { images = { - up = iup.LoadImage "12-em-up.tga", - down = iup.LoadImage "12-em-down.tga", - cross = iup.LoadImage "12-em-cross.tga", - plus = iup.LoadImage "12-em-plus.tga", + up = imLoadImage "12-em-up.tga", + down = imLoadImage "12-em-down.tga", + cross = imLoadImage "12-em-cross.tga", + plus = imLoadImage "12-em-plus.tga", + }, + + types = { + "int8", + "uint8", + "int16", + "uint16", + "int32", + "uint32", + "int64", + "uint64", + "float", + "double", + "asciiz", + "nascii", }, get_settings = function (self) @@ -20,6 +42,76 @@ dalosp.struct = { input_change = function (self) end, + cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) + if col == 1 then + dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 2 and lin ~= 0 then + dalosp.struct.images.cross:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 3 and lin ~= 0 then + dalosp.struct.images.up:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 4 and lin ~= 0 then + dalosp.struct.images.down:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + end + + return iup.IGNORE + end, + + cfg_click_cb = function (self, lin, col, status) + if col == 1 and lin == 0 then return self.struct:insert_line() end + end, + + cfg_value_cb = function (self, lin, col) + if lin == 0 then + if col == 5 then + return "Name" + elseif col == 6 then + return "Type" + elseif col == 7 then + return "Size" + elseif col == 8 then + return "CumSize" + end + end + + return "" + end, + + cfg_value_edit_cb = function (self, lin, col, newval) + end, + + insert_line = function (self) + local mx = self.cfg_dlg.mx + mx.numlin = mx.numlin + 1 + mx.numlin_visible = mx.numlin_visible + 1 + end, + + cfg_dropcheck_cb = function (self, lin, col) + return col == 6 and iup.DEFAULT or iup.IGNORE + end, + + cfg_edition_cb = function (self, lin, col, mode, update) + if mode == 1 then + return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE + else + return iup.DEFAULT + end + end, + + cfg_drop_cb = function (self, drop, lin, col) + if col ~= 6 then return iup.IGNORE end + + for i, v in ipairs(dalosp.struct.types) do + drop[i] = v + end + drop.value = self.previousvalue + + return iup.DEFAULT + end, + create = function (d, tab, settings) tab.ninputs = 1 tab.noutputs = 0 @@ -28,6 +120,9 @@ dalosp.struct = { tab.activate = dalosp.struct.activate tab.input_change = dalosp.struct.input_change tab.get_settings = dalosp.struct.get_settings + tab.draw = function (self, cv, x, y, w, h) + dalosp.object.default_draw(self, cv, x, y, w, h) + end tab.default_name = "Struct" tab.ntype = "Struct" @@ -36,8 +131,32 @@ dalosp.struct = { local obj = dalos.object(d, tab, extra) - local cmx = iup.matrix {} - cmx.draw_cb = dalosp.struct.cfg_draw_cb + obj.insert_line = dalosp.struct.insert_line + + local cmx = iup.matrix { + numcol = 8, + numcol_visible = 8, + usetitlesize = "Yes", + rasterwidth1 = 12, + rasterwidth2 = 12, + rasterwidth3 = 12, + rasterwidth4 = 12, + rasterwidth5 = 150, + rasterwidth6 = 80, + rasterwidth7 = 80, + rasterwidth8 = 80, + resizematrix = "Yes", + readonly = "No", + draw_cb = dalosp.struct.cfg_draw_cb, + value_cb = dalosp.struct.cfg_value_cb, + value_edit_cb = dalosp.struct.cfg_value_edit_cb, + dropcheck_cb = dalosp.struct.cfg_dropcheck_cb, + drop_cb = dalosp.struct.cfg_drop_cb, + edition_cb = dalosp.struct.cfg_edition_cb, + click_cb = dalosp.struct.cfg_click_cb, + struct = obj, + } + local amx = iup.matrix {} obj.cfg_dlg = iup.dialog { iup.vbox { @@ -51,12 +170,12 @@ dalosp.struct = { iup.fill {}, }, }, + + size = "350x120", } obj.cfg_dlg.mx = cmx - local amx = iup.matrix {} - obj.actv_dlg = iup.dialog { amx, } -- cgit v1.2.3 From 1325aa091d6061913969d6e45775cf5d032c833b Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 26 Dec 2009 13:56:59 +0100 Subject: More work on the struct configuration dialog. --- dalos-struct.lua | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++----- dalos.lua | 2 +- 2 files changed, 204 insertions(+), 19 deletions(-) diff --git a/dalos-struct.lua b/dalos-struct.lua index 350e329..7d6b8b0 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -24,8 +24,27 @@ dalosp.struct = { "uint64", "float", "double", - "asciiz", "nascii", + "asciiz", + }, + + rtypes = { + int8 = 1, + uint8 = 2, + int16 = 3, + uint16 = 4, + int32 = 5, + uint32 = 6, + int64 = 7, + uint64 = 8, + float = 9, + double = 10, + nascii = 11, + asciiz = 12, + }, + + typessizes = { + 1, 1, 2, 2, 4, 4, 8, 8, 4, 8, 1, -1, }, get_settings = function (self) @@ -42,6 +61,96 @@ dalosp.struct = { input_change = function (self) end, + offset = function (self, lin) + local cache = self.extra.cache + return cache[lin] + end, + + cacheoffset = function (self) + local entries = self.extra.entries + self.extra.cache = {} + local cache = self.extra.cache + local offset = 0 + local got_var = false + local ssize + local vsize + + for i, v in ipairs(entries) do + ssize = dalosp.struct.typessizes[v.type] + vsize = ssize == -1 or type(v.size) ~= "number" + if vsize then got_var = true end + if got_var then + cache[i] = -1 + else + cache[i] = offset + end + if not vsize then offset = offset + ssize * v.size end + end + self.extra.size = offset + if self.cfg_dlg then + self.cfg_dlg.mx.redraw = "C10" + self.cfg_dlg.lsize.title = offset + end + end, + + isunique = function (self, name) + for _, v in ipairs(self.extra.entries) do + if name == v.name then return false end + end + return true + end, + + getunique = function (self, lin) + local newname = "Field" .. lin + local base_newname = newname + local i = 1 + while not self:isunique(newname) do + newname = base_newname .. "." .. i + i = i + 1 + end + return newname + end, + + insert_line = function (self, lin) + if not lin then lin = (#self.extra.entries + 1) end + local name = self:getunique(lin) + table.insert(self.extra.entries, lin, { name = name, type = 1, size = 1 }) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.numlin = mx.numlin + 1 + mx.numlin_visible = mx.numlin_visible + 1 + end, + + remove_line = function (self, lin) + table.remove(self.extra.entries, lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.numlin = mx.numlin - 1 + mx.numlin_visible = mx.numlin_visible - 1 + end, + + line_up = function (self, lin) + if lin == 1 then return iup.DEFAULT end + local entries = self.extra.entries + local old_lin = entries[lin] + table.remove(entries, lin) + table.insert(entries, lin - 1, old_lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.redraw = "All" + end, + + line_down = function (self, lin) + local entries = self.extra.entries + if lin == #entries then return iup.DEFAULT end + local old_lin = entries[lin] + table.remove(entries, lin) + table.insert(entries, lin + 1, old_lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.redraw = "All" + end, + cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) if col == 1 then dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) @@ -49,10 +158,10 @@ dalosp.struct = { elseif col == 2 and lin ~= 0 then dalosp.struct.images.cross:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) return iup.DEFAULT - elseif col == 3 and lin ~= 0 then + elseif col == 3 and lin ~= 0 and lin ~= 1 then dalosp.struct.images.up:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) return iup.DEFAULT - elseif col == 4 and lin ~= 0 then + elseif col == 4 and lin ~= 0 and lin ~= #self.struct.extra.entries then dalosp.struct.images.down:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) return iup.DEFAULT end @@ -62,6 +171,17 @@ dalosp.struct = { cfg_click_cb = function (self, lin, col, status) if col == 1 and lin == 0 then return self.struct:insert_line() end + if lin == 0 then return iup.DEFAULT end + + if col == 1 then + self.struct:insert_line(lin) + elseif col == 2 then + self.struct:remove_line(lin) + elseif col == 3 then + self.struct:line_up(lin) + elseif col == 4 then + self.struct:line_down(lin) + end end, cfg_value_cb = function (self, lin, col) @@ -73,22 +193,50 @@ dalosp.struct = { elseif col == 7 then return "Size" elseif col == 8 then - return "CumSize" + return "Enum" + elseif col == 9 then + return "Value Check" + elseif col == 10 then + return "Offset" end + return "" + end + + local entries = self.struct.extra.entries + + if col == 5 then + return entries[lin].name + elseif col == 6 then + return dalosp.struct.types[entries[lin].type] + elseif col == 7 then + return entries[lin].size + elseif col == 10 then + return self.struct:offset(lin) end return "" end, cfg_value_edit_cb = function (self, lin, col, newval) + local entries = self.struct.extra.entries + + if col == 5 then + entries[lin].name = newval + elseif col == 6 then + entries[lin].type = dalosp.struct.rtypes[newval] + self.struct:cacheoffset() + elseif col == 7 then + local nnewval = tonumber(newval) + if nnewval then newval = nnewval end + entries[lin].size = nnewval + self.struct:cacheoffset() + elseif col == 8 then + -- enum + elseif col == 9 then + -- value check + end end, - insert_line = function (self) - local mx = self.cfg_dlg.mx - mx.numlin = mx.numlin + 1 - mx.numlin_visible = mx.numlin_visible + 1 - end, - cfg_dropcheck_cb = function (self, lin, col) return col == 6 and iup.DEFAULT or iup.IGNORE end, @@ -97,6 +245,18 @@ dalosp.struct = { if mode == 1 then return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE else + if update == 0 then return iup.DEFAULT end + if col == 5 then + -- lookup duplicates in names + elseif col == 6 then + -- do a check on the dropdown ? I don't think so + elseif col == 7 then + -- do a check on the size; can be the name of another field + elseif col == 8 then + -- enum + elseif col == 9 then + -- value check + end return iup.DEFAULT end end, @@ -108,13 +268,14 @@ dalosp.struct = { drop[i] = v end drop.value = self.previousvalue + drop.visible_items = 15 return iup.DEFAULT end, create = function (d, tab, settings) tab.ninputs = 1 - tab.noutputs = 0 + tab.noutputs = 1 tab.otype = dalos.objtype.LUA_VIEWER tab.configure = dalosp.struct.configure tab.activate = dalosp.struct.activate @@ -128,23 +289,35 @@ dalosp.struct = { local extra = { } if not settings then settings = {} end + extra.entries = settings.entries or {} local obj = dalos.object(d, tab, extra) obj.insert_line = dalosp.struct.insert_line + obj.remove_line = dalosp.struct.remove_line + obj.line_up = dalosp.struct.line_up + obj.line_down = dalosp.struct.line_down + obj.offset = dalosp.struct.offset + obj.cacheoffset = dalosp.struct.cacheoffset + obj.isunique = dalosp.struct.isunique + obj.getunique = dalosp.struct.getunique + + obj:cacheoffset() local cmx = iup.matrix { - numcol = 8, - numcol_visible = 8, + numcol = 10, + numcol_visible = 10, usetitlesize = "Yes", rasterwidth1 = 12, rasterwidth2 = 12, rasterwidth3 = 12, rasterwidth4 = 12, - rasterwidth5 = 150, + rasterwidth5 = 120, rasterwidth6 = 80, rasterwidth7 = 80, rasterwidth8 = 80, + rasterwidth9 = 120, + rasterwidth10 = 40, resizematrix = "Yes", readonly = "No", draw_cb = dalosp.struct.cfg_draw_cb, @@ -156,10 +329,22 @@ dalosp.struct = { click_cb = dalosp.struct.cfg_click_cb, struct = obj, } - local amx = iup.matrix {} + local amx = iup.matrix { + numcol = 2, + numcol_visible = 2, + usetitlesize = "Yes", + rasterwidth1 = 120, + rasterwidth2 = 120, + struct = obj, + } + local lsize = iup.label { title = "0", expand = "Horizontal", } obj.cfg_dlg = iup.dialog { iup.vbox { + iup.hbox { + iup.label { title = "Struct size: " }, + lsize, + }, cmx, iup.hbox { iup.fill {}, @@ -171,11 +356,11 @@ dalosp.struct = { }, }, - size = "350x120", + size = "450x220", + mx = cmx, + lsize = lsize } - obj.cfg_dlg.mx = cmx - obj.actv_dlg = iup.dialog { amx, } diff --git a/dalos.lua b/dalos.lua index 9846f72..c13ffd3 100644 --- a/dalos.lua +++ b/dalos.lua @@ -816,7 +816,7 @@ dalosp.menu = { } dalosp.object = { - default_draw = function (self, cv, x, y, w, h ) + 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) local cx, cy = (x1 + x2) / 2, (y1 + y2) / 2 -- cgit v1.2.3 From ef0404604e36a45ea950439c2396eb0ea3b5bdf9 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 26 Dec 2009 20:15:19 +0100 Subject: Template system rework. --- dalos-luafilter.lua | 19 +++++++++++++++---- dalos-struct.lua | 34 ++++++++++++++++++++++++++++++++-- dalos.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 0d83fb4..9c87f93 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -1,4 +1,6 @@ dalosp.luafilter = { + templates = {}, + default_code = [[ -- available globals: @@ -101,21 +103,26 @@ end local data, otype, tname = f() if otype ~= "Lua Filter" then error("Wrong template type: " .. otype) end - self.extra.code = data.template.code + self:apply_template(data.template) end, gen_template = function (self) return { code = self.extra.close } end, + apply_template = function (self, data) + self.extra.code = data.code + end, + configure = function (self) local okay = false local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end } local bexport = iup.button { title = "Export", action = function() self:save_template(self:gen_template()) end } + local busetpl = iup.button { title = "Use Template", action = function() self:use_template() end } local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } - local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, busetpl, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } local r = dlg:popup() -- if r ~= iup.NOERROR then return end local newcode = text.value @@ -151,13 +158,17 @@ end obj.load_code = dalosp.luafilter.load_code obj.run_in_localenv = dalosp.luafilter.run_in_localenv - obj.load_template = dalosp.luafilter.load_template obj.gen_template = dalosp.luafilter.gen_template + obj.apply_template = dalosp.luafilter.apply_template obj:load_code(extra.code) return obj end, + + register_template = function (data, tname) + dalosp.luafilters.templates[tname] = data + end, } dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable") +dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable", dalosp.luafilter.register_template) diff --git a/dalos-struct.lua b/dalos-struct.lua index 7d6b8b0..0835b7d 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -6,6 +6,8 @@ local function imLoadImage(fname) end dalosp.struct = { + templates = {}, + images = { up = imLoadImage "12-em-up.tga", down = imLoadImage "12-em-down.tga", @@ -48,6 +50,7 @@ dalosp.struct = { }, get_settings = function (self) + return { self.extra.entries } end, configure = function (self) @@ -151,6 +154,15 @@ dalosp.struct = { mx.redraw = "All" end, + gen_template = function (self) + return self:get_settings() + end, + + apply_template = function (self, data) + self.extra.entries = data.entries + self:cacheoffset() + end, + cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) if col == 1 then dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) @@ -301,6 +313,8 @@ dalosp.struct = { obj.cacheoffset = dalosp.struct.cacheoffset obj.isunique = dalosp.struct.isunique obj.getunique = dalosp.struct.getunique + obj.gen_template = dalosp.struct.gen_template + obj.apply_template = dalosp.struct.apply_template obj:cacheoffset() @@ -350,7 +364,19 @@ dalosp.struct = { iup.fill {}, iup.button { title = "Ok", - action = function (self) return iup.CLOSE end + action = function (self) return iup.CLOSE end, + }, + iup.button { + title = "Import", + action = function() obj:load_template() return iup.CLOSE end, + }, + iup.button { + title = "Export", + action = function() obj:save_template(self:gen_template()) end, + }, + iup.button { + title = "Use Template", + action = function() obj:use_template() end, }, iup.fill {}, }, @@ -367,7 +393,11 @@ dalosp.struct = { return obj end, + + register_template = function (data, tname) + dalosp.struct.templates[tname] = data + end, } dalos.struct = dalosp.struct.create -dalos:register_obj("Struct", dalos.struct, "Programmable") +dalos:register_obj("Struct", dalos.struct, "Programmable", dalosp.struct.register_template) 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, } -- cgit v1.2.3 From 551cae6794486d30bee8333c54b1586edb2913ed Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 27 Dec 2009 02:22:14 +0100 Subject: Structures are now displaying, at least partially. --- dalos-struct.lua | 160 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 144 insertions(+), 16 deletions(-) diff --git a/dalos-struct.lua b/dalos-struct.lua index 0835b7d..d3e0080 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -50,7 +50,7 @@ dalosp.struct = { }, get_settings = function (self) - return { self.extra.entries } + return { entries = self.extra.entries } end, configure = function (self) @@ -58,10 +58,11 @@ dalosp.struct = { end, activate = function (self) - self.actv_dlg:show() + self.act_dlg:show() end, - input_change = function (self) + input_change = function (self, ind) + if ind == 1 then self:update_values() end end, offset = function (self, lin) @@ -69,6 +70,72 @@ dalosp.struct = { return cache[lin] end, + read_value = function (self, h, t, flags, size) + local v + + if t == "int8" then + v = h:readU8() + return v > 127 and v - 256 or v + elseif t == "uint8" then + return h:readU8() + elseif t == "int16" then + elseif t == "uint16" then + return h:readU16() + elseif t == "int32" then + elseif t == "uint32" then + return h:readU32() + elseif t == "int64" then + elseif t == "uint64" then + elseif t == "float" then + return h:readFloat() + elseif t == "double" then + return h:readDouble() + elseif t == "asciiz" then + v = "" + local b + repeat + b = h:readU8() + if b ~= 0 then v = v .. string.char(b) end + until b == 0 + return v + elseif t == "nascii" then + v = "" + for i = 1, size do + v = v .. string.char(h:readU8()) + end + return v + end + + return 0 + end, + + update_values = function (self) + local h = self:get_linked_input(1) + self.extra.values = {} + self.extra.values_by_name = {} + if h and h:getsize() >= self.extra.size then + h:seek(0) + local v, s, t + for e, f in ipairs(self.extra.entries) do + s = f.size + if not tonumber(s) then + s = self.extra.values_by_name[s] + end + t = dalosp.struct.types[f.type] + if t == "asciiz" or t == "nascii" or s == 1 then + v = self:read_value(h, t, f.flags, s) + else + v = {} + for i = 1, f.size do + v[i] = self:read_value(h, t, f.flags, s) + end + end + self.extra.values[e] = v + self.extra.values_by_name[f.name] = v + end + end + end, + cacheoffset = function (self) local entries = self.extra.entries self.extra.cache = {} @@ -93,6 +160,10 @@ dalosp.struct = { if self.cfg_dlg then self.cfg_dlg.mx.redraw = "C10" self.cfg_dlg.lsize.title = offset + self:update_values() + self.act_dlg.mx.numlin = #entries + self.act_dlg.mx.numlin_visible = #entries + self.act_dlg.mx.redraw = "All" end end, @@ -140,7 +211,8 @@ dalosp.struct = { table.insert(entries, lin - 1, old_lin) self:cacheoffset() local mx = self.cfg_dlg.mx - mx.redraw = "All" + mx.redraw = "L" .. (lin - 1) + mx.redraw = "L" .. lin end, line_down = function (self, lin) @@ -151,7 +223,8 @@ dalosp.struct = { table.insert(entries, lin + 1, old_lin) self:cacheoffset() local mx = self.cfg_dlg.mx - mx.redraw = "All" + mx.redraw = "L" .. lin + mx.redraw = "L" .. (lin + 1) end, gen_template = function (self) @@ -163,6 +236,24 @@ dalosp.struct = { self:cacheoffset() end, + get_field_value = function (self, lin) + local v = self.extra.values[lin] + if type(v) == "table" then + local r = nil + for k, sv in ipairs(v) do + if not r then + r = sv + else + r = r .. ", " .. sv + end + end + + return "[" .. (r or " ") .."]" + else + return v or "" + end + end, + cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) if col == 1 then dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) @@ -193,6 +284,8 @@ dalosp.struct = { self.struct:line_up(lin) elseif col == 4 then self.struct:line_down(lin) + elseif col == 11 then + -- edit flags end end, @@ -210,6 +303,8 @@ dalosp.struct = { return "Value Check" elseif col == 10 then return "Offset" + elseif col == 11 then + return "Flags" end return "" end @@ -223,7 +318,11 @@ dalosp.struct = { elseif col == 7 then return entries[lin].size elseif col == 10 then - return self.struct:offset(lin) + local off = self.struct:offset(lin) + if off == -1 then return "" end + return off + elseif col == 11 then + -- flags end return "" @@ -240,13 +339,14 @@ dalosp.struct = { elseif col == 7 then local nnewval = tonumber(newval) if nnewval then newval = nnewval end - entries[lin].size = nnewval + entries[lin].size = newval self.struct:cacheoffset() elseif col == 8 then -- enum elseif col == 9 then -- value check end + self.struct.act_dlg.mx.redraw = "All" end, cfg_dropcheck_cb = function (self, lin, col) @@ -257,13 +357,14 @@ dalosp.struct = { if mode == 1 then return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE else + local newval = self.value if update == 0 then return iup.DEFAULT end if col == 5 then - -- lookup duplicates in names + if not self.struct:isunique(newval) then return iup.IGNORE end elseif col == 6 then -- do a check on the dropdown ? I don't think so elseif col == 7 then - -- do a check on the size; can be the name of another field + if not tonumber(newval) and self.struct:isunique(newval) then return iup.IGNORE end elseif col == 8 then -- enum elseif col == 9 then @@ -285,9 +386,26 @@ dalosp.struct = { return iup.DEFAULT end, + act_value_cb = function (self, lin, col) + if lin == 0 then if col == 1 then return "Field" elseif col == 2 return "Value" end end + if col == 0 then return nil end + + local entry = self.struct.extra.entries[lin] + + if col == 1 then + return entry.name + else + return self.struct:get_field_value(lin) + end + end, + + act_click_cb = function (self, lin, col, status) + + end, + create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = 1 + tab.ninputs = 2 + tab.noutputs = 2 tab.otype = dalos.objtype.LUA_VIEWER tab.configure = dalosp.struct.configure tab.activate = dalosp.struct.activate @@ -315,12 +433,15 @@ dalosp.struct = { obj.getunique = dalosp.struct.getunique obj.gen_template = dalosp.struct.gen_template obj.apply_template = dalosp.struct.apply_template + obj.get_field_value = dalosp.struct.get_field_value + obj.update_values = dalosp.struct.update_values + obj.read_value = dalosp.struct.read_value obj:cacheoffset() local cmx = iup.matrix { - numcol = 10, - numcol_visible = 10, + numcol = 11, + numcol_visible = 11, usetitlesize = "Yes", rasterwidth1 = 12, rasterwidth2 = 12, @@ -332,8 +453,10 @@ dalosp.struct = { rasterwidth8 = 80, rasterwidth9 = 120, rasterwidth10 = 40, + rasterwidth11 = 60, resizematrix = "Yes", readonly = "No", + struct = obj, draw_cb = dalosp.struct.cfg_draw_cb, value_cb = dalosp.struct.cfg_value_cb, value_edit_cb = dalosp.struct.cfg_value_edit_cb, @@ -341,7 +464,6 @@ dalosp.struct = { drop_cb = dalosp.struct.cfg_drop_cb, edition_cb = dalosp.struct.cfg_edition_cb, click_cb = dalosp.struct.cfg_click_cb, - struct = obj, } local amx = iup.matrix { numcol = 2, @@ -349,7 +471,11 @@ dalosp.struct = { usetitlesize = "Yes", rasterwidth1 = 120, rasterwidth2 = 120, + readonly = "Yes", + resizematrix = "Yes", struct = obj, + value_cb = dalosp.struct.act_value_cb, + click_cb = dalosp.struct.act_click_cb, } local lsize = iup.label { title = "0", expand = "Horizontal", } @@ -382,13 +508,15 @@ dalosp.struct = { }, }, - size = "450x220", + size = "500x220", mx = cmx, lsize = lsize } - obj.actv_dlg = iup.dialog { + obj.act_dlg = iup.dialog { amx, + size = "250x120", + mx = amx, } return obj -- cgit v1.2.3 From 6a1356a266e376bee112452a515f61ac42d2556f Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 27 Dec 2009 19:45:09 +0100 Subject: Small enhancement of the template system. --- dalos.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dalos.lua b/dalos.lua index 047a54f..a6517d3 100644 --- a/dalos.lua +++ b/dalos.lua @@ -665,7 +665,8 @@ dalosp.menu = { local f = preload(v) v:destroy() if not f then error("Syntax error loading file " .. dlg.value) end - local data, otype, tname = f() + local t = f() + local data, otype, tname = t.data, t.otype, t.tname local tobj = dalos.objectstypes_by_name[otype] if not tobj then error("Unknown template object type: " .. otype) end @@ -855,7 +856,8 @@ dalosp.object = { local f = preload(v) v:destroy() if not f then error("Syntax error loading file " .. dlg.value) end - local data, otype, tname = f() + local t = f() + local data, otype, tname = t.data, t.otype, t.tname if otype ~= self.ntype then error("Wrong template type: " .. otype) end self:apply_template(data.template) @@ -958,7 +960,7 @@ dalosp.object = { dumpvars(v, dalos.version, "version") v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, template, "template") - v:write("return template, '" .. self.ntype .. "', '" .. name .. "'") + v:write("return { data = template, otype = '" .. self.ntype .. "', tname = '" .. name .. "' }\n") v:destroy() else error("Failed opening " .. dlg.value .. " for writing") -- cgit v1.2.3 From 3085628ad505a930d2b542bd65941f2b62b979ae Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 00:19:19 +0100 Subject: Completing a bit the struct display. --- dalos-struct.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dalos-struct.lua b/dalos-struct.lua index d3e0080..189c3be 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -74,18 +74,21 @@ dalosp.struct = { local v if t == "int8" then - v = h:readU8() - return v > 127 and v - 256 or v + return h:read8() elseif t == "uint8" then return h:readU8() elseif t == "int16" then + return h:read16() elseif t == "uint16" then return h:readU16() elseif t == "int32" then + return h:read32() elseif t == "uint32" then return h:readU32() elseif t == "int64" then + return h:read64() elseif t == "uint64" then + return h:readU64() elseif t == "float" then return h:readFloat() elseif t == "double" then @@ -99,11 +102,7 @@ dalosp.struct = { until b == 0 return v elseif t == "nascii" then - v = "" - for i = 1, size do - v = v .. string.char(h:readU8()) - end - return v + return h:readstring(size) end return 0 @@ -387,7 +386,7 @@ dalosp.struct = { end, act_value_cb = function (self, lin, col) - if lin == 0 then if col == 1 then return "Field" elseif col == 2 return "Value" end end + if lin == 0 then if col == 1 then return "Field" elseif col == 2 then return "Value" end end if col == 0 then return nil end local entry = self.struct.extra.entries[lin] -- cgit v1.2.3 From 28bddffd5991251e2c69b60b3c7d9c551043784e Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 00:20:50 +0100 Subject: Stopping displaying the struct configuration window as modal. --- dalos-struct.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dalos-struct.lua b/dalos-struct.lua index 189c3be..3e72871 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -54,7 +54,7 @@ dalosp.struct = { end, configure = function (self) - self.cfg_dlg:popup() + self.cfg_dlg:show() end, activate = function (self) -- cgit v1.2.3 From dd4d0d5131f3cd079ec052a058c7f2ad19130348 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 14:05:16 +0100 Subject: Adding textviewer, and doing a few minor tweaks. --- dalos-luafilter.lua | 2 +- dalos-struct.lua | 1077 ++++++++++++++++++++++++++------------------------- dalos-textview.lua | 52 +++ dalos.lua | 21 +- 4 files changed, 615 insertions(+), 537 deletions(-) create mode 100644 dalos-textview.lua diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 9c87f93..297441e 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -120,7 +120,7 @@ end local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end } local bexport = iup.button { title = "Export", action = function() self:save_template(self:gen_template()) end } - local busetpl = iup.button { title = "Use Template", action = function() self:use_template() end } + local busetpl = iup.button { title = "Use Template", action = function() self:use_template(dalosp.luafilter.templates) end } local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, busetpl, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } local r = dlg:popup() diff --git a/dalos-struct.lua b/dalos-struct.lua index 3e72871..84e9699 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -1,530 +1,547 @@ -local function imLoadImage(fname) - local f = im.FileOpen(fname) - local r = f:LoadImage() - f:Close() - return r -end - -dalosp.struct = { - templates = {}, - - images = { - up = imLoadImage "12-em-up.tga", - down = imLoadImage "12-em-down.tga", - cross = imLoadImage "12-em-cross.tga", - plus = imLoadImage "12-em-plus.tga", - }, - - types = { - "int8", - "uint8", - "int16", - "uint16", - "int32", - "uint32", - "int64", - "uint64", - "float", - "double", - "nascii", - "asciiz", - }, - - rtypes = { - int8 = 1, - uint8 = 2, - int16 = 3, - uint16 = 4, - int32 = 5, - uint32 = 6, - int64 = 7, - uint64 = 8, - float = 9, - double = 10, - nascii = 11, - asciiz = 12, - }, - - typessizes = { - 1, 1, 2, 2, 4, 4, 8, 8, 4, 8, 1, -1, - }, - - get_settings = function (self) - return { entries = self.extra.entries } - end, - - configure = function (self) - self.cfg_dlg:show() - end, - - activate = function (self) - self.act_dlg:show() - end, - - input_change = function (self, ind) - if ind == 1 then self:update_values() end - end, - - offset = function (self, lin) - local cache = self.extra.cache - return cache[lin] - end, - - read_value = function (self, h, t, flags, size) - local v - - if t == "int8" then - return h:read8() - elseif t == "uint8" then - return h:readU8() - elseif t == "int16" then - return h:read16() - elseif t == "uint16" then - return h:readU16() - elseif t == "int32" then - return h:read32() - elseif t == "uint32" then - return h:readU32() - elseif t == "int64" then - return h:read64() - elseif t == "uint64" then - return h:readU64() - elseif t == "float" then - return h:readFloat() - elseif t == "double" then - return h:readDouble() - elseif t == "asciiz" then - v = "" - local b - repeat - b = h:readU8() - if b ~= 0 then v = v .. string.char(b) end - until b == 0 - return v - elseif t == "nascii" then - return h:readstring(size) - end - - return 0 - end, - - update_values = function (self) - local h = self:get_linked_input(1) - self.extra.values = {} - self.extra.values_by_name = {} - if h and h:getsize() >= self.extra.size then - h:seek(0) - local v, s, t - for e, f in ipairs(self.extra.entries) do - s = f.size - if not tonumber(s) then - s = self.extra.values_by_name[s] - end - t = dalosp.struct.types[f.type] - if t == "asciiz" or t == "nascii" or s == 1 then - v = self:read_value(h, t, f.flags, s) - else - v = {} - for i = 1, f.size do - v[i] = self:read_value(h, t, f.flags, s) - end - end - self.extra.values[e] = v - self.extra.values_by_name[f.name] = v - end - end - end, - - cacheoffset = function (self) - local entries = self.extra.entries - self.extra.cache = {} - local cache = self.extra.cache - local offset = 0 - local got_var = false - local ssize - local vsize - - for i, v in ipairs(entries) do - ssize = dalosp.struct.typessizes[v.type] - vsize = ssize == -1 or type(v.size) ~= "number" - if vsize then got_var = true end - if got_var then - cache[i] = -1 - else - cache[i] = offset - end - if not vsize then offset = offset + ssize * v.size end - end - self.extra.size = offset - if self.cfg_dlg then - self.cfg_dlg.mx.redraw = "C10" - self.cfg_dlg.lsize.title = offset - self:update_values() - self.act_dlg.mx.numlin = #entries - self.act_dlg.mx.numlin_visible = #entries - self.act_dlg.mx.redraw = "All" - end - end, - - isunique = function (self, name) - for _, v in ipairs(self.extra.entries) do - if name == v.name then return false end - end - return true - end, - - getunique = function (self, lin) - local newname = "Field" .. lin - local base_newname = newname - local i = 1 - while not self:isunique(newname) do - newname = base_newname .. "." .. i - i = i + 1 - end - return newname - end, - - insert_line = function (self, lin) - if not lin then lin = (#self.extra.entries + 1) end - local name = self:getunique(lin) - table.insert(self.extra.entries, lin, { name = name, type = 1, size = 1 }) - self:cacheoffset() - local mx = self.cfg_dlg.mx - mx.numlin = mx.numlin + 1 - mx.numlin_visible = mx.numlin_visible + 1 - end, - - remove_line = function (self, lin) - table.remove(self.extra.entries, lin) - self:cacheoffset() - local mx = self.cfg_dlg.mx - mx.numlin = mx.numlin - 1 - mx.numlin_visible = mx.numlin_visible - 1 - end, - - line_up = function (self, lin) - if lin == 1 then return iup.DEFAULT end - local entries = self.extra.entries - local old_lin = entries[lin] - table.remove(entries, lin) - table.insert(entries, lin - 1, old_lin) - self:cacheoffset() - local mx = self.cfg_dlg.mx - mx.redraw = "L" .. (lin - 1) - mx.redraw = "L" .. lin - end, - - line_down = function (self, lin) - local entries = self.extra.entries - if lin == #entries then return iup.DEFAULT end - local old_lin = entries[lin] - table.remove(entries, lin) - table.insert(entries, lin + 1, old_lin) - self:cacheoffset() - local mx = self.cfg_dlg.mx - mx.redraw = "L" .. lin - mx.redraw = "L" .. (lin + 1) - end, - - gen_template = function (self) - return self:get_settings() - end, - - apply_template = function (self, data) - self.extra.entries = data.entries - self:cacheoffset() - end, - - get_field_value = function (self, lin) - local v = self.extra.values[lin] - if type(v) == "table" then - local r = nil - for k, sv in ipairs(v) do - if not r then - r = sv - else - r = r .. ", " .. sv - end - end - - return "[" .. (r or " ") .."]" - else - return v or "" - end - end, - - cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) - if col == 1 then - dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) - return iup.DEFAULT - elseif col == 2 and lin ~= 0 then - dalosp.struct.images.cross:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) - return iup.DEFAULT - elseif col == 3 and lin ~= 0 and lin ~= 1 then - dalosp.struct.images.up:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) - return iup.DEFAULT - elseif col == 4 and lin ~= 0 and lin ~= #self.struct.extra.entries then - dalosp.struct.images.down:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) - return iup.DEFAULT - end - - return iup.IGNORE - end, - - cfg_click_cb = function (self, lin, col, status) - if col == 1 and lin == 0 then return self.struct:insert_line() end - if lin == 0 then return iup.DEFAULT end - - if col == 1 then - self.struct:insert_line(lin) - elseif col == 2 then - self.struct:remove_line(lin) - elseif col == 3 then - self.struct:line_up(lin) - elseif col == 4 then - self.struct:line_down(lin) - elseif col == 11 then - -- edit flags - end - end, - - cfg_value_cb = function (self, lin, col) - if lin == 0 then - if col == 5 then - return "Name" - elseif col == 6 then - return "Type" - elseif col == 7 then - return "Size" - elseif col == 8 then - return "Enum" - elseif col == 9 then - return "Value Check" - elseif col == 10 then - return "Offset" - elseif col == 11 then - return "Flags" - end - return "" - end - - local entries = self.struct.extra.entries - - if col == 5 then - return entries[lin].name - elseif col == 6 then - return dalosp.struct.types[entries[lin].type] - elseif col == 7 then - return entries[lin].size - elseif col == 10 then - local off = self.struct:offset(lin) - if off == -1 then return "" end - return off - elseif col == 11 then - -- flags - end - - return "" - end, - - cfg_value_edit_cb = function (self, lin, col, newval) - local entries = self.struct.extra.entries - - if col == 5 then - entries[lin].name = newval - elseif col == 6 then - entries[lin].type = dalosp.struct.rtypes[newval] - self.struct:cacheoffset() - elseif col == 7 then - local nnewval = tonumber(newval) - if nnewval then newval = nnewval end - entries[lin].size = newval - self.struct:cacheoffset() - elseif col == 8 then - -- enum - elseif col == 9 then - -- value check - end - self.struct.act_dlg.mx.redraw = "All" - end, - - cfg_dropcheck_cb = function (self, lin, col) - return col == 6 and iup.DEFAULT or iup.IGNORE - end, - - cfg_edition_cb = function (self, lin, col, mode, update) - if mode == 1 then - return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE - else - local newval = self.value - if update == 0 then return iup.DEFAULT end - if col == 5 then - if not self.struct:isunique(newval) then return iup.IGNORE end - elseif col == 6 then - -- do a check on the dropdown ? I don't think so - elseif col == 7 then - if not tonumber(newval) and self.struct:isunique(newval) then return iup.IGNORE end - elseif col == 8 then - -- enum - elseif col == 9 then - -- value check - end - return iup.DEFAULT - end - end, - - cfg_drop_cb = function (self, drop, lin, col) - if col ~= 6 then return iup.IGNORE end - - for i, v in ipairs(dalosp.struct.types) do - drop[i] = v - end - drop.value = self.previousvalue - drop.visible_items = 15 - - return iup.DEFAULT - end, - - act_value_cb = function (self, lin, col) - if lin == 0 then if col == 1 then return "Field" elseif col == 2 then return "Value" end end - if col == 0 then return nil end - - local entry = self.struct.extra.entries[lin] - - if col == 1 then - return entry.name - else - return self.struct:get_field_value(lin) - end - end, - - act_click_cb = function (self, lin, col, status) - - end, - - create = function (d, tab, settings) - tab.ninputs = 2 - tab.noutputs = 2 - tab.otype = dalos.objtype.LUA_VIEWER - tab.configure = dalosp.struct.configure - tab.activate = dalosp.struct.activate - tab.input_change = dalosp.struct.input_change - tab.get_settings = dalosp.struct.get_settings - tab.draw = function (self, cv, x, y, w, h) - dalosp.object.default_draw(self, cv, x, y, w, h) - end - tab.default_name = "Struct" - tab.ntype = "Struct" - - local extra = { } - if not settings then settings = {} end - extra.entries = settings.entries or {} - - local obj = dalos.object(d, tab, extra) - - obj.insert_line = dalosp.struct.insert_line - obj.remove_line = dalosp.struct.remove_line - obj.line_up = dalosp.struct.line_up - obj.line_down = dalosp.struct.line_down - obj.offset = dalosp.struct.offset - obj.cacheoffset = dalosp.struct.cacheoffset - obj.isunique = dalosp.struct.isunique - obj.getunique = dalosp.struct.getunique - obj.gen_template = dalosp.struct.gen_template - obj.apply_template = dalosp.struct.apply_template - obj.get_field_value = dalosp.struct.get_field_value - obj.update_values = dalosp.struct.update_values - obj.read_value = dalosp.struct.read_value - - obj:cacheoffset() - - local cmx = iup.matrix { - numcol = 11, - numcol_visible = 11, - usetitlesize = "Yes", - rasterwidth1 = 12, - rasterwidth2 = 12, - rasterwidth3 = 12, - rasterwidth4 = 12, - rasterwidth5 = 120, - rasterwidth6 = 80, - rasterwidth7 = 80, - rasterwidth8 = 80, - rasterwidth9 = 120, - rasterwidth10 = 40, - rasterwidth11 = 60, - resizematrix = "Yes", - readonly = "No", - struct = obj, - draw_cb = dalosp.struct.cfg_draw_cb, - value_cb = dalosp.struct.cfg_value_cb, - value_edit_cb = dalosp.struct.cfg_value_edit_cb, - dropcheck_cb = dalosp.struct.cfg_dropcheck_cb, - drop_cb = dalosp.struct.cfg_drop_cb, - edition_cb = dalosp.struct.cfg_edition_cb, - click_cb = dalosp.struct.cfg_click_cb, - } - local amx = iup.matrix { - numcol = 2, - numcol_visible = 2, - usetitlesize = "Yes", - rasterwidth1 = 120, - rasterwidth2 = 120, - readonly = "Yes", - resizematrix = "Yes", - struct = obj, - value_cb = dalosp.struct.act_value_cb, - click_cb = dalosp.struct.act_click_cb, - } - local lsize = iup.label { title = "0", expand = "Horizontal", } - - obj.cfg_dlg = iup.dialog { - iup.vbox { - iup.hbox { - iup.label { title = "Struct size: " }, - lsize, - }, - cmx, - iup.hbox { - iup.fill {}, - iup.button { - title = "Ok", - action = function (self) return iup.CLOSE end, - }, - iup.button { - title = "Import", - action = function() obj:load_template() return iup.CLOSE end, - }, - iup.button { - title = "Export", - action = function() obj:save_template(self:gen_template()) end, - }, - iup.button { - title = "Use Template", - action = function() obj:use_template() end, - }, - iup.fill {}, - }, - }, - - size = "500x220", - mx = cmx, - lsize = lsize - } - - obj.act_dlg = iup.dialog { - amx, - size = "250x120", - mx = amx, - } - - return obj - end, - - register_template = function (data, tname) - dalosp.struct.templates[tname] = data - end, -} - -dalos.struct = dalosp.struct.create -dalos:register_obj("Struct", dalos.struct, "Programmable", dalosp.struct.register_template) +local function imLoadImage(fname) + local f = im.FileOpen(fname) + local r = f:LoadImage() + f:Close() + return r +end + +dalosp.struct = { + templates = {}, + + images = { + up = imLoadImage "12-em-up.tga", + down = imLoadImage "12-em-down.tga", + cross = imLoadImage "12-em-cross.tga", + plus = imLoadImage "12-em-plus.tga", + }, + + types = { + "int8", + "uint8", + "int16", + "uint16", + "int32", + "uint32", + "int64", + "uint64", + "float", + "double", + "nascii", + "asciiz", + }, + + rtypes = { + int8 = 1, + uint8 = 2, + int16 = 3, + uint16 = 4, + int32 = 5, + uint32 = 6, + int64 = 7, + uint64 = 8, + float = 9, + double = 10, + nascii = 11, + asciiz = 12, + }, + + typessizes = { + 1, 1, 2, 2, 4, 4, 8, 8, 4, 8, 1, -1, + }, + + get_settings = function (self) + return { entries = self.extra.entries } + end, + + configure = function (self) + self.cfg_dlg:show() + end, + + activate = function (self) + self.act_dlg:show() + end, + + input_change = function (self, ind) + if ind == 1 then self:update_values() end + if ind == 2 then + + end + end, + + offset = function (self, lin) + local cache = self.extra.cache + return cache[lin] + end, + + read_value = function (self, h, t, flags, size) + local v + + if t == "int8" then + return h:read8() + elseif t == "uint8" then + return h:readU8() + elseif t == "int16" then + return h:read16() + elseif t == "uint16" then + return h:readU16() + elseif t == "int32" then + return h:read32() + elseif t == "uint32" then + return h:readU32() + elseif t == "int64" then + return h:read64() + elseif t == "uint64" then + return h:readU64() + elseif t == "float" then + return h:readFloat() + elseif t == "double" then + return h:readDouble() + elseif t == "asciiz" then + v = "" + local b + repeat + b = h:readU8() + if b ~= 0 then v = v .. string.char(b) end + until b == 0 + return v + elseif t == "nascii" then + return h:readstring(size) + end + + return 0 + end, + + update_values = function (self) + local h = self:get_linked_input(1) + self.extra.values = {} + self.extra.values_by_name = {} + if h and h:getsize() >= self.extra.size then + h:seek(0) + local v, s, t + for e, f in ipairs(self.extra.entries) do + s = f.size + if not tonumber(s) then + s = self.extra.values_by_name[s] + end + t = dalosp.struct.types[f.type] + if t == "asciiz" or t == "nascii" or s == 1 then + v = self:read_value(h, t, f.flags, s) + else + v = {} + for i = 1, f.size do + v[i] = self:read_value(h, t, f.flags, s) + end + end + self.extra.values[e] = v + self.extra.values_by_name[f.name] = v + end + self:output_selected() + local b = Buffer(true) + + ---- filling in the output structure in b + self:set_houtput(b, 2) + else + self:set_houtput(nil, 1) + self:set_houtput(nil, 2) + end + end, + + output_selected = function (self) + end, + + cacheoffset = function (self) + local entries = self.extra.entries + self.extra.cache = {} + local cache = self.extra.cache + local offset = 0 + local got_var = false + local ssize + local vsize + + for i, v in ipairs(entries) do + ssize = dalosp.struct.typessizes[v.type] + vsize = ssize == -1 or type(v.size) ~= "number" + if vsize then got_var = true end + if got_var then + cache[i] = -1 + else + cache[i] = offset + end + if not vsize then offset = offset + ssize * v.size end + end + self.extra.size = offset + if self.cfg_dlg then + self.cfg_dlg.mx.redraw = "C10" + self.cfg_dlg.lsize.title = offset + self:update_values() + self.act_dlg.mx.numlin = #entries + self.act_dlg.mx.numlin_visible = #entries + self.act_dlg.mx.redraw = "All" + end + end, + + isunique = function (self, name) + for _, v in ipairs(self.extra.entries) do + if name == v.name then return false end + end + return true + end, + + getunique = function (self, lin) + local newname = "Field" .. lin + local base_newname = newname + local i = 1 + while not self:isunique(newname) do + newname = base_newname .. "." .. i + i = i + 1 + end + return newname + end, + + insert_line = function (self, lin) + if not lin then lin = (#self.extra.entries + 1) end + local name = self:getunique(lin) + table.insert(self.extra.entries, lin, { name = name, type = 1, size = 1 }) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.numlin = mx.numlin + 1 + mx.numlin_visible = mx.numlin_visible + 1 + end, + + remove_line = function (self, lin) + table.remove(self.extra.entries, lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.numlin = mx.numlin - 1 + mx.numlin_visible = mx.numlin_visible - 1 + end, + + line_up = function (self, lin) + if lin == 1 then return iup.DEFAULT end + local entries = self.extra.entries + local old_lin = entries[lin] + table.remove(entries, lin) + table.insert(entries, lin - 1, old_lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.redraw = "L" .. (lin - 1) + mx.redraw = "L" .. lin + end, + + line_down = function (self, lin) + local entries = self.extra.entries + if lin == #entries then return iup.DEFAULT end + local old_lin = entries[lin] + table.remove(entries, lin) + table.insert(entries, lin + 1, old_lin) + self:cacheoffset() + local mx = self.cfg_dlg.mx + mx.redraw = "L" .. lin + mx.redraw = "L" .. (lin + 1) + end, + + gen_template = function (self) + return self:get_settings() + end, + + apply_template = function (self, data) + self.extra.entries = data.entries + self:cacheoffset() + end, + + get_field_value = function (self, lin) + local v = self.extra.values[lin] + if type(v) == "table" then + local r = nil + for k, sv in ipairs(v) do + if not r then + r = sv + else + r = r .. ", " .. sv + end + end + + return "[" .. (r or " ") .."]" + else + return v or "" + end + end, + + cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv) + if col == 1 then + dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 2 and lin ~= 0 then + dalosp.struct.images.cross:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 3 and lin ~= 0 and lin ~= 1 then + dalosp.struct.images.up:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + elseif col == 4 and lin ~= 0 and lin ~= #self.struct.extra.entries then + dalosp.struct.images.down:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12) + return iup.DEFAULT + end + + return iup.IGNORE + end, + + cfg_click_cb = function (self, lin, col, status) + if col == 1 and lin == 0 then return self.struct:insert_line() end + if lin == 0 then return iup.DEFAULT end + + if col == 1 then + self.struct:insert_line(lin) + elseif col == 2 then + self.struct:remove_line(lin) + elseif col == 3 then + self.struct:line_up(lin) + elseif col == 4 then + self.struct:line_down(lin) + elseif col == 11 then + -- edit flags + end + end, + + cfg_value_cb = function (self, lin, col) + if lin == 0 then + if col == 5 then + return "Name" + elseif col == 6 then + return "Type" + elseif col == 7 then + return "Size" + elseif col == 8 then + return "Enum" + elseif col == 9 then + return "Value Check" + elseif col == 10 then + return "Offset" + elseif col == 11 then + return "Flags" + end + return "" + end + + local entries = self.struct.extra.entries + + if col == 5 then + return entries[lin].name + elseif col == 6 then + return dalosp.struct.types[entries[lin].type] + elseif col == 7 then + return entries[lin].size + elseif col == 10 then + local off = self.struct:offset(lin) + if off == -1 then return "" end + return off + elseif col == 11 then + -- flags + end + + return "" + end, + + cfg_value_edit_cb = function (self, lin, col, newval) + local entries = self.struct.extra.entries + + if col == 5 then + entries[lin].name = newval + elseif col == 6 then + entries[lin].type = dalosp.struct.rtypes[newval] + self.struct:cacheoffset() + elseif col == 7 then + local nnewval = tonumber(newval) + if nnewval then newval = nnewval end + entries[lin].size = newval + self.struct:cacheoffset() + elseif col == 8 then + -- enum + elseif col == 9 then + -- value check + end + self.struct.act_dlg.mx.redraw = "All" + end, + + cfg_dropcheck_cb = function (self, lin, col) + return col == 6 and iup.DEFAULT or iup.IGNORE + end, + + cfg_edition_cb = function (self, lin, col, mode, update) + if mode == 1 then + return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE + else + local newval = self.value + if update == 0 then return iup.DEFAULT end + if col == 5 then + if not self.struct:isunique(newval) then return iup.IGNORE end + elseif col == 6 then + -- do a check on the dropdown ? I don't think so + elseif col == 7 then + if not tonumber(newval) and self.struct:isunique(newval) then return iup.IGNORE end + elseif col == 8 then + -- enum + elseif col == 9 then + -- value check + end + return iup.DEFAULT + end + end, + + cfg_drop_cb = function (self, drop, lin, col) + if col ~= 6 then return iup.IGNORE end + + for i, v in ipairs(dalosp.struct.types) do + drop[i] = v + end + drop.value = self.previousvalue + drop.visible_items = 15 + + return iup.DEFAULT + end, + + act_value_cb = function (self, lin, col) + if lin == 0 then if col == 1 then return "Field" elseif col == 2 then return "Value" end end + if col == 0 then return nil end + + local entry = self.struct.extra.entries[lin] + + if col == 1 then + return entry.name + else + return self.struct:get_field_value(lin) + end + end, + + act_click_cb = function (self, lin, col, status) + + end, + + create = function (d, tab, settings) + tab.ninputs = 2 + tab.noutputs = 3 + tab.otype = dalos.objtype.LUA_VIEWER + tab.configure = dalosp.struct.configure + tab.activate = dalosp.struct.activate + tab.input_change = dalosp.struct.input_change + tab.get_settings = dalosp.struct.get_settings + tab.draw = function (self, cv, x, y, w, h) + dalosp.object.default_draw(self, cv, x, y, w, h) + end + tab.default_name = "Struct" + tab.ntype = "Struct" + + local extra = { } + if not settings then settings = {} end + extra.entries = settings.entries or {} + + local obj = dalos.object(d, tab, extra) + + obj.insert_line = dalosp.struct.insert_line + obj.remove_line = dalosp.struct.remove_line + obj.line_up = dalosp.struct.line_up + obj.line_down = dalosp.struct.line_down + obj.offset = dalosp.struct.offset + obj.cacheoffset = dalosp.struct.cacheoffset + obj.isunique = dalosp.struct.isunique + obj.getunique = dalosp.struct.getunique + obj.gen_template = dalosp.struct.gen_template + obj.apply_template = dalosp.struct.apply_template + obj.get_field_value = dalosp.struct.get_field_value + obj.update_values = dalosp.struct.update_values + obj.read_value = dalosp.struct.read_value + obj.output_selected = dalosp.struct.output_selected + + obj:cacheoffset() + + local cmx = iup.matrix { + numcol = 11, + numcol_visible = 11, + usetitlesize = "Yes", + rasterwidth1 = 12, + rasterwidth2 = 12, + rasterwidth3 = 12, + rasterwidth4 = 12, + rasterwidth5 = 120, + rasterwidth6 = 80, + rasterwidth7 = 80, + rasterwidth8 = 80, + rasterwidth9 = 120, + rasterwidth10 = 40, + rasterwidth11 = 60, + resizematrix = "Yes", + readonly = "No", + struct = obj, + draw_cb = dalosp.struct.cfg_draw_cb, + value_cb = dalosp.struct.cfg_value_cb, + value_edit_cb = dalosp.struct.cfg_value_edit_cb, + dropcheck_cb = dalosp.struct.cfg_dropcheck_cb, + drop_cb = dalosp.struct.cfg_drop_cb, + edition_cb = dalosp.struct.cfg_edition_cb, + click_cb = dalosp.struct.cfg_click_cb, + } + local amx = iup.matrix { + numcol = 2, + numcol_visible = 2, + usetitlesize = "Yes", + rasterwidth1 = 120, + rasterwidth2 = 120, + readonly = "Yes", + resizematrix = "Yes", + struct = obj, + value_cb = dalosp.struct.act_value_cb, + click_cb = dalosp.struct.act_click_cb, + } + local lsize = iup.label { title = "0", expand = "Horizontal", } + + obj.cfg_dlg = iup.dialog { + iup.vbox { + iup.hbox { + iup.label { title = "Struct size: " }, + lsize, + }, + cmx, + iup.hbox { + iup.fill {}, + iup.button { + title = "Ok", + action = function (self) return iup.CLOSE end, + }, + iup.button { + title = "Import", + action = function() obj:load_template() return iup.CLOSE end, + }, + iup.button { + title = "Export", + action = function() obj:save_template(self:gen_template()) end, + }, + iup.button { + title = "Use Template", + action = function() obj:use_template(dalsop.struct.templates) end, + }, + iup.fill {}, + }, + }, + + size = "500x220", + mx = cmx, + lsize = lsize, + title = obj.name .. " configuration", + } + + obj.act_dlg = iup.dialog { + amx, + size = "250x120", + mx = amx, + title = obj.name, + } + + return obj + end, + + register_template = function (data, tname) + dalosp.struct.templates[tname] = data + end, +} + +dalos.struct = dalosp.struct.create +dalos:register_obj("Struct", dalos.struct, "Programmable", dalosp.struct.register_template) diff --git a/dalos-textview.lua b/dalos-textview.lua new file mode 100644 index 0000000..496fd26 --- /dev/null +++ b/dalos-textview.lua @@ -0,0 +1,52 @@ +dalosp.textview = { + get_settings = function (self) + return { } + end, + + input_change = function (self) + local h = self:get_linked_input(1) + + if h then + self.extra.txt.value = h:readfile() + else + self.extra.txt.value = "" + end + end, + + activate = function (self) + self.extra.dlg:show() + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 0 + tab.otype = dalos.objtype.LUA_VIEWER + tab.activate = dalosp.textview.activate + tab.input_change = dalosp.textview.input_change + tab.default_name = "Text View" + tab.ntype = "Text View" + tab.get_settings = dalosp.textview.get_settings + local extra = { } + + local obj = dalos.object(d, tab, extra) + + local txt = iup.text { + multiline = "Yes", + readonly = "Yes", + expand = "Yes", + font = "Courier, 8" + } + local dlg = iup.dialog { + txt, + size = "320x200", + title = obj.name + } + extra.dlg = dlg + extra.txt = txt + + return obj + end, +} + +dalos.textview = dalosp.textview.create +dalos:register_obj("Text View", dalos.textview, "Basic Viewers") diff --git a/dalos.lua b/dalos.lua index a6517d3..e7c02bd 100644 --- a/dalos.lua +++ b/dalos.lua @@ -724,11 +724,11 @@ dalosp.menu = { create = function (canvas, tab) local item_new = iup.item { title = "New" } item_new.action = dalosp.menu.action_new - local item_load = iup.item { title = "Load" } + local item_load = iup.item { title = "Load workspace" } item_load.action = dalosp.menu.action_load - local item_save = iup.item { title = "Save" } + local item_save = iup.item { title = "Save workspace" } item_save.action = dalosp.menu.action_save - local item_import = iup.item { title = "Import" } + local item_import = iup.item { title = "Import Lua file" } item_import.action = dalosp.menu.action_import local item_reload = iup.item { title = "Reload all" } item_reload.action = dalosp.menu.action_reload @@ -818,8 +818,7 @@ dalosp.menu = { } dalosp.object = { - use_template = function (self) - local templates = dalosp.luafilter.templates + use_template = function (self, templates) local ttpllst = {} for n, v in pairs(templates) do table.insert(ttpllst, n) @@ -840,7 +839,15 @@ dalosp.object = { 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]]) + self:apply_template(templates[ttpllst[tind]]) + end, + + auto_template = function (self, templates, name) + for n, v in pairs(templates) do + if n == name then + self:apply_template(v) + end + end end, load_template = function (self) @@ -1004,6 +1011,7 @@ dalosp.object = { save_template = dalosp.object.save_template, load_template = dalosp.object.load_template, use_template = dalosp.object.use_template, + auto_template = dalosp.object.auto_template, dcanvas = dcanvas, } @@ -1078,6 +1086,7 @@ load "dalos-tee.lua" load "dalos-buffer.lua" load "dalos-luafilter.lua" load "dalos-struct.lua" +load "dalos-textview.lua" ---------------- -- cgit v1.2.3 From 34dd8ccee048382aaae104159bdb6260be8df49e Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 15:24:13 +0100 Subject: Various fixes, and getting output on the struct. --- dalos-hexview.lua | 2 +- dalos-struct.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++-------- dalos-textview.lua | 1 + 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 0ee8a8c..28d7217 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -97,7 +97,7 @@ Marker lengths: %b origin = cursor, size = maxsize - cursor, getname = function (self) return self.hvo.name .. ":" .. self.ind end, - getmodif = function (self) return self.hvo:getmodif() end, + getmodif = function (self) return self.h:getmodif() end, do_seek = function (self) self.h:seek(self.offset + self.origin) self:post_read() diff --git a/dalos-struct.lua b/dalos-struct.lua index 84e9699..9bbe617 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -64,7 +64,8 @@ dalosp.struct = { input_change = function (self, ind) if ind == 1 then self:update_values() end if ind == 2 then - + local h = self:get_linked_input(2) + self:auto_template(dalosp.struct.templates, h:readstring()) end end, @@ -136,10 +137,7 @@ dalosp.struct = { self.extra.values_by_name[f.name] = v end self:output_selected() - local b = Buffer(true) - - ---- filling in the output structure in b - self:set_houtput(b, 2) + self:output_struct() else self:set_houtput(nil, 1) self:set_houtput(nil, 2) @@ -147,6 +145,43 @@ dalosp.struct = { end, output_selected = function (self) + local selected = self.extra.selected + local cache = self.extra.cache + local cursor = selected and cache[selected] or -1 + local h = self:get_linked_input(1) + if h and selected and selected > 0 and cursor >= 0 then + local field = self.extra.entries[selected].name + local maxsize = (cache[selected + 1] or self.extra.size) - cursor + h:seek(cursor) + local obj = { + h = h, + str = self, + origin = cursor, + field = field, + size = maxsize - cursor, + getname = function (self) return self.str.name .. ":" .. self.field end, + getmodif = function (self) return self.h:getmodif() end, + do_seek = function (self) + self.h:seek(self.offset + self.origin) + end, + do_read = function (self, count, userdata) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), 1) + local b = Buffer(true) + b:write(field .. "\n") + self:set_houtput(b, 3) + else + self:set_houtput(nil, 1) + self:set_houtput(nil, 3) + end + end, + + output_struct = function (self) + local b = Buffer(true) + dumpvars(b, self.extra.values_by_name, "data") + self:set_houtput(b, 2) end, cacheoffset = function (self) @@ -346,6 +381,8 @@ dalosp.struct = { if col == 5 then entries[lin].name = newval + self.struct:output_selected() + self.struct:output_struct() elseif col == 6 then entries[lin].type = dalosp.struct.rtypes[newval] self.struct:cacheoffset() @@ -413,7 +450,8 @@ dalosp.struct = { end, act_click_cb = function (self, lin, col, status) - + self.struct.extra.selected = lin + self.struct:output_selected() end, create = function (d, tab, settings) @@ -432,7 +470,8 @@ dalosp.struct = { local extra = { } if not settings then settings = {} end - extra.entries = settings.entries or {} + local entries = settings.entries or {} + extra.entries = entries local obj = dalos.object(d, tab, extra) @@ -450,8 +489,7 @@ dalosp.struct = { obj.update_values = dalosp.struct.update_values obj.read_value = dalosp.struct.read_value obj.output_selected = dalosp.struct.output_selected - - obj:cacheoffset() + obj.output_struct = dalosp.struct.output_struct local cmx = iup.matrix { numcol = 11, @@ -535,6 +573,14 @@ dalosp.struct = { title = obj.name, } + if entries then + obj.cfg_dlg.mx.numlin = #entries + obj.cfg_dlg.mx.numlin_visible = #entries + obj.act_dlg.mx.numlin = #entries + obj.act_dlg.mx.numlin_visible = #entries + end + obj:cacheoffset() + return obj end, diff --git a/dalos-textview.lua b/dalos-textview.lua index 496fd26..2a0e220 100644 --- a/dalos-textview.lua +++ b/dalos-textview.lua @@ -34,6 +34,7 @@ dalosp.textview = { multiline = "Yes", readonly = "Yes", expand = "Yes", + shrink = "Yes", font = "Courier, 8" } local dlg = iup.dialog { -- cgit v1.2.3 From 9e6429099d53b850862ed4cfcf22ac1b8c332437 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 15:28:25 +0100 Subject: Getting shrink right. --- dalos-hexview.lua | 2 +- dalos-textview.lua | 4 ++-- dalos.lua | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 28d7217..b59993a 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -161,7 +161,7 @@ Marker lengths: %b local hv = iupe.hexview { } local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x", shrink = "Yes" } extra.hv = hv extra.hvtb = hvtb diff --git a/dalos-textview.lua b/dalos-textview.lua index 2a0e220..2bd0be5 100644 --- a/dalos-textview.lua +++ b/dalos-textview.lua @@ -34,13 +34,13 @@ dalosp.textview = { multiline = "Yes", readonly = "Yes", expand = "Yes", - shrink = "Yes", font = "Courier, 8" } local dlg = iup.dialog { txt, size = "320x200", - title = obj.name + title = obj.name, + shrink = "Yes", } extra.dlg = dlg extra.txt = txt diff --git a/dalos.lua b/dalos.lua index e7c02bd..c0235cc 100644 --- a/dalos.lua +++ b/dalos.lua @@ -474,7 +474,6 @@ dalosp.canvas = { create = function (tab) tab.border = "No" tab.expand = "Yes" - tab.shrink = "Yes" tab.minsize = "1x1" tab.rastersize = "1x1" local r = iup.canvas(tab) @@ -1097,7 +1096,7 @@ function dalos:main() m = self.menu(d) s = self.status() - dlg = iup.dialog { iup.vbox { d, s }, title = "Dalos", menu = m, size = "400x250" } + dlg = iup.dialog { iup.vbox { d, s }, title = "Dalos", menu = m, size = "400x250", shrink = "Yes", } d.dialog = dlg -- cgit v1.2.3 From 3389b6abdab512ff3e03c080f95d0a3ffe1db097 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 16:09:18 +0100 Subject: Adding cd-reader. --- dalos-cd.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 50 insertions(+) create mode 100644 dalos-cd.lua diff --git a/dalos-cd.lua b/dalos-cd.lua new file mode 100644 index 0000000..cb0b6a7 --- /dev/null +++ b/dalos-cd.lua @@ -0,0 +1,49 @@ +loadmodule "luacd" + +dalosp.cd = { + get_settings = function (self) + return { filename = self.extra.filename } + end, + + configure = function (self) + local drives_list = self.extra.drives_list + local list = "" + for i, v in ipairs(drives_list) do + list = list .. v .. "|" + end + local s, id = iup.GetParam("CD drive", nil, "CD drive: %l|" .. list .. "\n", 0) + + if s then + self.extra.filename = "cd:" .. drives_list[id + 1] + local s, v = pcall(cdabstract, self.extra.filename) + if s then + self:set_houtput(v) + return + end + end + self:set_houtput(nil) + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.configure = dalosp.cd.configure + tab.default_name = "CD" + tab.ntype = "CD" + tab.get_settings = dalosp.cd.get_settings + local extra = { drives_list = cdprobe() } + if settings then extra.filename = settings.filename end + local obj = dalos.object(d, tab, extra) + + if extra.filename then + local s, v = pcall(cdabstract, extra.filename) + if s then obj:set_houtput(v) end + end + + return obj + end, +} + +dalos.cd = dalosp.cd.create +dalos:register_obj("CD", dalos.cd, "Basic Inputs") diff --git a/dalos.lua b/dalos.lua index c0235cc..68dd7a2 100644 --- a/dalos.lua +++ b/dalos.lua @@ -1086,6 +1086,7 @@ load "dalos-buffer.lua" load "dalos-luafilter.lua" load "dalos-struct.lua" load "dalos-textview.lua" +load "dalos-cd.lua" ---------------- -- cgit v1.2.3 From 664c9c7f18fe901086dd7296127bbc4c45d8fc2d Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 16:25:26 +0100 Subject: Removing unnecessary parameter --- iupe-hexview.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/iupe-hexview.lua b/iupe-hexview.lua index fb02b68..a6817d9 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -551,7 +551,6 @@ iupep.hexview = { tab.gridsize = nil tab.cursor = "TEXT" tab.expand = "Yes" - tab.shrink = "Yes" tab.border = "No" tab.minsize = "0x0" tab.size = "0x0" -- cgit v1.2.3 From 3286955dc331841136d51c3921d0b488c5e89aab Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 17:06:15 +0100 Subject: Permitting name changes of the struct objects. --- dalos-struct.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dalos-struct.lua b/dalos-struct.lua index 9bbe617..d66e02a 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -556,7 +556,15 @@ dalosp.struct = { title = "Use Template", action = function() obj:use_template(dalsop.struct.templates) end, }, + iup.button { + title = "Change name", + action = function() local s, n = iup.GetParam("Change name", nil, "Name: %s\n", obj.name) if s then obj.name = n end end + }, iup.fill {}, + iup.button { + title = "Close", + action = function() return iup.CLOSE end, + }, }, }, -- cgit v1.2.3 From dec3f7e6c7e5b7ed5ef94b68456bd267ea62143b Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 17:16:21 +0100 Subject: Adding framebuffer skeleton. --- dalos-framebuffer.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 5 ++++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 dalos-framebuffer.lua diff --git a/dalos-framebuffer.lua b/dalos-framebuffer.lua new file mode 100644 index 0000000..ab3e593 --- /dev/null +++ b/dalos-framebuffer.lua @@ -0,0 +1,54 @@ +dalosp.framebuffer = { + get_settings = function (self) + return { } + end, + + input_change = function (self) + local h = self:get_linked_input(1) + + if h then + else + end + end, + + activate = function (self) + self.extra.dlg:show() + end, + + configure = function (self) + dalosp.object.default_configure(self) + end, + + create = function (d, tab, settings) + tab.ninputs = 2 + tab.noutputs = 0 + tab.otype = dalos.objtype.LUA_VIEWER + tab.activate = dalosp.framebuffer.activate + tab.configure = dalosp.framebuffer.configure + tab.input_change = dalosp.framebuffer.input_change + tab.default_name = "Framebuffer" + tab.ntype = "Framebuffer" + tab.get_settings = dalosp.framebuffer.get_settings + local extra = { } + + local obj = dalos.object(d, tab, extra) + + local fb = iup.canvas { + expand = "Yes", + font = "Courier, 8" + } + local dlg = iup.dialog { + fb, + size = "320x200", + title = obj.name, + shrink = "Yes", + } + extra.dlg = dlg + extra.fb = fb + + return obj + end, +} + +dalos.framebuffer = dalosp.framebuffer.create +dalos:register_obj("Framebuffer", dalos.framebuffer, "Basic Viewers") diff --git a/dalos.lua b/dalos.lua index 68dd7a2..94a16e3 100644 --- a/dalos.lua +++ b/dalos.lua @@ -907,7 +907,9 @@ dalosp.object = { end, default_configure = function (self) - print "default configure" + local s, n = iup.GetParam("Change name", nil, "Name: %s\n", self.name) + + if s then self.name = n end end, change_curinput = function (self, delta) @@ -1087,6 +1089,7 @@ load "dalos-luafilter.lua" load "dalos-struct.lua" load "dalos-textview.lua" load "dalos-cd.lua" +load "dalos-framebuffer.lua" ---------------- -- cgit v1.2.3 From 57a3540010861f78bb86d493f084a2f4dd52169c Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 23:57:18 +0100 Subject: Tweaking a bit the framebuffer, in order to properly use the double buffer. --- dalos-framebuffer.lua | 6 +++++- iupe-dbuffer.lua | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dalos-framebuffer.lua b/dalos-framebuffer.lua index ab3e593..b3b3706 100644 --- a/dalos-framebuffer.lua +++ b/dalos-framebuffer.lua @@ -1,3 +1,5 @@ +load "iupe-dbuffer.lua" + dalosp.framebuffer = { get_settings = function (self) return { } @@ -35,7 +37,9 @@ dalosp.framebuffer = { local fb = iup.canvas { expand = "Yes", - font = "Courier, 8" + font = "Courier, 8", + action = iupep.dbuffer.action, + draw = dalos.framebuffer.draw, } local dlg = iup.dialog { fb, diff --git a/iupe-dbuffer.lua b/iupe-dbuffer.lua index 4321206..8c1412f 100644 --- a/iupe-dbuffer.lua +++ b/iupe-dbuffer.lua @@ -4,6 +4,8 @@ loadmodule "lualibs" if not iupep then iupep = {} end +if not iupep.dbuffer then + iupep.dbuffer = { map_cb = function (self) self.cv = cd.CreateCanvas(cd.IUP, self) @@ -41,3 +43,5 @@ iupep.dbuffer = { return iup.DEFAULT end, } + +end -- cgit v1.2.3 From 162ddadae30f2a8fade8e99bcd8e55a00407edf8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 30 Dec 2009 01:43:22 +0100 Subject: Moving apply_template and gen_template to a more common place. --- dalos-luafilter.lua | 4 ++-- dalos-struct.lua | 4 ++-- dalos.lua | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 297441e..312aff7 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -146,6 +146,8 @@ end tab.default_name = "Lua Filter" tab.get_settings = dalosp.luafilter.get_settings tab.ntype = "Lua Filter" + tab.gen_template = dalosp.luafilter.gen_template + tab.apply_template = dalosp.luafilter.apply_template local extra = { localenv = {} } extra.code = settings and settings.code if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end @@ -158,8 +160,6 @@ end obj.load_code = dalosp.luafilter.load_code obj.run_in_localenv = dalosp.luafilter.run_in_localenv - obj.gen_template = dalosp.luafilter.gen_template - obj.apply_template = dalosp.luafilter.apply_template obj:load_code(extra.code) return obj diff --git a/dalos-struct.lua b/dalos-struct.lua index d66e02a..5f157ef 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -462,6 +462,8 @@ dalosp.struct = { tab.activate = dalosp.struct.activate tab.input_change = dalosp.struct.input_change tab.get_settings = dalosp.struct.get_settings + tab.gen_template = dalosp.struct.gen_template + tab.apply_template = dalosp.struct.apply_template tab.draw = function (self, cv, x, y, w, h) dalosp.object.default_draw(self, cv, x, y, w, h) end @@ -483,8 +485,6 @@ dalosp.struct = { obj.cacheoffset = dalosp.struct.cacheoffset obj.isunique = dalosp.struct.isunique obj.getunique = dalosp.struct.getunique - obj.gen_template = dalosp.struct.gen_template - obj.apply_template = dalosp.struct.apply_template obj.get_field_value = dalosp.struct.get_field_value obj.update_values = dalosp.struct.update_values obj.read_value = dalosp.struct.read_value diff --git a/dalos.lua b/dalos.lua index 94a16e3..36ca02a 100644 --- a/dalos.lua +++ b/dalos.lua @@ -953,6 +953,7 @@ dalosp.object = { end, save_template = function (self, template) + if not template then template = self:gen_template() end local dlg = iup.filedlg { dialogtype = "Save", filter = "*.dtpl", @@ -1013,6 +1014,8 @@ dalosp.object = { load_template = dalosp.object.load_template, use_template = dalosp.object.use_template, auto_template = dalosp.object.auto_template, + apply_template = tab.apply_template, + gen_template = tab.gen_template, dcanvas = dcanvas, } -- cgit v1.2.3 From 375cdbda2ebe625d06be76ddb760e71aa2f9ac44 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 30 Dec 2009 20:33:53 +0100 Subject: Framebuffer is working. Slowly but working. --- dalos-framebuffer.lua | 170 +++++++++++++++++++++++++++++++++++++++++++++++--- dalos.lua | 2 +- 2 files changed, 161 insertions(+), 11 deletions(-) diff --git a/dalos-framebuffer.lua b/dalos-framebuffer.lua index b3b3706..c21a193 100644 --- a/dalos-framebuffer.lua +++ b/dalos-framebuffer.lua @@ -1,16 +1,23 @@ load "iupe-dbuffer.lua" -dalosp.framebuffer = { +dalosp.framebuffer = { get_settings = function (self) - return { } + return { width = self.extra.width, height = self.extra.height, bpp = self.extra.bpp } end, - input_change = function (self) - local h = self:get_linked_input(1) - - if h then - else + input_change = function (self, ind) + local h = self:get_linked_input(ind) + if ind == 2 then + if h then + local cfg, s = h:readfile() + s, cfg = pcall(loadstring, "local cfg = " .. cfg .. "\nreturn cfg\n") + if s then self:apply_config(cfg) end + end + return end + + if h then h.getnextbyte = dalosp.framebuffer.getnextbyte end + self:apply_config{} end, activate = function (self) @@ -18,7 +25,140 @@ dalosp.framebuffer = { end, configure = function (self) - dalosp.object.default_configure(self) + invert_lookup = { + [1] = 0, + [2] = 1, + [4] = 2, + [8] = 3, + [24] = 4, + [32] = 5, + } + lookup = { + [0] = 1, + [1] = 2, + [2] = 4, + [3] = 8, + [4] = 24, + [5] = 32, + } + local owidth, oheight, obpp, oppdir = self.extra.width, self.extra.height, self.extra.bpp, self.extra.ppdir + local cb = function (dlg, pi) + if pi < 0 then return end + local width, height, bpp, dir + width = iup.GetParamParam(dlg, 1).value + 0 + height = iup.GetParamParam(dlg, 2).value + 0 + bpp = iup.GetParamParam(dlg, 3).value + 0 + dir = iup.GetParamParam(dlg, 4).value + 0 + self:apply_config{ width = width, height = height, bpp = lookup[bpp], dir = dir } + end + local s, nname, width, height, bpp, ppdir = iup.GetParam(self.name .. " configuration", cb, "New name: %s\nWidth: %i\nHeight: %i\nBpp: %l|1 bpp|2 bpp|4 bpp|8 bpp|24 bpp|32 bpp|\nDirection: %l|Little Endian|Big Endian|\n", self.name, self.extra.width, self.extra.height, invert_lookup[self.extra.bpp], self.extra.ppdir) + if not s then + self:apply_config{ width = owidth, height = oheight, bpp = obpp, ppdir = oppdir } + else + self.name = nname + end + end, + + apply_config = function (self, cfg) + local fb = self.extra.fb + local h = self:get_linked_input(1) + if cfg.width then self.extra.width = cfg.width end + if cfg.height then self.extra.height = cfg.height end + if cfg.bpp then self.extra.bpp = cfg.bpp end + if cfg.ppdir then self.extra.ppdir = cfg.ppdir end + fb.cfg = { h = h, width = self.extra.width, height = self.extra.height, bpp = self.extra.bpp } + fb:prepare() + fb:draw() + fb:action() + end, + + getnextbyte = function (h) + return h:tell() ~= h:getsize() and h:readU8() or 0 + end, + + getbit = function (cfg) + local rc + local h = cfg.h + local stateful = cfg.stateful + if cfg.bpp >= 8 then return end + stateful = cfg.stateful + if not stateful or bit.band(stateful, 0x7f) == 0 then + stateful = h:getnextbyte() * 2 + 1 + else + stateful = stateful * 2 + end + cfg.stateful = stateful + return bit.band(bit.rshift(stateful, 8), 1) + end, + + getnextpixel = function (cfg) + local rc + local r, g, b + local h = cfg.h + local getbit = function() return dalosp.framebuffer.getbit(cfg) end + if cfg.bpp == 1 then + rc = getbit() * 255 + r, g, b = rc, rc, rc + elseif cfg.bpp == 2 then + rc = getbit() * 2 + rc = (rc + getbit()) * 255 / 3 + r, g, b = rc, rc, rc + elseif cfg.bpp == 4 then + rc = getbit() * 8 + rc = rc + getbit() * 4 + rc = rc + getbit() * 2 + rc = (rc + getbit()) * 255 / 15 + r, g, b = rc, rc, rc + elseif cfg.bpp == 8 then + rc = h:getnextbyte() + r, g, b = rc, rc, rc + elseif cfg.bpp == 24 then + r = h:getnextbyte() + g = h:getnextbyte() + b = h:getnextbyte() + elseif cfg.bpp == 32 then + r = h:getnextbyte() + g = h:getnextbyte() + b = h:getnextbyte() + h:getnextbyte() + end + return r, g, b + end, + + prepare = function (self) + local cfg = self.cfg + local h = cfg.h + local width = cfg.width + local height = cfg.height + local bpp = cfg.bpp + local ppdir = cfg.ppdir + local flipx = cfg.flipx + local flipy = cfg.flipy + local cim = im.ImageCreate(width, height, im.RGB, im.BYTE) + self.cim = cim + cim:Clear() + if not h then return iup.DEFAULT end + local getnextpixel = self.getnextpixel + + h:seek(0) + cfg.stateful = 0 + local r, g, b = cim[0], cim[1], cim[2] + + for y = 0, height - 1 do + for x = 0, width - 1 do + local px, py = flipx and width - x or x, flipy and height - y or y + r[py][px], g[py][px], b[py][px] = getnextpixel(cfg) + end + end + + return iup.DEFAULT + end, + + draw = function (self) + local cvdb = self.cvdb + if not cvdb then return iup.DEFAULT end + cvdb:Clear() + self.cim:cdCanvasPutImageRect(cvdb, 0, 0, 0, 0, 0, 0, 0, 0) -- use default values end, create = function (d, tab, settings) @@ -31,15 +171,23 @@ dalosp.framebuffer = { tab.default_name = "Framebuffer" tab.ntype = "Framebuffer" tab.get_settings = dalosp.framebuffer.get_settings - local extra = { } + local extra = { width = settings.width or 256 , height = settings.height or 256, bpp = settings.bpp or 32, ppdir = settings.dir or 0 } local obj = dalos.object(d, tab, extra) + + obj.apply_config = dalosp.framebuffer.apply_config local fb = iup.canvas { expand = "Yes", font = "Courier, 8", action = iupep.dbuffer.action, - draw = dalos.framebuffer.draw, + map_cb = iupep.dbuffer.map_cb, + unmap_cb = iupep.dbuffer.unmap_cb, + resize_cb = iupep.dbuffer.resize_cb, + draw = dalosp.framebuffer.draw, + prepare = dalosp.framebuffer.prepare, + getnextpixel = dalosp.framebuffer.getnextpixel, + rastersize = extra.width .. "x" .. extra.height, } local dlg = iup.dialog { fb, @@ -50,6 +198,8 @@ dalosp.framebuffer = { extra.dlg = dlg extra.fb = fb + obj:apply_config{} + return obj end, } diff --git a/dalos.lua b/dalos.lua index 36ca02a..e4a6957 100644 --- a/dalos.lua +++ b/dalos.lua @@ -704,7 +704,7 @@ dalosp.menu = { end, add_object = function (canvas, object, x, y) - object.constructor(canvas, { counter = object.counter, x = (x or 25) + 0, y = (y or 25) + 0}) + object.constructor(canvas, { counter = object.counter, x = (x or 25) + 0, y = (y or 25) + 0}, {}) object.counter = object.counter + 1 end, -- cgit v1.2.3 From 80bf27f647f587a5175f7b68bfe7dd4a7da17f5c Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 5 Jan 2010 08:52:26 -0800 Subject: Framebuffer almost done; zoom is slightly broken. --- dalos-framebuffer.lua | 236 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 214 insertions(+), 22 deletions(-) diff --git a/dalos-framebuffer.lua b/dalos-framebuffer.lua index c21a193..f2dd01d 100644 --- a/dalos-framebuffer.lua +++ b/dalos-framebuffer.lua @@ -2,7 +2,16 @@ load "iupe-dbuffer.lua" dalosp.framebuffer = { get_settings = function (self) - return { width = self.extra.width, height = self.extra.height, bpp = self.extra.bpp } + local extra = self.extra + return { + width = extra.width, + height = extra.height, + bpp = extra.bpp, + zoom = extra.zoom, + ppdir = extra.ppdir, + flipx = extra.flipx, + flipy = extra.flipy, + } end, input_change = function (self, ind) @@ -11,13 +20,19 @@ dalosp.framebuffer = { if h then local cfg, s = h:readfile() s, cfg = pcall(loadstring, "local cfg = " .. cfg .. "\nreturn cfg\n") - if s then self:apply_config(cfg) end + if s then + self:apply_config(cfg) + self.extra.fb:prepare() + self.extra.fb:draw() + end end return end if h then h.getnextbyte = dalosp.framebuffer.getnextbyte end self:apply_config{} + self.extra.fb:prepare() + self.extra.fb:draw() end, activate = function (self) @@ -25,6 +40,7 @@ dalosp.framebuffer = { end, configure = function (self) + local extra = self.extra invert_lookup = { [1] = 0, [2] = 1, @@ -41,7 +57,7 @@ dalosp.framebuffer = { [4] = 24, [5] = 32, } - local owidth, oheight, obpp, oppdir = self.extra.width, self.extra.height, self.extra.bpp, self.extra.ppdir + local owidth, oheight, obpp, oppdir, oflipx, oflipy = extra.width, extra.height, extra.bpp, extra.ppdir, not not extra.flipx, not not extra.flipy local cb = function (dlg, pi) if pi < 0 then return end local width, height, bpp, dir @@ -49,27 +65,69 @@ dalosp.framebuffer = { height = iup.GetParamParam(dlg, 2).value + 0 bpp = iup.GetParamParam(dlg, 3).value + 0 dir = iup.GetParamParam(dlg, 4).value + 0 - self:apply_config{ width = width, height = height, bpp = lookup[bpp], dir = dir } + flipx = (iup.GetParamParam(dlg, 5).value + 0) ~= 0 + flipy = (iup.GetParamParam(dlg, 6).value + 0) ~= 0 + self:apply_config{ width = width, height = height, bpp = lookup[bpp], dir = dir, flipx = flipx, flipy = flipy } + self.extra.fb:prepare() + self.extra.fb:draw() end - local s, nname, width, height, bpp, ppdir = iup.GetParam(self.name .. " configuration", cb, "New name: %s\nWidth: %i\nHeight: %i\nBpp: %l|1 bpp|2 bpp|4 bpp|8 bpp|24 bpp|32 bpp|\nDirection: %l|Little Endian|Big Endian|\n", self.name, self.extra.width, self.extra.height, invert_lookup[self.extra.bpp], self.extra.ppdir) + local s, nname = iup.GetParam(self.name .. " configuration", cb, [[ +New name: %s +Width: %i +Height: %i +Bpp: %l|1 bpp|2 bpp|4 bpp|8 bpp|24 bpp|32 bpp| +Packed Pixels: %l|Little Endian|Big Endian| +Flip X axis: %b +Flip Y axis: %b +]], self.name, owidth, oheight, invert_lookup[obpp], oppdir, oflipx and 1 or 0, oflipy and 1 or 0) if not s then - self:apply_config{ width = owidth, height = oheight, bpp = obpp, ppdir = oppdir } + self:apply_config{ width = owidth, height = oheight, bpp = obpp, ppdir = oppdir, flipx = oflipx, flipy = oflipy } + self.extra.fb:prepare() + self.extra.fb:draw() else self.name = nname end end, apply_config = function (self, cfg) - local fb = self.extra.fb + local extra = self.extra + local fb = extra.fb local h = self:get_linked_input(1) - if cfg.width then self.extra.width = cfg.width end - if cfg.height then self.extra.height = cfg.height end - if cfg.bpp then self.extra.bpp = cfg.bpp end - if cfg.ppdir then self.extra.ppdir = cfg.ppdir end - fb.cfg = { h = h, width = self.extra.width, height = self.extra.height, bpp = self.extra.bpp } - fb:prepare() - fb:draw() - fb:action() + if cfg.width then extra.width = cfg.width end + if cfg.height then extra.height = cfg.height end + if cfg.bpp then extra.bpp = cfg.bpp end + if cfg.ppdir then extra.ppdir = cfg.ppdir end + if cfg.flipx then extra.flipx = cfg.flipx end + if cfg.flipy then extra.flipy = cfg.flipy end + if cfg.zoom then extra.zoom = cfg.zoom end + local zoom = 2 ^ extra.zoom + local posx = fb.posx + local posy = fb.posy + local dx = fb.dx + 0 + local dy = fb.dy + 0 + local fw = math.floor(extra.width * zoom) + local fh = math.floor(extra.height * zoom) + if dx >= (fb.xmax - fb.xmin) then posx = math.floor((fw - dx) / 2) end + if dy >= (fb.ymax - fb.ymin) then posy = math.floor((fh - dy) / 2) end + fb.xmax = fw + fb.ymax = fh + cfg = { + h = h, + width = extra.width, + height = extra.height, + bpp = extra.bpp, + ppdir = extra.ppdir, + flipx = extra.flipx, + flipy = extra.flipy, + zoom = zoom, + x = -posx, + y = -posy, + fw = fw, + fh = fh, + } + fb.cfg = cfg + local cvwidth, cvheight = fb.width or 0, fb.height or 0 + cvwidth, cvheight = cvwidth + 0, cvheight + 0 end, getnextbyte = function (h) @@ -133,7 +191,7 @@ dalosp.framebuffer = { local bpp = cfg.bpp local ppdir = cfg.ppdir local flipx = cfg.flipx - local flipy = cfg.flipy + local flipy = not cfg.flipy local cim = im.ImageCreate(width, height, im.RGB, im.BYTE) self.cim = cim cim:Clear() @@ -146,7 +204,7 @@ dalosp.framebuffer = { for y = 0, height - 1 do for x = 0, width - 1 do - local px, py = flipx and width - x or x, flipy and height - y or y + local px, py = flipx and width - x - 1 or x, flipy and height - y - 1 or y r[py][px], g[py][px], b[py][px] = getnextpixel(cfg) end end @@ -157,8 +215,65 @@ dalosp.framebuffer = { draw = function (self) local cvdb = self.cvdb if not cvdb then return iup.DEFAULT end - cvdb:Clear() - self.cim:cdCanvasPutImageRect(cvdb, 0, 0, 0, 0, 0, 0, 0, 0) -- use default values + cvdb:Clear() + local cim = self.cim + local cfg = self.cfg + cim:cdCanvasPutImageRect(cvdb, cfg.x, cvdb:InvertYAxis(cfg.y + cfg.fh), cfg.fw, cfg.fh, 0, 0, 0, 0) + cvdb:Flush() + end, + + resize_cb = function (self, width, height) + self.dx = width + self.dy = height + self.posx = self.posx + self.posy = self.posy + iupep.dbuffer.resize_cb(self, width, height) + self.obj:apply_config{} + self:draw() + end, + + fimg2canvas = function (self, ix, iy) + local cfg = self.cfg + local cx, cy + return ix + cfg.x, iy + cfg.y + end, + + canvas2fimg = function (self, cx, cy) + local cfg = self.cfg + return cx - cfg.x, cy - cfg.y + end, + + img2canvas = function (self, ix, iy) + local cfg = self.cfg + local cx, cy + return math.floor((ix + cfg.x) * cfg.zoom), math.floor((iy + cfg.y) * cfg.zoom) + end, + + canvas2img = function (self, cx, cy) + local cfg = self.cfg + return math.floor((cx - cfg.x) / cfg.zoom), math.floor((cy - cfg.y) / cfg.zoom) + end, + + scroll_cb = function (self, op, posx, posy) + print "Scroll called." + self:resize_cb(self.width, self.height) + end, + + wheel_cb = function (self, delta, x, y, status) + local ox, oy = self:canvas2img(x, y) + local opx, opy = self.cfg.x, self.cfg.y + self.obj:apply_config { zoom = self.obj.extra.zoom + (delta / 10) } + local nx, ny = self:img2canvas(ox, oy) + local dx, dy = ox - nx, oy - ny +-- dtable({opx = opx, opy = opy, dx = dx, dy = dy, nx = opx - dx, ny = opy - dy}, "params") +-- self.posx, self.posy = opx - dx, opy - dy + self:resize_cb(self.width, self.height) + end, + + motion_cb = function (self, x, y) + local ox, oy = self:canvas2img(x, y) + local nx, ny = self:img2canvas(ox, oy) +-- dtable({x = x, y = y, ox = ox, oy = oy, nx = nx, ny = ny}, "params") end, create = function (d, tab, settings) @@ -171,7 +286,15 @@ dalosp.framebuffer = { tab.default_name = "Framebuffer" tab.ntype = "Framebuffer" tab.get_settings = dalosp.framebuffer.get_settings - local extra = { width = settings.width or 256 , height = settings.height or 256, bpp = settings.bpp or 32, ppdir = settings.dir or 0 } + local extra = { + width = settings.width or 256, + height = settings.height or 256, + bpp = settings.bpp or 32, + ppdir = settings.dir or 0, + flipx = settings.flipx, + flipy = settings.flipy, + zoom = settings.zoom or 0, + } local obj = dalos.object(d, tab, extra) @@ -183,14 +306,81 @@ dalosp.framebuffer = { action = iupep.dbuffer.action, map_cb = iupep.dbuffer.map_cb, unmap_cb = iupep.dbuffer.unmap_cb, - resize_cb = iupep.dbuffer.resize_cb, + resize_cb = dalosp.framebuffer.resize_cb, + motion_cb = dalosp.framebuffer.motion_cb, draw = dalosp.framebuffer.draw, + scroll_cb = dalosp.framebuffer.scroll_cb, + wheel_cb = dalosp.framebuffer.wheel_cb, prepare = dalosp.framebuffer.prepare, + img2canvas = dalosp.framebuffer.img2canvas, + canvas2img = dalosp.framebuffer.canvas2img, + fimg2canvas = dalosp.framebuffer.img2canvas, + canvas2fimg = dalosp.framebuffer.canvas2img, getnextpixel = dalosp.framebuffer.getnextpixel, rastersize = extra.width .. "x" .. extra.height, + scrollbar = "Yes", + dx = 1, + dy = 1, + linex = 1, + liney = 1, + xmax = 0, + ymax = 0, + xautohide = "No", + yautohide = "No", + obj = obj, } local dlg = iup.dialog { - fb, + iup.vbox { + fb, + iup.hbox { + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = -4 } fb:resize_cb(fb.width, fb.height) end, + title = "1:16", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = -3 } fb:resize_cb(fb.width, fb.height) end, + title = "1:8", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = -2 } fb:resize_cb(fb.width, fb.height) end, + title = "1:4", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = -1 } fb:resize_cb(fb.width, fb.height) end, + title = "1:2", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = 0 } fb:resize_cb(fb.width, fb.height) end, + title = "1:1", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = 1 } fb:resize_cb(fb.width, fb.height) end, + title = "2:1", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = 2 } fb:resize_cb(fb.width, fb.height) end, + title = "4:1", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = 3 } fb:resize_cb(fb.width, fb.height) end, + title = "8:1", + }, + iup.fill{}, + iup.button { + action = function () fb.posx, fb.posy = 0, 0 obj:apply_config { zoom = 4 } fb:resize_cb(fb.width, fb.height) end, + title = "16:1", + }, + iup.fill{}, + }, + }, size = "320x200", title = obj.name, shrink = "Yes", @@ -199,6 +389,8 @@ dalosp.framebuffer = { extra.fb = fb obj:apply_config{} + fb:prepare() + fb:draw() return obj end, -- cgit v1.2.3 From 69836d15333d9d48aecf3e0aef139c7eacf59214 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 5 Jan 2010 10:14:38 -0800 Subject: Somehow fixed the zoom. Still not optimal though. --- dalos-framebuffer.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dalos-framebuffer.lua b/dalos-framebuffer.lua index f2dd01d..27e183c 100644 --- a/dalos-framebuffer.lua +++ b/dalos-framebuffer.lua @@ -245,8 +245,7 @@ Flip Y axis: %b img2canvas = function (self, ix, iy) local cfg = self.cfg - local cx, cy - return math.floor((ix + cfg.x) * cfg.zoom), math.floor((iy + cfg.y) * cfg.zoom) + return math.floor(ix * cfg.zoom + cfg.x), math.floor(iy * cfg.zoom + cfg.y) end, canvas2img = function (self, cx, cy) @@ -255,7 +254,6 @@ Flip Y axis: %b end, scroll_cb = function (self, op, posx, posy) - print "Scroll called." self:resize_cb(self.width, self.height) end, @@ -265,15 +263,13 @@ Flip Y axis: %b self.obj:apply_config { zoom = self.obj.extra.zoom + (delta / 10) } local nx, ny = self:img2canvas(ox, oy) local dx, dy = ox - nx, oy - ny --- dtable({opx = opx, opy = opy, dx = dx, dy = dy, nx = opx - dx, ny = opy - dy}, "params") --- self.posx, self.posy = opx - dx, opy - dy + self.posx, self.posy = -opx - dx, -opy - dy self:resize_cb(self.width, self.height) end, motion_cb = function (self, x, y) local ox, oy = self:canvas2img(x, y) local nx, ny = self:img2canvas(ox, oy) --- dtable({x = x, y = y, ox = ox, oy = oy, nx = nx, ny = ny}, "params") end, create = function (d, tab, settings) -- cgit v1.2.3