1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-30 16:26:50 +00: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:
Rémi Verschelde
2017-03-05 16:44:50 +01:00
parent 45438e9918
commit 5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions

View File

@@ -29,37 +29,33 @@
#include "line_2d_editor_plugin.h"
#include "canvas_item_editor_plugin.h"
#include "os/file_access.h"
#include "editor/editor_settings.h"
#include "os/file_access.h"
#include "os/keyboard.h"
//----------------------------------------------------------------------------
// Line2DEditor
//----------------------------------------------------------------------------
void Line2DEditor::_node_removed(Node *p_node) {
if(p_node == node) {
node=NULL;
if (p_node == node) {
node = NULL;
hide();
}
}
void Line2DEditor::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_VISIBILITY_CHANGED:
// This widget is not a child but should have the same visibility state
base_hb->set_visible(is_visible());
break;
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED:
// This widget is not a child but should have the same visibility state
base_hb->set_visible(is_visible());
break;
}
}
Vector2 Line2DEditor::mouse_to_local_pos(Vector2 gpoint, bool alt) {
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
return !alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint))
: node->get_global_transform().affine_inverse().xform(
canvas_item_editor->snap_point(
canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) );
return !alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
}
int Line2DEditor::get_point_index_at(Vector2 gpos) {
@@ -68,9 +64,9 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) {
real_t grab_treshold = EDITOR_DEF("poly_editor/point_grab_radius", 8);
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
for(int i = 0; i < node->get_point_count(); ++i) {
Point2 p = xform.xform( node->get_point_pos(i) );
if(gpos.distance_to(p) < grab_treshold) {
for (int i = 0; i < node->get_point_count(); ++i) {
Point2 p = xform.xform(node->get_point_pos(i));
if (gpos.distance_to(p) < grab_treshold) {
return i;
}
}
@@ -78,7 +74,7 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) {
return -1;
}
bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
bool Line2DEditor::forward_gui_input(const InputEvent &p_event) {
if (!node)
return false;
@@ -86,25 +82,24 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
if (!node->is_visible())
return false;
switch(p_event.type) {
switch (p_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb = p_event.mouse_button;
Vector2 gpoint = Point2(mb.x,mb.y);
Vector2 gpoint = Point2(mb.x, mb.y);
Vector2 cpoint = mouse_to_local_pos(gpoint, mb.mod.alt);
if(mb.pressed && _dragging == false) {
if (mb.pressed && _dragging == false) {
int i = get_point_index_at(gpoint);
if(i != -1) {
if (i != -1) {
if (mb.button_index == BUTTON_LEFT && !mb.mod.shift && mode == MODE_EDIT) {
_dragging = true;
action_point = i;
moving_from = node->get_point_pos(i);
moving_screen_from = gpoint;
}
else if((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) {
} else if ((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) {
undo_redo->create_action(TTR("Remove Point from Line2D"));
undo_redo->add_do_method(node, "remove_point", i);
undo_redo->add_undo_method(node, "add_point", node->get_point_pos(i), i);
@@ -116,7 +111,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
}
}
if(mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) {
if (mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) {
undo_redo->create_action(TTR("Add Point to Line2D"));
undo_redo->add_do_method(node, "add_point", cpoint);
@@ -126,7 +121,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
undo_redo->commit_action();
_dragging = true;
action_point = node->get_point_count()-1;
action_point = node->get_point_count() - 1;
moving_from = node->get_point_pos(action_point);
moving_screen_from = gpoint;
@@ -135,7 +130,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
return true;
}
if(!mb.pressed && mb.button_index == BUTTON_LEFT && _dragging) {
if (!mb.pressed && mb.button_index == BUTTON_LEFT && _dragging) {
undo_redo->create_action(TTR("Move Point in Line2D"));
undo_redo->add_do_method(node, "set_point_pos", action_point, cpoint);
undo_redo->add_undo_method(node, "set_point_pos", action_point, moving_from);
@@ -145,19 +140,17 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) {
_dragging = false;
return true;
}
}
break;
} break;
case InputEvent::MOUSE_MOTION: {
if (_dragging) {
const InputEventMouseMotion &mm = p_event.mouse_motion;
Vector2 cpoint = mouse_to_local_pos(Vector2(mm.x, mm.y), mm.mod.alt);
node->set_point_pos(action_point,cpoint);
node->set_point_pos(action_point, cpoint);
canvas_item_editor->get_viewport_control()->update();
return true;
}
}
break;
} break;
}
return false;
@@ -178,7 +171,7 @@ void Line2DEditor::_canvas_draw() {
int len = node->get_point_count();
Control *vpc = canvas_item_editor->get_viewport_control();
for(int i=0; i < len; ++i) {
for (int i = 0; i < len; ++i) {
Vector2 point = xform.xform(node->get_point_pos(i));
vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false);
}
@@ -201,8 +194,7 @@ void Line2DEditor::edit(Node *p_line2d) {
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
if (!node->is_connected("visibility_changed", this, "_node_visibility_changed"))
node->connect("visibility_changed", this, "_node_visibility_changed");
}
else {
} else {
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
// node may have been deleted at this point
@@ -219,7 +211,7 @@ void Line2DEditor::_bind_methods() {
}
void Line2DEditor::_mode_selected(int p_mode) {
for(unsigned int i = 0; i < _MODE_COUNT; ++i) {
for (unsigned int i = 0; i < _MODE_COUNT; ++i) {
toolbar_buttons[i]->set_pressed(i == p_mode);
}
mode = Mode(p_mode);
@@ -233,41 +225,37 @@ Line2DEditor::Line2DEditor(EditorNode *p_editor) {
_dragging = false;
base_hb = memnew( HBoxContainer );
base_hb = memnew(HBoxContainer);
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb);
sep = memnew( VSeparator);
sep = memnew(VSeparator);
base_hb->add_child(sep);
{
ToolButton * b = memnew(ToolButton);
ToolButton *b = memnew(ToolButton);
b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons"));
b->set_toggle_mode(true);
b->set_focus_mode(Control::FOCUS_NONE);
b->set_tooltip(
TTR("Select Points")+"\n"
+ TTR("Shift+Drag: Select Control Points")+"\n"
+ keycode_get_string(KEY_MASK_CMD)
+ TTR("Click: Add Point")+"\n"
+ TTR("Right Click: Delete Point"));
TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point"));
b->connect("pressed", this, "_mode_selected", varray(MODE_EDIT));
toolbar_buttons[MODE_EDIT] = b;
base_hb->add_child(b);
}
{
ToolButton * b = memnew(ToolButton);
ToolButton *b = memnew(ToolButton);
b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons"));
b->set_toggle_mode(true);
b->set_focus_mode(Control::FOCUS_NONE);
b->set_tooltip(TTR("Add Point (in empty space)")+"\n"+TTR("Split Segment (in line)"));
b->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in line)"));
b->connect("pressed", this, "_mode_selected", varray(MODE_CREATE));
toolbar_buttons[MODE_CREATE] = b;
base_hb->add_child(b);
}
{
ToolButton * b = memnew( ToolButton );
ToolButton *b = memnew(ToolButton);
b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons"));
b->set_toggle_mode(true);
b->set_focus_mode(Control::FOCUS_NONE);
@@ -297,15 +285,13 @@ bool Line2DEditorPlugin::handles(Object *p_object) const {
void Line2DEditorPlugin::make_visible(bool p_visible) {
line2d_editor->set_visible(p_visible);
if(p_visible == false)
if (p_visible == false)
line2d_editor->edit(NULL);
}
Line2DEditorPlugin::Line2DEditorPlugin(EditorNode *p_node) {
editor=p_node;
line2d_editor = memnew( Line2DEditor(p_node) );
editor = p_node;
line2d_editor = memnew(Line2DEditor(p_node));
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(line2d_editor);
line2d_editor->hide();
}