Example #1
0
 private void reset() {
   if (ball.getUserData("resetted") == null) { // To make sure that we call destroy only once
     ball.setUserData("resetted", true);
     app.invokeLater(
         new Runnable() {
           public void run() {
             IPhysicsComponent a = (IPhysicsComponent) ball;
             a.getBody()
                 .setXForm(
                     new Vec2(
                         getMTApplication().width / 2f / scale,
                         getMTApplication().height / 2f / scale),
                     a.getBody().getAngle());
             //					a.getBody().setLinearVelocity(new Vec2(0,0));
             a.getBody()
                 .setLinearVelocity(
                     new Vec2(ToolsMath.getRandom(-8, 8), ToolsMath.getRandom(-8, 8)));
             a.getBody().setAngularVelocity(0);
             ball.setUserData("resetted", null);
           }
         });
   }
   this.scorePlayer1 = 0;
   this.scorePlayer2 = 0;
   this.updateScores();
 }
 private void enablePaymentButton(final boolean enable) {
   _application.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           _okButton.setEnabled(enable);
         }
       });
 }
 private void showText(final String text) {
   _application.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           _textArea.setText(text);
           _textArea.setPositionGlobal(
               new Vector3D(_application.getWidth() / 2, _application.getHeight() / 3));
         }
       });
 }
  /**
   * Instantiates a new mT scene window.
   *
   * @param applet the applet
   * @param scene the scene
   * @param borderWidth the border width
   * @param borderHeight the border height
   * @param fboWidth the fbo width
   * @param fboHeight the fbo height
   */
  public MTSceneWindow(
      final AbstractMTApplication applet,
      final Iscene scene,
      float borderWidth,
      float borderHeight,
      int fboWidth,
      int fboHeight) {
    //		super(0-borderWidth, 0-borderHeight, applet.width+2*borderWidth,
    // applet.height+2*borderHeight, applet);
    super(
        applet,
        0 - borderWidth,
        0 - borderHeight,
        0,
        MT4jSettings.getInstance().getWindowWidth() + 2 * borderWidth,
        MT4jSettings.getInstance().getWindowHeight() + 2 * borderHeight,
        30,
        30);

    this.setStrokeColor(new MTColor(0, 0, 0));

    sceneTexture = new MTSceneTexture(applet, 0, 0, fboWidth, fboHeight, scene);
    sceneTexture.setStrokeColor(new MTColor(0, 0, 0));
    this.addChild(sceneTexture);

    // Add the scene to the scene list in the Application
    // FIXME add the scene later to the MTApplication because if we add the scene
    // before any other scene is added it becomes the active scene which we dont want
    if (applet.getSceneCount() == 0) {
      applet.invokeLater(
          new Runnable() {
            public void run() {
              applet.addScene(sceneTexture.getScene());
            }
          });
    } else {
      applet.addScene(sceneTexture.getScene());
    }

    sceneTexture.addStateChangeListener(
        StateChange.COMPONENT_DESTROYED,
        new StateChangeListener() {
          public void stateChanged(StateChangeEvent evt) {
            destroy();
          }
        });

    if (closeButtonImage == null) {
      closeButtonImage =
          applet.loadImage(
              MT4jSettings.getInstance().getDefaultImagesPath()
                  +
                  //			"close_32.png")
                  //			"126182-simple-black-square-icon-alphanumeric-circled-x3_cr.png"
                  //			"124241-matte-white-square-icon-alphanumeric-circled-x3_cr.png"
                  //			"124241-matte-white-square-icon-alphanumeric-circled-x3128.png"
                  "closeButton64.png");
    }
    MTImageButton closeButton = new MTImageButton(applet, closeButtonImage);
    closeButton.addGestureListener(
        TapProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            TapEvent te = (TapEvent) ge;
            if (te.isTapped()) {
              close();
            }
            return true;
          }
        });
    this.addChild(closeButton);
    closeButton.setNoStroke(true);
    //		closeButton.setSizeXYRelativeToParent(borderWidth - borderWidth/20, borderWidth -
    // borderWidth/20);
    closeButton.setSizeXYRelativeToParent(
        borderWidth - borderWidth / 30, borderWidth - borderWidth / 30);
    //		closeButton.setSizeXYRelativeToParent(borderWidth -0.5f, borderWidth-0.5f);
    closeButton.setPositionRelativeToParent(
        new Vector3D((applet.width + (borderWidth / 2f)), borderHeight - 5));

    if (maximizeButtonImage == null) {
      maximizeButtonImage =
          applet.loadImage(
              MT4jSettings.getInstance().getDefaultImagesPath()
                  +
                  //			"window_app_blank_32.png")
                  //			"127941-simple-black-square-icon-symbols-shapes-maximize-button_cr.png"
                  "maximizeButton64.png");
    }
    MTImageButton maximizeButton = new MTImageButton(applet, maximizeButtonImage);
    maximizeButton.addGestureListener(
        TapProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            TapEvent te = (TapEvent) ge;
            if (te.isTapped()) {
              maximize();
            }
            return true;
          }
        });
    this.addChild(maximizeButton);
    maximizeButton.setNoStroke(true);
    //		maximizeButton.setSizeXYRelativeToParent(borderWidth - borderWidth/10, borderWidth -
    // borderWidth/10);
    maximizeButton.setSizeXYRelativeToParent(
        borderWidth - borderWidth / 30, borderWidth - borderWidth / 30);
    //		maximizeButton.setPositionRelativeToParent(new Vector3D(
    // (applet.width+2*borderWidth)-maximizeButton.getWidthXY(TransformSpace.RELATIVE_TO_PARENT),
    // closeButton.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) + 40));
    //		maximizeButton.setPositionRelativeToParent(new Vector3D( (applet.width+ (borderWidth /2f)),
    // borderHeight + closeButton.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) + 15));
    maximizeButton.setPositionRelativeToParent(
        new Vector3D(
            (applet.width + (borderWidth / 2f)),
            applet.height - closeButton.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) / 2f));
  }