back_buffer_copy.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**************************************************************************/
  2. /* back_buffer_copy.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "back_buffer_copy.h"
  31. void BackBufferCopy::_update_copy_mode() {
  32. switch (copy_mode) {
  33. case COPY_MODE_DISABLED: {
  34. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2());
  35. } break;
  36. case COPY_MODE_RECT: {
  37. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect);
  38. } break;
  39. case COPY_MODE_VIEWPORT: {
  40. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2());
  41. } break;
  42. }
  43. }
  44. #ifdef TOOLS_ENABLED
  45. Rect2 BackBufferCopy::_edit_get_rect() const {
  46. return rect;
  47. }
  48. bool BackBufferCopy::_edit_use_rect() const {
  49. return true;
  50. }
  51. #endif
  52. Rect2 BackBufferCopy::get_anchorable_rect() const {
  53. return rect;
  54. }
  55. void BackBufferCopy::set_rect(const Rect2 &p_rect) {
  56. rect = p_rect;
  57. _update_copy_mode();
  58. item_rect_changed();
  59. }
  60. Rect2 BackBufferCopy::get_rect() const {
  61. return rect;
  62. }
  63. void BackBufferCopy::set_copy_mode(CopyMode p_mode) {
  64. copy_mode = p_mode;
  65. _update_copy_mode();
  66. _change_notify();
  67. }
  68. BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const {
  69. return copy_mode;
  70. }
  71. void BackBufferCopy::_validate_property(PropertyInfo &p_property) const {
  72. if (copy_mode != COPY_MODE_RECT && p_property.name == "rect") {
  73. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  74. }
  75. }
  76. void BackBufferCopy::_bind_methods() {
  77. ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect);
  78. ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect);
  79. ClassDB::bind_method(D_METHOD("set_copy_mode", "copy_mode"), &BackBufferCopy::set_copy_mode);
  80. ClassDB::bind_method(D_METHOD("get_copy_mode"), &BackBufferCopy::get_copy_mode);
  81. ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode", PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport"), "set_copy_mode", "get_copy_mode");
  82. ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect");
  83. BIND_ENUM_CONSTANT(COPY_MODE_DISABLED);
  84. BIND_ENUM_CONSTANT(COPY_MODE_RECT);
  85. BIND_ENUM_CONSTANT(COPY_MODE_VIEWPORT);
  86. }
  87. BackBufferCopy::BackBufferCopy() {
  88. rect = Rect2(-100, -100, 200, 200);
  89. copy_mode = COPY_MODE_RECT;
  90. _update_copy_mode();
  91. }
  92. BackBufferCopy::~BackBufferCopy() {
  93. }