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(-) (limited to 'dalos-binaryops.lua') 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