Class: FXConnection
- Inherits:
-
Connection
- Object
- Connection
- FXConnection
- Defined in:
- lib/IFMapper/PDFMapExporter.rb,
lib/IFMapper/FXConnection.rb,
lib/IFMapper/SVGMapExporter.rb,
lib/IFMapper/PDFMapExporter_prawn.rb,
lib/IFMapper/PDFMapExporter_pdfwriter.rb
Overview
Open all the map class and add all pdf methods there Gotta love Ruby’s flexibility to just inject in new methods.
Constant Summary collapse
- @@win =
nil
Constants inherited from Connection
Connection::AtoB, Connection::BOTH, Connection::BtoA, Connection::CLOSED_DOOR, Connection::EXIT_TEXT, Connection::FREE, Connection::LOCKED_DOOR, Connection::SPECIAL
Instance Attribute Summary collapse
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#gpts ⇒ Object
Returns the value of attribute gpts.
-
#pts ⇒ Object
Returns the value of attribute pts.
-
#selected ⇒ Object
Returns the value of attribute selected.
Attributes inherited from Connection
Class Method Summary collapse
Instance Method Summary collapse
- #_cvt_pt(p, opts) ⇒ Object
-
#complex? ⇒ Boolean
Is this a complex path.
-
#draw(dc, zoom, opt) ⇒ Object
Main draw function.
- #flip ⇒ Object
-
#initialize(roomA, roomB, dir = Connection::BOTH, type = Connection::FREE) ⇒ FXConnection
constructor
A new instance of FXConnection.
- #marshal_dump ⇒ Object
- #marshal_load(vars) ⇒ Object
- #pdf_draw(pdf, opts) ⇒ Object
- #pdf_draw_arrow(pdf, opts, x1, y1, x2, y2) ⇒ Object
- #pdf_draw_complex(pdf, opts) ⇒ Object
- #pdf_draw_complex_as_bspline(pdf, opts) ⇒ Object
-
#pdf_draw_complex_as_lines(pdf, opts) ⇒ Object
PRE: If it’s a loop exit that comes back to the same place, let’s move it up and right.
- #pdf_draw_door(pdf, x1, y1, x2, y2) ⇒ Object
- #pdf_draw_exit_text(pdf, opts) ⇒ Object
- #pdf_draw_simple(pdf, opts) ⇒ Object
-
#pdf_draw_text(pdf, x, y, dir, text, arrow) ⇒ Object
Draw the connection text next to the arrow (‘I’, ‘O’, etc).
- #properties(map, event = nil) ⇒ Object
- #svg_draw(svg, opts, x, y) ⇒ Object
- #svg_draw_arrow(svg, opts, x1, y1, x2, y2) ⇒ Object
- #svg_draw_complex(svg, opts, sx, sy) ⇒ Object
- #svg_draw_complex_as_bspline(svg, opts) ⇒ Object
- #svg_draw_complex_as_lines(svg, opts) ⇒ Object
- #svg_draw_door(svg, x1, y1, x2, y2, opts) ⇒ Object
- #svg_draw_exit_text(pdf, opts, sx, sy) ⇒ Object
- #svg_draw_simple(svg, opts, sx, sy) ⇒ Object
-
#svg_draw_text(svg, x, y, dir, text, arrow) ⇒ Object
Draw the connection text next to the arrow (‘I’, ‘O’, etc).
-
#toggle_direction ⇒ Object
Change direction of connection.
- #update_properties(map) ⇒ Object
Methods inherited from Connection
#dirs, #door?, #exitAtext, #exitAtext=, #exitBtext, #exitBtext=, #index, #loop?, #opposite, #roomA, #roomA=, #roomB, #roomB=, #stub?, #to_s
Constructor Details
#initialize(roomA, roomB, dir = Connection::BOTH, type = Connection::FREE) ⇒ FXConnection
Returns a new instance of FXConnection.
45 46 47 48 49 50 |
# File 'lib/IFMapper/FXConnection.rb', line 45 def initialize( roomA, roomB, dir = Connection::BOTH, type = Connection::FREE ) super( roomA, roomB, dir, type ) @selected = @failed = false @pts = @gpts = [] end |
Instance Attribute Details
#failed ⇒ Object
Returns the value of attribute failed.
36 37 38 |
# File 'lib/IFMapper/FXConnection.rb', line 36 def failed @failed end |
#gpts ⇒ Object
Returns the value of attribute gpts.
37 38 39 |
# File 'lib/IFMapper/FXConnection.rb', line 37 def gpts @gpts end |
#pts ⇒ Object
Returns the value of attribute pts.
37 38 39 |
# File 'lib/IFMapper/FXConnection.rb', line 37 def pts @pts end |
#selected ⇒ Object
Returns the value of attribute selected.
35 36 37 |
# File 'lib/IFMapper/FXConnection.rb', line 35 def selected @selected end |
Class Method Details
.no_maps ⇒ Object
41 42 43 |
# File 'lib/IFMapper/FXConnection.rb', line 41 def self.no_maps @@win.hide if @@win end |
Instance Method Details
#_cvt_pt(p, opts) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 30 def _cvt_pt(p, opts) x = (p[0] - WW / 2.0) / WW.to_f y = (p[1] - HH / 2.0) / HH.to_f x = x * opts['ww'] + opts['ws_2'] + opts['margin_2'] + opts['w'] / 2.0 y = (opts['height'] - y) * opts['hh'] + opts['hs_2'] + opts['margin_2'] + opts['hs'] return [x, y] end |
#complex? ⇒ Boolean
Is this a complex path. Check if connection is contiguous
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/IFMapper/FXConnection.rb', line 95 def complex?() return false if not @room[1] return true if @room[1] == @room[0] return true unless @room[0].next_to?(@room[1]) # Even if rooms are next to each other, we need to # verify that following the exits does indeed take us to next room. exitA = @room[0].exits.index(self) dir = Room::DIR_TO_VECTOR[exitA] if @room[0].x + dir[0] == @room[1].x and @room[0].y + dir[1] == @room[1].y exitB = @room[1].exits.rindex(self) dir = Room::DIR_TO_VECTOR[exitB] if @room[1].x + dir[0] == @room[0].x and @room[1].y + dir[1] == @room[0].y return false else return true end else return true end end |
#draw(dc, zoom, opt) ⇒ Object
Main draw function
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/IFMapper/FXConnection.rb', line 123 def draw(dc, zoom, opt) if @selected if @failed dc.foreground = 'cyan' else dc.foreground = 'yellow' end elsif @failed dc.foreground = 'red' else dc.foreground = opt['Arrow Color'] end draw_exit_text(dc, zoom) if @type == SPECIAL dc.lineStyle = LINE_ONOFF_DASH else dc.lineStyle = LINE_SOLID end if pts.size > 0 draw_complex(dc, zoom, opt) else draw_simple(dc, zoom) end end |
#flip ⇒ Object
63 64 65 66 67 68 |
# File 'lib/IFMapper/FXConnection.rb', line 63 def flip super pts.reverse! gpts.reverse! @@win.copy_from(self) if @@win end |
#marshal_dump ⇒ Object
59 60 61 |
# File 'lib/IFMapper/FXConnection.rb', line 59 def marshal_dump [ @selected ] + super end |
#marshal_load(vars) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/IFMapper/FXConnection.rb', line 52 def marshal_load(vars) @pts = @gpts = [] @selected = vars.shift @failed = false super(vars) end |
#pdf_draw(pdf, opts) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 199 def pdf_draw(pdf, opts) pdf_draw_exit_text(pdf, opts) if @type == SPECIAL s = PDF::Writer::StrokeStyle.new(2, :dash => { :pattern => [2], :phase => [1] } ) else s = PDF::Writer::StrokeStyle.new(2, :cap => :butt, :join => :miter, :dash => PDF::Writer::StrokeStyle::SOLID_LINE ) end pdf.stroke_style( s ) pdf.stroke_color Color::RGB::Black pdf.fill_color Color::RGB::Black if @pts.size > 0 pdf_draw_complex(pdf, opts) else pdf_draw_simple(pdf, opts) end end |
#pdf_draw_arrow(pdf, opts, x1, y1, x2, y2) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 38 def pdf_draw_arrow(pdf, opts, x1, y1, x2, y2) return if @dir == BOTH pt1, d = _arrow_info( x1, y1, x2, y2, 0.5 ) p = [] p << PDF::Writer::PolygonPoint.new( pt1[0], pt1[1] ) p << PDF::Writer::PolygonPoint.new( pt1[0] + d[0], pt1[1] - d[1] ) p << PDF::Writer::PolygonPoint.new( pt1[0] + d[1], pt1[1] + d[0] ) pdf.fill_color Color::RGB::Black pdf.polygon(p).fill end |
#pdf_draw_complex(pdf, opts) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 111 def pdf_draw_complex( pdf, opts ) if opts['Paths as Curves'] if @room[0] == @room[1] dirA, dirB = dirs if dirA == dirB p = pdf_draw_complex_as_lines( pdf, opts ) else p = pdf_draw_complex_as_bspline( pdf, opts ) end else p = pdf_draw_complex_as_bspline( pdf, opts ) end else p = pdf_draw_complex_as_lines( pdf, opts ) end pdf.move_to( p[0][0], p[0][1] ) p.each { |pt| pdf.line_to( pt[0], pt[1] ) } pdf.stroke x1, y1 = [p[0][0], p[0][1]] x2, y2 = [p[-1][0], p[-1][1]] pdf_draw_arrow(pdf, opts, x1, y1, x2, y2) if @type == LOCKED_DOOR or @type == CLOSED_DOOR t = p.size / 2 x1, y1 = [ p[t][0], p[t][1] ] x2, y2 = [ p[t-2][0], p[t-2][1] ] pdf_draw_door(pdf, x1, y1, x2, y2) end end |
#pdf_draw_complex_as_bspline(pdf, opts) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 51 def pdf_draw_complex_as_bspline( pdf, opts ) p = [] p << _cvt_pt(@pts[0], opts) p << p[0] p << p[0] @pts.each { |pt| p << _cvt_pt(pt, opts) } p << p[-1] p << p[-1] p << p[-1] return FXSpline::bspline(p) end |
#pdf_draw_complex_as_lines(pdf, opts) ⇒ Object
PRE: If it’s a loop exit that comes back to the same place, let’s move
it up and right
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 67 def pdf_draw_complex_as_lines( pdf, opts ) p = [] maxy = opts['height'] * opts['hh'] + opts['hs_2'] + opts['margin_2'] @pts.each { |pt| if loop? == true p << [ pt[0] * PDF_ZOOM + 10, maxy - pt[1] * PDF_ZOOM + 48 ] else p << [ pt[0] * PDF_ZOOM, maxy - pt[1] * PDF_ZOOM ] end } return p end |
#pdf_draw_door(pdf, x1, y1, x2, y2) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 80 def pdf_draw_door( pdf, x1, y1, x2, y2 ) v = [ (x2-x1), (y2-y1) ] t = 10 / Math.sqrt(v[0]*v[0]+v[1]*v[1]) v = [ v[0]*t, v[1]*t ] m = [ (x2+x1)/2, (y2+y1)/2 ] x1, y1 = [m[0] + v[1], m[1] - v[0]] x2, y2 = [m[0] - v[1], m[1] + v[0]] if @type == LOCKED_DOOR pdf.move_to(x1, y1) pdf.line_to(x2, y2).stroke else s = PDF::Writer::StrokeStyle.new(1, :cap => :butt, :join => :miter, :dash => PDF::Writer::StrokeStyle::SOLID_LINE ) pdf.stroke_style(s) v = [ v[0] / 3, v[1] / 3] pdf.move_to(x1 - v[0], y1 - v[1]) pdf.line_to(x1 + v[0], y1 + v[1]) pdf.line_to(x2 + v[0], y2 + v[1]) pdf.line_to(x2 - v[0], y2 - v[1]) pdf.line_to(x1 - v[0], y1 - v[1]) pdf.stroke s = PDF::Writer::StrokeStyle.new(2, :cap => :butt, :join => :miter, :dash => PDF::Writer::StrokeStyle::SOLID_LINE ) pdf.stroke_style(s) end end |
#pdf_draw_exit_text(pdf, opts) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 182 def pdf_draw_exit_text(pdf, opts) if @exitText[0] != 0 dir = @room[0].exits.index(self) x, y = @room[0].pdf_corner(opts, self, dir) pdf_draw_text( pdf, x, y, dir, EXIT_TEXT[@exitText[0]], @dir == BtoA) end if @exitText[1] != 0 dir = @room[1].exits.rindex(self) x, y = @room[1].pdf_corner(opts, self, dir) pdf_draw_text( pdf, x, y, dir, EXIT_TEXT[@exitText[1]], @dir == AtoB) end end |
#pdf_draw_simple(pdf, opts) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 142 def pdf_draw_simple(pdf, opts) return if not @room[1] # PDF does not print unfinished complex connections dir = @room[0].exits.index(self) x1, y1 = @room[0].pdf_corner(opts, self, dir) x2, y2 = @room[1].pdf_corner(opts, self) pdf.move_to(x1, y1) pdf.line_to(x2, y2).stroke pdf_draw_arrow(pdf, opts, x1, y1, x2, y2) if @type == LOCKED_DOOR or @type == CLOSED_DOOR pdf_draw_door(pdf, x1, y1, x2, y2) end end |
#pdf_draw_text(pdf, x, y, dir, text, arrow) ⇒ Object
Draw the connection text next to the arrow (‘I’, ‘O’, etc)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 159 def pdf_draw_text(pdf, x, y, dir, text, arrow) if dir == 7 or dir < 6 and dir != 1 if arrow and (dir == 0 or dir == 4) x += 5 end x += 2.5 elsif dir == 6 or dir == 1 x -= 7.5 end if dir > 5 or dir < 4 if arrow and (dir == 6 or dir == 2) y += 5 end y += 2.5 elsif dir == 4 or dir == 5 y -= 7.5 end font_size = 8 pdf.add_text(x, y, text, font_size) end |
#properties(map, event = nil) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/IFMapper/FXConnection.rb', line 156 def properties(map, event = nil) if not @@win @@win = FXConnectionDialogBox.new(map, self, event) end @@win.show update_properties(map) end |
#svg_draw(svg, opts, x, y) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 398 def svg_draw(svg, opts, x, y) if DEBUG_OUTPUT; printf("svg::FXConnection::svg_draw:draw_connections=%s\r\n", opts['draw_connections'].to_s()) end if opts['draw_connections'] == true if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw" end svg_draw_exit_text(svg, opts, x, y) if @pts.size > 0 svg_draw_complex(svg, opts, x, y) else svg_draw_simple(svg, opts, x, y) end end end |
#svg_draw_arrow(svg, opts, x1, y1, x2, y2) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 186 def svg_draw_arrow(svg, opts, x1, y1, x2, y2) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_arrow:#{x1},#{y1},#{x2},#{y2}" end return if @dir == BOTH pt1, d = _arrow_info( x1, y1, x2, y2, 0.5 ) if DEBUG_OUTPUT; printf("svg::FXConnection::svg_draw_arrow: pt1[0]=%0.01f,pt1[1]=%0.01f,d[0]=%0.01f,d[1]=%0.01f\r\n", pt1[0], pt1[1], d[0], d[1]) end mx = pt1[0]; my = pt1[1]; if DEBUG_OUTPUT; printf("svg::FXConnection::svg_draw_arrow: mx=%0.01f,my=%0.01f\r\n",mx,my) end lx1 = pt1[0] + d[0] ly1 = pt1[1] + d[1] if DEBUG_OUTPUT; printf("svg::FXConnection::svg_draw_arrow: lx1=%0.01f,ly1=%0.01f\r\n",lx1,ly1) end lx2 = pt1[0] + d[1] ly2 = pt1[1] - d[0] if DEBUG_OUTPUT; printf("svg::FXConnection::svg_draw_arrow: lx2=%0.01f,ly2=%0.01f\r\n",lx2,ly2) end points = sprintf("%0.01f", mx) + "," + sprintf("%0.01f", my) + " " points << sprintf("%0.01f", lx1) + "," + sprintf("%0.01f", ly1) + " " points << sprintf("%0.01f", lx2) + "," + sprintf("%0.01f", ly2) + " " svg.root.add_element "polygon", { "style" => sprintf("stroke:%s;stroke-width:%s;fill:%s",opts['arrow_line_colour'],opts['arrow_line_width'],opts['arrow_fill_colour']), "points" => points } end |
#svg_draw_complex(svg, opts, sx, sy) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 266 def svg_draw_complex( svg, opts, sx ,sy ) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_complex" end if opts['Paths as Curves'] if @room[0] == @room[1] dirA, dirB = dirs if dirA == dirB p = svg_draw_complex_as_lines( svg, opts ) else p = svg_draw_complex_as_bspline( svg, opts ) end else p = svg_draw_complex_as_bspline( svg, opts ) end else p = svg_draw_complex_as_lines( svg, opts ) end p.each { |pt| pt[0] = pt[0] + sx pt[1] = pt[1] + sy } d = "M" + sprintf("%0.01f", p[0][0]) + "," + sprintf("%0.01f", p[0][1]) + " " p.each { |pt| d = d + "L" + sprintf("%0.01f", pt[0]) + "," + sprintf("%0.01f", pt[1]) + " " } path = svg.root.add_element "path", { "style" => sprintf("stroke:%s;stroke-width:%s;fill:none",opts['conn_line_colour'],opts['conn_line_width']), "d" => d } if @type == SPECIAL path.attributes["style"] << ";stroke-dasharray:9,5" end x1, y1 = [p[0][0], p[0][1]] x2, y2 = [p[-1][0], p[-1][1]] svg_draw_arrow(svg, opts, x1, y1, x2, y2) if @type == LOCKED_DOOR or @type == CLOSED_DOOR t = p.size / 2 x1, y1 = [ p[t][0], p[t][1] ] x2, y2 = [ p[t-2][0], p[t-2][1] ] svg_draw_door(svg, x1, y1, x2, y2, opts) end end |
#svg_draw_complex_as_bspline(svg, opts) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 219 def svg_draw_complex_as_bspline( svg, opts ) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_complex_as_bspline" end p = [] p << _cvt_pt(@pts[0], opts) p << p[0] p << p[0] @pts.each { |pt| p << _cvt_pt(pt, opts) } p << p[-1] p << p[-1] p << p[-1] return FXSpline::bspline(p) end |
#svg_draw_complex_as_lines(svg, opts) ⇒ Object
234 235 236 237 238 239 240 241 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 234 def svg_draw_complex_as_lines( svg, opts ) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_complex_as_lines" end p = [] @pts.each { |pt| p << _cvt_pt(pt, opts) } return p end |
#svg_draw_door(svg, x1, y1, x2, y2, opts) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 243 def svg_draw_door( svg, x1, y1, x2, y2 , opts) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_arrow:#{x1},#{y1},#{x2},#{y2}" end v = [ (x2-x1), (y2-y1) ] t = 10 / Math.sqrt(v[0]*v[0]+v[1]*v[1]) v = [ v[0]*t, v[1]*t ] m = [ (x2+x1)/2, (y2+y1)/2 ] x1, y1 = [m[0] + v[1], m[1] - v[0]] x2, y2 = [m[0] - v[1], m[1] + v[0]] v = [ v[0] / 3, v[1] / 3] poly = svg.root.add_element "polygon", { "style" => sprintf("stroke:%s;stroke-width:%s", opts['door_line_colour'],opts['door_line_width']), "points" => sprintf("%0.01f,%0.01f %0.01f,%0.01f %0.01f,%0.01f %0.01f,%0.01f", x1-v[0], y1-v[1], x1+v[0], y1+v[1], x2+v[0], y2+v[1], x2-v[0], y2-v[1]) } if @type == LOCKED_DOOR poly.attributes["style"] << sprintf(";fill:%s", opts['door_line_colour']) else poly.attributes["style"] << ";fill:none" end end |
#svg_draw_exit_text(pdf, opts, sx, sy) ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 377 def svg_draw_exit_text(pdf, opts, sx, sy) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_exit_text" end if @exitText[0] != 0 dir = @room[0].exits.index(self) x, y = @room[0].svg_corner(opts, self, dir) x = x + sx y = y + sy svg_draw_text( pdf, x, y, dir, EXIT_TEXT[@exitText[0]], @dir == BtoA) end if @exitText[1] != 0 dir = @room[1].exits.rindex(self) x, y = @room[1].svg_corner(opts, self, dir) x = x + sx y = y + sy svg_draw_text( pdf, x, y, dir, EXIT_TEXT[@exitText[1]], @dir == AtoB) end end |
#svg_draw_simple(svg, opts, sx, sy) ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 314 def svg_draw_simple(svg, opts, sx, sy) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_simple" end return if not @room[1] dir = @room[0].exits.index(self) x1, y1 = @room[0].svg_corner(opts, self, dir) x2, y2 = @room[1].svg_corner(opts, self) x1 = x1 + sx; x2 = x2 + sx; y1 = y1 + sy; y2 = y2 + sy; line = svg.root.add_element "line", { "x1" => x1, "y1" => y1, "x2" => x2, "y2" => y2, "style" => sprintf("stroke:%s;stroke-width:%s", opts['conn_line_colour'],opts['conn_line_width']) } if @type == SPECIAL line.attributes["style"] << ";stroke-dasharray:9,5" end svg_draw_arrow(svg, opts, x1, y1, x2, y2) if @type == LOCKED_DOOR or @type == CLOSED_DOOR svg_draw_door(svg, x1, y1, x2, y2, opts) end end |
#svg_draw_text(svg, x, y, dir, text, arrow) ⇒ Object
Draw the connection text next to the arrow (‘I’, ‘O’, etc)
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 347 def svg_draw_text(svg, x, y, dir, text, arrow) if DEBUG_OUTPUT; puts "svg::FXConnection::svg_draw_text:#{x},#{y},#{text}" end if dir == 7 or dir < 6 and dir != 1 if arrow and (dir == 0 or dir == 4) x += 5 end x += 2.5 elsif dir == 6 or dir == 1 x -= 7.5 end if dir > 5 or dir < 4 if arrow and (dir == 6 or dir == 2) y -= 5 end y -= 2.5 elsif dir == 4 or dir == 5 y += 7.5 end font_size = 6 t = svg.root.add_element "text", { "x" => x, "y" => y, "style" => "font-size:" + font_size.to_s() + "pt"} t.text = text; end |
#toggle_direction ⇒ Object
Change direction of connection
82 83 84 85 86 87 88 89 |
# File 'lib/IFMapper/FXConnection.rb', line 82 def toggle_direction # If a self-loop, we cannot change dir return if @room[0] == @room[1] and @room[0].exits.index(self) == @room[0].exits.rindex(self) @dir ^= 1 @@win.copy_from(self) if @@win end |
#update_properties(map) ⇒ Object
150 151 152 153 154 |
# File 'lib/IFMapper/FXConnection.rb', line 150 def update_properties(map) return if not @@win or not @@win.shown? @@win.map = map @@win.copy_from(self) end |