Class: Zyps::WxCanvas
- Inherits:
-
Object
- Object
- Zyps::WxCanvas
- Defined in:
- lib/zyps/views/canvas/wx.rb
Overview
Called by View objects for use in wxRuby applications. Assign an instance to a View, and the drawing_area will be updated whenever the View is.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
The Wx::Bitmap to draw to.
-
#height ⇒ Object
Dimensions of the drawing area.
-
#width ⇒ Object
Dimensions of the drawing area.
Instance Method Summary collapse
-
#draw_line(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :width => nil :x1 => nil :y1 => nil :x2 => nil :y2 => nil.
-
#draw_rectangle(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :border_width => 1 :filled => true :x => nil :y => nil :width => nil :height => nil.
-
#initialize ⇒ WxCanvas
constructor
A new instance of WxCanvas.
-
#render ⇒ Object
Draw all objects to the drawing area.
Constructor Details
#initialize ⇒ WxCanvas
Returns a new instance of WxCanvas.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zyps/views/canvas/wx.rb', line 37 def initialize #Will be resized later. @width, @height = 1, 1 #Set to correct size. resize #Arrays of shapes that will be painted when render() is called. @rectangle_queue = [] @line_queue = [] #Hash of Wx::Pens used to draw in various colors and widths. @pens = Hash.new {|h, k| h[k] = Hash.new} #Hash of Wx::Brushes for various colors. @brushes = Hash.new end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
The Wx::Bitmap to draw to.
31 32 33 |
# File 'lib/zyps/views/canvas/wx.rb', line 31 def buffer @buffer end |
#height ⇒ Object
Dimensions of the drawing area. Control should normally be left to the owner View object.
34 35 36 |
# File 'lib/zyps/views/canvas/wx.rb', line 34 def height @height end |
#width ⇒ Object
Dimensions of the drawing area. Control should normally be left to the owner View object.
34 35 36 |
# File 'lib/zyps/views/canvas/wx.rb', line 34 def width @width end |
Instance Method Details
#draw_line(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :width => nil :x1 => nil :y1 => nil :x2 => nil :y2 => nil
92 93 94 |
# File 'lib/zyps/views/canvas/wx.rb', line 92 def draw_line( = {}) @line_queue << end |
#draw_rectangle(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :border_width => 1 :filled => true :x => nil :y => nil :width => nil :height => nil
75 76 77 78 79 80 81 |
# File 'lib/zyps/views/canvas/wx.rb', line 75 def draw_rectangle( = {}) = { :filled => true, :border_width => 1 }.merge() @rectangle_queue << end |
#render ⇒ Object
Draw all objects to the drawing area.
98 99 100 101 102 103 104 105 |
# File 'lib/zyps/views/canvas/wx.rb', line 98 def render buffer.draw do |surface| #Draw all queued rectangles. render_rectangles(surface) #Draw all queued lines. render_lines(surface) end end |