diff options
author | Pixel <pixel@nobis-crew.org> | 2009-12-24 19:24:55 +0100 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-12-24 19:24:55 +0100 |
commit | dc22c96581d74e353b722edd903ee1c5eeb67414 (patch) | |
tree | 3ffb68391356bafc7557554ccd1fbcbde697ba42 | |
parent | 00bd9d1299f954b6776429e6b91159649fa1ccf9 (diff) |
Adding more hexview configuration items, and adding the ability of the hexviewer to display read limits, somehow.
-rw-r--r-- | dalos-hexview.lua | 49 | ||||
-rw-r--r-- | dalos-luahandle.lua | 1 | ||||
-rw-r--r-- | iupe-hexview.lua | 23 |
3 files changed, 62 insertions, 11 deletions
diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 79f2a08..0ee8a8c 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -32,17 +32,38 @@ dalosp.hexview = { end, configure = function (self) + local s, newname, gsx, gsy, dgsx, dgsy, dl, ml = + iup.GetParam(self.name .. " properties", nil, [[ +Name: %s +Gridsize X: %i +Gridsize Y: %i +Default gridsize X: %i +Default gridsize Y: %i +Lines: %i +Marker lengths: %b +]], + self.name, self.extra.hv.gridsize.x, self.extra.hv.gridsize.y, iupep.hexview.gridsize.x, iupep.hexview.gridsize.y, + self.extra.hv.displaylines, self.extra.hv.showmarkerslengths and 1 or 0) + if not s then return end + self.name = newname + self.extra.hv.gridsize.x = gsx + self.extra.hv.gridsize.y = gsy + iupep.hexview.gridsize.x = dgsx + iupep.hexview.gridsize.y = dgsy + self.extra.hv.displaylines = dl + self.extra.hv.showmarkerslengths = ml == 1 end, get_settings = function (self) - local hv = extra.hv + local hv = self.extra.hv local r = { mcursor = hv.mcursor + 0, kcursor = hv.kcursor + 0, markers = {}, filecursor = hv.filecursor + 0, - nbbytes = hv.nbbytes + 0, - nblines = hv.nblines + 0, + displaylines = hv.displaylines + 0, + gridsize = hv.gridsize, + showmarkerslengths = hv.showmarkerslengths, } for i = 1, 10 do r.markers[i] = hv.markers[i] + 0 @@ -51,6 +72,7 @@ dalosp.hexview = { end, output_change = function (self, ind) + self.extra.hv.markerslengths[ind] = 0 self.watchees[ind] = self.outputs[ind] and true or false self:set_houtput(nil, ind) self.oldcursors[ind] = -1 @@ -58,13 +80,16 @@ dalosp.hexview = { end, update_houtput = function (self, ind, cursor) + local hv = self.extra.hv local h = self:get_linked_input(1) local maxsize = h and h:getsize() or -1 cursor = cursor + 0 if cursor >= 0 and h and self.watchees[ind] then - if cursor < maxsize then + if cursor >= maxsize then self:set_houtput(nil, ind) + return end + h:seek(cursor) local obj = { h = h, hvo = self, @@ -75,10 +100,21 @@ dalosp.hexview = { getmodif = function (self) return self.hvo:getmodif() end, do_seek = function (self) self.h:seek(self.offset + self.origin) + self:post_read() end, do_read = function (self, count, userdata) return self.h:read(count, userdata) end, + post_read = function (self, count) + local ol = hv.markerslengths[ind] + local nl = self.offset + if nl > ol then + hv.markerslengths[ind] = nl + if hv.showmarkerslengths then + hv:draw() + end + end + end, } self:set_houtput(dalos.luahandle(obj), ind) end @@ -145,8 +181,9 @@ dalosp.hexview = { if settings.mcursor then hv.mcursor = settings.mcursor end if settings.kcursor then hv.kcursor = settings.kcursor end if settings.filecursor then hv.filecursor = settings.filecursor end - if settings.nbbytes then hv.nbbytes = settings.nbbytes end - if settings.nblines then hv.nblines = settings.nblines end + if settings.displaylines then hv.displaylines = settings.displaylines end + if settings.gridsize then hv.gridsize.x, hv.gridsize.y = settings.gridsize.x, settings.gridsize.y end + if settings.showmarkerslengths then hv.showmarkerslengths = settings.showmarkerslengths end end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 952f856..d3615fc 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -38,6 +38,7 @@ dalosp.luahandle = { local r, t = self:do_read(count, userdata) self.offset = self.offset + r + if self.post_read then self:post_read(r) end return r, t end, } diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 1d5f9e3..fb02b68 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -34,6 +34,8 @@ markercolors = { } iupep.hexview = { + gridsize = { x = 8, y = 14 }, + printgrid = function (self, msg, y, x) local cvdb = self.cvdb if not x then x = self.textcursor.x end @@ -116,15 +118,24 @@ iupep.hexview = { self:colorgrid(cursorcolors.GREEN, 2, kline, kcolumn * 3 + 10) self:colorgrid(cursorcolors.GREEN, 1, kline, kcolumn + 12 + columns * 3) - local marker + local marker, len, mlen for i = 0, 10 do marker = self.markers[i] or -1 marker = marker - filecursor - if marker >= 0 and marker < nbbytes then + mlen = self.markerslengths[i] + if marker >= 0 and self.showmarkerslengths and mlen and mlen > 0 then + len = math.min(mlen, nbbytes - marker) + elseif marker >= 0 and marker < nbbytes then + len = 1 + else + len = 0 + end + for j = 1, len do mline = math.floor(marker / columns) mcolumn = marker % columns self:colorgrid(markercolors[i], 2, mline, mcolumn * 3 + 10) self:colorgrid(markercolors[i], 1, mline, mcolumn + 12 + columns * 3) + marker = marker + 1 end end @@ -522,7 +533,7 @@ iupep.hexview = { end, updategridsize = function (self, gridsize) - self.gridsize = gridsize or { x = 8, y = 14 } + self.gridsize = gridsize or iupep.hexview.gridsize self:resize_cb(self.width, self.height) end, @@ -575,9 +586,11 @@ iupep.hexview = { r.filesize = handle and handle:getsize() or 0 r.mcursor = -1 r.markers = {} - r.displaylines = -1 + r.markerslengths = {} + r.showmarkerslengths = false + r.displaylines = 0 for i = 0, 10 do r.markers[i] = -1 end - r.gridsize = gridsize or { x = 8, y = 14 } + r.gridsize = gridsize or iupep.hexview.gridsize r.textcursor = { x = 0, y = 0 } return r end, |