aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_sdl.js20
-rw-r--r--tests/sdl_canvas.c4
2 files changed, 14 insertions, 10 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 49f52a11..b6988338 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -173,16 +173,20 @@ mergeInto(LibraryManager.library, {
},
// Load SDL color into a CSS-style color specification
- loadColorToCSS: function(color) {
+ loadColorToCSSRGB: function(color) {
+ var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
+ return 'rgb(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ')';
+ },
+ loadColorToCSSRGBA: function(color) {
var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (((rgba >> 24)&255)/255) + ')';
},
- translateColorToCSS: function(rgba) {
+ translateColorToCSSRGBA: function(rgba) {
return 'rgba(' + ((rgba >> 24)&255) + ',' + ((rgba >> 16)&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba&255)/255) + ')';
},
- translateRGBAToCSS: function(r, g, b, a) {
+ translateRGBAToCSSRGBA: function(r, g, b, a) {
return 'rgba(' + r + ',' + g + ',' + b + ',' + (a/255) + ')';
},
@@ -574,7 +578,7 @@ mergeInto(LibraryManager.library, {
assert(!surfData.locked); // but we could unlock and re-lock if we must..
var r = SDL.loadRect(rect);
surfData.ctx.save();
- surfData.ctx.fillStyle = SDL.translateColorToCSS(color);
+ surfData.ctx.fillStyle = SDL.translateColorToCSSRGBA(color);
surfData.ctx.fillRect(r.x, r.y, r.w, r.h);
surfData.ctx.restore();
},
@@ -810,7 +814,7 @@ mergeInto(LibraryManager.library, {
var fontData = SDL.fonts[font];
var w = SDL.estimateTextWidth(fontData, text);
var h = fontData.size;
- var color = SDL.loadColorToCSS(color);
+ var color = SDL.loadColorToCSSRGB(color); // XXX alpha breaks fonts?
var fontString = h + 'px sans-serif';
var surf = SDL.makeSurface(w, h, 0, false, 'text:' + text); // bogus numbers..
var surfData = SDL.surfaces[surf];
@@ -853,7 +857,7 @@ mergeInto(LibraryManager.library, {
assert(!surfData.locked); // but we could unlock and re-lock if we must..
// TODO: if ctx does not change, leave as is, and also do not re-set xStyle etc.
surfData.ctx.save();
- surfData.ctx.fillStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.fillStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.fillRect(x1, y1, x2-x1, y2-y1);
surfData.ctx.restore();
},
@@ -862,7 +866,7 @@ mergeInto(LibraryManager.library, {
var surfData = SDL.surfaces[surf];
assert(!surfData.locked); // but we could unlock and re-lock if we must..
surfData.ctx.save();
- surfData.ctx.strokeStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.strokeStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.strokeRect(x1, y1, x2-x1, y2-y1);
surfData.ctx.restore();
},
@@ -871,7 +875,7 @@ mergeInto(LibraryManager.library, {
var surfData = SDL.surfaces[surf];
assert(!surfData.locked); // but we could unlock and re-lock if we must..
surfData.ctx.save();
- surfData.ctx.strokeStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.strokeStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.beginPath();
surfData.ctx.moveTo(x1, y1);
surfData.ctx.lineTo(x2, y2);
diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c
index 6c6adc2d..ab1340a8 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, 0x4f };
+ SDL_Color color = { 0xff, 0x99, 0x00, 0xff };
- SDL_Surface *text = TTF_RenderText_Solid(font, "hello faint orange world", color);
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color);
SDL_Color color2 = { 0xbb, 0, 0xff, 0xff };
SDL_Surface *text2 = TTF_RenderText_Solid(font, "a second line, purple", color2);