123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- = indicator
- :author:
- :revnumber:
- :revdate: 2016/03/17 20:48
- :relfileprefix: ../../../
- :imagesdir: ../../..
- ifdef::env-github,env-browser[:outfilesuffix: .adoc]
- == Indicator Class
- An indicator is a highly customizable progress bar, which can be used showing/displaying player stats, etc
- The Indicator uses the 3 standard constructors as shown in the <<jme3/contributions/tonegodgui/quickstart#,Quick Start Guide>> with the addition of one extra parameter:
- * Orientation appended to the end of the param list for each
- *Features include:*
- * Clipping + an alpha mask to create any shaped indicator you would like
- * Display the indicator in any color you choose.
- * Image based indicators in place of color+clipping
- * An overlay image for transparent indicator containers
- === Constructor example:
- [source,java]
- ----
- /**
- * Parameters:
- * Screen screen
- * String UID
- * Vector2f position
- * Orientation orientation
- */
- Indicator ind = new Indicator(
- screen,
- “SomeID”,
- new Vector2f(10,10),
- Orientation.VERTICAL
- );
- ----
- === Changing & Reshaping the Indicator
- [source,java]
- ----
- // Using an image in place of a colored indicator
- ind.setBaseImage(String imgPath);
- // Use a clipped image for the indicator
- ind.setIndicatorImage(String imgPath);
- // Changing the color of the indicator or colorize the image-based indicator
- ind.setIndicatorColor(ColorRGBA indicatorColor);
- // Add padding (margins) to the indicator portion of the indicator
- ind.setIndicatorPadding(Vector4f padding);
- // Reshape the indicator !IMPORTANT! setIndicatorAlphaMap is now @Deprecated, use this instead:
- ind.setAlphaMap(String alphaMapPath);
- ----
- === Methods specific to the Indicator class
- [source,java]
- ----
- // Get the indicators oritentation
- ind.getOrientation();
-
- // Adjust value ranges
- ind.setMaxValue(float maxValue);
- ind.setCurrentValue(float currentValue);
-
- // Get current info
- ind.getCurrentPercentage();
- ind.getCurrentValue();
- ind.getMaxValue();
- ind.getTextDisplayElement(); // Return the text element for formatting purposes
- ind.setDisplayValues(); // Display value in format: current/max or 10/100
- ind.setDisplayPercentage(); // Displays percentage: 82% etc
- ind.setHideText(); // removes display text (default)
- ----
- == Indicator Examples
- Cut & Paste the following code into the simpleInitApp method of a new JME project. Use the slider to adjust the indicator.
- [source,java]
- ----
- flyCam.setDragToRotate(true);
- inputManager.setCursorVisible(true);
-
- screen = new Screen(this);
- guiNode.addControl(screen);
- final ColorRGBA color = new ColorRGBA();
- final Indicator ind = new Indicator(
- screen,
- new Vector2f(50,50),
- new Vector2f(300,30),
- Orientation.HORIZONTAL
- ) {
- @Override
- public void onChange(float currentValue, float currentPercentage) { }
- };
- ind.setBaseImage(screen.getStyle("Window").getString("defaultImg"));
- //ind.setIndicatorImage(screen.getStyle("Window").getString("defaultImg"));
- ind.setIndicatorColor(ColorRGBA.randomColor());
- ind.setAlphaMap(screen.getStyle("Indicator").getString("alphaImg"));
- ind.setIndicatorPadding(new Vector4f(7,7,7,7));
- ind.setMaxValue(100);
- ind.setDisplayPercentage();
-
- screen.addElement(ind);
-
- Slider slider = new Slider(screen, new Vector2f(100,100), Orientation.HORIZONTAL, true) {
- @Override
- public void onChange(int selectedIndex, Object value) {
- float blend = selectedIndex*0.01f;
- color.interpolate(ColorRGBA.Red, ColorRGBA.Green, blend);
- ind.setIndicatorColor(color);
- ind.setCurrentValue((Integer)value);
- }
- };
-
- screen.addElement(slider);
- ----
- image:jme3/contributions/tonegodgui/indicatorexample.png[indicatorexample.png,width="",height=""]
|