Рефакторинг

This commit is contained in:
Book Pauk
2019-01-29 22:27:35 +07:00
parent e208697aef
commit bb6ec8d2bd

View File

@@ -360,10 +360,13 @@ class TextPage extends Vue {
this.linesDown = this.linesDownNext; this.linesDown = this.linesDownNext;
this.linesUp = this.linesUpNext; this.linesUp = this.linesUpNext;
} else { } else {
const lines = this.getLines(this.bookPos);
this.linesDown = lines.linesDown;
this.linesUp = lines.linesUp;
if (this.toggleLayout) if (this.toggleLayout)
this.page1 = this.drawPage(this.bookPos); this.page1 = this.drawPage(lines.linesDown);
else else
this.page2 = this.drawPage(this.bookPos); this.page2 = this.drawPage(lines.linesDown);
} }
if (this.currentTransition) { if (this.currentTransition) {
@@ -386,30 +389,30 @@ class TextPage extends Vue {
this.doEnd(); this.doEnd();
} }
drawPage(bookPos, nextChangeLines) { getLines(bookPos) {
if (!this.parsed || this.pageLineCount < 1)
return {};
return {
linesDown: this.parsed.getLines(bookPos, 2*this.pageLineCount),
linesUp: this.parsed.getLines(bookPos, -2*this.pageLineCount)
};
}
drawPage(lines) {
if (!this.lastBook || this.pageLineCount < 1) if (!this.lastBook || this.pageLineCount < 1)
return ''; return '';
let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` + let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
` color: ${this.textColor}; background-color: ${this.backgroundColor}">`; ` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
if (!this.book || !this.parsed.textLength) { if (!this.book || !lines || !this.parsed.textLength) {
out += '</div>'; out += '</div>';
return out; return out;
} }
const spaceWidth = this.measureText(' ', {}); const spaceWidth = this.measureText(' ', {});
const lines = this.parsed.getLines(bookPos, 2*this.pageLineCount);
if (!nextChangeLines) {
this.linesDown = lines;
this.linesUp = this.parsed.getLines(bookPos, -2*this.pageLineCount);
} else {
this.linesDownNext = lines;
this.linesUpNext = this.parsed.getLines(bookPos, -2*this.pageLineCount);
}
if (lines) {
let y = this.indentTB - this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift; let y = this.indentTB - this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
if (this.showStatusBar) if (this.showStatusBar)
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0); y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
@@ -480,7 +483,6 @@ class TextPage extends Vue {
} }
y += this.lineHeight; y += this.lineHeight;
} }
}
out += '</div>'; out += '</div>';
return out; return out;
@@ -556,10 +558,14 @@ class TextPage extends Vue {
if (i >= 0 && this.linesDown.length > i) { if (i >= 0 && this.linesDown.length > i) {
this.bookPosPrepared = this.linesDown[i].begin; this.bookPosPrepared = this.linesDown[i].begin;
const lines = this.getLines(this.bookPosPrepared);
this.linesDownNext = lines.linesDown;
this.linesUpNext = lines.linesUp;
if (this.toggleLayout) if (this.toggleLayout)
this.page2 = this.drawPage(this.bookPosPrepared, true);//наоборот this.page2 = this.drawPage(lines.linesDown);//наоборот
else else
this.page1 = this.drawPage(this.bookPosPrepared, true); this.page1 = this.drawPage(lines.linesDown);
this.pagePrepared = true; this.pagePrepared = true;
} }