mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-23 12:53:50 +00:00
Added pixel() to Rend2D::Sprite
This commit is contained in:
parent
7345f2307f
commit
593ac7b240
3 changed files with 40 additions and 0 deletions
|
@ -7,6 +7,38 @@
|
|||
|
||||
using namespace Mangle::Rend2D;
|
||||
|
||||
// This is a really crappy and slow implementation
|
||||
void SDL_Sprite::pixel(int x, int y, int color)
|
||||
{
|
||||
SDL_LockSurface(surface);
|
||||
|
||||
int bpp = surface->format->BytesPerPixel;
|
||||
char *p = (char*)surface->pixels + y*surface->pitch + x*bpp;
|
||||
|
||||
switch(bpp)
|
||||
{
|
||||
case 1: *p = color; break;
|
||||
case 3:
|
||||
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
{
|
||||
p[0] = (color >> 16) & 0xff;
|
||||
p[1] = (color >> 8) & 0xff;
|
||||
p[2] = color & 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
p[0] = color & 0xff;
|
||||
p[1] = (color >> 8) & 0xff;
|
||||
p[2] = (color >> 16) & 0xff;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
*(int*)p = color;
|
||||
break;
|
||||
}
|
||||
SDL_UnlockSurface(surface);
|
||||
}
|
||||
|
||||
void SDL_Sprite::draw(Sprite *s, // Must be SDL_Sprite
|
||||
int x, int y, // Destination position
|
||||
int sx, int sy, // Source position
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace Mangle
|
|||
// Fill with a given pixel value
|
||||
void fill(int value);
|
||||
|
||||
// Set one pixel
|
||||
void pixel(int x, int y, int value);
|
||||
|
||||
private:
|
||||
// The SDL surface
|
||||
SDL_Surface* surface;
|
||||
|
|
|
@ -28,6 +28,11 @@ namespace Mangle
|
|||
/// Fill the sprite with the given pixel value. The pixel format
|
||||
/// depends on the format of the sprite.
|
||||
virtual void fill(int value) = 0;
|
||||
|
||||
/// Set one pixel value. The pixel format depends on the sprite
|
||||
/// format. This is not expected to be fast, and in some
|
||||
/// implementations may not work at all.
|
||||
virtual void pixel(int x, int y, int value) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue