コード例 #1
0
ファイル: GuiScreen.java プロジェクト: nocaremc/game
  @Override
  public void render() {
    int width = App.getScreenWidth();
    int height = App.getScreenHeight();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, width, 0, height);
    glScalef(1, -1, 1);
    glTranslatef(0, -height, 0);
    glMatrixMode(GL_MODELVIEW);
    glDisable(GL_DEPTH_TEST);
    // Draw background
    glBegin(GL_QUADS);
    {
      if (backgroundColor != null) GeneralUtils.glColorShortcut(backgroundColor);

      glVertex2f(0, 0);
      glVertex2f(0, height);
      glVertex2f(width, height);
      glVertex2f(width, 0);
    }
    glEnd();

    for (GuiButton b : buttons) {
      b.render();
      // System.out.println(b.isMouseOver());

    }

    // I don't want to set the same opengl settings for every button.
    // We can reduce a least a tiny bit of overhead by doing it in one go
    font.renderBegin();
    for (GuiButton b : buttons) {
      b.renderText();
    }
    font.renderEnd();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_DEPTH_TEST);
  }
コード例 #2
0
ファイル: GuiScreen.java プロジェクト: nocaremc/game
  @Override
  public void handleInput(IGuiMouseState gui) {
    if ((gui.getState() == ButtonState.CLICKED)) {
      // Associate lua action file for this guiscreen with the lua engine
      App.getLua().get("dofile").call(LuaValue.valueOf(resourcePath + "buttonActions.lua"));

      // The function we call for clicks, within lua fine
      LuaValue clickAction = App.getLua().get("returnClick");

      // Value we pass to lua function. Button ID in this case
      LuaValue returnValue = clickAction.call(LuaValue.valueOf(((GuiButton) gui).getID()));

      // Set the button's state to none/null so we don't grab it again
      ((GuiButton) gui).setState(ButtonState.NONE);

      // String value of returnValue
      String sReturnValue = returnValue.tojstring();

      // Have App send the command to the proper place
      App.delegateLuaActionResponse(sReturnValue);
    }
  }