Java Code Examples for com.badlogic.gdx.utils.Align#left()

The following examples show how to use com.badlogic.gdx.utils.Align#left() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RadialBlurEffect.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
/**
 * Specify the zoom origin in {@link Align} bits.
 * @see Align
 */
public void setOrigin(int align) {
    final float originX;
    final float originY;
    if ((align & Align.left) != 0) {
        originX = 0f;
    } else if ((align & Align.right) != 0) {
        originX = 1f;
    } else {
        originX = 0.5f;
    }
    if ((align & Align.bottom) != 0) {
        originY = 0f;
    } else if ((align & Align.top) != 0) {
        originY = 1f;
    } else {
        originY = 0.5f;
    }
    setOrigin(originX, originY);
}
 
Example 2
Source File: ZoomEffect.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
/**
 * Specify the zoom origin in {@link Align} bits.
 * @see Align
 */
public void setOrigin(int align) {
    final float originX;
    final float originY;
    if ((align & Align.left) != 0) {
        originX = 0f;
    } else if ((align & Align.right) != 0) {
        originX = 1f;
    } else {
        originX = 0.5f;
    }
    if ((align & Align.bottom) != 0) {
        originY = 0f;
    } else if ((align & Align.top) != 0) {
        originY = 1f;
    } else {
        originY = 0.5f;
    }
    setOrigin(originX, originY);
}
 
Example 3
Source File: MenuScreen.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private int getAlign() {
	if (getStyle().align == null || "center".equals(getStyle().align))
		return Align.center;

	if ("top".equals(getStyle().align))
		return Align.top;

	if ("bottom".equals(getStyle().align))
		return Align.bottom;

	if ("left".equals(getStyle().align))
		return Align.left;

	if ("right".equals(getStyle().align))
		return Align.right;

	return Align.center;
}
 
Example 4
Source File: AlignUtils.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public static String getAlign(int align) {
	switch (align) {
	case Align.bottomRight:
		return "bottom-right";
	case Align.bottomLeft:
		return "bottom-left";
	case Align.topRight:
		return "top-right";
	case Align.topLeft:
		return "top-left";
	case Align.right:
		return "right";
	case Align.left:
		return "left";
	case Align.bottom:
		return "bottom";
	case Align.top:
		return "top";
	case Align.center:
		return "center";
	}

	return "";
}
 
Example 5
Source File: AlignUtils.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public static int getAlign(String s) {
	if ("bottom-right".equals(s))
		return Align.bottomRight;
	else if ("bottom-left".equals(s))
		return Align.bottomLeft;
	else if ("top-right".equals(s))
		return Align.topRight;
	else if ("top-left".equals(s))
		return Align.topLeft;
	else if ("right".equals(s))
		return Align.right;
	else if ("left".equals(s))
		return Align.left;
	else if ("bottom".equals(s))
		return Align.bottom;
	else if ("top".equals(s))
		return Align.top;
	else if ("center".equals(s))
		return Align.center;

	return 0;
}
 
Example 6
Source File: CCLabel.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {

    final TTFLabelStyle labelStyle = editor.createLabelStyle(widget,
        widget.getLabelText(), editor.getColor(widget.getCColor(), 0));

    TTFLabel label = new TTFLabel(widget.getLabelText(), labelStyle);
    // 水平
    int h = Integer.MAX_VALUE;
    if ("HT_Center".equals(widget.getHorizontalAlignmentType())) {
        h = Align.center;
    } else if ("HT_Left".equals(widget.getHorizontalAlignmentType())) {
        h = Align.left;
    } else if ("HT_Right".equals(widget.getHorizontalAlignmentType())) {
        h = Align.right;
    }

    // 垂直
    int v = Integer.MAX_VALUE;
    if ("HT_Center".equals(widget.getVerticalAlignmentType())) {
        v = Align.center;
    } else if ("HT_Top".equals(widget.getVerticalAlignmentType())) {
        v = Align.top;
    } else if ("HT_Bottom".equals(widget.getVerticalAlignmentType())) {
        v = Align.bottom;
    }

    if (v != Integer.MAX_VALUE) {
        label.setAlignment(h, v);
    }

    return label;
}
 
Example 7
Source File: ToastManager.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private void updateToastsPositions () {
	boolean bottom = (alignment & Align.bottom) != 0;
	boolean left = (alignment & Align.left) != 0;
	float y = bottom ? screenPadding : root.getHeight() - screenPadding;

	for (Toast toast : toasts) {
		Table table = toast.getMainTable();
		table.setPosition(
				left ? screenPadding : root.getWidth() - table.getWidth() - screenPadding,
				bottom ? y : y - table.getHeight());

		y += (table.getHeight() + messagePadding) * (bottom ? 1 : -1);
	}
}
 
