int Signature::init()
{


   //var obj = document.getElementById("pad");
   var obj = document.getElementById("canwr");

    do {
        m_xOff += obj.offsetLeft;
        m_yOff += obj.offsetTop;
    } while (obj = obj.offsetParent);

    clearSig();

 //   canvas=document.getElementById("can");
    canvasW=document.getElementById("canwr");

 //   m_ctx=canvas.getContext("2d");
    m_ctxW=canvasW.getContext("2d");

    m_ctxW.fillStyle = bgCol; //"rgb(192,192,192)";

   m_ctxW.fillRect(0, 0 , 480, 100);
  // m_ctxW.fillStyle = "rgb(255,0,0)";
   m_ctxW.fillStyle = lnCol;
   m_ctxW.strokeStyle  = lnCol;


   m_ctxW.lineWidth = lnTk;

    onObj =  document.getElementById('on');

   getSign();
   drawSig();

   drawDone();
  // alert( "done");


}
Beispiel #2
0
    void BfVM::initializeStateMachine() {
        // see the state chart for a clearer picture of what's going on with the states
        /////////////////////////////////////////////////////////////////////////////////////
        //// STATE NAME INITIALIZATIONS
        ///////////////////////////////
        //: Please don't translate the state names in case I forget to remove the tr()s
        m_stateGroup->setProperty("statename", QVariant::fromValue(tr("main state group")));
        m_runGroup->setProperty("statename", QVariant::fromValue(tr("run state group")));
        m_emptySt->setProperty("statename", QVariant::fromValue(tr("empty VM")));
        m_steppingSt->setProperty("statename", QVariant::fromValue(tr("stepping")));
        m_runningSt->setProperty("statename", QVariant::fromValue(tr("running")));
        m_clearSt->setProperty("statename", QVariant::fromValue(tr("clearing")));
        m_initializedSt->setProperty("statename", QVariant::fromValue(tr("initialized")));
        m_finishedSt->setProperty("statename", QVariant::fromValue(tr("finished")));
        m_waitingForInpSt->setProperty("statename", QVariant::fromValue(
                tr("waiting for input")));
        m_breakpointSt->setProperty("statename", QVariant::fromValue(tr("breakpoint")));
        m_runHistorySt->setProperty("statename", QVariant::fromValue(
                tr("run history state")));


        /////////////////////////////////////////////////////////////////////////////////////
        //// EMPTY STATE
        ////////////////
        /*
         Only transition away from the empty state when the VM is initialized, ie. a
         Brainfuck program is loaded succesfully
          */
        InitedEventTransition *iet = new InitedEventTransition();
        iet->setTargetState(m_initializedSt);
        m_emptySt->addTransition(iet);


        /////////////////////////////////////////////////////////////////////////////////////
        //// INITIALIZED STATE
        //////////////////////
        // reset the VM when the initialized state is entered
        connect(m_initializedSt, SIGNAL(entered()), this, SLOT(reset()));

        // emit inited() when entering the initialized state so the GUI knows we're ready
        connect(m_initializedSt, SIGNAL(entered()), this, SIGNAL(inited()));

        m_initializedSt->addTransition(this, SIGNAL(toggleRunSig()), m_runningSt);
        m_initializedSt->addTransition(this, SIGNAL(stepSig()), m_steppingSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// STEPPING STATE
        ///////////////////
        // run step() whenever this state is entered
        connect(m_steppingSt, SIGNAL(entered()), this, SLOT(step()));
        // just loops back to itself when receiving additional stepSig()s
        m_steppingSt->addTransition(this, SIGNAL(stepSig()), m_steppingSt);
        // Transition to running if toggleRunSig() received
        m_steppingSt->addTransition(this, SIGNAL(toggleRunSig()), m_runningSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// RUNNING STATE
        //////////////////
        /* Entering or exiting this state controls whether the run timer is running. */
        connect(m_runningSt, SIGNAL(entered()), this, SLOT(go()));
        connect(m_runningSt, SIGNAL(exited()), this, SLOT(stop()));
        m_runningSt->addTransition(this, SIGNAL(stepSig()), m_steppingSt);
        m_runningSt->addTransition(this, SIGNAL(toggleRunSig()), m_steppingSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// FINISHED STATE
        ///////////////////
        /* the only way to get out of the finished state is to reset or clear the VM.
           finish() is emitted when this state is entered so that the GUI can disable
           actions and whatnot */

        connect(m_finishedSt, SIGNAL(entered()), this, SIGNAL(finish()));
        m_finishedSt->addTransition(this, SIGNAL(resetSig()), m_initializedSt);

        /////////////////////////////////////////////////////////////////////////////////////
        //// WAITING FOR INPUT STATE
        ////////////////////////////

        // signal the GUI that the VM needs input
        connect(m_waitingForInpSt, SIGNAL(entered()), this, SIGNAL(needInput()));

        /* send the same signal when exiting the state, so the GUI can toggle its
           input notification */
        connect(m_waitingForInpSt, SIGNAL(exited()), this, SIGNAL(needInput()));

        /* To get out of the wait state we need either input or a reset/clear.
           Clears are handled by the top state group, but we need to catch the reset
           signal ourselves.
           Transitions back to the correct state of the running state group by using
           m_runGroup's history state */
        InpBufFilledTransition *ibft = new InpBufFilledTransition();
        ibft->setTargetState(m_runHistorySt);
        m_waitingForInpSt->addTransition(ibft);
        m_waitingForInpSt->addTransition(this, SIGNAL(resetted()), m_initializedSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// BREAKPOINT STATE
        /////////////////////
        connect(m_breakpointSt, SIGNAL(entered()), this, SLOT(breakPtTest()));
        m_breakpointSt->addTransition(this, SIGNAL(stepSig()), m_steppingSt);
        m_breakpointSt->addTransition(this, SIGNAL(toggleRunSig()), m_runningSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// CLEARING STATE
        ///////////////////
        connect(m_clearSt, SIGNAL(entered()), this, SLOT(clear()));
        m_clearSt->addTransition(m_emptySt);

        /////////////////////////////////////////////////////////////////////////////////////
        //// TOP STATE GROUP
        ////////////////////
        m_stateGroup->setInitialState(m_emptySt);  // start in the empty state
        // if the clearSig() signal is sent when in any state, go to the clear state
        m_stateGroup->addTransition(this, SIGNAL(clearSig()), m_clearSt);


        /////////////////////////////////////////////////////////////////////////////////////
        //// RUN STATE GROUP
        ////////////////////
        m_runGroup->setInitialState(m_steppingSt); /* the run group always starts in the
                                                      stepping state*/

        /* If the VM is reset while running, go back to the initialized state */
        m_runGroup->addTransition(this, SIGNAL(resetSig()), m_initializedSt);

        // Stop the VM when exiting the run group
        connect(m_runGroup, SIGNAL(exited()), this, SLOT(stop()));

        /* handle an EndEvent in any run state by transitioning to the finished state */
        EndEventTransition *eet = new EndEventTransition();
        eet->setTargetState(m_finishedSt);
        m_runGroup->addTransition(eet);

        /* if the input buffer is empty and the VM needs input, go into the waiting
           for input state */
        InpBufEmptyTransition *ibet = new InpBufEmptyTransition();
        ibet->setTargetState(m_waitingForInpSt);
        m_runGroup->addTransition(ibet);

        // go to the breakpoint state if a breakpoint was reached
        BreakpointTransition *bpt = new BreakpointTransition();
        bpt->setTargetState(m_breakpointSt);
        m_runGroup->addTransition(bpt);



        /////////////////////////////////////////////////////////////////////////////////////
        //// STATE MACHINE INITIALIZATION
        /////////////////////////////////

        m_stateMachine->addState(m_stateGroup);
        m_stateMachine->setInitialState(m_stateGroup);
    }