indicator.adoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. = indicator
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == Indicator Class
  9. An indicator is a highly customizable progress bar, which can be used showing/displaying player stats, etc
  10. 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:
  11. * Orientation appended to the end of the param list for each
  12. *Features include:*
  13. * Clipping + an alpha mask to create any shaped indicator you would like
  14. * Display the indicator in any color you choose.
  15. * Image based indicators in place of color+clipping
  16. * An overlay image for transparent indicator containers
  17. === Constructor example:
  18. [source,java]
  19. ----
  20. /**
  21. * Parameters:
  22. * Screen screen
  23. * String UID
  24. * Vector2f position
  25. * Orientation orientation
  26. */
  27. Indicator ind = new Indicator(
  28. screen,
  29. “SomeID”,
  30. new Vector2f(10,10),
  31. Orientation.VERTICAL
  32. );
  33. ----
  34. === Changing & Reshaping the Indicator
  35. [source,java]
  36. ----
  37. // Using an image in place of a colored indicator
  38. ind.setBaseImage(String imgPath);
  39. // Use a clipped image for the indicator
  40. ind.setIndicatorImage(String imgPath);
  41. // Changing the color of the indicator or colorize the image-based indicator
  42. ind.setIndicatorColor(ColorRGBA indicatorColor);
  43. // Add padding (margins) to the indicator portion of the indicator
  44. ind.setIndicatorPadding(Vector4f padding);
  45. // Reshape the indicator !IMPORTANT! setIndicatorAlphaMap is now @Deprecated, use this instead:
  46. ind.setAlphaMap(String alphaMapPath);
  47. ----
  48. === Methods specific to the Indicator class
  49. [source,java]
  50. ----
  51. // Get the indicators oritentation
  52. ind.getOrientation();
  53. // Adjust value ranges
  54. ind.setMaxValue(float maxValue);
  55. ind.setCurrentValue(float currentValue);
  56. // Get current info
  57. ind.getCurrentPercentage();
  58. ind.getCurrentValue();
  59. ind.getMaxValue();
  60. ind.getTextDisplayElement(); // Return the text element for formatting purposes
  61. ind.setDisplayValues(); // Display value in format: current/max or 10/100
  62. ind.setDisplayPercentage(); // Displays percentage: 82% etc
  63. ind.setHideText(); // removes display text (default)
  64. ----
  65. == Indicator Examples
  66. Cut &amp; Paste the following code into the simpleInitApp method of a new JME project. Use the slider to adjust the indicator.
  67. [source,java]
  68. ----
  69. flyCam.setDragToRotate(true);
  70. inputManager.setCursorVisible(true);
  71. screen = new Screen(this);
  72. guiNode.addControl(screen);
  73. final ColorRGBA color = new ColorRGBA();
  74. final Indicator ind = new Indicator(
  75. screen,
  76. new Vector2f(50,50),
  77. new Vector2f(300,30),
  78. Orientation.HORIZONTAL
  79. ) {
  80. @Override
  81. public void onChange(float currentValue, float currentPercentage) { }
  82. };
  83. ind.setBaseImage(screen.getStyle("Window").getString("defaultImg"));
  84. //ind.setIndicatorImage(screen.getStyle("Window").getString("defaultImg"));
  85. ind.setIndicatorColor(ColorRGBA.randomColor());
  86. ind.setAlphaMap(screen.getStyle("Indicator").getString("alphaImg"));
  87. ind.setIndicatorPadding(new Vector4f(7,7,7,7));
  88. ind.setMaxValue(100);
  89. ind.setDisplayPercentage();
  90. screen.addElement(ind);
  91. Slider slider = new Slider(screen, new Vector2f(100,100), Orientation.HORIZONTAL, true) {
  92. @Override
  93. public void onChange(int selectedIndex, Object value) {
  94. float blend = selectedIndex*0.01f;
  95. color.interpolate(ColorRGBA.Red, ColorRGBA.Green, blend);
  96. ind.setIndicatorColor(color);
  97. ind.setCurrentValue((Integer)value);
  98. }
  99. };
  100. screen.addElement(slider);
  101. ----
  102. image:jme3/contributions/tonegodgui/indicatorexample.png[indicatorexample.png,width="",height=""]