Example 8
Source File: ToastManager.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void updateToastsPositions () {
	boolean bottom = (alignment & Align.bottom) != 0;
	boolean left = (alignment & Align.left) != 0;
	float y = bottom ? screenPaddingY : root.getHeight() - screenPaddingY;

	for (Toast toast : toasts) {
		Table table = toast.getMainTable();
		table.setPosition(
				left ? screenPaddingX : root.getWidth() - table.getWidth() - screenPaddingX,
				bottom ? y : y - table.getHeight());

		y += (table.getHeight() + messagePadding) * (bottom ? 1 : -1);
	}
}
 
Example 9
Source File: TextRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static float getAlignDx(float width, int align) {
	if ((align & Align.left) != 0)
		return 0;
	else if ((align & Align.right) != 0)
		return -width;
	else if ((align & Align.center) != 0)
		return -width / 2.0f;

	return -width / 2.0f;
}
 
Example 10
Source File: AnimationRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static float getAlignDx(float width, int align) {
	if ((align & Align.left) != 0)
		return 0;
	else if ((align & Align.right) != 0)
		return -width;
	else if ((align & Align.center) != 0)
		return -width / 2.0f;

	return -width / 2.0f;
}
 
Example 11
Source File: TabbedPane.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void initialize () {

		setTouchable(Touchable.enabled);
		tabTitleTable = new Table();
		tabBodyStack = new Stack();
		selectedIndex = -1;

		// Create 1st row
		Cell<?> leftCell = add(new Image(style.titleBegin));
		Cell<?> midCell = add(tabTitleTable);
		Cell<?> rightCell = add(new Image(style.titleEnd));
		switch (tabTitleAlign) {
		case Align.left:
			leftCell.width(((Image)leftCell.getActor()).getWidth()).bottom();
			midCell.left();
			rightCell.expandX().fillX().bottom();
			break;
		case Align.right:
			leftCell.expandX().fillX().bottom();
			midCell.right();
			rightCell.width(((Image)rightCell.getActor()).getWidth()).bottom();
			break;
		case Align.center:
			leftCell.expandX().fillX().bottom();
			midCell.center();
			rightCell.expandX().fillX().bottom();
			break;
		default:
			throw new IllegalArgumentException("TabbedPane align must be one of left, center, right");
		}

		// Create 2nd row
		row();
		Table t = new Table();
		t.setBackground(style.bodyBackground);
		t.add(tabBodyStack);
		add(t).colspan(3).expand().fill();
	}
 
Example 12
Source File: GameOverScreen.java    From libgdx-2d-tutorial with MIT License 4 votes vote down vote up
@Override
public void render (float delta) {
	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	game.batch.begin();
	
	game.scrollingBackground.updateAndRender(delta, game.batch);
	
	game.batch.draw(gameOverBanner, SpaceGame.WIDTH / 2 - BANNER_WIDTH / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - 15, BANNER_WIDTH, BANNER_HEIGHT);
	
	GlyphLayout scoreLayout = new GlyphLayout(scoreFont, "Score: \n" + score, Color.WHITE, 0, Align.left, false);
	GlyphLayout highscoreLayout = new GlyphLayout(scoreFont, "Highscore: \n" + highscore, Color.WHITE, 0, Align.left, false);
	scoreFont.draw(game.batch, scoreLayout, SpaceGame.WIDTH / 2 - scoreLayout.width / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - 15 * 2);
	scoreFont.draw(game.batch, highscoreLayout, SpaceGame.WIDTH / 2 - highscoreLayout.width / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - scoreLayout.height - 15 * 3);
	
	float touchX = game.cam.getInputInGameWorld().x, touchY = SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y;
	
	GlyphLayout tryAgainLayout = new GlyphLayout(scoreFont, "Try Again");
	GlyphLayout mainMenuLayout = new GlyphLayout(scoreFont, "Main Menu");
	
	float tryAgainX = SpaceGame.WIDTH / 2 - tryAgainLayout.width /2;
	float tryAgainY = SpaceGame.HEIGHT / 2 - tryAgainLayout.height / 2;
	float mainMenuX = SpaceGame.WIDTH / 2 - mainMenuLayout.width /2;
	float mainMenuY = SpaceGame.HEIGHT / 2 - mainMenuLayout.height / 2 - tryAgainLayout.height - 15;
	
	//Checks if hovering over try again button
	if (touchX >= tryAgainX && touchX < tryAgainX + tryAgainLayout.width && touchY >= tryAgainY - tryAgainLayout.height && touchY < tryAgainY)
		tryAgainLayout.setText(scoreFont, "Try Again", Color.YELLOW, 0, Align.left, false);
	
	//Checks if hovering over main menu button
	if (touchX >= mainMenuX && touchX < mainMenuX + mainMenuLayout.width && touchY >= mainMenuY - mainMenuLayout.height && touchY < mainMenuY)
		mainMenuLayout.setText(scoreFont, "Main Menu", Color.YELLOW, 0, Align.left, false);
	
	//If try again and main menu is being pressed
	if (Gdx.input.isTouched()) {
		//Try again
		if (touchX > tryAgainX && touchX < tryAgainX + tryAgainLayout.width && touchY > tryAgainY - tryAgainLayout.height && touchY < tryAgainY) {
			this.dispose();
			game.batch.end();
			game.setScreen(new MainGameScreen(game));
			return;
		}
		
		//main menu
		if (touchX > mainMenuX && touchX < mainMenuX + mainMenuLayout.width && touchY > mainMenuY - mainMenuLayout.height && touchY < mainMenuY) {
			this.dispose();
			game.batch.end();
			game.setScreen(new MainMenuScreen(game));
			return;
		}
	}
	
	//Draw buttons
	scoreFont.draw(game.batch, tryAgainLayout, tryAgainX, tryAgainY);
	scoreFont.draw(game.batch, mainMenuLayout, mainMenuX, mainMenuY);
	
	game.batch.end();
}
 
