Class: Wx::MemoryDC

Inherits:
DC show all
Defined in:
lib/wx/doc/gen/memory_dc.rb,
lib/wx/doc/memory_dc.rb

Overview

Note:

This class is untracked and should not be derived from nor instances extended!

A memory device context provides a means to draw graphics onto a bitmap.

When drawing in to a mono-bitmap, using WHITE, WHITE_PEN and WHITE_BRUSH will draw the background colour (i.e. 0) whereas all other colours will draw the foreground colour (i.e. 1). A bitmap must be selected into the new memory DC before it may be used for anything. Typical usage is as follows:

Wx::MemoryDC.draw_on(test_bitmap) do |mem_dc|
    # We can now draw into the memory DC...
    
    # Copy from this DC to another DC.
    old_dc.blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, mem_dc, 0, 0)
  end

Note that the memory DC must be deleted (or the bitmap selected out of it) before a bitmap can be reselected into another memory DC. And, before performing any other operations on the bitmap data, the bitmap must be selected out of the memory DC. Note that when using the .draw_on method this will happen automatically when the block returns.

Note that the scaling factor of the bitmap determines the scaling factor used by this device context, so when using a memory device context as a back buffer for a window, you should typically create the bitmap using the same scale factor as used by the window, e.g.

class MyWindow

    def on_paint(_)
      bmp = Wx::Bitmap.new
      bmp.create_with_dip_size(get_client_size, get_dpi_scale_factor)
      Wx::MemoryDC.draw_on(bmp) do |mem_dc|  
        ... use mem_dc to draw on the bitmap ...
      end
      self.paint do |dc|
        dc.draw_bitmap(bmp, Wx::Point.new(0, 0))
      end
    end

  end

Category: Device Contexts

See Also:

Direct Known Subclasses

BufferedDC

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DC

#blit, #calc_bounding_box, #can_draw_bitmap, #can_get_text_extent, #can_use_transform_matrix, #clear, #copy_attributes, #cross_hair, #destroy_clipping_region, #device_to_logical, #device_to_logical_rel, #device_to_logical_x, #device_to_logical_x_rel, #device_to_logical_y, #device_to_logical_y_rel, #draw_arc, #draw_bitmap, #draw_check_mark, #draw_circle, #draw_ellipse, #draw_elliptic_arc, #draw_icon, #draw_label, #draw_line, #draw_lines, #draw_point, #draw_poly_polygon, #draw_polygon, #draw_rectangle, #draw_rotated_text, #draw_rounded_rectangle, #draw_spline, #draw_text, #end_doc, #end_page, #flood_fill, #from_dip, #get_as_bitmap, #get_background, #get_background_mode, #get_brush, #get_char_height, #get_char_width, #get_clipping_box, #get_content_scale_factor, #get_depth, #get_device_origin, #get_dimensions, #get_dimensions_mm, #get_font, #get_font_metrics, #get_graphics_context, #get_layout_direction, #get_logical_function, #get_logical_origin, #get_logical_scale, #get_map_mode, #get_multi_line_text_extent, #get_multi_line_text_size, #get_pen, #get_pixel, #get_ppi, #get_size, #get_size_mm, #get_text_background, #get_text_extent, #get_text_foreground, #get_text_size, #get_transform_matrix, #get_user_scale, #gradient_fill_concentric, #gradient_fill_linear, #is_ok, #logical_to_device, #logical_to_device_rel, #logical_to_device_x, #logical_to_device_x_rel, #logical_to_device_y, #logical_to_device_y_rel, #max_x, #max_y, #min_x, #min_y, #reset_bounding_box, #reset_transform_matrix, #set_axis_orientation, #set_background, #set_background_mode, #set_brush, #set_clipping_region, #set_device_clipping_region, #set_device_origin, #set_font, #set_graphics_context, #set_layout_direction, #set_logical_function, #set_logical_origin, #set_logical_scale, #set_map_mode, #set_palette, #set_pen, #set_text_background, #set_text_foreground, #set_transform_matrix, #set_user_scale, #start_doc, #start_page, #stretch_blit, #to_dip, #with_background_mode, #with_brush, #with_font, #with_pen, #with_text_background, #with_text_foreground

Methods inherited from Object

#clone, #dup, #initialize, #is_same_as, #un_share

Constructor Details

This class inherits a constructor from Wx::Object

Class Method Details

.self.draw_on {|dc| ... } ⇒ Object .self.draw_on(bitmap) {|dc| ... } ⇒ Object .self.draw_on(dc) {|dc| ... } ⇒ Object

Creates a Memory DC and passes that to the given block to draw on. Automatically unselects any source object of the MemoryDC after the block finishes.

Overloads:



22
# File 'lib/wx/doc/memory_dc.rb', line 22

def self.draw_on(*arg) end

Instance Method Details

#get_selected_bitmapWx::Bitmap Also known as: selected_bitmap

Get the selected bitmap.

Returns:



95
# File 'lib/wx/doc/gen/memory_dc.rb', line 95

def get_selected_bitmap; end

#select_object(bitmap) ⇒ void

This method returns an undefined value.

Allow using this device context object to modify the given bitmap contents.

Note that if you need to only use the existing bitmap contents instead of modifying it, you should use #select_object_as_source instead. Before using the updated bitmap data, make sure to select it out of context first either by selecting NULL_BITMAP into the device context or destroying the device context entirely. If the bitmap is already selected in this device context, nothing is done. If it is selected in another context, the function asserts and drawing on the bitmap won’t work correctly.

Parameters:



76
# File 'lib/wx/doc/gen/memory_dc.rb', line 76

def select_object(bitmap) end

#select_object_as_source(bitmap) ⇒ void

This method returns an undefined value.

Selects the given bitmap into the device context, to use as the memory bitmap.

Selecting the bitmap as source into a memory DC allows you to copy its contents to another device context using DC#blit. Note that using DC#draw_bitmap or DC#draw_icon is a simpler way to do the same thing.

Note:

Modifying a bitmap selected only as a source may not work correctly and can notably modify the other bitmaps sharing the same data due to the use of reference counting (see Reference Counting).

If the argument is NULL_BITMAP (or some other uninitialised Bitmap) the current bitmap is selected out of the device context, allowing the current bitmap to be destroyed safely.

Parameters:



91
# File 'lib/wx/doc/gen/memory_dc.rb', line 91

def select_object_as_source(bitmap) end