From 99eb0952b67b7f7f9dffd6b744dfe123e45d1bae Mon Sep 17 00:00:00 2001 From: John-Michael Faircloth Date: Fri, 2 Sep 2022 15:30:15 -0500 Subject: [PATCH 1/2] Work in progress: use canvas for day view actagram --- browse/makefile | 5 +- browse/showdir.c | 76 ++++++++++-- browse/showdir.js | 295 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 368 insertions(+), 8 deletions(-) create mode 100755 browse/showdir.js diff --git a/browse/makefile b/browse/makefile index 94e2896..01e9e01 100755 --- a/browse/makefile +++ b/browse/makefile @@ -3,7 +3,7 @@ CC=gcc -std=c99 -Wall -DVIEWCGI LINKER=link LINKCON = /nologo -all:objdir view.cgi wait_change.cgi tb.cgi ../../www/realtime.html ../../www/favicon.ico ../../www/showpic.js ../../www/styledir.css +all:objdir view.cgi wait_change.cgi tb.cgi ../../www/realtime.html ../../www/favicon.ico ../../www/showpic.js ../../www/showdir.js ../../www/styledir.css OBJ = obj @@ -49,5 +49,8 @@ wait_change.cgi: $(OBJ)/wait_change.o ../../www/showpic.js: showpic.js cp showpic.js ../../www +../../www/showdir.js: showdir.js + cp showdir.js ../../www + ../../www/styledir.css: styledir.css cp styledir.css ../../www diff --git a/browse/showdir.c b/browse/showdir.c index fbefd74..90eb67a 100755 --- a/browse/showdir.c +++ b/browse/showdir.c @@ -80,6 +80,7 @@ static void PrintNavLinks(Dir_t * Dir, int IsRoot) //---------------------------------------------------------------------------------- // Show an actagram for one hour. //---------------------------------------------------------------------------------- +/* static void ShowHourActagram(VarList SubdImages, char * HtmlPath, char * SubdirName) { // Build an actagram for the hour. @@ -129,6 +130,7 @@ static void ShowHourActagram(VarList SubdImages, char * HtmlPath, char * SubdirN if (hrefOpen) printf(""); printf("\n"); } +*/ //---------------------------------------------------------------------------------- // Show directories for all the hours (or days) @@ -140,9 +142,9 @@ static int ShowHourlyDirs(char * HtmlPath, int IsRoot, VarList Directories) int prevwkd = 6, thiswkd=6; for (int b=0;b\n"); if (!IsRoot) { - ShowHourActagram(SubdImages, HtmlPath, SubdirName); + //ShowHourActagram(SubdImages, HtmlPath, SubdirName); + printf("
\n\n", SubdirName); + int npic = 0; + char * Prefix = NULL; + int prefixlen = 0; + + for (int a=0;a<(int)SubdImages.NumEntries;a++){ + if (!NameIsImage(SubdirName)) continue; + + if (Prefix == NULL){ + Prefix = SubdirName; + prefixlen = 7; + continue; + } + + for (int b=0;b= 7 ? 7 : 0; + + + printf("\n\n"); } free(SubdImages.Entries); @@ -179,7 +238,7 @@ static int ShowHourlyDirs(char * HtmlPath, int IsRoot, VarList Directories) } printf("
\n"); if (TotImages) printf("
%d images
",TotImages); - + return TotImages; } @@ -430,11 +489,14 @@ void MakeHtmlOutput(Dir_t * Dir) // Add javascript for hover-over preview when showing a whole day's worth of images if (SubdirImages){ - + printf("

\n" "\n"); - // Javascript + // Include the showdir.js javascript file. + printf("\n"); + + // Javascript printf("\n"); + // Include the showdir.js javascript file. + printf("\n"); } free(SubdImages.Entries); @@ -405,11 +408,11 @@ void MakeHtmlOutput(Dir_t * Dir) int IsSavedDir = 0; int IsRoot = 0; - + if (strstr(Dir->HtmlPath, "saved") != NULL) IsSavedDir = 1; - + Images = Dir->Images; - Directories = Dir->Dirs; + Directories = Dir->Dirs; // Header of file. printf("\n%s\n",Dir->HtmlPath); @@ -453,7 +456,7 @@ void MakeHtmlOutput(Dir_t * Dir) } printf("

