summaryrefslogtreecommitdiff
path: root/dalos.lua
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-19 16:44:45 -0800
committerPixel <pixel@nobis-crew.org>2009-12-19 16:44:45 -0800
commit442c3b3ce4c431f2a9760000f56c86f239728225 (patch)
tree07c6641b559cb02122c412510f9c45148b606633 /dalos.lua
parent4456d2f6ca62fe69e058dd3f5bc4c1b087afc9a1 (diff)
All menus should be working now.
Diffstat (limited to 'dalos.lua')
-rw-r--r--dalos.lua103
1 files 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)