Skip to content

Commit e886104

Browse files
committed
ui: improve the box appearance, positioning
1 parent 6095d6e commit e886104

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

plugins/string-machine/StringMachineUI.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,21 @@ void StringMachineUI::onDisplay()
198198
for (const Label *label : group_labels) {
199199
Font font;
200200
font.name = "title";
201-
font.size = 12.0;
201+
font.size = 13.0;
202+
font.color = ColorRGBA8{0xff, 0xff, 0xff, 0xff};
202203

203-
Rect bounds = label->bounds;
204+
RectF frame = label->bounds.to<double>().off_by({0.5, 0.5}).reduced({1, 1});
205+
RectF titleFrame = RectF(frame).take_from_top(14);
204206

205-
bounds.y += 2;
207+
cairo_rounded_rectangle_with_corners(cr, titleFrame, 5.0, RectangleNW|RectangleNE);
208+
cairo_set_source_rgba8(cr, ColorRGBA8{0x58, 0x58, 0x56, 0xff});
209+
cairo_fill_preserve(cr);
210+
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
211+
cairo_stroke(cr);
206212

207-
fe.drawInBox(cr, label->text, font, bounds, label->align);
213+
Rect textBounds = label->bounds.off_by({0, 2});
214+
fe.drawInBox(cr, label->text, font, textBounds, label->align);
208215

209-
RectF frame = label->bounds.to<double>().off_by({0.5, 0.5});
210216
cairo_rounded_rectangle(cr, frame, 5.0);
211217
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
212218
cairo_stroke(cr);
@@ -217,13 +223,10 @@ void StringMachineUI::onDisplay()
217223
font.name = "title";
218224
font.size = 12.0;
219225

220-
Rect bounds = label->bounds;
221-
222-
bounds.y += 2;
223-
224-
fe.drawInBox(cr, label->text, font, bounds, label->align);
226+
Rect textBounds = label->bounds.off_by({0, 2});
227+
fe.drawInBox(cr, label->text, font, textBounds, label->align);
225228

226-
RectF frame = label->bounds.to<double>().off_by({0.5, 0.5});
229+
RectF frame = label->bounds.to<double>().off_by({0.5, 0.5}).reduced({1, 1});
227230
cairo_rounded_rectangle(cr, frame, 5.0);
228231
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
229232
cairo_stroke(cr);

plugins/string-machine/StringMachineUILayouts.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace MainLayout {
7474
DECL_IGNORABLE static Rect val_EnvSustain = {725, 193, 40, 12};
7575
DECL_IGNORABLE static Rect knob_EnvRelease = {775, 160, 30, 30};
7676
DECL_IGNORABLE static Rect val_EnvRelease = {770, 193, 40, 12};
77-
DECL_IGNORABLE static Rect plot_Env = {815, 155, 105, 45};
77+
DECL_IGNORABLE static Rect plot_Env = {815, 160, 105, 45};
7878
DECL_IGNORABLE static Label group_StringOsc_label = {"String Osc", 17, {5, 30, 185, 170}};
7979
DECL_IGNORABLE static Label subgroup_AutoDetune_label = {"Auto Detune", 17, {10, 50, 85, 145}};
8080
DECL_IGNORABLE static Label knob_OscDetune_label = {"Detune", 1, {50, 145, 30, 30}};
@@ -111,5 +111,5 @@ namespace MainLayout {
111111
DECL_IGNORABLE static Label knob_EnvDecay_label = {"D", 1, {685, 160, 30, 30}};
112112
DECL_IGNORABLE static Label knob_EnvSustain_label = {"S", 1, {730, 160, 30, 30}};
113113
DECL_IGNORABLE static Label knob_EnvRelease_label = {"R", 1, {775, 160, 30, 30}};
114-
DECL_IGNORABLE static Label plot_Env_label = {"ADSR - Env", 1, {815, 155, 105, 45}};
114+
DECL_IGNORABLE static Label plot_Env_label = {"ADSR - Env", 1, {815, 160, 105, 45}};
115115
};

resources/ui/layout.fl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ header_name {.h}
44
code_name {.cxx}
55
Function {make_window()} {open
66
} {
7-
Fl_Window window_TopLevel {open selected
7+
Fl_Window window_TopLevel {open
88
xywh {741 151 935 245} type Double visible
99
} {
1010
Fl_Group group_StringOsc {
@@ -223,8 +223,8 @@ Function {make_window()} {open
223223
xywh {770 193 40 12} box THIN_UP_BOX labelsize 10
224224
}
225225
Fl_Box plot_Env {
226-
label {ADSR - Env}
227-
xywh {815 155 105 45} box ENGRAVED_BOX labelsize 10 align 1
226+
label {ADSR - Env} selected
227+
xywh {815 160 105 45} box ENGRAVED_BOX labelsize 10 align 1
228228
}
229229
}
230230
}

sources/ui/Cairo++.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,48 @@ void cairo_rounded_rectangle(cairo_t *cr, const RectT<T> &r, double radius)
3333
double w = r.w;
3434
double h = r.h;
3535

36-
cairo_new_sub_path(cr);
36+
cairo_new_path(cr);
3737
cairo_arc(cr, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
3838
cairo_arc(cr, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
3939
cairo_arc(cr, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
4040
cairo_arc(cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
4141
cairo_close_path(cr);
4242
}
43+
44+
enum RectangleCorner {
45+
RectangleNE = 1 << 0,
46+
RectangleSE = 1 << 1,
47+
RectangleSW = 1 << 2,
48+
RectangleNW = 1 << 3,
49+
RectangleAllCorners = RectangleNE|RectangleSE|RectangleSW|RectangleNW,
50+
};
51+
52+
template <class T>
53+
void cairo_rounded_rectangle_with_corners(cairo_t *cr, const RectT<T> &r, double radius, int corners)
54+
{
55+
double degrees = M_PI / 180.0;
56+
57+
double x = r.x;
58+
double y = r.y;
59+
double w = r.w;
60+
double h = r.h;
61+
62+
cairo_new_path(cr);
63+
if (corners & RectangleNE)
64+
cairo_arc(cr, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
65+
else
66+
cairo_move_to(cr, x + w, y);
67+
if (corners & RectangleSE)
68+
cairo_arc(cr, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
69+
else
70+
cairo_line_to(cr, x + w, y + h);
71+
if (corners & RectangleSW)
72+
cairo_arc(cr, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
73+
else
74+
cairo_line_to(cr, x, y + h);
75+
if (corners & RectangleNW)
76+
cairo_arc(cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
77+
else
78+
cairo_line_to(cr, x, y);
79+
cairo_close_path(cr);
80+
}

0 commit comments

Comments
 (0)