└── addons └── linepath2d ├── icon.svg ├── linepath2d.gd ├── linepath2d.gd.uid ├── plugin.cfg ├── plugin.gd └── plugin.gd.uid /addons/linepath2d/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /addons/linepath2d/linepath2d.gd: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Claudio Z. (cloudofoz) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | @tool 22 | extends Path2D 23 | 24 | #--------------------------------------------------------------------------------------------------- 25 | # CONSTANTS 26 | #--------------------------------------------------------------------------------------------------- 27 | 28 | # Enable the creation of a default curve when this class is instantiated 29 | const LP_CREATE_DEFAULT_CURVE = true 30 | 31 | # Enable the creation of a default curve width profile when this class is instatiated 32 | const LP_CREATE_DEFAULT_PROFILE = true 33 | 34 | # Size in pixels of the default curve 35 | const LP_DEFAULT_CURVE_SIZE = 400 36 | 37 | # Size in pixels of the default curve width 38 | const LP_DEFAULT_CURVE_WIDTH = 25 39 | 40 | #--------------------------------------------------------------------------------------------------- 41 | # PRIVATE VARIABLES 42 | #--------------------------------------------------------------------------------------------------- 43 | 44 | var lp_line: Line2D = null 45 | 46 | #--------------------------------------------------------------------------------------------------- 47 | # PUBLIC VARIABLES 48 | #--------------------------------------------------------------------------------------------------- 49 | 50 | @export_category("LinePath2D") 51 | 52 | ## Sets the Path2D 'Curve2D' resource 53 | ## 54 | ## Note: Please, use this variable to change the curve and not the original Path2D property 55 | ## Reason: It's not currently possible to override the parent setter: 56 | ## 'Path2D.set_curve(value)'. 57 | ## Reference: https://github.com/godotengine/godot-proposals/issues/8045 58 | @export var _curve: Curve2D = null: 59 | set(value): 60 | if(curve && curve.changed.is_connected(lp_build_line)): 61 | curve.changed.disconnect(lp_build_line) 62 | curve = value 63 | if(curve): 64 | curve.changed.connect(lp_build_line) 65 | lp_build_line() 66 | get: 67 | return curve 68 | 69 | ## Sets the width of the curve 70 | @export var width: float = LP_DEFAULT_CURVE_WIDTH: 71 | set(value): 72 | if(!lp_line): return 73 | lp_line.width = value 74 | #lp_line.draw.emit() 75 | get: 76 | return lp_line.width if lp_line else LP_DEFAULT_CURVE_WIDTH 77 | 78 | ## Use this [Curve] to modify the line width profile 79 | @export var width_profile: Curve: 80 | set(value): 81 | if(!lp_line): return 82 | lp_line.width_curve = value 83 | #lp_line.draw.emit() 84 | get: 85 | return lp_line.width_curve if lp_line else null 86 | 87 | 88 | @export_group("Fill", "fill_") 89 | 90 | ## Default path color 91 | @export var fill_default_color: Color = Color.WHITE: 92 | set(value): 93 | if(lp_line): lp_line.default_color = value 94 | get: 95 | return lp_line.default_color if lp_line else Color.WHITE 96 | 97 | ## Fill the path with a gradient 98 | @export var fill_gradient: Gradient = null: 99 | set(value): 100 | if(lp_line): lp_line.gradient = value 101 | get: 102 | return lp_line.gradient if lp_line else null 103 | 104 | ## Fill the path with a texture 105 | @export var fill_texture: Texture2D = null: 106 | set(value): 107 | if(lp_line): lp_line.texture = value 108 | get: 109 | return lp_line.texture if lp_line else null 110 | 111 | ## Change the texture fill mode 112 | @export_enum("None: 0", "Tile: 1", "Stretch: 2") 113 | var fill_texture_mode: int = Line2D.LINE_TEXTURE_NONE: 114 | set(value): 115 | if(lp_line): lp_line.texture_mode = value 116 | get: 117 | return lp_line.texture_mode if lp_line else Line2D.LINE_TEXTURE_NONE 118 | 119 | ## Sets the material (CanvasMaterial2D or ShaderMaterial) 120 | #@export var fill_material: Material = null: 121 | #set(value): 122 | #if(!lp_line): return 123 | #if(!(value is CanvasItemMaterial) && !(value is ShaderMaterial)): 124 | #lp_line.material = null 125 | #return 126 | #lp_line.material = value 127 | #get: 128 | #return lp_line.material if lp_line else null 129 | 130 | 131 | @export_group("Capping", "cap_") 132 | 133 | ## The style of connection between segments of the polyline 134 | @export_enum("Sharp: 0", "Bevel: 1", "Round: 2") 135 | var cap_joint_mode: int = Line2D.LINE_JOINT_SHARP: 136 | set(value): 137 | if(lp_line): lp_line.joint_mode = value 138 | get: 139 | return lp_line.joint_mode if lp_line else 0 140 | 141 | ## The style of the beginning of the polyline 142 | @export_enum("None: 0", "Box: 1", "Round: 2") 143 | var cap_begin_cap: int = Line2D.LINE_CAP_NONE: 144 | set(value): 145 | if(lp_line): lp_line.begin_cap_mode = value 146 | get: 147 | return lp_line.begin_cap_mode if lp_line else Line2D.LINE_CAP_NONE 148 | 149 | ## The style of the ending of the polyline 150 | @export_enum("None: 0", "Box: 1", "Round: 2") 151 | var cap_end_cap: int = Line2D.LINE_CAP_NONE: 152 | set(value): 153 | if(lp_line): lp_line.end_cap_mode = value 154 | get: 155 | return lp_line.end_cap_mode if lp_line else Line2D.LINE_CAP_NONE 156 | 157 | ## If true and the polyline has more than two segments, 158 | ## the first and the last point will be connected by a segment 159 | @export var cap_close_curve: bool = false: 160 | set(value): 161 | if(lp_line): lp_line.closed = value 162 | get: 163 | return lp_line.closed if lp_line else false 164 | 165 | 166 | @export_group("Border", "border_") 167 | 168 | ## Determines the miter limit of the polyline 169 | @export var border_sharp_limit: float = 2.0: 170 | set(value): 171 | if(lp_line): lp_line.sharp_limit = value 172 | get: 173 | return lp_line.sharp_limit if lp_line else 2.0 174 | 175 | ## The smoothness of the rounded joints and caps 176 | @export var border_round_precision: int = 8: 177 | set(value): 178 | if(lp_line): lp_line.round_precision = value 179 | get: 180 | return lp_line.round_precision if lp_line else 8 181 | 182 | ## If true the polyline border will be antialiased 183 | ## Note: Antialiased polylines are not accelerated by batching 184 | @export var border_antialiased: bool = false: 185 | set(value): 186 | if(lp_line): lp_line.antialiased = value 187 | get: 188 | return lp_line.antialiased if lp_line else false 189 | 190 | #--------------------------------------------------------------------------------------------------- 191 | # VIRTUAL METHODS 192 | #--------------------------------------------------------------------------------------------------- 193 | 194 | func _init() -> void: 195 | if(!lp_line): 196 | lp_line = Line2D.new() 197 | 198 | func _ready() -> void: 199 | lp_clear_duplicated_internal_children() 200 | lp_line.set_meta("__lp2d_internal__", true) 201 | add_child(lp_line) 202 | if(!curve || curve.point_count < 2): 203 | curve = lp_create_default_curve(LP_DEFAULT_CURVE_SIZE) 204 | if(!lp_line.width_curve): 205 | lp_line.width_curve = lp_create_default_profile(LP_DEFAULT_CURVE_WIDTH) 206 | lp_build_line() 207 | if(curve && !curve.changed.is_connected(lp_build_line)): 208 | curve.changed.connect(lp_build_line) 209 | 210 | #--------------------------------------------------------------------------------------------------- 211 | # PRIVATE METHODS 212 | #--------------------------------------------------------------------------------------------------- 213 | 214 | func lp_create_default_curve(size:int) -> Curve2D: 215 | if(!LP_CREATE_DEFAULT_CURVE): return null 216 | var c = Curve2D.new() 217 | c.add_point(Vector2.ZERO, Vector2.ZERO, Vector2(size,0)) 218 | c.add_point(Vector2(size,size), Vector2(-size,0), Vector2.ZERO) 219 | return c 220 | 221 | func lp_create_default_profile(size:float) -> Curve: 222 | if(!LP_CREATE_DEFAULT_PROFILE): return null 223 | var c = Curve.new() 224 | c.add_point(Vector2.ZERO) 225 | c.add_point(Vector2(0.5,1)) 226 | c.add_point(Vector2(1.0, 0)) 227 | return c 228 | 229 | func lp_build_line() -> void: 230 | if(!lp_line): 231 | return 232 | if(!curve || curve.point_count < 2): 233 | lp_line.clear_points() 234 | return 235 | lp_line.points = curve.get_baked_points() 236 | 237 | func lp_clear_duplicated_internal_children(): 238 | for c in get_children(): 239 | if(c.get_meta("__lp2d_internal__", false)): 240 | c.queue_free() 241 | 242 | 243 | #--------------------------------------------------------------------------------------------------- 244 | # KNOWN BUGS/LIMITATIONS: 245 | # 246 | # *) Changing the 'Path2D.curve' in the editor will result in an unexpected behaviour 247 | # TO-FIX: Overriding the default setter 'Path2D.set_curve(value)', it's not currently possible. 248 | # PROPOSAL: https://github.com/godotengine/godot-proposals/issues/8045 249 | -------------------------------------------------------------------------------- /addons/linepath2d/linepath2d.gd.uid: -------------------------------------------------------------------------------- 1 | uid://cpe28ltvm5it4 2 | -------------------------------------------------------------------------------- /addons/linepath2d/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="LinePath2D" 4 | description="This simple Godot addon brings the 'Line2D' drawing capabilities to 'Path2D' curves." 5 | author="cloudofoz" 6 | version="0.10" 7 | script="plugin.gd" 8 | -------------------------------------------------------------------------------- /addons/linepath2d/plugin.gd: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Claudio Z. (cloudofoz) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | @tool 22 | extends EditorPlugin 23 | 24 | 25 | func _enter_tree() -> void: 26 | ## This simple addon brings the 'Line2D' drawing capabilities to 'Path2D' curves. 27 | add_custom_type("LinePath2D", "Path2D", preload("linepath2d.gd"), preload("icon.svg")) 28 | 29 | 30 | func _exit_tree() -> void: 31 | remove_custom_type("LinePath2D") 32 | -------------------------------------------------------------------------------- /addons/linepath2d/plugin.gd.uid: -------------------------------------------------------------------------------- 1 | uid://ivbm16hkft42 2 | --------------------------------------------------------------------------------