Class: MtgCardMaker::ArtLayer

Inherits:
BaseLayer show all
Defined in:
lib/mtg_card_maker/layers/art_layer.rb

Overview

ArtLayer is a specialized layer for card artwork. It provides a placeholder for the art area, the art itself is not a feature of this gem.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from BaseLayer

#color, #height, #template, #width, #x, #y

Instance Method Summary collapse

Methods inherited from BaseLayer

#svg

Constructor Details

#initialize(dimensions:, color_scheme: DEFAULT_COLOR_SCHEME, art: nil) ⇒ ArtLayer

Returns a new instance of ArtLayer.

Since:

  • 0.1.0



13
14
15
16
17
# File 'lib/mtg_card_maker/layers/art_layer.rb', line 13

def initialize(dimensions:, color_scheme: DEFAULT_COLOR_SCHEME, art: nil)
  super(dimensions: dimensions, color: '#000')
  @color_scheme = color_scheme
  @art = parse_image_url(art)
end

Instance Attribute Details

#artObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/mtg_card_maker/layers/art_layer.rb', line 11

def art
  @art
end

#color_schemeObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/mtg_card_maker/layers/art_layer.rb', line 11

def color_scheme
  @color_scheme
end

Instance Method Details

#renderObject

Render the art area with an ornate frame and optional image

Since:

  • 0.1.0



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mtg_card_maker/layers/art_layer.rb', line 20

def render
  layer_config = LayerConfig.default
  stroke_width = layer_config.stroke_width
  outer_corners = layer_config.corner_radius(:art)
  inner_corners = { x: 5, y: 5 } # Inner frame uses smaller radius

  svg.g do
    # Ornate art frame
    svg.rect x: x - 3, y: y - 3,
             width: width + 6, height: height + 6,
             fill: 'none',
             stroke: color_scheme.primary_color,
             stroke_width: stroke_width,
             rx: outer_corners[:x], ry: outer_corners[:y]

    # Frame border for the transparent window
    svg.rect x: x, y: y, width: width, height: height, fill: 'none',
             stroke: ColorPalette::FRAME_STROKE_COLOR, stroke_width: stroke_width,
             rx: inner_corners[:x], ry: inner_corners[:y]

    # Render image if provided
    render_image if art
  end
end