/* * call-seq: * set_at([x,y], color) * * Set the color of the pixel at the given coordinate. * * color can be one of: * * an Array, [r,g,b] or [r,g,b,a] with each component in 0-255 * * an instance of ColorRGB, ColorHSV, etc. * * the name of a color in Rubygame::Color, as a Symbol or String * * Raises IndexError if the coordinates are out of bounds. * *-- * * I'm lazy and just using SDL_FillRect. ;-P * It's easier and less bug-prone this way. * I have no idea about speed comparisons. * */ VALUE rbgm_surface_setat( int argc, VALUE *argv, VALUE self ) { SDL_Surface *surf; SDL_Rect *rect; Uint32 color; Uint8 r,g,b,a; VALUE vpos, vcolor; Data_Get_Struct(self, SDL_Surface, surf); rb_scan_args(argc, argv, "2", &vpos, &vcolor); vcolor = convert_color(vcolor); extract_rgba_u8_as_u8(vcolor, &r, &g, &b, &a); color = SDL_MapRGBA(surf->format, r,g,b,a); vpos = convert_to_array(vpos); rect = make_rect( NUM2INT(rb_ary_entry(vpos,0)), NUM2INT(rb_ary_entry(vpos,1)), 1, 1 ); SDL_FillRect(surf,rect,color); free(rect); return self; }