Date:2014-07-19 12:06:09 (4 months 9 days ago)
Author:Maarten ter Huurne
Commit:79dcc8a146f3db3120453b62ad338a0b51c04eea
Message: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.
Files: src/gmenu2x.cpp (1 diff)
src/surface.cpp (2 diffs)
src/surface.h (2 diffs)

Change Details

src/gmenu2x.cpp
549549
550550        int i;
551551        for (i = 0; i < NUM_COLORS; ++i) {
552            inf << colorToString((enum color)i) << "=#";
553            inf.width(2); inf.fill('0');
554            inf << right << hex << skinConfColors[i].r;
555            inf.width(2); inf.fill('0');
556            inf << right << hex << skinConfColors[i].g;
557            inf.width(2); inf.fill('0');
558            inf << right << hex << skinConfColors[i].b;
559            inf.width(2); inf.fill('0');
560            inf << right << hex << skinConfColors[i].a << endl;
552            inf << colorToString((enum color)i) << "=#"
553                << skinConfColors[i] << endl;
561554        }
562555
563556        inf.close();
src/surface.cpp
2727
2828#include <algorithm>
2929#include <cassert>
30#include <iostream>
30#include <iomanip>
3131
3232using namespace std;
3333
...... 
4444    };
4545}
4646
47ostream& operator<<(ostream& os, RGBAColor const& color) {
48    auto oldfill = os.fill('0');
49    auto oldflags = os.setf(ios::hex | ios::right,
50                            ios::basefield | ios::adjustfield);
51    os << setw(2) << uint32_t(color.r)
52       << setw(2) << uint32_t(color.g)
53       << setw(2) << uint32_t(color.b)
54       << setw(2) << uint32_t(color.a);
55    os.fill(oldfill);
56    os.setf(oldflags);
57    return os;
58}
59
4760Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
4861    SDL_ShowCursor(SDL_DISABLE);
4962    SDL_Surface *raw = SDL_SetVideoMode(
src/surface.h
2424#include "font.h"
2525
2626#include <SDL.h>
27#include <string>
27
2828#include <cstdint>
29#include <ostream>
30#include <string>
2931
3032struct RGBAColor {
3133    uint8_t r, g, b, a;
...... 
3335    RGBAColor() : r(0), g(0), b(0), a(0) {}
3436    RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
3537        : r(r), g(g), b(b), a(a) {}
36    Uint32 pixelValue(SDL_PixelFormat *fmt) {
38    Uint32 pixelValue(SDL_PixelFormat *fmt) const {
3739        return SDL_MapRGBA(fmt, r, g, b, a);
3840    }
3941};
42std::ostream& operator<<(std::ostream& os, RGBAColor const& color);
4043
4144/**
4245    Wrapper around SDL_Surface

Archive Download the corresponding diff file



interactive