mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@@ -27,8 +27,8 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "dialogs.h"
|
||||
#include "print_string.h"
|
||||
#include "line_edit.h"
|
||||
#include "print_string.h"
|
||||
#include "translation.h"
|
||||
|
||||
void WindowDialog::_post_popup() {
|
||||
@@ -44,7 +44,7 @@ void WindowDialog::_fix_size() {
|
||||
Point2i pos = get_global_pos();
|
||||
Size2i size = get_size();
|
||||
Size2i viewport_size = get_viewport_rect().size;
|
||||
|
||||
|
||||
// Windows require additional padding to keep the window chrome visible.
|
||||
Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
|
||||
float top = panel->get_margin(MARGIN_TOP);
|
||||
@@ -64,7 +64,7 @@ void WindowDialog::_fix_size() {
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowDialog::has_point(const Point2& p_point) const {
|
||||
bool WindowDialog::has_point(const Point2 &p_point) const {
|
||||
|
||||
Rect2 r(Point2(), get_size());
|
||||
|
||||
@@ -85,7 +85,7 @@ bool WindowDialog::has_point(const Point2& p_point) const {
|
||||
return r.has_point(p_point);
|
||||
}
|
||||
|
||||
void WindowDialog::_gui_input(const InputEvent& p_event) {
|
||||
void WindowDialog::_gui_input(const InputEvent &p_event) {
|
||||
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
@@ -94,7 +94,7 @@ void WindowDialog::_gui_input(const InputEvent& p_event) {
|
||||
drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y));
|
||||
if (drag_type != DRAG_NONE)
|
||||
drag_offset = get_global_mouse_pos() - get_pos();
|
||||
drag_offset_far = get_pos() + get_size() - get_global_mouse_pos();
|
||||
drag_offset_far = get_pos() + get_size() - get_global_mouse_pos();
|
||||
} else if (drag_type != DRAG_NONE && !p_event.mouse_button.pressed) {
|
||||
// End a dragging operation.
|
||||
drag_type = DRAG_NONE;
|
||||
@@ -208,13 +208,13 @@ void WindowDialog::_closed() {
|
||||
hide();
|
||||
}
|
||||
|
||||
int WindowDialog::_drag_hit_test(const Point2& pos) const {
|
||||
int WindowDialog::_drag_hit_test(const Point2 &pos) const {
|
||||
int drag_type = DRAG_NONE;
|
||||
|
||||
if (resizable) {
|
||||
int titlebar_height = get_constant("titlebar_height", "WindowDialog");
|
||||
int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
|
||||
|
||||
|
||||
Rect2 rect = get_rect();
|
||||
|
||||
if (pos.y < (-titlebar_height + scaleborder_size))
|
||||
@@ -233,9 +233,9 @@ int WindowDialog::_drag_hit_test(const Point2& pos) const {
|
||||
return drag_type;
|
||||
}
|
||||
|
||||
void WindowDialog::set_title(const String& p_title) {
|
||||
void WindowDialog::set_title(const String &p_title) {
|
||||
|
||||
title=XL_MESSAGE(p_title);
|
||||
title = XL_MESSAGE(p_title);
|
||||
update();
|
||||
}
|
||||
String WindowDialog::get_title() const {
|
||||
@@ -250,36 +250,32 @@ bool WindowDialog::get_resizable() const {
|
||||
return resizable;
|
||||
}
|
||||
|
||||
|
||||
Size2 WindowDialog::get_minimum_size() const {
|
||||
|
||||
Ref<Font> font = get_font("title_font","WindowDialog");
|
||||
int msx=close_button->get_combined_minimum_size().x;
|
||||
msx+=font->get_string_size(title).x;
|
||||
Ref<Font> font = get_font("title_font", "WindowDialog");
|
||||
int msx = close_button->get_combined_minimum_size().x;
|
||||
msx += font->get_string_size(title).x;
|
||||
|
||||
return Size2(msx,1);
|
||||
return Size2(msx, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TextureButton *WindowDialog::get_close_button() {
|
||||
|
||||
|
||||
return close_button;
|
||||
}
|
||||
|
||||
void WindowDialog::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method( D_METHOD("_gui_input"),&WindowDialog::_gui_input);
|
||||
ClassDB::bind_method( D_METHOD("set_title","title"),&WindowDialog::set_title);
|
||||
ClassDB::bind_method( D_METHOD("get_title"),&WindowDialog::get_title);
|
||||
ClassDB::bind_method( D_METHOD("set_resizable","resizable"),&WindowDialog::set_resizable);
|
||||
ClassDB::bind_method( D_METHOD("get_resizable"), &WindowDialog::get_resizable);
|
||||
ClassDB::bind_method( D_METHOD("_closed"),&WindowDialog::_closed);
|
||||
ClassDB::bind_method( D_METHOD("get_close_button:TextureButton"),&WindowDialog::get_close_button);
|
||||
ClassDB::bind_method(D_METHOD("_gui_input"), &WindowDialog::_gui_input);
|
||||
ClassDB::bind_method(D_METHOD("set_title", "title"), &WindowDialog::set_title);
|
||||
ClassDB::bind_method(D_METHOD("get_title"), &WindowDialog::get_title);
|
||||
ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &WindowDialog::set_resizable);
|
||||
ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable);
|
||||
ClassDB::bind_method(D_METHOD("_closed"), &WindowDialog::_closed);
|
||||
ClassDB::bind_method(D_METHOD("get_close_button:TextureButton"), &WindowDialog::get_close_button);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::STRING,"window_title",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL),"set_title","get_title");
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"resizable",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL),"set_resizable","get_resizable");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_resizable", "get_resizable");
|
||||
}
|
||||
|
||||
WindowDialog::WindowDialog() {
|
||||
@@ -290,57 +286,46 @@ WindowDialog::WindowDialog() {
|
||||
close_button = memnew(TextureButton);
|
||||
add_child(close_button);
|
||||
close_button->connect("pressed", this, "_closed");
|
||||
|
||||
}
|
||||
|
||||
WindowDialog::~WindowDialog(){
|
||||
|
||||
|
||||
WindowDialog::~WindowDialog() {
|
||||
}
|
||||
|
||||
|
||||
void PopupDialog::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
||||
get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
|
||||
}
|
||||
}
|
||||
|
||||
PopupDialog::PopupDialog() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
PopupDialog::~PopupDialog() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// AcceptDialog
|
||||
|
||||
|
||||
void AcceptDialog::_post_popup() {
|
||||
|
||||
WindowDialog::_post_popup();
|
||||
get_ok()->grab_focus();
|
||||
|
||||
}
|
||||
|
||||
void AcceptDialog::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_MODAL_CLOSE) {
|
||||
if (p_what == NOTIFICATION_MODAL_CLOSE) {
|
||||
|
||||
cancel_pressed();
|
||||
} else if (p_what==NOTIFICATION_RESIZED) {
|
||||
} else if (p_what == NOTIFICATION_RESIZED) {
|
||||
|
||||
_update_child_rects();
|
||||
}
|
||||
}
|
||||
|
||||
void AcceptDialog::_builtin_text_entered(const String& p_text) {
|
||||
void AcceptDialog::_builtin_text_entered(const String &p_text) {
|
||||
|
||||
_ok_pressed();
|
||||
}
|
||||
@@ -351,7 +336,6 @@ void AcceptDialog::_ok_pressed() {
|
||||
hide();
|
||||
ok_pressed();
|
||||
emit_signal("confirmed");
|
||||
|
||||
}
|
||||
void AcceptDialog::_close_pressed() {
|
||||
|
||||
@@ -371,7 +355,7 @@ void AcceptDialog::set_text(String p_text) {
|
||||
|
||||
void AcceptDialog::set_hide_on_ok(bool p_hide) {
|
||||
|
||||
hide_on_ok=p_hide;
|
||||
hide_on_ok = p_hide;
|
||||
}
|
||||
|
||||
bool AcceptDialog::get_hide_on_ok() const {
|
||||
@@ -379,91 +363,82 @@ bool AcceptDialog::get_hide_on_ok() const {
|
||||
return hide_on_ok;
|
||||
}
|
||||
|
||||
|
||||
void AcceptDialog::register_text_enter(Node *p_line_edit) {
|
||||
|
||||
ERR_FAIL_NULL(p_line_edit);
|
||||
p_line_edit->connect("text_entered", this,"_builtin_text_entered");
|
||||
p_line_edit->connect("text_entered", this, "_builtin_text_entered");
|
||||
}
|
||||
|
||||
void AcceptDialog::_update_child_rects() {
|
||||
|
||||
|
||||
Size2 label_size=label->get_minimum_size();
|
||||
Size2 label_size = label->get_minimum_size();
|
||||
if (label->get_text().empty()) {
|
||||
label_size.height = 0;
|
||||
}
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
Size2 size = get_size();
|
||||
Size2 hminsize = hbc->get_combined_minimum_size();
|
||||
|
||||
Vector2 cpos(margin,margin+label_size.height);
|
||||
Vector2 csize(size.x-margin*2,size.y-margin*3-hminsize.y-label_size.height);
|
||||
Vector2 cpos(margin, margin + label_size.height);
|
||||
Vector2 csize(size.x - margin * 2, size.y - margin * 3 - hminsize.y - label_size.height);
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
if (c==hbc || c==label || c==get_close_button() || c->is_set_as_toplevel())
|
||||
if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
c->set_pos(cpos);
|
||||
c->set_size(csize);
|
||||
|
||||
}
|
||||
|
||||
cpos.y+=csize.y+margin;
|
||||
csize.y=hminsize.y;
|
||||
cpos.y += csize.y + margin;
|
||||
csize.y = hminsize.y;
|
||||
|
||||
hbc->set_pos(cpos);
|
||||
hbc->set_size(csize);
|
||||
|
||||
}
|
||||
|
||||
Size2 AcceptDialog::get_minimum_size() const {
|
||||
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
Size2 minsize = label->get_combined_minimum_size();
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
if (c==hbc || c==label || c==const_cast<AcceptDialog*>(this)->get_close_button() || c->is_set_as_toplevel())
|
||||
if (c == hbc || c == label || c == const_cast<AcceptDialog *>(this)->get_close_button() || c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2 cminsize = c->get_combined_minimum_size();
|
||||
minsize.x=MAX(cminsize.x,minsize.x);
|
||||
minsize.y=MAX(cminsize.y,minsize.y);
|
||||
|
||||
minsize.x = MAX(cminsize.x, minsize.x);
|
||||
minsize.y = MAX(cminsize.y, minsize.y);
|
||||
}
|
||||
|
||||
|
||||
Size2 hminsize = hbc->get_combined_minimum_size();
|
||||
minsize.x = MAX(hminsize.x,minsize.x);
|
||||
minsize.y+=hminsize.y;
|
||||
minsize.x+=margin*2;
|
||||
minsize.y+=margin*3; //one as separation between hbc and child
|
||||
minsize.x = MAX(hminsize.x, minsize.x);
|
||||
minsize.y += hminsize.y;
|
||||
minsize.x += margin * 2;
|
||||
minsize.y += margin * 3; //one as separation between hbc and child
|
||||
|
||||
Size2 wmsize = WindowDialog::get_minimum_size();
|
||||
minsize.x=MAX(wmsize.x,minsize.x);
|
||||
minsize.x = MAX(wmsize.x, minsize.x);
|
||||
return minsize;
|
||||
}
|
||||
|
||||
void AcceptDialog::_custom_action(const String &p_action) {
|
||||
|
||||
void AcceptDialog::_custom_action(const String& p_action) {
|
||||
|
||||
emit_signal("custom_action",p_action);
|
||||
emit_signal("custom_action", p_action);
|
||||
custom_action(p_action);
|
||||
}
|
||||
|
||||
Button* AcceptDialog::add_button(const String& p_text,bool p_right,const String& p_action) {
|
||||
Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) {
|
||||
|
||||
|
||||
Button *button = memnew( Button );
|
||||
Button *button = memnew(Button);
|
||||
button->set_text(p_text);
|
||||
if (p_right) {
|
||||
hbc->add_child(button);
|
||||
@@ -471,98 +446,91 @@ Button* AcceptDialog::add_button(const String& p_text,bool p_right,const String&
|
||||
} else {
|
||||
|
||||
hbc->add_child(button);
|
||||
hbc->move_child(button,0);
|
||||
hbc->move_child(button, 0);
|
||||
hbc->add_spacer(true);
|
||||
}
|
||||
|
||||
if (p_action!="") {
|
||||
button->connect("pressed",this,"_custom_action",varray(p_action));
|
||||
if (p_action != "") {
|
||||
button->connect("pressed", this, "_custom_action", varray(p_action));
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Button* AcceptDialog::add_cancel(const String &p_cancel) {
|
||||
Button *AcceptDialog::add_cancel(const String &p_cancel) {
|
||||
|
||||
String c = p_cancel;
|
||||
if (p_cancel=="")
|
||||
c=RTR("Cancel");
|
||||
Button *b = swap_ok_cancel ? add_button(c,true) : add_button(c);
|
||||
b->connect("pressed",this,"_closed");
|
||||
if (p_cancel == "")
|
||||
c = RTR("Cancel");
|
||||
Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
|
||||
b->connect("pressed", this, "_closed");
|
||||
return b;
|
||||
}
|
||||
|
||||
void AcceptDialog::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_ok"),&AcceptDialog::_ok_pressed);
|
||||
ClassDB::bind_method(D_METHOD("get_ok"),&AcceptDialog::get_ok);
|
||||
ClassDB::bind_method(D_METHOD("get_label"),&AcceptDialog::get_label);
|
||||
ClassDB::bind_method(D_METHOD("set_hide_on_ok","enabled"),&AcceptDialog::set_hide_on_ok);
|
||||
ClassDB::bind_method(D_METHOD("get_hide_on_ok"),&AcceptDialog::get_hide_on_ok);
|
||||
ClassDB::bind_method(D_METHOD("add_button:Button","text","right","action"),&AcceptDialog::add_button,DEFVAL(false),DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("add_cancel:Button","name"),&AcceptDialog::add_cancel);
|
||||
ClassDB::bind_method(D_METHOD("_builtin_text_entered"),&AcceptDialog::_builtin_text_entered);
|
||||
ClassDB::bind_method(D_METHOD("register_text_enter:LineEdit","line_edit"),&AcceptDialog::register_text_enter);
|
||||
ClassDB::bind_method(D_METHOD("_custom_action"),&AcceptDialog::_custom_action);
|
||||
ClassDB::bind_method(D_METHOD("set_text","text"),&AcceptDialog::set_text);
|
||||
ClassDB::bind_method(D_METHOD("get_text"),&AcceptDialog::get_text);
|
||||
ClassDB::bind_method(D_METHOD("_ok"), &AcceptDialog::_ok_pressed);
|
||||
ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok);
|
||||
ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label);
|
||||
ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok);
|
||||
ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok);
|
||||
ClassDB::bind_method(D_METHOD("add_button:Button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("add_cancel:Button", "name"), &AcceptDialog::add_cancel);
|
||||
ClassDB::bind_method(D_METHOD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered);
|
||||
ClassDB::bind_method(D_METHOD("register_text_enter:LineEdit", "line_edit"), &AcceptDialog::register_text_enter);
|
||||
ClassDB::bind_method(D_METHOD("_custom_action"), &AcceptDialog::_custom_action);
|
||||
ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text);
|
||||
ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("confirmed") );
|
||||
ADD_SIGNAL( MethodInfo("custom_action",PropertyInfo(Variant::STRING,"action")) );
|
||||
|
||||
ADD_GROUP("Dialog","dialog");
|
||||
ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"dialog_text",PROPERTY_HINT_MULTILINE_TEXT,"",PROPERTY_USAGE_DEFAULT_INTL),"set_text","get_text");
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "dialog_hide_on_ok"),"set_hide_on_ok","get_hide_on_ok") ;
|
||||
ADD_SIGNAL(MethodInfo("confirmed"));
|
||||
ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING, "action")));
|
||||
|
||||
ADD_GROUP("Dialog", "dialog");
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "dialog_text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog_hide_on_ok"), "set_hide_on_ok", "get_hide_on_ok");
|
||||
}
|
||||
|
||||
|
||||
bool AcceptDialog::swap_ok_cancel=false;
|
||||
bool AcceptDialog::swap_ok_cancel = false;
|
||||
void AcceptDialog::set_swap_ok_cancel(bool p_swap) {
|
||||
|
||||
swap_ok_cancel=p_swap;
|
||||
swap_ok_cancel = p_swap;
|
||||
}
|
||||
|
||||
AcceptDialog::AcceptDialog() {
|
||||
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int button_margin = get_constant("button_margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
int button_margin = get_constant("button_margin", "Dialogs");
|
||||
|
||||
|
||||
label = memnew( Label );
|
||||
label->set_anchor(MARGIN_RIGHT,ANCHOR_END);
|
||||
label->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
|
||||
label->set_begin( Point2( margin, margin) );
|
||||
label->set_end( Point2( margin, button_margin+10) );
|
||||
label = memnew(Label);
|
||||
label->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
||||
label->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
|
||||
label->set_begin(Point2(margin, margin));
|
||||
label->set_end(Point2(margin, button_margin + 10));
|
||||
//label->set_autowrap(true);
|
||||
add_child(label);
|
||||
|
||||
hbc = memnew( HBoxContainer );
|
||||
hbc = memnew(HBoxContainer);
|
||||
add_child(hbc);
|
||||
|
||||
hbc->add_spacer();
|
||||
ok = memnew( Button );
|
||||
ok = memnew(Button);
|
||||
ok->set_text(RTR("OK"));
|
||||
hbc->add_child(ok);
|
||||
hbc->add_spacer();
|
||||
|
||||
|
||||
ok->connect("pressed", this,"_ok");
|
||||
ok->connect("pressed", this, "_ok");
|
||||
set_as_toplevel(true);
|
||||
|
||||
hide_on_ok=true;
|
||||
hide_on_ok = true;
|
||||
set_title(RTR("Alert!"));
|
||||
}
|
||||
|
||||
|
||||
AcceptDialog::~AcceptDialog()
|
||||
{
|
||||
AcceptDialog::~AcceptDialog() {
|
||||
}
|
||||
|
||||
|
||||
void ConfirmationDialog::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_cancel:Button"),&ConfirmationDialog::get_cancel);
|
||||
ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel);
|
||||
}
|
||||
|
||||
Button *ConfirmationDialog::get_cancel() {
|
||||
|
||||
Reference in New Issue
Block a user