Module: WindowBlessing::Window::Drawing

Included in:
WindowBlessing::Window
Defined in:
lib/window_blessing/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



201
202
203
# File 'lib/window_blessing/window.rb', line 201

def buffer
  @buffer
end

#redraw_areasObject (readonly)

Returns the value of attribute redraw_areas.



201
202
203
# File 'lib/window_blessing/window.rb', line 201

def redraw_areas
  @redraw_areas
end

Instance Method Details

#add_redraw_area(area) ⇒ Object



207
208
209
210
211
# File 'lib/window_blessing/window.rb', line 207

def add_redraw_area(area)
  area = area | internal_area
  (@redraw_areas ||= WindowRedrawAreas.new) << area
  area
end

#clear_redraw_areasObject

return redraw_areas after clearing it (returns [] if none)



214
215
216
217
218
# File 'lib/window_blessing/window.rb', line 214

def clear_redraw_areas
  ret = redraw_areas
  @redraw_areas = nil
  ret
end

#draw(target_buffer = nil, internal_area = self.internal_area) ⇒ Object

Draw the window:

1) Draw all requested internal redraw areas, and clear all requests. 2) Draw @buffer to target_buffer. Optionally, only draw the specified internal_area. 3) return an array of internal areas redrawn



268
269
270
271
272
# File 'lib/window_blessing/window.rb', line 268

def draw(target_buffer = nil, internal_area = self.internal_area)
  ret = redraw
  target_buffer.draw_buffer loc, buffer, internal_area if target_buffer
  ret
end

#draw_backgroundObject

Reset @buffer to the designated background. The default implementation resets it to the ‘ ’ character with @bg and @fg colors.

NOTE: Buffer may have a cropping area set

NOTE: Safe to override. Calling ‘super’ is optional. Should fully replace all character, foreground and background colors for @buffer’s current croparea.



237
238
239
# File 'lib/window_blessing/window.rb', line 237

def draw_background
  buffer.fill :string => ' ', :bg => bg, :fg => fg
end

#draw_internal(area = nil) ⇒ Object

Update @buffer

The default implementation calls #draw_background and then calls #draw on each child.

NOTE: Buffer may have a cropping area set

NOTE: Safe to override. Calling ‘super’ is optional.



248
249
250
251
252
253
254
255
# File 'lib/window_blessing/window.rb', line 248

def draw_internal(area = nil)
  buffer.cropped(area) do
    draw_background
    children.each do |child|
      child.draw buffer, buffer.crop_area - child.loc
    end
  end
end

#redrawObject

perform the request redraws return the areas redrawn (returns [] if none)



259
260
261
# File 'lib/window_blessing/window.rb', line 259

def redraw
  clear_redraw_areas.each {|area| draw_internal area}
end

#redraw_requested?Boolean

Returns:

  • (Boolean)


230
# File 'lib/window_blessing/window.rb', line 230

def redraw_requested?; redraw_areas.length > 0 end

#request_redraw(redraw_area = nil) ⇒ Object

ask the parent to redraw all, or, if area is set, some of the area covered by this window



225
226
227
228
# File 'lib/window_blessing/window.rb', line 225

def request_redraw(redraw_area = nil)
  redraw_area ||= internal_area
  parent && parent.request_redraw_internal(redraw_area + loc)
end

#request_redraw_internal(area = internal_area) ⇒ Object



220
221
222
# File 'lib/window_blessing/window.rb', line 220

def request_redraw_internal(area = internal_area)
  request_redraw add_redraw_area(area)
end