back_buffer_copy.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* back_buffer_copy.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 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 "back_buffer_copy.h"
  30. void BackBufferCopy::_update_copy_mode() {
  31. switch(copy_mode) {
  32. case COPY_MODE_DISABLED: {
  33. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2());
  34. } break;
  35. case COPY_MODE_RECT: {
  36. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect);
  37. } break;
  38. case COPY_MODE_VIEWPORT: {
  39. VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2());
  40. } break;
  41. }
  42. }
  43. Rect2 BackBufferCopy::get_item_rect() const {
  44. return rect;
  45. }
  46. void BackBufferCopy::set_rect(const Rect2& p_rect) {
  47. rect=p_rect;
  48. _update_copy_mode();
  49. }
  50. Rect2 BackBufferCopy::get_rect() const{
  51. return rect;
  52. }
  53. void BackBufferCopy::set_copy_mode(CopyMode p_mode){
  54. copy_mode=p_mode;
  55. _update_copy_mode();
  56. }
  57. BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const{
  58. return copy_mode;
  59. }
  60. void BackBufferCopy::_bind_methods() {
  61. ClassDB::bind_method(_MD("set_rect","rect"),&BackBufferCopy::set_rect);
  62. ClassDB::bind_method(_MD("get_rect"),&BackBufferCopy::get_rect);
  63. ClassDB::bind_method(_MD("set_copy_mode","copy_mode"),&BackBufferCopy::set_copy_mode);
  64. ClassDB::bind_method(_MD("get_copy_mode"),&BackBufferCopy::get_copy_mode);
  65. ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),"set_copy_mode","get_copy_mode");
  66. ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),"set_rect","get_rect");
  67. BIND_CONSTANT( COPY_MODE_DISABLED );
  68. BIND_CONSTANT( COPY_MODE_RECT );
  69. BIND_CONSTANT( COPY_MODE_VIEWPORT );
  70. }
  71. BackBufferCopy::BackBufferCopy(){
  72. rect=Rect2(-100,-100,200,200);
  73. copy_mode=COPY_MODE_RECT;
  74. _update_copy_mode();
  75. }
  76. BackBufferCopy::~BackBufferCopy(){
  77. }