Example #1
1
 /* returns true if deletion is allowed */
 private boolean isAllowedDeletion() {
   if ((org.lwjgl.input.Keyboard.getEventKey() == org.lwjgl.input.Keyboard.KEY_BACK)
       && (text.length() > 1)
       && (cursorLocation > 0)) return true;
   else return false;
 }
Example #2
1
 /* returns true if the users right arrow navigation is allowed */
 private boolean isAllowedRightArrowNavigation() {
   if (org.lwjgl.input.Keyboard.getEventKey() == org.lwjgl.input.Keyboard.KEY_RIGHT
       && cursorLocation < text.length() - 1) return true;
   else return false;
 }
Example #3
1
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();

    mc.getTextureManager().bindTexture(skrivemaskinegui);

    this.drawTexturedModalRect(this.width / 2 - 128, this.height / 2 - 128, 0, 0, 256, 256);

    /* this is where the editor reads keys and writes to the screen */
    if (org.lwjgl.input.Keyboard.getEventKeyState()) {
      //
      if (isAllowedDeletion()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedNewLine()) {
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, '\n');
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedLeftArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (isAllowedRightArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
        text.deleteCharAt(cursorLocation);
        for (int i = 0; i < 3; i++) {
          text.insert(cursorLocation, " ");
          cursorLocation++;
        }
        text.insert(cursorLocation, cursor); // moving cursor

      } else {
        if (isAllowedCharacters()) {
          // System.out.println(org.lwjgl.input.Keyboard.getEventKey());
          text.deleteCharAt(cursorLocation);
          text.insert(cursorLocation, org.lwjgl.input.Keyboard.getEventCharacter());
          cursorLocation++;
          text.insert(cursorLocation, cursor); // moving cursor
        }
      }

      org.lwjgl.input.Keyboard.destroy();
    } else if (!org.lwjgl.input.Keyboard.isCreated()) {
      try {
        org.lwjgl.input.Keyboard.create();
      } catch (Exception e) {
      }
    }

    /* writes the text string to the screen */
    renderer.drawSplitString(
        text.toString(), this.width / 2 - 118, this.height / 2 - 119, 238, 0xFFFFF0);

    super.drawScreen(mouseX, mouseY, partialTicks);
  }
Example #4
0
 @Override
 public void close() {
   AL.destroy();
   Display.destroy();
   org.lwjgl.input.Mouse.destroy();
   org.lwjgl.input.Keyboard.destroy();
 }
Example #5
0
 @Override
 public void init() {
   try {
     DisplayMode[] modes = Display.getAvailableDisplayModes();
     int closestindex = -1;
     for (int i = 0; i < modes.length; i++) {
       if (closestindex == -1) closestindex = 0;
       else if (getModeDist(modes[closestindex]) > getModeDist(modes[i])) closestindex = i;
     }
     Display.setDisplayMode(modes[closestindex]);
     Display.setTitle("Voxels " + Main.Version);
     Display.create();
     setVSyncEnabled(Main.isVSyncEnabled);
     org.lwjgl.input.Mouse.create();
     org.lwjgl.input.Keyboard.create();
     org.lwjgl.input.Keyboard.enableRepeatEvents(true);
     if (!AL.isCreated()) AL.create();
     this.mouse.init();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
Example #6
0
 /* returns true if the key press is the return key */
 private boolean isAllowedNewLine() {
   if (org.lwjgl.input.Keyboard.getEventKey() == org.lwjgl.input.Keyboard.KEY_RETURN) return true;
   else return false;
 }
Example #7
0
 /* returns true if the users left arrow navigation is allowed */
 private boolean isAllowedLeftArrowNavigation() {
   if (org.lwjgl.input.Keyboard.getEventKey() == org.lwjgl.input.Keyboard.KEY_LEFT
       && cursorLocation > 0) return true;
   else return false;
 }
Example #8
0
 /* returns true if pressed button is allowed for "writing" */
 private boolean isAllowedCharacters() {
   if ((org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_BACK)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_LEFT)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_RIGHT)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_UP)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_DOWN)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_RSHIFT)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_LSHIFT)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_RCONTROL)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_LCONTROL)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_RMENU)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_RMETA)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_LMETA)
       && (org.lwjgl.input.Keyboard.getEventKey() != org.lwjgl.input.Keyboard.KEY_LMENU))
     return true;
   else return false;
 }