Initial commit: X11 C code editor
This commit is contained in:
commit
8eae6763f6
21 files changed
+36389
No files matched your search
@@ -0,0 +1,14 @@
|
||||
#ifndef RENDER_H
|
||||
#define RENDER_H
|
||||
|
||||
#include "../editor.h"
|
||||
|
||||
int render_calc_comment_state(const Editor *ed, int target_line);
|
||||
void render_syntax_line(Editor *ed, const char *line, int scroll_x, int x, int y, int max_chars, int *in_comment);
|
||||
void render_search_highlights(Editor *ed, int line_idx, int top_y, int visible_cols);
|
||||
void render_selection_bg(Editor *ed, int line_idx, int top_y, int visible_cols);
|
||||
void render_scrollbars(Editor *ed, int visible_lines, int visible_cols);
|
||||
void render_status_bar(Editor *ed, int cur_col);
|
||||
void render_hover_symbol_link(Editor *ed, int line_idx, int top_y, int baseline_y, int visible_cols);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "render.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
#include "render.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *c_keywords[] = {
|
||||
"auto", "break", "case", "char", "const", "continue", "default", "do",
|
||||
"double", "else", "enum", "extern", "float", "for", "goto", "if",
|
||||
"inline", "int", "long", "register", "restrict", "return", "short",
|
||||
"signed", "sizeof", "static", "struct", "switch", "typedef", "union",
|
||||
"unsigned", "void", "volatile", "while", NULL
|
||||
};
|
||||
|
||||
static const char *c_types[] = {
|
||||
"bool", "size_t", "ssize_t", "ptrdiff_t", "intptr_t", "uintptr_t",
|
||||
"int8_t", "int16_t", "int32_t", "int64_t",
|
||||
"uint8_t", "uint16_t", "uint32_t", "uint64_t",
|
||||
"FILE", "DIR", "time_t", "clock_t", "off_t", "pid_t", "uid_t", "gid_t",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *c_constants[] = {
|
||||
"NULL", "true", "false", "EOF", "errno",
|
||||
"STDIN_FILENO", "STDOUT_FILENO", "STDERR_FILENO",
|
||||
"EXIT_SUCCESS", "EXIT_FAILURE", NULL
|
||||
};
|
||||
|
||||
static int in_word_list(const char *word, int len, const char **list) {
|
||||
for (int i = 0; list[i]; i++) {
|
||||
if ((int)strlen(list[i]) == len && strncmp(list[i], word, len) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int render_calc_comment_state(const Editor *ed, int target_line) {
|
||||
int in_comment = 0;
|
||||
for (int y = 0; y < target_line && y < ed->num_lines; y++) {
|
||||
const char *line = ed->lines[y];
|
||||
int len = (int)strlen(line);
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
if (in_comment) {
|
||||
if (line[i] == '*' && i + 1 < len && line[i + 1] == '/') {
|
||||
in_comment = 0;
|
||||
i += 2;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if (line[i] == '/' && i + 1 < len && line[i + 1] == '/') {
|
||||
break;
|
||||
} else if (line[i] == '/' && i + 1 < len && line[i + 1] == '*') {
|
||||
in_comment = 1;
|
||||
i += 2;
|
||||
} else if (line[i] == '"' || line[i] == '\'') {
|
||||
char quote = line[i++];
|
||||
while (i < len && line[i] != quote) {
|
||||
if (line[i] == '\\' && i + 1 < len) i++;
|
||||
i++;
|
||||
}
|
||||
if (i < len) i++;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return in_comment;
|
||||
}
|
||||
|
||||
void render_syntax_line(Editor *ed, const char *line, int scroll_x, int x, int y, int max_chars, int *in_comment) {
|
||||
int len = (int)strlen(line);
|
||||
int start_byte = utf8_byte_offset(line, scroll_x);
|
||||
int end_byte = utf8_byte_offset(line, scroll_x + max_chars);
|
||||
|
||||
int first_non_space = 0;
|
||||
while (first_non_space < len && isspace((unsigned char)line[first_non_space])) {
|
||||
first_non_space++;
|
||||
}
|
||||
|
||||
if (!(*in_comment) && first_non_space < len && line[first_non_space] == '#') {
|
||||
if (start_byte < len) {
|
||||
XftDrawStringUtf8(ed->xft_draw, &ed->xft_prep, ed->font, x, y,
|
||||
(const FcChar8 *)(line + start_byte), end_byte - start_byte);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
int tok_start = i;
|
||||
int tok_end = i;
|
||||
XftColor *color = &ed->xft_fg;
|
||||
|
||||
if (*in_comment) {
|
||||
color = &ed->xft_mcom;
|
||||
while (tok_end < len) {
|
||||
if (line[tok_end] == '*' && tok_end + 1 < len && line[tok_end + 1] == '/') {
|
||||
tok_end += 2;
|
||||
*in_comment = 0;
|
||||
break;
|
||||
}
|
||||
tok_end++;
|
||||
}
|
||||
} else if (line[i] == '/' && i + 1 < len && line[i + 1] == '/') {
|
||||
color = &ed->xft_com;
|
||||
tok_end = len;
|
||||
} else if (line[i] == '/' && i + 1 < len && line[i + 1] == '*') {
|
||||
color = &ed->xft_mcom;
|
||||
tok_end += 2;
|
||||
*in_comment = 1;
|
||||
while (tok_end < len) {
|
||||
if (line[tok_end] == '*' && tok_end + 1 < len && line[tok_end + 1] == '/') {
|
||||
tok_end += 2;
|
||||
*in_comment = 0;
|
||||
break;
|
||||
}
|
||||
tok_end++;
|
||||
}
|
||||
} else if (line[i] == '"' || line[i] == '\'') {
|
||||
char quote = line[i];
|
||||
tok_end++;
|
||||
while (tok_end < len && line[tok_end] != quote) {
|
||||
if (line[tok_end] == '\\' && tok_end + 1 < len) tok_end++;
|
||||
tok_end++;
|
||||
}
|
||||
if (tok_end < len) tok_end++;
|
||||
color = &ed->xft_str;
|
||||
} else if (isdigit((unsigned char)line[i])) {
|
||||
color = &ed->xft_num;
|
||||
if (line[i] == '0' && i + 1 < len && (line[i + 1] == 'x' || line[i + 1] == 'X')) {
|
||||
tok_end += 2;
|
||||
while (tok_end < len && (isxdigit((unsigned char)line[tok_end]) || line[tok_end] == '_')) {
|
||||
tok_end++;
|
||||
}
|
||||
} else if (line[i] == '0' && i + 1 < len && (line[i + 1] == 'b' || line[i + 1] == 'B')) {
|
||||
tok_end += 2;
|
||||
while (tok_end < len && (line[tok_end] == '0' || line[tok_end] == '1' || line[tok_end] == '_')) {
|
||||
tok_end++;
|
||||
}
|
||||
} else {
|
||||
while (tok_end < len && (isdigit((unsigned char)line[tok_end]) || line[tok_end] == '.' || line[tok_end] == '_')) {
|
||||
tok_end++;
|
||||
}
|
||||
if (tok_end < len && (line[tok_end] == 'e' || line[tok_end] == 'E')) {
|
||||
tok_end++;
|
||||
if (tok_end < len && (line[tok_end] == '+' || line[tok_end] == '-')) tok_end++;
|
||||
while (tok_end < len && isdigit((unsigned char)line[tok_end])) tok_end++;
|
||||
}
|
||||
}
|
||||
while (tok_end < len && strchr("uUlLfF", line[tok_end])) {
|
||||
tok_end++;
|
||||
}
|
||||
} else if (isalpha((unsigned char)line[i]) || line[i] == '_') {
|
||||
while (tok_end < len && (isalnum((unsigned char)line[tok_end]) || line[tok_end] == '_')) {
|
||||
tok_end++;
|
||||
}
|
||||
int wlen = tok_end - tok_start;
|
||||
if (in_word_list(&line[tok_start], wlen, c_keywords)) {
|
||||
color = &ed->xft_kw;
|
||||
} else if (in_word_list(&line[tok_start], wlen, c_types)) {
|
||||
color = &ed->xft_type;
|
||||
} else if (in_word_list(&line[tok_start], wlen, c_constants)) {
|
||||
color = &ed->xft_num;
|
||||
} else {
|
||||
color = &ed->xft_fg;
|
||||
}
|
||||
} else {
|
||||
tok_end = utf8_next_char_pos(line, i);
|
||||
}
|
||||
|
||||
if (start_byte < len) {
|
||||
int vis_start = (tok_start > start_byte) ? tok_start : start_byte;
|
||||
int vis_end = (tok_end < end_byte) ? tok_end : end_byte;
|
||||
if (vis_start < vis_end) {
|
||||
int col_offset = utf8_char_count(line + start_byte, vis_start - start_byte);
|
||||
XftDrawStringUtf8(ed->xft_draw, color, ed->font,
|
||||
x + col_offset * ed->char_w, y,
|
||||
(const FcChar8 *)&line[vis_start], vis_end - vis_start);
|
||||
}
|
||||
}
|
||||
i = tok_end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
#include "render.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BAR_BUF_LEN 512
|
||||
|
||||
void render_search_highlights(Editor *ed, int line_idx, int top_y, int visible_cols) {
|
||||
if (!ed->search_mode || !ed->search_highlight_all) return;
|
||||
int qlen = (int)strlen(ed->search_query);
|
||||
if (qlen == 0) return;
|
||||
|
||||
const char *line = ed->lines[line_idx];
|
||||
const char *p = line;
|
||||
|
||||
while ((p = strstr(p, ed->search_query)) != NULL) {
|
||||
int b_start = (int)(p - line);
|
||||
int b_end = b_start + qlen;
|
||||
|
||||
int c_start = utf8_char_count(line, b_start);
|
||||
int c_end = utf8_char_count(line, b_end);
|
||||
|
||||
if (c_end > ed->scroll_x && c_start < ed->scroll_x + visible_cols + 1) {
|
||||
int vis_s = (c_start < ed->scroll_x) ? ed->scroll_x : c_start;
|
||||
int vis_e = (c_end > ed->scroll_x + visible_cols + 1) ? (ed->scroll_x + visible_cols + 1) : c_end;
|
||||
int x1 = GUTTER_W + 8 + (vis_s - ed->scroll_x) * ed->char_w;
|
||||
int w = (vis_e - vis_s) * ed->char_w;
|
||||
if (w > 0) {
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_match_all);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, x1, top_y, w, ed->line_h);
|
||||
}
|
||||
}
|
||||
p += qlen;
|
||||
}
|
||||
}
|
||||
|
||||
void render_selection_bg(Editor *ed, int line_idx, int top_y, int visible_cols) {
|
||||
if (!ed->has_sel) return;
|
||||
|
||||
int sy, sx, ey, ex;
|
||||
editor_get_sel_bounds(ed, &sy, &sx, &ey, &ex);
|
||||
if (line_idx < sy || line_idx > ey) return;
|
||||
|
||||
const char *line = ed->lines[line_idx];
|
||||
int line_len = (int)strlen(line);
|
||||
int b_start = (line_idx == sy) ? sx : 0;
|
||||
int b_end = (line_idx == ey) ? ex : line_len;
|
||||
|
||||
int c_start = utf8_char_count(line, b_start);
|
||||
int c_end = utf8_char_count(line, b_end);
|
||||
if (line_idx < ey) c_end += 1;
|
||||
|
||||
if (c_end <= ed->scroll_x || c_start >= ed->scroll_x + visible_cols + 1) return;
|
||||
if (c_start < ed->scroll_x) c_start = ed->scroll_x;
|
||||
if (c_end > ed->scroll_x + visible_cols + 1) c_end = ed->scroll_x + visible_cols + 1;
|
||||
|
||||
int x1 = GUTTER_W + 8 + (c_start - ed->scroll_x) * ed->char_w;
|
||||
int w = (c_end - c_start) * ed->char_w;
|
||||
if (w > 0) {
|
||||
unsigned long bg = (ed->search_mode && ed->search_highlight_all) ? ed->col_match_cur : ed->col_sel;
|
||||
XSetForeground(ed->dpy, ed->gc, bg);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, x1, top_y, w, ed->line_h);
|
||||
}
|
||||
}
|
||||
|
||||
void render_hover_symbol_link(Editor *ed, int line_idx, int top_y, int baseline_y, int visible_cols) {
|
||||
if (ed->hover_sym_line != line_idx) return;
|
||||
|
||||
const char *line = ed->lines[line_idx];
|
||||
int vis_b_start = (ed->hover_sym_sx > utf8_byte_offset(line, ed->scroll_x))
|
||||
? ed->hover_sym_sx : utf8_byte_offset(line, ed->scroll_x);
|
||||
int vis_b_end = (ed->hover_sym_ex < utf8_byte_offset(line, ed->scroll_x + visible_cols + 1))
|
||||
? ed->hover_sym_ex : utf8_byte_offset(line, ed->scroll_x + visible_cols + 1);
|
||||
|
||||
if (vis_b_start >= vis_b_end) return;
|
||||
|
||||
int c_start = utf8_char_count(line, vis_b_start);
|
||||
int c_end = utf8_char_count(line, vis_b_end);
|
||||
int x1 = GUTTER_W + 8 + (c_start - ed->scroll_x) * ed->char_w;
|
||||
int w = (c_end - c_start) * ed->char_w;
|
||||
|
||||
if (w > 0) {
|
||||
unsigned long line_bg = (line_idx == ed->cy && !ed->has_sel) ? ed->col_curline : ed->col_bg;
|
||||
XSetForeground(ed->dpy, ed->gc, line_bg);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, x1, top_y, w, ed->line_h);
|
||||
|
||||
XftDrawStringUtf8(ed->xft_draw, &ed->xft_link, ed->font, x1, baseline_y,
|
||||
(const FcChar8 *)&line[vis_b_start], vis_b_end - vis_b_start);
|
||||
|
||||
XSetForeground(ed->dpy, ed->gc, ed->xft_link.pixel);
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, x1, baseline_y + 1, x1 + w - 1, baseline_y + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* dir: 0 = вверх, 1 = вниз, 2 = влево, 3 = вправо */
|
||||
static void draw_sb_arrow_btn(Editor *ed, int x, int y, int dir, int hovered, int pressed) {
|
||||
unsigned long bg = pressed ? ed->col_sel : (hovered ? ed->col_bg : ed->col_status);
|
||||
XSetForeground(ed->dpy, ed->gc, bg);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, x, y, SCROLLBAR_W, SCROLLBAR_W);
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_thumb);
|
||||
XDrawRectangle(ed->dpy, ed->backbuf, ed->gc, x, y, SCROLLBAR_W - 1, SCROLLBAR_W - 1);
|
||||
|
||||
int shift = pressed ? 1 : 0;
|
||||
int cx = x + SCROLLBAR_W / 2 + shift;
|
||||
int cy = y + SCROLLBAR_W / 2 + shift;
|
||||
XPoint p0, p1, p2;
|
||||
|
||||
if (dir == 0) {
|
||||
p0 = (XPoint){(short)(cx - 3), (short)(cy + 2)};
|
||||
p1 = (XPoint){(short)(cx + 3), (short)(cy + 2)};
|
||||
p2 = (XPoint){(short)cx, (short)(cy - 2)};
|
||||
} else if (dir == 1) {
|
||||
p0 = (XPoint){(short)(cx - 3), (short)(cy - 2)};
|
||||
p1 = (XPoint){(short)(cx + 3), (short)(cy - 2)};
|
||||
p2 = (XPoint){(short)cx, (short)(cy + 2)};
|
||||
} else if (dir == 2) {
|
||||
p0 = (XPoint){(short)(cx + 2), (short)(cy - 3)};
|
||||
p1 = (XPoint){(short)(cx + 2), (short)(cy + 3)};
|
||||
p2 = (XPoint){(short)(cx - 2), (short)cy};
|
||||
} else {
|
||||
p0 = (XPoint){(short)(cx - 2), (short)(cy - 3)};
|
||||
p1 = (XPoint){(short)(cx - 2), (short)(cy + 3)};
|
||||
p2 = (XPoint){(short)(cx + 2), (short)cy};
|
||||
}
|
||||
|
||||
XPoint tri[3] = {p0, p1, p2};
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_fg);
|
||||
XFillPolygon(ed->dpy, ed->backbuf, ed->gc, tri, 3, Convex, CoordModeOrigin);
|
||||
}
|
||||
|
||||
void render_scrollbars(Editor *ed, int visible_lines, int visible_cols) {
|
||||
int st_h = editor_status_h(ed);
|
||||
int v_track_x = ed->win_w - SCROLLBAR_W;
|
||||
int v_full_y = TOP_UI_H;
|
||||
int v_full_h = ed->win_h - TOP_UI_H - st_h - SCROLLBAR_W;
|
||||
|
||||
if (v_full_h >= SCROLLBAR_W * 2) {
|
||||
draw_sb_arrow_btn(ed, v_track_x, v_full_y, 0, ed->hover_btn == 2, ed->pressed_btn == 2);
|
||||
draw_sb_arrow_btn(ed, v_track_x, v_full_y + v_full_h - SCROLLBAR_W, 1, ed->hover_btn == 3, ed->pressed_btn == 3);
|
||||
|
||||
int v_track_y = v_full_y + SCROLLBAR_W;
|
||||
int v_track_h = v_full_h - SCROLLBAR_W * 2;
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_track);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, v_track_x, v_track_y, SCROLLBAR_W, v_track_h);
|
||||
|
||||
if (ed->num_lines > visible_lines && v_track_h > 0) {
|
||||
int thumb_h = (v_track_h * visible_lines) / ed->num_lines;
|
||||
if (thumb_h < 16) thumb_h = 16;
|
||||
if (thumb_h > v_track_h) thumb_h = v_track_h;
|
||||
int max_sy = ed->num_lines - visible_lines;
|
||||
int thumb_y = v_track_y + ((max_sy > 0) ? (ed->scroll_y * (v_track_h - thumb_h)) / max_sy : 0);
|
||||
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_thumb);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, v_track_x + 2, thumb_y, SCROLLBAR_W - 4, thumb_h);
|
||||
}
|
||||
}
|
||||
|
||||
int h_full_x = GUTTER_W;
|
||||
int h_track_y = ed->win_h - st_h - SCROLLBAR_W;
|
||||
int h_full_w = ed->win_w - GUTTER_W - SCROLLBAR_W;
|
||||
|
||||
if (h_full_w >= SCROLLBAR_W * 2) {
|
||||
draw_sb_arrow_btn(ed, h_full_x, h_track_y, 2, ed->hover_btn == 4, ed->pressed_btn == 4);
|
||||
draw_sb_arrow_btn(ed, h_full_x + h_full_w - SCROLLBAR_W, h_track_y, 3, ed->hover_btn == 5, ed->pressed_btn == 5);
|
||||
|
||||
int h_track_x = h_full_x + SCROLLBAR_W;
|
||||
int h_track_w = h_full_w - SCROLLBAR_W * 2;
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_track);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, h_track_x, h_track_y, h_track_w, SCROLLBAR_W);
|
||||
|
||||
int max_cols = editor_max_line_len(ed);
|
||||
if (max_cols > visible_cols && h_track_w > 0) {
|
||||
int thumb_w = (h_track_w * visible_cols) / max_cols;
|
||||
if (thumb_w < 16) thumb_w = 16;
|
||||
if (thumb_w > h_track_w) thumb_w = h_track_w;
|
||||
int max_sx = max_cols - visible_cols;
|
||||
int thumb_x = h_track_x + ((max_sx > 0) ? (ed->scroll_x * (h_track_w - thumb_w)) / max_sx : 0);
|
||||
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_thumb);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, thumb_x, h_track_y + 2, thumb_w, SCROLLBAR_W - 4);
|
||||
}
|
||||
}
|
||||
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_gutter);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, v_track_x, h_track_y, SCROLLBAR_W, SCROLLBAR_W);
|
||||
|
||||
int st_pressed = (ed->pressed_btn == 1);
|
||||
unsigned long st_bg = st_pressed ? ed->col_sel : ((ed->hover_btn == 1) ? ed->col_bg : ed->col_gutter);
|
||||
XSetForeground(ed->dpy, ed->gc, st_bg);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, 0, h_track_y, GUTTER_W, SCROLLBAR_W);
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_thumb);
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, 0, h_track_y, GUTTER_W - 1, h_track_y);
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, GUTTER_W - 1, h_track_y, GUTTER_W - 1, h_track_y + SCROLLBAR_W);
|
||||
|
||||
int shift = st_pressed ? 1 : 0;
|
||||
int cx = GUTTER_W / 2 + shift;
|
||||
int cy = h_track_y + SCROLLBAR_W / 2 + shift;
|
||||
XPoint p0, p1, p2;
|
||||
if (!ed->status_collapsed) {
|
||||
p0 = (XPoint){(short)(cx - 4), (short)(cy - 2)};
|
||||
p1 = (XPoint){(short)(cx + 4), (short)(cy - 2)};
|
||||
p2 = (XPoint){(short)cx, (short)(cy + 3)};
|
||||
} else {
|
||||
p0 = (XPoint){(short)(cx - 4), (short)(cy + 2)};
|
||||
p1 = (XPoint){(short)(cx + 4), (short)(cy + 2)};
|
||||
p2 = (XPoint){(short)cx, (short)(cy - 3)};
|
||||
}
|
||||
XPoint tri[3] = {p0, p1, p2};
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_fg);
|
||||
XFillPolygon(ed->dpy, ed->backbuf, ed->gc, tri, 3, Convex, CoordModeOrigin);
|
||||
}
|
||||
|
||||
void render_status_bar(Editor *ed, int cur_col) {
|
||||
if (ed->status_collapsed) return;
|
||||
|
||||
int st_h = editor_status_h(ed);
|
||||
int status_y = ed->win_h - st_h;
|
||||
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_status);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, 0, status_y, ed->win_w, st_h);
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_sb_thumb);
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, 0, status_y, ed->win_w, status_y);
|
||||
int baseline = status_y + ed->font->ascent + 4;
|
||||
char bar[BAR_BUF_LEN];
|
||||
if (ed->search_mode) {
|
||||
snprintf(bar, sizeof(bar), " Find: %s_ ", ed->search_query);
|
||||
int bar_len = (int)strlen(bar);
|
||||
int bar_cols = utf8_char_count(bar, bar_len);
|
||||
XftDrawStringUtf8(ed->xft_draw, &ed->xft_fg, ed->font, 6, baseline,
|
||||
(const FcChar8 *)bar, bar_len);
|
||||
int box_x = 6 + bar_cols * ed->char_w;
|
||||
int box_y = status_y + (st_h - 14) / 2;
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_bg);
|
||||
XFillRectangle(ed->dpy, ed->backbuf, ed->gc, box_x, box_y, 14, 14);
|
||||
XSetForeground(ed->dpy, ed->gc, ed->col_fg);
|
||||
XDrawRectangle(ed->dpy, ed->backbuf, ed->gc, box_x, box_y, 14, 14);
|
||||
if (ed->search_highlight_all) {
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, box_x + 3, box_y + 7, box_x + 6, box_y + 11);
|
||||
XDrawLine(ed->dpy, ed->backbuf, ed->gc, box_x + 6, box_y + 11, box_x + 11, box_y + 3);
|
||||
}
|
||||
const char *lbl = " All | Enter: Next | Shift+Enter: Prev | Esc: Close";
|
||||
XftDrawStringUtf8(ed->xft_draw, &ed->xft_fg, ed->font, box_x + 18, baseline,
|
||||
(const FcChar8 *)lbl, (int)strlen(lbl));
|
||||
ed->chk_x1 = box_x;
|
||||
ed->chk_x2 = box_x + 18 + 4 * ed->char_w;
|
||||
} else {
|
||||
snprintf(bar, sizeof(bar), " %.200s | Ln %d, Col %d | Ctrl+O: Open | Ctrl+N/W: Tabs",
|
||||
ed->status_msg, ed->cy + 1, cur_col + 1);
|
||||
XftDrawStringUtf8(ed->xft_draw, &ed->xft_fg, ed->font, 6, baseline,
|
||||
(const FcChar8 *)bar, (int)strlen(bar));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user