Android Open Source - android_game_engine Control






From Project

Back to project page android_game_engine.

License

The source code is released under:

GNU General Public License

If you think the Android project android_game_engine 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 org.es.engine.hud;
//w  w  w. jav a 2  s .c  o  m
import android.graphics.Canvas;
import android.graphics.RectF;
import android.view.MotionEvent;

import org.es.engine.graphics.drawable.DrawableElement;

/**
 * @author Cyril Leroux
 *         Created 02/03/14.
 */
public abstract class Control implements DrawableElement {

    /** The bounds of the control on screen. */
    private final RectF mBounds;

    private float mXCoef;
    private float mYCoef;

    public Control(float xCoef, float yCoef) {
        mBounds = new RectF();
        mXCoef = xCoef;
        mYCoef = yCoef;
    }

    /**
     * Intercepts events.
     * Returns true if the event is consumed. and false otherwise.
     * By default a control does not consume the event.
     * @param event the event to intercepts.
     * @return true if the event is consumed. False otherwise.
     */
    public boolean consumeEvent(MotionEvent event) {
        return false;
    }

    public RectF getBounds() { return mBounds; }

    protected void setBounds(RectF bounds) { mBounds.set(bounds); }

    protected void setBounds(float left, float top, float right, float bottom) {
        mBounds.set(left, top, right, bottom);
    }

    public void draw(Canvas canvas) {
        draw(canvas, null);
    }

    @Override
    public void onUpdateSurfaceSize(int surfaceWidth, int surfaceHeight) { }

    @Override
    public float getPosX() { return mBounds.left; }

    @Override
    public float getPosY() { return mBounds.top; }

    /**
     * Define the position coefficient for abscissa and ordinates.
     * @param xCoef coefficient for abscissa.
     * @param yCoef coefficient for ordinates.
     */
    @Override
    public void setPosition(float xCoef, float yCoef) {
        mXCoef = xCoef;
        mYCoef = yCoef;
    }

    @Override
    public void offsetPosition(float dx, float dy) {
        mXCoef += dx;
        mYCoef += dy;
    }

    @Override
    public float getWidth() { return mBounds.width(); }

    @Override
    public float getHeight() { return mBounds.height(); }

    protected float getXCoef() { return mXCoef; }

    protected float getYCoef() { return mYCoef; }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
com.google.example.games.basegameutils.ScreenUtils.java
org.es.engine.audio.Sound.java
org.es.engine.game_mechanic.DrawingThread.java
org.es.engine.game_mechanic.DrawingView.java
org.es.engine.graphics.animation.AnimationCallback.java
org.es.engine.graphics.animation.Animation.java
org.es.engine.graphics.animation.BitmapAnimation.java
org.es.engine.graphics.animation.SpriteSheetAnimation.java
org.es.engine.graphics.drawable.DrawableElement.java
org.es.engine.graphics.sprite.GenericSprite.java
org.es.engine.graphics.sprite.SpriteSheet.java
org.es.engine.graphics.sprite.Sprite.java
org.es.engine.graphics.utils.DrawTextUtils.java
org.es.engine.graphics.utils.DrawingParam.java
org.es.engine.hud.Button.java
org.es.engine.hud.Control.java
org.es.engine.hud.HUD.java
org.es.engine.hud.Text.java
org.es.engine.hud.ToggleButton.java
org.es.engine.toolbox.pathfinding.Node.java
org.es.engine.toolbox.pathfinding.ShortestPath.java