Class: FXRoom
- Defined in:
- lib/IFMapper/FXRoom.rb,
lib/IFMapper/SVGMapExporter.rb,
lib/IFMapper/PDFMapExporter_prawn.rb,
lib/IFMapper/PDFMapExporter_pdfwriter.rb
Overview
Class used to reprent an IF room
Constant Summary collapse
- @@win =
nil
Constants inherited from Room
Room::DIRECTIONS, Room::DIRECTIONS_ENGLISH, Room::DIR_TO_VECTOR
Instance Attribute Summary collapse
-
#selected ⇒ Object
Returns the value of attribute selected.
-
#xx ⇒ Object
Returns the value of attribute xx.
-
#yy ⇒ Object
Returns the value of attribute yy.
Attributes inherited from Room
#comment, #darkness, #desc, #exits, #name, #objects, #tasks, #x, #y
Class Method Summary collapse
Instance Method Summary collapse
-
#_corner(c, idx) ⇒ Object
Given a connection and/or an exit index, return the x and y offset multipliers needed from the top corner of the box.
- #copy(b) ⇒ Object
-
#corner(c, zoom, idx = nil) ⇒ Object
Given a connection belonging to a room, return draw coordinate of that corner.
-
#draw(dc, zoom, idx, opt, data) ⇒ Object
Main draw function for room.
- #hasComments ⇒ Object
- #hasDescription ⇒ Object
- #hasObjects ⇒ Object
- #hasTasks ⇒ Object
-
#initialize(x, y, *opts) ⇒ FXRoom
constructor
A new instance of FXRoom.
- #marshal_dump ⇒ Object
- #marshal_load(vars) ⇒ Object
-
#modal_properties(map) ⇒ Object
Open a modal requester to change properties.
- #pdf_corner(opts, c, idx = nil) ⇒ Object
-
#pdf_draw(pdf, opts, idx, pdflocationnos) ⇒ Object
PRE: Send through the index so we can print the location number along with boolean value indicating whether the user wants them.
- #pdf_draw_box(pdf, opts, idx, pdflocationnos) ⇒ Object
- #pdf_draw_name(pdf, opts, pdflocationnos) ⇒ Object
- #pdf_draw_objects(pdf, opts, x, y, pdflocationnos) ⇒ Object
- #pdf_draw_text(pdf, opts, x, y, text, font_size, pdflocationnos) ⇒ Object
-
#properties(map, event = nil) ⇒ Object
Open a new requester to change room properties.
- #svg_corner(opts, c, idx = nil) ⇒ Object
- #svg_draw(svg, opts, idx, x, y) ⇒ Object
- #svg_draw_box(svg, opts, idx, sx, sy) ⇒ Object
- #svg_draw_interactive(svg, opts, idx, sx, sy, section_idx) ⇒ Object
- #svg_draw_interactive_objects(group, opts, x, y, font_size, lines) ⇒ Object
- #svg_draw_name(svg, opts, sx, sy, roomname) ⇒ Object
- #svg_draw_objects(svg, opts, x, y) ⇒ Object
- #svg_draw_text(svg, opts, x, y, text, font_size) ⇒ Object
- #update_properties(map) ⇒ Object
-
#x=(v) ⇒ Object
Set a new x position for the room.
-
#y=(v) ⇒ Object
Set a new y position for the room.
Methods inherited from Room
#[], #[]=, #exit_to, #inspect, #next_to?, #num_doors, #num_exits, #to_s, #vector_to_dir, vector_to_dir
Constructor Details
Instance Attribute Details
#selected ⇒ Object
Returns the value of attribute selected.
10 11 12 |
# File 'lib/IFMapper/FXRoom.rb', line 10 def selected @selected end |
#xx ⇒ Object
Returns the value of attribute xx.
9 10 11 |
# File 'lib/IFMapper/FXRoom.rb', line 9 def xx @xx end |
#yy ⇒ Object
Returns the value of attribute yy.
9 10 11 |
# File 'lib/IFMapper/FXRoom.rb', line 9 def yy @yy end |
Class Method Details
.no_maps ⇒ Object
19 20 21 |
# File 'lib/IFMapper/FXRoom.rb', line 19 def self.no_maps @@win.hide if @@win end |
Instance Method Details
#_corner(c, idx) ⇒ Object
Given a connection and/or an exit index, return the x and y offset multipliers needed from the top corner of the box.
110 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 |
# File 'lib/IFMapper/FXRoom.rb', line 110 def _corner(c, idx) idx = @exits.index(c) unless idx raise "corner: #{c} not found in #{self}" unless idx x = y = 0 case idx when 0 x = 0.5 when 1 x = 1 when 2 x = 1 y = 0.5 when 3 x = 1 y = 1 when 4 x = 0.5 y = 1 when 5 y = 1 when 6 y = 0.5 when 7 else raise "error wrong index #{idx}" end return [ x, y ] end |
#copy(b) ⇒ Object
14 15 16 17 |
# File 'lib/IFMapper/FXRoom.rb', line 14 def copy(b) self.selected = b.selected super b end |
#corner(c, zoom, idx = nil) ⇒ Object
Given a connection belonging to a room, return draw coordinate of that corner.
142 143 144 145 146 147 |
# File 'lib/IFMapper/FXRoom.rb', line 142 def corner( c, zoom, idx = nil ) x, y = _corner(c, idx) x = @xx + W * x y = @yy + H * y return [x * zoom, y * zoom] end |
#draw(dc, zoom, idx, opt, data) ⇒ Object
Main draw function for room
153 154 155 156 157 158 159 160 161 |
# File 'lib/IFMapper/FXRoom.rb', line 153 def draw(dc, zoom, idx, opt, data) dc.font = data['objfont'] draw_box(dc, zoom, idx, opt) return if zoom < 0.5 dc.font = data['font'] x, y = draw_name(dc, zoom) dc.font = data['objfont'] draw_objects(dc, zoom, x, y) end |
#hasComments ⇒ Object
499 500 501 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 499 def hasComments() return (@comment and not @comment == '') end |
#hasDescription ⇒ Object
503 504 505 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 503 def hasDescription() return (@desc and not @desc == '') end |
#hasObjects ⇒ Object
495 496 497 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 495 def hasObjects() return (@objects and not @objects == '') end |
#hasTasks ⇒ Object
491 492 493 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 491 def hasTasks() return (@tasks and not @tasks == '') end |
#marshal_dump ⇒ Object
23 24 25 |
# File 'lib/IFMapper/FXRoom.rb', line 23 def marshal_dump super + [ @selected ] end |
#marshal_load(vars) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/IFMapper/FXRoom.rb', line 27 def marshal_load(vars) super(vars) @selected = vars[-1] @xx = x * WW + WS_2 @yy = y * HH + HS_2 end |
#modal_properties(map) ⇒ Object
Open a modal requester to change properties
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/IFMapper/FXRoom.rb', line 71 def modal_properties(map) if @@win and @@win.shown? shown = @@win @@win.hide end win = FXRoomDialogBox.new(map, self, nil, true) win.setFocus win.show win.copy_from(self) if win.execute != 0 win.copy_to() else return false end if shown @@win.show end return true end |
#pdf_corner(opts, c, idx = nil) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 226 def pdf_corner( opts, c, idx = nil ) x, y = _corner(c, idx) y = -y ww = opts['ww'] hh = opts['hh'] w = opts['w'] h = opts['h'] ry = opts['height'] - @y x = @x * ww + opts['ws_2'] + opts['margin_2'] + x * w y = ry * hh + opts['hs_2'] + h + opts['margin_2'] + y * h return [x, y] end |
#pdf_draw(pdf, opts, idx, pdflocationnos) ⇒ Object
PRE: Send through the index so we can print the location number
along with boolean value indicating whether the user wants them
333 334 335 336 337 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 333 def pdf_draw( pdf, opts, idx, pdflocationnos ) pdf_draw_box( pdf, opts, idx, pdflocationnos ) x, y = pdf_draw_name( pdf, opts, pdflocationnos ) pdf_draw_objects(pdf, opts, x, y, pdflocationnos) end |
#pdf_draw_box(pdf, opts, idx, pdflocationnos) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 242 def pdf_draw_box( pdf, opts, idx, pdflocationnos ) x = @x * opts['ww'] + opts['ws_2'] + opts['margin_2'] y = (opts['height'] - @y) * opts['hh'] + opts['hs_2'] + opts['margin_2'] pdf.cap_style = :butt pdf.join_style = :miter pdf.line_width 1 pdf.undash if @darkness pdf.fill_color '808080' pdf.stroke_color '000000' pdf.fill_rectangle [x, y], opts['w'], -opts['h'] else pdf.fill_color 'ffffff' pdf.stroke_color '000000' end pdf.stroke_rectangle [x, y], opts['w'], -opts['h'] if pdflocationnos == 1 # PRE: Draw a rectangle for the location number pdf.stroke_rectangle( [x+opts['w']-opts['w']/4, y], opts['w']/4, -opts['h']/4 ) # PRE: Pad out the number so it is three chars long locationno = (idx+1).to_s if (idx+1) < 10 locationno = ' '+locationno elsif (idx+1) < 100 locationno = ' '+locationno end # PRE: Write the location number pdf.stroke_color '000000' pdf.fill_color '000000' # WAS: y+2 pdf.text_box locationno, :at => [(x+((opts['w']/4)*3)+2), y+7], :size => 8, :width => opts['w']/4, :height => opts['h']/4, :overflow => :shrink_to_fit end end |
#pdf_draw_name(pdf, opts, pdflocationnos) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 319 def pdf_draw_name(pdf, opts, pdflocationnos) # We could also use pdf_corner(7) here x = @x * opts['ww'] + opts['margin_2'] + opts['ws_2'] + 2 y = opts['height'] - @y font_size = 8 y = y * opts['hh'] + opts['margin_2'] + opts['hs_2'] + opts['h'] - (font_size + 2) pdf.stroke_color '000000' pdf.fill_color '000000' return pdf_draw_text( pdf, opts, x, y, @name, font_size, pdflocationnos ) end |
#pdf_draw_objects(pdf, opts, x, y, pdflocationnos) ⇒ Object
311 312 313 314 315 316 317 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 311 def pdf_draw_objects(pdf, opts, x, y, pdflocationnos) font_size = 6 objs = @objects.split("\n") objs = objs.join(', ') return pdf_draw_text( pdf, opts, x, y, objs, font_size, pdflocationnos ) end |
#pdf_draw_text(pdf, opts, x, y, text, font_size, pdflocationnos) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 290 def pdf_draw_text( pdf, opts, x, y, text, font_size, pdflocationnos ) miny = (opts['height'] - @y) * opts['hh'] + opts['hs_2'] + opts['margin_2'] while text != '' # PRE: Wrap the text to avoid the location number box if (y >= miny) and (y <= (miny+font_size)) and (pdflocationnos == 1) wrapwidthmodifier = 15 else wrapwidthmodifier = 2 end text = pdf.text_box text, :at => [x, y+6], :size => font_size, :width => opts['w'] - wrapwidthmodifier, :height => opts['h'], :valign => :top, :align => :left, :overflow => :shrink_to_fit y -= font_size break if y <= miny end return [x, y] end |
#properties(map, event = nil) ⇒ Object
Open a new requester to change room properties
98 99 100 101 102 103 104 |
# File 'lib/IFMapper/FXRoom.rb', line 98 def properties( map, event = nil ) if not @@win @@win = FXRoomDialogBox.new(map, self, event, false) end @@win.show update_properties(map) end |
#svg_corner(opts, c, idx = nil) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 507 def svg_corner( opts, c, idx = nil ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_corner" end x, y = _corner(c, idx) ww = opts['ww'] hh = opts['hh'] w = opts['w'] h = opts['h'] x = @x * ww + x * w + opts['margin'] y = @y * hh + y * h + opts['margin'] return [x, y] end |
#svg_draw(svg, opts, idx, x, y) ⇒ Object
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 813 def svg_draw( svg, opts, idx, x, y ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw" end if (!((opts['draw_connections'] == false) && (@name =~ /#{MSG_SVG_SHORTCUT_TO}.*/i))) svg_draw_box( svg, opts, idx, x, y ) if ((opts['draw_roomnames'] == true) || (opts['current_section_only'] && opts['text_for_selected_only'] && @selected == true) || (@name =~ /#{MSG_SVG_SHORTCUT_TO}.*/i) || (idx == 0)) # Even if we're not printing location names, print the "Shortcut to" # part of any locations which start with that text. This convention of # a room named "Shortcut to <another location>" is for the sole purpose # of allowing additional connections to be collected which are then fwd'd # to the named location, because currently IFMapper can only provide # support for up to eight cardinal / ordinal directions which can be a # problem for large locations. roomname = @name if ((opts['draw_roomnames'] == false) && (@name =~ /(#{MSG_SVG_SHORTCUT_TO}).*/i)) roomname = $1 end x, y = svg_draw_name( svg, opts, x, y, roomname ) end end end |
#svg_draw_box(svg, opts, idx, sx, sy) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 522 def svg_draw_box( svg, opts, idx, sx, sy ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_box" end x = sx + (@x * opts['ww']) + opts['margin'] y = sy + (@y * opts['hh']) + opts['margin'] if DEBUG_OUTPUT; printf("svg::FXRoom::svg_draw_box[x=%s,y=%s,w=%s,h=%s]\r\n", x,y,opts['w'],opts['h']) end roomrect = svg.root.add_element "rect", { "x" => x, "y" => y, "width" => opts['w'], "height" => opts['h'], "style" => sprintf("stroke:%s;stroke-width:%s", opts['room_line_colour'],opts['room_line_width'])} if @darkness if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_box:DARKNESS" end roomrect.attributes["style"] << ";fill:gray" else if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_box:not darkness" end roomrect.attributes["style"] << ";fill:none" end if opts['print_room_nums'] == true # Add the room number to the bottom right hand corner! pad = 2 font_size = 8 numbox_width = (pad*2) + (3*font_size) numbox_height = (pad*2)+font_size numbox_x = (x + opts['w']) - numbox_width numbox_y = (y + opts['h']) - numbox_height numbox_rect = svg.root.add_element "rect", { "x" => numbox_x, "y" => numbox_y, "width" => numbox_width, "height" => numbox_height, "style" => sprintf("stroke:%s;stroke-width:%s;fill:%s", opts['num_line_colour'],opts['num_line_width'],opts['num_fill_colour']) } numtext_x = numbox_x + pad numtext_y = numbox_y + font_size + pad idx += 1 if idx < 100 numtext_x += font_size end if idx < 10 numtext_x += font_size end numtext = svg.root.add_element "text", { "x" => numtext_x, "y" => numtext_y, "style" => "font-size:" + font_size.to_s() + "pt" } numtext.text = idx.to_s() end end |
#svg_draw_interactive(svg, opts, idx, sx, sy, section_idx) ⇒ Object
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 651 def svg_draw_interactive( svg, opts, idx, sx, sy, section_idx ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_interactive" end if (hasObjects() and opts['draw_objects']) or (hasTasks() and opts['draw_tasks']) or (hasComments() and opts['draw_comments']) or (hasDescription() and opts['draw_description']) x = sx + (@x * opts['ww']) + opts['margin'] + opts['w'] y = sy + (@y * opts['hh']) + opts['margin'] x1 = x - opts['corner_size'] y1 = y x2 = x y2 = y + opts['corner_size'] poly = svg.root.add_element "polygon", { "style" => sprintf("stroke:%s;stroke-width:%s;fill:%s", opts['corner_line_colour'],opts['corner_line_width'],opts['corner_fill_colour']), "points" => sprintf("%0.01f,%0.01f %0.01f,%0.01f %0.01f,%0.01f", x, y, x1, y1, x2, y2), "onclick" => "ToggleOpacity(evt, \"section"+section_idx.to_s()+"room"+idx.to_s()+"\")" } objs_font_size = opts['objects_font_size'] num_chars_per_line = ((opts['objects_width'] / (objs_font_size)) * opts['font_width_fiddle']).floor numObjsLines = 0 numTaskLines = 0 numCommLines = 0 numDescLines = 0 if(hasObjects() and opts['draw_objects']) numObjsLines = SVGUtilities::num_text_lines(@objects, num_chars_per_line); end if(hasTasks() and opts['draw_tasks']) numTaskLines = SVGUtilities::num_text_lines(@tasks, num_chars_per_line); end if(hasComments() and opts['draw_comments']) numCommLines = SVGUtilities::num_text_lines(@comment, num_chars_per_line); end if(hasDescription() and opts['draw_description']) numDescLines = SVGUtilities::num_text_lines(@desc, num_chars_per_line); end if(numObjsLines > 0) numObjsLines = numObjsLines + 2 end if(numTaskLines > 0) numTaskLines = numTaskLines + 2 end if(numCommLines > 0) numCommLines = numCommLines + 2 end if(numDescLines > 0) numDescLines = numDescLines + 2 end lines = numObjsLines + numTaskLines + numCommLines + numDescLines objs_height = (lines+1) * (objs_font_size + opts['text_line_spacing']) g = svg.root.add_element "g", { "id" => "section"+section_idx.to_s()+"room"+idx.to_s(), "opacity" => "0" } rect_x = x - opts['objects_width'] - opts['corner_size'] rect_y = y + opts['corner_size'] g.add_element "rect", { "x" => rect_x, "y" => rect_y, "width" => opts['objects_width'], "height" => objs_height, "style" => sprintf("stroke:%s;stroke-width:%s;fill:%s", opts['objs_line_colour'],opts['objs_line_width'],opts['objs_fill_colour']) } text_x = rect_x + opts['text_margin'] text_y = rect_y + opts['text_margin'] + objs_font_size if hasObjects() and opts['draw_objects'] t1 = g.add_element "text", { "x" => text_x, "y" => text_y, "style" => "font-size:" + objs_font_size.to_s() + "pt;font-weight:bold" } t1.text = "Objects:" text_y = text_y + objs_font_size + opts['text_line_spacing'] objs_lines = SVGUtilities::break_text_lines(@objects, num_chars_per_line) text_x, text_y = svg_draw_interactive_objects( g, opts, text_x, text_y, objs_font_size, objs_lines) text_y = text_y + objs_font_size + opts['text_line_spacing'] end if hasTasks() and opts['draw_tasks'] t2 = g.add_element "text", { "x" => text_x, "y" => text_y, "style" => "font-size:" + objs_font_size.to_s() + "pt;font-weight:bold" } t2.text = "Tasks:" text_y = text_y + objs_font_size + opts['text_line_spacing'] tasks_lines = SVGUtilities::break_text_lines(@tasks, num_chars_per_line) text_x, text_y = svg_draw_interactive_objects( g, opts, text_x, text_y, objs_font_size, tasks_lines) text_y = text_y + objs_font_size + opts['text_line_spacing'] end if hasComments() and opts['draw_comments'] t2 = g.add_element "text", { "x" => text_x, "y" => text_y, "style" => "font-size:" + objs_font_size.to_s() + "pt;font-weight:bold" } t2.text = "Comments:" text_y = text_y + objs_font_size + opts['text_line_spacing'] comments_lines = SVGUtilities::break_text_lines(@comment, num_chars_per_line) text_x, text_y = svg_draw_interactive_objects( g, opts, text_x, text_y, objs_font_size, comments_lines) text_y = text_y + objs_font_size + opts['text_line_spacing'] end if hasDescription() and opts['draw_description'] t2 = g.add_element "text", { "x" => text_x, "y" => text_y, "style" => "font-size:" + objs_font_size.to_s() + "pt;font-weight:bold" } t2.text = "Description:" text_y = text_y + objs_font_size + opts['text_line_spacing'] desc_lines = SVGUtilities::break_text_lines(@desc, num_chars_per_line) text_x, text_y = svg_draw_interactive_objects( g, opts, text_x, text_y, objs_font_size, desc_lines) text_y = text_y + objs_font_size + opts['text_line_spacing'] end end end |
#svg_draw_interactive_objects(group, opts, x, y, font_size, lines) ⇒ Object
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 787 def svg_draw_interactive_objects( group, opts, x, y, font_size, lines) if DEBUG_OUTPUT; printf("svg::FXRoom::svg_draw_interactive_objects\r\n") end t = group.add_element "text", { "x" => x, "y" => y, "style" => "font-size:" + font_size.to_s() + "pt"} dy = 0 ypos = 0 lines.each { |obj| ypos = ypos + font_size + opts['text_line_spacing'] tspan = t.add_element "tspan", { "x" => x, "dy" => dy } tspan.text = obj if dy == 0 dy = font_size + opts['text_line_spacing'] end } return [x, y+ypos] end |
#svg_draw_name(svg, opts, sx, sy, roomname) ⇒ Object
640 641 642 643 644 645 646 647 648 649 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 640 def svg_draw_name(svg, opts, sx, sy, roomname) if DEBUG_OUTPUT; printf("svg::FXRoom::svg_draw_name:name=%s\r\n", roomname) end x = sx + (@x * opts['ww']) + opts['margin'] + opts['text_margin'] y = sy + (@y * opts['hh']) + opts['margin'] + opts['text_margin'] font_size = 8 y = y + font_size return svg_draw_text( svg, opts, x, y, roomname, font_size ) end |
#svg_draw_objects(svg, opts, x, y) ⇒ Object
632 633 634 635 636 637 638 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 632 def svg_draw_objects(svg, opts, x, y) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_objects" end font_size = 6 objs = @objects.split("\n") objs = objs.join(', ') return svg_draw_text( svg, opts, x, y, objs, font_size ) end |
#svg_draw_text(svg, opts, x, y, text, font_size) ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 585 def svg_draw_text( svg, opts, x, y, text, font_size ) if DEBUG_OUTPUT; printf("svg::FXRoom::svg_draw_text:text=%s\r\n", text) end t = svg.root.add_element "text", { "x" => x, "y" => y, "style" => "font-size:" + font_size.to_s() + "pt"} max_chars = opts['text_max_chars'] words = text.split(" ") dy = 0 ypos = 0 lasty = opts['h'] - opts['text_margin'] cur_str = "" words.each { |word| new_len = cur_str.length + word.length if DEBUG_OUTPUT; printf("current word: %s :: new_len: %d\r\n", word, new_len) end new_len = cur_str.length + word.length if new_len <= max_chars cur_str = cur_str + word + " " else ypos = ypos + font_size + opts['text_line_spacing'] if ypos >= lasty break end tspan = t.add_element "tspan", { "x" => x, "dy" => dy } tspan.text = cur_str if dy == 0 dy = font_size + opts['text_line_spacing'] end cur_str = "" + word + " " end } if ypos < lasty tspan = t.add_element "tspan", { "x" => x, "dy" => dy } tspan.text = cur_str end return [x, y+ypos] end |
#update_properties(map) ⇒ Object
91 92 93 94 95 |
# File 'lib/IFMapper/FXRoom.rb', line 91 def update_properties(map) return if not @@win or not @@win.shown? @@win.map = map @@win.copy_from(self) end |