Class: SFML::BlendMode
- Inherits:
-
Object
- Object
- SFML::BlendMode
- Defined in:
- lib/sfml/graphics/blend_mode.rb
Overview
How source pixels combine with destination pixels when drawing. Use the named constants for the common cases:
window.draw(sprite, blend_mode: SFML::BlendMode::ADD)
ADD — bright shapes accumulate (great for glow / lighting) MULTIPLY — darken (shadows, screen-style overlays) MIN / MAX — pick the darker / brighter pixel NONE — overwrite, ignoring the destination ALPHA — the default; src*α blended onto dst
Build a custom mode with kwargs:
SFML::BlendMode.new(
color_src: :src_alpha, color_dst: :one, color_eq: :add,
alpha_src: :one, alpha_dst: :one, alpha_eq: :add,
)
Constant Summary collapse
- FACTORS =
Order matches sfBlendFactor in CSFML 3.
%i[ zero one src_color one_minus_src_color dst_color one_minus_dst_color src_alpha one_minus_src_alpha dst_alpha one_minus_dst_alpha ].freeze
- FACTOR_INDEX =
Blend-factor symbol → integer Hash.
FACTORS.each_with_index.to_h.freeze
- EQUATIONS =
Blend-equation symbols in CSFML enum order.
%i[add subtract reverse_subtract min max].freeze
- EQUATION_INDEX =
Blend-equation symbol → integer Hash.
EQUATIONS.each_with_index.to_h.freeze
- ALPHA =
Built-in modes — read straight out of CSFML's global constants so we never have to hand-maintain the canonical factor lists.
from_native(C::Graphics.sfBlendAlpha)
- ADD =
from_native(C::Graphics.sfBlendAdd)
- MULTIPLY =
from_native(C::Graphics.sfBlendMultiply)
- MIN =
from_native(C::Graphics.sfBlendMin)
- MAX =
from_native(C::Graphics.sfBlendMax)
- NONE =
The 0.0.0.0 / empty placeholder address.
from_native(C::Graphics.sfBlendNone)
Instance Attribute Summary collapse
-
#alpha_dst ⇒ Object
readonly
The color src, color dst, color eq components.
-
#alpha_eq ⇒ Object
readonly
The color src, color dst, color eq components.
-
#alpha_src ⇒ Object
readonly
The color src, color dst, color eq components.
-
#color_dst ⇒ Object
readonly
The color src, color dst, color eq components.
-
#color_eq ⇒ Object
readonly
The color src, color dst, color eq components.
-
#color_src ⇒ Object
readonly
The color src, color dst, color eq components.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#hash ⇒ Object
Returns the hash.
-
#initialize(color_src:, color_dst:, color_eq:, alpha_src:, alpha_dst:, alpha_eq:) ⇒ BlendMode
constructor
A new instance of BlendMode.
-
#to_s ⇒ Object
(also: #inspect)
Returns the to s.
Constructor Details
#initialize(color_src:, color_dst:, color_eq:, alpha_src:, alpha_dst:, alpha_eq:) ⇒ BlendMode
Returns a new instance of BlendMode.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sfml/graphics/blend_mode.rb', line 37 def initialize(color_src:, color_dst:, color_eq:, alpha_src:, alpha_dst:, alpha_eq:) @color_src = _check_factor(color_src) @color_dst = _check_factor(color_dst) @color_eq = _check_equation(color_eq) @alpha_src = _check_factor(alpha_src) @alpha_dst = _check_factor(alpha_dst) @alpha_eq = _check_equation(alpha_eq) freeze end |
Instance Attribute Details
#alpha_dst ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def alpha_dst @alpha_dst end |
#alpha_eq ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def alpha_eq @alpha_eq end |
#alpha_src ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def alpha_src @alpha_src end |
#color_dst ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def color_dst @color_dst end |
#color_eq ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def color_eq @color_eq end |
#color_src ⇒ Object (readonly)
The color src, color dst, color eq components.
34 35 36 |
# File 'lib/sfml/graphics/blend_mode.rb', line 34 def color_src @color_src end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
48 49 50 51 52 |
# File 'lib/sfml/graphics/blend_mode.rb', line 48 def ==(other) other.is_a?(BlendMode) && color_src == other.color_src && color_dst == other.color_dst && color_eq == other.color_eq && alpha_src == other.alpha_src && alpha_dst == other.alpha_dst && alpha_eq == other.alpha_eq end |
#hash ⇒ Object
Returns the hash.
55 |
# File 'lib/sfml/graphics/blend_mode.rb', line 55 def hash = [color_src, color_dst, color_eq, alpha_src, alpha_dst, alpha_eq].hash |
#to_s ⇒ Object Also known as: inspect
Returns the to s.
58 59 60 |
# File 'lib/sfml/graphics/blend_mode.rb', line 58 def to_s "BlendMode(color: #{color_src}/#{color_dst}/#{color_eq}, alpha: #{alpha_src}/#{alpha_dst}/#{alpha_eq})" end |