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().
721 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 721 def begin_layer(opacity) end |
#clear_rectangle(x, y, w, h) ⇒ void #clear_rectangle(rect) ⇒ void
582 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 582 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.
697 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 697 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.
705 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 705 def create_bitmap_from_image(image) end |
#create_brush(brush) ⇒ Wx::GraphicsBrush
Creates a native brush from a Brush.
360 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 360 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
639 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 639 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
385 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 385 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.
586 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 586 def create_path; end |
#create_pen(pen) ⇒ Wx::GraphicsPen #create_pen(info) ⇒ Wx::GraphicsPen
436 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 436 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
413 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 413 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.
714 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 714 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.
815 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 815 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
472 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 472 def draw_bitmap(*args) end |
#draw_ellipse(x, y, w, h) ⇒ void #draw_ellipse(rect) ⇒ void
485 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 485 def draw_ellipse(*args) end |
#draw_icon(icon, x, y, w, h) ⇒ void #draw_icon(icon, rect) ⇒ void
500 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 500 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.
506 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 506 def draw_path(path, fillStyle=Wx::PolygonFillMode::ODDEVEN_RULE) end |
#draw_rectangle(x, y, w, h) ⇒ void #draw_rectangle(rect) ⇒ void
519 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 519 def draw_rectangle(*args) end |
#draw_rounded_rectangle(x, y, w, h, radius) ⇒ void #draw_rounded_rectangle(rect, radius) ⇒ void
534 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 534 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
569 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 569 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.
811 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 811 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.)
678 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 678 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.
725 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 725 def end_layer; end |
#end_page ⇒ void
This method returns an undefined value.
Ends the current page (relevant only for printing / pdf / etc.)
690 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 690 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.
592 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 592 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.
743 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 743 def flush; end |
#from_dip(sz) ⇒ Wx::Size #from_dip(pt) ⇒ Wx::Point #from_dip(d) ⇒ Integer
837 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 837 def from_dip(*args) end |
#get_antialias_mode ⇒ Wx::AntialiasMode Also known as: antialias_mode
Returns the current shape antialiasing mode.
753 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 753 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.
781 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 781 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.
791 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 791 def get_dpi; end |
#get_interpolation_quality ⇒ Wx::InterpolationQuality Also known as: interpolation_quality
Returns the current interpolation quality.
770 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 770 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.
662 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 662 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.
786 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 786 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.
668 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 668 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
799 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 799 def get_window; end |
#offset_enabled ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
819 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 819 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.
739 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 739 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.
732 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 732 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.
332 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 332 def rotate(angle) end |
#scale(xScale, yScale) ⇒ void
This method returns an undefined value.
Scales (i.e., shrinks or grows) the current transformation matrix.
338 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 338 def scale(xScale, yScale) end |
#set_antialias_mode(antialias) ⇒ Boolean Also known as: antialias_mode=
Sets the antialiasing mode; returns true if it supported.
748 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 748 def set_antialias_mode(antialias) end |
#set_brush(brush) ⇒ void #set_brush(brush) ⇒ void Also known as: brush=
423 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 423 def set_brush(*args) end |
#set_composition_mode(op) ⇒ Boolean Also known as: composition_mode=
Sets the compositing operator, returns true if it supported.
776 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 776 def set_composition_mode(op) end |
#set_font(font, colour) ⇒ void #set_font(font) ⇒ void Also known as: font=
656 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 656 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.
765 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 765 def set_interpolation_quality(interpolation) end |
#set_pen(pen) ⇒ void #set_pen(pen) ⇒ void Also known as: pen=
446 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 446 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.
343 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 343 def set_transform(matrix) end |
#should_offset ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
804 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 804 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.
674 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 674 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.)
686 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 686 def start_page(width=0, height=0) end |
#stroke_line(x1, y1, x2, y2) ⇒ void #stroke_line(pt1, pt2) ⇒ void
606 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 606 def stroke_line(*args) end |
#stroke_path(path) ⇒ void
This method returns an undefined value.
Strokes along a path with the current pen.
611 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 611 def stroke_path(path) end |
#to_dip(sz) ⇒ Wx::Size #to_dip(pt) ⇒ Wx::Point #to_dip(d) ⇒ Integer
855 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 855 def to_dip(*args) end |
#translate(dx, dy) ⇒ void #translate(pt) ⇒ void
355 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 355 def translate(*args) end |