<?xml version="1.0" ?>
<diagram author="Simon Van Mierlo" name="Timer">
    <description>
    </description>
    <inport name="ui" />

    <class name="MainApp" default="true">
        <method name="MainApp">
            <body>
                <![CDATA[
                this.canvas = ui.append_canvas(ui.window,400,150,{'background':'#eee'})
                this.clock_text = this.canvas.add_text(25,25,'0.0')
                this.actual_clock_text = this.canvas.add_text(25,50,'0.0')
                var interrupt_button = ui.append_button(ui.window, 'INTERRUPT');
                var continue_button = ui.append_button(ui.window, 'CONTINUE');
                ui.bind_event(interrupt_button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'interrupt_clicked');
                ui.bind_event(continue_button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'continue_clicked');
                ]]>
            </body>
        </method>
        <method name="update_timers">
            <body>
                this.clock_text.set_text(get_simulated_time().toFixed(2));
                this.actual_clock_text.set_text(time().toFixed(2));
            </body>
        </method>
        <scxml initial="running">
            <state id="running">
                <transition target="." after="0.05">
                    <script>
                        this.update_timers();
                    </script>
                </transition>
                <transition target="../interrupted" event="interrupt_clicked" port="ui">
                    <script>
                        this.update_timers();
                    </script>
                </transition>
            </state>
            <state id="interrupted">
                <onentry>
                    <script>
                        console.log("entering interrupted");
                    </script>
                </onentry>
                <onexit>
                    <script>
                        console.log("entering interrupted");
                    </script>
                </onexit>
                <transition target="." event="interrupt_clicked" port="ui">
                    <script>
                        this.update_timers();
                    </script>
                </transition>
                <transition target="../running" event="continue_clicked" port="ui">
                    <script>
                        this.update_timers();
                    </script>
                </transition>
            </state>
        </scxml>
    </class>
</diagram>
