loadmodule "luaiup" 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 if not dalos then dalos = {} end dalosp.canvas = { draw = function (self) local cvdb = self.cvdb if not cvdb then return iup.DEFAULT end cvdb:Clear() for k, v in ipairs(self.objects) do v.obj:draw(cvdb, v.x, v.y, v.w, v.h) end cvdb:Flush() return iup.DEFAULT end, addobj = function (self, obj, x, y, w, h) table.insert(self.objects, { obj = obj, x = x, y = y, w = w, h = h }) self:draw() end, findobj = function (self, x, y) local obj, ind x = x + 0 y = y + 0 for k, v in ipairs(self.objects) do if v.x <= x and (v.x + v.w) >= x and v.y <= y and (v.y + v.h) >= y then obj, ind = v, k end end return obj, ind end, moveobj = function (self, obj, dx, dy) obj.x, obj.y = obj.x + dx, obj.y + dy self:draw() end, setobjplace = function (self, obj, x, y) obj.x, obj.y = x, y self:draw() end, focus_cb = function (self, focus) end, motion_cb = function (self, x, y, status) if iup.isbutton1(status) then elseif iup.isbutton3(status) then elseif iup.isbutton2(status) then local moving = self.moving if moving then local ox, oy = self.ox, self.oy local dx, dy = x - ox, y - oy self:moveobj(moving, dx, dy) self.ox, self.oy = x, y end end end, button_cb = function (self, button, pressed, x, y, status) if button == iup.BUTTON1 then if pressed == 1 then else end elseif button == iup.BUTTON3 then if pressed == 1 then else end elseif button == iup.BUTTON2 then if pressed == 1 then self.moving = self:findobj(x, y) self.ox, self.oy = x, y else self.moving = nil end end end, create = function (tab) tab.border = "No" tab.expand = "Yes" tab.shrink = "Yes" tab.minsize = "1x1" tab.size = "1x1" local r = iup.canvas(tab) r.action = iupep.dbuffer.action r.draw = dalosp.canvas.draw r.resize_cb = iupep.dbuffer.resize_cb r.map_cb = iupep.dbuffer.map_cb r.unmap_cb = iupep.dbuffer.unmap_cb r.focus_cb = dalosp.canvas.focus_cb r.motion_cb = dalosp.canvas.motion_cb r.button_cb = dalosp.canvas.button_cb r.addobj = dalosp.canvas.addobj r.findobj = dalosp.canvas.findobj r.moveobj = dalosp.canvas.moveobj r.setobjplace = dalosp.canvas.setobjplace r.objects = {} return r end, } dalosp.menu = { action_exit = function (self) return iup.CLOSE 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" } local menu_file = iup.submenu { iup.menu { item_exit }, title = "File" } local menu_help = iup.submenu { iup.menu { item_about }, title = "Help" } return iup.menu { menu_file, menu_help } end, } dalosp.object = { default_draw = function (self, cv, x, y, w, h ) cv:Foreground(self.color) local x1, x2, y1, y2 = x, x + w, y, y + h cv:Box(x1, x2, cv:InvertYAxis(y2), cv:InvertYAxis(y1)) end, create = function (dcanvas, tab, extra) if not tab then tab = {} end local obj = { draw = dalosp.object.default_draw, color = tab.color or cd.GRAY, inputs = tab.inpus or 0, outputs = tab.outputs or 0, otype = tab.otype or dalos.objtype.DUMMY, extra = extra, } if tab.otype and not tab.c then if tab.otype == dalos.objtype.DUMMY then obj.color = cd.GRAY elseif tab.otype == dalos.objtype.HANDLE then obj.color = cd.CYAN elseif tab.otype == dalos.objtype.LUA_FILTER then obj.color = cd.YELLOW else obj.color = cd.DARK_RED end end dcanvas:addobj(obj, tab.x or 0, tab.y or 0, tab.w or 50, tab.h or 50) end, } dalos.canvas = dalosp.canvas.create dalos.menu = dalosp.menu.create dalos.object = dalosp.object.create dalos.objtype = { UNKNOWN = 0, DUMMY = 1, HANDLE = 2, LUA_FILTER = 3, } ---------------- d = dalos.canvas {} m = dalos.menu {} o = dalos.object(d) dlg = iup.dialog { d, title = "Dalos", menu = m } dlg:show() iup.MainLoop() dlg:hide()