-- A new piece that takes care of the special functionality of a design portal piece. -- Design portal pieces must indicate to the user not only their status as selected or -- unselected, but also their status as selcted for linking and unselected for linking. class V_DESIGN_PORTAL inherit V_DESIGN_PIECE rename set_special_bitmaps as set_link_bitmaps undefine vacate redefine on_left_button_down, make, highlight, unhighlight, on_paint, on_right_button_down, set_link_bitmaps select cell end DESIGN_PORTAL rename cell as cell_dp redefine set_link_id end WEL_TA_CONSTANTS creation make feature --ensure that we only create a portal piece here. make( s : STRING ; vdr : V_DESIGN_ROOM ; pp : V_PALETTE_PIECE ; c : V_DESIGN_CELL ; is_fg : BOOLEAN ) is -- Make myself a V_DESIGN_PIECE with name `s', parent `vdr', palette piece `pp' and put me in cell `c'. do Precursor ( s, vdr, pp, c, is_fg ) !!text_color.make_rgb (10, 10, 100) end set_link_bitmaps( ln, lh : WEL_BITMAP ) is -- Receive my normal and highlighted link bitmaps, normally immediately after creation. do link_normal := ln link_highlighted := lh end -- Handle a shift-left click on a portal piece here. on_left_button_down( keys, x_pos, y_pos : INTEGER ) is -- Call room's `sselect' feature. do if keys /= Mk_shift + Mk_lbutton then room.sselect( Current ) else room.sselect_for_linking (Current) end end -- Either the portal is leaving with its link -- or just the link is going. on_right_button_down( keys, x_pos, y_pos : INTEGER ) is -- delete piece or delete link, depending upon shift key state. do room.try_to_delete_link(Current, TRUE) -- No shift with the right button. Remove the piece also. if keys /= Mk_shift + Mk_rbutton then Precursor (0, x_pos, y_pos) end end -- redefined for extra functionality of portals highlight is -- Show myself off. require else has_bitmaps: link_highlighted /= Void has_bitmaps: highlighted /= Void do if is_sel_for_link then bitmap := link_highlighted else bitmap := highlighted end invalidate end unhighlight is -- Return to normal. require else has_bitmaps: link_normal /= Void has_bitmaps: normal /= Void do if is_sel_for_link then bitmap := link_normal else bitmap := normal end invalidate end -- Design portals also have "link numbers on them" on_paint (paint_dc: WEL_PAINT_DC; invalid_rect: WEL_RECT) is -- Draw my bitmap do paint_dc.draw_bitmap (bitmap, 0, 0, width, height ) if link_id /= 0 then paint_dc.set_text_alignment (Ta_left) paint_dc.set_text_color (text_color) paint_dc.set_background_opaque paint_dc.text_out (0, 0 , link_id.out ) end end -- Changing the link number need to force a re-paint set_link_id (i : INTEGER) is do {DESIGN_PORTAL} Precursor (i) invalidate end feature {NONE} text_color : WEL_COLOR_REF end -- class V_DESIGN_PIECE_PORTAL