//函数：获取尺寸
function findDimensions() {

    if(document.getElementById(canvas)){
        content = document.getElementById("content")
        document.getElementById(canvas).height = content.offsetHeight;
        document.getElementById(canvas).width = content.offsetWidth;
    }
    // alert(window.innerHeight);

    //触发自定义窗口变化事件
    window.dispatchEvent(windowChangeEvent)
}

function readNewComp(){
    let newcomp = document.getElementById("newcomp").value;
    if (newcomp != ""){
        NewComp = eval('(' + newcomp + ')')
    }else{
        NewComp = {template:{type:'Grid'}}
    }
    console.log(NewComp)
}

//计算滚动位置
function ScollPostion() {
    if (document.documentElement && document.documentElement.scrollTop) {
        ScrollTop = document.documentElement.scrollTop;
        ScrollLeft = document.documentElement.scrollLeft;
    } else if (document.body) {
        ScrollTop = document.body.scrollTop;
        ScrollLeft = document.body.scrollLeft;
    }
}

//保存组件json
function save(m){
    let newcomp = document.getElementById("newcomp");
    newcomp.value = JSON.stringify(m);
    NewComp = m;
    console.log(m, JSON.stringify(m), newcomp.innerText, newcomp.innerHTML, newcomp.value)
}

//读取所有图片文件
function getImages(imageNames, imageSource) {
    imageNames.forEach(function f(item, index){
       img =  new Image();
       n = item.split(".")[0];
       img.src = imageSource + item;
       global.Images[n] = img
    });
    window.dispatchEvent(addImageEvent)
    console.log(Images)
}

// 设置时钟，先清除旧的，再设置新的
// f: 时钟到以后的回调函数
tipTimer = null;
function setTipTime(f) {
    clearTipTime();
    tipTimer = setTimeout(f, 1000)
}

// 清除tips时钟
function clearTipTime() {
    if (tipTimer) {
        clearTimeout(tipTimer)
    }
}

// 让canvas捕获鼠标事件
function captureEvent () {
    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP)
}

// 让canvas捕获鼠标事件
function releaseEvent() {
    window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP)
}

global.Verify = function (verifyKey, value, callBack){
    let result = true;
    if (verifyKey === "1"){
        result = false;
        callBack(false, "error!!!");
        return
    }
    callBack(result);
    return
}
