diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-02-21 19:34:16 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-02-21 19:34:16 +0200 |
commit | 7385c3602da3dc95bc8bb6fa248c7fcc323f1ac1 (patch) | |
tree | 7067a55e9caaed4620a7f5917e1c7f468f487663 /scene/main | |
parent | c55aa03c436fb40f9a42128397b69872d85fb237 (diff) |
Add RichTextLabel "hint" tag.
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_item.cpp | 20 | ||||
-rw-r--r-- | scene/main/canvas_item.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 26b67b763c..de616f16e8 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -443,6 +443,25 @@ void CanvasItem::item_rect_changed(bool p_size_changed) { emit_signal(SceneStringNames::get_singleton()->item_rect_changed); } +void CanvasItem::draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, real_t p_dash) { + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); + + float length = (p_to - p_from).length(); + if (length < p_dash) { + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width); + return; + } + + Point2 off = p_from; + Vector2 step = p_dash * (p_to - p_from).normalized(); + int steps = length / p_dash / 2; + for (int i = 0; i < steps; i++) { + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, off, (off + step), p_color, p_width); + off += 2 * step; + } + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, off, p_to, p_color, p_width); +} + void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width) { ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); @@ -868,6 +887,7 @@ void CanvasItem::_bind_methods() { //ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform); ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width"), &CanvasItem::draw_line, DEFVAL(1.0)); + ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash"), &CanvasItem::draw_dashed_line, DEFVAL(1.0), DEFVAL(2.0)); ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_arc, DEFVAL(1.0), DEFVAL(false)); diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index c0558b6be2..02fdd63440 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -216,6 +216,7 @@ public: /* DRAWING API */ + void draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = 1.0, real_t p_dash = 2.0); void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = 1.0); void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = 1.0, bool p_antialiased = false); void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = 1.0, bool p_antialiased = false); |