#include "render.h" #include #include #define NUM_BUF_LEN 16 void editor_render(Editor *ed) { int top_offset = TOP_UI_H; int st_h = editor_status_h(ed); int text_x = GUTTER_W + 8; int view_h = ed->win_h - top_offset - st_h - SCROLLBAR_W; int view_w = ed->win_w - text_x - SCROLLBAR_W; int visible_lines = (view_h > 0) ? (view_h / ed->line_h) : 1; int visible_cols = (view_w > 0) ? (view_w / ed->char_w) : 1; XSetForeground(ed->dpy, ed->gc, ed->col_bg); XFillRectangle(ed->dpy, ed->backbuf, ed->gc, 0, 0, ed->win_w, ed->win_h); XSetForeground(ed->dpy, ed->gc, ed->col_gutter); XFillRectangle(ed->dpy, ed->backbuf, ed->gc, 0, top_offset, GUTTER_W, ed->win_h - top_offset - st_h); int in_comment = render_calc_comment_state(ed, ed->scroll_y); for (int i = 0; i < visible_lines; i++) { int line_idx = ed->scroll_y + i; if (line_idx >= ed->num_lines) break; int top_y = top_offset + i * ed->line_h; int baseline_y = top_y + ed->font->ascent + 2; if (line_idx == ed->cy && !ed->has_sel) { XSetForeground(ed->dpy, ed->gc, ed->col_curline); XFillRectangle(ed->dpy, ed->backbuf, ed->gc, GUTTER_W, top_y, ed->win_w - GUTTER_W - SCROLLBAR_W, ed->line_h); } render_search_highlights(ed, line_idx, top_y, visible_cols); render_selection_bg(ed, line_idx, top_y, visible_cols); char num_buf[NUM_BUF_LEN]; snprintf(num_buf, sizeof(num_buf), "%4d", line_idx + 1); XftColor *num_col = (line_idx == ed->cy) ? &ed->xft_fg : &ed->xft_lineno; XftDrawStringUtf8(ed->xft_draw, num_col, ed->font, 6, baseline_y, (const FcChar8 *)num_buf, (int)strlen(num_buf)); render_syntax_line(ed, ed->lines[line_idx], ed->scroll_x, text_x, baseline_y, visible_cols + 1, &in_comment); render_hover_symbol_link(ed, line_idx, top_y, baseline_y, visible_cols); } int cur_col = utf8_char_count(ed->lines[ed->cy], ed->cx); if (ed->cursor_visible && ed->cy >= ed->scroll_y && ed->cy < ed->scroll_y + visible_lines && cur_col >= ed->scroll_x && cur_col <= ed->scroll_x + visible_cols) { int cur_y = top_offset + (ed->cy - ed->scroll_y) * ed->line_h; int cur_x = text_x + (cur_col - ed->scroll_x) * ed->char_w; XSetForeground(ed->dpy, ed->gc, ed->col_fg); XFillRectangle(ed->dpy, ed->backbuf, ed->gc, cur_x, cur_y + 2, 2, ed->line_h - 4); } render_scrollbars(ed, visible_lines, visible_cols); render_status_bar(ed, cur_col); tabs_render(ed); menu_render(ed); fbrowser_render(ed); confirm_render(ed); XCopyArea(ed->dpy, ed->backbuf, ed->win, ed->gc, 0, 0, ed->win_w, ed->win_h, 0, 0); }