From 970cdc59b8e5d18f15bf5fb96d768ccb447248d1 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 17 Dec 2009 18:30:34 -0800 Subject: Adding a few menu containers, not active yet; fixing a few callbacks, adding the object registration system, and enabling hexview's cursors. --- dalos.lua | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 131 insertions(+), 12 deletions(-) diff --git a/dalos.lua b/dalos.lua index 426b54e..fbaf76a 100644 --- a/dalos.lua +++ b/dalos.lua @@ -9,6 +9,14 @@ load "iupe-tview.lua" if not dalosp then dalosp = {} end if not dalos then dalos = {} end +dalos.objects = {} + +function dalos:register_obj(name, constructor) + table.insert(self.objects, { name = name, constructor = constructor }) + if self.activemenu then + self.activemenu:update_objects() + end +end dalosp.canvas = { DARK_WHITE = cd.EncodeColor(224, 224, 224), @@ -300,6 +308,8 @@ dalosp.canvas = { self.menu.x = nil self.menu.y = nil self:draw() + elseif self.stateful.moving then + -- check for the trash can end self.stateful.panning = nil self.stateful.moving = nil @@ -358,6 +368,8 @@ dalosp.canvas = { r.objects = {} + dalos.active_canvas = r + return r end, } @@ -379,14 +391,55 @@ dalosp.menu = { return iup.DEFAULT end, + update_objects = function (self) + if dalos.dlg then + local newmenu = dalos.menu {} + -- copy anything from self to newmenu ? *shrug* + dalos.dlg.menu = newmenu + end + end, + create = function (tab) local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } item_about.action = dalosp.menu.action_about + local add_menu = { } + local north_menu = { radio = "1" } + 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 } + table.insert(add_menu, item) + item = iup.item { title = v.name } + table.insert(north_menu, item) + item = iup.item { title = v.name } + table.insert(east_menu, item) + item = iup.item { title = v.name } + table.insert(west_menu, item) + item = iup.item { title = v.name } + table.insert(south_menu, item) + end + end local menu_file = iup.submenu { iup.menu { 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" }, + iup.submenu { iup.menu(east_menu), title = "East" }, + iup.submenu { iup.menu(west_menu), title = "West" }, + iup.submenu { iup.menu(south_menu), title = "South" }, + }, title = "Cross", } local menu_help = iup.submenu { iup.menu { item_about }, title = "Help" } - return iup.menu { menu_file, menu_help } + local r = iup.menu { menu_file, menu_add, menu_cross, menu_help } + r.update_objects = dalosp.menu.update_objects + r.add_menu = add_menu + + dalos.active_menu = r + + return r end, } @@ -464,7 +517,7 @@ dalosp.object = { self.houtputs[ind] = h local obj = self.outputs[ind] if obj then - obj.obj:input_change(obj.ind) + obj.obj.obj:input_change(obj.ind) end end, @@ -538,26 +591,88 @@ dalosp.hexview = { input_change = function (self, ind) local extra = self.extra local hv = extra.hv - hv:updatehandle(self:get_linked_input(ind)) + local h = self:get_linked_input(ind) + if not h then + self.color = cd.YELLOW + hv:updatehandle(nil) + return + end + if not h:canread() or not h:canseek() then + self.color = cd.RED + hv:updatehandle(nil) + return + end + self.color = cd.GREEN + for i = 1, 12 do + self:set_houtput(nil, i) + self.oldcursors[i] = -1 + end + hv:updatehandle(h) 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.lh: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) - if reset then - local h, o = self.houtputs - for i = 1, 12 do - self.oldcursors[i] = -1 - end - end - local m for i = 1, 10 do m = hv.markers[i] @@ -590,13 +705,13 @@ dalosp.hexview = { tab.ninputs = 1 tab.noutputs = 12 - 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 obj = dalos.object(d, tab, { hv = hv, hvtb = hvtb, hvdlg = hvdlg }) obj.oldcursors = { } + obj.watchees = { } obj.update_houtput = dalosp.hexview.update_houtput for i = 1, 12 do obj.oldcursors[i] = -1 end @@ -607,6 +722,7 @@ dalosp.hexview = { } dalos.hexview = dalosp.hexview.create +dalos:register_obj("Hexview", dalos.hexview) ---------------- @@ -620,13 +736,16 @@ 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 }) -h = dalos.hexview(d, { y = 60, x = 100 }) +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) dlg = iup.dialog { d, title = "Dalos", menu = m } +dalos.dialog = dlg + dlg:show() iup.MainLoop() dlg:hide() -- cgit v1.2.3