Android Open Source - YOGOSec G U I Component






From Project

Back to project page YOGOSec.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project YOGOSec 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 YOGOSec.core.gui;
//from ww w. j a va2 s .  co  m
import YOGOSec.core.Game;
import YOGOSec.core.render.Render;
import YOGOSec.core.util.Point2i;
import YOGOSec.core.util.Rectangle;
import YOGOSec.core.util.Rectanglef;

/**
 * @author Aritz Lopez
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 */
public abstract class GUIComponent implements InputListener {

    protected final boolean centerX, centerY, relativeWidth, relativeHeight, absolute;
    protected Rectangle<Float> relativeBounds;
    protected Rectangle<Float> bounds;

    public GUIComponent(Rectanglef bounds) {
        this.relativeBounds = bounds;

        this.centerX = this.relativeBounds.getX() < 0;
        this.centerY = this.relativeBounds.getY() < 0;
        this.relativeWidth = this.relativeBounds.getWidth() < 0;
        this.relativeHeight = this.relativeBounds.getHeight() < 0;

        this.absolute = !(centerX || centerY || relativeWidth || relativeHeight);


        this.relativeBounds = this.relativeBounds.setPos(Math.abs(this.relativeBounds.getX()), Math.abs(this.relativeBounds.getY()));
        this.relativeBounds = this.relativeBounds.setSize(Math.abs(this.relativeBounds.getWidth()), Math.abs(this.relativeBounds.getHeight()));
        this.updateBounds();
    }

    protected void updateBounds() {
        if (this.absolute) {
            if (this.bounds == null) this.bounds = this.relativeBounds;
            else return;
        }

        final int gameWidth = Game.INSTANCE.getRender().getWidth();
        final int gameHeight = Game.INSTANCE.getRender().getHeight();

        float width = this.relativeBounds.getWidth() * (this.relativeWidth ? gameWidth : 1);
        float height = this.relativeBounds.getHeight() * (this.relativeHeight ? gameHeight : 1);

        float x = gameWidth * this.relativeBounds.getX() - (this.centerX ? width / 2 : 0);
        float y = gameHeight * this.relativeBounds.getY() - (this.centerY ? height / 2 : 0);

        this.bounds = new Rectanglef(x, y, width, height);
    }

    public void render(Render render) {

    }

    @Override
    public boolean keyDown(int keycode) {
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        return false;
    }

    @Override
    public boolean touchDown(Point2i point, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchUp(Point2i point, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchDragged(Point2i point, int pointer) {
        return false;
    }

    @Override
    public boolean mouseMoved(Point2i point) {
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        return false;
    }

    public Rectangle<Float> getBounds() {
        return this.bounds;
    }

    public void onGUIResized(int width, int height) {
        this.updateBounds();
    }

    public float getWidth() {
        return this.bounds.getWidth();
    }

    public void setWidth(float width) {
        this.relativeBounds = this.relativeBounds.setWidth(width);
    }

    public float getHeight() {
        return this.bounds.getHeight();
    }

    public void setHeight(float height) {
        this.relativeBounds = this.relativeBounds.setHeight(height);
    }

    public void dispose() {
        
    }
}




Java Source Code List

YOGOSec.android.GameActivity.java
YOGOSec.core.Game.java
YOGOSec.core.gui.Button.java
YOGOSec.core.gui.GUIComponent.java
YOGOSec.core.gui.GUI.java
YOGOSec.core.gui.IActionListener.java
YOGOSec.core.gui.InputListener.java
YOGOSec.core.gui.ProgressBar.java
YOGOSec.core.input.Input.java
YOGOSec.core.render.Render.java
YOGOSec.core.render.YUpPixmap.java
YOGOSec.core.screens.MainMenuScreen.java
YOGOSec.core.screens.MyScreen.java
YOGOSec.core.util.Point2f.java
YOGOSec.core.util.Point2i.java
YOGOSec.core.util.Point.java
YOGOSec.core.util.Rectangle.java
YOGOSec.core.util.Rectanglef.java
YOGOSec.core.util.Rectanglei.java
YOGOSec.java.GameDesktop.java