Добавление теневых канвасов

This commit is contained in:
Book Pauk
2019-01-20 21:17:47 +07:00
parent f7f9f4d51e
commit c4049b90b3

View File

@@ -75,9 +75,15 @@ class TextPage extends Vue {
this.canvas.height = this.realHeight; this.canvas.height = this.realHeight;
} }
//this.offscreen = new OffscreenCanvas(256, 256); this.canvasCurr = new OffscreenCanvas(this.realWidth, this.realHeight);
this.canvasNext = new OffscreenCanvas(this.realWidth, this.realHeight);
this.contextCurr = this.canvasCurr.getContext('2d');
this.contextNext = this.canvasNext.getContext('2d');
this.contextMain.textAlign = 'left'; this.contextMain.textAlign = 'left';
this.contextNext.textAlign = 'left';
this.contextMain.textBaseline = 'bottom'; this.contextMain.textBaseline = 'bottom';
this.contextNext.textBaseline = 'bottom';
this.w = this.realWidth - 2*this.indent; this.w = this.realWidth - 2*this.indent;
this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0); this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
@@ -94,6 +100,8 @@ class TextPage extends Vue {
} }
this.statusBarColor = this.hex2rgba(this.textColor, 0.5); this.statusBarColor = this.hex2rgba(this.textColor, 0.5);
this.currentTransition = '';
//drawHelper //drawHelper
this.drawHelper.realWidth = this.realWidth; this.drawHelper.realWidth = this.realWidth;
this.drawHelper.realHeight = this.realHeight; this.drawHelper.realHeight = this.realHeight;
@@ -137,13 +145,17 @@ class TextPage extends Vue {
this.p = 50;// px, отступ параграфа this.p = 50;// px, отступ параграфа
this.indent = 15;// px, отступ всего текста слева и справа this.indent = 15;// px, отступ всего текста слева и справа
this.wordWrap = true; this.wordWrap = true;
this.keepLastToFirst = true;//перенос последней строки в первую при листании
this.showStatusBar = true; this.showStatusBar = true;
this.statusBarTop = false;//top, bottom this.statusBarTop = false;//top, bottom
this.statusBarHeight = 20;// px this.statusBarHeight = 20;// px
this.pageChangeTransition = '';//'' - нет, up-down, left-right, протаивание, мерцание
this.pageChangeTransitionSpeed = 50; //0-100%
this.calcDrawProps(); this.calcDrawProps();
this.draw();// пока не загрузили, очистим канвас this.draw(true);// пока не загрузили, очистим канвас
if (this.lastBook) { if (this.lastBook) {
(async() => { (async() => {
@@ -190,7 +202,19 @@ class TextPage extends Vue {
} }
draw(immediate) { draw(immediate) {
if (immediate) {
this.drawPage(this.contextMain); this.drawPage(this.contextMain);
this.drawPage(this.contextCurr);
} else {
this.contextCurr.drawImage(this.canvasNext, 0, 0);
this.drawPage(this.contextNext);
if (!this.currentTransition) {
this.contextMain.drawImage(this.canvasNext, 0, 0);
} else {
//make this.currentTransition
}
this.currentTransition = '';
}
} }
drawPage(context) { drawPage(context) {
@@ -302,8 +326,10 @@ class TextPage extends Vue {
doPageDown() { doPageDown() {
if (this.linesDown) { if (this.linesDown) {
let i = this.pageLineCount; let i = this.pageLineCount;
if (this.keepLastToFirst)
i--; i--;
if (i >= 0 && this.linesDown.length > i) { if (i >= 0 && this.linesDown.length > i) {
this.currentTransition = this.pageChangeTransition;
this.bookPos = this.linesDown[i].begin; this.bookPos = this.linesDown[i].begin;
} }
} }
@@ -312,9 +338,11 @@ class TextPage extends Vue {
doPageUp() { doPageUp() {
if (this.linesUp) { if (this.linesUp) {
let i = this.pageLineCount; let i = this.pageLineCount;
if (this.keepLastToFirst)
i--; i--;
i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i); i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
if (i >= 0 && this.linesUp.length > i) { if (i >= 0 && this.linesUp.length > i) {
this.currentTransition = this.pageChangeTransition;
this.bookPos = this.linesUp[i].begin; this.bookPos = this.linesUp[i].begin;
} }
} }