cleanup before testing.

This commit is contained in:
Howland Owl 2013-09-26 15:22:23 +03:00
parent 893b5cf1de
commit 4f48d4d45f

431
sahli.js
View file

@ -1,7 +1,7 @@
// .___________________________________. ._____. // .___________________________________, ___
// | / | | . | |_____| // | / | | . \ .(___):
// | ____ | : | | | // | _______ | : \ : |
//: |___/ / | | l_____| | //: |___/ / | | \__| |
//| / | | | | //| / | | | |
//l__________/__________|___|______l__________j_____j //l__________/__________|___|______l__________j_____j
// //
@ -10,27 +10,30 @@
// Uses fonts by DMG, http://trueschool.se // Uses fonts by DMG, http://trueschool.se
// Uses SixteenColors textmode js library for rendering // Uses SixteenColors textmode js library for rendering
var Sahli = function(){ var Sahli = function() {
this.outbox = $('div#outbox'); this.outbox = $('div#outbox');
this.dbox = $('div#drawbox'); this.dbox = $('div#drawbox');
this.image; this.image = 0;
// scroll speed of 5 looks ... "ok" on macbook pro. 4 was original. // scroll speed of 5 looks ... "ok" on macbook pro. 4 was original.
this.scroll_speed = 5; this.scroll_speed = 5;
this.scroll_direction = 1; this.scroll_direction = 1;
this.zoomspeed = 200; this.zoomspeed = 200;
this.asciiasgfx = true; // changed at Evoke as the 16colors amiga bits aren't the same as old lib. this.asciiasgfx = true; // changed at Evoke as the 16colors amiga bits aren't the same as old lib.
// You need to submit your fixes/changes to them, truck... // You need to submit your fixes/changes to them, truck...
this.DEBUG = false; this.DEBUG = false;
this.dbox.height(document.height - 24); this.dbox.height(document.height - 24);
this.dbox.width(document.width - 2); this.dbox.width(document.width - 2);
this.sizemult = 16; // 32 is larger than screen, and somewhat silly this.sizemult = 16; // 32 is larger than screen, and somewhat silly
this.origheight, this.origwidth, this.filedata, this.slides; this.origheight = 0;
this.origwidth = 0;
this.filedata = '';
this.slides = 0;
this.currentpic = 0; this.currentpic = 0;
this.nonfsheight = document.height - 40; this.nonfsheight = document.height - 40;
this.loadpic = function(picdata,inserthere){ this.loadpic = function(picdata, inserthere) {
var infob = $('div.infobox'); var infob = $('div.infobox');
var pdiv = $('<div>'); var pdiv = $('<div>');
var canv = document.createElement('canvas'); var canv = document.createElement('canvas');
@ -42,21 +45,25 @@ var Sahli = function(){
var color = this.calccolor(picdata.color); var color = this.calccolor(picdata.color);
var bgcolor = this.calccolor(picdata.bg); var bgcolor = this.calccolor(picdata.bg);
ptxt.addClass(picdata.font.toLowerCase()); ptxt.addClass(picdata.font.toLowerCase());
ptxt.css({'color':color,'background-color':bgcolor,'margin':'auto'}); ptxt.css({
ptxt.width(picdata.width*8); 'color': color,
'background-color': bgcolor,
'margin': 'auto'
});
ptxt.width(picdata.width * 8);
pdiv.width('100%'); pdiv.width('100%');
pdiv.append(ptxt); pdiv.append(ptxt);
// x-user-defined // x-user-defined
req.overrideMimeType('text/plain; charset=ISO-8859-1'); req.overrideMimeType('text/plain; charset=ISO-8859-1');
req.onreadystatechange = function () { req.onreadystatechange = function() {
if (req.readyState === req.DONE) { if (req.readyState === req.DONE) {
if (req.status === 200 || req.status === 0) { if (req.status === 200 || req.status === 0) {
ptxt.text(this.responseText); ptxt.text(this.responseText);
inserthere.after(pdiv); inserthere.after(pdiv);
} else { } else {
// I really should make a real error handler. // I really should make a real error handler.
alert(req); alert(req);
}; }
} }
}; };
req.open('GET', picdata.file, true); req.open('GET', picdata.file, true);
@ -66,11 +73,11 @@ var Sahli = function(){
this.image = new ImageTextModeANSI(); this.image = new ImageTextModeANSI();
this.image.parseUrl(picdata.file); this.image.parseUrl(picdata.file);
this.image.renderCanvas(canv); this.image.renderCanvas(canv);
pdiv.append(canv) pdiv.append(canv);
inserthere.after(pdiv); inserthere.after(pdiv);
this.origwidth=canv.width; this.origwidth = canv.width;
this.origheight=canv.height; this.origheight = canv.height;
}; }
infob.find('h1').text(picdata.name); infob.find('h1').text(picdata.name);
infob.find('h2').text(picdata.author); infob.find('h2').text(picdata.author);
infob.find('h3#text').text(picdata.line1); infob.find('h3#text').text(picdata.line1);
@ -82,55 +89,67 @@ var Sahli = function(){
}; };
this.calccolor = function(colorset) { this.calccolor = function(colorset) {
return 'rgba('+colorset.toString()+')'; return 'rgba(' + colorset.toString() + ')';
}; };
this.resize = function(amt){ this.resize = function(amt) {
var canv = $('canvas'); var canv = $('canvas');
var w = canv.width() * amt; var w = canv.width() * amt;
var h = canv.height() * amt; var h = canv.height() * amt;
canv.animate({width:w,height:h},this.zoomspeed); canv.animate({
width: w,
height: h
}, this.zoomspeed);
}; };
this.fullwidth = function(){ this.fullwidth = function() {
this.stopscroll(); this.stopscroll();
if($('canvas').width() == this.dbox.width() ) { if ($('canvas').width() == this.dbox.width()) {
this.originalsize(this.zoomspeed); this.originalsize(this.zoomspeed);
} else { } else {
var ratio = this.origwidth / this.dbox.width(); var ratio = this.origwidth / this.dbox.width();
$('canvas').animate({width:this.dbox.width(),height:this.origheight / ratio},this.zoomspeed); $('canvas').animate({
width: this.dbox.width(),
height: this.origheight / ratio
}, this.zoomspeed);
} }
}; };
this.fullheight = function(){ this.fullheight = function() {
var canv = $('canvas'); var canv = $('canvas');
if(canv.height() == this.dbox.height() ) { if (canv.height() == this.dbox.height()) {
this.originalsize(this.zoomspeed); this.originalsize(this.zoomspeed);
} else { } else {
var ratio = this.origheight / this.dbox.height() ; var ratio = this.origheight / this.dbox.height();
canv.animate({height: this.dbox.height(), width:this.origwidth / ratio},this.zoomspeed); canv.animate({
height: this.dbox.height(),
width: this.origwidth / ratio
}, this.zoomspeed);
} }
}; };
this.originalsize = function(zoomspeed) { this.originalsize = function(zoomspeed) {
// why do we not have origwidth now? hmm. // why do we not have origwidth now? hmm.
var canv = $('canvas'); var canv = $('canvas');
canv.animate({width: this.origwidth, height:this.origheight},this.zoomspeed); canv.animate({
width: this.origwidth,
height: this.origheight
}, this.zoomspeed);
}; };
this.toptext = function(text) { this.toptext = function(text) {
if (this.DEBUG) { if (this.DEBUG) {
$('h1#top').text(text); $('h1#top').text(text);
}; }
}; };
this.setscroll = function() { this.setscroll = function() {
var bottom = $('.scrolly').height(); var bottom = $('.scrolly').height();
var scrollto = bottom; var scrollto = bottom;
var steps; var steps;
// kill animations from before // kill animations from before
this.dbox.stop(true); this.dbox.stop(true);
if (this.scroll_direction === 1) { if (this.scroll_direction === 1) {
this.scroll_direction = -1; this.scroll_direction = -1;
@ -140,14 +159,16 @@ var Sahli = function(){
scrollto = 0; scrollto = 0;
steps = this.dbox.scrollTop(); steps = this.dbox.scrollTop();
} }
this.toptext(this.scroll_speed +' | '+ steps); this.toptext(this.scroll_speed + ' | ' + steps);
this.dbox.animate({scrollTop : scrollto}, this.scroll_speed*steps ,'linear'); this.dbox.animate({
scrollTop: scrollto
}, this.scroll_speed * steps, 'linear');
}; };
this.resizedrawbox = function(height) { this.resizedrawbox = function(height) {
var dbox1 = $('div#drawbox'); var dbox1 = $('div#drawbox');
if( 'undefined' === typeof height ) { if ('undefined' === typeof height) {
dbox1.height(window.innerHeight - 2); dbox1.height(window.innerHeight - 2);
} else { } else {
dbox1.height(height); dbox1.height(height);
@ -155,33 +176,33 @@ var Sahli = function(){
dbox1.width(window.innerWidth - 2); dbox1.width(window.innerWidth - 2);
}; };
this.stopscroll = function () { this.stopscroll = function() {
this.dbox.stop(true); this.dbox.stop(true);
}; };
this.moveabout = function(lines) { this.moveabout = function(lines) {
var line = this.dbox.scrollTop(); var line = this.dbox.scrollTop();
this.dbox.stop(true); this.dbox.stop(true);
switch(lines) { switch (lines) {
case 0: case 0:
this.dbox.scrollTop(0); this.dbox.scrollTop(0);
break; break;
case Infinity: case Infinity:
this.dbox.scrollTop(this.origheight); this.dbox.scrollTop(this.origheight);
break; break;
default: default:
this.dbox.scrollTop(line - lines * 8); this.dbox.scrollTop(line - lines * 8);
break; break;
} }
}; };
this.requestsahlifile = function(url) { this.requestsahlifile = function(url) {
var ref = this; var ref = this;
$.getJSON(url,function(json) { $.getJSON(url, function(json) {
ref.filedata = json.filedata; ref.filedata = json.filedata;
ref.slides = json.slides; ref.slides = json.slides;
ref.buildcompo(); ref.buildcompo();
} ); });
}; };
@ -192,197 +213,195 @@ var Sahli = function(){
this.nextpic = function() { this.nextpic = function() {
this.dbox.children().remove(); this.dbox.children().remove();
// reset scrolling; // reset scrolling;
this.stopscroll(); this.stopscroll();
this.scroll_direction = 1; this.scroll_direction = 1;
var i = this.currentpic; var i = this.currentpic;
var filedata = this.filedata; var filedata = this.filedata;
filedata[i].pic = $("<h6>"+filedata[i].file+"</h6>"); filedata[i].pic = $("<h6>" + filedata[i].file + "</h6>");
this.dbox.append(filedata[i].pic); this.dbox.append(filedata[i].pic);
this.loadpic(filedata[i],filedata[i].pic); this.loadpic(filedata[i], filedata[i].pic);
this.currentpic += 1; this.currentpic += 1;
if (this.currentpic > filedata.length -1 ) { if (this.currentpic > filedata.length - 1) {
this.currentpic = 0; this.currentpic = 0;
} }
}; };
this.gofullscreen = function(){ this.gofullscreen = function() {
var docElm= document.documentElement; var docElm = document.documentElement;
var toid = window.setTimeout( sahli.resizedrawbox, 100); var toid = window.setTimeout(sahli.resizedrawbox, 100);
if (docElm.requestFullscreen) { if (docElm.requestFullscreen) {
docElm.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT); docElm.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
} } else if (docElm.mozRequestFullScreen) {
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); docElm.mozRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} } else if (docElm.webkitRequestFullScreen) {
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); docElm.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} }
}; };
this.cancelfullscreen = function(){ this.cancelfullscreen = function() {
var toid = window.setTimeout( sahli.resizedrawbox, 100, this.nonfsheight ); var toid = window.setTimeout(sahli.resizedrawbox, 100, this.nonfsheight);
if (document.exitFullscreen) { if (document.exitFullscreen) {
document.exitFullscreen(); document.exitFullscreen();
} } else if (document.mozCancelFullScreen) {
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); document.mozCancelFullScreen();
} } else if (document.webkitCancelFullScreen) {
else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen(); document.webkitCancelFullScreen();
} }
}; };
this.fixhelpbox = function() { this.fixhelpbox = function() {
var h = $('.help'); var h = $('.help');
// var xy = {'top': document.height/2 - h.height()/2, 'left': document.width/2 - h.width()/2}; // var xy = {'top': document.height/2 - h.height()/2, 'left': document.width/2 - h.width()/2};
var xy = {'top': 0, 'left': document.width/2 - h.width()/2}; var xy = {
'top': 0,
'left': document.width / 2 - h.width() / 2
};
h.css(xy); h.css(xy);
}; };
this.toggledebug = function(){ this.toggledebug = function() {
$('h1#top').fadeToggle(); $('h1#top').fadeToggle();
this.DEBUG = (!this.DEBUG); this.DEBUG = (!this.DEBUG);
}; };
this.loadkeys = function(){ this.loadkeys = function() {
var ref = this; var ref = this;
$(document).bind('click', function(ev) { $(document).bind('click', function(ev) {
if (ev.clientY < 100) { if (ev.clientY < 100) {
if (ev.clientX < 100) { if (ev.clientX < 100) {
ref.nextpic(); ref.nextpic();
} else { } else {
ref.fullwidth(); ref.fullwidth();
} }
} else { } else {
ref.setscroll();
};
});
$(document).bind('keydown', function(ev){
switch(ev.which) {
case 84: // t
ref.asciiasgfx = (! ref.asciiasgfx);
ref.toptext(ref.asciiasgfx);
break;
case 85: // u
case 9: // u
$('div.infobox').slideToggle('slow');
break;
case 70: // f
ref.gofullscreen();
break;
case 27: // esc
case 71: // G, as escape seems to not get passed from fullscreen on chrome
ref.cancelfullscreen();
break;
case 73: // i
ref.resize(2);
break;
case 75: // k
ref.resize(.5);
break;
case 79: // o
ref.fullwidth();
break;
case 76: // l
ref.fullheight();
break;
case 80: // p
ref.originalsize(0);
break;
case 83: // s
ref.setscroll(); ref.setscroll();
break; }
case 72: // h });
case 191: // "?" (also / but no shift)
$('.help').fadeToggle('fast'); $(document).bind('keydown', function(ev) {
break; switch (ev.which) {
case 107: // + case 84: // t
case 190: // . ref.asciiasgfx = (!ref.asciiasgfx);
ref.scroll_speed = ref.scroll_speed * 2; ref.toptext(ref.asciiasgfx);
ref.toptext("speed doubled:" + ref.scroll_speed ); break;
break; case 85: // u
case 109: // - case 9: // u
case 188: // , $('div.infobox').slideToggle('slow');
ref.scroll_speed = ref.scroll_speed / 2; break;
ref.toptext("speed halved:" + ref.scroll_speed); case 70: // f
break; ref.gofullscreen();
case 49: // 1 break;
ref.scroll_speed = 1; case 27: // esc
break; case 71: // G, as escape seems to not get passed from fullscreen on chrome
case 50: //2 ref.cancelfullscreen();
ref.scroll_speed = 2; break;
break; case 73: // i
case 51: //3 ref.resize(2);
ref.scroll_speed = 3; break;
break; case 75: // k
case 52: //4 ref.resize(0.5);
ref.scroll_speed = 4; break;
break; case 79: // o
case 53: //5 ref.fullwidth();
ref.scroll_speed = 5; break;
break; case 76: // l
case 220: // "\" ref.fullheight();
ref.toptext(ref.scroll_speed); break;
break; case 80: // p
case 8: // backspace ref.originalsize(0);
case 68: // D break;
ref.stopscroll();
break; case 83: // s
// move about keys ref.setscroll();
case 33: // pgup break;
ref.moveabout(24); case 72: // h
break; case 191: // "?" (also / but no shift)
case 34: // pgdwn $('.help').fadeToggle('fast');
ref.moveabout(-24); break;
break; case 107: // +
case 36: // home case 190: // .
ref.moveabout(0); ref.scroll_speed = ref.scroll_speed * 2;
break; ref.toptext("speed doubled:" + ref.scroll_speed);
case 35: // end break;
ref.moveabout(Infinity); case 109: // -
break; case 188: // ,
case 40: // down ref.scroll_speed = ref.scroll_speed / 2;
ref.moveabout(-1); ref.toptext("speed halved:" + ref.scroll_speed);
break; break;
case 32: // space case 49: // 1
ref.nextpic(); ref.scroll_speed = 1;
break; break;
case 38: // up case 50: //2
ref.moveabout(1); ref.scroll_speed = 2;
break; break;
case 19: // pause/break case 51: //3
case 121: // F10 ref.scroll_speed = 3;
ref.toggledebug(); break;
break; case 52: //4
// debug alerts for these keys are annoying (: ref.scroll_speed = 4;
case 116: // f5 break;
case 123: // f12 case 53: //5
break; ref.scroll_speed = 5;
default: break;
if (ref.DEBUG) { case 220: // "\"
alert(ev.which); ref.toptext(ref.scroll_speed);
}; break;
break; case 8: // backspace
}; case 68: // D
ref.stopscroll();
break;
// move about keys
case 33: // pgup
ref.moveabout(24);
break;
case 34: // pgdwn
ref.moveabout(-24);
break;
case 36: // home
ref.moveabout(0);
break;
case 35: // end
ref.moveabout(Infinity);
break;
case 40: // down
ref.moveabout(-1);
break;
case 32: // space
ref.nextpic();
break;
case 38: // up
ref.moveabout(1);
break;
case 19: // pause/break
case 121: // F10
ref.toggledebug();
break;
// debug alerts for these keys are annoying (:
case 116: // f5
case 123: // f12
break;
default:
if (ref.DEBUG) {
alert(ev.which);
}
break;
}
}); });
}; };
this.loadkeys(); this.loadkeys();
// this.loadpic('h7-r2012.ans',this.dbox); // this.loadpic('h7-r2012.ans',this.dbox);
this.fixhelpbox(); this.fixhelpbox();
var ref = this; var ref = this;
$(window).resize(function () { $(window).resize(function() {
ref.resizedrawbox(); ref.resizedrawbox();
}); });
this.requestsahlifile('list.sahli'); this.requestsahlifile('list.sahli');
}; };
// Dammit I hate how conttrol-R in textmate is "some shell shit" // I switched to Sublime text + sublemacs pro.
// I also hate how scrolling is incredibly stupid on osX // Yes, the author of Sublime Text's emacs hatred is annoying.
// Mind you, it's better than touching anything in Windows.