aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-03-24 19:33:06 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-03-24 19:33:06 -0700
commita7bc331fac817437fcaaeaffcad7dd4b5cb75d84 (patch)
tree311e22767163e97627464db7ff4a1d21104f4ec2
parentb88b4035ddf5a8aad6391f68fa809a06b510daa3 (diff)
support for rgba in sdl
-rw-r--r--src/library_sdl.js6
-rw-r--r--tests/sdl_canvas.c4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index fcc7e5b9..93bf133b 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -175,15 +175,15 @@ mergeInto(LibraryManager.library, {
// Load SDL color into a CSS-style color specification
loadColorToCSS: function(color) {
var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
- return 'rgb(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ')';
+ return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (1-((rgba >> 24)&255)/255) + ')';
},
translateColorToCSS: function(rgba) {
- return 'rgb(' + ((rgba >> 24)&255) + ',' + ((rgba >> 16)&255) + ',' + ((rgba >> 8)&255) + ')';
+ return 'rgba(' + ((rgba >> 24)&255) + ',' + ((rgba >> 16)&255) + ',' + ((rgba >> 8)&255) + ',' + (1-(rgba&255)/255) + ')';
},
translateRGBAToCSS: function(r, g, b, a) {
- return 'rgb(' + r + ',' + g + ',' + b + ')';
+ return 'rgba(' + r + ',' + g + ',' + b + ',' + (1-a/255) + ')';
},
makeSurface: function(width, height, flags, usePageCanvas, source) {
diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c
index ae617604..aaa9d653 100644
--- a/tests/sdl_canvas.c
+++ b/tests/sdl_canvas.c
@@ -12,9 +12,9 @@ int main() {
TTF_Font *font = TTF_OpenFont("myfont.ttf", 40);
printf("Font: %p\n", font);
- SDL_Color color = { 0xff, 0x99, 0x00, 0x77 };
+ SDL_Color color = { 0xff, 0x99, 0x00, 0xb0 };
- SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color);
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello faint orange world", color);
SDL_Color color2 = { 0xbb, 0, 0xff, 0 };
SDL_Surface *text2 = TTF_RenderText_Solid(font, "a second line, purple", color2);