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 | |
31 | #include "back_buffer_copy.h" |
32 | |
33 | void BackBufferCopy::_update_copy_mode() { |
34 | switch (copy_mode) { |
35 | case COPY_MODE_DISABLED: { |
36 | RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2()); |
37 | } break; |
38 | case COPY_MODE_RECT: { |
39 | RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect); |
40 | } break; |
41 | case COPY_MODE_VIEWPORT: { |
42 | RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2()); |
43 | |
44 | } break; |
45 | } |
46 | } |
47 | |
48 | #ifdef TOOLS_ENABLED |
49 | Rect2 BackBufferCopy::_edit_get_rect() const { |
50 | return rect; |
51 | } |
52 | |
53 | bool BackBufferCopy::_edit_use_rect() const { |
54 | return true; |
55 | } |
56 | #endif |
57 | |
58 | Rect2 BackBufferCopy::get_anchorable_rect() const { |
59 | return rect; |
60 | } |
61 | |
62 | void BackBufferCopy::set_rect(const Rect2 &p_rect) { |
63 | rect = p_rect; |
64 | _update_copy_mode(); |
65 | item_rect_changed(); |
66 | } |
67 | |
68 | Rect2 BackBufferCopy::get_rect() const { |
69 | return rect; |
70 | } |
71 | |
72 | void BackBufferCopy::set_copy_mode(CopyMode p_mode) { |
73 | copy_mode = p_mode; |
74 | _update_copy_mode(); |
75 | notify_property_list_changed(); |
76 | } |
77 | |
78 | BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const { |
79 | return copy_mode; |
80 | } |
81 | |
82 | void BackBufferCopy::_validate_property(PropertyInfo &p_property) const { |
83 | if (copy_mode != COPY_MODE_RECT && p_property.name == "rect" ) { |
84 | p_property.usage = PROPERTY_USAGE_NO_EDITOR; |
85 | } |
86 | } |
87 | |
88 | void BackBufferCopy::_bind_methods() { |
89 | ClassDB::bind_method(D_METHOD("set_rect" , "rect" ), &BackBufferCopy::set_rect); |
90 | ClassDB::bind_method(D_METHOD("get_rect" ), &BackBufferCopy::get_rect); |
91 | |
92 | ClassDB::bind_method(D_METHOD("set_copy_mode" , "copy_mode" ), &BackBufferCopy::set_copy_mode); |
93 | ClassDB::bind_method(D_METHOD("get_copy_mode" ), &BackBufferCopy::get_copy_mode); |
94 | |
95 | ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode" , PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport" ), "set_copy_mode" , "get_copy_mode" ); |
96 | ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect" , PROPERTY_HINT_NONE, "suffix:px" ), "set_rect" , "get_rect" ); |
97 | |
98 | BIND_ENUM_CONSTANT(COPY_MODE_DISABLED); |
99 | BIND_ENUM_CONSTANT(COPY_MODE_RECT); |
100 | BIND_ENUM_CONSTANT(COPY_MODE_VIEWPORT); |
101 | } |
102 | |
103 | BackBufferCopy::BackBufferCopy() { |
104 | _update_copy_mode(); |
105 | set_hide_clip_children(true); |
106 | } |
107 | |
108 | BackBufferCopy::~BackBufferCopy() { |
109 | } |
110 | |