Class: Wx::GraphicsContext
- Inherits:
-
GraphicsObject
- Object
- Object
- GraphicsObject
- Wx::GraphicsContext
- Defined in:
- lib/wx/doc/gen/graphics_context.rb,
lib/wx/doc/graphics_context.rb
Overview
This class is untracked and should not be derived from nor instances extended!
A GraphicsContext instance is the object that is drawn upon.
It is created by a renderer using Wx::GraphicsRenderer#create_context. This can be either directly using a renderer instance, or indirectly using the static convenience GraphicsContext.create functions of GraphicsContext that always delegate the task to the default renderer.
class MyCanvas < Wx::ScrolledWindow
def on_paint(event)
# Create paint DC
self.paint do |dc|
# Create graphics context from it
Wx::GraphicsContext.draw_on(dc) do |gc|
# make a path that contains a circle and some lines
gc.set_pen(Wx::RED_PEN)
path = gc.create_path
path.add_circle(50.0, 50.0, 50.0)
path.move_to_point(0.0, 50.0)
path.add_line_to_point(100.0, 50.0)
path.move_to_point(50.0, 0.0)
path.add_line_to_point(50.0, 100.0)
path.close_sub_path
path.add_rectangle(25.0, 25.0, 50.0, 50.0)
gc.stroke_path(path)
end
end
end
end
end
For some renderers (like Direct2D or Cairo), the processing of drawing operations may be deferred. For example, Direct2D render targets normally build up a batch of rendering commands but defers processing them, while Cairo operates on a separate surface. To make drawing results visible, you need to update the context's content by either calling #flush or by destroying the context.
Category: Graphics Device Interface (GDI), Device Contexts
Class Method Summary collapse
Instance Method Summary collapse
-
#begin_layer(opacity) ⇒ void
All rendering will be done into a fully transparent, temporary context.
- #clear_rectangle(*args) ⇒ Object
- #clip(*args) ⇒ Object
-
#concat_transform(matrix) ⇒ void
Concatenates the passed-in transform with the current transform of this context.
-
#create_bitmap(bitmap) ⇒ Wx::GraphicsBitmap
Creates GraphicsBitmap from an existing Bitmap.
-
#create_bitmap_from_image(image) ⇒ Wx::GraphicsBitmap
Creates GraphicsBitmap from an existing Image.
-
#create_brush(brush) ⇒ Wx::GraphicsBrush
Creates a native brush from a Brush.
- #create_font(*args) ⇒ Object
- #create_linear_gradient_brush(*args) ⇒ Object
-
#create_matrix(a = 1.0, b = 0.0, c = 0.0, d = 1.0, tx = 0.0, ty = 0.0) ⇒ Wx::GraphicsMatrix
Creates a native affine transformation matrix from the passed-in values.
-
#create_path ⇒ Wx::GraphicsPath
Creates a native graphics path which is initially empty.
- #create_pen(*args) ⇒ Object
- #create_radial_gradient_brush(*args) ⇒ Object
-
#create_sub_bitmap(bitmap, x, y, w, h) ⇒ Wx::GraphicsBitmap
Extracts a sub-bitmap from an existing bitmap.
-
#disable_offset ⇒ void
Helper to determine if a 0.5 offset should be applied for the drawing operation.
- #draw_bitmap(*args) ⇒ Object
- #draw_ellipse(*args) ⇒ Object
- #draw_icon(*args) ⇒ Object
-
#draw_path(path, fillStyle = Wx::PolygonFillMode::ODDEVEN_RULE) ⇒ void
Draws the path by first filling and then stroking.
- #draw_rectangle(*args) ⇒ Object
- #draw_rounded_rectangle(*args) ⇒ Object
- #draw_text(*args) ⇒ Object
-
#enable_offset(enable = true) ⇒ void
Indicates whether the context should try to offset for pixel boundaries.
-
#end_doc ⇒ void
Done with that document (relevant only for printing / pdf / etc.).
-
#end_layer ⇒ void
Composites back the drawings into the context with the opacity given at the #begin_layer call.
-
#end_page ⇒ void
Ends the current page (relevant only for printing / pdf / etc.).
-
#fill_path(path, fillStyle = Wx::PolygonFillMode::ODDEVEN_RULE) ⇒ void
Fills the path with the current brush.
-
#flush ⇒ void
Make sure that the current content of this context is immediately visible.
- #from_dip(*args) ⇒ Object
-
#get_antialias_mode ⇒ Wx::AntialiasMode
(also: #antialias_mode)
Returns the current shape antialiasing mode.
-
#get_clip_box ⇒ Wx::Rect2DDouble
(also: #clip_box)
This is an overloaded member function, provided for convenience.
-
#get_composition_mode ⇒ Wx::CompositionMode
(also: #composition_mode)
Returns the current compositing operator.
-
#get_dpi ⇒ Array(Float,Float)
(also: #dpi)
Returns the resolution of the graphics context in device points per inch.
-
#get_interpolation_quality ⇒ Wx::InterpolationQuality
(also: #interpolation_quality)
Returns the current interpolation quality.
-
#get_partial_text_extents(text) ⇒ Array<Float>
(also: #partial_text_extents)
Fills the widths array with the widths from the beginning of text to the corresponding character of text.
-
#get_size ⇒ Array(Float,Float)
(also: #size)
Returns the size of the graphics context in device coordinates.
-
#get_text_extent(text) ⇒ Array(Float,Float,Float,Float)
(also: #text_extent)
Gets the dimensions of the string using the currently selected font.
-
#get_transform ⇒ Wx::GraphicsMatrix
(also: #transform)
Gets the current transformation matrix of this context.
-
#get_window ⇒ Wx::Window
(also: #window)
Returns the associated window, if any.
-
#offset_enabled ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
-
#pop_state ⇒ void
Sets current state of the context to the state saved by a preceding call to #push_state and removes that state from the stack of saved states.
-
#push_state ⇒ void
Push the current state (like transformations, clipping region and quality settings) of the context on a stack.
-
#reset_clip ⇒ void
Resets the clipping to original shape.
-
#rotate(angle) ⇒ void
Rotates the current transformation matrix (in radians).
-
#scale(xScale, yScale) ⇒ void
Scales (i.e., shrinks or grows) the current transformation matrix.
-
#set_antialias_mode(antialias) ⇒ Boolean
(also: #antialias_mode=)
Sets the antialiasing mode; returns true if it supported.
- #set_brush(*args) ⇒ Object (also: #brush=)
-
#set_composition_mode(op) ⇒ Boolean
(also: #composition_mode=)
Sets the compositing operator, returns true if it supported.
- #set_font(*args) ⇒ Object (also: #font=)
-
#set_interpolation_quality(interpolation) ⇒ Boolean
(also: #interpolation_quality=)
Sets the interpolation quality; returns true if it is supported.
- #set_pen(*args) ⇒ Object (also: #pen=)
-
#set_transform(matrix) ⇒ void
(also: #transform=)
Sets the current transformation matrix of this context.
-
#should_offset ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
-
#start_doc(message) ⇒ Boolean
Begin a new document (relevant only for printing / pdf / etc.) If there is a progress dialog, message will be shown.
-
#start_page(width = 0, height = 0) ⇒ void
Opens a new page (relevant only for printing / pdf etc.) with the given size in points.
- #stroke_line(*args) ⇒ Object
-
#stroke_path(path) ⇒ void
Strokes along a path with the current pen.
- #to_dip(*args) ⇒ Object
- #translate(*args) ⇒ Object
Methods inherited from GraphicsObject
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.create(window) ⇒ Wx::GraphicsContext .self.create(windowDC) ⇒ Wx::GraphicsContext .self.create(memoryDC) ⇒ Wx::GraphicsContext .self.create(printerDC) ⇒ Wx::GraphicsContext .self.create(image) ⇒ Wx::GraphicsContext .self.create ⇒ Wx::GraphicsContext
256 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 256 def self.create(*args) end |
.self.draw_on(window) {|| ... } ⇒ ::Object .self.draw_on(windowDC) {|| ... } ⇒ ::Object .self.draw_on(memoryDC) {|| ... } ⇒ ::Object .self.draw_on(printerDC) {|| ... } ⇒ ::Object .self.draw_on(image) {|| ... } ⇒ ::Object .self.draw_on {|| ... } ⇒ ::Object
55 |
# File 'lib/wx/doc/graphics_context.rb', line 55 def self.draw_on(*args) end |
Instance Method Details
#begin_layer(opacity) ⇒ void
This method returns an undefined value.
All rendering will be done into a fully transparent, temporary context.
Layers can be nested by making balanced calls to #begin_layer/EndLayer().
727 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 727 def begin_layer(opacity) end |
#clear_rectangle(x, y, w, h) ⇒ void #clear_rectangle(rect) ⇒ void
588 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 588 def clear_rectangle(*args) end |
#clip(region) ⇒ void #clip(x, y, w, h) ⇒ void #clip(rect) ⇒ void
297 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 297 def clip(*args) end |
#concat_transform(matrix) ⇒ void
This method returns an undefined value.
Concatenates the passed-in transform with the current transform of this context.
319 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 319 def concat_transform(matrix) end |
#create_bitmap(bitmap) ⇒ Wx::GraphicsBitmap
Creates Wx::GraphicsBitmap from an existing Bitmap.
An invalid NULL_GRAPHICS_BITMAP on failure.
703 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 703 def create_bitmap(bitmap) end |
#create_bitmap_from_image(image) ⇒ Wx::GraphicsBitmap
Creates Wx::GraphicsBitmap from an existing Image.
This method is more efficient than converting Image to Bitmap first and then calling #create_bitmap, but otherwise has the same effect. An invalid NULL_GRAPHICS_BITMAP on failure.
711 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 711 def create_bitmap_from_image(image) end |
#create_brush(brush) ⇒ Wx::GraphicsBrush
Creates a native brush from a Brush.
366 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 366 def create_brush(brush) end |
#create_font(font, col = Wx::BLACK) ⇒ Wx::GraphicsFont #create_font(sizeInPixels, facename, flags = Wx::FontFlag::FONTFLAG_DEFAULT, col = Wx::BLACK) ⇒ Wx::GraphicsFont
645 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 645 def create_font(*args) end |
#create_linear_gradient_brush(x1, y1, x2, y2, c1, c2, matrix = Wx::NULL_GRAPHICS_MATRIX) ⇒ Wx::GraphicsBrush #create_linear_gradient_brush(x1, y1, x2, y2, stops, matrix = Wx::NULL_GRAPHICS_MATRIX) ⇒ Wx::GraphicsBrush
391 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 391 def create_linear_gradient_brush(*args) end |
#create_matrix(a = 1.0, b = 0.0, c = 0.0, d = 1.0, tx = 0.0, ty = 0.0) ⇒ Wx::GraphicsMatrix
Creates a native affine transformation matrix from the passed-in values.
The default parameters result in an identity matrix.
314 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 314 def create_matrix(a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0) end |
#create_path ⇒ Wx::GraphicsPath
Creates a native graphics path which is initially empty.
592 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 592 def create_path; end |
#create_pen(pen) ⇒ Wx::GraphicsPen #create_pen(info) ⇒ Wx::GraphicsPen
442 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 442 def create_pen(*args) end |
#create_radial_gradient_brush(startX, startY, endX, endY, radius, oColor, cColor, matrix = Wx::NULL_GRAPHICS_MATRIX) ⇒ Wx::GraphicsBrush #create_radial_gradient_brush(startX, startY, endX, endY, radius, stops, matrix = Wx::NULL_GRAPHICS_MATRIX) ⇒ Wx::GraphicsBrush
419 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 419 def create_radial_gradient_brush(*args) end |
#create_sub_bitmap(bitmap, x, y, w, h) ⇒ Wx::GraphicsBitmap
Extracts a sub-bitmap from an existing bitmap.
720 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 720 def create_sub_bitmap(bitmap, x, y, w, h) end |
#disable_offset ⇒ void
This method returns an undefined value.
Helper to determine if a 0.5 offset should be applied for the drawing operation.
821 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 821 def disable_offset; end |
#draw_bitmap(bmp, x, y, w, h) ⇒ void #draw_bitmap(bmp, x, y, w, h) ⇒ void #draw_bitmap(bmp, rect) ⇒ void
478 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 478 def draw_bitmap(*args) end |
#draw_ellipse(x, y, w, h) ⇒ void #draw_ellipse(rect) ⇒ void
491 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 491 def draw_ellipse(*args) end |
#draw_icon(icon, x, y, w, h) ⇒ void #draw_icon(icon, rect) ⇒ void
506 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 506 def draw_icon(*args) end |
#draw_path(path, fillStyle = Wx::PolygonFillMode::ODDEVEN_RULE) ⇒ void
This method returns an undefined value.
Draws the path by first filling and then stroking.
512 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 512 def draw_path(path, fillStyle=Wx::PolygonFillMode::ODDEVEN_RULE) end |
#draw_rectangle(x, y, w, h) ⇒ void #draw_rectangle(rect) ⇒ void
525 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 525 def draw_rectangle(*args) end |
#draw_rounded_rectangle(x, y, w, h, radius) ⇒ void #draw_rounded_rectangle(rect, radius) ⇒ void
540 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 540 def draw_rounded_rectangle(*args) end |
#draw_text(str, x, y) ⇒ void #draw_text(str, pt) ⇒ void #draw_text(str, x, y, angle) ⇒ void #draw_text(str, x, y, backgroundBrush) ⇒ void #draw_text(str, x, y, angle, backgroundBrush) ⇒ void
575 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 575 def draw_text(*args) end |
#enable_offset(enable = true) ⇒ void
This method returns an undefined value.
Indicates whether the context should try to offset for pixel boundaries.
This only makes sense on bitmap devices like screen. By default, this is turned off.
817 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 817 def enable_offset(enable=true) end |
#end_doc ⇒ void
This method returns an undefined value.
Done with that document (relevant only for printing / pdf / etc.)
684 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 684 def end_doc; end |
#end_layer ⇒ void
This method returns an undefined value.
Composites back the drawings into the context with the opacity given at the #begin_layer call.
731 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 731 def end_layer; end |
#end_page ⇒ void
This method returns an undefined value.
Ends the current page (relevant only for printing / pdf / etc.)
696 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 696 def end_page; end |
#fill_path(path, fillStyle = Wx::PolygonFillMode::ODDEVEN_RULE) ⇒ void
This method returns an undefined value.
Fills the path with the current brush.
598 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 598 def fill_path(path, fillStyle=Wx::PolygonFillMode::ODDEVEN_RULE) end |
#flush ⇒ void
This method returns an undefined value.
Make sure that the current content of this context is immediately visible.
749 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 749 def flush; end |
#from_dip(sz) ⇒ Wx::Size #from_dip(pt) ⇒ Wx::Point #from_dip(d) ⇒ Integer
843 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 843 def from_dip(*args) end |
#get_antialias_mode ⇒ Wx::AntialiasMode Also known as: antialias_mode
Returns the current shape antialiasing mode.
759 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 759 def get_antialias_mode; end |
#get_clip_box ⇒ Wx::Rect2DDouble Also known as: clip_box
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
301 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 301 def get_clip_box; end |
#get_composition_mode ⇒ Wx::CompositionMode Also known as: composition_mode
Returns the current compositing operator.
787 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 787 def get_composition_mode; end |
#get_dpi ⇒ Array(Float,Float) Also known as: dpi
Returns the resolution of the graphics context in device points per inch.
797 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 797 def get_dpi; end |
#get_interpolation_quality ⇒ Wx::InterpolationQuality Also known as: interpolation_quality
Returns the current interpolation quality.
776 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 776 def get_interpolation_quality; end |
#get_partial_text_extents(text) ⇒ Array<Float> Also known as: partial_text_extents
Fills the widths array with the widths from the beginning of text to the corresponding character of text.
668 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 668 def get_partial_text_extents(text) end |
#get_size ⇒ Array(Float,Float) Also known as: size
Returns the size of the graphics context in device coordinates.
792 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 792 def get_size; end |
#get_text_extent(text) ⇒ Array(Float,Float,Float,Float) Also known as: text_extent
Gets the dimensions of the string using the currently selected font.
674 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 674 def get_text_extent(text) end |
#get_transform ⇒ Wx::GraphicsMatrix Also known as: transform
Gets the current transformation matrix of this context.
323 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 323 def get_transform; end |
#get_window ⇒ Wx::Window Also known as: window
805 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 805 def get_window; end |
#offset_enabled ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
825 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 825 def offset_enabled; end |
#pop_state ⇒ void
This method returns an undefined value.
Sets current state of the context to the state saved by a preceding call to #push_state and removes that state from the stack of saved states.
745 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 745 def pop_state; end |
#push_state ⇒ void
This method returns an undefined value.
Push the current state (like transformations, clipping region and quality settings) of the context on a stack.
Multiple balanced calls to #push_state and #pop_state can be nested.
738 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 738 def push_state; end |
#reset_clip ⇒ void
This method returns an undefined value.
Resets the clipping to original shape.
Use #get_clip_box to cache and restore a previous clipping area.
266 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 266 def reset_clip; end |
#rotate(angle) ⇒ void
This method returns an undefined value.
Rotates the current transformation matrix (in radians).
This can be useful for applying a tilt to your drawing commands or for drawing radial patterns.
A positive angle will rotate clockwise, negative counterclockwise.
338 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 338 def rotate(angle) end |
#scale(xScale, yScale) ⇒ void
This method returns an undefined value.
Scales (i.e., shrinks or grows) the current transformation matrix.
344 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 344 def scale(xScale, yScale) end |
#set_antialias_mode(antialias) ⇒ Boolean Also known as: antialias_mode=
Sets the antialiasing mode; returns true if it supported.
754 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 754 def set_antialias_mode(antialias) end |
#set_brush(brush) ⇒ void #set_brush(brush) ⇒ void Also known as: brush=
429 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 429 def set_brush(*args) end |
#set_composition_mode(op) ⇒ Boolean Also known as: composition_mode=
Sets the compositing operator, returns true if it supported.
782 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 782 def set_composition_mode(op) end |
#set_font(font, colour) ⇒ void #set_font(font) ⇒ void Also known as: font=
662 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 662 def set_font(*args) end |
#set_interpolation_quality(interpolation) ⇒ Boolean Also known as: interpolation_quality=
Sets the interpolation quality; returns true if it is supported.
Not implemented in the Cairo backend currently.
771 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 771 def set_interpolation_quality(interpolation) end |
#set_pen(pen) ⇒ void #set_pen(pen) ⇒ void Also known as: pen=
452 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 452 def set_pen(*args) end |
#set_transform(matrix) ⇒ void Also known as: transform=
This method returns an undefined value.
Sets the current transformation matrix of this context.
349 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 349 def set_transform(matrix) end |
#should_offset ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
810 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 810 def should_offset; end |
#start_doc(message) ⇒ Boolean
Begin a new document (relevant only for printing / pdf / etc.) If there is a progress dialog, message will be shown.
680 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 680 def start_doc() end |
#start_page(width = 0, height = 0) ⇒ void
This method returns an undefined value.
Opens a new page (relevant only for printing / pdf etc.) with the given size in points.
(If both are nil, then the default page size will be used.)
692 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 692 def start_page(width=0, height=0) end |
#stroke_line(x1, y1, x2, y2) ⇒ void #stroke_line(pt1, pt2) ⇒ void
612 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 612 def stroke_line(*args) end |
#stroke_path(path) ⇒ void
This method returns an undefined value.
Strokes along a path with the current pen.
617 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 617 def stroke_path(path) end |
#to_dip(sz) ⇒ Wx::Size #to_dip(pt) ⇒ Wx::Point #to_dip(d) ⇒ Integer
861 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 861 def to_dip(*args) end |
#translate(dx, dy) ⇒ void #translate(pt) ⇒ void
361 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 361 def translate(*args) end |