]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add support for script image rotation
authorCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 22 Jun 2009 20:20:13 +0000 (21:20 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 22 Jun 2009 20:20:13 +0000 (21:20 +0100)
An image rotate operation creates a new image with the same dimensions but with
the contents rotated by an angle around the centre of the image. Also added a
script object to float function to allow this.

src/plugins/splash/script/script-lib-image.c
src/plugins/splash/script/script-lib-sprite.script
src/plugins/splash/script/script-object.c
src/plugins/splash/script/script-object.h
themes/script/script.script

index 14df7236de96105e8b52b957326eebf193adeb90..7c1c16eb9c498a321c17bff74c2e3b6acb997045 100644 (file)
@@ -3,6 +3,7 @@
 #include "ply-utils.h"
 #include "script.h"
 #include "script-object.h"
+#include "script-parse.h"
 #include "script-execute.h"
 #include "script-lib-image.h" 
 #include <assert.h>
@@ -84,6 +85,28 @@ static script_return image_get_height (script_state* state, void* user_data)
 
 
 
+static script_return image_rotate (script_state* state, void* user_data)
+{
+ script_lib_image_data_t* data = user_data;
+ script_obj* script_obj_image = script_obj_hash_get_element (state->local, "image");
+ script_obj* script_obj_angle = script_obj_hash_get_element (state->local, "angle");
+ script_obj_deref(&script_obj_image);
+ script_obj* reply;
+ if (script_obj_image->type == SCRIPT_OBJ_TYPE_NATIVE &&
+     script_obj_image->data.native.class == data->class){
+    ply_image_t *image = script_obj_image->data.native.object_data;
+    ply_image_t *new_image = ply_image_rotate (image, ply_image_get_width (image)/2, ply_image_get_height (image)/2, script_obj_as_float (script_obj_angle));
+    reply = script_obj_new_native (new_image, data->class);
+    }
+ else
+    reply = script_obj_new_null ();
+ script_obj_unref(script_obj_image);
+ script_obj_unref(script_obj_angle);
+ return (script_return){SCRIPT_RETURN_TYPE_RETURN, reply};
+}
+
+
+
 
 script_lib_image_data_t* script_lib_image_setup(script_state *state, char* image_dir)
 {
@@ -92,6 +115,7 @@ script_lib_image_data_t* script_lib_image_setup(script_state *state, char* image
  data->image_dir = strdup(image_dir);
 
  script_add_native_function (state->global, "ImageNew", image_new, data, "filename", NULL);
+ script_add_native_function (state->global, "ImageRotate", image_rotate, data, "image", "angle", NULL);
  script_add_native_function (state->global, "ImageGetWidth", image_get_width, data, "image", NULL);
  script_add_native_function (state->global, "ImageGetHeight", image_get_height, data, "image", NULL);
  
index f8fddfa0263f746064d5b3380e83e14dc1cd7b26..95f279efe0a4b9472149e8ba32741798e4e4c5f9 100644 (file)
@@ -2,6 +2,7 @@ fun SpriteUpdate(sprite){
     SpriteSetX(sprite.native, sprite.x);
     SpriteSetY(sprite.native, sprite.y);
     SpriteSetZ(sprite.native, sprite.z);
+    SpriteSetImage(sprite.native, sprite.image);
     }
 
 
index 5a56d5e8b74108690cad58e24bd2cf7568c89bfc..59eb296e51c8f5f8fb7302ca3ccce0880ba0bf69 100644 (file)
@@ -288,6 +288,30 @@ int script_obj_as_int (script_obj* obj)
  return false;
 }
 
+float script_obj_as_float (script_obj* obj)
+{                                                     // If in then reply contents, otherwise reply 0
+ obj = script_obj_deref_direct(obj);
+ switch (obj->type){
+    case SCRIPT_OBJ_TYPE_INT:
+        return (float) obj->data.integer;
+    case SCRIPT_OBJ_TYPE_FLOAT:
+        return obj->data.floatpoint;
+    case SCRIPT_OBJ_TYPE_NULL:
+        return 0;
+    case SCRIPT_OBJ_TYPE_REF:       // should have been de-reffed already
+        assert(0);
+    case SCRIPT_OBJ_TYPE_HASH:
+    case SCRIPT_OBJ_TYPE_FUNCTION:
+    case SCRIPT_OBJ_TYPE_NATIVE:
+        return 0;
+    case SCRIPT_OBJ_TYPE_STRING:
+        return 0;
+    }
+    
+ assert(0);         // Abort on uncaught
+ return false;
+}
+
 bool script_obj_as_bool (script_obj* obj)
 {                                                 // False objects are NULL, 0, ""
  obj = script_obj_deref_direct(obj);
index 54d1f7b17b071235fe452c14961b54c19eaf6f11..30f039fc4e4d523ebae9f93264174807a0c1e366 100644 (file)
@@ -19,6 +19,7 @@ script_obj* script_obj_new_function (script_function* function);
 script_obj* script_obj_new_ref (script_obj* sub_obj);
 script_obj* script_obj_new_native (void* object_data, script_obj_native_class* class);
 int script_obj_as_int (script_obj* obj);
+float script_obj_as_float (script_obj* obj);
 bool script_obj_as_bool (script_obj* obj);
 char* script_obj_as_string (script_obj* obj);
 void script_obj_assign (script_obj* obj_a, script_obj* obj_b);
index 60ca573d9a21f073a325146a50f78102a812da55..3eef2f3570846a94a3473187042bcd6984c7f5fe 100644 (file)
@@ -4,12 +4,14 @@ while (index<30){
     mystring = index;
     if (index<10) mystring = "0" + index;
     sprites[index] = SpriteNewWithImage("../spinfinity/throbber-" + mystring + ".png");
+    sprites[index].orig_image = sprites[index].image;
     sprites[index].xd = 1 + index;
     sprites[index].yd = 1 + index;
     index = index + 1;
     }
 
 random = 1;
+count = 0;
 
 fun update_logo_sprite (sprite){
     image_width =  ImageGetWidth (sprite.image);
@@ -28,13 +30,14 @@ fun update_logo_sprite (sprite){
     
     sprite.x = sprite.x + sprite.xd;
     sprite.y = sprite.y + sprite.yd;
-    
+    sprite.image = ImageRotate(sprite.orig_image, count*0.1);
     SpriteUpdate(sprite);
     }
 
 
 fun refresh (){
     index = 0;
+    count++;
     while (!(index>=30)){
         update_logo_sprite (sprites[index]);
         index++;