Date: | 2014-07-19 12:06:09 (9 years 8 months 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 | ||
---|---|---|
549 | 549 | |
550 | 550 | int i; |
551 | 551 | 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; | |
561 | 554 | } |
562 | 555 | |
563 | 556 | inf.close(); |
src/surface.cpp | ||
---|---|---|
27 | 27 | |
28 | 28 | #include <algorithm> |
29 | 29 | #include <cassert> |
30 | #include <iostream> | |
30 | #include <iomanip> | |
31 | 31 | |
32 | 32 | using namespace std; |
33 | 33 | |
... | ... | |
44 | 44 | }; |
45 | 45 | } |
46 | 46 | |
47 | ostream& 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 | ||
47 | 60 | Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) { |
48 | 61 | SDL_ShowCursor(SDL_DISABLE); |
49 | 62 | SDL_Surface *raw = SDL_SetVideoMode( |
src/surface.h | ||
---|---|---|
24 | 24 | #include "font.h" |
25 | 25 | |
26 | 26 | #include <SDL.h> |
27 | #include <string> | |
27 | ||
28 | 28 | #include <cstdint> |
29 | #include <ostream> | |
30 | #include <string> | |
29 | 31 | |
30 | 32 | struct RGBAColor { |
31 | 33 | uint8_t r, g, b, a; |
... | ... | |
33 | 35 | RGBAColor() : r(0), g(0), b(0), a(0) {} |
34 | 36 | RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) |
35 | 37 | : r(r), g(g), b(b), a(a) {} |
36 | Uint32 pixelValue(SDL_PixelFormat *fmt) { | |
38 | Uint32 pixelValue(SDL_PixelFormat *fmt) const { | |
37 | 39 | return SDL_MapRGBA(fmt, r, g, b, a); |
38 | 40 | } |
39 | 41 | }; |
42 | std::ostream& operator<<(std::ostream& os, RGBAColor const& color); | |
40 | 43 | |
41 | 44 | /** |
42 | 45 | Wrapper around SDL_Surface |
Branches:
install_locations
master
opkrun
packages