Tint2conf: more gradient support

This commit is contained in:
o9000 2017-03-04 12:24:55 +01:00
parent 8ec7f2dd9c
commit b94cb3eb7e
4 changed files with 138 additions and 41 deletions

View file

@ -98,7 +98,7 @@ void create_background(GtkWidget *parent)
GTK_TYPE_INT, GTK_TYPE_INT,
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_STRING, GTK_TYPE_STRING,
@ -106,12 +106,12 @@ void create_background(GtkWidget *parent)
GTK_TYPE_INT, GTK_TYPE_INT,
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_TYPE_INT, GTK_TYPE_INT,
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_BOOL, GTK_TYPE_BOOL,
GTK_TYPE_BOOL, GTK_TYPE_BOOL,
GTK_TYPE_BOOL, GTK_TYPE_BOOL,
@ -359,7 +359,7 @@ void create_background(GtkWidget *parent)
g_signal_connect(G_OBJECT(background_gradient_over), "changed", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_gradient_over), "changed", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_fill_color_press), "color-set", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_fill_color_press), "color-set", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_border_color_press), "color-set", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_border_color_press), "color-set", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_gradient_over), "changed", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_gradient_press), "changed", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_border_width), "value-changed", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_border_width), "value-changed", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_corner_radius), "value-changed", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_corner_radius), "value-changed", G_CALLBACK(background_update), NULL);
g_signal_connect(G_OBJECT(background_border_sides_top), "toggled", G_CALLBACK(background_update), NULL); g_signal_connect(G_OBJECT(background_border_sides_top), "toggled", G_CALLBACK(background_update), NULL);
@ -426,8 +426,8 @@ void background_create_new()
&borderColor, &borderColor,
bgColBorderOpacity, bgColBorderOpacity,
borderOpacity, borderOpacity,
bgColGradientId, bgColGradientId,
-1, -1,
bgColBorderWidth, bgColBorderWidth,
b, b,
bgColCornerRadius, bgColCornerRadius,
@ -442,8 +442,8 @@ void background_create_new()
&borderColorOver, &borderColorOver,
bgColBorderOpacityOver, bgColBorderOpacityOver,
borderOpacityOver, borderOpacityOver,
bgColGradientIdOver, bgColGradientIdOver,
-1, -1,
bgColFillColorPress, bgColFillColorPress,
&fillColorPress, &fillColorPress,
bgColFillOpacityPress, bgColFillOpacityPress,
@ -452,8 +452,8 @@ void background_create_new()
&borderColorPress, &borderColorPress,
bgColBorderOpacityPress, bgColBorderOpacityPress,
borderOpacityPress, borderOpacityPress,
bgColGradientIdPress, bgColGradientIdPress,
-1, -1,
bgColBorderSidesTop, bgColBorderSidesTop,
sideTop, sideTop,
bgColBorderSidesBottom, bgColBorderSidesBottom,
@ -542,12 +542,12 @@ void background_duplicate(GtkWidget *widget, gpointer data)
&sideLeft, &sideLeft,
bgColBorderSidesRight, bgColBorderSidesRight,
&sideRight, &sideRight,
bgColGradientId, bgColGradientId,
&gradient_id, &gradient_id,
bgColGradientIdOver, bgColGradientIdOver,
&gradient_id_over, &gradient_id_over,
bgColGradientIdPress, bgColGradientIdPress,
&gradient_id_press, &gradient_id_press,
-1); -1);
gtk_list_store_append(backgrounds, &iter); gtk_list_store_append(backgrounds, &iter);
@ -561,8 +561,8 @@ void background_duplicate(GtkWidget *widget, gpointer data)
fillOpacity, fillOpacity,
bgColBorderColor, bgColBorderColor,
borderColor, borderColor,
bgColGradientId, bgColGradientId,
gradient_id, gradient_id,
bgColBorderOpacity, bgColBorderOpacity,
borderOpacity, borderOpacity,
bgColText, bgColText,
@ -575,8 +575,8 @@ void background_duplicate(GtkWidget *widget, gpointer data)
borderColorOver, borderColorOver,
bgColBorderOpacityOver, bgColBorderOpacityOver,
borderOpacityOver, borderOpacityOver,
bgColGradientIdOver, bgColGradientIdOver,
gradient_id_over, gradient_id_over,
bgColFillColorPress, bgColFillColorPress,
fillColorPress, fillColorPress,
bgColFillOpacityPress, bgColFillOpacityPress,
@ -585,8 +585,8 @@ void background_duplicate(GtkWidget *widget, gpointer data)
borderColorPress, borderColorPress,
bgColBorderOpacityPress, bgColBorderOpacityPress,
borderOpacityPress, borderOpacityPress,
bgColGradientIdPress, bgColGradientIdPress,
gradient_id_press, gradient_id_press,
bgColBorderWidth, bgColBorderWidth,
b, b,
bgColCornerRadius, bgColCornerRadius,
@ -651,6 +651,7 @@ void background_update_image(int index)
int fillOpacity = 50; int fillOpacity = 50;
GdkColor *borderColor; GdkColor *borderColor;
int borderOpacity = 100; int borderOpacity = 100;
int gradient_id;
gtk_tree_model_get(GTK_TREE_MODEL(backgrounds), gtk_tree_model_get(GTK_TREE_MODEL(backgrounds),
&iter, &iter,
@ -666,6 +667,8 @@ void background_update_image(int index)
&b, &b,
bgColCornerRadius, bgColCornerRadius,
&r, &r,
bgColGradientId,
&gradient_id,
-1); -1);
double bg_r, bg_g, bg_b, bg_a; double bg_r, bg_g, bg_b, bg_a;
@ -697,9 +700,8 @@ void background_update_image(int index)
cairo_arc(cr, r + b, r + b, r, 180 * degrees, 270 * degrees); cairo_arc(cr, r + b, r + b, r, 180 * degrees, 270 * degrees);
cairo_close_path(cr); cairo_close_path(cr);
int gradient_index = gtk_combo_box_get_active(GTK_COMBO_BOX(background_gradient)); if (index >= 1 && gradient_id >= 1) {
if (index >= 1 && gradient_index >= 1) { GradientConfig *g = (GradientConfig *)g_list_nth(gradients, (guint)gradient_id)->data;
GradientConfig *g = (GradientConfig *)g_list_nth(gradients, (guint)gradient_index)->data;
gradient_draw(cr, g, w, h, TRUE); gradient_draw(cr, g, w, h, TRUE);
} }
@ -800,8 +802,8 @@ void background_update(GtkWidget *widget, gpointer data)
&borderColor, &borderColor,
bgColBorderOpacity, bgColBorderOpacity,
borderOpacity, borderOpacity,
bgColGradientId, bgColGradientId,
gradient_id, gradient_id,
bgColFillColorOver, bgColFillColorOver,
&fillColorOver, &fillColorOver,
bgColFillOpacityOver, bgColFillOpacityOver,
@ -810,8 +812,8 @@ void background_update(GtkWidget *widget, gpointer data)
&borderColorOver, &borderColorOver,
bgColBorderOpacityOver, bgColBorderOpacityOver,
borderOpacityOver, borderOpacityOver,
bgColGradientIdOver, bgColGradientIdOver,
gradient_id_over, gradient_id_over,
bgColFillColorPress, bgColFillColorPress,
&fillColorPress, &fillColorPress,
bgColFillOpacityPress, bgColFillOpacityPress,
@ -820,8 +822,8 @@ void background_update(GtkWidget *widget, gpointer data)
&borderColorPress, &borderColorPress,
bgColBorderOpacityPress, bgColBorderOpacityPress,
borderOpacityPress, borderOpacityPress,
bgColGradientIdPress, bgColGradientIdPress,
gradient_id_press, gradient_id_press,
bgColBorderWidth, bgColBorderWidth,
b, b,
bgColCornerRadius, bgColCornerRadius,
@ -885,8 +887,8 @@ void current_background_changed(GtkWidget *widget, gpointer data)
&borderColor, &borderColor,
bgColBorderOpacity, bgColBorderOpacity,
&borderOpacity, &borderOpacity,
bgColGradientId, bgColGradientId,
&gradient_id, &gradient_id,
bgColFillColorOver, bgColFillColorOver,
&fillColorOver, &fillColorOver,
bgColFillOpacityOver, bgColFillOpacityOver,
@ -895,8 +897,8 @@ void current_background_changed(GtkWidget *widget, gpointer data)
&borderColorOver, &borderColorOver,
bgColBorderOpacityOver, bgColBorderOpacityOver,
&borderOpacityOver, &borderOpacityOver,
bgColGradientIdOver, bgColGradientIdOver,
&gradient_id_over, &gradient_id_over,
bgColFillColorPress, bgColFillColorPress,
&fillColorPress, &fillColorPress,
bgColFillOpacityPress, bgColFillOpacityPress,
@ -905,8 +907,8 @@ void current_background_changed(GtkWidget *widget, gpointer data)
&borderColorPress, &borderColorPress,
bgColBorderOpacityPress, bgColBorderOpacityPress,
&borderOpacityPress, &borderOpacityPress,
bgColGradientIdPress, bgColGradientIdPress,
&gradient_id_press, &gradient_id_press,
bgColBorderWidth, bgColBorderWidth,
&b, &b,
bgColCornerRadius, bgColCornerRadius,
@ -959,3 +961,61 @@ void current_background_changed(GtkWidget *widget, gpointer data)
background_updates_disabled = FALSE; background_updates_disabled = FALSE;
background_update_image(index); background_update_image(index);
} }
void background_update_for_gradient(int gradient_id_changed)
{
gboolean deleted = gradient_id_changed >= get_model_length(GTK_TREE_MODEL(gradient_ids));
int current_bg_index = gtk_combo_box_get_active(GTK_COMBO_BOX(current_background));
for (int index = 1;; index++) {
GtkTreePath *path;
GtkTreeIter iter;
path = gtk_tree_path_new_from_indices(index, -1);
gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(backgrounds), &iter, path);
gtk_tree_path_free(path);
if (!found) {
break;
}
int gradient_id, gradient_id_over, gradient_id_press;
gtk_tree_model_get(GTK_TREE_MODEL(backgrounds),
&iter,
bgColGradientId,
&gradient_id,
bgColGradientIdOver,
&gradient_id_over,
bgColGradientIdPress,
&gradient_id_press,
-1);
gboolean changed = FALSE;
if (gradient_id == gradient_id_changed && deleted)
gradient_id = -1, changed = TRUE;
if (gradient_id_over == gradient_id_changed && deleted)
gradient_id_over = -1, changed = TRUE;
if (gradient_id_press == gradient_id_changed && deleted)
gradient_id_press = -1, changed = TRUE;
if (changed) {
gtk_list_store_set(GTK_LIST_STORE(backgrounds),
&iter,
bgColGradientId,
gradient_id,
bgColGradientIdOver,
gradient_id_over,
bgColGradientIdPress,
gradient_id_press,
-1);
if (index == current_bg_index) {
gtk_combo_box_set_active(GTK_COMBO_BOX(background_gradient), gradient_id);
gtk_combo_box_set_active(GTK_COMBO_BOX(background_gradient_over), gradient_id_over);
gtk_combo_box_set_active(GTK_COMBO_BOX(background_gradient_press), gradient_id_press);
background_force_update();
} else {
background_update_image(index);
}
} else {
background_update_image(index);
}
}
}

