texture_progress.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* texture_progress.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "texture_progress.h"
  30. void TextureProgress::set_under_texture(const Ref<Texture>& p_texture) {
  31. under=p_texture;
  32. update();
  33. minimum_size_changed();
  34. }
  35. Ref<Texture> TextureProgress::get_under_texture() const{
  36. return under;
  37. }
  38. void TextureProgress::set_over_texture(const Ref<Texture>& p_texture) {
  39. over=p_texture;
  40. update();
  41. minimum_size_changed();
  42. }
  43. Ref<Texture> TextureProgress::get_over_texture() const{
  44. return over;
  45. }
  46. Size2 TextureProgress::get_minimum_size() const {
  47. if (under.is_valid())
  48. return under->get_size();
  49. else if (over.is_valid())
  50. return over->get_size();
  51. else if (progress.is_valid())
  52. return progress->get_size();
  53. return Size2(1,1);
  54. }
  55. void TextureProgress::set_progress_texture(const Ref<Texture>& p_texture) {
  56. progress=p_texture;
  57. update();
  58. minimum_size_changed();
  59. }
  60. Ref<Texture> TextureProgress::get_progress_texture() const{
  61. return progress;
  62. }
  63. void TextureProgress::_notification(int p_what){
  64. switch(p_what) {
  65. case NOTIFICATION_DRAW: {
  66. if (under.is_valid())
  67. draw_texture(under,Point2());
  68. if (progress.is_valid()) {
  69. Size2 s = progress->get_size();
  70. draw_texture_rect_region(progress,Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)),Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)));
  71. }
  72. if (over.is_valid())
  73. draw_texture(over,Point2());
  74. } break;
  75. }
  76. }
  77. void TextureProgress::_bind_methods() {
  78. ObjectTypeDB::bind_method(_MD("set_under_texture","tex"),&TextureProgress::set_under_texture);
  79. ObjectTypeDB::bind_method(_MD("get_under_texture"),&TextureProgress::get_under_texture);
  80. ObjectTypeDB::bind_method(_MD("set_progress_texture","tex"),&TextureProgress::set_progress_texture);
  81. ObjectTypeDB::bind_method(_MD("get_progress_texture"),&TextureProgress::get_progress_texture);
  82. ObjectTypeDB::bind_method(_MD("set_over_texture","tex"),&TextureProgress::set_over_texture);
  83. ObjectTypeDB::bind_method(_MD("get_over_texture"),&TextureProgress::get_over_texture);
  84. ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/under",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_under_texture"),_SCS("get_under_texture"));
  85. ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/over",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_over_texture"),_SCS("get_over_texture"));
  86. ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/progress",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_progress_texture"),_SCS("get_progress_texture"));
  87. }
  88. TextureProgress::TextureProgress()
  89. {
  90. }