]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Allow alpha color component to be set when generating text images
authorCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 23 Mar 2010 22:28:22 +0000 (22:28 +0000)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Thu, 25 Mar 2010 18:26:01 +0000 (18:26 +0000)
The Image.Text function now accepts an alpha parameter of the color used. If
not set this will be assumed to be 1 (thus reverse compatible).

src/plugins/splash/script/script-lib-image.c
src/plugins/splash/script/script-lib-image.script

index 15bfe879f3a43ac34e147372b494aea59c204ff6..b017dbdf8cc6411a08fe8c56e6c5352bc0503212 100644 (file)
@@ -158,6 +158,7 @@ static script_return_t image_text (script_state_t *state,
   script_lib_image_data_t *data = user_data;
   ply_pixel_buffer_t *image;
   ply_label_t *label;
+  script_obj_t *alpha_obj;
   int width, height;
   
   char *text = script_obj_hash_get_string (state->local, "text");
@@ -166,12 +167,21 @@ static script_return_t image_text (script_state_t *state,
   float red = CLAMP(script_obj_hash_get_number (state->local, "red"), 0, 1);
   float green = CLAMP(script_obj_hash_get_number (state->local, "green"), 0, 1);
   float blue = CLAMP(script_obj_hash_get_number (state->local, "blue"), 0, 1);
-  
+  float alpha = 1;
+
+  alpha_obj = script_obj_hash_peek_element (state->local, "alpha");
+
+  if (alpha_obj)
+    {
+      alpha = CLAMP(script_obj_as_number (alpha_obj), 0, 1);
+      script_obj_unref(alpha_obj);
+    }
+
   if (!text) return script_return_obj_null ();
-  
+
   label = ply_label_new ();
   ply_label_set_text (label, text);
-  ply_label_set_color (label, red, green, blue, 1.0);
+  ply_label_set_color (label, red, green, blue, alpha);
   ply_label_show (label, NULL, 0, 0);
   
   width = ply_label_get_width (label);
@@ -233,6 +243,7 @@ script_lib_image_data_t *script_lib_image_setup (script_state_t *state,
                               "red",
                               "green",
                               "blue",
+                              "alpha",
                               NULL);
 
   script_obj_unref (image_hash);
index 443e6ec53eb22f5fac540e908f9dad04e4876bc4..015a2f501f694297dd19b54c8dcb4797a163baf9 100644 (file)
@@ -14,9 +14,9 @@ Image.Scale = fun (width, height)
   return Image.Adopt (this._Scale(width, height));
 };
 
-Image.Text = fun (text, red, green, blue)
+Image.Text = fun (text, red, green, blue, alpha)
 {
-  return Image.Adopt (Image._Text (text, red, green, blue));
+  return Image.Adopt (Image._Text (text, red, green, blue, alpha));
 };
 
 Image |= fun (filename)