lib/wx/shapes/shapes/bitmap_shape.rb in wxruby3-shapes-0.9.0.pre.beta.3 vs lib/wx/shapes/shapes/bitmap_shape.rb in wxruby3-shapes-0.9.5

- old
+ new

@@ -11,36 +11,26 @@ # from XPM image. class BitmapShape < RectShape property :can_scale, :bitmap - # @overload initialize() - # Default constructor. - # @overload initialize(pos, bmp_path, diagram) - # User constructor. - # @param [Wx::RealPoint] pos Initial position - # @param [String] bmp_path Bitmap path - # @param [Wx::SF::Diagram] diagram parent diagram - def initialize(*args) + # Constructor. + # @param [Wx::RealPoint,Wx::Point] pos Initial position + # @param [String] bmp_path Bitmap path + # @param [Wx::SF::Diagram] diagram parent diagram + def initialize(pos = Shape::DEFAULT::POSITION, bmp_path = nil, diagram: nil) + super(pos, diagram: diagram) @bitmap = Wx::NULL_BITMAP @art_path = @art_section = nil - if args.empty? - super - @bitmap_path = nil - @original_bitmap = @bitmap = nil - @bitmap_type = nil - else - pos, bmp_path, diagram = args - super(pos, RectShape::DEFAULT::SIZE.dup, diagram) - create_from_file(bmp_path) - end + @bitmap_path = bmp_path + create_from_file(bmp_path) if bmp_path @rescale_in_progress = false @can_scale = true end - # Get full name of a source BMP file. - # @return [String] String containing full file name + # Get full name of a source BMP file (if set). + # @return [String,nil] String containing full file name def get_bitmap_path @bitmap_path end # Enable/disable scaling mode of the bitmap. @@ -78,11 +68,20 @@ if path @bitmap = Wx::Bitmap.new success = @bitmap.load_file(path, type ? type : Wx::BITMAP_TYPE_ANY) if success p = Pathname.new(art_path) - @art_path = p.relative? ? art_path : p.relative_path_from(Dir.getwd).to_s + if Wx::PLATFORM == 'WXMSW' + # take possibility of different drive into account + @art_path = if p.relative? || art_path[0] != Dir.getwd[0] + art_path + else + p.relative_path_from(Dir.getwd).to_s + end + else + @art_path = p.relative? ? art_path : p.relative_path_from(Dir.getwd).to_s + end @art_section = art_section end else @bitmap = nil success = false @@ -141,11 +140,11 @@ # Handle action at handle drag beginning def do_begin_handle if @can_scale @rescale_in_progress = true - @prev_pos = get_absolute_position + @prev_pos = get_absolute_position.dup end end # Scale the rectangle size for this shape. # @param [Float] x Horizontal scale factor @@ -195,11 +194,11 @@ # @param [Wx::DC] dc Reference to device context where the shape will be drawn to def draw_hover(dc) _draw_bitmap(dc, get_absolute_position.to_point) dc.with_brush(Wx::TRANSPARENT_BRUSH) do - dc.with_pen(Wx::Pen.new(@hover_color, 1)) do + dc.with_pen(Wx::Pen.new(hover_colour, 1)) do dc.draw_rectangle(get_absolute_position.to_point, @rect_size.to_size) end end end @@ -208,10 +207,10 @@ # @param [Wx::DC] dc Reference to device context where the shape will be drawn to def draw_highlighted(dc) _draw_bitmap(dc, get_absolute_position.to_point) dc.with_brush(Wx::TRANSPARENT_BRUSH) do - dc.with_pen(Wx::Pen.new(@hover_color, 2)) do + dc.with_pen(Wx::Pen.new(hover_colour, 2)) do dc.draw_rectangle(get_absolute_position.to_point, @rect_size.to_size) end end end