qaida.app.Haraf.java Source code

Java tutorial

Introduction

Here is the source code for qaida.app.Haraf.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package qaida.app;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.StringBuilder;

/**
 * @author hafiz
 */
public class Haraf {
    private Sprite img;
    private float fX, fY;
    private Sound sound;
    private ShapeRenderer shape;
    private SpriteBatch batch;
    private Rectangle playButton;
    private StringBuilder stringBuilder;
    boolean bShowDarker = false;

    public Haraf(String sPath, float fX, float fY, int nButtonY, ShapeRenderer shape, SpriteBatch batch) {
        img = new Sprite(new Texture(sPath));
        this.fX = fX;
        this.fY = fY;
        this.shape = shape;
        this.batch = batch;
        stringBuilder = new StringBuilder(sPath);
        stringBuilder.replace("jpg", "mp3");
        playButton = new Rectangle(fX + img.getWidth() / 2 - 10, nButtonY + 20, 20, 20);
        sound = Gdx.audio.newSound(Gdx.files.internal(stringBuilder.toString()));
    }

    public void display() {
        batch.begin();
        batch.draw(img, fX, fY);
        batch.end();
        shape.begin(ShapeRenderer.ShapeType.Filled);
        if (bShowDarker) {
            shape.setColor(Color.BLUE);
        } else {
            shape.setColor(Color.GREEN);
        }
        shape.rect(playButton.getX(), playButton.getY(), playButton.getWidth(), playButton.getHeight());
        shape.setColor(Color.WHITE);
        shape.triangle(playButton.getX() + 2, playButton.getY() + 18, playButton.getX() + 18,
                playButton.getY() + 10, playButton.getX() + 2, playButton.y + 2);
        shape.end();
    }

    public void playSound() {
        sound.play();
    }

    public Rectangle getBoundingRectanble() {
        return playButton;
    }
}