Package thegame.gui

Source Code of thegame.gui.SelectionMenuCell

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package thegame.gui;

import java.awt.*;
import javax.swing.JLabel;
import net.sf.jiga.xtended.impl.Sf3Renderable;
import net.sf.jiga.xtended.impl.Sf3RenderableImpl;
import net.sf.jiga.xtended.impl.game.RenderingScene;
import net.sf.jiga.xtended.impl.game.gl.geom.GLGeom;
import thegame.FieldGui;

/**
*
* @author www.b23prodtm.info
*/
public class SelectionMenuCell extends GameMenuElement {

    public Selectable_CELL selectable;
    Paint shadow_gradient = null;
    public final String name;
    FieldGui gui;

    public SelectionMenuCell(FieldGui gui, String name, Runnable doSelection, Runnable doUnselect, boolean selected) {
        this(gui, name, doSelection, doUnselect);
        this.selectable.setDefaultState(selected);
        this.selectable.reset();
    }

    public SelectionMenuCell(FieldGui gui, String name, Runnable doSelection, Runnable doUnselect) {
        super(null, new Sf3RenderableImpl(), gui.rbHasKey(gui.rb, name) ? gui.rb.getString(name) : name);
        this.gui = gui;
        this.name = name;
        this.selectable = new Selectable_CELL(this, doSelection, doUnselect);
    }

    public void setSelected(boolean b) {
        this.selectable.setSelected(b);
    }

    public int hashCode() {
        return name.hashCode();
    }

    public boolean equals(Object o) {
        if (o != null) {
            return o.hashCode() == hashCode();
        } else {
            return false;
        }
    }
    Rectangle gradientBounds = new Rectangle();

    private Paint newGradient(Color first, Color second) {
        gradientBounds = getBounds();
        return new GradientPaint(gradientBounds.x, gradientBounds.y, first, gradientBounds.x, gradientBounds.y + (float) gradientBounds.height * 0.66f, second, false);
    }

    @Override
    public void setForeground(Color c) {
        super.setForeground(c);
        shadow_gradient = newGradient(new Color(1f, 1f, 1f, 0f), getForeground());
    }
    boolean isSelected = false;
    boolean cellHasFocus = false;

    public boolean isSelected() {
        return isSelected;
    }

    public boolean isCellHasFocus() {
        return cellHasFocus;
    }
    static int font = 5;

    protected void GLpaintComponent(RenderingScene gld, double z, int fx, Point fx_loc, Color fx_color) {
        Rectangle cellBounds = getBounds();
        boolean i = gui.glow.glow > .5f;
        String label = (cellHasFocus ? (i ? "> " : " >") : "") + name + (cellHasFocus ? (i ? " <" : "< ") : "");
        if (isSelected) {
            GLGeom._GLfillRoundRect(gld, 0, true, cellBounds, z, GLGeom.getCWrgbaColors(Color.GREEN, .8f), fx, fx_loc, fx_color);
        } else {
            GLGeom._GLfillRoundRect(gld, 0, true, cellBounds, z, GLGeom.getCWrgbaColors(Color.YELLOW, .8f), fx, fx_loc, fx_color);
        }
        if (cellHasFocus) {
            GLGeom._GLdrawRoundRect(gld, hashCode(), true, 3, cellBounds, z, GLGeom.getCWrgbaColors(Color.GREEN, gui.glow.glow), fx, fx_loc, fx_color);
        }
        Dimension labelDim = gui._GL_baseCodeStringCLIPSIZE(gld, label, font);
        labelDim.width = Math.min(labelDim.width, cellBounds.width);
        labelDim.height = Math.min(labelDim.height, cellBounds.height);
        Dimension fontSize = new Dimension((int) ((float) labelDim.width / (float) label.length()), labelDim.height);
        gui._GL_baseCodeStringDRAW(gld,
                cellBounds.x + (int) ((float) (cellBounds.getWidth() - labelDim.width) / 2f),
                cellBounds.y + (int) ((float) (cellBounds.getHeight() - labelDim.height) / 2f),
                z + 1,
                fontSize,
                label, fx, fx_loc, GLGeom.getGlowingColor(Color.WHITE, gui.glow.glowCos));
    }

    /**
     * set to unselected
     */
    public void reset() {
        selectable.reset();
    }
}
TOP

Related Classes of thegame.gui.SelectionMenuCell

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.