1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-10-04 02:08:32 +03:00
gmenu2x/src/surface.h
Maarten ter Huurne 950518f3a7 Made RGBAColor components 8 bits wide
The values are all in the range 0..255, so storing more than 8 bits
is wasteful.
2014-07-19 00:43:05 +02:00

99 lines
3.9 KiB
C++

/***************************************************************************
* Copyright (C) 2006 by Massimiliano Torromeo *
* massimiliano.torromeo@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef SURFACE_H
#define SURFACE_H
#include "font.h"
#include <SDL.h>
#include <string>
#include <cstdint>
struct RGBAColor {
uint8_t r, g, b, a;
};
RGBAColor strtorgba(const std::string &strColor);
/**
Wrapper around SDL_Surface
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
*/
class Surface {
public:
static Surface *openOutputSurface(int width, int height, int bitsperpixel);
static Surface *emptySurface(int width, int height);
static Surface *loadImage(const std::string &img,
const std::string &skin="", bool loadAlpha=true);
Surface(Surface *s);
~Surface();
/** Converts the underlying surface to the same pixel format as the frame
* buffer, for faster blitting. This removes the alpha channel if the
* image has done.
*/
void convertToDisplayFormat();
int width() const { return raw->w; }
int height() const { return raw->h; }
void flip();
void clearClipRect();
void setClipRect(int x, int y, int w, int h);
void setClipRect(SDL_Rect rect);
void blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const;
void blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void write(Font *font, const std::string &text, int x, int y,
Font::HAlign halign = Font::HAlignLeft,
Font::VAlign valign = Font::VAlignTop) {
font->write(this, text, x, y, halign, valign);
}
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor);
void box(SDL_Rect, RGBAColor);
void rectangle(Sint16, Sint16, Uint16, Uint16, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void rectangle(Sint16, Sint16, Uint16, Uint16, RGBAColor);
void rectangle(SDL_Rect, RGBAColor);
private:
Surface(SDL_Surface *raw, bool freeWhenDone);
void blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
SDL_Surface *raw;
bool freeWhenDone;
int halfW, halfH;
// For direct access to "raw".
friend class Font;
};
#endif