61 GtkStateFlags
state = gtk_widget_get_state_flags(widget);
64 GtkStyleContext *context = gtk_widget_get_style_context(widget);
65 gtk_style_context_get_color(context,
state, &fg_color);
71 if(
state & GTK_STATE_FLAG_PRELIGHT)
74 flags &= ~CPF_PRELIGHT;
78 GtkAllocation allocation;
79 gtk_widget_get_allocation(widget, &allocation);
80 const int width = allocation.width;
81 const int height = allocation.height;
84 GtkBorder margin, border, padding;
85 gtk_style_context_get_margin(context,
state, &margin);
86 gtk_style_context_get_border(context,
state, &border);
87 gtk_style_context_get_padding(context,
state, &padding);
90 int startx = margin.left;
91 int starty = margin.top;
92 int cwidth =
width - margin.left - margin.right;
93 int cheight =
height - margin.top - margin.bottom;
96 gtk_render_background(context, cr, startx, starty, cwidth, cheight);
97 gtk_render_frame(context, cr, startx, starty, cwidth, cheight);
98 gdk_cairo_set_source_rgba(cr, &fg_color);
104 startx += border.left + padding.left;
105 starty += border.top + padding.top;
106 cwidth -= border.left + border.right + padding.left + padding.right;
107 cheight -= border.top + border.bottom + padding.top + padding.bottom;
113 GtkBorder cmargin = { 0 };
114 GtkWidget *canvas = gtk_bin_get_child(GTK_BIN(widget));
117 GtkStyleContext *ccontext = gtk_widget_get_style_context(canvas);
118 gtk_style_context_get_margin(ccontext,
state, &cmargin);
121 startx += round(cmargin.left * cwidth / 100.0f);
122 starty += round(cmargin.top * cheight / 100.0f);
123 cwidth = round((
float)cwidth * (1.0 - (cmargin.left + cmargin.right) / 100.0f));
124 cheight = round((
float)cheight * (1.0 - (cmargin.top + cmargin.bottom) / 100.0f));
127 if(cwidth > 0 && cheight > 0)
128 DTGTK_BUTTON(widget)->icon(cr, startx, starty, cwidth, cheight,
flags, icon_data);
139 button->
icon = paint;
142 button->
canvas = gtk_drawing_area_new();
143 gtk_container_add(GTK_CONTAINER(button), button->
canvas);
145 gtk_widget_set_valign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
146 gtk_widget_set_halign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
147 gtk_widget_set_vexpand(GTK_WIDGET(button),
FALSE);
148 gtk_widget_set_hexpand(GTK_WIDGET(button),
FALSE);
154 static GType dtgtk_button_type = 0;
155 if(!dtgtk_button_type)
157 static const GTypeInfo dtgtk_button_info = {
164 dtgtk_button_type = g_type_register_static(GTK_TYPE_BUTTON,
"GtkDarktableButton", &dtgtk_button_info, 0);
166 return dtgtk_button_type;