Example 13
Source File: EditWidget.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public void layout() {
    super.layout();
    temp.set(0, 0);
    
    if (followActor != null) {
        followActor.localToStageCoordinates(temp);
        stageToLocalCoordinates(temp);
        setBounds(temp.x, temp.y, followActor.getWidth(), followActor.getHeight());
    } else if (cell != null) {
        var table = cell.getTable();
        temp.set(table.getPadLeft(), table.getPadBottom());

        var contentWidth = 0f;
        var contentHeight = 0f;
        for (int i = 0; i < table.getColumns(); i++) {
            contentWidth += table.getColumnWidth(i);
        }
        for (int i = 0; i < table.getRows(); i++) {
            contentHeight += table.getRowHeight(i);
        }

        if ((table.getAlign() & Align.right) != 0) {
            temp.add(table.getWidth() - contentWidth - table.getPadLeft() - table.getPadRight(), 0);
        } else if ((table.getAlign() & Align.left) == 0) {
            temp.add((table.getWidth() - contentWidth - table.getPadLeft() - table.getPadRight()) / 2, 0);
        }

        if ((table.getAlign() & Align.top) != 0) {
            temp.add(0, table.getHeight() - contentHeight - table.getPadBottom()  - table.getPadTop());
        } else if ((table.getAlign() & Align.bottom) == 0) {
            temp.add(0, (table.getHeight() - contentHeight - table.getPadBottom() - table.getPadTop()) / 2);
        }
        
        table.localToStageCoordinates(temp);
        stageToLocalCoordinates(temp);
        
        var xpos = 0f;
        var ypos = 0f;
        
        for (int i = 0; i < cell.getColumn(); i++) {
            xpos += table.getColumnWidth(i);
        }
        
        for (int i = table.getRows() - 1; i > cell.getRow(); i--) {
            ypos += table.getRowHeight(i);
        }

        var cellWidth = 0;
        for (int i = cell.getColumn(); i < cell.getColumn() + cell.getColspan(); i++) {
            cellWidth += table.getColumnWidth(i);
        }
        
        setBounds(temp.x + xpos, temp.y + ypos, cellWidth, table.getRowHeight(cell.getRow()));
    }
}
 
Example 14
Source File: SpellsQuickPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public SpellsQuickPanel(final HotkeyButton o, final boolean leftSkills) {
  this.observer = o;
  this.leftSkills = leftSkills;

  Riiablo.assets.load(SkilliconDescriptor);
  Riiablo.assets.finishLoadingAsset(SkilliconDescriptor);
  Skillicon = Riiablo.assets.get(SkilliconDescriptor);

  CharSkilliconDescriptor = new AssetDescriptor[7];
  CharSkillicon = new DC6[CharSkilliconDescriptor.length];
  for (int i = 0; i < CharSkilliconDescriptor.length; i++) {
    CharSkilliconDescriptor[i] = new AssetDescriptor<>(SPELLS_PATH + CharacterClass.get(i).spellIcons + ".DC6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
    Riiablo.assets.load(CharSkilliconDescriptor[i]);
    Riiablo.assets.finishLoadingAsset(CharSkilliconDescriptor[i]);
    CharSkillicon[i] = Riiablo.assets.get(CharSkilliconDescriptor[i]);
  }

  SIZE = Gdx.app.getType() == Application.ApplicationType.Android ? 64 : 48;
  ALIGN = leftSkills ? Align.left : Align.right;

  keyMappings = new ObjectMap<>(31);
  tables = new Table[5];
  for (int i = tables.length - 1; i >= 0; i--) {
    Table table = tables[i] = new Table();
    add(table).align(ALIGN).row();
  }
  pack();
  //setDebug(true, true);

  mappedKeyListener = new MappedKeyStateAdapter() {
    @Override
    public void onPressed(MappedKey key, int keycode) {
      HotkeyButton button = keyMappings.get(key);
      if (button == null) return;
      // TODO: Assign
      ControlPanel controlPanel = Riiablo.game.controlPanel;
      if (leftSkills) {
        controlPanel.getLeftSkill().copy(button);
      } else {
        controlPanel.getRightSkill().copy(button);
      }
    }
  };
  for (MappedKey Skill : Keys.Skill) Skill.addStateListener(mappedKeyListener);
  Riiablo.charData.addSkillListener(this);
}