Class: FXRoom
- Defined in:
- lib/IFMapper/FXRoom.rb,
lib/IFMapper/PDFMapExporter.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.
-
#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) ⇒ 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
21 22 23 |
# File 'lib/IFMapper/FXRoom.rb', line 21 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.
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 |
# File 'lib/IFMapper/FXRoom.rb', line 112 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 18 19 |
# File 'lib/IFMapper/FXRoom.rb', line 14 def copy(b) self.xx = b.xx self.yy = b.yy 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.
144 145 146 147 148 149 |
# File 'lib/IFMapper/FXRoom.rb', line 144 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
155 156 157 158 159 160 161 162 163 |
# File 'lib/IFMapper/FXRoom.rb', line 155 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 |
#marshal_dump ⇒ Object
25 26 27 |
# File 'lib/IFMapper/FXRoom.rb', line 25 def marshal_dump super + [ @selected ] end |
#marshal_load(vars) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/IFMapper/FXRoom.rb', line 29 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/IFMapper/FXRoom.rb', line 73 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
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 225 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
313 314 315 316 317 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 313 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
241 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 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 241 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'] s = PDF::Writer::StrokeStyle::DEFAULT pdf.stroke_style( s ) if @darkness pdf.fill_color( Color::RGB::Gray ) else pdf.fill_color( Color::RGB::White ) end pdf.rectangle(x, y, opts['w'], opts['h']).fill_stroke if pdflocationnos == 1 # PRE: Draw a rectangle for the location number pdf.rectangle((x+opts['w']-opts['w']/4), y, opts['w']/4, opts['h']/4).fill_stroke # 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.fill_color(Color::RGB::Black) pdf.add_text((x+((opts['w']/4)*3)+2), y+2, locationno, 8) end end |
#pdf_draw_name(pdf, opts, pdflocationnos) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 299 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(Color::RGB::Black) pdf.fill_color(Color::RGB::Black) return pdf_draw_text( pdf, opts, x, y, @name, font_size, pdflocationnos ) end |
#pdf_draw_objects(pdf, opts, x, y, pdflocationnos) ⇒ Object
292 293 294 295 296 297 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 292 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
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 275 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.add_text_wrap(x, y, opts['w'] - wrapwidthmodifier, text, font_size) 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
100 101 102 103 104 105 106 |
# File 'lib/IFMapper/FXRoom.rb', line 100 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
416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 416 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
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 698 def svg_draw( svg, opts, idx, x, y ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw" end if (!((opts['draw_connections'] == false) && (@name =~ /Shortcut to.*/i))) svg_draw_box( svg, opts, idx, x, y ) if ((opts['draw_roomnames'] == true) || (@name =~ /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. if ((opts['draw_roomnames'] == false) && (@name =~ /(Shortcut to).*/i)) @name = $1 end x, y = svg_draw_name( svg, opts, x, y ) end end end |
#svg_draw_box(svg, opts, idx, sx, sy) ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 431 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 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+1).to_s() end end |
#svg_draw_interactive(svg, opts, idx, sx, sy, section_idx) ⇒ Object
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 584 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 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 558 def svg_draw_interactive( svg, opts, idx, sx, sy, section_idx ) if DEBUG_OUTPUT; puts "svg::FXRoom::svg_draw_interactive" end if (@objects and not @objects == '') or (@tasks and not @tasks == '') or (@comment and not @comment == '') 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) numObjsLines = 0 numTaskLines = 0 numCommLines = 0 if(@objects) numObjsLines = SVGUtilities::num_text_lines(@objects, num_chars_per_line); end if(@tasks) numTaskLines = SVGUtilities::num_text_lines(@tasks, num_chars_per_line); end if(@comment) numCommLines = SVGUtilities::num_text_lines(@comment, 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 lines = numObjsLines + numTaskLines + numCommLines 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, "z-index" => "1", "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 @objects and not @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 @tasks and not @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 @comment and not @comment == '' 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 end end |
#svg_draw_interactive_objects(group, opts, x, y, font_size, lines) ⇒ Object
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 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 672 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) ⇒ Object
547 548 549 550 551 552 553 554 555 556 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 547 def svg_draw_name(svg, opts, sx, sy) if DEBUG_OUTPUT; printf("svg::FXRoom::svg_draw_name:name=%s\r\n", @name) 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, @name, font_size ) end |
#svg_draw_objects(svg, opts, x, y) ⇒ Object
539 540 541 542 543 544 545 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 539 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
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 492 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
93 94 95 96 97 |
# File 'lib/IFMapper/FXRoom.rb', line 93 def update_properties(map) return if not @@win or not @@win.shown? @@win.map = map @@win.copy_from(self) end |