1 /*************************************************************************/ 2 /* line_builder.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #ifndef LINE_BUILDER_H 32 #define LINE_BUILDER_H 33 34 #include "core/color.h" 35 #include "core/math/vector2.h" 36 #include "line_2d.h" 37 #include "scene/resources/gradient.h" 38 39 class LineBuilder { 40 public: 41 // TODO Move in a struct and reference it 42 // Input 43 Vector<Vector2> points; 44 Line2D::LineJointMode joint_mode; 45 Line2D::LineCapMode begin_cap_mode; 46 Line2D::LineCapMode end_cap_mode; 47 float width; 48 Curve *curve; 49 Color default_color; 50 Gradient *gradient; 51 Line2D::LineTextureMode texture_mode; 52 float sharp_limit; 53 int round_precision; 54 float tile_aspect; // w/h 55 // TODO offset_joints option (offers alternative implementation of round joints) 56 57 // TODO Move in a struct and reference it 58 // Output 59 Vector<Vector2> vertices; 60 Vector<Color> colors; 61 Vector<Vector2> uvs; 62 Vector<int> indices; 63 64 LineBuilder(); 65 66 void build(); 67 void clear_output(); 68 69 private: 70 enum Orientation { 71 UP = 0, 72 DOWN = 1 73 }; 74 75 // Triangle-strip methods 76 void strip_begin(Vector2 up, Vector2 down, Color color, float uvx); 77 void strip_new_quad(Vector2 up, Vector2 down, Color color, float uvx); 78 void strip_add_quad(Vector2 up, Vector2 down, Color color, float uvx); 79 void strip_add_tri(Vector2 up, Orientation orientation); 80 void strip_add_arc(Vector2 center, float angle_delta, Orientation orientation); 81 82 void new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Color color, Rect2 uv_rect); 83 84 private: 85 bool _interpolate_color; 86 int _last_index[2]; // Index of last up and down vertices of the strip 87 }; 88 89 #endif // LINE_BUILDER_H 90