37namespace blender::ed::ime {
44static void cursor_overlay_draw(
const wmIMEData &ime_data,
45 const rcti &cursor_rect,
47 const int region_size[2],
48 const float pixelsize)
51 const char *
str = ime_data.composite.c_str();
52 const int str_len = int(ime_data.composite.size());
54 const int line_height = cursor_rect.ymax - cursor_rect.ymin;
63 auto column_from_byte_offset_fn = [&](
const int64_t byte_offset) {
66 const int columns = column_from_byte_offset_fn(str_len);
70 const int border = std::max(
int(pixelsize), 1);
74 const int box_width = columns * char_width;
75 const int box_x = std::clamp(cursor_rect.xmin, 0, std::max(region_size[0] - box_width, 0));
76 const int box_y = std::clamp(cursor_rect.ymin, 0, std::max(region_size[1] - line_height, 0));
79 .xmax = box_x + box_width,
81 .ymax = box_y + line_height,
87 const int underline_y = box.ymin;
96 immRectf(pos, box.xmin, box.ymin - border, box.xmax + border, box.ymax + border);
98 immRectf(pos, box.xmin, box.ymin, box.xmax, box.ymax);
101 ui::theme::font_theme_color_set(font_id, TH_TEXT);
110 immRectf(pos, box.xmin, underline_y, box.xmax, underline_y + border);
113 if (
const std::optional<IndexRange> sel_range = WM_window_IME_composite_select_range(&ime_data))
116 const IndexRange sel_cols = IndexRange::from_begin_end(
117 column_from_byte_offset_fn(sel_range->start()),
118 column_from_byte_offset_fn(sel_range->one_after_last()))
119 .intersect(IndexRange(columns));
120 if (!sel_cols.is_empty()) {
122 box.xmin +
int(sel_cols.start()) * char_width,
124 box.xmin +
int(sel_cols.one_after_last()) * char_width,
125 underline_y + (2 * border));
130 if (!ime_data.composite.empty() && (ime_data.cursor_pos != -1)) {
131 const int cursor_width = 2 * border;
132 const int cursor_x = box.xmin +
133 std::min(column_from_byte_offset_fn(ime_data.cursor_pos) * char_width,
134 std::max(box_width - cursor_width, 0));
136 immRectf(pos, cursor_x, box.ymin, cursor_x + cursor_width, box.ymax);
143void region_overlay_draw(wmWindow *win,
144 const ARegion *region,
145 const float pixelsize,
146 const ARegionIMECursor &cursor)
148 const wmIMEData *ime_data = WM_window_IME_data_get(win, region);
149 if (ime_data ==
nullptr) {
152 const int region_size[2] = {region->winx, region->winy};
153 cursor_overlay_draw(*ime_data, cursor.rect, cursor.font_size, region_size, pixelsize);
void BLF_position(int fontid, float x, float y, float z)
GPUVertFormat * immVertexFormat()
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
int BLI_str_utf8_offset_to_column(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void immUniformThemeColor(int color_id)
void BLF_size(int fontid, float size)
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int char_width, int tab_columns) ATTR_NONNULL(2)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
void GPU_blend(GPUBlend blend)
void immRectf(uint pos, float x1, float y1, float x2, float y2)