Module: Denko::Display::PixelCommon
- Included in:
- SPICommon
- Defined in:
- lib/denko/display/pixel_common.rb
Instance Method Summary collapse
- #canvas ⇒ Object
- #colors ⇒ Object
- #columns ⇒ Object (also: #cols)
- #draw(x_start = x_min, x_finish = x_max, y_start = y_min, y_finish = y_max) ⇒ Object
- #get_partial_buffer(buffer, x_start, x_finish, p_start, p_finish) ⇒ Object
- #p_max ⇒ Object
- #p_min ⇒ Object
- #refresh ⇒ Object
- #rows ⇒ Object
- #x_max ⇒ Object
- #x_min ⇒ Object
- #y_max ⇒ Object
- #y_min ⇒ Object
Instance Method Details
#canvas ⇒ Object
49 50 51 |
# File 'lib/denko/display/pixel_common.rb', line 49 def canvas @canvas ||= Canvas.new(columns, rows, colors: colors) end |
#colors ⇒ Object
45 46 47 |
# File 'lib/denko/display/pixel_common.rb', line 45 def colors @colors ||= params[:colors] || 1 end |
#columns ⇒ Object Also known as: cols
4 5 6 7 8 9 10 |
# File 'lib/denko/display/pixel_common.rb', line 4 def columns return @columns if @columns @columns = self.class.const_get("COLUMNS") if self.class.const_defined?("COLUMNS") @columns = params[:width] if params[:width] @columns = params[:columns] if params[:columns] @columns end |
#draw(x_start = x_min, x_finish = x_max, y_start = y_min, y_finish = y_max) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/denko/display/pixel_common.rb', line 70 def draw(x_start=x_min, x_finish=x_max, y_start=y_min, y_finish=y_max) # Convert y-coords to page coords. p_start = y_start / 8 p_finish = y_finish / 8 colors.times do |i| draw_partial(canvas.framebuffers[i], x_start, x_finish, p_start, p_finish, i+1) end refresh end |
#get_partial_buffer(buffer, x_start, x_finish, p_start, p_finish) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/denko/display/pixel_common.rb', line 56 def get_partial_buffer(buffer, x_start, x_finish, p_start, p_finish) # If bounds == max bounds, just return the buffer. return buffer if (x_start == x_min) && (x_finish == x_max) && (p_start == p_min) && (p_finish == p_max) # Copy bytes for the given rectangle into a temp buffer. temp_buffer = [] (p_start..p_finish).each do |page| src_start = (columns * page) + x_start src_end = (columns * page) + x_finish temp_buffer += buffer[src_start..src_end] end temp_buffer end |
#p_max ⇒ Object
41 42 43 |
# File 'lib/denko/display/pixel_common.rb', line 41 def p_max @p_max ||= (rows / 8.0).ceil - 1 end |
#p_min ⇒ Object
37 38 39 |
# File 'lib/denko/display/pixel_common.rb', line 37 def p_min @p_min ||= 0 end |
#refresh ⇒ Object
53 54 |
# File 'lib/denko/display/pixel_common.rb', line 53 def refresh end |
#rows ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/denko/display/pixel_common.rb', line 13 def rows return @rows if @rows @rows = self.class.const_get("ROWS") if self.class.const_defined?("ROWS") @rows = params[:height] if params[:height] @rows = params[:rows] if params[:rows] @rows end |
#x_max ⇒ Object
25 26 27 |
# File 'lib/denko/display/pixel_common.rb', line 25 def x_max @x_max ||= columns - 1 end |
#x_min ⇒ Object
21 22 23 |
# File 'lib/denko/display/pixel_common.rb', line 21 def x_min @x_min ||= 0 end |
#y_max ⇒ Object
33 34 35 |
# File 'lib/denko/display/pixel_common.rb', line 33 def y_max @y_max ||= rows - 1 end |
#y_min ⇒ Object
29 30 31 |
# File 'lib/denko/display/pixel_common.rb', line 29 def y_min @y_min ||= 0 end |