[maemo-commits] [maemo-commits] r16419 - in projects/haf/trunk/hildon-theme-tools: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Oct 16 12:50:18 EEST 2008
- Previous message: [maemo-commits] r16418 - in projects/haf/trunk/hildon-thumbnail: . debian
- Next message: [maemo-commits] r16420 - projects/haf/trunk/glib/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: danielb Date: 2008-10-16 12:46:30 +0300 (Thu, 16 Oct 2008) New Revision: 16419 Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog projects/haf/trunk/hildon-theme-tools/src/common.h projects/haf/trunk/hildon-theme-tools/src/outliner.c projects/haf/trunk/hildon-theme-tools/src/outliner.h Log: added option to create borders from rc files Modified: projects/haf/trunk/hildon-theme-tools/ChangeLog =================================================================== --- projects/haf/trunk/hildon-theme-tools/ChangeLog 2008-10-15 15:14:00 UTC (rev 16418) +++ projects/haf/trunk/hildon-theme-tools/ChangeLog 2008-10-16 09:46:30 UTC (rev 16419) @@ -1,3 +1,10 @@ +2008-10-16 Daniel Borgmann <danielb at openismus.com> + + * src/common.h: + * src/outliner.h: + * src/outliner.c: Add an option to create border overlays from RC + files + 2008-06-09 Sven Herzberg <sven at imendio.com> * scripts/hildon-theme-bootstrap: fix a typo Modified: projects/haf/trunk/hildon-theme-tools/src/common.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/common.h 2008-10-15 15:14:00 UTC (rev 16418) +++ projects/haf/trunk/hildon-theme-tools/src/common.h 2008-10-16 09:46:30 UTC (rev 16419) @@ -38,8 +38,13 @@ gint Y; gint Width; gint Height; + gint BorderTop; + gint BorderBottom; + gint BorderLeft; + gint BorderRight; gboolean ForcedAlpha; gboolean NoAlpha; + } typedef Element; struct _Color Modified: projects/haf/trunk/hildon-theme-tools/src/outliner.c =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/outliner.c 2008-10-15 15:14:00 UTC (rev 16418) +++ projects/haf/trunk/hildon-theme-tools/src/outliner.c 2008-10-16 09:46:30 UTC (rev 16419) @@ -42,6 +42,7 @@ for (iterator = templ->ElementList; iterator; iterator = g_slist_next (iterator)) { Element *element = (Element *) iterator->data; GdkPixbuf *image = NULL; + GdkPixbuf *border_img = NULL; if (element->X > templ->Width || element->Y > templ->Height || @@ -62,13 +63,41 @@ gdk_pixbuf_fill (image, 0x00cc00ff); else gdk_pixbuf_fill (image, 0x00bb00ff); + + if (element->BorderTop > 0) { + border_img = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, element->Width, element->BorderTop); + gdk_pixbuf_fill (border_img, 0xffffffff); + gdk_pixbuf_composite (border_img, image, 0, 0, element->Width, element->BorderTop, + 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 32); + } + + if (element->BorderBottom > 0) { + border_img = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, element->Width, element->BorderBottom); + gdk_pixbuf_fill (border_img, 0xffffffff); + gdk_pixbuf_composite (border_img, image, 0, element->Height - element->BorderBottom, element->Width, element->BorderBottom, + 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 32); + } + + if (element->BorderLeft > 0) { + border_img = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, element->BorderLeft, element->Height); + gdk_pixbuf_fill (border_img, 0xffffffff); + gdk_pixbuf_composite (border_img, image, 0, 0, element->BorderLeft, element->Height, + 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 32); + } + + if (element->BorderRight > 0) { + border_img = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, element->BorderRight, element->Height); + gdk_pixbuf_fill (border_img, 0xffffffff); + gdk_pixbuf_composite (border_img, image, element->Width - element->BorderRight, 0, element->BorderRight, element->Height, + 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 32); + } } if (image != NULL) { /* Draw the stuff over the composite image */ gdk_pixbuf_copy_area (image, 0, 0, element->Width, element->Height, composite_image, element->X, element->Y); - g_print ("Outlined %s\n", element->Name); + //g_print ("Outlined %s\n", element->Name); gdk_pixbuf_unref (image); } @@ -107,7 +136,7 @@ /* Draw the stuff over the composite image */ gdk_pixbuf_copy_area (image, 0, 0, 8, 8, composite_image, color->X - 4, color->Y - 4); - g_print ("Outlined color %s\n", color->Name); + //g_print ("Outlined color %s\n", color->Name); gdk_pixbuf_unref (image); } @@ -118,6 +147,93 @@ return composite_image; } +void parse_rc (gchar *filename, Template *template, GScanner *scanner) +{ + GSList *iterator = NULL; + GTokenType ttype = 0; + gchar imgname[256]; + gint left, right, top, bottom; + + int gtkrc_fd = open (filename, O_RDONLY); + + if (gtkrc_fd < 0) { + g_print ("Failed to open '%s'. Skipping ...\n", filename); + } else { + g_scanner_input_file (scanner, gtkrc_fd); + scanner->input_name = filename; + + for (ttype = g_scanner_get_next_token (scanner); ttype != G_TOKEN_EOF; ttype = g_scanner_get_next_token (scanner)) { + + if (ttype == G_TOKEN_IDENTIFIER && !strcmp(scanner->value.v_string, "image")) { + + while (ttype != G_TOKEN_RIGHT_CURLY) { + ttype = g_scanner_get_next_token (scanner); + + if (ttype == G_TOKEN_IDENTIFIER && !strcmp(scanner->value.v_string, "file")) { + ttype = g_scanner_get_next_token (scanner); + + if (ttype != G_TOKEN_EQUAL_SIGN) + break; + + ttype = g_scanner_get_next_token (scanner); + strcpy (imgname, g_path_get_basename (scanner->value.v_string)); + } else if (ttype == G_TOKEN_IDENTIFIER && !strcmp(scanner->value.v_string, "border")) { + + ttype = g_scanner_get_next_token (scanner); + + // scan all four values, skipping the commas + ttype = g_scanner_get_next_token (scanner); + ttype = g_scanner_get_next_token (scanner); + if (ttype == G_TOKEN_INT) + left = scanner->value.v_int; + else + break; + ttype = g_scanner_get_next_token (scanner); + ttype = g_scanner_get_next_token (scanner); + if (ttype == G_TOKEN_INT) + right = scanner->value.v_int; + else + break; + ttype = g_scanner_get_next_token (scanner); + ttype = g_scanner_get_next_token (scanner); + if (ttype == G_TOKEN_INT) + top = scanner->value.v_int; + else + break; + ttype = g_scanner_get_next_token (scanner); + ttype = g_scanner_get_next_token (scanner); + if (ttype == G_TOKEN_INT) + bottom = scanner->value.v_int; + else + break; + + // got valid border values, so look for a corresponding entry in the elements list + for (iterator = template->ElementList; iterator; iterator = g_slist_next (iterator)) { + Element *element = (Element *) iterator->data; + + if (strcmp (element->Name, imgname)) + continue; + + element->BorderLeft = left; + element->BorderRight = right; + element->BorderTop = top; + element->BorderBottom = bottom; + + break; + } + + // skip the right curly + ttype = g_scanner_get_next_token (scanner); + ttype = g_scanner_get_next_token (scanner); + } + } + } + } + } + + close (gtkrc_fd); +} + /* Shows the initial copyright/info banner */ void show_banner (void) { @@ -128,8 +244,10 @@ /* Show some info about basic usage of the tool */ void show_usage (void) { - g_print ("Usage: %s <layout> <outputimage>\n\n", g_get_prgname ()); + g_print ("Usage: %s <layout> <outputimage> [rcdirectory]\n\n", g_get_prgname ()); g_print ("This tool will create an outline image that shows the slicing guides. \n" + "If rcdirectory is given, it will look for .rc files in this directory\n" + "and gather matching border values from there.\n" "You can use this image in your graphics program to check if your drawings\n" "fit the proper areas. \n\n"); } @@ -139,10 +257,13 @@ { gchar *template_file = NULL; gchar *output_image_file = NULL; + gchar *rc_directory = NULL; int return_val = 0; Template *template = NULL; GdkPixbuf *output_image = NULL; + GScanner *scanner = NULL; + g_type_init (); g_set_prgname (g_basename (argv [0])); @@ -164,6 +285,10 @@ g_printerr ("Bad arguments given!\n"); goto Error; } + + if (argc > 3) { + rc_directory = argv [3]; + } /* Check the template file... */ if (! g_file_test (template_file, G_FILE_TEST_EXISTS)) { @@ -176,6 +301,29 @@ if (template == NULL) goto Error; + + + /* Get border values from a directory containing .rc files */ + if (rc_directory) { + if (!g_file_test (rc_directory, G_FILE_TEST_IS_DIR)) { + g_printerr ("ERROR: %s is not a directory\n", rc_directory); + goto Error; + } + + g_print ("\n\n** Using directory '%s' for rc files.\n\n", rc_directory); + + gchar *rc_file = NULL; + GDir *rc_dir = g_dir_open (rc_directory, 0, NULL); + + scanner = g_scanner_new (NULL); + while (rc_file = g_dir_read_name (rc_dir)) { + parse_rc (g_build_filename (rc_directory, rc_file, NULL), template, scanner); + } + g_scanner_destroy (scanner); + g_dir_close (rc_dir); + } else { + g_print ("\n\n** No rc directory specified, borders will not be generated.\n\n"); + } /* Basic info */ show_template (template); Modified: projects/haf/trunk/hildon-theme-tools/src/outliner.h =================================================================== --- projects/haf/trunk/hildon-theme-tools/src/outliner.h 2008-10-15 15:14:00 UTC (rev 16418) +++ projects/haf/trunk/hildon-theme-tools/src/outliner.h 2008-10-16 09:46:30 UTC (rev 16419) @@ -24,7 +24,13 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + int main (int argc, char **argv); void show_usage (void); @@ -32,3 +38,5 @@ void show_banner (void); GdkPixbuf* process (Template *templ); + +void parse_rc (gchar *filename, Template *template, GScanner *scanner);
- Previous message: [maemo-commits] r16418 - in projects/haf/trunk/hildon-thumbnail: . debian
- Next message: [maemo-commits] r16420 - projects/haf/trunk/glib/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]