]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add text to image capability
authorCharlie Brej <cbrej@cs.man.ac.uk>
Sat, 21 Nov 2009 17:45:41 +0000 (17:45 +0000)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Sat, 21 Nov 2009 17:45:41 +0000 (17:45 +0000)
Enables scripts to display test by converting it into an image. This can then
be shown using a sprite. Function takes a string and the value of the three
colors (red green blue).

new_image = Image.Text("text we want", 1.0, 0.0, 0.0); // gives red text image

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

index 3582b84c47e4895f58d9a89883d7255545803601..1989289cb236306ee7b26a880d7696135be5dfae 100644 (file)
@@ -46,7 +46,6 @@
 #include "ply-entry.h"
 #include "ply-event-loop.h"
 #include "ply-key-file.h"
-#include "ply-label.h"
 #include "ply-list.h"
 #include "ply-logger.h"
 #include "ply-image.h"
index b4f998c7ccad00f177f678952b05b640db7ab2fe..1abae268f18a66726e38203d4dc072eddc167dd4 100644 (file)
@@ -21,6 +21,7 @@
  */
 #define _GNU_SOURCE
 #include "ply-image.h"
+#include "ply-label.h"
 #include "ply-pixel-buffer.h"
 #include "ply-utils.h"
 #include "script.h"
@@ -151,6 +152,39 @@ static script_return_t image_scale (script_state_t *state,
   return script_return_obj_null ();
 }
 
+static script_return_t image_text (script_state_t *state,
+                                   void           *user_data)
+{
+  script_lib_image_data_t *data = user_data;
+  ply_pixel_buffer_t *image;
+  ply_label_t *label;
+  int width, height;
+  
+  char *text = script_obj_hash_get_string (state->local, "text");
+  
+  /* These colour values are currently unused, but will be once label supports them */
+  float red = script_obj_hash_get_number (state->local, "red");
+  float green = script_obj_hash_get_number (state->local, "green");
+  float blue = script_obj_hash_get_number (state->local, "blue");
+  
+  if (!text) return script_return_obj_null ();
+  
+  label = ply_label_new ();
+  ply_label_set_text (label, text);
+  ply_label_show (label, NULL, 0, 0);
+  
+  width = ply_label_get_width (label);
+  height = ply_label_get_height (label);
+  
+  image = ply_pixel_buffer_new (width, height);
+  ply_label_draw_area (label, image, 0, 0, width, height);
+  
+  free (text);
+  ply_label_free (label);
+  
+  return script_return_obj (script_obj_new_native (image, data->class));
+}
+
 script_lib_image_data_t *script_lib_image_setup (script_state_t *state,
                                                  char         *image_dir)
 {
@@ -190,6 +224,15 @@ script_lib_image_data_t *script_lib_image_setup (script_state_t *state,
                               image_get_height,
                               data,
                               NULL);
+  script_add_native_function (image_hash,
+                              "_Text",
+                              image_text,
+                              data,
+                              "text",
+                              "red",
+                              "green",
+                              "blue",
+                              NULL);
 
   script_obj_unref (image_hash);
   data->script_main_op = script_parse_string (script_lib_image_string, "script-lib-image.script");
index 68f0de1b5b61f1dcf6e0d2c3b19179847d7db1f6..443e6ec53eb22f5fac540e908f9dad04e4876bc4 100644 (file)
@@ -14,6 +14,11 @@ Image.Scale = fun (width, height)
   return Image.Adopt (this._Scale(width, height));
 };
 
+Image.Text = fun (text, red, green, blue)
+{
+  return Image.Adopt (Image._Text (text, red, green, blue));
+};
+
 Image |= fun (filename)
 {
   return Image.Adopt (Image._New(filename));
index d99217d08c3690f11fa114161a221ed1c2ad456c..80302b73765bd8039763dc7373537ed016f30d28 100644 (file)
@@ -145,7 +145,20 @@ Plymouth.SetBootProgressFunction(progress_callback);
 
 fun quit_callback ()
 {
- logo.sprite.SetOpacity (1);
 logo.sprite.SetOpacity (1);
 }
 
 Plymouth.SetQuitFunction(quit_callback);
+
+#----------------------------------------- Message --------------------------------
+
+message_sprite = Sprite();
+message_sprite.SetPosition(10, 10, 10000);
+
+fun message_callback (text)
+{
+  my_image = Image.Text(text, 1, 1, 1);
+  message_sprite.SetImage(my_image);
+}
+
+Plymouth.SetMessageFunction(message_callback);