TextPage.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <template>
  2. <div ref="main" class="main">
  3. <div v-show="toggleLayout" class="layout">
  4. <div v-html="page1"></div>
  5. </div>
  6. <div v-show="!toggleLayout" class="layout">
  7. <div v-html="page2"></div>
  8. </div>
  9. <div v-show="showStatusBar" ref="statusBar" class="layout">
  10. <div v-html="statusBar"></div>
  11. </div>
  12. <div ref="layoutEvents" class="layout events" @mousedown.prevent.stop="onMouseDown" @mouseup.prevent.stop="onMouseUp"
  13. @wheel.prevent.stop="onMouseWheel"
  14. @touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchcancel.prevent.stop="onTouchCancel"
  15. oncontextmenu="return false;">
  16. <div v-show="showStatusBar" v-html="statusBarClickable" @mousedown.prevent.stop @touchstart.stop
  17. @click.prevent.stop="onStatusBarClick"></div>
  18. <div v-show="fontsLoading" ref="fontsLoading"></div>
  19. </div>
  20. <!-- невидимым делать нельзя, вовремя не подгружаютя шрифты -->
  21. <canvas ref="offscreenCanvas" class="layout" style="width: 0px; height: 0px"></canvas>
  22. </div>
  23. </template>
  24. <script>
  25. //-----------------------------------------------------------------------------
  26. import Vue from 'vue';
  27. import Component from 'vue-class-component';
  28. import {loadCSS} from 'fg-loadcss';
  29. import _ from 'lodash';
  30. import {sleep} from '../../../share/utils';
  31. import bookManager from '../share/bookManager';
  32. import DrawHelper from './DrawHelper';
  33. export default @Component({
  34. watch: {
  35. bookPos: function(newValue) {
  36. this.debouncedEmitPosChange(newValue);
  37. this.draw();
  38. },
  39. },
  40. })
  41. class TextPage extends Vue {
  42. toggleLayout = false;
  43. showStatusBar = false;
  44. page1 = null;
  45. page2 = null;
  46. statusBar = null;
  47. statusBarClickable = null;
  48. fontsLoading = null;
  49. lastBook = null;
  50. bookPos = 0;
  51. fontStyle = null;
  52. fontSize = null;
  53. fontName = null;
  54. meta = null;
  55. created() {
  56. this.drawHelper = new DrawHelper();
  57. this.commit = this.$store.commit;
  58. this.dispatch = this.$store.dispatch;
  59. this.config = this.$store.state.config;
  60. this.reader = this.$store.state.reader;
  61. this.debouncedEmitPosChange = _.debounce((newValue) => {
  62. this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen});
  63. }, 1000);
  64. this.debouncedStartClickRepeat = _.debounce((x, y) => {
  65. this.startClickRepeat(x, y);
  66. }, 800);
  67. this.debouncedPrepareNextPage = _.debounce(() => {
  68. this.prepareNextPage();
  69. }, 100);
  70. this.debouncedDrawStatusBar = _.throttle(() => {
  71. this.drawStatusBar();
  72. }, 60);
  73. this.$root.$on('resize', () => {this.$nextTick(this.onResize)});
  74. this.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
  75. }
  76. mounted() {
  77. this.context = this.$refs.offscreenCanvas.getContext('2d');
  78. }
  79. hex2rgba(hex, alpha = 1) {
  80. const [r, g, b] = hex.match(/\w\w/g).map(x => parseInt(x, 16));
  81. return `rgba(${r},${g},${b},${alpha})`;
  82. }
  83. calcDrawProps() {
  84. //preloaded fonts
  85. this.fontShifts = {//%
  86. ReaderDefault: 0,
  87. Roboto: 0,
  88. OpenSans: 0,
  89. Archivo: 0,
  90. Rubik: 0,
  91. Avrile: -10,
  92. }
  93. if (!this.fontShifts.hasOwnProperty(this.fontName))
  94. this.fontShifts[this.fontName] = this.fontVertShift;
  95. this.fontList = [];
  96. for (let fontName in this.fontShifts)
  97. this.fontList.push(`12px ${fontName}`);
  98. //widths
  99. this.realWidth = this.$refs.main.clientWidth;
  100. this.realHeight = this.$refs.main.clientHeight;
  101. this.$refs.layoutEvents.style.width = this.realWidth + 'px';
  102. this.$refs.layoutEvents.style.height = this.realHeight + 'px';
  103. this.w = this.realWidth - 2*this.indent;
  104. this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
  105. this.lineHeight = this.fontSize + this.lineInterval;
  106. this.pageLineCount = Math.floor(this.h/this.lineHeight);
  107. if (this.parsed) {
  108. this.parsed.p = this.p;
  109. this.parsed.w = this.w;// px, ширина текста
  110. this.parsed.font = this.font;
  111. this.parsed.wordWrap = this.wordWrap;
  112. this.parsed.measureText = this.measureText;
  113. }
  114. //сообщение "Загрузка шрифтов..."
  115. const flText = 'Загрузка шрифта...';
  116. this.$refs.fontsLoading.innerHTML = flText;
  117. const fontsLoadingStyle = this.$refs.fontsLoading.style;
  118. fontsLoadingStyle.position = 'absolute';
  119. fontsLoadingStyle.fontSize = this.fontSize + 'px';
  120. fontsLoadingStyle.top = (this.realHeight/2 - 2*this.fontSize) + 'px';
  121. fontsLoadingStyle.left = (this.realWidth - this.measureText(flText, {}))/2 + 'px';
  122. //stuff
  123. this.statusBarColor = this.hex2rgba(this.textColor, this.statusBarColorAlpha);
  124. this.currentTransition = '';
  125. this.pageChangeDirectionDown = true;
  126. this.fontShift = (this.fontShifts[this.fontName] ? this.fontShifts[this.fontName] : 0)/100;
  127. //drawHelper
  128. this.drawHelper.realWidth = this.realWidth;
  129. this.drawHelper.realHeight = this.realHeight;
  130. this.drawHelper.backgroundColor = this.backgroundColor;
  131. this.drawHelper.statusBarColor = this.statusBarColor;
  132. this.drawHelper.fontName = this.fontName;
  133. this.drawHelper.fontShift = this.fontShift;
  134. this.drawHelper.measureText = this.measureText;
  135. this.drawHelper.measureTextFont = this.measureTextFont;
  136. this.$refs.statusBar.style.left = '0px';
  137. this.$refs.statusBar.style.top = (this.statusBarTop ? 1 : this.realHeight - this.statusBarHeight) + 'px';
  138. this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
  139. }
  140. measureText(text, style) {// eslint-disable-line no-unused-vars
  141. this.context.font = this.fontByStyle(style);
  142. return this.context.measureText(text).width;
  143. }
  144. measureTextFont(text, font) {// eslint-disable-line no-unused-vars
  145. this.context.font = font;
  146. return this.context.measureText(text).width;
  147. }
  148. async checkLoadedFonts() {
  149. let loaded = await Promise.all(this.fontList.map(font => document.fonts.check(font)));
  150. if (loaded.some(r => !r)) {
  151. loaded = await Promise.all(this.fontList.map(font => document.fonts.load(font)));
  152. if (loaded.some(r => !r.length))
  153. throw new Error('some font not loaded');
  154. }
  155. }
  156. async loadFonts() {
  157. this.fontsLoading = true;
  158. if (!this.fontsLoaded)
  159. this.fontsLoaded = {};
  160. //загрузка дин.шрифта
  161. const loaded = this.fontsLoaded[this.fontCssUrl];
  162. if (this.fontCssUrl && !loaded) {
  163. loadCSS(this.fontCssUrl);
  164. this.fontsLoaded[this.fontCssUrl] = 1;
  165. }
  166. const waitingTime = 10*1000;
  167. const delay = 100;
  168. let i = 0;
  169. //ждем шрифты
  170. while (i < waitingTime/delay) {
  171. i++;
  172. try {
  173. await this.checkLoadedFonts();
  174. i = waitingTime;
  175. } catch (e) {
  176. await sleep(delay);
  177. }
  178. }
  179. if (i !== waitingTime) {
  180. this.$notify.error({
  181. title: 'Ошибка загрузки',
  182. message: 'Некоторые шрифты не удалось загрузить'
  183. });
  184. }
  185. this.fontsLoading = false;
  186. }
  187. showBook() {
  188. this.$refs.main.focus();
  189. this.toggleLayout = false;
  190. this.book = null;
  191. this.meta = null;
  192. this.fb2 = null;
  193. this.parsed = null;
  194. this.linesUp = null;
  195. this.linesDown = null;
  196. //default draw props
  197. this.textColor = '#000000';
  198. this.backgroundColor = '#478355';
  199. this.fontStyle = '';// 'bold','italic'
  200. this.fontSize = 35;// px
  201. this.fontName = 'Archivo';
  202. this.fontCssUrl = '';
  203. this.fontVertShift = 0;
  204. this.lineInterval = 7;// px, межстрочный интервал
  205. this.textAlignJustify = true;// выравнивание по ширине
  206. this.p = 50;// px, отступ параграфа
  207. this.indent = 15;// px, отступ всего текста слева и справа
  208. this.wordWrap = true;
  209. this.keepLastToFirst = true;// перенос последней строки в первую при листании
  210. this.showStatusBar = true;
  211. this.statusBarTop = false;// top, bottom
  212. this.statusBarHeight = 19;// px
  213. this.statusBarColorAlpha = 0.4;
  214. this.pageChangeTransition = '';// '' - нет, downShift, rightShift, thaw - протаивание, blink - мерцание
  215. this.pageChangeTransitionSpeed = 50; //0-100%
  216. this.calcDrawProps();
  217. this.draw();// пока не загрузили, очистим канвас
  218. if (this.lastBook) {
  219. (async() => {
  220. const isParsed = await bookManager.hasBookParsed(this.lastBook);
  221. if (!isParsed) {
  222. return;
  223. }
  224. this.book = await bookManager.getBook(this.lastBook);
  225. this.meta = bookManager.metaOnly(this.book);
  226. this.fb2 = this.meta.fb2;
  227. const authorName = _.compact([
  228. this.fb2.lastName,
  229. this.fb2.firstName,
  230. this.fb2.middleName
  231. ]).join(' ');
  232. this.title = _.compact([
  233. authorName,
  234. this.fb2.bookTitle
  235. ]).join(' - ');
  236. this.$root.$emit('set-app-title', this.title);
  237. this.parsed = this.book.parsed;
  238. this.calcDrawProps();
  239. await this.loadFonts();
  240. //this.draw();
  241. // шрифты хрен знает когда подгружаются, поэтому
  242. let i = 0;
  243. this.parsed.force = true;
  244. while (i < 10) {
  245. this.draw();
  246. await sleep(1000);
  247. i++;
  248. }
  249. this.parsed.force = false;
  250. this.refreshTime();
  251. })();
  252. }
  253. }
  254. onResize() {
  255. this.calcDrawProps();
  256. this.draw();
  257. }
  258. get font() {
  259. return `${this.fontStyle} ${this.fontSize}px ${this.fontName}`;
  260. }
  261. fontByStyle(style) {
  262. return `${style.italic ? 'italic' : ''} ${style.bold ? 'bold' : ''} ${this.fontSize}px ${this.fontName}`;
  263. }
  264. draw() {
  265. if (this.w < 10)
  266. return;
  267. if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) {
  268. this.doEnd();
  269. return;
  270. }
  271. this.toggleLayout = !this.toggleLayout;
  272. if (this.pageChangeDirectionDown && this.pagePrepared && this.bookPos == this.bookPosPrepared) {
  273. this.linesDown = this.linesDownNext;
  274. this.linesUp = this.linesUpNext;
  275. } else {
  276. if (this.toggleLayout)
  277. this.page1 = this.drawPage(this.bookPos);
  278. else
  279. this.page2 = this.drawPage(this.bookPos);
  280. }
  281. if (this.currentTransition) {
  282. //this.currentTransition
  283. //this.pageChangeTransitionSpeed
  284. //this.pageChangeDirectionDown
  285. //curr to next transition
  286. //пока заглушка
  287. }
  288. this.currentTransition = '';
  289. this.pageChangeDirectionDown = false;//true только если PgDown
  290. this.pagePrepared = false;
  291. this.debouncedPrepareNextPage();
  292. this.debouncedDrawStatusBar();
  293. }
  294. drawPage(bookPos, nextChangeLines) {
  295. if (!this.lastBook)
  296. return;
  297. let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
  298. ` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
  299. if (!this.book || !this.parsed.textLength) {
  300. out += '</div>';
  301. return out;
  302. }
  303. const spaceWidth = this.measureText(' ', {});
  304. const lines = this.parsed.getLines(bookPos, 2*this.pageLineCount);
  305. if (!nextChangeLines) {
  306. this.linesDown = lines;
  307. this.linesUp = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  308. } else {
  309. this.linesDownNext = lines;
  310. this.linesUpNext = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  311. }
  312. let y = -this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
  313. if (this.showStatusBar)
  314. y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
  315. let len = lines.length;
  316. len = (len > this.pageLineCount ? len = this.pageLineCount : len);
  317. for (let i = 0; i < len; i++) {
  318. const line = lines[i];
  319. /* line:
  320. {
  321. begin: Number,
  322. end: Number,
  323. first: Boolean,
  324. last: Boolean,
  325. parts: array of {
  326. style: {bold: Boolean, italic: Boolean, center: Boolean}
  327. text: String,
  328. }
  329. }*/
  330. let indent = this.indent + (line.first ? this.p : 0);
  331. let lineText = '';
  332. let center = false;
  333. let centerStyle = {};
  334. for (const part of line.parts) {
  335. lineText += part.text;
  336. center = center || part.style.center;
  337. if (part.style.center)
  338. centerStyle = part.style.center;
  339. }
  340. let filled = false;
  341. // если выравнивание по ширине включено
  342. if (this.textAlignJustify && !line.last && !center) {
  343. const words = lineText.split(' ');
  344. if (words.length > 1) {
  345. const spaceCount = words.length - 1;
  346. const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
  347. let x = indent;
  348. for (const part of line.parts) {
  349. const font = this.fontByStyle(part.style);
  350. let partWords = part.text.split(' ');
  351. for (let i = 0; i < partWords.length; i++) {
  352. let word = partWords[i];
  353. out += this.drawHelper.fillText(word, x, y, font);
  354. x += this.measureText(word, part.style) + (i < partWords.length - 1 ? space : 0);
  355. }
  356. }
  357. filled = true;
  358. }
  359. }
  360. // просто выводим текст
  361. if (!filled) {
  362. let x = indent;
  363. x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
  364. for (const part of line.parts) {
  365. let text = part.text;
  366. const font = this.fontByStyle(part.style);
  367. out += this.drawHelper.fillText(text, x, y, font);
  368. x += this.measureText(text, part.style);
  369. }
  370. }
  371. y += this.lineHeight;
  372. }
  373. out += '</div>';
  374. return out;
  375. }
  376. drawStatusBar() {
  377. if (this.showStatusBar && this.linesDown) {
  378. const lines = this.linesDown;
  379. let i = this.pageLineCount;
  380. if (this.keepLastToFirst)
  381. i--;
  382. i = (i > lines.length - 1 ? lines.length - 1 : i);
  383. if (i >= 0) {
  384. this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
  385. lines[i].end, this.parsed.textLength, this.title);
  386. this.bookPosSeen = lines[i].end;
  387. }
  388. }
  389. }
  390. async refreshTime() {
  391. if (!this.timeRefreshing) {
  392. this.timeRefreshing = true;
  393. await sleep(60*1000);
  394. if (this.book && this.parsed.textLength) {
  395. this.debouncedDrawStatusBar();
  396. }
  397. this.timeRefreshing = false;
  398. this.refreshTime();
  399. }
  400. }
  401. prepareNextPage() {
  402. // подготовка следующей страницы заранее
  403. if (!this.book || !this.parsed.textLength || !this.linesDown)
  404. return;
  405. if (!this.preparing) {
  406. this.preparing = true;
  407. (async() => {
  408. await sleep(100);
  409. if (this.cancelPrepare) {
  410. this.preparing = false;
  411. return;
  412. }
  413. let i = this.pageLineCount;
  414. if (this.keepLastToFirst)
  415. i--;
  416. if (i >= 0 && this.linesDown.length > i) {
  417. this.bookPosPrepared = this.linesDown[i].begin;
  418. if (this.toggleLayout)
  419. this.page2 = this.drawPage(this.bookPosPrepared, true);//наоборот
  420. else
  421. this.page1 = this.drawPage(this.bookPosPrepared, true);
  422. this.pagePrepared = true;
  423. }
  424. this.preparing = false;
  425. })();
  426. }
  427. }
  428. doDown() {
  429. if (this.linesDown && this.linesDown.length > this.pageLineCount) {
  430. this.bookPos = this.linesDown[1].begin;
  431. }
  432. }
  433. doUp() {
  434. if (this.linesUp && this.linesUp.length > 1) {
  435. this.bookPos = this.linesUp[1].begin;
  436. }
  437. }
  438. doPageDown() {
  439. if (this.linesDown) {
  440. let i = this.pageLineCount;
  441. if (this.keepLastToFirst)
  442. i--;
  443. if (i >= 0 && this.linesDown.length >= 2*i) {
  444. this.currentTransition = this.pageChangeTransition;
  445. this.pageChangeDirectionDown = true;
  446. this.bookPos = this.linesDown[i].begin;
  447. } else
  448. this.doEnd();
  449. }
  450. }
  451. doPageUp() {
  452. if (this.linesUp) {
  453. let i = this.pageLineCount;
  454. if (this.keepLastToFirst)
  455. i--;
  456. i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
  457. if (i >= 0 && this.linesUp.length > i) {
  458. this.currentTransition = this.pageChangeTransition;
  459. this.pageChangeDirectionDown = false;
  460. this.bookPos = this.linesUp[i].begin;
  461. }
  462. }
  463. }
  464. doHome() {
  465. this.bookPos = 0;
  466. }
  467. doEnd() {
  468. if (this.parsed.para.length) {
  469. let i = this.parsed.para.length - 1;
  470. let lastPos = this.parsed.para[i].offset + this.parsed.para[i].length - 1;
  471. const lines = this.parsed.getLines(lastPos, -this.pageLineCount);
  472. i = this.pageLineCount - 1;
  473. i = (i > lines.length - 1 ? lines.length - 1 : i);
  474. this.bookPos = lines[i].begin;
  475. }
  476. }
  477. doToolBarToggle() {
  478. this.$emit('tool-bar-toggle');
  479. }
  480. keyHook(event) {
  481. //console.log(event.code);
  482. if (event.type == 'keydown') {
  483. switch (event.code) {
  484. case 'ArrowDown':
  485. this.doDown();
  486. break;
  487. case 'ArrowUp':
  488. this.doUp();
  489. break;
  490. case 'PageDown':
  491. case 'ArrowRight':
  492. case 'Space':
  493. this.doPageDown();
  494. break;
  495. case 'PageUp':
  496. case 'ArrowLeft':
  497. case 'Backspace':
  498. this.doPageUp();
  499. break;
  500. case 'Home':
  501. this.doHome();
  502. break;
  503. case 'End':
  504. this.doEnd();
  505. break;
  506. case 'Enter':
  507. case 'Backquote'://`
  508. case 'KeyF':
  509. if (this.fullScreenToggle)
  510. this.fullScreenToggle();
  511. break;
  512. case 'Tab':
  513. this.doToolBarToggle();
  514. event.preventDefault();
  515. event.stopPropagation();
  516. break;
  517. }
  518. }
  519. }
  520. async startClickRepeat(pointX, pointY) {
  521. this.repX = pointX;
  522. this.repY = pointY;
  523. if (!this.repInit && this.repDoing) {
  524. this.repInit = true;
  525. let delay = 400;
  526. while (this.repDoing) {
  527. this.handleClick(pointX, pointY);
  528. await sleep(delay);
  529. if (delay > 15)
  530. delay *= 0.8;
  531. }
  532. this.repInit = false;
  533. }
  534. }
  535. endClickRepeat() {
  536. this.repDoing = false;
  537. }
  538. onTouchStart(event) {
  539. if (!this.mobile)
  540. return;
  541. this.endClickRepeat();
  542. if (event.touches.length == 1) {
  543. const touch = event.touches[0];
  544. const rect = event.target.getBoundingClientRect();
  545. const x = touch.pageX - rect.left;
  546. const y = touch.pageY - rect.top;
  547. if (this.handleClick(x, y)) {
  548. this.repDoing = true;
  549. this.debouncedStartClickRepeat(x, y);
  550. }
  551. }
  552. }
  553. onTouchEnd() {
  554. if (!this.mobile)
  555. return;
  556. this.endClickRepeat();
  557. }
  558. onTouchCancel() {
  559. if (!this.mobile)
  560. return;
  561. this.endClickRepeat();
  562. }
  563. onMouseDown(event) {
  564. if (this.mobile)
  565. return;
  566. this.endClickRepeat();
  567. if (event.button == 0) {
  568. if (this.handleClick(event.offsetX, event.offsetY)) {
  569. this.repDoing = true;
  570. this.debouncedStartClickRepeat(event.offsetX, event.offsetY);
  571. }
  572. } else if (event.button == 2) {
  573. this.doToolBarToggle();
  574. }
  575. }
  576. onMouseUp() {
  577. if (this.mobile)
  578. return;
  579. this.endClickRepeat();
  580. }
  581. onMouseWheel(event) {
  582. if (this.mobile)
  583. return;
  584. if (event.deltaY > 0) {
  585. this.doDown();
  586. } else if (event.deltaY < 0) {
  587. this.doUp();
  588. }
  589. }
  590. onStatusBarClick() {
  591. window.open(this.meta.url, '_blank');
  592. }
  593. handleClick(pointX, pointY) {
  594. const mouseLegend = {
  595. 40: {30: 'PgUp', 100: 'PgDown'},
  596. 60: {40: 'Up', 60: 'Menu', 100: 'Down'},
  597. 100: {30: 'PgUp', 100: 'PgDown'}
  598. };
  599. const w = pointX/this.realWidth*100;
  600. const h = pointY/this.realHeight*100;
  601. let action = '';
  602. loops: {
  603. for (const x in mouseLegend) {
  604. for (const y in mouseLegend[x]) {
  605. if (w < x && h < y) {
  606. action = mouseLegend[x][y];
  607. break loops;
  608. }
  609. }
  610. }
  611. }
  612. switch (action) {
  613. case 'Down' ://Down
  614. this.doDown();
  615. break;
  616. case 'Up' ://Up
  617. this.doUp();
  618. break;
  619. case 'PgDown' ://PgDown
  620. this.doPageDown();
  621. break;
  622. case 'PgUp' ://PgUp
  623. this.doPageUp();
  624. break;
  625. case 'Menu' :
  626. this.doToolBarToggle();
  627. break;
  628. default :
  629. // Nothing
  630. }
  631. return (action && action != 'Menu');
  632. }
  633. }
  634. //-----------------------------------------------------------------------------
  635. </script>
  636. <style scoped>
  637. .main {
  638. flex: 1;
  639. margin: 0;
  640. padding: 0;
  641. overflow: hidden;
  642. position: relative;
  643. }
  644. .layout {
  645. margin: 0;
  646. padding: 0;
  647. position: absolute;
  648. z-index: 10;
  649. }
  650. .events {
  651. z-index: 20;
  652. background-color: rgba(0,0,0,0);
  653. }
  654. </style>