summaryrefslogtreecommitdiffstats
path: root/editor/plugins/collision_shape_2d_editor_plugin.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /editor/plugins/collision_shape_2d_editor_plugin.cpp
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadredot-engine-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz
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
Diffstat (limited to 'editor/plugins/collision_shape_2d_editor_plugin.cpp')
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp222
1 files changed, 110 insertions, 112 deletions
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index a05eeb7a27..3538878877 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -29,23 +29,23 @@
#include "collision_shape_2d_editor_plugin.h"
#include "canvas_item_editor_plugin.h"
-#include "scene/resources/segment_shape_2d.h"
-#include "scene/resources/shape_line_2d.h"
-#include "scene/resources/circle_shape_2d.h"
-#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/capsule_shape_2d.h"
-#include "scene/resources/convex_polygon_shape_2d.h"
+#include "scene/resources/circle_shape_2d.h"
#include "scene/resources/concave_polygon_shape_2d.h"
+#include "scene/resources/convex_polygon_shape_2d.h"
+#include "scene/resources/rectangle_shape_2d.h"
+#include "scene/resources/segment_shape_2d.h"
+#include "scene/resources/shape_line_2d.h"
Variant CollisionShape2DEditor::get_handle_value(int idx) const {
- switch ( shape_type ) {
+ switch (shape_type) {
case CAPSULE_SHAPE: {
Ref<CapsuleShape2D> capsule = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
return capsule->get_radius();
- } else if (idx==1) {
+ } else if (idx == 1) {
return capsule->get_height();
}
@@ -54,7 +54,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
case CIRCLE_SHAPE: {
Ref<CircleShape2D> circle = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
return circle->get_radius();
}
@@ -71,7 +71,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
case LINE_SHAPE: {
Ref<LineShape2D> line = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
return line->get_d();
} else {
return line->get_normal();
@@ -82,7 +82,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
case RAY_SHAPE: {
Ref<RayShape2D> ray = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
return ray->get_length();
}
@@ -91,7 +91,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
case RECTANGLE_SHAPE: {
Ref<RectangleShape2D> rect = node->get_shape();
- if (idx<2) {
+ if (idx < 2) {
return rect->get_extents().abs();
}
@@ -100,9 +100,9 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
case SEGMENT_SHAPE: {
Ref<SegmentShape2D> seg = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
return seg->get_a();
- } else if (idx==1) {
+ } else if (idx == 1) {
return seg->get_b();
}
@@ -112,19 +112,19 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
return Variant();
}
-void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
+void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) {
- switch ( shape_type ) {
+ switch (shape_type) {
case CAPSULE_SHAPE: {
if (idx < 2) {
Ref<CapsuleShape2D> capsule = node->get_shape();
real_t parameter = Math::abs(p_point[idx]);
- if (idx==0) {
+ if (idx == 0) {
capsule->set_radius(parameter);
- } else if (idx==1){
- capsule->set_height(parameter*2 - capsule->get_radius()*2);
+ } else if (idx == 1) {
+ capsule->set_height(parameter * 2 - capsule->get_radius() * 2);
}
canvas_item_editor->get_viewport_control()->update();
@@ -149,19 +149,18 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
} break;
case LINE_SHAPE: {
- if (idx<2) {
+ if (idx < 2) {
Ref<LineShape2D> line = node->get_shape();
- if (idx==0){
+ if (idx == 0) {
line->set_d(p_point.length());
- }else{
+ } else {
line->set_normal(p_point.normalized());
}
canvas_item_editor->get_viewport_control()->update();
}
-
} break;
case RAY_SHAPE: {
@@ -174,7 +173,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
} break;
case RECTANGLE_SHAPE: {
- if (idx<2) {
+ if (idx < 2) {
Ref<RectangleShape2D> rect = node->get_shape();
Vector2 extents = rect->get_extents();
@@ -191,9 +190,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
if (edit_handle < 2) {
Ref<SegmentShape2D> seg = node->get_shape();
- if (idx==0) {
+ if (idx == 0) {
seg->set_a(p_point);
- } else if (idx==1) {
+ } else if (idx == 1) {
seg->set_b(p_point);
}
@@ -204,25 +203,25 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
}
}
-void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
+void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
- Control* c = canvas_item_editor->get_viewport_control();
+ Control *c = canvas_item_editor->get_viewport_control();
undo_redo->create_action(TTR("Set Handle"));
- switch ( shape_type ) {
+ switch (shape_type) {
case CAPSULE_SHAPE: {
Ref<CapsuleShape2D> capsule = node->get_shape();
- if (idx==0) {
- undo_redo->add_do_method(capsule.ptr(),"set_radius",capsule->get_radius());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(capsule.ptr(),"set_radius",p_org);
- undo_redo->add_do_method(c,"update");
- } else if (idx==1) {
- undo_redo->add_do_method(capsule.ptr(),"set_height",capsule->get_height());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(capsule.ptr(),"set_height",p_org);
- undo_redo->add_undo_method(c,"update");
+ if (idx == 0) {
+ undo_redo->add_do_method(capsule.ptr(), "set_radius", capsule->get_radius());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(capsule.ptr(), "set_radius", p_org);
+ undo_redo->add_do_method(c, "update");
+ } else if (idx == 1) {
+ undo_redo->add_do_method(capsule.ptr(), "set_height", capsule->get_height());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(capsule.ptr(), "set_height", p_org);
+ undo_redo->add_undo_method(c, "update");
}
} break;
@@ -230,10 +229,10 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
case CIRCLE_SHAPE: {
Ref<CircleShape2D> circle = node->get_shape();
- undo_redo->add_do_method(circle.ptr(),"set_radius",circle->get_radius());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(circle.ptr(),"set_radius",p_org);
- undo_redo->add_undo_method(c,"update");
+ undo_redo->add_do_method(circle.ptr(), "set_radius", circle->get_radius());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(circle.ptr(), "set_radius", p_org);
+ undo_redo->add_undo_method(c, "update");
} break;
@@ -248,16 +247,16 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
case LINE_SHAPE: {
Ref<LineShape2D> line = node->get_shape();
- if (idx==0) {
- undo_redo->add_do_method(line.ptr(),"set_d",line->get_d());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(line.ptr(),"set_d",p_org);
- undo_redo->add_undo_method(c,"update");
+ if (idx == 0) {
+ undo_redo->add_do_method(line.ptr(), "set_d", line->get_d());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(line.ptr(), "set_d", p_org);
+ undo_redo->add_undo_method(c, "update");
} else {
- undo_redo->add_do_method(line.ptr(),"set_normal",line->get_normal());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(line.ptr(),"set_normal",p_org);
- undo_redo->add_undo_method(c,"update");
+ undo_redo->add_do_method(line.ptr(), "set_normal", line->get_normal());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(line.ptr(), "set_normal", p_org);
+ undo_redo->add_undo_method(c, "update");
}
} break;
@@ -265,35 +264,35 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
case RAY_SHAPE: {
Ref<RayShape2D> ray = node->get_shape();
- undo_redo->add_do_method(ray.ptr(),"set_length",ray->get_length());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(ray.ptr(),"set_length",p_org);
- undo_redo->add_undo_method(c,"update");
+ undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(ray.ptr(), "set_length", p_org);
+ undo_redo->add_undo_method(c, "update");
} break;
case RECTANGLE_SHAPE: {
Ref<RectangleShape2D> rect = node->get_shape();
- undo_redo->add_do_method(rect.ptr(),"set_extents",rect->get_extents());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(rect.ptr(),"set_extents",p_org);
- undo_redo->add_undo_method(c,"update");
+ undo_redo->add_do_method(rect.ptr(), "set_extents", rect->get_extents());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(rect.ptr(), "set_extents", p_org);
+ undo_redo->add_undo_method(c, "update");
} break;
case SEGMENT_SHAPE: {
Ref<SegmentShape2D> seg = node->get_shape();
- if (idx==0) {
- undo_redo->add_do_method(seg.ptr(),"set_a",seg->get_a());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(seg.ptr(),"set_a",p_org);
- undo_redo->add_undo_method(c,"update");
- } else if (idx==1) {
- undo_redo->add_do_method(seg.ptr(),"set_b",seg->get_b());
- undo_redo->add_do_method(c,"update");
- undo_redo->add_undo_method(seg.ptr(),"set_b",p_org);
- undo_redo->add_undo_method(c,"update");
+ if (idx == 0) {
+ undo_redo->add_do_method(seg.ptr(), "set_a", seg->get_a());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(seg.ptr(), "set_a", p_org);
+ undo_redo->add_undo_method(c, "update");
+ } else if (idx == 1) {
+ undo_redo->add_do_method(seg.ptr(), "set_b", seg->get_b());
+ undo_redo->add_do_method(c, "update");
+ undo_redo->add_undo_method(seg.ptr(), "set_b", p_org);
+ undo_redo->add_undo_method(c, "update");
}
} break;
@@ -302,7 +301,7 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
undo_redo->commit_action();
}
-bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) {
+bool CollisionShape2DEditor::forward_gui_input(const InputEvent &p_event) {
if (!node) {
return false;
@@ -316,13 +315,13 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) {
return false;
}
- switch( p_event.type ) {
+ switch (p_event.type) {
case InputEvent::MOUSE_BUTTON: {
- const InputEventMouseButton& mb = p_event.mouse_button;
+ const InputEventMouseButton &mb = p_event.mouse_button;
Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Point2 gpoint(mb.x,mb.y);
+ Point2 gpoint(mb.x, mb.y);
if (mb.button_index == BUTTON_LEFT) {
if (mb.pressed) {
@@ -334,7 +333,7 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) {
}
}
- if (edit_handle==-1) {
+ if (edit_handle == -1) {
pressed = false;
return false;
@@ -362,13 +361,13 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) {
} break;
case InputEvent::MOUSE_MOTION: {
- const InputEventMouseMotion& mm = p_event.mouse_motion;
+ const InputEventMouseMotion &mm = p_event.mouse_motion;
if (edit_handle == -1 || !pressed) {
return false;
}
- Point2 gpoint = Point2(mm.x,mm.y);
+ Point2 gpoint = Point2(mm.x, mm.y);
Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint = canvas_item_editor->snap_point(cpoint);
cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
@@ -437,8 +436,8 @@ void CollisionShape2DEditor::_canvas_draw() {
Control *c = canvas_item_editor->get_viewport_control();
Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Ref<Texture> h = get_icon("EditorHandle","EditorIcons");
- Vector2 size = h->get_size()*0.5;
+ Ref<Texture> h = get_icon("EditorHandle", "EditorIcons");
+ Vector2 size = h->get_size() * 0.5;
handles.clear();
@@ -448,13 +447,13 @@ void CollisionShape2DEditor::_canvas_draw() {
handles.resize(2);
float radius = shape->get_radius();
- float height = shape->get_height()/2;
+ float height = shape->get_height() / 2;
handles[0] = Point2(radius, -height);
- handles[1] = Point2(0,-(height + radius));
+ handles[1] = Point2(0, -(height + radius));
- c->draw_texture(h, gt.xform(handles[0])-size);
- c->draw_texture(h, gt.xform(handles[1])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
+ c->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@@ -462,9 +461,9 @@ void CollisionShape2DEditor::_canvas_draw() {
Ref<CircleShape2D> shape = node->get_shape();
handles.resize(1);
- handles[0] = Point2(shape->get_radius(),0);
+ handles[0] = Point2(shape->get_radius(), 0);
- c->draw_texture(h, gt.xform(handles[0])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
} break;
@@ -483,8 +482,8 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = shape->get_normal() * shape->get_d();
handles[1] = shape->get_normal() * (shape->get_d() + 30.0);
- c->draw_texture(h,gt.xform(handles[0])-size);
- c->draw_texture(h,gt.xform(handles[1])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
+ c->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@@ -492,9 +491,9 @@ void CollisionShape2DEditor::_canvas_draw() {
Ref<RayShape2D> shape = node->get_shape();
handles.resize(1);
- handles[0] = Point2(0,shape->get_length());
+ handles[0] = Point2(0, shape->get_length());
- c->draw_texture(h,gt.xform(handles[0])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
} break;
@@ -503,11 +502,11 @@ void CollisionShape2DEditor::_canvas_draw() {
handles.resize(2);
Vector2 ext = shape->get_extents();
- handles[0] = Point2(ext.x,0);
- handles[1] = Point2(0,-ext.y);
+ handles[0] = Point2(ext.x, 0);
+ handles[1] = Point2(0, -ext.y);
- c->draw_texture(h,gt.xform(handles[0])-size);
- c->draw_texture(h,gt.xform(handles[1])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
+ c->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@@ -518,24 +517,24 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = shape->get_a();
handles[1] = shape->get_b();
- c->draw_texture(h, gt.xform(handles[0])-size);
- c->draw_texture(h, gt.xform(handles[1])-size);
+ c->draw_texture(h, gt.xform(handles[0]) - size);
+ c->draw_texture(h, gt.xform(handles[1]) - size);
} break;
}
}
-void CollisionShape2DEditor::edit(Node* p_node) {
+void CollisionShape2DEditor::edit(Node *p_node) {
if (!canvas_item_editor) {
- canvas_item_editor=CanvasItemEditor::get_singleton();
+ canvas_item_editor = CanvasItemEditor::get_singleton();
}
if (p_node) {
- node=p_node->cast_to<CollisionShape2D>();
+ node = p_node->cast_to<CollisionShape2D>();
- if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw"))
- canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw");
+ if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
+ canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
_get_current_shape_type();
@@ -543,10 +542,10 @@ void CollisionShape2DEditor::edit(Node* p_node) {
edit_handle = -1;
shape_type = -1;
- if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw"))
- canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw");
+ 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=NULL;
+ node = NULL;
}
canvas_item_editor->get_viewport_control()->update();
@@ -554,11 +553,11 @@ void CollisionShape2DEditor::edit(Node* p_node) {
void CollisionShape2DEditor::_bind_methods() {
- ClassDB::bind_method("_canvas_draw",&CollisionShape2DEditor::_canvas_draw);
- ClassDB::bind_method("_get_current_shape_type",&CollisionShape2DEditor::_get_current_shape_type);
+ ClassDB::bind_method("_canvas_draw", &CollisionShape2DEditor::_canvas_draw);
+ ClassDB::bind_method("_get_current_shape_type", &CollisionShape2DEditor::_get_current_shape_type);
}
-CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) {
+CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) {
node = NULL;
canvas_item_editor = NULL;
@@ -570,12 +569,12 @@ CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) {
pressed = false;
}
-void CollisionShape2DEditorPlugin::edit(Object* p_obj) {
+void CollisionShape2DEditorPlugin::edit(Object *p_obj) {
collision_shape_2d_editor->edit(p_obj->cast_to<Node>());
}
-bool CollisionShape2DEditorPlugin::handles(Object* p_obj) const {
+bool CollisionShape2DEditorPlugin::handles(Object *p_obj) const {
return p_obj->is_class("CollisionShape2D");
}
@@ -587,14 +586,13 @@ void CollisionShape2DEditorPlugin::make_visible(bool visible) {
}
}
-CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode* p_node) {
+CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode *p_node) {
- editor=p_node;
+ editor = p_node;
- collision_shape_2d_editor = memnew( CollisionShape2DEditor(p_node) );
+ collision_shape_2d_editor = memnew(CollisionShape2DEditor(p_node));
p_node->get_gui_base()->add_child(collision_shape_2d_editor);
}
CollisionShape2DEditorPlugin::~CollisionShape2DEditorPlugin() {
-
}