mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-03-12 18:32:48 +01:00
Add basic rounding
There's probably a better way of doing this, But this will do for now. Added basic rounding to buttons. Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
parent
e3081fb6e9
commit
d423720553
@ -13,6 +13,7 @@ struct clr_scheme schemes[] = {
|
|||||||
.swipe = {.bgra = {100, 255, 100, 64}},
|
.swipe = {.bgra = {100, 255, 100, 64}},
|
||||||
.text = {.color = UINT32_MAX},
|
.text = {.color = UINT32_MAX},
|
||||||
.font = DEFAULT_FONT,
|
.font = DEFAULT_FONT,
|
||||||
|
.rounding = 5,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
/* colors */
|
/* colors */
|
||||||
@ -22,6 +23,7 @@ struct clr_scheme schemes[] = {
|
|||||||
.swipe = {.bgra = {100, 255, 100, 64}},
|
.swipe = {.bgra = {100, 255, 100, 64}},
|
||||||
.text = {.color = UINT32_MAX},
|
.text = {.color = UINT32_MAX},
|
||||||
.font = DEFAULT_FONT,
|
.font = DEFAULT_FONT,
|
||||||
|
.rounding = 5,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
43
drw.c
43
drw.c
@ -71,7 +71,7 @@ drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
|||||||
|
|
||||||
void
|
void
|
||||||
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h, bool over)
|
uint32_t w, uint32_t h, bool over, int rounding)
|
||||||
{
|
{
|
||||||
cairo_save(d->cairo);
|
cairo_save(d->cairo);
|
||||||
|
|
||||||
@ -81,27 +81,48 @@ drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
|||||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
|
cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_rectangle(d->cairo, x, y, w, h);
|
if (rounding > 0) {
|
||||||
cairo_set_source_rgba(
|
double radius = rounding / 1.0;
|
||||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
double degrees = M_PI / 180.0;
|
||||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
|
||||||
cairo_fill(d->cairo);
|
|
||||||
|
|
||||||
cairo_restore(d->cairo);
|
cairo_new_sub_path (d->cairo);
|
||||||
|
cairo_arc (d->cairo, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
|
||||||
|
cairo_arc (d->cairo, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
|
||||||
|
cairo_arc (d->cairo, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
|
||||||
|
cairo_arc (d->cairo, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
|
||||||
|
cairo_close_path (d->cairo);
|
||||||
|
|
||||||
|
cairo_set_source_rgba(
|
||||||
|
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||||
|
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||||
|
cairo_fill (d->cairo);
|
||||||
|
cairo_set_source_rgba(d->cairo, 0, 0, 0, 0.9);
|
||||||
|
cairo_set_line_width(d->cairo, 1.0);
|
||||||
|
cairo_stroke(d->cairo);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cairo_rectangle(d->cairo, x, y, w, h);
|
||||||
|
cairo_set_source_rgba(
|
||||||
|
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||||
|
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||||
|
cairo_fill(d->cairo);
|
||||||
|
|
||||||
|
cairo_restore(d->cairo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h)
|
uint32_t w, uint32_t h, int rounding)
|
||||||
{
|
{
|
||||||
drw_do_rectangle(d, color, x, y, w, h, false);
|
drw_do_rectangle(d, color, x, y, w, h, false, rounding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h)
|
uint32_t w, uint32_t h, int rounding)
|
||||||
{
|
{
|
||||||
drw_do_rectangle(d, color, x, y, w, h, true);
|
drw_do_rectangle(d, color, x, y, w, h, true, rounding);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
|
6
drw.h
6
drw.h
@ -33,11 +33,11 @@ typedef union {
|
|||||||
void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y,
|
void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h);
|
uint32_t w, uint32_t h);
|
||||||
void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h, bool fill);
|
uint32_t w, uint32_t h, bool fill, int rounding);
|
||||||
void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h);
|
uint32_t w, uint32_t h, int rounding);
|
||||||
void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h);
|
uint32_t w, uint32_t h, int rounding);
|
||||||
|
|
||||||
void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
uint32_t w, uint32_t h, uint32_t b, const char *label,
|
uint32_t w, uint32_t h, uint32_t b, const char *label,
|
||||||
|
20
keyboard.c
20
keyboard.c
@ -561,15 +561,15 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
|
|||||||
case None:
|
case None:
|
||||||
case Unpress:
|
case Unpress:
|
||||||
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||||
scheme->fg);
|
scheme->fg, scheme->rounding);
|
||||||
break;
|
break;
|
||||||
case Press:
|
case Press:
|
||||||
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||||
scheme->high);
|
scheme->high, scheme->rounding);
|
||||||
break;
|
break;
|
||||||
case Swipe:
|
case Swipe:
|
||||||
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||||
scheme->swipe);
|
scheme->swipe, scheme->rounding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,9 +586,9 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
|
|||||||
kb->last_popup_h = k->h;
|
kb->last_popup_h = k->h;
|
||||||
|
|
||||||
drw_fill_rectangle(kb->popup_surf, scheme->bg, k->x,
|
drw_fill_rectangle(kb->popup_surf, scheme->bg, k->x,
|
||||||
kb->last_popup_y, k->w, k->h);
|
kb->last_popup_y, k->w, k->h, scheme->rounding);
|
||||||
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
|
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
|
||||||
KBD_KEY_BORDER, scheme->high);
|
KBD_KEY_BORDER, scheme->high, scheme->rounding);
|
||||||
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
|
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
|
||||||
k->w, k->h, KBD_KEY_BORDER, label,
|
k->w, k->h, KBD_KEY_BORDER, label,
|
||||||
scheme->font_description);
|
scheme->font_description);
|
||||||
@ -605,7 +605,7 @@ kbd_draw_layout(struct kbd *kb)
|
|||||||
if (kb->debug)
|
if (kb->debug)
|
||||||
fprintf(stderr, "Draw layout\n");
|
fprintf(stderr, "Draw layout\n");
|
||||||
|
|
||||||
drw_fill_rectangle(d, kb->schemes[0].bg, 0, 0, kb->w, kb->h);
|
drw_fill_rectangle(d, kb->schemes[0].bg, 0, 0, kb->w, kb->h, 0);
|
||||||
|
|
||||||
while (next_key->type != Last) {
|
while (next_key->type != Last) {
|
||||||
if ((next_key->type == Pad) || (next_key->type == EndRow)) {
|
if ((next_key->type == Pad) || (next_key->type == EndRow)) {
|
||||||
@ -647,17 +647,17 @@ kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount)
|
|||||||
|
|
||||||
void
|
void
|
||||||
draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
uint32_t height, uint32_t border, Color color)
|
uint32_t height, uint32_t border, Color color, int rounding)
|
||||||
{
|
{
|
||||||
drw_fill_rectangle(ds, color, x + border, y + border, width - (border * 2),
|
drw_fill_rectangle(ds, color, x + border, y + border, width - (border * 2),
|
||||||
height - (border * 2));
|
height - (border * 2), rounding);
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
uint32_t height, uint32_t border, Color color)
|
uint32_t height, uint32_t border, Color color, int rounding)
|
||||||
{
|
{
|
||||||
drw_over_rectangle(ds, color, x + border, y + border, width - (border * 2),
|
drw_over_rectangle(ds, color, x + border, y + border, width - (border * 2),
|
||||||
height - (border * 2));
|
height - (border * 2), rounding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -55,6 +55,7 @@ struct clr_scheme {
|
|||||||
Color swipe;
|
Color swipe;
|
||||||
Color text;
|
Color text;
|
||||||
char *font;
|
char *font;
|
||||||
|
int rounding;
|
||||||
PangoFontDescription *font_description;
|
PangoFontDescription *font_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,9 +122,9 @@ struct kbd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
uint32_t height, uint32_t border, Color color);
|
uint32_t height, uint32_t border, Color color, int rounding);
|
||||||
void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
uint32_t height, uint32_t border, Color color);
|
uint32_t height, uint32_t border, Color color, int rounding);
|
||||||
|
|
||||||
void kbd_init(struct kbd *kb, struct layout *layouts,
|
void kbd_init(struct kbd *kb, struct layout *layouts,
|
||||||
char *layer_names_list, char *landscape_layer_names_list);
|
char *layer_names_list, char *landscape_layer_names_list);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user