\n"); - + if (IsRoot){ // Show host name and free space for root directory. FILE * fp = fopen("/proc/sys/kernel/hostname","r"); @@ -461,20 +464,25 @@ void MakeHtmlOutput(Dir_t * Dir) memset(HostName, 0, 32); fread(HostName, 1, 30, fp); fclose(fp); - + struct statvfs sv; statvfs("pix/", &sv); printf("%s: %5.1f gig ", HostName, (double)sv.f_bavail * sv.f_bsize / 1000000000); printf("(%4.1f%%) free
\n", (double)(sv.f_bavail*100.0/sv.f_blocks)); } - + int SubdirImages = 0; if (Directories.NumEntries){ if (!IsSavedDir){ printf("20%.2s/%.2s/%.2s
",Dir->HtmlPath,Dir->HtmlPath+2,Dir->HtmlPath+4); } PrintNavLinks(Dir, IsRoot); + SubdirImages = ShowHourlyDirs(Dir->HtmlPath, IsRoot, Directories); + + // Include the showdir.js javascript file. + //printf("\n"); + }else{ PrintNavLinks(Dir, IsRoot); } @@ -484,7 +492,7 @@ void MakeHtmlOutput(Dir_t * Dir) ShowThumbnailList(Dir->HtmlPath, IsSavedDir, Images); } - printf("

\n"); + printf("

\n"); PrintNavLinks(Dir, IsRoot); // Add javascript for hover-over preview when showing a whole day's worth of images @@ -493,9 +501,6 @@ void MakeHtmlOutput(Dir_t * Dir) printf("

