Sha256: 4938ca2c2a311d9e47d6e32b195cb3b0103ae79a2349aa5a9672c82354cbe071

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
# License: Ruby License

module SGL
  def background(*a)	$__a__.background(*a);	end
  def backgroundHSV(*a)	$__a__.backgroundHSV(*a);	end
  def color(*a)		$__a__.color(*a);	end
  def colorHSV(*a)	$__a__.colorHSV(*a);	end

  class Application
    def initialize_color
      @bg_color = @cur_color = nil
      @rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
      @hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
    end
    private :initialize_color
    attr_reader :cur_color

    def background(x, y=nil, z=nil, a=nil)
      @bg_color = @rgb.norm(x,y,z,a)
    end

    def backgroundHSV(x, y=nil, z=nil, a=nil)
      @bg_color = @hsv.norm(x,y,z,a)
    end

    def color(x, y=nil, z=nil, a=nil)
      @cur_color = @rgb.norm(x,y,z,a)
      set_cur_color
    end

    def colorHSV(x, y=nil, z=nil, a=nil)
      @cur_color = @hsv.norm(x,y,z,a)
      set_cur_color
    end

    # called from cocoa-media
    # Since thie method called from NSFont, this should be public.
    def make_cur_color
      make_color(*@cur_color)
    end

    def get_cur_color_alpha
      @cur_color[3]
    end

    # private
    def set_cur_color
      set_color(*@cur_color)
    end

    def set_cur_bg
      set_color(*@bg_color)
    end

    def set_color(*a)
      make_color(*a).set if @win
    end

    def make_color(r, g, b, a)
      OSX::NSColor.colorWithDeviceRed(r, :green, g, :blue, b, :alpha, a)
    end
    private :set_cur_color, :set_cur_bg, :set_color, :make_color
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sgl-1.0.0 lib/sgl/cocoa-color.rb