summaryrefslogtreecommitdiff
path: root/scene/2d/line_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/line_2d.cpp')
-rw-r--r--scene/2d/line_2d.cpp105
1 files changed, 51 insertions, 54 deletions
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 059711549f..cd9b8e8cb9 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -30,19 +30,18 @@
#include "core_string_names.h"
-
// Needed so we can bind functions
VARIANT_ENUM_CAST(LineJointMode)
VARIANT_ENUM_CAST(LineCapMode)
VARIANT_ENUM_CAST(LineTextureMode)
-
-Line2D::Line2D() : Node2D() {
+Line2D::Line2D()
+ : Node2D() {
_joint_mode = LINE_JOINT_SHARP;
_begin_cap_mode = LINE_CAP_NONE;
_end_cap_mode = LINE_CAP_NONE;
_width = 10;
- _default_color = Color(0.4,0.5,1);
+ _default_color = Color(0.4, 0.5, 1);
_sharp_limit = 2.f;
_round_precision = 8;
}
@@ -53,7 +52,7 @@ void Line2D::set_points(const PoolVector<Vector2> &p_points) {
}
void Line2D::set_width(float width) {
- if(width < 0.0)
+ if (width < 0.0)
width = 0.0;
_width = width;
update();
@@ -99,17 +98,17 @@ Color Line2D::get_default_color() const {
return _default_color;
}
-void Line2D::set_gradient(const Ref<ColorRamp>& gradient) {
+void Line2D::set_gradient(const Ref<ColorRamp> &gradient) {
// Cleanup previous connection if any
- if(_gradient.is_valid()) {
+ if (_gradient.is_valid()) {
(**_gradient).disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
_gradient = gradient;
// Connect to the gradient so the line will update when the ColorRamp is changed
- if(_gradient.is_valid()) {
+ if (_gradient.is_valid()) {
(**_gradient).connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
@@ -120,7 +119,7 @@ Ref<ColorRamp> Line2D::get_gradient() const {
return _gradient;
}
-void Line2D::set_texture(const Ref<Texture>& texture) {
+void Line2D::set_texture(const Ref<Texture> &texture) {
_texture = texture;
update();
}
@@ -166,15 +165,15 @@ LineCapMode Line2D::get_end_cap_mode() const {
}
void Line2D::_notification(int p_what) {
- switch(p_what) {
- case NOTIFICATION_DRAW:
- _draw();
- break;
+ switch (p_what) {
+ case NOTIFICATION_DRAW:
+ _draw();
+ break;
}
}
void Line2D::set_sharp_limit(float limit) {
- if(limit < 0.f)
+ if (limit < 0.f)
limit = 0.f;
_sharp_limit = limit;
update();
@@ -185,7 +184,7 @@ float Line2D::get_sharp_limit() const {
}
void Line2D::set_round_precision(int precision) {
- if(precision < 1)
+ if (precision < 1)
precision = 1;
_round_precision = precision;
update();
@@ -196,16 +195,17 @@ int Line2D::get_round_precision() const {
}
void Line2D::_draw() {
- if(_points.size() <= 1 || _width == 0.f)
+ if (_points.size() <= 1 || _width == 0.f)
return;
// TODO Is this really needed?
// Copy points for faster access
Vector<Vector2> points;
points.resize(_points.size());
- int len = points.size(); {
+ int len = points.size();
+ {
PoolVector<Vector2>::Read points_read = _points.read();
- for(int i = 0; i < len; ++i) {
+ for (int i = 0; i < len; ++i) {
points[i] = points_read[i];
}
}
@@ -226,36 +226,36 @@ void Line2D::_draw() {
lb.build();
RID texture_rid;
- if(_texture.is_valid())
+ if (_texture.is_valid())
texture_rid = (**_texture).get_rid();
VS::get_singleton()->canvas_item_add_triangle_array(
- get_canvas_item(),
- lb.indices,
- lb.vertices,
- lb.colors,
- lb.uvs,
- texture_rid);
+ get_canvas_item(),
+ lb.indices,
+ lb.vertices,
+ lb.colors,
+ lb.uvs,
+ texture_rid);
// DEBUG
// Draw wireframe
-// if(lb.indices.size() % 3 == 0) {
-// Color col(0,0,0);
-// for(int i = 0; i < lb.indices.size(); i += 3) {
-// int vi = lb.indices[i];
-// int lbvsize = lb.vertices.size();
-// Vector2 a = lb.vertices[lb.indices[i]];
-// Vector2 b = lb.vertices[lb.indices[i+1]];
-// Vector2 c = lb.vertices[lb.indices[i+2]];
-// draw_line(a, b, col);
-// draw_line(b, c, col);
-// draw_line(c, a, col);
-// }
-// for(int i = 0; i < lb.vertices.size(); ++i) {
-// Vector2 p = lb.vertices[i];
-// draw_rect(Rect2(p.x-1, p.y-1, 2, 2), Color(0,0,0,0.5));
-// }
-// }
+ // if(lb.indices.size() % 3 == 0) {
+ // Color col(0,0,0);
+ // for(int i = 0; i < lb.indices.size(); i += 3) {
+ // int vi = lb.indices[i];
+ // int lbvsize = lb.vertices.size();
+ // Vector2 a = lb.vertices[lb.indices[i]];
+ // Vector2 b = lb.vertices[lb.indices[i+1]];
+ // Vector2 c = lb.vertices[lb.indices[i+2]];
+ // draw_line(a, b, col);
+ // draw_line(b, c, col);
+ // draw_line(c, a, col);
+ // }
+ // for(int i = 0; i < lb.vertices.size(); ++i) {
+ // Vector2 p = lb.vertices[i];
+ // draw_rect(Rect2(p.x-1, p.y-1, 2, 2), Color(0,0,0,0.5));
+ // }
+ // }
}
void Line2D::_gradient_changed() {
@@ -265,10 +265,10 @@ void Line2D::_gradient_changed() {
// static
void Line2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_points","points"), &Line2D::set_points);
+ ClassDB::bind_method(D_METHOD("set_points", "points"), &Line2D::set_points);
ClassDB::bind_method(D_METHOD("get_points"), &Line2D::get_points);
- ClassDB::bind_method(D_METHOD("set_point_pos","i", "pos"), &Line2D::set_point_pos);
+ ClassDB::bind_method(D_METHOD("set_point_pos", "i", "pos"), &Line2D::set_point_pos);
ClassDB::bind_method(D_METHOD("get_point_pos", "i"), &Line2D::get_point_pos);
ClassDB::bind_method(D_METHOD("get_point_count"), &Line2D::get_point_count);
@@ -276,7 +276,7 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_point", "pos"), &Line2D::add_point);
ClassDB::bind_method(D_METHOD("remove_point", "i"), &Line2D::remove_point);
- ClassDB::bind_method(D_METHOD("set_width","width"), &Line2D::set_width);
+ ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width);
ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width);
ClassDB::bind_method(D_METHOD("set_default_color", "color"), &Line2D::set_default_color);
@@ -309,12 +309,12 @@ void Line2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_color"), "set_default_color", "get_default_color");
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_gradient", "get_gradient");
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile" ), "set_texture_mode","get_texture_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "joint_mode", PROPERTY_HINT_ENUM, "Sharp,Bevel,Round" ), "set_joint_mode","get_joint_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "begin_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round" ), "set_begin_cap_mode","get_begin_cap_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "end_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round" ), "set_end_cap_mode","get_end_cap_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_gradient", "get_gradient");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile"), "set_texture_mode", "get_texture_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "joint_mode", PROPERTY_HINT_ENUM, "Sharp,Bevel,Round"), "set_joint_mode", "get_joint_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "begin_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_begin_cap_mode", "get_begin_cap_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "end_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_end_cap_mode", "get_end_cap_mode");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharp_limit"), "set_sharp_limit", "get_sharp_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision");
@@ -330,7 +330,4 @@ void Line2D::_bind_methods() {
BIND_CONSTANT(LINE_TEXTURE_TILE);
ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed);
-
}
-
-