From ee4606d05a6a28399ec73b1b60c05a15877f8a2f Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 15 Dec 2009 00:34:25 -0800 Subject: Adding panning, and more cohering left/right click behavior. --- dalos.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 13 deletions(-) (limited to 'dalos.lua') diff --git a/dalos.lua b/dalos.lua index a317e98..b9af1f5 100644 --- a/dalos.lua +++ b/dalos.lua @@ -17,7 +17,7 @@ dalosp.canvas = { cvdb:Clear() for k, v in ipairs(self.objects) do - v.obj:draw(cvdb, v.x, v.y, v.w, v.h) + v.obj:draw(cvdb, self.origin.x + v.x, self.origin.y + v.y, v.w, v.h) end cvdb:Flush() @@ -55,38 +55,83 @@ dalosp.canvas = { self:draw() end, + panning = function (self, dx, dy) + self.origin.x = self.origin.x + dx + self.origin.y = self.origin.y + dy + self:draw() + end, + focus_cb = function (self, focus) end, motion_cb = function (self, x, y, status) - if iup.isbutton1(status) then + if self.stateful.panning then + print "Panning..." + local ox, oy = self.ox, self.oy + local dx, dy = x - ox, y - oy + self:panning(dx, dy) + self.ox, self.oy = x, y + elseif iup.isbutton1(status) then + if self.stateful.leftclk and not self.stateful.linking then self.stateful.linking = self.stateful.leftclk end + local linking = self.stateful.linking + if linking then + -- writing linking code... + else + -- start selection square ? + end elseif iup.isbutton3(status) then - elseif iup.isbutton2(status) then - local moving = self.moving + if self.stateful.rghtclk and not self.stateful.moving then self.stateful.moving = self.stateful.rghtclk end + local moving = self.stateful.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 + else + -- show X menu 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 button == iup.BUTTON1 or not button then if pressed == 1 then + self.stateful.leftbutton = true + if self.stateful.rghtclk then + self.stateful.panning = true + else + self.stateful.leftclk = self:findobj(x,y) + self.ox, self.oy = x, y + self.bx, self.by = x, y + end else + if not self.stateful.linking and self.stateful.leftclk then + self.stateful.leftclk.obj:activate() + end + self.stateful.panning = nil + self.stateful.linking = nil + self.stateful.leftclk = nil + self.stateful.leftbutton = nil end - elseif button == iup.BUTTON2 then + end + + if button == iup.BUTTON3 or not button then if pressed == 1 then - self.moving = self:findobj(x, y) - self.ox, self.oy = x, y + self.stateful.rghtbutton = true + if self.stateful.leftclk then + self.stateful.panning = true + else + self.stateful.rghtclk = self:findobj(x, y) + self.ox, self.oy = x, y + end else - self.moving = nil + if not self.stateful.moving and self.stateful.rghtclk then + self.stateful.rghtclk.obj:configure() + end + self.stateful.panning = nil + self.stateful.moving = nil + self.stateful.rghtclk = nil + self.stateful.rghtbutton = nil end end end, @@ -110,6 +155,9 @@ dalosp.canvas = { r.findobj = dalosp.canvas.findobj r.moveobj = dalosp.canvas.moveobj r.setobjplace = dalosp.canvas.setobjplace + r.panning = dalosp.canvas.panning + r.origin = { x = 0, y = 0 } + r.stateful = {} r.objects = {} @@ -139,6 +187,14 @@ dalosp.object = { cv:Box(x1, x2, cv:InvertYAxis(y2), cv:InvertYAxis(y1)) end, + default_activate = function (self) + print "activate" + end, + + default_configure = function(self) + print "configure" + end, + create = function (dcanvas, tab, extra) if not tab then tab = {} end local obj = { @@ -147,6 +203,8 @@ dalosp.object = { inputs = tab.inpus or 0, outputs = tab.outputs or 0, otype = tab.otype or dalos.objtype.DUMMY, + activate = tab.activate or dalosp.object.default_activate, + configure = tab.configure or dalosp.object.default_configure, extra = extra, } @@ -182,6 +240,7 @@ dalos.objtype = { d = dalos.canvas {} m = dalos.menu {} o = dalos.object(d) +o2 = dalos.object(d) dlg = iup.dialog { d, title = "Dalos", menu = m } -- cgit v1.2.3