綺麗に

This commit is contained in:
2026-01-17 18:35:27 +09:00
parent b20fa6cc3a
commit fa83f224e2
9 changed files with 164 additions and 151 deletions

View File

@@ -3,28 +3,28 @@
#include <string.h>
void drawbuttons(Display *dpy, Drawable target, GC gc, SuwaButton *btn,
XftDraw *xftdraw, XftColor *textcolor, XftFont *font) {
void drawbuttons(UiSystem *ui, SuwaButton *btn, XftDraw *xftdraw) {
unsigned long curbg = btn->pressed ? BTSEL : BTCOL;
XSetForeground(dpy, gc, curbg);
XFillRectangle(dpy, target, gc, btn->x, btn->y, btn->width, btn->height);
XSetForeground(ui->display, ui->gc, curbg);
XFillRectangle(ui->display, ui->target, ui->gc, btn->x, btn->y, btn->width, btn->height);
// 文字の中央に
if (btn->label && font && xftdraw) {
if (btn->label && ui->font && xftdraw) {
const FcChar8 *str = (const FcChar8 *)btn->label;
int len = strlen((const char *)str);
XGlyphInfo extents;
XftTextExtentsUtf8(dpy, font, str, len, &extents);
XftTextExtentsUtf8(ui->display, ui->font, str, len, &extents);
int text_w = extents.xOff;
int text_h = font->ascent + font->descent;
int text_h = ui->font->ascent + ui->font->descent;
int tx = btn->x + (btn->width - text_w) / 2;
int ty = btn->y + (btn->height - text_h) / 2 + font->ascent;
int ty = btn->y + (btn->height - text_h) / 2 + ui->font->ascent;
// tx -= extents.x;
XftDrawStringUtf8(xftdraw, textcolor, font, tx, ty, (FcChar8 *)btn->label, len);
XftDrawStringUtf8(xftdraw, &ui->textcolor, ui->font, tx, ty,
(FcChar8 *)btn->label, len);
}
}