Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
icon.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2011 Henrik Andersson.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2012, 2014, 2016, 2018 Tobias Ellinghaus.
6 Copyright (C) 2013-2014, 2016 Roman Lebedev.
7 Copyright (C) 2019 Aurélien PIERRE.
8 Copyright (C) 2020 Pascal Obry.
9 Copyright (C) 2021 Hubert Kowalski.
10 Copyright (C) 2022 Martin Bařinka.
11
12 darktable is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 darktable is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with darktable. If not, see <http://www.gnu.org/licenses/>.
24*/
25#include "icon.h"
26#include "gui/gtk.h"
27#include <string.h>
28
29static void _icon_class_init(GtkDarktableIconClass *klass);
30static void _icon_init(GtkDarktableIcon *icon);
31static gboolean _icon_draw(GtkWidget *widget, cairo_t *cr);
32
33
35{
36 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
37 widget_class->draw = _icon_draw;
38}
39
40static void _icon_init(GtkDarktableIcon *icon)
41{
42}
43
44static gboolean _icon_draw(GtkWidget *widget, cairo_t *cr)
45{
46 g_return_val_if_fail(!IS_NULL_PTR(widget), FALSE);
47 g_return_val_if_fail(DTGTK_IS_ICON(widget), FALSE);
48
49 /* begin cairo drawing */
50 GtkAllocation allocation;
51 gtk_widget_get_allocation(widget, &allocation);
52
53 GtkStateFlags state = gtk_widget_get_state_flags(widget);
54
55 GdkRGBA fg_color;
56 GtkStyleContext *context = gtk_widget_get_style_context(widget);
57 gtk_style_context_get_color(context, state, &fg_color);
58
59 gdk_cairo_set_source_rgba(cr, &fg_color);
60
61 /* draw icon */
62 if(DTGTK_ICON(widget)->icon)
63 DTGTK_ICON(widget)->icon(cr, 0, 0, allocation.width, allocation.height, DTGTK_ICON(widget)->icon_flags,
64 DTGTK_ICON(widget)->icon_data);
65
66 return FALSE;
67}
68
69// Public functions
70GtkWidget *dtgtk_icon_new(DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
71{
72 GtkDarktableIcon *icon;
73 icon = g_object_new(dtgtk_icon_get_type(), NULL);
74 gtk_event_box_set_visible_window(GTK_EVENT_BOX(icon), FALSE);
75 icon->icon = paint;
76 icon->icon_flags = paintflags;
77 icon->icon_data = paintdata;
78 gtk_widget_set_name(GTK_WIDGET(icon), "dt-icon");
79 return (GtkWidget *)icon;
80}
81
83{
84 static GType dtgtk_icon_type = 0;
85 if(!dtgtk_icon_type)
86 {
87 static const GTypeInfo dtgtk_icon_info = {
88 sizeof(GtkDarktableIconClass), (GBaseInitFunc)NULL, (GBaseFinalizeFunc)NULL,
89 (GClassInitFunc)_icon_class_init, NULL, /* class_finalize */
90 NULL, /* class_data */
91 sizeof(GtkDarktableIcon), 0, /* n_preallocs */
92 (GInstanceInitFunc)_icon_init,
93 };
94 dtgtk_icon_type = g_type_register_static(GTK_TYPE_EVENT_BOX, "GtkDarktableIcon", &dtgtk_icon_info, 0);
95 }
96 return dtgtk_icon_type;
97}
98
99void dtgtk_icon_set_paint(GtkWidget *icon, DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
100{
101 g_return_if_fail(!IS_NULL_PTR(icon));
102 DTGTK_ICON(icon)->icon = paint;
103 DTGTK_ICON(icon)->icon_flags = paintflags;
104 DTGTK_ICON(icon)->icon_data = paintdata;
105 gtk_widget_queue_draw(icon);
106}
107
108// clang-format off
109// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
110// vim: shiftwidth=2 expandtab tabstop=2 cindent
111// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
112// clang-format on
113
#define FALSE
Definition ashift_lsd.c:158
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
void(* DTGTKCairoPaintIconFunc)(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)
Definition dtgtk/paint.h:75
static gboolean _icon_draw(GtkWidget *widget, cairo_t *cr)
Definition icon.c:44
static void _icon_init(GtkDarktableIcon *icon)
Definition icon.c:40
GtkWidget * dtgtk_icon_new(DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
Definition icon.c:70
static void _icon_class_init(GtkDarktableIconClass *klass)
Definition icon.c:34
GType dtgtk_icon_get_type()
Definition icon.c:82
void dtgtk_icon_set_paint(GtkWidget *icon, DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
Definition icon.c:99
struct _GtkDarktableIcon GtkDarktableIcon
struct _GtkDarktableIconClass GtkDarktableIconClass
#define DTGTK_IS_ICON(obj)
Definition icon.h:32
#define DTGTK_ICON(obj)
Definition icon.h:30
struct _GtkWidget GtkWidget
Definition splash.h:29
const float uint32_t state[4]
DTGTKCairoPaintIconFunc icon
Definition icon.h:38
void * icon_data
Definition icon.h:40
gint icon_flags
Definition icon.h:39