Separator: simplify
This commit is contained in:
@@ -18,6 +18,13 @@
|
||||
Separator *create_separator()
|
||||
{
|
||||
Separator *separator = (Separator *)calloc(1, sizeof(Separator));
|
||||
separator->color.rgb[0] = 0.5;
|
||||
separator->color.rgb[1] = 0.5;
|
||||
separator->color.rgb[2] = 0.5;
|
||||
separator->color.alpha = 0.9;
|
||||
separator->style = SEPARATOR_DOTS;
|
||||
separator->thickness = 3;
|
||||
separator->area.paddingxlr = 1;
|
||||
return separator;
|
||||
}
|
||||
|
||||
@@ -96,133 +103,104 @@ void cleanup_separator()
|
||||
gboolean resize_separator(void *obj)
|
||||
{
|
||||
Separator *separator = (Separator *)obj;
|
||||
// Panel *panel = separator->area.panel;
|
||||
if (!separator->area.on_screen)
|
||||
return FALSE;
|
||||
|
||||
double d_height = panel_horizontal ? separator->area.height : separator->area.width;
|
||||
double d_thickness = round(d_height / 16) >= 1.0 ? round(d_height / 16) : 1.0;
|
||||
|
||||
if (separator->style == 3)
|
||||
d_thickness = round(d_height / 8) >= 1.0 ? round(d_height / 8) : 1.0;
|
||||
|
||||
double d_len = round(d_height / 16) >= 1.0 ? round(d_height / 16) : 1.0;
|
||||
double d_width = d_thickness * 5;
|
||||
|
||||
if (separator->style == 4) {
|
||||
d_width = d_thickness * 7;
|
||||
d_thickness = d_thickness * 3;
|
||||
}
|
||||
|
||||
if (separator->style == 2) {
|
||||
d_width = d_height;
|
||||
d_thickness = round(d_height / 8) >= 1.0 ? round(d_height / 8) : 1.0;
|
||||
d_len = d_thickness;
|
||||
}
|
||||
|
||||
double d_empty_thickness = d_thickness;
|
||||
|
||||
if (separator->style == 5 || separator->style == 6) {
|
||||
d_width = (d_thickness * 4) + 2.0;
|
||||
d_thickness = 1.0;
|
||||
}
|
||||
|
||||
if (panel_horizontal) {
|
||||
separator->area.width = d_width;
|
||||
separator->area.height = d_height;
|
||||
separator->area.width =
|
||||
separator->thickness + 2 * separator->area.paddingxlr + left_right_border_width(&separator->area);
|
||||
separator->length =
|
||||
separator->area.height - 2 * separator->area.paddingy - top_bottom_border_width(&separator->area);
|
||||
} else {
|
||||
separator->area.width = d_height;
|
||||
separator->area.height = d_width;
|
||||
separator->area.height =
|
||||
separator->thickness + 2 * separator->area.paddingxlr + top_bottom_border_width(&separator->area);
|
||||
separator->length =
|
||||
separator->area.width - 2 * separator->area.paddingy - left_right_border_width(&separator->area);
|
||||
}
|
||||
|
||||
separator->empty_thickness = d_empty_thickness;
|
||||
separator->thickness = d_thickness;
|
||||
separator->len = d_len;
|
||||
|
||||
schedule_redraw(&separator->area);
|
||||
panel_refresh = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void draw_separator_line(void *obj, cairo_t *c);
|
||||
void draw_separator_dots(void *obj, cairo_t *c);
|
||||
|
||||
void draw_separator(void *obj, cairo_t *c)
|
||||
{
|
||||
Separator *separator = (Separator *)obj;
|
||||
|
||||
if (separator->style == 0)
|
||||
if (separator->style == SEPARATOR_EMPTY)
|
||||
return;
|
||||
else if (separator->style == SEPARATOR_LINE)
|
||||
draw_separator_line(separator, c);
|
||||
else if (separator->style == SEPARATOR_DOTS)
|
||||
draw_separator_dots(separator, c);
|
||||
}
|
||||
|
||||
void draw_separator_line(void *obj, cairo_t *c)
|
||||
{
|
||||
Separator *separator = (Separator *)obj;
|
||||
|
||||
if (separator->thickness <= 0)
|
||||
return;
|
||||
|
||||
double start_point = 0 + (separator->thickness * 2);
|
||||
double end_point = separator->area.height - (separator->thickness * 2);
|
||||
if (!panel_horizontal)
|
||||
end_point = separator->area.width - (separator->thickness * 2);
|
||||
double count = end_point - start_point;
|
||||
double thickness = separator->thickness;
|
||||
double len = separator->len;
|
||||
int alt = 0;
|
||||
double x_fix = 0;
|
||||
|
||||
if (separator->style == 2) {
|
||||
if (!panel_horizontal)
|
||||
start_point = start_point + 2;
|
||||
cairo_set_source_rgba(c,
|
||||
separator->color.rgb[0],
|
||||
separator->color.rgb[1],
|
||||
separator->color.rgb[2],
|
||||
separator->color.alpha);
|
||||
cairo_set_line_width(c, 1);
|
||||
cairo_rectangle(c,
|
||||
start_point - 2,
|
||||
start_point - (panel_horizontal ? 0 : 4),
|
||||
end_point - thickness - 3,
|
||||
end_point - thickness - (panel_horizontal ? 3 : 3));
|
||||
cairo_stroke_preserve(c);
|
||||
cairo_fill(c);
|
||||
return;
|
||||
}
|
||||
|
||||
if (count < thickness)
|
||||
return;
|
||||
|
||||
while (((int)count) % 2) {
|
||||
if (alt) {
|
||||
start_point++;
|
||||
alt = 0;
|
||||
} else {
|
||||
end_point--;
|
||||
alt = 1;
|
||||
}
|
||||
count = end_point - start_point;
|
||||
if (count < thickness)
|
||||
return;
|
||||
}
|
||||
|
||||
if (separator->style == 3 || separator->style == 4)
|
||||
x_fix = round(thickness / 2) + (separator->style == 4 ? 1.0 : 0.0);
|
||||
|
||||
if (separator->style == 5 || separator->style == 6) {
|
||||
x_fix = -1.0;
|
||||
start_point = start_point + 2;
|
||||
end_point--;
|
||||
}
|
||||
|
||||
double separator_pattern[] = {len, len};
|
||||
double separator_style6_pattern[] = {1.0};
|
||||
cairo_set_source_rgba(c,
|
||||
separator->color.rgb[0],
|
||||
separator->color.rgb[1],
|
||||
separator->color.rgb[2],
|
||||
separator->color.alpha);
|
||||
cairo_set_line_width(c, thickness);
|
||||
if (separator->style == 6)
|
||||
cairo_set_dash(c, separator_style6_pattern, 1, 0);
|
||||
else
|
||||
cairo_set_dash(c, separator_pattern, sizeof(separator_pattern) / sizeof(separator_pattern[0]), 0);
|
||||
cairo_set_line_width(c, separator->thickness);
|
||||
cairo_set_line_cap(c, CAIRO_LINE_CAP_ROUND);
|
||||
if (panel_horizontal) {
|
||||
cairo_move_to(c, (separator->area.width / 2) - thickness + x_fix, start_point);
|
||||
cairo_line_to(c, (separator->area.width / 2) - thickness + x_fix, end_point);
|
||||
cairo_move_to(c, separator->area.width / 2.0, separator->area.height / 2.0 - separator->length / 2.0);
|
||||
cairo_line_to(c, separator->area.width / 2.0, separator->area.height / 2.0 + separator->length / 2.0);
|
||||
} else {
|
||||
cairo_move_to(c, start_point, (separator->area.height / 2) - thickness + x_fix);
|
||||
cairo_line_to(c, end_point, (separator->area.height / 2) - thickness + x_fix);
|
||||
cairo_move_to(c, separator->area.width / 2.0 - separator->length / 2.0, separator->area.height / 2.0);
|
||||
cairo_line_to(c, separator->area.width / 2.0 - separator->length / 2.0, separator->area.height / 2.0);
|
||||
}
|
||||
cairo_stroke(c);
|
||||
}
|
||||
|
||||
void draw_separator_dots(void *obj, cairo_t *c)
|
||||
{
|
||||
Separator *separator = (Separator *)obj;
|
||||
if (separator->thickness <= 0)
|
||||
return;
|
||||
|
||||
cairo_set_source_rgba(c,
|
||||
separator->color.rgb[0],
|
||||
separator->color.rgb[1],
|
||||
separator->color.rgb[2],
|
||||
separator->color.alpha);
|
||||
cairo_set_line_width(c, 0);
|
||||
|
||||
int num_circles = separator->length / (1.618 * separator->thickness - 1);
|
||||
double spacing = (separator->length - num_circles * separator->thickness) / MAX(1.0, num_circles - 1.0);
|
||||
if (spacing > separator->thickness)
|
||||
num_circles++;
|
||||
spacing = (separator->length - num_circles * separator->thickness) / MAX(1.0, num_circles - 1.0);
|
||||
double offset = (panel_horizontal ? separator->area.height : separator->area.width) / 2.0 - separator->length / 2.0;
|
||||
if (num_circles == 1)
|
||||
offset += spacing / 2.0;
|
||||
for (int i = 0; i < num_circles; i++) {
|
||||
if (panel_horizontal) {
|
||||
cairo_arc(c,
|
||||
separator->area.width / 2.0,
|
||||
offset + separator->thickness / 2.0,
|
||||
separator->thickness / 2.0,
|
||||
0,
|
||||
2 * M_PI);
|
||||
} else {
|
||||
cairo_arc(c,
|
||||
offset + separator->thickness / 2.0,
|
||||
separator->area.height / 2.0,
|
||||
separator->thickness / 2.0,
|
||||
0,
|
||||
2 * M_PI);
|
||||
}
|
||||
cairo_stroke_preserve(c);
|
||||
cairo_fill(c);
|
||||
offset += separator->thickness + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,18 @@
|
||||
#include "common.h"
|
||||
#include "area.h"
|
||||
|
||||
typedef enum SeparatorStyle {
|
||||
SEPARATOR_EMPTY = 0,
|
||||
SEPARATOR_LINE,
|
||||
SEPARATOR_DOTS
|
||||
} SeparatorStyle;
|
||||
|
||||
typedef struct Separator {
|
||||
Area area;
|
||||
int style;
|
||||
SeparatorStyle style;
|
||||
Color color;
|
||||
double empty_thickness;
|
||||
double thickness;
|
||||
double len;
|
||||
int thickness;
|
||||
int length;
|
||||
} Separator;
|
||||
|
||||
Separator *create_separator();
|
||||
|
||||
Reference in New Issue
Block a user