(Rgb) : New for CSS3COLOR support.
@@ -57,15 +57,15 @@ | ||
57 | 57 | libes___a_AR = $(AR) $(ARFLAGS) |
58 | 58 | libes___a_LIBADD = |
59 | 59 | am__libes___a_SOURCES_DIST = src/md5.c src/rand48.c src/string.c \ |
60 | - src/utf.c src/apply.cpp src/context.cpp src/dateTime.cpp \ | |
61 | - src/dump.cpp src/inet.cpp src/throw.cpp src/formatter.cpp \ | |
62 | - src/ring.cpp include/core.h src/report.cpp src/system.cpp \ | |
63 | - src/posix_system.cpp | |
60 | + src/utf.c src/apply.cpp src/color.cpp src/context.cpp \ | |
61 | + src/dateTime.cpp src/dump.cpp src/inet.cpp src/throw.cpp \ | |
62 | + src/formatter.cpp src/ring.cpp include/core.h src/report.cpp \ | |
63 | + src/system.cpp src/posix_system.cpp | |
64 | 64 | am__objects_1 = md5.$(OBJEXT) rand48.$(OBJEXT) string.$(OBJEXT) \ |
65 | 65 | utf.$(OBJEXT) |
66 | -am__objects_2 = apply.$(OBJEXT) context.$(OBJEXT) dateTime.$(OBJEXT) \ | |
67 | - dump.$(OBJEXT) inet.$(OBJEXT) throw.$(OBJEXT) \ | |
68 | - formatter.$(OBJEXT) ring.$(OBJEXT) | |
66 | +am__objects_2 = apply.$(OBJEXT) color.$(OBJEXT) context.$(OBJEXT) \ | |
67 | + dateTime.$(OBJEXT) dump.$(OBJEXT) inet.$(OBJEXT) \ | |
68 | + throw.$(OBJEXT) formatter.$(OBJEXT) ring.$(OBJEXT) | |
69 | 69 | am__objects_3 = |
70 | 70 | am__objects_4 = $(am__objects_1) $(am__objects_2) $(am__objects_3) |
71 | 71 | @ES_TRUE@am__objects_5 = system.$(OBJEXT) |
@@ -222,6 +222,7 @@ | ||
222 | 222 | |
223 | 223 | cpp_source_files = \ |
224 | 224 | src/apply.cpp \ |
225 | + src/color.cpp \ | |
225 | 226 | src/context.cpp \ |
226 | 227 | src/dateTime.cpp \ |
227 | 228 | src/dump.cpp \ |
@@ -314,6 +315,7 @@ | ||
314 | 315 | -rm -f *.tab.c |
315 | 316 | |
316 | 317 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apply.Po@am__quote@ |
318 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/color.Po@am__quote@ | |
317 | 319 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/context.Po@am__quote@ |
318 | 320 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dateTime.Po@am__quote@ |
319 | 321 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump.Po@am__quote@ |
@@ -427,6 +429,20 @@ | ||
427 | 429 | @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
428 | 430 | @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o apply.obj `if test -f 'src/apply.cpp'; then $(CYGPATH_W) 'src/apply.cpp'; else $(CYGPATH_W) '$(srcdir)/src/apply.cpp'; fi` |
429 | 431 | |
432 | +color.o: src/color.cpp | |
433 | +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT color.o -MD -MP -MF $(DEPDIR)/color.Tpo -c -o color.o `test -f 'src/color.cpp' || echo '$(srcdir)/'`src/color.cpp | |
434 | +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/color.Tpo $(DEPDIR)/color.Po | |
435 | +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='src/color.cpp' object='color.o' libtool=no @AMDEPBACKSLASH@ | |
436 | +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
437 | +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o color.o `test -f 'src/color.cpp' || echo '$(srcdir)/'`src/color.cpp | |
438 | + | |
439 | +color.obj: src/color.cpp | |
440 | +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT color.obj -MD -MP -MF $(DEPDIR)/color.Tpo -c -o color.obj `if test -f 'src/color.cpp'; then $(CYGPATH_W) 'src/color.cpp'; else $(CYGPATH_W) '$(srcdir)/src/color.cpp'; fi` | |
441 | +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/color.Tpo $(DEPDIR)/color.Po | |
442 | +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='src/color.cpp' object='color.obj' libtool=no @AMDEPBACKSLASH@ | |
443 | +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
444 | +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o color.obj `if test -f 'src/color.cpp'; then $(CYGPATH_W) 'src/color.cpp'; else $(CYGPATH_W) '$(srcdir)/src/color.cpp'; fi` | |
445 | + | |
430 | 446 | context.o: src/context.cpp |
431 | 447 | @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT context.o -MD -MP -MF $(DEPDIR)/context.Tpo -c -o context.o `test -f 'src/context.cpp' || echo '$(srcdir)/'`src/context.cpp |
432 | 448 | @am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/context.Tpo $(DEPDIR)/context.Po |
@@ -0,0 +1,163 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2007 | |
3 | + * Nintendo Co., Ltd. | |
4 | + * | |
5 | + * Permission to use, copy, modify, distribute and sell this software | |
6 | + * and its documentation for any purpose is hereby granted without fee, | |
7 | + * provided that the above copyright notice appear in all copies and | |
8 | + * that both that copyright notice and this permission notice appear | |
9 | + * in supporting documentation. Nintendo makes no | |
10 | + * representations about the suitability of this software for any | |
11 | + * purpose. It is provided "as is" without express or implied warranty. | |
12 | + */ | |
13 | + | |
14 | +/* | |
15 | + * cf. CSS3 Color Module | |
16 | + * http://www.w3.org/TR/css3-color/ | |
17 | + */ | |
18 | + | |
19 | +#include <string.h> | |
20 | +#include <stdio.h> | |
21 | +#include <algorithm> | |
22 | +#include <es/color.h> | |
23 | + | |
24 | +namespace | |
25 | +{ | |
26 | + struct Keyword | |
27 | + { | |
28 | + const char* name; | |
29 | + u32 rgba; | |
30 | + }; | |
31 | + | |
32 | + Keyword keywords[] = | |
33 | + { | |
34 | + { "aqua", 0xffffff00 }, | |
35 | + { "black", 0xff000000 }, | |
36 | + { "blue", 0xffff0000 }, | |
37 | + { "fuchsia", 0xffff00ff }, | |
38 | + { "gray", 0xff808080 }, | |
39 | + { "green", 0xff008000 }, | |
40 | + { "lime", 0xff00ff00 }, | |
41 | + { "maroon", 0xff000080 }, | |
42 | + { "navy", 0xff800000 }, | |
43 | + { "olive", 0xff008080 }, | |
44 | + { "purple", 0xff800080 }, | |
45 | + { "red", 0xff0000ff }, | |
46 | + { "silver", 0xffc0c0c0 }, | |
47 | + { "teal", 0xff808000 }, | |
48 | + { "transparent", 0x00000000 }, | |
49 | + { "white", 0xffffffff }, | |
50 | + { "yellow", 0xff00ffff } | |
51 | + }; | |
52 | + | |
53 | + const size_t MaxKeywords = (sizeof keywords) / (sizeof keywords[0]); | |
54 | + const size_t MaxKeywordLen = 12; | |
55 | +} | |
56 | + | |
57 | +bool Rgb::assign(const char* color) | |
58 | +{ | |
59 | + if (*color == '#') | |
60 | + { | |
61 | + unsigned int r, g, b; | |
62 | + | |
63 | + switch (strnlen(color, 8)) | |
64 | + { | |
65 | + case 7: | |
66 | + if (sscanf(color, "#%2x%2x%2x", &r, &g, &b) == 3) | |
67 | + { | |
68 | + rgba = 0xff000000 | (b << 16) | (g << 8) | r; | |
69 | + return true; | |
70 | + } | |
71 | + break; | |
72 | + case 4: | |
73 | + if (sscanf(color, "#%1x%1x%1x", &r, &g, &b) == 3) | |
74 | + { | |
75 | + r |= (r << 4); | |
76 | + g |= (g << 4); | |
77 | + b |= (b << 4); | |
78 | + rgba = 0xff000000 | (b << 16) | (g << 8) | r; | |
79 | + return true; | |
80 | + } | |
81 | + break; | |
82 | + } | |
83 | + } | |
84 | + else if (strncasecmp(color, "rgb(", 4) == 0) | |
85 | + { | |
86 | + int r, g, b; | |
87 | + float s, t, u; | |
88 | + | |
89 | + if (sscanf(color + 3, "(%d,%d,%d)", &r, &g, &b) == 3) | |
90 | + { | |
91 | + r = std::max(0, std::min(255, r)); | |
92 | + g = std::max(0, std::min(255, g)); | |
93 | + b = std::max(0, std::min(255, b)); | |
94 | + rgba = 0xff000000 | (b << 16) | (g << 8) | r; | |
95 | + return true; | |
96 | + } | |
97 | + else if (sscanf(color + 3, "(%f%%,%f%%,%f%%)", &s, &t, &u) == 3) | |
98 | + { | |
99 | + s = std::max(0.0f, std::min(100.0f, s)); | |
100 | + t = std::max(0.0f, std::min(100.0f, t)); | |
101 | + u = std::max(0.0f, std::min(100.0f, u)); | |
102 | + r = static_cast<int>(255.0f * (s / 100.0f)); | |
103 | + g = static_cast<int>(255.0f * (t / 100.0f)); | |
104 | + b = static_cast<int>(255.0f * (u / 100.0f)); | |
105 | + rgba = 0xff000000 | (b << 16) | (g << 8) | r; | |
106 | + return true; | |
107 | + } | |
108 | + } | |
109 | + else if (strncasecmp(color, "rgba(", 5) == 0) | |
110 | + { | |
111 | + int r, g, b, a; | |
112 | + float s, t, u, v; | |
113 | + | |
114 | + if (sscanf(color + 4, "(%d,%d,%d,%f)", &r, &g, &b, &v) == 4) | |
115 | + { | |
116 | + r = static_cast<int>(std::max(0, std::min(255, r))); | |
117 | + g = static_cast<int>(std::max(0, std::min(255, g))); | |
118 | + b = static_cast<int>(std::max(0, std::min(255, b))); | |
119 | + v = std::max(0.0f, std::min(1.0f, v)); | |
120 | + a = static_cast<int>(255.0f * v); | |
121 | + rgba = (a << 24) | (b << 16) | (g << 8) | r; | |
122 | + return true; | |
123 | + } | |
124 | + else if (sscanf(color + 4, "(%f%%,%f%%,%f%%,%f)", &s, &t, &u, &v) == 4) | |
125 | + { | |
126 | + s = std::max(0.0f, std::min(100.0f, s)); | |
127 | + t = std::max(0.0f, std::min(100.0f, t)); | |
128 | + u = std::max(0.0f, std::min(100.0f, u)); | |
129 | + v = std::max(0.0f, std::min(1.0f, v)); | |
130 | + r = static_cast<int>(255.0f * (s / 100.0f)); | |
131 | + g = static_cast<int>(255.0f * (t / 100.0f)); | |
132 | + b = static_cast<int>(255.0f * (u / 100.0f)); | |
133 | + a = static_cast<int>(255.0f * v); | |
134 | + rgba = (a << 24) | (b << 16) | (g << 8) | r; | |
135 | + return true; | |
136 | + } | |
137 | + } | |
138 | + else | |
139 | + { | |
140 | + int low = 0; | |
141 | + int high = MaxKeywords - 1; | |
142 | + while (low <= high) | |
143 | + { | |
144 | + int mid = static_cast<unsigned>(low + high) >> 1; | |
145 | + | |
146 | + int cond = strncasecmp(color, keywords[mid].name, MaxKeywordLen); | |
147 | + if (cond < 0) | |
148 | + { | |
149 | + high = mid - 1; | |
150 | + } | |
151 | + else if (cond == 0) | |
152 | + { | |
153 | + rgba = keywords[mid].rgba; | |
154 | + return true; | |
155 | + } | |
156 | + else if (0 < cond) | |
157 | + { | |
158 | + low = mid + 1; | |
159 | + } | |
160 | + } | |
161 | + } | |
162 | + return false; | |
163 | +} |
@@ -16,6 +16,7 @@ | ||
16 | 16 | |
17 | 17 | cpp_source_files = \ |
18 | 18 | src/apply.cpp \ |
19 | + src/color.cpp \ | |
19 | 20 | src/context.cpp \ |
20 | 21 | src/dateTime.cpp \ |
21 | 22 | src/dump.cpp \ |
@@ -0,0 +1,74 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2007 | |
3 | + * Nintendo Co., Ltd. | |
4 | + * | |
5 | + * Permission to use, copy, modify, distribute and sell this software | |
6 | + * and its documentation for any purpose is hereby granted without fee, | |
7 | + * provided that the above copyright notice appear in all copies and | |
8 | + * that both that copyright notice and this permission notice appear | |
9 | + * in supporting documentation. Nintendo makes no | |
10 | + * representations about the suitability of this software for any | |
11 | + * purpose. It is provided "as is" without express or implied warranty. | |
12 | + */ | |
13 | + | |
14 | +#include <assert.h> | |
15 | +#include <stdio.h> | |
16 | +#include <stdlib.h> | |
17 | +#include <es/color.h> | |
18 | + | |
19 | +int main() | |
20 | +{ | |
21 | + Rgb rgb; | |
22 | + printf("%08x\n", (u32) rgb); | |
23 | + | |
24 | + rgb = Rgb("#123"); | |
25 | + printf("%08x\n", (u32) rgb); | |
26 | + | |
27 | + rgb = Rgb("#123456"); | |
28 | + printf("%08x\n", (u32) rgb); | |
29 | + | |
30 | + rgb = Rgb("rgb(16, 32, 48)"); | |
31 | + printf("%08x\n", (u32) rgb); | |
32 | + | |
33 | + rgb = Rgb("rgb(100%, 50%, 25%)"); | |
34 | + printf("%08x\n", (u32) rgb); | |
35 | + | |
36 | + rgb = Rgb("rgba(16, 32, 48, 0.5)"); | |
37 | + printf("%08x\n", (u32) rgb); | |
38 | + | |
39 | + rgb = Rgb("rgba(100%, 50%, 25%, 0.25)"); | |
40 | + printf("%08x\n", (u32) rgb); | |
41 | + | |
42 | + rgb = Rgb("red"); | |
43 | + printf("%08x\n", (u32) rgb); | |
44 | + | |
45 | + rgb = Rgb("green"); | |
46 | + printf("%08x\n", (u32) rgb); | |
47 | + | |
48 | + rgb = Rgb("blue"); | |
49 | + printf("%08x\n", (u32) rgb); | |
50 | + | |
51 | + try | |
52 | + { | |
53 | + rgb = Rgb("a"); // lower bound | |
54 | + } | |
55 | + catch (...) | |
56 | + { | |
57 | + printf("error: %08x\n", (u32) rgb); | |
58 | + } | |
59 | + | |
60 | + try | |
61 | + { | |
62 | + rgb = Rgb("z"); // upper bound | |
63 | + } | |
64 | + catch (...) | |
65 | + { | |
66 | + printf("error: %08x\n", (u32) rgb); | |
67 | + } | |
68 | + | |
69 | + rgb = "transparent"; | |
70 | + printf("%08x\n", (u32) rgb); | |
71 | + | |
72 | + rgb = 0x123456; | |
73 | + printf("%08x\n", (u32) rgb); | |
74 | +} |
@@ -33,9 +33,9 @@ | ||
33 | 33 | build_triplet = @build@ |
34 | 34 | host_triplet = @host@ |
35 | 35 | target_triplet = @target@ |
36 | -@POSIX_TRUE@TESTS = collection$(EXEEXT) list$(EXEEXT) \ | |
37 | -@POSIX_TRUE@ hashtable$(EXEEXT) tree$(EXEEXT) rand$(EXEEXT) \ | |
38 | -@POSIX_TRUE@ smartptr$(EXEEXT) formatter$(EXEEXT) | |
36 | +@POSIX_TRUE@TESTS = collection$(EXEEXT) colorTest$(EXEEXT) \ | |
37 | +@POSIX_TRUE@ list$(EXEEXT) hashtable$(EXEEXT) tree$(EXEEXT) \ | |
38 | +@POSIX_TRUE@ rand$(EXEEXT) smartptr$(EXEEXT) formatter$(EXEEXT) | |
39 | 39 | @POSIX_TRUE@noinst_PROGRAMS = $(am__EXEEXT_1) |
40 | 40 | subdir = libes++/testsuite |
41 | 41 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in |
@@ -45,9 +45,9 @@ | ||
45 | 45 | $(ACLOCAL_M4) |
46 | 46 | mkinstalldirs = $(install_sh) -d |
47 | 47 | CONFIG_CLEAN_FILES = |
48 | -@POSIX_TRUE@am__EXEEXT_1 = collection$(EXEEXT) list$(EXEEXT) \ | |
49 | -@POSIX_TRUE@ hashtable$(EXEEXT) tree$(EXEEXT) rand$(EXEEXT) \ | |
50 | -@POSIX_TRUE@ smartptr$(EXEEXT) formatter$(EXEEXT) | |
48 | +@POSIX_TRUE@am__EXEEXT_1 = collection$(EXEEXT) colorTest$(EXEEXT) \ | |
49 | +@POSIX_TRUE@ list$(EXEEXT) hashtable$(EXEEXT) tree$(EXEEXT) \ | |
50 | +@POSIX_TRUE@ rand$(EXEEXT) smartptr$(EXEEXT) formatter$(EXEEXT) | |
51 | 51 | PROGRAMS = $(noinst_PROGRAMS) |
52 | 52 | am__collection_SOURCES_DIST = collection.cpp |
53 | 53 | @POSIX_TRUE@am_collection_OBJECTS = collection.$(OBJEXT) |
@@ -54,6 +54,11 @@ | ||
54 | 54 | collection_OBJECTS = $(am_collection_OBJECTS) |
55 | 55 | collection_LDADD = $(LDADD) |
56 | 56 | collection_DEPENDENCIES = ../libessup++.a |
57 | +am__colorTest_SOURCES_DIST = colorTest.cpp | |
58 | +@POSIX_TRUE@am_colorTest_OBJECTS = colorTest.$(OBJEXT) | |
59 | +colorTest_OBJECTS = $(am_colorTest_OBJECTS) | |
60 | +colorTest_LDADD = $(LDADD) | |
61 | +colorTest_DEPENDENCIES = ../libessup++.a | |
57 | 62 | am__formatter_SOURCES_DIST = formatter.cpp |
58 | 63 | @POSIX_TRUE@am_formatter_OBJECTS = formatter.$(OBJEXT) |
59 | 64 | formatter_OBJECTS = $(am_formatter_OBJECTS) |
@@ -92,13 +97,14 @@ | ||
92 | 97 | CXXLD = $(CXX) |
93 | 98 | CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ |
94 | 99 | -o $@ |
95 | -SOURCES = $(collection_SOURCES) $(formatter_SOURCES) \ | |
96 | - $(hashtable_SOURCES) $(list_SOURCES) $(rand_SOURCES) \ | |
97 | - $(smartptr_SOURCES) $(tree_SOURCES) | |
100 | +SOURCES = $(collection_SOURCES) $(colorTest_SOURCES) \ | |
101 | + $(formatter_SOURCES) $(hashtable_SOURCES) $(list_SOURCES) \ | |
102 | + $(rand_SOURCES) $(smartptr_SOURCES) $(tree_SOURCES) | |
98 | 103 | DIST_SOURCES = $(am__collection_SOURCES_DIST) \ |
99 | - $(am__formatter_SOURCES_DIST) $(am__hashtable_SOURCES_DIST) \ | |
100 | - $(am__list_SOURCES_DIST) $(am__rand_SOURCES_DIST) \ | |
101 | - $(am__smartptr_SOURCES_DIST) $(am__tree_SOURCES_DIST) | |
104 | + $(am__colorTest_SOURCES_DIST) $(am__formatter_SOURCES_DIST) \ | |
105 | + $(am__hashtable_SOURCES_DIST) $(am__list_SOURCES_DIST) \ | |
106 | + $(am__rand_SOURCES_DIST) $(am__smartptr_SOURCES_DIST) \ | |
107 | + $(am__tree_SOURCES_DIST) | |
102 | 108 | ETAGS = etags |
103 | 109 | CTAGS = ctags |
104 | 110 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) |
@@ -211,6 +217,7 @@ | ||
211 | 217 | -I $(srcdir)/../../../include |
212 | 218 | |
213 | 219 | @POSIX_TRUE@collection_SOURCES = collection.cpp |
220 | +@POSIX_TRUE@colorTest_SOURCES = colorTest.cpp | |
214 | 221 | @POSIX_TRUE@list_SOURCES = list.cpp |
215 | 222 | @POSIX_TRUE@hashtable_SOURCES = hashtable.cpp |
216 | 223 | @POSIX_TRUE@rand_SOURCES = rand.cpp |
@@ -256,6 +263,9 @@ | ||
256 | 263 | collection$(EXEEXT): $(collection_OBJECTS) $(collection_DEPENDENCIES) |
257 | 264 | @rm -f collection$(EXEEXT) |
258 | 265 | $(CXXLINK) $(collection_OBJECTS) $(collection_LDADD) $(LIBS) |
266 | +colorTest$(EXEEXT): $(colorTest_OBJECTS) $(colorTest_DEPENDENCIES) | |
267 | + @rm -f colorTest$(EXEEXT) | |
268 | + $(CXXLINK) $(colorTest_OBJECTS) $(colorTest_LDADD) $(LIBS) | |
259 | 269 | formatter$(EXEEXT): $(formatter_OBJECTS) $(formatter_DEPENDENCIES) |
260 | 270 | @rm -f formatter$(EXEEXT) |
261 | 271 | $(CXXLINK) $(formatter_OBJECTS) $(formatter_LDADD) $(LIBS) |
@@ -282,6 +292,7 @@ | ||
282 | 292 | -rm -f *.tab.c |
283 | 293 | |
284 | 294 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collection.Po@am__quote@ |
295 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/colorTest.Po@am__quote@ | |
285 | 296 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/formatter.Po@am__quote@ |
286 | 297 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashtable.Po@am__quote@ |
287 | 298 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@ |
@@ -8,12 +8,14 @@ | ||
8 | 8 | |
9 | 9 | if POSIX |
10 | 10 | |
11 | -TESTS = collection list hashtable tree rand smartptr formatter | |
11 | +TESTS = collection colorTest list hashtable tree rand smartptr formatter | |
12 | 12 | |
13 | 13 | noinst_PROGRAMS = $(TESTS) |
14 | 14 | |
15 | 15 | collection_SOURCES = collection.cpp |
16 | 16 | |
17 | +colorTest_SOURCES = colorTest.cpp | |
18 | + | |
17 | 19 | list_SOURCES = list.cpp |
18 | 20 | |
19 | 21 | hashtable_SOURCES = hashtable.cpp |
@@ -151,20 +151,20 @@ | ||
151 | 151 | top_srcdir = @top_srcdir@ |
152 | 152 | SUFFIXES = .h .idl |
153 | 153 | nobase_include_HEADERS = es.h es/apply.h es/broker.h es/classFactory.h \ |
154 | - es/clsid.h es/collection.h es/context.h es/dateTime.h es/elf.h \ | |
155 | - es/ent.h es/endian.h es/exception.h es/formatter.h es/handle.h \ | |
156 | - es/hashtable.h es/interlocked.h es/list.h es/md5.h es/ref.h \ | |
157 | - es/reflect.h es/ring.h es/synchronized.h es/timer.h \ | |
158 | - es/timeSpan.h es/tree.h es/types.h es/usage.h es/utf.h \ | |
159 | - es/uuid.h es/net/arp.h es/net/dhcp.h es/net/dns.h es/net/dix.h \ | |
160 | - es/net/icmp.h es/net/igmp.h es/net/inet4.h es/net/inet6.h \ | |
161 | - es/net/tcp.h es/net/udp.h es/base/IAlarm.idl \ | |
162 | - es/base/ICache.idl es/base/ICallback.idl \ | |
163 | - es/base/IClassFactory.idl es/base/IClassStore.idl \ | |
164 | - es/base/IFile.idl es/base/IInterface.idl \ | |
165 | - es/base/IInterfaceStore.idl es/base/IMonitor.idl \ | |
166 | - es/base/IPageable.idl es/base/IPageSet.idl \ | |
167 | - es/base/IProcess.idl es/base/IRuntime.idl \ | |
154 | + es/clsid.h es/color.h es/collection.h es/context.h \ | |
155 | + es/dateTime.h es/elf.h es/ent.h es/endian.h es/exception.h \ | |
156 | + es/formatter.h es/handle.h es/hashtable.h es/interlocked.h \ | |
157 | + es/list.h es/md5.h es/ref.h es/reflect.h es/ring.h \ | |
158 | + es/synchronized.h es/timer.h es/timeSpan.h es/tree.h \ | |
159 | + es/types.h es/usage.h es/utf.h es/uuid.h es/net/arp.h \ | |
160 | + es/net/dhcp.h es/net/dns.h es/net/dix.h es/net/icmp.h \ | |
161 | + es/net/igmp.h es/net/inet4.h es/net/inet6.h es/net/tcp.h \ | |
162 | + es/net/udp.h es/base/IAlarm.idl es/base/ICache.idl \ | |
163 | + es/base/ICallback.idl es/base/IClassFactory.idl \ | |
164 | + es/base/IClassStore.idl es/base/IFile.idl \ | |
165 | + es/base/IInterface.idl es/base/IInterfaceStore.idl \ | |
166 | + es/base/IMonitor.idl es/base/IPageable.idl \ | |
167 | + es/base/IPageSet.idl es/base/IProcess.idl es/base/IRuntime.idl \ | |
168 | 168 | es/base/ISelectable.idl es/base/IService.idl \ |
169 | 169 | es/base/IStream.idl es/base/IThread.idl \ |
170 | 170 | es/device/IAudioFormat.idl es/device/IBeep.idl \ |
@@ -0,0 +1,84 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2007 | |
3 | + * Nintendo Co., Ltd. | |
4 | + * | |
5 | + * Permission to use, copy, modify, distribute and sell this software | |
6 | + * and its documentation for any purpose is hereby granted without fee, | |
7 | + * provided that the above copyright notice appear in all copies and | |
8 | + * that both that copyright notice and this permission notice appear | |
9 | + * in supporting documentation. Nintendo makes no | |
10 | + * representations about the suitability of this software for any | |
11 | + * purpose. It is provided "as is" without express or implied warranty. | |
12 | + */ | |
13 | + | |
14 | +/* | |
15 | + * cf. CSS3 Color Module | |
16 | + * http://www.w3.org/TR/css3-color/ | |
17 | + */ | |
18 | + | |
19 | +#ifndef NINTENDO_ES_COLOR_H_INCLUDED | |
20 | +#define NINTENDO_ES_COLOR_H_INCLUDED | |
21 | + | |
22 | +#include <errno.h> | |
23 | +#include <es/types.h> | |
24 | +#include <es/exception.h> | |
25 | + | |
26 | +class Rgb | |
27 | +{ | |
28 | + u32 rgba; | |
29 | + | |
30 | + bool assign(const char* color); | |
31 | + | |
32 | +public: | |
33 | + Rgb(u32 rgba = 0xff000000) : | |
34 | + rgba(rgba) | |
35 | + { | |
36 | + } | |
37 | + | |
38 | + Rgb(const char* color) : | |
39 | + rgba(0xff000000) | |
40 | + { | |
41 | + if (!assign(color)) | |
42 | + { | |
43 | + throw SystemException<EINVAL>(); | |
44 | + } | |
45 | + } | |
46 | + | |
47 | + Rgb(u8 r, u8 g, u8 b, u8 a = 255u) | |
48 | + { | |
49 | + rgba = (a << 24) | (b << 16) | (g << 8) | r; | |
50 | + } | |
51 | + | |
52 | + u8 getR() | |
53 | + { | |
54 | + return (u8) (rgba & 0xff); | |
55 | + } | |
56 | + | |
57 | + u8 getG() const | |
58 | + { | |
59 | + return (u8) ((rgba >> 8) & 0xff); | |
60 | + } | |
61 | + | |
62 | + u8 getB() const | |
63 | + { | |
64 | + return (u8) ((rgba >> 16) & 0xff); | |
65 | + } | |
66 | + | |
67 | + u8 getA() const | |
68 | + { | |
69 | + return (u8) ((rgba >> 24) & 0xff); | |
70 | + } | |
71 | + | |
72 | + Rgb& operator=(const char* color) | |
73 | + { | |
74 | + assign(color); | |
75 | + return *this; | |
76 | + } | |
77 | + | |
78 | + operator u32() const | |
79 | + { | |
80 | + return rgba; | |
81 | + } | |
82 | +}; | |
83 | + | |
84 | +#endif // NINTENDO_ES_COLOR_H_INCLUDED |
@@ -18,6 +18,7 @@ | ||
18 | 18 | es/broker.h \ |
19 | 19 | es/classFactory.h \ |
20 | 20 | es/clsid.h \ |
21 | + es/color.h \ | |
21 | 22 | es/collection.h \ |
22 | 23 | es/context.h \ |
23 | 24 | es/dateTime.h \ |