org.meanworks.engine.gui.Image.java Source code

Java tutorial

Introduction

Here is the source code for org.meanworks.engine.gui.Image.java

Source

package org.meanworks.engine.gui;

import org.lwjgl.opengl.GL11;
import org.meanworks.engine.EngineLogger;
import org.meanworks.engine.render.opengl.GLImmediate;
import org.meanworks.engine.render.texture.Texture;
import org.meanworks.engine.render.texture.TextureLoader;

/**
 * Copyright (C) 2013 Steffen Evensen
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author Meanz
 */
public class Image extends Component {

    /**
     * 
     */
    private Texture imageTexture;

    /**
     * 
     */
    private boolean dragging;

    /**
     * The constructor
     * 
     * @param texture
     * @param x
     * @param y
     */
    public Image(String textureLocation, int x, int y) {
        super("Image" + Component.getNextId(), x, y, 0, 0);
        imageTexture = TextureLoader.loadTexture(textureLocation);
        if (imageTexture != null) {
            setSize(imageTexture.getWidth(), imageTexture.getHeight());
        } else {
            EngineLogger.error("Added component " + getName() + " type Image with null texture.");
        }
    }

    /**
     * The constructor
     * 
     * @param texture
     * @param x
     * @param y
     */
    public Image(Texture texture, int x, int y) {
        super("Image" + Component.getNextId(), x, y, texture.getWidth(), texture.getHeight());
        this.imageTexture = texture;
    }

    /**
     * Draw the image
     */
    @Override
    public void render() {
        if (imageTexture != null) {
            GL11.glColor3f(1.0f, 1.0f, 1.0f);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            imageTexture.bind();
            GLImmediate.drawTexturedQuad(getX(), getY(), imageTexture.getWidth(), imageTexture.getHeight());
        }
    }
}