de.rico.engine.effect.ortho
Class ListMenuRenderer

java.lang.Object
  extended by de.rico.engine.effect.ortho.ListMenuRenderer

public class ListMenuRenderer
extends java.lang.Object

This class can be used as a renderer for a list menu. A list menu usually has several text entries that are ordered in a top-down array.

Author:
Frank Bruns

Constructor Summary
ListMenuRenderer(int x, int y, int spacing, int margin, Color4f txtCol, Color4f hoverCol, Color4f bgCol)
          Creates a new list menu with the specified parameters.
ListMenuRenderer(int x, int y, int spacing, int margin, Color4f txtCol, Color4f hoverCol, Color4f bgCol, Font font)
          Creates a new list menu with the specified parameters.
 
Method Summary
 void add(java.lang.String entry, java.lang.String id)
          Adds a new entry to the list menu.
 void clear()
          Clears the entries from the list menu.
 void draw(int mouseX, int mouseY)
          Draws the list menu and its current entries.
 java.lang.String getEntryId(int mouseX, int mouseY)
          Returns the id of the entry that lies under the specified screen coordinates.
 void remove(java.lang.String id)
          Removes the entry which corresponds to the specified id from the menu.
 void setBGImage(OverlayImage img, float alpha)
          Sets a background image to the list menu.
 void setVisible(boolean visible)
          Sets whether or not the list menu ought to be visible.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListMenuRenderer

public ListMenuRenderer(int x,
                        int y,
                        int spacing,
                        int margin,
                        Color4f txtCol,
                        Color4f hoverCol,
                        Color4f bgCol)
Creates a new list menu with the specified parameters. The width and height of the menu area will adapt to the space that is required by its entries.

Parameters:
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
spacing - vertical spacing (gap size) between the entries
margin - margin for the menu box.
txtCol - text color for the menu entries
hoverCol - color of text while mouse is hovering over it
bgCol - background color of the menu

ListMenuRenderer

public ListMenuRenderer(int x,
                        int y,
                        int spacing,
                        int margin,
                        Color4f txtCol,
                        Color4f hoverCol,
                        Color4f bgCol,
                        Font font)
Creates a new list menu with the specified parameters. The width and height of the menu area will adapt to the space that is required by its entries.

Parameters:
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
spacing - vertical spacing (gap size) between the entries
margin - margin for the menu box.
txtCol - text color for the menu entries
hoverCol - color of text while mouse is hovering over it
bgCol - background color of the menu
font - font from the Font enumeration class
Method Detail

setBGImage

public void setBGImage(OverlayImage img,
                       float alpha)
Sets a background image to the list menu.

Parameters:
img - overlay image that ought to be used as a background image.
alpha - alpha value [0..1] for transparency

add

public void add(java.lang.String entry,
                java.lang.String id)
Adds a new entry to the list menu. The id is used to refer to the menu entry later on.

Parameters:
entry - new list menu entry
id - id to refer to the entry

remove

public void remove(java.lang.String id)
Removes the entry which corresponds to the specified id from the menu.

Parameters:
id - id that refers to the entry which is meant to be removed.

clear

public void clear()
Clears the entries from the list menu.


setVisible

public void setVisible(boolean visible)
Sets whether or not the list menu ought to be visible.

Parameters:
visible - set visible? --> true=yes, false=no

draw

public void draw(int mouseX,
                 int mouseY)
Draws the list menu and its current entries. The specified mouse coords are used to figure out which entry needs to be highlighted (hover effect).

Parameters:
mouseX - x-coordinate of current mouse position
mouseY - y-coordinate of current mouse position

getEntryId

public java.lang.String getEntryId(int mouseX,
                                   int mouseY)
Returns the id of the entry that lies under the specified screen coordinates. If the coordinates point to no entry the method returns null.

Parameters:
mouseX - screen x-coordinate
mouseY - screen y-coordinate
Returns:
id of the entry under the screen coordinates, or null