Zrythm v2.0.0-DEV
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
9
10#ifndef __GUI_WIDGETS_CUSTOM_BUTTON_H__
11#define __GUI_WIDGETS_CUSTOM_BUTTON_H__
12
13#include <string>
14
15#include "common/utils/color.h"
16#include "gui/backend/gtk_widgets/gtk_wrapper.h"
17
23
24constexpr int CUSTOM_BUTTON_WIDGET_MAX_TRANSITION_FRAMES = 9;
25
29class CustomButtonWidget
30{
31public:
32 enum class State
33 {
34 NORMAL,
35 HOVERED,
36 ACTIVE,
37 TOGGLED,
38
41 };
42
43 enum class Owner
44 {
45 TRACK,
46 LANE,
47 AT,
48 };
49
50public:
51 CustomButtonWidget ();
52 CustomButtonWidget (const std::string &iicon_name, int isize);
53 CustomButtonWidget (const CustomButtonWidget &) = delete;
54 CustomButtonWidget &operator= (const CustomButtonWidget &) = delete;
55 CustomButtonWidget (CustomButtonWidget &&) = default;
56 CustomButtonWidget &operator= (CustomButtonWidget &&) = default;
57 ~CustomButtonWidget ();
58
59 void draw (GtkSnapshot * snapshot, double ix, double iy, State state);
60
65 GtkSnapshot * snapshot,
66 double ix,
67 double iy,
68 double iwidth,
69 State state);
70
77 void set_text (
78 PangoLayout * ilayout,
79 const std::string &itext,
80 const std::string &font_descr);
81
82private:
83 void init ();
84
85 GdkRGBA get_color_for_state (State state) const;
86
87 void draw_bg (
88 GtkSnapshot * snapshot,
89 double ix,
90 double iy,
91 double iwidth,
92 int draw_frame,
93 State state);
94
95 void draw_icon_with_shadow (
96 GtkSnapshot * snapshot,
97 double ix,
98 double iy,
99 State state);
100
101public:
103 Color def_color = {};
104
106 Color hovered_color = {};
107
109 Color toggled_color = {};
110
113 Color held_color = {};
114
116 std::string icon_name;
117
119 int size = 0;
120
122 int width = 0;
123
125 double aspect = 1.0;
126
128 double corner_radius = 0.0;
129
131 GdkTexture * icon_texture = nullptr;
132
134 State last_state = State::NORMAL;
135
137 Owner owner_type = Owner::TRACK;
138
140 void * owner = nullptr;
141
143 Color last_color = {};
144
150 std::string text;
151
152 int text_height = 0;
153
155 PangoLayout * layout = nullptr;
156
158 double x = 0;
159 double y = 0;
160
168 unsigned int button_id = 0;
169
172};
173
177
178#endif
Color hovered_color
Hovered color.
int width
if non-zero, the button has "size" height and this width.
Owner owner_type
Owner type.
Color last_color
Used during transitions.
Color held_color
Held color (used after clicking and before releasing).
GdkTexture * icon_texture
The icon surface.
std::string icon_name
Name of the icon to show.
int transition_frames
Frames left for a transition in color.
double aspect
Aspect ratio for the rounded rectangle.
double x
X/y relative to parent drawing area.
std::string text
Text, if any, to show after the icon.
@ SEMI_TOGGLED
Only border is toggled.
double corner_radius
Corner curvature radius for the rounded rectangle.
void draw_with_text(GtkSnapshot *snapshot, double ix, double iy, double iwidth, State state)
void set_text(PangoLayout *ilayout, const std::string &itext, const std::string &font_descr)
Sets the text and layout to draw the text width.
Color toggled_color
Toggled color.
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...
Color def_color
Default color.
State last_state
Used to update caches if state changed.