View file

@ -168,9 +168,42 @@ void gradient_create_new(GradientConfigType t)
current_gradient_changed(0, 0); current_gradient_changed(0, 0);
} }
gpointer copy_GradientConfigColorStop(gconstpointer arg, gpointer data)
{
GradientConfigColorStop *old = (GradientConfigColorStop *)arg;
GradientConfigColorStop *copy = (GradientConfigColorStop *)calloc(1, sizeof(GradientConfigColorStop));
memcpy(copy, old, sizeof(GradientConfigColorStop));
return copy;
}
void gradient_duplicate(GtkWidget *widget, gpointer data) void gradient_duplicate(GtkWidget *widget, gpointer data)
{ {
gradient_create_new(GRADIENT_CONFIG_VERTICAL); int old_index = gtk_combo_box_get_active(GTK_COMBO_BOX(current_gradient));
if (old_index < 0) {
gradient_create_new(GRADIENT_CONFIG_VERTICAL);
return;
}
GradientConfig *g_old = (GradientConfig*)g_list_nth(gradients, (guint)old_index)->data;
int index = get_model_length(GTK_TREE_MODEL(gradient_ids));
GradientConfig *g = (GradientConfig *)calloc(1, sizeof(GradientConfig));
g->type = g_old->type;
g->extra_color_stops = g_list_copy_deep(g->extra_color_stops, copy_GradientConfigColorStop, NULL);
gradients = g_list_append(gradients, g);
GtkTreeIter iter;
gtk_list_store_append(gradient_ids, &iter);
gtk_list_store_set(gradient_ids, &iter,
grColPixbuf, NULL,
grColId, &index,
grColText, "",
-1);
gradient_update_image(index);
gtk_combo_box_set_active(GTK_COMBO_BOX(current_gradient), index);
current_gradient_changed(0, 0);
} }
void gradient_delete(GtkWidget *widget, gpointer data) void gradient_delete(GtkWidget *widget, gpointer data)
@ -192,9 +225,11 @@ void gradient_delete(GtkWidget *widget, gpointer data)
gradients = g_list_remove(gradients, g_list_nth(gradients, (guint)index)->data); gradients = g_list_remove(gradients, g_list_nth(gradients, (guint)index)->data);
gtk_list_store_remove(gradient_ids, &iter); gtk_list_store_remove(gradient_ids, &iter);
if (index == get_model_length(GTK_TREE_MODEL(gradient_ids))) background_update_for_gradient(index);
if (index >= get_model_length(GTK_TREE_MODEL(gradient_ids)))
index--; index--;
gtk_combo_box_set_active(GTK_COMBO_BOX(gradient_ids), index); gtk_combo_box_set_active(GTK_COMBO_BOX(current_gradient), index);
} }
void gradient_draw(cairo_t *c, GradientConfig *g, int w, int h, gboolean preserve) void gradient_draw(cairo_t *c, GradientConfig *g, int w, int h, gboolean preserve)
@ -302,6 +337,7 @@ void gradient_update(GtkWidget *widget, gpointer data)
grColText, "", grColText, "",
-1); -1);
gradient_update_image(index); gradient_update_image(index);
background_update_for_gradient(index);
} }
void current_gradient_changed(GtkWidget *widget, gpointer data) void current_gradient_changed(GtkWidget *widget, gpointer data)

View file

@ -12,6 +12,7 @@ void gradient_update_image(int index);
void gradient_update(GtkWidget *widget, gpointer data); void gradient_update(GtkWidget *widget, gpointer data);
void gradient_force_update(); void gradient_force_update();
void current_gradient_changed(GtkWidget *widget, gpointer data); void current_gradient_changed(GtkWidget *widget, gpointer data);
void background_update_for_gradient(int gradient_id);
typedef enum GradientConfigType { typedef enum GradientConfigType {
GRADIENT_CONFIG_VERTICAL = 0, GRADIENT_CONFIG_VERTICAL = 0,

View file

@ -191,7 +191,7 @@ gboolean update_snapshot()
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &path, -1); gtk_tree_model_get(model, &iter, COL_THEME_FILE, &path, -1);
char fname[128]; char fname[128];
sprintf(fname, "tint2-%d.jpg", (int)getpid()); sprintf(fname, "tint2-%d.png", (int)getpid());
gchar *snap = g_build_filename(g_get_tmp_dir(), fname, NULL); gchar *snap = g_build_filename(g_get_tmp_dir(), fname, NULL);
g_remove(snap); g_remove(snap);