Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
custom_button.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __GUI_WIDGETS_CUSTOM_BUTTON_H__
11#define __GUI_WIDGETS_CUSTOM_BUTTON_H__
12
13#include "gtk_wrapper.h"
14
21#define CUSTOM_BUTTON_WIDGET_MAX_TRANSITION_FRAMES 9
22
24{
25 CUSTOM_BUTTON_WIDGET_STATE_NORMAL,
26 CUSTOM_BUTTON_WIDGET_STATE_HOVERED,
27 CUSTOM_BUTTON_WIDGET_STATE_ACTIVE,
28 CUSTOM_BUTTON_WIDGET_STATE_TOGGLED,
29
32};
33
34enum class CustomButtonWidgetOwner
35{
36 CUSTOM_BUTTON_WIDGET_OWNER_TRACK,
37 CUSTOM_BUTTON_WIDGET_OWNER_LANE,
38 CUSTOM_BUTTON_WIDGET_OWNER_AT,
39};
40
44typedef struct CustomButtonWidget
45{
48 // void (*press_cb) (void *);
49
51 // int is_toggle;
52
54 GdkRGBA def_color;
55
58
61
64 GdkRGBA held_color;
65
67 char icon_name[120];
68
71 int size;
72
75 int width;
76
78 // int hovered;
79
81 // int pressed;
82
84 double aspect;
85
89
91 // void * obj;
92
94 GdkTexture * icon_texture;
95
98
100 CustomButtonWidgetOwner owner_type;
101
103 void * owner;
104
106 GdkRGBA last_color;
107
113 char * text;
114
115 int text_height;
116
118 PangoLayout * layout;
119
121 double x;
122 double y;
123
131 unsigned int button_id;
132
135
137
142custom_button_widget_new (const char * icon_name, int size);
143
144void
145custom_button_widget_draw (
146 CustomButtonWidget * self,
147 GtkSnapshot * snapshot,
148 double x,
149 double y,
151
155void
157 CustomButtonWidget * self,
158 GtkSnapshot * snapshot,
159 double x,
160 double y,
161 double width,
163
170void
172 CustomButtonWidget * self,
173 PangoLayout * layout,
174 char * text,
175 const char * font_descr);
176
177void
178custom_button_widget_free (CustomButtonWidget * self);
179
184#endif
void custom_button_widget_set_text(CustomButtonWidget *self, PangoLayout *layout, char *text, const char *font_descr)
Sets the text and layout to draw the text width.
CustomButtonWidgetState
void custom_button_widget_draw_with_text(CustomButtonWidget *self, GtkSnapshot *snapshot, double x, double y, double width, CustomButtonWidgetState state)
CustomButtonWidget * custom_button_widget_new(const char *icon_name, int size)
Creates a new track widget from the given track.
@ CUSTOM_BUTTON_WIDGET_STATE_SEMI_TOGGLED
Only border is toggled.
Custom button to be drawn inside drawing areas.
int width
if non-zero, the button has "size" height and this width.
GdkRGBA hovered_color
Hovered color.
CustomButtonWidgetState last_state
Used to update caches if state changed.
GdkTexture * icon_texture
Object to pass to the callback.
char icon_name[120]
Name of the icon to show.
char * text
Text, if any, to show after the icon.
int transition_frames
Frames left for a transition in color.
double aspect
Whether currently hovered.
double x
X/y relative to parent drawing area.
double corner_radius
Corner curvature radius for the rounded rectangle.
GdkRGBA last_color
Used during transitions.
GdkRGBA held_color
Held color (used after clicking and before releasing).
CustomButtonWidgetOwner owner_type
Owner type.
PangoLayout * layout
Cache layout for drawing the text.
int size
Size in pixels (width and height will be set to this).
unsigned int button_id
The id of the button returned by a symap of its icon name, for better performance vs comparing string...
GdkRGBA toggled_color
Toggled color.
GdkRGBA def_color
Function to call on press (after click and release).