Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/back_buffer_copy.cpp
9903 views
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 DEBUG_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 // DEBUG_ENABLED
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 (!Engine::get_singleton()->is_editor_hint()) {
84
return;
85
}
86
if (copy_mode != COPY_MODE_RECT && p_property.name == "rect") {
87
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
88
}
89
}
90
91
void BackBufferCopy::_bind_methods() {
92
ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect);
93
ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect);
94
95
ClassDB::bind_method(D_METHOD("set_copy_mode", "copy_mode"), &BackBufferCopy::set_copy_mode);
96
ClassDB::bind_method(D_METHOD("get_copy_mode"), &BackBufferCopy::get_copy_mode);
97
98
ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode", PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport"), "set_copy_mode", "get_copy_mode");
99
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect", PROPERTY_HINT_NONE, "suffix:px"), "set_rect", "get_rect");
100
101
BIND_ENUM_CONSTANT(COPY_MODE_DISABLED);
102
BIND_ENUM_CONSTANT(COPY_MODE_RECT);
103
BIND_ENUM_CONSTANT(COPY_MODE_VIEWPORT);
104
}
105
106
BackBufferCopy::BackBufferCopy() {
107
_update_copy_mode();
108
set_hide_clip_children(true);
109
}
110
111
BackBufferCopy::~BackBufferCopy() {
112
}
113
114