Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| const char *drawstr) | const char *drawstr) | ||||
| { | { | ||||
| int ofs_x, width; | int ofs_x, width; | ||||
| int rect_x = BLI_rcti_size_x(rect); | int rect_x = BLI_rcti_size_x(rect); | ||||
| int sel_start = ime_data->sel_start, sel_end = ime_data->sel_end; | int sel_start = ime_data->sel_start, sel_end = ime_data->sel_end; | ||||
| float fcol[4]; | float fcol[4]; | ||||
| if (drawstr[0] != 0) { | if (drawstr[0] != 0) { | ||||
| if (but->pos >= but->ofs) { | if (but->ime_start >= but->ofs) { | ||||
| ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->pos - but->ofs); | ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->ime_start - but->ofs); | ||||
| } | } | ||||
| else { | else { | ||||
| ofs_x = 0; | ofs_x = 0; | ||||
| } | } | ||||
| width = BLF_width( | width = BLF_width( | ||||
| fstyle->uifont_id, drawstr + but->ofs, ime_data->composite_len + but->pos - but->ofs); | fstyle->uifont_id, drawstr + but->ofs, ime_data->len + but->ime_start - but->ofs); | ||||
| rgba_uchar_to_float(fcol, wcol->text); | rgba_uchar_to_float(fcol, wcol->text); | ||||
| UI_draw_text_underline(rect->xmin + ofs_x, | UI_draw_text_underline(rect->xmin + ofs_x, | ||||
| rect->ymin + 6 * U.pixelsize, | rect->ymin + 6 * U.pixelsize, | ||||
| min_ii(width, rect_x - 2) - ofs_x, | min_ii(width, rect_x - 2) - ofs_x, | ||||
| 1, | 1, | ||||
| fcol); | fcol); | ||||
| /* draw the thick line */ | /* draw the thick line */ | ||||
| if (sel_start != -1 && sel_end != -1) { | if (sel_start != -1 && sel_end != -1) { | ||||
| sel_end -= sel_start; | sel_end -= sel_start; | ||||
| sel_start += but->pos; | sel_start += but->ime_start; | ||||
| if (sel_start >= but->ofs) { | if (sel_start >= but->ofs) { | ||||
| ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, sel_start - but->ofs); | ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, sel_start - but->ofs); | ||||
| } | } | ||||
| else { | else { | ||||
| ofs_x = 0; | ofs_x = 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| uiBut *but, | uiBut *but, | ||||
| rcti *rect) | rcti *rect) | ||||
| { | { | ||||
| int drawstr_left_len = UI_MAX_DRAW_STR; | int drawstr_left_len = UI_MAX_DRAW_STR; | ||||
| const char *drawstr = but->drawstr; | const char *drawstr = but->drawstr; | ||||
| const char *drawstr_right = NULL; | const char *drawstr_right = NULL; | ||||
| bool use_right_only = false; | bool use_right_only = false; | ||||
| #ifdef WITH_INPUT_IME | |||||
| const wmIMEData *ime_data; | |||||
| #endif | |||||
| UI_fontstyle_set(fstyle); | UI_fontstyle_set(fstyle); | ||||
| eFontStyle_Align align; | eFontStyle_Align align; | ||||
| if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) { | if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) { | ||||
| align = UI_STYLE_TEXT_LEFT; | align = UI_STYLE_TEXT_LEFT; | ||||
| } | } | ||||
| else if (but->drawflag & UI_BUT_TEXT_RIGHT) { | else if (but->drawflag & UI_BUT_TEXT_RIGHT) { | ||||
| align = UI_STYLE_TEXT_RIGHT; | align = UI_STYLE_TEXT_RIGHT; | ||||
| Show All 16 Lines | |||||
| align = UI_STYLE_TEXT_LEFT; | align = UI_STYLE_TEXT_LEFT; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (but->editstr) { | if (but->editstr) { | ||||
| /* max length isn't used in this case, | /* max length isn't used in this case, | ||||
| * we rely on string being NULL terminated. */ | * we rely on string being NULL terminated. */ | ||||
| drawstr_left_len = INT_MAX; | drawstr_left_len = INT_MAX; | ||||
| drawstr = but->editstr; | |||||
| #ifdef WITH_INPUT_IME | |||||
| /* FIXME, IME is modifying 'const char *drawstr! */ | |||||
| ime_data = ui_but_ime_data_get(but); | |||||
| if (ime_data && ime_data->composite_len) { | |||||
| /* insert composite string into cursor pos */ | |||||
| BLI_snprintf((char *)drawstr, | |||||
| UI_MAX_DRAW_STR, | |||||
| "%s%s%s", | |||||
| but->editstr, | |||||
| ime_data->str_composite, | |||||
| but->editstr + but->pos); | |||||
| } | |||||
| else | |||||
| #endif | |||||
| { | |||||
| drawstr = but->editstr; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* text button selection, cursor, composite underline */ | /* text button selection, cursor, composite underline */ | ||||
| if (but->editstr && but->pos != -1) { | if (but->editstr && but->pos != -1) { | ||||
| int but_pos_ofs; | int but_pos_ofs; | ||||
| /* Shape of the cursor for drawing. */ | /* Shape of the cursor for drawing. */ | ||||
| rcti but_cursor_shape; | rcti but_cursor_shape; | ||||
| Show All 30 Lines | |||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| } | } | ||||
| /* text cursor */ | /* text cursor */ | ||||
| but_pos_ofs = but->pos; | but_pos_ofs = but->pos; | ||||
| #ifdef WITH_INPUT_IME | |||||
| /* if is ime compositing, move the cursor */ | |||||
| if (ime_data && ime_data->composite_len && ime_data->cursor_pos != -1) { | |||||
| but_pos_ofs += ime_data->cursor_pos; | |||||
| } | |||||
| #endif | |||||
| if (but->pos >= but->ofs) { | if (but->pos >= but->ofs) { | ||||
| int t; | int t; | ||||
| if (drawstr[0] != 0) { | if (drawstr[0] != 0) { | ||||
| t = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but_pos_ofs - but->ofs); | t = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but_pos_ofs - but->ofs); | ||||
| } | } | ||||
| else { | else { | ||||
| t = 0; | t = 0; | ||||
| } | } | ||||
| Show All 16 Lines | |||||
| /* draw cursor */ | /* draw cursor */ | ||||
| immRecti(pos, | immRecti(pos, | ||||
| but_cursor_shape.xmin, | but_cursor_shape.xmin, | ||||
| but_cursor_shape.ymin, | but_cursor_shape.ymin, | ||||
| but_cursor_shape.xmax, | but_cursor_shape.xmax, | ||||
| but_cursor_shape.ymax); | but_cursor_shape.ymax); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | |||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_INPUT_IME | ||||
| if (ime_data && ime_data->composite_len) { | if ((but->ime_end - but->ime_start) > 0) { | ||||
| /* ime cursor following */ | const wmIMEData *ime_data = ui_but_ime_data_get(but); | ||||
| if (but->pos >= but->ofs) { | /* IME cursor following. */ | ||||
| ui_but_ime_reposition(but, but_cursor_shape.xmax + 5, but_cursor_shape.ymin + 3, false); | int width = BLF_width(fstyle->uifont_id, | ||||
| drawstr + but->ofs, | |||||
| max_ii(but->ime_start + ime_data->sel_start - but->ofs, 0)); | |||||
| ui_but_ime_position(but, | |||||
| but_cursor_shape.xmin - t + width, | |||||
| but_cursor_shape.ymin, | |||||
| but_cursor_shape.ymax - but_cursor_shape.ymin); | |||||
| /* Composite underline. */ | |||||
| widget_draw_text_ime_underline(fstyle, wcol, but, rect, ime_data, drawstr); | |||||
| } | } | ||||
| /* composite underline */ | |||||
| widget_draw_text_ime_underline(fstyle, wcol, but, rect, ime_data, drawstr); | |||||
| } | |||||
| #endif | #endif | ||||
| } | |||||
| } | } | ||||
| if (fstyle->kerning == 1) { | if (fstyle->kerning == 1) { | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| #if 0 | #if 0 | ||||
| ui_rasterpos_safe(x, y, but->aspect); | ui_rasterpos_safe(x, y, but->aspect); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||