TextPage.vue 24 KB

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