michael@0: -- Initiate scene management michael@0: local sceneloc = director:createScene() michael@0: sceneloc.name = 'Scene: Main' michael@0: michael@0: -- Database instantiated michael@0: local debe michael@0: local pathStor = system:getFilePath('storage') michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: debe:exec[=[ michael@0: CREATE TABLE qsos(id INTEGER PRIMARY KEY, call TEXT); michael@0: ]=] michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: -- Constants calculated michael@0: local dsw = director.displayWidth michael@0: local dsh = director.displayHeight michael@0: local dmw = director.displayCenterX michael@0: local dmh = director.displayCenterY michael@0: michael@0: -- Fonts created michael@0: local fontsegoe = director:createFont('fonts/SegoeUI-92pt_smbld.fnt') michael@0: local fontarial = director:createFont('fonts/Arial-96pt_bold.fnt') michael@0: michael@0: -- Tables of indexed and marked db rows michael@0: local dbIdx = {0, 0, 0, 0, 0, 0, 0} michael@0: local dbMrk = {0, 0, 0, 0, 0, 0, 0} michael@0: michael@0: -- Scrolling index michael@0: local nScroll = 0 michael@0: michael@0: -- Scrolling placeholder michael@0: local posMove = 0 michael@0: michael@0: function sceneloc:setUp(event) michael@0: dbg.print('sceneloc:setUp') michael@0: --self.obj0 = director:createLabel(4, dh/2, 'MAIN MENU') michael@0: --self.obj1 = director:createRectangle( michael@0: michael@0: -- Print background michael@0: local imgback = director:createSprite(0, dsh - fontarial.height * 12, 'textures/skynorm.png') michael@0: imgback.xScale = dsw / imgback.w michael@0: imgback.yScale = fontarial.height * 10.5 / imgback.h michael@0: michael@0: -- Declare defaults michael@0: --director:setNodesColor(32, 32, 32, 128) michael@0: --director:setNodesColor(112, 128, 144, 255) michael@0: director:setNodesColor(192, 192, 192) michael@0: michael@0: -- Heading labels michael@0: -- x=0, y=dsh-fontarial.height, michael@0: -- x=dsw/2, y=dsh-fontarial.height, michael@0: -- textTouchableBorder=0 michael@0: local labnull = director:createLabel() michael@0: --labnull.isVisible = false michael@0: -- x=-dsw/4, y=-fontarial.height*1.5/6, michael@0: -- x=dsw/4, y=-fontarial.height*1.5/6, michael@0: -- hAlignment='centre', vAlignment='top', michael@0: local labtitle = director:createLabel({ michael@0: x=0, y=-fontarial.height*1.5/6, michael@0: hAlignment='centre', vAlignment='top', michael@0: font=fontarial, michael@0: text='Amalog', michael@0: color={0xe0, 0xe0, 0xff} michael@0: }) michael@0: local butabout = director:createSprite(0, 0, 'images/buttinfo.png') michael@0: butabout.x = fontarial.height*1.5/2 michael@0: butabout.y = dsh-fontarial.height*1.5/2 michael@0: butabout.xAnchor = 0.5 michael@0: butabout.yAnchor = 0.5 michael@0: local buthelp = director:createSprite(0, 0, 'images/butthelp.png') michael@0: buthelp.x = dsw-fontarial.height*1.5/2 michael@0: buthelp.y = dsh-fontarial.height*1.5/2 michael@0: buthelp.xAnchor = 0.5 michael@0: buthelp.yAnchor = 0.5 michael@0: --tween:dissolve(labnull, butabout, 1, 0) michael@0: --tween:dissolve(labnull, buthelp, 1, 0) michael@0: michael@0: --local rectest = director:createRectangle(0, (dsh - fontarial.height * 4.5), dsw, fontarial.height * 1.5) michael@0: rectoddy = director:createRectangle(0, (dsh - fontarial.height * 3), dsw, fontarial.height * 1.5) michael@0: --rectoddy.color = color.black; rectoddy.color.a = 224; michael@0: rectoddy.color = color.lightGrey michael@0: recteven = director:createRectangle(0, (dsh - fontarial.height * 4.5), dsw, fontarial.height * 1.5) michael@0: recthree = director:createRectangle(0, (dsh - fontarial.height * 6), dsw, fontarial.height * 1.5) michael@0: --recthree.color = color.black; recthree.color.a = 224; michael@0: recthree.color = color.lightGrey michael@0: rectfour = director:createRectangle(0, (dsh - fontarial.height * 7.5), dsw, fontarial.height * 1.5) michael@0: rectfive = director:createRectangle(0, (dsh - fontarial.height * 9), dsw, fontarial.height * 1.5) michael@0: --rectfive.color = color.black; rectfive.color.a = 224; michael@0: rectfive.color = color.lightGrey michael@0: rectseis = director:createRectangle(0, (dsh - fontarial.height * 10.5), dsw, fontarial.height * 1.5) michael@0: rectsieb = director:createRectangle(0, (dsh - fontarial.height * 12), dsw, fontarial.height * 1.5) michael@0: --rectsieb.color = color.black; rectsieb.color.a = 224; michael@0: rectsieb.color = color.lightGrey michael@0: michael@0: ----local labtext = director:createLabel(0, 0, 'Excusez moi Welt!') michael@0: --local labheight = director:createLabel({x=0, y=0, font=fontsegoe, color=color.white, text=dsh}) michael@0: --local labwidth = director:createLabel({x=0, y=fontsegoe.height, font=fontsegoe, color=color.yellow, text=dsw}) michael@0: --local labmith = director:createLabel({x=0, y=2*fontsegoe.height, font=fontsegoe, color=color.green, text=dmh}) michael@0: --local labmitw = director:createLabel({x=0, y=3*fontsegoe.height, font=fontsegoe, color=color.blue, text=dmw}) michael@0: michael@0: function rectoddy:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif rectoddy.color.r == 240 and rectoddy.color.g == 230 and rectoddy.color.b == 140 then michael@0: rectoddy.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: rectoddy.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: --if event.phase == 'moved' then michael@0: -- posMove = event.y michael@0: --end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectoddy:addEventListener('touch', rectoddy) michael@0: michael@0: function recteven:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif recteven.color.r == 220 and recteven.color.g == 210 and recteven.color.b == 120 then michael@0: recteven.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: recteven.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: recteven:addEventListener('touch', recteven) michael@0: michael@0: function recthree:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif recthree.color.r == 240 and recthree.color.g == 230 and recthree.color.b == 140 then michael@0: recthree.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: recthree.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: recthree:addEventListener('touch', recthree) michael@0: michael@0: function rectfour:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif rectfour.color.r == 220 and rectfour.color.g == 210 and rectfour.color.b == 120 then michael@0: rectfour.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: rectfour.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfour:addEventListener('touch', rectfour) michael@0: michael@0: function rectfive:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif rectfive.color.r == 240 and rectfive.color.g == 230 and rectfive.color.b == 140 then michael@0: rectfive.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: rectfive.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfive:addEventListener('touch', rectfive) michael@0: michael@0: function rectseis:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif rectseis.color.r == 220 and rectseis.color.g == 210 and rectseis.color.b == 120 then michael@0: rectseis.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: rectseis.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectseis:addEventListener('touch', rectseis) michael@0: michael@0: function rectsieb:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif rectsieb.color.r == 240 and rectsieb.color.g == 230 and rectsieb.color.b == 140 then michael@0: rectsieb.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: else michael@0: rectsieb.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectsieb:addEventListener('touch', rectsieb) michael@0: michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Populate UI michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: local nTemp = nCount michael@0: local nIter = 6; --for nIter = 0, 7 do michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nIter < 0 then break end michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: if event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: else michael@0: event.target.color = color.khaki michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: local labpopo = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: local butdel = director:createSprite(0, 0, 'images/buttdel1.png') michael@0: local butadd = director:createSprite(0, 0, 'images/buttadd.png') michael@0: michael@0: butdel.color = color.white michael@0: butdel.x = (dsw - butdel.w - butadd.w) / 3 michael@0: butdel.y = (dsh-fontarial.height*12)/2 michael@0: butdel.xAnchor = 0 michael@0: butdel.yAnchor = 0.5 michael@0: --butdel.xScale = 5 michael@0: --butdel.yScale = 1.25 michael@0: michael@0: butadd.color = color.white michael@0: butadd.x = dsw-dsw/8 michael@0: butadd.x = dsw - (dsw - butdel.w - butadd.w) / 3 michael@0: butadd.y = (dsh-fontarial.height*12)/2 michael@0: butadd.xAnchor = 1 michael@0: butadd.yAnchor = 0.5 michael@0: michael@0: -- Good transitions: slideInL/R, shrinkGrow, crossFade, fadeTR/BL, pageTurn, progressVertical michael@0: --local transoptl = {transitionType = 'progressHorizontal', transitionTime = 0.5} michael@0: local transoptr = {transitionType = 'slideInR', transitionTime = 0.5} michael@0: michael@0: function butabout:touch(event) michael@0: if event.phase == 'began' then michael@0: director:moveToScene(sceneAbout, transoptr) michael@0: end michael@0: end michael@0: butabout:addEventListener('touch', butabout) michael@0: michael@0: function buthelp:touch(event) michael@0: if event.phase == 'began' then michael@0: director:moveToScene(sceneHelp, transoptr) michael@0: end michael@0: end michael@0: buthelp:addEventListener('touch', buthelp) michael@0: michael@0: -- String reader events handler michael@0: function gotString(event) michael@0: if (event.type == 'error') then michael@0: dbg.print('Error reading string: ' .. event.text) michael@0: elseif (event.type == 'read') then michael@0: dbg.print('String read: ' .. event.text) michael@0: end michael@0: end michael@0: michael@0: function butadd:touch(event) michael@0: if (event.phase == 'began') then michael@0: -- Ensure that the string reading extension is available michael@0: if nui:isReadStringAvailable() then michael@0: -- Add a string reader event handler michael@0: system:addEventListener('stringread', gotString) michael@0: michael@0: -- Create the string reader michael@0: widginput = nui:readString('New QSO Entry', '', 'Call Sign, QTH, Notes...') michael@0: if widginput then michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: debe:exec('INSERT INTO qsos VALUES(NULL, \'' .. widginput .. '\')') michael@0: --debe:exec[=[ michael@0: -- INSERT INTO qsos VALUES(NULL, widginput); michael@0: --]=] michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nIter < 0 then break end michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: if event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: else michael@0: event.target.color = color.khaki michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: else michael@0: dbg.print('String reading is not supported on this platform') michael@0: end michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: butadd:addEventListener('touch', butadd) michael@0: michael@0: function butdel:touch(event) michael@0: if (event.phase == 'began') then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Iterate over visible rows, deleting michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: local nTemp = nCount michael@0: local nIter = 0; --for nIter = 0, 7 do michael@0: michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nIter > 6 then break end michael@0: if dbMrk[nIter+1] ~= 0 then michael@0: debe:exec('DELETE FROM qsos WHERE id = \'' .. dbRows['id'] .. '\'') michael@0: end michael@0: nIter = nIter + 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Repopulate UI michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: if event.phase == 'ended' then michael@0: if math.abs(event.y - posMove) > fontarial.height*1.5 then michael@0: -- Provide callback to count rows in table michael@0: local nCount = 0 michael@0: function countrows(udata, cols, values, names) michael@0: assert(udata == 'dingdong') michael@0: nCount = tonumber(values[1]) michael@0: return 0 michael@0: end michael@0: michael@0: -- Repopulate UI conditionally michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: local nRet = debe:exec('SELECT Count(*) FROM qsos', countrows, 'dingdong') michael@0: debe:close() michael@0: debe = nil michael@0: michael@0: if event.y - posMove > 0 then -- Gesture upward michael@0: if nScroll + 7 < nCount then michael@0: nScroll = nScroll + 7 michael@0: else michael@0: return michael@0: end michael@0: else -- Gesture downward michael@0: if nScroll - 7 >= 0 then michael@0: nScroll = nScroll - 7 michael@0: else michael@0: return michael@0: end michael@0: end michael@0: michael@0: -- Kludge stucked event handlers michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: michael@0: -- Clear viewport michael@0: for nIter = 0, 6 do michael@0: local rectfresh = director:createRectangle(0, (dsh - fontarial.height * 3 - nIter * fontarial.height * 1.5), dsw, fontarial.height * 1.5) michael@0: michael@0: function rectfresh:touch(event) michael@0: if event.phase == 'began' then michael@0: posMove = event.y michael@0: local nBase = event.y - (dsh - fontarial.height * 12) michael@0: local nRect = fontarial.height * 1.5 michael@0: local nTemp = nBase / nRect michael@0: local nIdx = 7 - math.floor(nTemp) michael@0: if dbIdx[nIdx] == 0 then michael@0: return michael@0: elseif event.target.color.r == 240 and event.target.color.g == 230 and event.target.color.b == 140 then michael@0: event.target.color = color.lightGrey michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 220 and event.target.color.g == 210 and event.target.color.b == 120 then michael@0: event.target.color = {192, 192, 192} michael@0: dbMrk[nIdx] = 0 michael@0: elseif event.target.color.r == 192 and event.target.color.g == 192 and event.target.color.b == 192 then michael@0: event.target.color = {220, 210, 120} michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: else michael@0: event.target.color = color.khaki michael@0: dbMrk[nIdx] = dbIdx[nIdx] michael@0: end michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: rectfresh:addEventListener('touch', rectfresh) michael@0: michael@0: if nIter % 2 == 0 then michael@0: rectfresh.color = color.lightGrey michael@0: else michael@0: rectfresh.color = {192, 192, 192} michael@0: end michael@0: michael@0: -- Clear indexes michael@0: dbIdx[nIter+1] = 0 michael@0: dbMrk[nIter+1] = 0 michael@0: end michael@0: michael@0: -- Redraw labels michael@0: local nIter = 6 michael@0: --for nIter = 0, 7 do michael@0: local nTemp = nCount - nScroll michael@0: if nTemp < 7 then michael@0: nIter = nTemp - 1 michael@0: end michael@0: michael@0: debe = sqlite3.open(pathStor .. 'amalog.sql') michael@0: for dbRows in debe:nrows('SELECT * FROM qsos') do michael@0: if nTemp < 8 then michael@0: if nTemp < 0 then break end michael@0: if nIter < 0 then break end michael@0: local labrepop = director:createLabel({ michael@0: x=fontsegoe.height/2, y=dsh-fontarial.height*(3+nIter*1.5) + (fontsegoe.height/3), michael@0: hAlignment='left', vAlignment='bottom', michael@0: font=fontsegoe, michael@0: text=dbRows['call'] michael@0: }) michael@0: dbIdx[nIter+1] = dbRows['id'] michael@0: nIter = nIter - 1 michael@0: nTemp = nTemp - 1 michael@0: else michael@0: nTemp = nTemp - 1 michael@0: end michael@0: end michael@0: debe:close() michael@0: debe = nil michael@0: end michael@0: posMove = 0 michael@0: end michael@0: end michael@0: butdel:addEventListener('touch', butdel) michael@0: end michael@0: michael@0: function sceneloc:tearDown(event) michael@0: dbg.print('sceneloc:tearDown') michael@0: --rectfresh:removeEventListener('touch', rectfresh) michael@0: rectoddy:removeEventListener('touch', rectoddy) michael@0: recteven:removeEventListener('touch', recteven) michael@0: recthree:removeEventListener('touch', recthree) michael@0: rectfour:removeEventListener('touch', rectfour) michael@0: rectfive:removeEventListener('touch', rectfive) michael@0: rectseis:removeEventListener('touch', rectseis) michael@0: rectsieb:removeEventListener('touch', rectsieb) michael@0: --self.obj0:removeFromParent() michael@0: --self.obj1:removeFromParent() michael@0: --self.obj0 = nil michael@0: --self.obj1 = nil michael@0: end michael@0: function sceneloc:enterPreTransition(event) michael@0: dbg.print('sceneloc:enterPreTransition') michael@0: end michael@0: function sceneloc:enterPostTransition(event) michael@0: dbg.print('sceneloc:enterPostTransition') michael@0: end michael@0: function sceneloc:exitPreTransition(event) michael@0: dbg.print('sceneloc:exitPreTransition') michael@0: end michael@0: function sceneloc:exitPostTransition(event) michael@0: dbg.print('sceneloc:exitPostTransition') michael@0: end michael@0: michael@0: sceneloc:addEventListener({'setUp', 'tearDown', 'enterPreTransition', michael@0: 'enterPostTransition', 'exitPreTransition', 'exitPostTransition'}, sceneloc) michael@0: michael@0: return sceneloc