1/* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const { GLFrame } = require("./engine/GLFrame"); 17const { Scr } = require("./engine/XDefine"); 18const { XTools } = require("./engine/XTools"); 19const { XSelect } = require("./engine/control/XSelect"); 20const { X2DFast } = require("./engine/graphics/X2DFast"); 21const { IrViewer } = require("./ir/IrViewer"); 22const { LogParser } = require("./ir/LogParser"); 23 24class MainEditor { 25 constructor() { 26 XTools.LoadConfig(); 27 28 this.filePoint_ = ""; 29 this.files_ = []; 30 this.viewer_ = {} 31 LogParser.Load("test.txt", this.onLoad.bind(this)); 32 33 this.selectFile_ = new XSelect(this.files_, this.filePoint_); 34 this.selectFile_.registCallback(this.changeFile.bind(this)); 35 36 GLFrame.gi().pCallbackDropfile = this.onDrop.bind(this); 37 } 38 changeFile(name) { 39 this.filePoint_ = name; 40 } 41 onLoad(fn, result) { 42 try { 43 let irv = new IrViewer(fn, result); 44 if (this.files_.indexOf(fn) < 0) { 45 this.files_.push(fn); 46 this.selectFile_.resetList(this.files_, fn); 47 this.changeFile(fn); 48 } 49 this.viewer_[fn] = irv; 50 } 51 catch (e) { 52 XTools.PROC_TO = 0; 53 console.log(e); 54 alert("读取" + fn + "失败"); 55 return; 56 } 57 } 58 onDrop(files, x, y) { 59 if (files.length == 1) { 60 let reader = new FileReader(); 61 reader.readAsDataURL(files[0]); 62 reader.onload = (e) => { 63 let ret = atob(e.target.result.split(",")[1]); 64 this.onLoad(files[0].name, ret); 65 } 66 } 67 } 68 static pInstance_ = null; 69 static gi() { 70 if (MainEditor.pInstance_ == null) MainEditor.pInstance_ = new MainEditor(); 71 return MainEditor.pInstance_; 72 } 73 74 onDraw() { 75 if (this.selectFile_.list_.length <= 0) { 76 X2DFast.gi().drawText("拖入log文件", 30, Scr.logicw / 2, Scr.logich / 2, 1, 1, 0, -2, -2, 0xff000000); 77 return; 78 } 79 80 for (let v in this.viewer_) { 81 if (this.filePoint_ == v) { 82 this.viewer_[v].onDraw(); 83 } 84 } 85 86 this.selectFile_.move(Scr.logicw - 200 - 10, 10, 200, 20); 87 this.selectFile_.draw(); 88 if (XTools.PROC_TO > 0 && XTools.PROC_TO < 100) { 89 X2DFast.gi().fillRect(0, Scr.logich - 5, XTools.PROC_TO * Scr.logicw / 100, 5, 0xffff0000); 90 } 91 } 92 93 onTouch(msg, x, y) { 94 if (this.selectFile_.list_.length <= 0) { 95 return true; 96 } 97 if (this.selectFile_.onTouch(msg, x, y)) { 98 return true; 99 } 100 for (let v in this.viewer_) { 101 if (this.filePoint_ == v) { 102 if (this.viewer_[v].onTouch(msg, x, y)) { 103 return true; 104 } 105 } 106 } 107 return false; 108 } 109 110 onKey(k) { 111 for (let v in this.viewer_) { 112 if (this.filePoint_ == v) { 113 if (this.viewer_[v].onKey(k)) { 114 return true; 115 } 116 } 117 } 118 return true; 119 } 120} 121 122module.exports = { 123 MainEditor 124}