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
_update_copy_mode()32 void BackBufferCopy::_update_copy_mode() {
33
34 switch (copy_mode) {
35
36 case COPY_MODE_DISABLED: {
37
38 VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2());
39 } break;
40 case COPY_MODE_RECT: {
41
42 VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect);
43 } break;
44 case COPY_MODE_VIEWPORT: {
45
46 VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2());
47
48 } break;
49 }
50 }
51
get_item_rect() const52 Rect2 BackBufferCopy::get_item_rect() const {
53
54 return rect;
55 }
56
set_rect(const Rect2 & p_rect)57 void BackBufferCopy::set_rect(const Rect2 &p_rect) {
58
59 rect = p_rect;
60 _update_copy_mode();
61 }
62
get_rect() const63 Rect2 BackBufferCopy::get_rect() const {
64 return rect;
65 }
66
set_copy_mode(CopyMode p_mode)67 void BackBufferCopy::set_copy_mode(CopyMode p_mode) {
68
69 copy_mode = p_mode;
70 _update_copy_mode();
71 }
get_copy_mode() const72 BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const {
73
74 return copy_mode;
75 }
76
_bind_methods()77 void BackBufferCopy::_bind_methods() {
78
79 ObjectTypeDB::bind_method(_MD("set_rect", "rect"), &BackBufferCopy::set_rect);
80 ObjectTypeDB::bind_method(_MD("get_rect"), &BackBufferCopy::get_rect);
81
82 ObjectTypeDB::bind_method(_MD("set_copy_mode", "copy_mode"), &BackBufferCopy::set_copy_mode);
83 ObjectTypeDB::bind_method(_MD("get_copy_mode"), &BackBufferCopy::get_copy_mode);
84
85 ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode", PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport"), _SCS("set_copy_mode"), _SCS("get_copy_mode"));
86 ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), _SCS("set_rect"), _SCS("get_rect"));
87
88 BIND_CONSTANT(COPY_MODE_DISABLED);
89 BIND_CONSTANT(COPY_MODE_RECT);
90 BIND_CONSTANT(COPY_MODE_VIEWPORT);
91 }
92
BackBufferCopy()93 BackBufferCopy::BackBufferCopy() {
94
95 rect = Rect2(-100, -100, 200, 200);
96 copy_mode = COPY_MODE_RECT;
97 _update_copy_mode();
98 }
~BackBufferCopy()99 BackBufferCopy::~BackBufferCopy() {
100 }
101