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