1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-06-30 21:02:21 +03:00

Implemented stream output for RGBAColor

In commit 950518f3 I changed the component type of RGBAColor from
16-bit to 8-bit integers. Unfortunately, in C++ 8-bit integers are
identical to characters, so this broke the writing of colors to
output streams.
This commit is contained in:
Maarten ter Huurne 2014-07-19 12:06:09 +02:00
parent 69d6c0006c
commit 79dcc8a146
3 changed files with 21 additions and 12 deletions

View File

@ -549,15 +549,8 @@ void GMenu2X::writeSkinConfig() {
int i;
for (i = 0; i < NUM_COLORS; ++i) {
inf << colorToString((enum color)i) << "=#";
inf.width(2); inf.fill('0');
inf << right << hex << skinConfColors[i].r;
inf.width(2); inf.fill('0');
inf << right << hex << skinConfColors[i].g;
inf.width(2); inf.fill('0');
inf << right << hex << skinConfColors[i].b;
inf.width(2); inf.fill('0');
inf << right << hex << skinConfColors[i].a << endl;
inf << colorToString((enum color)i) << "=#"
<< skinConfColors[i] << endl;
}
inf.close();

View File

@ -27,7 +27,7 @@
#include <algorithm>
#include <cassert>
#include <iostream>
#include <iomanip>
using namespace std;
@ -44,6 +44,19 @@ RGBAColor RGBAColor::fromString(const string &strColor) {
};
}
ostream& operator<<(ostream& os, RGBAColor const& color) {
auto oldfill = os.fill('0');
auto oldflags = os.setf(ios::hex | ios::right,
ios::basefield | ios::adjustfield);
os << setw(2) << uint32_t(color.r)
<< setw(2) << uint32_t(color.g)
<< setw(2) << uint32_t(color.b)
<< setw(2) << uint32_t(color.a);
os.fill(oldfill);
os.setf(oldflags);
return os;
}
Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
SDL_ShowCursor(SDL_DISABLE);
SDL_Surface *raw = SDL_SetVideoMode(

View File

@ -24,8 +24,10 @@
#include "font.h"
#include <SDL.h>
#include <string>
#include <cstdint>
#include <ostream>
#include <string>
struct RGBAColor {
uint8_t r, g, b, a;
@ -33,10 +35,11 @@ struct RGBAColor {
RGBAColor() : r(0), g(0), b(0), a(0) {}
RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
: r(r), g(g), b(b), a(a) {}
Uint32 pixelValue(SDL_PixelFormat *fmt) {
Uint32 pixelValue(SDL_PixelFormat *fmt) const {
return SDL_MapRGBA(fmt, r, g, b, a);
}
};
std::ostream& operator<<(std::ostream& os, RGBAColor const& color);
/**
Wrapper around SDL_Surface