60 GtkStateFlags
state = gtk_widget_get_state_flags(widget);
63 GtkStyleContext *context = gtk_widget_get_style_context(widget);
64 gtk_style_context_get_color(context,
state, &fg_color);
70 if(
state & GTK_STATE_FLAG_PRELIGHT)
73 flags &= ~CPF_PRELIGHT;
77 GtkAllocation allocation;
78 gtk_widget_get_allocation(widget, &allocation);
79 const int width = allocation.width;
80 const int height = allocation.height;
83 GtkBorder margin, border, padding;
84 gtk_style_context_get_margin(context,
state, &margin);
85 gtk_style_context_get_border(context,
state, &border);
86 gtk_style_context_get_padding(context,
state, &padding);
89 int startx = margin.left;
90 int starty = margin.top;
91 int cwidth =
width - margin.left - margin.right;
92 int cheight =
height - margin.top - margin.bottom;
95 gtk_render_background(context, cr, startx, starty, cwidth, cheight);
96 gtk_render_frame(context, cr, startx, starty, cwidth, cheight);
97 gdk_cairo_set_source_rgba(cr, &fg_color);
103 startx += border.left + padding.left;
104 starty += border.top + padding.top;
105 cwidth -= border.left + border.right + padding.left + padding.right;
106 cheight -= border.top + border.bottom + padding.top + padding.bottom;
112 GtkBorder cmargin = { 0 };
113 GtkWidget *canvas = gtk_bin_get_child(GTK_BIN(widget));
116 GtkStyleContext *ccontext = gtk_widget_get_style_context(canvas);
117 gtk_style_context_get_margin(ccontext,
state, &cmargin);
120 startx += round(cmargin.left * cwidth / 100.0f);
121 starty += round(cmargin.top * cheight / 100.0f);
122 cwidth = round((
float)cwidth * (1.0 - (cmargin.left + cmargin.right) / 100.0f));
123 cheight = round((
float)cheight * (1.0 - (cmargin.top + cmargin.bottom) / 100.0f));
126 if(cwidth > 0 && cheight > 0)
127 DTGTK_BUTTON(widget)->icon(cr, startx, starty, cwidth, cheight,
flags, icon_data);
138 button->
icon = paint;
141 button->
canvas = gtk_drawing_area_new();
142 gtk_container_add(GTK_CONTAINER(button), button->
canvas);
144 gtk_widget_set_valign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
145 gtk_widget_set_halign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
146 gtk_widget_set_vexpand(GTK_WIDGET(button),
FALSE);
147 gtk_widget_set_hexpand(GTK_WIDGET(button),
FALSE);
153 static GType dtgtk_button_type = 0;
154 if(!dtgtk_button_type)
156 static const GTypeInfo dtgtk_button_info = {
163 dtgtk_button_type = g_type_register_static(GTK_TYPE_BUTTON,
"GtkDarktableButton", &dtgtk_button_info, 0);
165 return dtgtk_button_type;
void(* DTGTKCairoPaintIconFunc)(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)