Skip to content
Browse files

rip-border: add custom textures support.

  • Loading branch information...
1 parent 592ca46 commit c51d8660db7cbcd0240edeecbd3eca66002bf50e @hejiann committed Jul 30, 2012
Showing with 155 additions and 25 deletions.
  1. +7 −1 README
  2. +148 −24 rip-border.c
View
8 README
@@ -29,7 +29,12 @@ Filters -> Beautify -> Skin whitening
Filters -> Beautify -> Rip Border
Filters -> Beautify -> Texture Border
-Add custom textures into Texture Border filter:
+Add custom textures for Rip Border filter:
+mkdir ~/.gimp-2.8/rip-border
+mkdir ~/.gimp-2.8/rip-border/custom
+cp my-textures/*.jpg ~/.gimp-2.8/rip-border/custom/
+
+Add custom textures for Texture Border filter:
mkdir ~/.gimp-2.8/texture-border
mkdir ~/.gimp-2.8/texture-border/custom
cp my-textures/*.jpg ~/.gimp-2.8/texture-border/custom/
@@ -49,6 +54,7 @@ beautify: fix missing effect.
beautify: add glass drops effect.
beautify: add life sketch effect.
beautify: add color pencil effect.
+rip-border: add custom texures support.
2012-07-29
texture-border: add custom texures support.
View
172 rip-border.c
@@ -24,6 +24,8 @@
#define PLUG_IN_BINARY "rip-border"
#define PLUG_IN_ROLE "gimp-rip-border"
+#define TEXTURE_PATH "rip-border"
+
#define PREVIEW_SIZE 480
#define THUMBNAIL_SIZE 80
@@ -32,6 +34,7 @@ typedef struct
const guint8* texture;
GimpRGB color;
gdouble opacity;
+ const gchar *custom_texture;
} RipBorderValues;
static void query (void);
@@ -46,6 +49,21 @@ static void rip_border (gint32 image_ID);
static gboolean rip_border_dialog ();
static void create_texture_page (GtkNotebook *notebook, const gchar* category, const guint8** textures, guint n_textures);
+static void create_custom_texture_pages (GtkNotebook *notebook);
+static void create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const gchar* path);
+
+static gboolean texture_press (GtkWidget *event_box, GdkEventButton *event, const guint8 *texture);
+static gboolean custom_texture_press (GtkWidget *event_box, GdkEventButton *event, const gchar *texture);
+static void do_texture_press ();
+
+static inline gboolean
+is_hidden (const gchar *filename)
+{
+ /* skip files starting with '.' so we don't try to parse
+* stuff like .DS_Store or other metadata storage files
+*/
+ return (filename[0] == '.');
+}
const GimpPlugInInfo PLUG_IN_INFO =
{
@@ -60,6 +78,7 @@ static RipBorderValues rbvals =
NULL, /* texture */
{1.0, 1.0, 1.0, 1.0}, /* color */
100, /* opacity */
+ NULL, /* custom_texture */
};
static gint32 image_ID = 0;
@@ -271,7 +290,14 @@ run (const gchar *name,
static void
rip_border (gint32 image_ID)
{
- if (rbvals.texture != NULL)
+ GdkPixbuf *pixbuf = NULL;
+
+ if (rbvals.texture)
+ pixbuf = gdk_pixbuf_new_from_inline (-1, rbvals.texture, FALSE, NULL);
+ else if (rbvals.custom_texture)
+ pixbuf = gdk_pixbuf_new_from_file (rbvals.custom_texture, NULL);
+
+ if (pixbuf)
{
gint32 color_layer = gimp_layer_new (image_ID, "color",
width, height,
@@ -287,7 +313,6 @@ rip_border (gint32 image_ID)
GIMP_ADD_WHITE_MASK);
gimp_layer_add_mask (color_layer, texture_mask);
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, rbvals.texture, FALSE, NULL);
gint32 texture = gimp_layer_new_from_pixbuf (image_ID, "texture", pixbuf, rbvals.opacity, GIMP_NORMAL_MODE, 0, 0);
gimp_image_add_layer (image_ID, texture, -1);
gimp_layer_scale (texture, width, height, FALSE);
@@ -315,27 +340,6 @@ preview_update (GtkWidget *preview)
gtk_image_set_from_pixbuf (GTK_IMAGE(preview), pixbuf);
}
-static gboolean
-select_texture (GtkWidget *event_box, GdkEventButton *event, const guint8* texture)
-{
- rbvals.texture = texture;
-
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, rbvals.texture, FALSE, NULL);
- gint32 texture_layer = gimp_layer_new_from_pixbuf (preview_image,
- "texture",
- pixbuf,
- rbvals.opacity,
- GIMP_NORMAL_MODE, 0, 0);
- gimp_image_add_layer (preview_image, texture_layer, -1);
- gimp_layer_scale (texture_layer, width, height, FALSE);
- gimp_invert (texture_layer);
- gimp_edit_copy (texture_layer);
- gimp_edit_paste (texture_mask, TRUE);
- gimp_image_remove_layer (preview_image, texture_layer);
-
- preview_update (preview);
-}
-
static void
color_update (GtkWidget *preview)
{
@@ -477,6 +481,8 @@ rip_border_dialog ()
create_texture_page (GTK_NOTEBOOK (notebook), "Lights", lights_textures, G_N_ELEMENTS (lights_textures));
create_texture_page (GTK_NOTEBOOK (notebook), "Others", others_textures, G_N_ELEMENTS (others_textures));
+ create_custom_texture_pages (GTK_NOTEBOOK (notebook));
+
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
@@ -523,9 +529,127 @@ create_texture_page (GtkNotebook *notebook, const gchar* category, const guint8*
col = 1;
}
- g_signal_connect (event_box, "button_press_event", G_CALLBACK (select_texture), (gpointer)textures[i]);
+ g_signal_connect (event_box, "button_press_event", G_CALLBACK (texture_press), (gpointer)textures[i]);
+ }
+
+ gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
+}
+
+static void
+create_custom_texture_pages (GtkNotebook *notebook)
+{
+ const gchar *gimp_dir = gimp_directory ();
+ const gchar *texture_dir = g_build_filename (gimp_dir, TEXTURE_PATH, NULL);
+ GDir *dir = g_dir_open (texture_dir, 0, NULL);
+ if (dir)
+ {
+ const gchar *dir_ent;
+ while (dir_ent = g_dir_read_name (dir))
+ {
+ if (is_hidden (dir_ent))
+ continue;
+
+ gchar *filename = g_build_filename (texture_dir, dir_ent, NULL);
+ if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+ create_custom_texture_page (GTK_NOTEBOOK (notebook), dir_ent, filename);
+ }
+ }
+ }
+}
+
+static void
+create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const gchar* path) {
+ GtkWidget *label = gtk_label_new (category);
+
+ GtkWidget *thispage = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (thispage), 12);
+ gtk_widget_show (thispage);
+
+ /* table */
+ gint rows = 5;
+ gint cols = 3;
+ GtkWidget *table = gtk_table_new (rows, cols, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (thispage), table, FALSE, FALSE, 0);
+ gtk_widget_show (table);
+
+ gint row = 1;
+ gint col = 1;
+
+ GDir *dir = g_dir_open (path, 0, NULL);
+ if (dir)
+ {
+ const gchar *dir_ent;
+ while (dir_ent = g_dir_read_name (dir))
+ {
+ if (is_hidden (dir_ent))
+ continue;
+
+ gchar *filename = g_build_filename (path, dir_ent, NULL);
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+ pixbuf = gdk_pixbuf_scale_simple (pixbuf, THUMBNAIL_SIZE, THUMBNAIL_SIZE, GDK_INTERP_BILINEAR);
+ GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
+ GtkWidget *event_box = gtk_event_box_new ();
+ gtk_container_add (GTK_CONTAINER (event_box), image);
+ gtk_widget_show (image);
+ gtk_table_attach_defaults (GTK_TABLE (table), event_box, col - 1, col, row - 1, row);
+ gtk_widget_show (event_box);
+
+ col++;
+ if (col > cols)
+ {
+ row++;
+ col = 1;
+ }
+
+ g_signal_connect (event_box, "button_press_event", G_CALLBACK (custom_texture_press), filename);
+ }
}
gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
}
+static gboolean
+texture_press (GtkWidget *event_box, GdkEventButton *event, const guint8* texture)
+{
+ rbvals.texture = texture;
+ rbvals.custom_texture = NULL;
+
+ do_texture_press ();
+}
+
+static gboolean
+custom_texture_press (GtkWidget *event_box, GdkEventButton *event, const gchar *texture)
+{
+ rbvals.texture = NULL;
+ rbvals.custom_texture = texture;
+
+ do_texture_press ();
+}
+
+static void
+do_texture_press ()
+{
+ GdkPixbuf *pixbuf;
+ if (rbvals.texture)
+ pixbuf = gdk_pixbuf_new_from_inline (-1, rbvals.texture, FALSE, NULL);
+ else
+ pixbuf = gdk_pixbuf_new_from_file (rbvals.custom_texture, NULL);
+
+ gint32 texture_layer = gimp_layer_new_from_pixbuf (preview_image,
+ "texture",
+ pixbuf,
+ rbvals.opacity,
+ GIMP_NORMAL_MODE, 0, 0);
+ gimp_image_add_layer (preview_image, texture_layer, -1);
+ gimp_layer_scale (texture_layer, width, height, FALSE);
+ gimp_invert (texture_layer);
+ gimp_edit_copy (texture_layer);
+ gimp_edit_paste (texture_mask, TRUE);
+ gimp_image_remove_layer (preview_image, texture_layer);
+
+ preview_update (preview);
+}
+
+

0 comments on commit c51d866

Please sign in to comment.
Something went wrong with that request. Please try again.