Permalink
Browse files

texture-border: add scrollbar to textures and make the dialog display…

… more quickly.
  • Loading branch information...
1 parent ba492aa commit b5dedcfc54fa35d8892eda0633f986f7568c7864 @hejiann committed Jul 31, 2012
Showing with 45 additions and 16 deletions.
  1. +1 −0 README
  2. +0 −2 beautify.c
  3. +44 −14 texture-border.c
View
1 README
@@ -52,6 +52,7 @@ CHANGELOG
2012-07-31:
beautify: fix ABao color effect.
texture-border: slim the plug-in size by only provide top textures and let other textures can be download.
+texture-border: add scrollbar to textures and make the dialog display quickly.
2012-07-30:
beautify: fix missing effect.
View
@@ -825,9 +825,7 @@ effects_switch_page (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpo
static time_t effects_timestamp [] = {0, 0, 0, 0, 0, 0};
if (effects_timestamp[page_num] > 0)
- {
return;
- }
// fix gtk2
page = gtk_notebook_get_nth_page (notebook, page_num);
View
@@ -50,7 +50,8 @@ static gboolean texture_border_dialog ();
static void create_texture_page (GtkNotebook *notebook, const gchar* category, const guint8** textures, guint n_textures);
static gboolean create_custom_texture_pages (GtkNotebook *notebook);
-static gboolean create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const gchar* path);
+static void create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const gchar* path);
+static void textures_switch_page (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data);
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);
@@ -109,6 +110,8 @@ static const guint8* top_textures[] =
texture_200543,
};
+static GArray *textures_timestamps = NULL;
+
/* compatable with gtk2 */
#if GTK_MAJOR_VERSION < 3
GtkWidget *
@@ -329,7 +332,7 @@ texture_border_dialog ()
right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (right_vbox), 12);
- gtk_widget_set_size_request (right_vbox, 300, -1);
+ gtk_widget_set_size_request (right_vbox, 320, -1);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
@@ -404,7 +407,12 @@ texture_border_dialog ()
create_texture_page (GTK_NOTEBOOK (notebook), "Top", top_textures, G_N_ELEMENTS (top_textures));
- if (!create_custom_texture_pages (GTK_NOTEBOOK (notebook))) {
+ if (create_custom_texture_pages (GTK_NOTEBOOK (notebook))) {
+ textures_timestamps = g_array_new (FALSE, TRUE, sizeof (time_t));
+ g_array_set_size (textures_timestamps, gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)));
+ g_signal_connect (notebook, "switch-page", G_CALLBACK (textures_switch_page), NULL);
+ }
+ else {
label = gtk_label_new ("You can download more textures at https://github.com/hejiann/beautify/wiki");
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (right_vbox), label, FALSE, FALSE, 0);
@@ -481,37 +489,63 @@ create_custom_texture_pages (GtkNotebook *notebook)
gchar *filename = g_build_filename (texture_dir, dir_ent, NULL);
if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
- if (create_custom_texture_page (GTK_NOTEBOOK (notebook), dir_ent, filename))
- has_custom_texture = TRUE;
+ create_custom_texture_page (GTK_NOTEBOOK (notebook), dir_ent, filename);
+ has_custom_texture = TRUE;
}
}
}
return has_custom_texture;
}
-static gboolean
+static void
create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const gchar* path) {
- gboolean has_custom_texture = FALSE;
-
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);
+ gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
+}
+
+static void
+textures_switch_page (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data)
+{
+ if (page_num == 0 || g_array_index (textures_timestamps, time_t, page_num) > 0)
+ return;
+
+ // fix gtk2
+ page = gtk_notebook_get_nth_page (notebook, page_num);
+
+ gtk_container_set_border_width (GTK_CONTAINER (page), 0);
+ gtk_widget_set_size_request (page, -1, 480);
+
+ const gchar *category = gtk_notebook_get_tab_label_text(notebook, page);
+
+ /* scrolled window */
+ GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (page), scrolled_window, TRUE, TRUE, 0);
+ gtk_widget_show (scrolled_window);
+
/* 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_container_set_border_width (GTK_CONTAINER (table), 10);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), table);
gtk_widget_show (table);
gint row = 1;
gint col = 1;
+ const gchar *gimp_dir = gimp_directory ();
+ const gchar *texture_dir = g_build_filename (gimp_dir, TEXTURE_PATH, NULL);
+ const gchar *path = g_build_filename (texture_dir, category, NULL);
+
GDir *dir = g_dir_open (path, 0, NULL);
if (dir)
{
@@ -539,14 +573,10 @@ create_custom_texture_page (GtkNotebook *notebook, const gchar* category, const
}
g_signal_connect (event_box, "button_press_event", G_CALLBACK (custom_texture_press), filename);
-
- has_custom_texture = TRUE;
}
}
- gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
-
- return has_custom_texture;
+ g_array_index (textures_timestamps, time_t, page_num) = time (NULL);
}
static gboolean

0 comments on commit b5dedcf

Please sign in to comment.