back_buffer_copy.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* back_buffer_copy.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. Rect2 BackBufferCopy::_edit_get_rect() const {
  45. return rect;
  46. }
  47. bool BackBufferCopy::_edit_use_rect() const {
  48. return true;
  49. }
  50. Rect2 BackBufferCopy::get_anchorable_rect() const {
  51. return rect;
  52. }
  53. void BackBufferCopy::set_rect(const Rect2 &p_rect) {
  54. rect = p_rect;
  55. _update_copy_mode();
  56. }
  57. Rect2 BackBufferCopy::get_rect() const {
  58. return rect;
  59. }
  60. void BackBufferCopy::set_copy_mode(CopyMode p_mode) {
  61. copy_mode = p_mode;
  62. _update_copy_mode();
  63. }
  64. BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const {
  65. return copy_mode;
  66. }
  67. void BackBufferCopy::_bind_methods() {
  68. ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect);
  69. ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect);
  70. ClassDB::bind_method(D_METHOD("set_copy_mode", "copy_mode"), &BackBufferCopy::set_copy_mode);
  71. ClassDB::bind_method(D_METHOD("get_copy_mode"), &BackBufferCopy::get_copy_mode);
  72. ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode", PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport"), "set_copy_mode", "get_copy_mode");
  73. ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect");
  74. BIND_ENUM_CONSTANT(COPY_MODE_DISABLED);
  75. BIND_ENUM_CONSTANT(COPY_MODE_RECT);
  76. BIND_ENUM_CONSTANT(COPY_MODE_VIEWPORT);
  77. }
  78. BackBufferCopy::BackBufferCopy() {
  79. rect = Rect2(-100, -100, 200, 200);
  80. copy_mode = COPY_MODE_RECT;
  81. _update_copy_mode();
  82. }
  83. BackBufferCopy::~BackBufferCopy() {
  84. }