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) processing of drawing operations may be deferred (Direct2D render target normally builds up a batch of rendering commands but defers processing of these commands, Cairo operates on a separate surface) so to make drawing results visible you need to update the content of the context by 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.
- #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(x, y, w, h) ⇒ void
Draws an ellipse.
-
#draw_icon(icon, x, y, w, h) ⇒ void
Draws the icon.
-
#draw_path(path, fillStyle = Wx::PolygonFillMode::ODDEVEN_RULE) ⇒ void
Draws the path by first filling and then stroking.
-
#draw_rectangle(x, y, w, h) ⇒ void
Draws a rectangle.
-
#draw_rounded_rectangle(x, y, w, h, radius) ⇒ void
Draws a rounded rectangle.
- #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 ⇒ Array(Float,Float,Float,Float)
(also: #clip_box)
Returns bounding box of the current clipping region.
-
#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 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(x1, y1, x2, y2) ⇒ void
Strokes a single line.
-
#stroke_path(path) ⇒ void
Strokes along a path with the current pen.
- #to_dip(*args) ⇒ Object
-
#translate(dx, dy) ⇒ void
Translates the current transformation matrix.
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().
661 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 661 def begin_layer(opacity) end |
#clip(region) ⇒ void #clip(x, y, w, h) ⇒ void
287 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 287 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.
318 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 318 def concat_transform(matrix) end |
#create_bitmap(bitmap) ⇒ Wx::GraphicsBitmap
Creates Wx::GraphicsBitmap from an existing Bitmap.
Returns an invalid NULL_GRAPHICS_BITMAP on failure.
637 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 637 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. Returns an invalid NULL_GRAPHICS_BITMAP on failure.
645 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 645 def create_bitmap_from_image(image) end |
#create_brush(brush) ⇒ Wx::GraphicsBrush
Creates a native brush from a Brush.
351 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 351 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
579 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 579 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
376 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 376 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.
313 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 313 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.
532 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 532 def create_path; end |
#create_pen(pen) ⇒ Wx::GraphicsPen #create_pen(info) ⇒ Wx::GraphicsPen
427 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 427 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
404 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 404 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.
654 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 654 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.
755 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 755 def disable_offset; end |
#draw_bitmap(bmp, x, y, w, h) ⇒ void #draw_bitmap(bmp, x, y, w, h) ⇒ void
458 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 458 def draw_bitmap(*args) end |
#draw_ellipse(x, y, w, h) ⇒ void
This method returns an undefined value.
Draws an ellipse.
466 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 466 def draw_ellipse(x, y, w, h) end |
#draw_icon(icon, x, y, w, h) ⇒ void
This method returns an undefined value.
Draws the icon.
475 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 475 def draw_icon(icon, x, y, w, h) 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.
481 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 481 def draw_path(path, fillStyle=Wx::PolygonFillMode::ODDEVEN_RULE) end |
#draw_rectangle(x, y, w, h) ⇒ void
This method returns an undefined value.
Draws a rectangle.
489 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 489 def draw_rectangle(x, y, w, h) end |
#draw_rounded_rectangle(x, y, w, h, radius) ⇒ void
This method returns an undefined value.
Draws a rounded rectangle.
498 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 498 def draw_rounded_rectangle(x, y, w, h, radius) end |
#draw_text(str, x, y) ⇒ void #draw_text(str, x, y, angle) ⇒ void #draw_text(str, x, y, backgroundBrush) ⇒ void #draw_text(str, x, y, angle, backgroundBrush) ⇒ void
528 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 528 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.
751 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 751 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.)
618 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 618 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.
665 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 665 def end_layer; end |
#end_page ⇒ void
This method returns an undefined value.
Ends the current page (relevant only for printing / pdf etc.)
630 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 630 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.
538 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 538 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.
683 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 683 def flush; end |
#from_dip(sz) ⇒ Wx::Size #from_dip(pt) ⇒ Wx::Point #from_dip(d) ⇒ Integer
777 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 777 def from_dip(*args) end |
#get_antialias_mode ⇒ Wx::AntialiasMode Also known as: antialias_mode
Returns the current shape antialiasing mode.
693 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 693 def get_antialias_mode; end |
#get_clip_box ⇒ Array(Float,Float,Float,Float) Also known as: clip_box
Returns bounding box of the current clipping region.
- If clipping region is empty, then empty rectangle is returned (x, y, w, h are set to zero).
300 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 300 def get_clip_box; end |
#get_composition_mode ⇒ Wx::CompositionMode Also known as: composition_mode
Returns the current compositing operator.
721 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 721 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.
731 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 731 def get_dpi; end |
#get_interpolation_quality ⇒ Wx::InterpolationQuality Also known as: interpolation_quality
Returns the current interpolation quality.
710 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 710 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.
602 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 602 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.
726 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 726 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.
608 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 608 def get_text_extent(text) end |
#get_transform ⇒ Wx::GraphicsMatrix Also known as: transform
Gets the current transformation matrix of this context.
322 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 322 def get_transform; end |
#get_window ⇒ Wx::Window Also known as: window
739 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 739 def get_window; end |
#offset_enabled ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
759 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 759 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.
679 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 679 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.
672 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 672 def push_state; end |
#reset_clip ⇒ void
This method returns an undefined value.
Resets the clipping to original shape.
260 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 260 def reset_clip; end |
#rotate(angle) ⇒ void
This method returns an undefined value.
Rotates the current transformation matrix (in radians).
328 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 328 def rotate(angle) end |
#scale(xScale, yScale) ⇒ void
This method returns an undefined value.
Scales the current transformation matrix.
334 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 334 def scale(xScale, yScale) end |
#set_antialias_mode(antialias) ⇒ Boolean Also known as: antialias_mode=
Sets the antialiasing mode, returns true if it supported.
688 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 688 def set_antialias_mode(antialias) end |
#set_brush(brush) ⇒ void #set_brush(brush) ⇒ void Also known as: brush=
414 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 414 def set_brush(*args) end |
#set_composition_mode(op) ⇒ Boolean Also known as: composition_mode=
Sets the compositing operator, returns true if it supported.
716 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 716 def set_composition_mode(op) end |
#set_font(font, colour) ⇒ void #set_font(font) ⇒ void Also known as: font=
596 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 596 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 Cairo backend currently.
705 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 705 def set_interpolation_quality(interpolation) end |
#set_pen(pen) ⇒ void #set_pen(pen) ⇒ void Also known as: pen=
437 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 437 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.
339 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 339 def set_transform(matrix) end |
#should_offset ⇒ Boolean
Helper to determine if a 0.5 offset should be applied for the drawing operation.
744 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 744 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.
614 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 614 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 null the default page size will be used.)
626 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 626 def start_page(width=0, height=0) end |
#stroke_line(x1, y1, x2, y2) ⇒ void
This method returns an undefined value.
Strokes a single line.
546 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 546 def stroke_line(x1, y1, x2, y2) end |
#stroke_path(path) ⇒ void
This method returns an undefined value.
Strokes along a path with the current pen.
551 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 551 def stroke_path(path) end |
#to_dip(sz) ⇒ Wx::Size #to_dip(pt) ⇒ Wx::Point #to_dip(d) ⇒ Integer
795 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 795 def to_dip(*args) end |
#translate(dx, dy) ⇒ void
This method returns an undefined value.
Translates the current transformation matrix.
346 |
# File 'lib/wx/doc/gen/graphics_context.rb', line 346 def translate(dx, dy) end |