49 lines
2.1 KiB
C++
49 lines
2.1 KiB
C++
#include "widget.h"
|
|
namespace gui {
|
|
|
|
void wdraw::basic(Display* d, Drawable win, GC gc, const Widget& w, int ax, int ay, OverlayList* ov) {
|
|
(void)ov;
|
|
const auto& t = theme();
|
|
const auto& dt = w.data;
|
|
int fs = dt.font_size ? dt.font_size : t.font_size;
|
|
|
|
if (dt.type == WidgetType::LABEL) {
|
|
gui_text(d, win, gc, ax, gui_base_c(ay, dt.height, fs), dt.text,
|
|
C(dt.fg_color, t.text), fs);
|
|
return;
|
|
}
|
|
|
|
uint32_t bg, bd, txt;
|
|
if (dt.primary) {
|
|
float p = w.pressed ? 0.5f : 0.f;
|
|
bg = mixc(mixc(C(dt.bg_color, t.btn), C(dt.bg_color, t.btn_h), w.hover_a), t.btn_p, p);
|
|
bd = bg; txt = t.on_accent;
|
|
} else {
|
|
float p = w.pressed ? 0.5f : 0.f;
|
|
bg = mixc(mixc(t.accent, t.accent_h, w.hover_a),t.accent_p, p * 0.5f);
|
|
bd = mixc(C(dt.frame_color, t.border), t.border_h, w.hover_a);
|
|
txt = C(dt.fg_color, t.text);
|
|
}
|
|
|
|
if (dt.type == WidgetType::SPRITE_BTN && dt.picture) {
|
|
dt.picture->present(d, win, gc, ax, ay);
|
|
} else {
|
|
XSetForeground(d, gc, bg);
|
|
x_fill_round(d, win, gc, ax, ay, dt.width, dt.height, t.radius);
|
|
}
|
|
XSetForeground(d, gc, bd);
|
|
x_draw_round(d, win, gc, ax, ay, dt.width, dt.height, t.radius);
|
|
|
|
if (dt.type == WidgetType::INPUT) {
|
|
// фон поля ввода + нижняя акцент при фокусе
|
|
XSetForeground(d, gc, C(dt.bg_color, t.input_bg));
|
|
x_fill_round(d, win, gc, ax + 1, ay + 1, dt.width - 2, dt.height - 2, std::max(0, t.radius - 1));
|
|
XSetForeground(d, gc, mixc(t.border, t.focus, w.hover_a));
|
|
XFillRectangle(d, win, gc, ax + t.radius, ay + dt.height - 2, dt.width - 2 * t.radius, 2);
|
|
int cx = ax + 6 + gui_text_width(dt.text, fs);
|
|
XSetForeground(d, gc, t.focus);
|
|
XDrawLine(d, win, gc, cx, ay + 6, cx, ay + dt.height - 6);
|
|
}
|
|
gui_text(d, win, gc, ax + 6, gui_base_c(ay, dt.height, fs), dt.text, txt, fs);
|
|
}
|
|
} |