2
0

guiProgressCtrl.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/console.h"
  23. #include "console/consoleTypes.h"
  24. #include "graphics/dgl.h"
  25. #include "gui/guiProgressCtrl.h"
  26. IMPLEMENT_CONOBJECT(GuiProgressCtrl);
  27. GuiProgressCtrl::GuiProgressCtrl()
  28. {
  29. mProgress = 0.0f;
  30. }
  31. const char* GuiProgressCtrl::getScriptValue()
  32. {
  33. char * ret = Con::getReturnBuffer(64);
  34. dSprintf(ret, 64, "%g", mProgress);
  35. return ret;
  36. }
  37. void GuiProgressCtrl::setScriptValue(const char *value)
  38. {
  39. //set the value
  40. if (! value)
  41. mProgress = 0.0f;
  42. else
  43. mProgress = dAtof(value);
  44. //validate the value
  45. mProgress = mClampF(mProgress, 0.f, 1.f);
  46. setUpdate();
  47. }
  48. void GuiProgressCtrl::onPreRender()
  49. {
  50. const char * var = getVariable();
  51. if(var)
  52. {
  53. F32 value = mClampF(dAtof(var), 0.f, 1.f);
  54. if(value != mProgress)
  55. {
  56. mProgress = value;
  57. setUpdate();
  58. }
  59. }
  60. }
  61. void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
  62. {
  63. RectI ctrlRect(offset, mBounds.extent);
  64. //draw the progress
  65. S32 width = (S32)((F32)mBounds.extent.x * mProgress);
  66. if (width > 0)
  67. {
  68. RectI progressRect = ctrlRect;
  69. progressRect.extent.x = width;
  70. dglDrawRectFill(progressRect, mProfile->mFillColor);
  71. }
  72. //now draw the border
  73. if (mProfile->mBorder)
  74. dglDrawRect(ctrlRect, mProfile->mBorderColor);
  75. Parent::onRender( offset, updateRect );
  76. //render the children
  77. renderChildControls(offset, updateRect);
  78. }