<template>
    <div>
        <el-button size="small" @click="changeEnable">切换item禁用状态</el-button>
        <canvas id="rect" width="740" height="400" />
    </div>
</template>

<script>

    import {SGraphScene, SGraphShape, SGraphView} from "@persagy-web/graph/lib";
    import {SRect} from "@persagy-web/draw/lib";

    class rect extends SGraphShape{
        constructor(parent, data) {
            super(parent, data.Style);
            this.leftTopX = data.X;
            this.leftTopyY= data.Y;
            this.width = data.Width;
            this.height = data.Height;
        }
        boundingRect() {
            return new SRect(this.leftTopX,this.leftTopyY,this.width,this.height);
        }
        onDraw(painter) {
            super.onDraw(painter);
            painter.drawRect(this.leftTopX,this.leftTopyY,this.width,this.height)
        }
    }
    export default {
        name: "rect1",
        data(){
            return {
                view: '',
                item: '',
                rectData: {
                    X: 0,
                    Y: 0,
                    Width: 500,
                    Height: 500,
                    Style: {
                        "Default":{
                            "Stroke": "#cccccc",
                            "Fill": "#ccffcc",
                            "LineWidth": 2,
                            "Effect": {}
                        },
                        "Selected": {
                            "Stroke": "#66ff66",
                            "Fill": "#11effe",
                            "LineWidth": 3,
                            "Effect": {}
                        },
                        "Disabled": {
                            "Stroke": "#333333",
                            "Fill": "#afafaf",
                            "LineWidth": 1,
                            "Effect": {}
                        },
                    }
                }
            }
        },
        mounted() {
            this.init();
        },
        methods:{
            init(){
                this.view = new SGraphView('rect');
                const scene = new SGraphScene();
                this.item = new rect(null, this.rectData);
                this.item.selectable = true;
                this.view.scene = scene;
                scene.addItem(this.item);
                this.view.fitSceneToView();
                this.view.scalable = false;
            },
            changeEnable(){
                if (this.item) {
                    this.item.enabled = !this.item.enabled;
                }
            }
        }
    }
</script>

<style scoped>
</style>
