//
// $Id$
//
// BUI - a user interface library for the JME 3D engine
// Copyright (C) 2005, Michael Bayne, All Rights Reserved
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.jme.bui;

import java.net.URL;

import java.awt.image.BufferedImage;

import com.jme.image.Image;
import com.jme.image.Texture;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;

import com.jme.bui.util.RenderUtil;

/**
 * Provides icon imagery for various components which make use of it.
 */
public class BIcon
{
    /**
     * Creates an icon from the image referenced by the supplied URL.
     */
    public BIcon (URL image)
    {
        this(TextureManager.loadTexture(
                 image, Texture.MM_LINEAR, Texture.FM_LINEAR,
                 Image.GUESS_FORMAT_NO_S3TC, 1.0f, true));
    }

    /**
     * Creates an icon from the supplied source image.
     */
    public BIcon (BufferedImage image)
    {
        this(TextureManager.loadTexture(image, Texture.MM_LINEAR_LINEAR,
                                        Texture.FM_LINEAR, true));
    }

    /**
     * Creates an icon from the supplied source texture.
     */
    public BIcon (Texture texture)
    {
        _texture = texture;
        _tstate = DisplaySystem.getDisplaySystem().getRenderer().
            createTextureState();
        _tstate.setEnabled(true);
        _tstate.setTexture(_texture);

        _quad = new Quad("icon", getWidth(), getHeight());
        _quad.setRenderState(_tstate);

        // we want transparent parts of our texture to show through
        RenderUtil.makeTransparent(_quad);
        _quad.updateRenderState();
    }

    /**
     * Returns the width of this icon.
     */
    public int getWidth ()
    {
        return _texture.getImage().getWidth();
    }

    /**
     * Returns the height of this icon.
     */
    public int getHeight ()
    {
        return _texture.getImage().getHeight();
    }

    /**
     * Returns the textured quad that is used to display this icon.
     */
    public Quad getQuad ()
    {
        return _quad;
    }

    protected Texture _texture;
    protected TextureState _tstate;
    protected Quad _quad;
}

@@ -1147,16 +1147,51 @@
 nager;%0A%0A
+import com.jme.bui.util.Dimension;%0A
 import c
@@ -1218,16 +1218,16 @@
 erUtil;%0A
-
 %0A/**%0A * 
@@ -1594,24 +1594,32 @@
  1.0f, true)
+, -1, -1
 );%0A    %7D%0A%0A  
@@ -1869,16 +1869,66 @@
 R, true)
+,%0A             image.getWidth(), image.getHeight()
 );%0A    %7D
@@ -2035,16 +2035,39 @@
  texture
+, int width, int height
 )%0A    %7B%0A
@@ -2263,24 +2263,213 @@
 _texture);%0A%0A
+        if (width == -1) %7B%0A            width = _texture.getImage().getWidth();%0A            height = _texture.getImage().getHeight();%0A        %7D%0A        _size = new Dimension(width, height);%0A
         _qua
@@ -2493,31 +2493,21 @@
 n%22, 
-getWidth(), getH
+width, h
 eight
-()
 );%0A 
@@ -2806,37 +2806,18 @@
 rn _
-texture.getImage().getW
+size.w
 idth
-()
 ;%0A  
@@ -2931,38 +2931,19 @@
 rn _
-texture.getImage().getH
+size.h
 eight
-()
 ;%0A  
@@ -3161,16 +3161,16 @@
 tstate;%0A
-
     prot
@@ -3187,10 +3187,41 @@
  _quad;%0A
+    protected Dimension _size;%0A
 %7D%0A

Support textures that have no underlying image.