Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| #include "interface_intern.h" | #include "interface_intern.h" | ||||
| #include "GPU_basic_shader.h" | #include "GPU_basic_shader.h" | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_IM_ONTHESPOT | ||||
| # include "WM_types.h" | # include "WM_types.h" | ||||
| #endif | #endif | ||||
| /* icons are 80% of height of button (16 pixels inside 20 height) */ | /* icons are 80% of height of button (16 pixels inside 20 height) */ | ||||
| #define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect)) | #define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect)) | ||||
| /* ************** widget base functions ************** */ | /* ************** widget base functions ************** */ | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 1,162 Lines • ▼ Show 20 Lines | if (but->strwidth > okwidth) { | ||||
| but->strwidth = strwidth; | but->strwidth = strwidth; | ||||
| but->drawstr[drawstr_len] = 0; | but->drawstr[drawstr_len] = 0; | ||||
| } | } | ||||
| if (fstyle->kerning == 1) | if (fstyle->kerning == 1) | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_IM_ONTHESPOT | ||||
| static void widget_draw_text_ime_underline( | static void widget_draw_text_im_underline( | ||||
| uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, const rcti *rect, | uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, const rcti *rect, | ||||
| const wmIMEData *ime_data, const char *drawstr) | const wmIMData *im_data, 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 = im_data->sel_start, sel_end = im_data->sel_end; | ||||
| if (drawstr[0] != 0) { | if (drawstr[0] != 0) { | ||||
| if (but->pos >= but->ofs) { | if (but->pos >= 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->pos - but->ofs); | ||||
| } | } | ||||
| else { | else { | ||||
| ofs_x = 0; | ofs_x = 0; | ||||
| } | } | ||||
| width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, | width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, | ||||
| ime_data->composite_len + but->pos - but->ofs); | im_data->composite_len + but->pos - but->ofs); | ||||
| glColor4ubv((unsigned char *)wcol->text); | glColor4ubv((unsigned char *)wcol->text); | ||||
| UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1); | UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1); | ||||
| /* 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->pos; | ||||
| 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; | ||||
| } | } | ||||
| width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, | width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, | ||||
| sel_end + sel_start - but->ofs); | sel_end + sel_start - but->ofs); | ||||
| UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2); | UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif /* WITH_INPUT_IME */ | #endif /* WITH_IM_ONTHESPOT */ | ||||
| static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) | static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, 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 | #ifdef WITH_IM_ONTHESPOT | ||||
| const wmIMEData *ime_data; | const wmIMData *im_data; | ||||
| #endif | #endif | ||||
| UI_fontstyle_set(fstyle); | UI_fontstyle_set(fstyle); | ||||
| if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) | if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) | ||||
| fstyle->align = UI_STYLE_TEXT_LEFT; | fstyle->align = UI_STYLE_TEXT_LEFT; | ||||
| else if (but->drawflag & UI_BUT_TEXT_RIGHT) | else if (but->drawflag & UI_BUT_TEXT_RIGHT) | ||||
| fstyle->align = UI_STYLE_TEXT_RIGHT; | fstyle->align = UI_STYLE_TEXT_RIGHT; | ||||
| Show All 14 Lines | if (UNLIKELY(but->flag & UI_BUT_DRAG_MULTI)) { | ||||
| } | } | ||||
| } | } | ||||
| 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; | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_IM_ONTHESPOT | ||||
| /* FIXME, IME is modifying 'const char *drawstr! */ | /* FIXME, IME is modifying 'const char *drawstr! */ | ||||
| ime_data = ui_but_ime_data_get(but); | im_data = ui_but_im_data_get(but); | ||||
| if (ime_data && ime_data->composite_len) { | if (im_data && im_data->composite_len) { | ||||
| /* insert composite string into cursor pos */ | /* insert composite string into cursor pos */ | ||||
| BLI_snprintf((char *)drawstr, UI_MAX_DRAW_STR, "%s%s%s", | BLI_snprintf((char *)drawstr, UI_MAX_DRAW_STR, "%s%s%s", | ||||
| but->editstr, ime_data->str_composite, | but->editstr, im_data->str_composite, | ||||
| but->editstr + but->pos); | but->editstr + but->pos); | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| drawstr = but->editstr; | drawstr = but->editstr; | ||||
| } | } | ||||
| } | } | ||||
| Show All 26 Lines | if ((but->selend - but->selsta) > 0) { | ||||
| min_ii(rect->xmin + selwidth_draw, rect->xmax - 2), | min_ii(rect->xmin + selwidth_draw, rect->xmax - 2), | ||||
| rect->ymax - 2); | rect->ymax - 2); | ||||
| } | } | ||||
| } | } | ||||
| /* text cursor */ | /* text cursor */ | ||||
| but_pos_ofs = but->pos; | but_pos_ofs = but->pos; | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_IM_ONTHESPOT | ||||
| /* if is ime compositing, move the cursor */ | /* if is IM compositing, move the cursor */ | ||||
| if (ime_data && ime_data->composite_len && ime_data->cursor_pos != -1) { | if (im_data && im_data->composite_len && im_data->cursor_pos != -1) { | ||||
| but_pos_ofs += ime_data->cursor_pos; | but_pos_ofs += im_data->cursor_pos; | ||||
| } | } | ||||
| #endif | #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; | ||||
| } | } | ||||
| glColor3f(0.2, 0.6, 0.9); | glColor3f(0.2, 0.6, 0.9); | ||||
| tx = rect->xmin + t + 2; | tx = rect->xmin + t + 2; | ||||
| ty = rect->ymin + 2; | ty = rect->ymin + 2; | ||||
| /* draw cursor */ | /* draw cursor */ | ||||
| glRecti(rect->xmin + t, ty, tx, rect->ymax - 2); | glRecti(rect->xmin + t, ty, tx, rect->ymax - 2); | ||||
| #ifdef WITH_IM_OVERTHESPOT | |||||
| /* over-the-spot style input needs coordinates of composition window every time | |||||
| * the cursor is drawn, because preedit text is drawn in the composition window | |||||
| * and there is no way to know if the preedit is empty or not. */ | |||||
| /* XXX python3 allows non-ascii variable name. is this if() really needed...? */ | |||||
| if (!ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER)) | |||||
| ui_but_im_spot_set(but, tx, ty, rect->ymax - 2 - ty); | |||||
| #endif | |||||
| } | } | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_IM_ONTHESPOT | ||||
| if (ime_data && ime_data->composite_len) { | if (im_data && im_data->composite_len) { | ||||
| /* ime cursor following */ | /* IM cursor following */ | ||||
| if (but->pos >= but->ofs) { | if (but->pos >= but->ofs) { | ||||
| ui_but_ime_reposition(but, tx + 5, ty + 3, false); | ui_but_im_spot_set(but, tx, ty, rect->ymax - 2 - ty); | ||||
| } | } | ||||
| /* composite underline */ | /* composite underline */ | ||||
| widget_draw_text_ime_underline(fstyle, wcol, but, rect, ime_data, drawstr); | widget_draw_text_im_underline(fstyle, wcol, but, rect, im_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 | ||||
| ▲ Show 20 Lines • Show All 2,766 Lines • Show Last 20 Lines | |||||