com.codefiddler.libgdx.spinit.Segment.java Source code

Java tutorial

Introduction

Here is the source code for com.codefiddler.libgdx.spinit.Segment.java

Source

/*
Copyright [2014] [James Thomas Hayes]
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.codefiddler.libgdx.spinit;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Segment {

    private TexturedSprite sprite;
    private boolean selected = false;
    private boolean highlight = false;
    private Color initialColor;

    public Segment(Texture texture, Color initialColor, int id, int numberOfSegments) {
        sprite = new TexturedSprite(texture);
        this.initialColor = new Color(initialColor);
        this.initialColor.r = this.initialColor.g + ((0.64f / numberOfSegments) * id);
        sprite.setColor(this.initialColor);
    }

    public void draw(SpriteBatch batch) {
        if (selected) {
            sprite.setColor(0f, 1f, 0f, 0.7f);
        } else if (highlight) {
            sprite.setColor(initialColor.r, initialColor.g, initialColor.b, 0.8f);
        } else {
            sprite.setColor(initialColor);
        }

        sprite.draw(batch);
    }

    public void dispose() {
        sprite.dispose();
    }

    public void toggleSelect() {

        selected = !selected;

    }

    public boolean getSelected() {
        return selected;
    }

    public void deselect() {
        highlight = false;
    }

    public void select() {
        highlight = true;
    }

}