### Home Classes Methods

### In Files

- lib/rubygame/color/palettes/palette.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #include
- #uninclude

### Files

- CREDITS
- LICENSE
- NEWS
- README
- ROADMAP
- custom_sdl_load_paths.rdoc
- getting_started.rdoc
- keyboard_symbols.rdoc
- macosx_install.rdoc
- managing_framerate.rdoc
- surface_palettes.rdoc
- windows_install.rdoc

### Class/Module Index

Quicksearch

- Rubygame
- Rubygame::ActiveEvent
- Rubygame::Clock
- Rubygame::Color
- Rubygame::Color::ColorBase
- Rubygame::Color::ColorHSL
- Rubygame::Color::ColorHSV
- Rubygame::Color::ColorRGB
- Rubygame::Color::Palette
- Rubygame::Event
- Rubygame::EventActions
- Rubygame::EventActions::BlockAction
- Rubygame::EventActions::MethodAction
- Rubygame::EventActions::MultiAction
- Rubygame::EventHandler
- Rubygame::EventHandler::HasEventHandler
- Rubygame::EventHook
- Rubygame::EventQueue
- Rubygame::EventTriggers
- Rubygame::EventTriggers::AndTrigger
- Rubygame::EventTriggers::AttrTrigger
- Rubygame::EventTriggers::BlockTrigger
- Rubygame::EventTriggers::InstanceOfTrigger
- Rubygame::EventTriggers::KeyPressTrigger
- Rubygame::EventTriggers::KeyReleaseTrigger
- Rubygame::EventTriggers::KindOfTrigger
- Rubygame::EventTriggers::MouseMoveTrigger
- Rubygame::EventTriggers::MousePressTrigger
- Rubygame::EventTriggers::MouseReleaseTrigger
- Rubygame::EventTriggers::OrTrigger
- Rubygame::EventTriggers::TickTrigger
- Rubygame::EventTriggers::YesTrigger
- Rubygame::Events
- Rubygame::Events::ClockTicked
- Rubygame::Events::InputFocusGained
- Rubygame::Events::InputFocusLost
- Rubygame::Events::JoystickAxisMoved
- Rubygame::Events::JoystickBallMoved
- Rubygame::Events::JoystickButtonEvent
- Rubygame::Events::JoystickButtonPressed
- Rubygame::Events::JoystickButtonReleased
- Rubygame::Events::JoystickHatMoved
- Rubygame::Events::KeyPressed
- Rubygame::Events::KeyReleased
- Rubygame::Events::KeyboardEvent
- Rubygame::Events::MouseButtonEvent
- Rubygame::Events::MouseFocusGained
- Rubygame::Events::MouseFocusLost
- Rubygame::Events::MouseMoved
- Rubygame::Events::MousePressed
- Rubygame::Events::MouseReleased
- Rubygame::Events::QuitRequested
- Rubygame::Events::WindowExposed
- Rubygame::Events::WindowMinimized
- Rubygame::Events::WindowResized
- Rubygame::Events::WindowUnminimized
- Rubygame::ExposeEvent
- Rubygame::Ftor
- Rubygame::GL
- Rubygame::Hotspot
- Rubygame::JoyAxisEvent
- Rubygame::JoyBallEvent
- Rubygame::JoyDownEvent
- Rubygame::JoyHatEvent
- Rubygame::JoyUpEvent
- Rubygame::Joystick
- Rubygame::Key
- Rubygame::KeyDownEvent
- Rubygame::KeyUpEvent
- Rubygame::MailQueue
- Rubygame::MediaBag
- Rubygame::Mixer
- Rubygame::Mixer::Music
- Rubygame::Mixer::Sample
- Rubygame::Mouse
- Rubygame::MouseDownEvent
- Rubygame::MouseMotionEvent
- Rubygame::MouseUpEvent
- Rubygame::Music
- Rubygame::NamedResource
- Rubygame::NamedResource::NamedResourceClassMethods
- Rubygame::QuitEvent
- Rubygame::Rect
- Rubygame::ResizeEvent
- Rubygame::SDLError
- Rubygame::SFont
- Rubygame::Screen
- Rubygame::Sound
- Rubygame::Sprites
- Rubygame::Sprites::DepthSortGroup
- Rubygame::Sprites::Group
- Rubygame::Sprites::LimitGroup
- Rubygame::Sprites::Sprite
- Rubygame::Sprites::UpdateGroup
- Rubygame::Surface
- Rubygame::TTF

No matching classes.

# Rubygame::Color::Palette

### Public Class Methods

new( colors = {} ) click to toggle source

Create a new Palette with the given name => color pairs.

    # File lib/rubygame/color/palettes/palette.rb, line 23
    def initialize( colors = {} )
            @includes = []

            @colors = {}
            colors.each_pair do |name, color|
                    @colors[sanitize_name(name)] = color
            end
    end

### Public Instance Methods

[]( name ) click to toggle source

Retrieve a color by name from this palette.

The name can be a Symbol or String. See sanitize_name.

If the color cannot be found in this palette, search each of the included palettes (recursively, depth-first, to a maximum depth of 5 levels).

If the color is not found in this palette or any included palettes, raise IndexError.

    # File lib/rubygame/color/palettes/palette.rb, line 43
    def []( name )
            c = lookup( sanitize_name( name ) )
            raise IndexError, "unknown color #{name}" unless c
            return c
    end

[]=( name, color ) click to toggle source

Store a color by name in this palette. See sanitize_name

    # File lib/rubygame/color/palettes/palette.rb, line 50
    def []=( name, color )
            name = sanitize_name( name )
            @colors[name] = color
    end

include( palette ) click to toggle source

Include another palette in this one. If a color cannot be found in this palette, the included palette(s) will be searched. See also uninclude.

Has no effect if the palette is already included.

    # File lib/rubygame/color/palettes/palette.rb, line 60
    def include( palette )
            @includes += [palette] unless @includes.include? palette
    end

uninclude( palette ) click to toggle source

Remove the other palette from this one, so that it won't be searched for missing colors anymore. Has no effect if the other palette hasn't been included.

    # File lib/rubygame/color/palettes/palette.rb, line 67
    def uninclude( palette )
            @includes -= [palette]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.