Sha256: 0134d3c33f2e9efda8719ed4865d89ef9a531e1cd2dee26deb39898ac0c3fcf6

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

class Shoes
  module Swt
    class Color
      include DisposedProtection

      def self.create(color)
        color ? new(color) : NullColor.new
      end

      # @param [Shoes::Color] color the DSL representation of this color
      def initialize(color)
        @dsl = color
        @real = ::Swt::Graphics::Color.new(Shoes.display, @dsl.red, @dsl.green, @dsl.blue)
      end

      attr_reader :dsl

      # @return [Integer] the alpha value, from 0 (transparent) to 255 (opaque)
      def alpha
        @dsl.alpha
      end

      # @param [Swt::Graphics::GC] gc the graphics context on which to apply fill
      # @note left, top, width, height, and angle are not used in this method, and only
      #   exist to satisfy the Pattern interface
      def apply_as_fill(gc, left = nil, top = nil, width = nil, height = nil, angle = nil)
        gc.set_background real
        gc.set_alpha alpha
      end

      # @param [Swt::Graphics::GC] gc the graphics context on which to apply stroke
      def apply_as_stroke(gc, left = nil, top = nil, width = nil, height = nil, angle = nil)
        gc.set_foreground real
        gc.set_alpha alpha
      end
    end

    class NullColor
      attr_reader :alpha, :dsl, :real
      def apply_as_fill(gc); end
      def apply_as_stroke(gc); end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-4.0.0.pre1 lib/shoes/swt/color.rb