Android Open Source - Castle-Invaders Slider






From Project

Back to project page Castle-Invaders.

License

The source code is released under:

GNU General Public License

If you think the Android project Castle-Invaders listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.noobygames.utils.ui;
/*from   w w  w .jav a 2s.c o m*/
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.noobygames.utils.exceptions.SliderOutOfBoundingsException;

/**
 * @author Nerzal
 * @extends SimpleElement
 **/
public class Slider extends SimpleElement {

  private boolean isVertical;
  private Rectangle ownerPos;
  private boolean border;

  /**
   * @param position
   *            Relative position
   * @param ownerPos
   *            Position of the Table or Window the element lays on
   * @param tex
   *            the texture
   * @param isVertical
   *            does it slide vertical
   **/
  public Slider(Rectangle position, Rectangle ownerPosition, Texture tex,
      boolean isVertical) {
    super(position, tex);
    this.isVertical = isVertical;
    this.ownerPos = ownerPosition;
  }

  /**
   * @return the isVertical
   */
  public boolean isVertical() {
    return isVertical;
  }

  /**
   * @param isVertical
   *            the isVertical to set
   */
  public void setVertical(boolean isVertical) {
    this.isVertical = isVertical;
  }

  /**
   * This method moves the slider within the borders of the owner
   * 
   * @param delta
   *            The pixels to scroll
   **/
  public void scroll(float delta) {
    try{
    if (this.isVertical) {
      if (delta > 0)
        if (this.getPosition().y + this.getPosition().height + delta < this.ownerPos.y)
          this.setPosition(this.getPosition().x + delta,
              this.getPosition().y, this.getPosition().width,
              this.getPosition().height);
        else {
          this.setBorder(true);
          throw new SliderOutOfBoundingsException();
        }

      else if (delta < 0)
        if (this.getPosition().y + delta > this.ownerPos.y)
          this.setPosition(this.getPosition().x + delta,
              this.getPosition().y, this.getPosition().width,
              this.getPosition().height);
        else {
          this.setBorder(true);
          throw new SliderOutOfBoundingsException();
        }
    } else {
      if (delta > 0)
        if (this.getPosition().x + this.getPosition().width + delta < this.ownerPos.x
            + this.ownerPos.width)
          this.setPosition(this.getPosition().x, this.getPosition().y
              + delta, this.getPosition().width,
              this.getPosition().height);
        else {
          this.setBorder(true);
          throw new SliderOutOfBoundingsException();
        }

      else if (delta < 0)
        if (this.getPosition().x + delta > this.ownerPos.x
            + this.ownerPos.width)
          this.setPosition(this.getPosition().x, this.getPosition().y
              + delta, this.getPosition().width,
              this.getPosition().height);
        else {
          this.setBorder(true);
          throw new SliderOutOfBoundingsException();
        }
    }
    } catch (SliderOutOfBoundingsException e) {
      e.printStackTrace();
    }
  }

  /**
   * @return the border
   */
  public boolean isBorder() {
    return border;
  }

  /**
   * @param border
   *            the border to set
   */
  public void setBorder(boolean border) {
    this.border = border;
  }

}




Java Source Code List

com.noobgygames.castleinvaders.ui.DragonUltiButton.java
com.noobgygames.castleinvaders.ui.ElementSwitcherButton.java
com.noobgygames.castleinvaders.ui.StoreElement.java
com.noobgygames.castleinvaders.ui.TextureElement.java
com.noobygames.castleinvaders.Assets.java
com.noobygames.castleinvaders.CastleInvaders.java
com.noobygames.castleinvaders.DynamicGameObject.java
com.noobygames.castleinvaders.GameLiving.java
com.noobygames.castleinvaders.GameObject.java
com.noobygames.castleinvaders.MainActivity.java
com.noobygames.castleinvaders.Main.java
com.noobygames.castleinvaders.Player.java
com.noobygames.castleinvaders.Projectile.java
com.noobygames.castleinvaders.Settings.java
com.noobygames.castleinvaders.WorldRenderer.java
com.noobygames.castleinvaders.World.java
com.noobygames.castleinvaders.mobs.Croco.java
com.noobygames.castleinvaders.mobs.EarthDragon.java
com.noobygames.castleinvaders.mobs.FireDragon.java
com.noobygames.castleinvaders.mobs.FireTroll.java
com.noobygames.castleinvaders.mobs.GameScreen.java
com.noobygames.castleinvaders.mobs.GreyTroll.java
com.noobygames.castleinvaders.mobs.IceDragon.java
com.noobygames.castleinvaders.mobs.IceTroll.java
com.noobygames.castleinvaders.mobs.Murloc.java
com.noobygames.castleinvaders.mobs.Orc.java
com.noobygames.castleinvaders.mobs.Skeleton.java
com.noobygames.castleinvaders.screens.GameScreen.java
com.noobygames.castleinvaders.screens.MainMenuScreen.java
com.noobygames.castleinvaders.screens.ScoreScreen.java
com.noobygames.castleinvaders.screens.SplashScreen.java
com.noobygames.castleinvaders.screens.StoreScreen.java
com.noobygames.castleinvaders.store.StoreObject.java
com.noobygames.castleinvaders.store.Store.java
com.noobygames.nerzal.castleinvaders.spells.Burning.java
com.noobygames.nerzal.castleinvaders.spells.Freeze.java
com.noobygames.nerzal.castleinvaders.spells.SpellEffect.java
com.noobygames.nerzal.castleinvaders.spells.Spells.java
com.noobygames.utils.ArrayListUtils.java
com.noobygames.utils.ObjectSelectionContainer.java
com.noobygames.utils.OverlapTester.java
com.noobygames.utils.exceptions.OutOfBoundingException.java
com.noobygames.utils.exceptions.SliderOutOfBoundingsException.java
com.noobygames.utils.ui.Button.java
com.noobygames.utils.ui.ClickableElement.java
com.noobygames.utils.ui.DropDownMenu.java
com.noobygames.utils.ui.Element.java
com.noobygames.utils.ui.RadioButton.java
com.noobygames.utils.ui.RadioGroupButton.java
com.noobygames.utils.ui.ScrollableElement.java
com.noobygames.utils.ui.SimpleElement.java
com.noobygames.utils.ui.Slider.java
com.noobygames.utils.ui.Table.java
com.noobygames.utils.ui.TextBox.java
com.noobygames.utils.ui.Text.java
com.noobygames.utils.ui.Window.java