indexing description: "[ Color palette for the EiffelMedia library. ]" date: "$Date$" revision: "$Revision$" class EM_PALETTE create {EM_PIXELFORMAT} make_from_pointer feature {NONE} -- Initialization make_from_pointer (a_pointer: POINTER) is -- Create a color palette. do create sdl_palette_struct.make_shared (a_pointer) end feature -- Access number_of_colors: INTEGER is -- Number of colors in palette do Result := sdl_palette_struct.ncolors end color (index: INTEGER): EM_COLOR is -- Color at `index' in palette require index_valid: 0 <= index and index < number_of_colors do create Result.make_from_pointer (sdl_palette_struct.colors + index*sdl_color_struct_size) ensure color_not_void: Result /= Void end feature -- Element change set_color (a_color: EM_COLOR; index: INTEGER) is -- Set color at `an_index' to `a_color'. require index_valid: 0 <= index and index < number_of_colors local pointer_in_palette: POINTER do pointer_in_palette := sdl_palette_struct.colors + (index * sdl_color_struct_size) ($pointer_in_palette).memory_copy (a_color.sdl_pointer, sdl_color_struct_size) ensure color_set: True end feature {EM_PIXELFORMAT} -- Implementation sdl_palette_struct: SDL_PALETTE_STRUCT -- SDL struct of palette sdl_color_struct_size: INTEGER is -- Size of SDL Color struct local ewg_struct: EWG_STRUCT once -- Workaround since SDL_COLOR_STRUCT exports 'sizeof' to NONE, but EWG_STRUCT exports it to ANY create {SDL_COLOR_STRUCT}ewg_struct.make_new_unshared Result := ewg_struct.sizeof end invariant sdl_palette_strucht_not_void: sdl_palette_struct /= Void end