\n" "\n"); - // Include the showdir.js javascript file. - printf("\n"); - // Javascript printf("\n"); } + printf("\n"); + printf("\n"); } diff --git a/browse/showdir.js b/browse/showdir.js index 3a03daf..d99c1e9 100755 --- a/browse/showdir.js +++ b/browse/showdir.js @@ -2,42 +2,20 @@ // Invoked from HTML generated by view.cgi module showpic.c var canv = document.getElementById(subdirname); pic_mouseindex = -1 +console.log("canv", subdirname) -canv.addEventListener('mousemove', function(event) { - var x = event.pageX - canv.offsetLeft; - var thisbin = Math.floor(x / per_hist_bar) - if (ActNums[thisbin] >= 0){ - if (ScrollDir) PlayStop() - pic_mouseindex = ActNums[thisbin] - UpdatePix(); - } -}, false); - -canv.addEventListener('mouseleave', function (event) { - if (pic_mouseindex >= 0){ - pic_mouseindex = -1 - UpdatePix(); - } -}, false); - -canv.addEventListener('click', function(event) { - var x = event.pageX - canv.offsetLeft; - var thisbin = Math.floor(x / per_hist_bar) - if (ActBins[thisbin]){ - SetIndex(ActNums[thisbin]) - }else if (thisbin>0 && ActBins[thisbin-1]){ - SetIndex(ActNums[thisbin-1]) - }else if (thisbin= 0 ? pic_mouseindex : pic_index - var n = prefix+piclist[index] - document.getElementById("this").innerHTML = n.substring(5,7)+":"+n.substring(7,9)+":"+n.substring(9,11) - var imgname = subdir+n - var url = pixpath+imgname; - flagsstr = "" - if (AdjustBright){ - flagsstr = "b"; - url = "tb.cgi?"+imgname+(ShowBigOn?"$1":"$2") - } - if (!document.getElementById("view").complete){ - NextImgUrl = url; - }else{ - document.getElementById("view").src = url - } - if (ShowBigOn) flagsstr = flagsstr + "e"; - if (flagsstr != "") flagsstr = flagsstr +"," - var nch = "#"+flagsstr+prefix+piclist[index] - - UpdateActagram() - if (SaveResp){ - document.getElementById("save").innerHTML = "Save" - SaveResp = "" - } - - if ((pic_mouseindex < 0 || pic_mouseindex == pic_index) - && (nch != currenthash)){ - if (nch.substring(0,5) == currenthash.substring(0,5) || currenthash == ""){ - // If only image# changed, don't fill up the browser history. - // But... when scrubbing thru a lot of images on iPad, history.replacestate ends up - // failing, so I moved it late in the processing so it doesn't cause other stuff to fail. - // I should make it only call on pictouchend (or mouse up) - // to not overwhelm history.replacestate mechaism. - history.replaceState({}, imgname, nch) - }else{ - location.hash = nch - document.title = imgname - } - currenthash = nch - } -} - -function DoNext(dir){ - if (pic_index+dir < 0 || pic_index+dir >= piclist.length){ - PlayStop() - return 0 - }else{ - pic_index += dir - UpdatePix(); - return 1 - } -} - -ScrollDir = 0 -ScrollTimer = 0 -function ScrollMoreTimer() -{ - ScrollTimer = 0 - var img = document.querySelector('img') - if (!document.getElementById("view").complete) return; - - if (ScrollDir){ - if (DoNext(ScrollDir)){ - ScrollTimer = setTimeout(ScrollMoreTimer,isSavedDir?400:100) - } - } -} - -function SetIndex(index) -{ - pic_index = index - UpdatePix() -} - -function PlayStart(dir) -{ - ScrollDir = dir - DoNext(ScrollDir) - ScrollTimer = setTimeout(ScrollMoreTimer, 400) -} -function PlayStop() -{ - ScrollDir = 0 - document.getElementById("play").innerHTML="Play" - clearTimeout(ScrollTimer) - ScrollTimer = 0 -} - -function PlayButtonClick() -{ - if (ScrollDir){ - PlayStop() - }else{ - if (pic_index >= piclist.length-1) pic_index = 0 - PlayStart(1) - document.getElementById("play").innerHTML="Stop" - } -} - -function PrevNextDirLinkUpdate() -{ - if (PrevDir) document.getElementById("prevdir").href = "view.cgi?"+PrevDir+"/#"+flagsstr - if (NextDir) document.getElementById("nextdir").href = "view.cgi?"+NextDir+"/#"+flagsstr -} - - -DragActive = false -xref = 0; -ref_index = 0; -MouseIsDown = 0 -TouchDebounce = false; // Touch and mouse events arrive out of order on iPad, so "debounce" to avoid turning - // single taps into double taps. - -function SizeImage() -{ - document.getElementById("big").innerHTML= ShowBigOn?"Smaller":"Enlarge" - if (ShowBigOn){ - vc.width = vc.naturalWidth; - vc.height = vc.naturalHeight; - ShwW = vc.width; - ShwH = vc.height; - return; - } - maxw = 950; maxh = 650 - //maxw = 600; maxh = 350 - - ShwW = maxw - if (ShwW > window.innerWidth-15) ShwW = window.innerWidth-15; - if (piclist.length == 0){ - return; - } - if (vc.naturalWidth > 0){ - ShwH = Math.round(ShwW*vc.naturalHeight/vc.naturalWidth) - if (ShwH > maxh){ - ShwH = maxh; - ShwW = Math.round(ShwH*vc.naturalWidth/vc.naturalHeight) - } - }else{ - console.log("Unknown width") - ShwW = 320; ShwH = 240 - } - vc.width = ShwW - vc.height = ShwH -} - - // Fill bins for actagram (a sort of motion time histogram) ActBins = [] ActNums = [] @@ -245,51 +72,4 @@ for (a=0;a 0 && ci < 5){ - flags=pct.substring(0,ci) - pct = pct.substring(ci) - } - var nab = flags.indexOf("b") >= 0 - if (nab != AdjustBright){ - AdjustBright = nab; - UpdBrBt(); - } - var lsb = ShowBigOn; - ShowBigOn = flags.indexOf("e") >= 0 - if (lsb != ShowBigOn && LastWidth !=0) SizeImage(); - - // Figure out index in picture list based on URL after '#' - var m = pct.substring(prefix.length+1) - //if (m.substring(m.length-4) == ".jpg") m = m.substring(0,m.length-4) - for (pic_index=0;pic_index= m) break; - } - if (pct == "first") pic_index = 0; - if (pct == "last") pic_index = piclist.length-1 - //console.log("big:"+ShowBigOn+" Bright:"+AdjustBright); - }else{ - pic_index = 0 - AdjustBright = ShowBigOn = false; - } - UpdatePix(); -} - UpdateActagram() -window.onhashchange = ReadHash -ReadHash(); -function DbgAdd(msg){ -// dbg = (dbg+" "+msg) -// document.getElementById("dbg").innerHTML = dbg -}