Class: Bagel::Graphic::Scoreboard::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/bagel/graphic/scoreboard/context.rb

Constant Summary collapse

HEIGHT =
40
PADDING =
10

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Context

Returns a new instance of Context.



6
7
8
# File 'lib/bagel/graphic/scoreboard/context.rb', line 6

def initialize(context)
  @context = context
end

Instance Method Details

#drawObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bagel/graphic/scoreboard/context.rb', line 10

def draw
  text = Image.new(HEIGHT * 10, HEIGHT * 2) { self.background_color = COLOR_WHITE }

  draw = Magick::Draw.new do |d|
    d.font_family = FONT_FAMILY
    d.font_weight = FONT_WEIGHT
    d.pointsize = 24
    d.gravity = WestGravity
    d.fill = COLOR_BLACK
  end

  draw.annotate(text, 0, 0, 0, 0, @context)
  text.trim!

  canvas = Image.new(text.columns + PADDING * 2, HEIGHT) { self.background_color = COLOR_WHITE }
  canvas.composite!(text, WestGravity, PADDING, 0, OverCompositeOp)
end