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 =
FACTORS.each_with_index.to_h.freeze
- EQUATIONS =
%i[add subtract reverse_subtract min max].freeze
- EQUATION_INDEX =
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 =
from_native(C::Graphics.sfBlendNone)
Instance Attribute Summary collapse
-
#alpha_dst ⇒ Object
readonly
Returns the value of attribute alpha_dst.
-
#alpha_eq ⇒ Object
readonly
Returns the value of attribute alpha_eq.
-
#alpha_src ⇒ Object
readonly
Returns the value of attribute alpha_src.
-
#color_dst ⇒ Object
readonly
Returns the value of attribute color_dst.
-
#color_eq ⇒ Object
readonly
Returns the value of attribute color_eq.
-
#color_src ⇒ Object
readonly
Returns the value of attribute color_src.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#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)
Constructor Details
#initialize(color_src:, color_dst:, color_eq:, alpha_src:, alpha_dst:, alpha_eq:) ⇒ BlendMode
Returns a new instance of BlendMode.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sfml/graphics/blend_mode.rb', line 33 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)
Returns the value of attribute alpha_dst.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def alpha_dst @alpha_dst end |
#alpha_eq ⇒ Object (readonly)
Returns the value of attribute alpha_eq.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def alpha_eq @alpha_eq end |
#alpha_src ⇒ Object (readonly)
Returns the value of attribute alpha_src.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def alpha_src @alpha_src end |
#color_dst ⇒ Object (readonly)
Returns the value of attribute color_dst.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def color_dst @color_dst end |
#color_eq ⇒ Object (readonly)
Returns the value of attribute color_eq.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def color_eq @color_eq end |
#color_src ⇒ Object (readonly)
Returns the value of attribute color_src.
30 31 32 |
# File 'lib/sfml/graphics/blend_mode.rb', line 30 def color_src @color_src end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
44 45 46 47 48 |
# File 'lib/sfml/graphics/blend_mode.rb', line 44 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
50 |
# File 'lib/sfml/graphics/blend_mode.rb', line 50 def hash = [color_src, color_dst, color_eq, alpha_src, alpha_dst, alpha_eq].hash |
#to_s ⇒ Object Also known as: inspect
52 53 54 |
# File 'lib/sfml/graphics/blend_mode.rb', line 52 def to_s "BlendMode(color: #{color_src}/#{color_dst}/#{color_eq}, alpha: #{alpha_src}/#{alpha_dst}/#{alpha_eq})" end |