static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc, ARegion *ar) { SuggItem *item, *first, *last, *sel; char str[SUGG_LIST_WIDTH * BLI_UTF8_MAX + 1]; int offl, offc, vcurl, vcurc; int w, boxw = 0, boxh, i, x, y, *top; const int lheight = st->lheight_dpi + TXT_LINE_SPACING; const int margin_x = 2; if (!st->text) return; if (!texttool_text_is_active(st->text)) return; first = texttool_suggest_first(); last = texttool_suggest_last(); if (!first || !last) return; text_pop_suggest_list(); sel = texttool_suggest_selected(); top = texttool_suggest_top(); wrap_offset(st, ar, st->text->curl, st->text->curc, &offl, &offc); vcurl = txt_get_span(st->text->lines.first, st->text->curl) - st->top + offl; vcurc = text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc; x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; x += vcurc * st->cwidth - 4; y = ar->winy - (vcurl + 1) * lheight - 2; /* offset back so the start of the text lines up with the suggestions, * not essential but makes suggestions easier to follow */ x -= st->cwidth * (st->text->curc - text_find_identifier_start(st->text->curl->line, st->text->curc)); boxw = SUGG_LIST_WIDTH * st->cwidth + 20; boxh = SUGG_LIST_SIZE * lheight + 8; if (x + boxw > ar->winx) x = MAX2(0, ar->winx - boxw); /* not needed but stands out nicer */ UI_draw_box_shadow(220, x, y - boxh, x + boxw, y); UI_ThemeColor(TH_SHADE1); glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1); UI_ThemeColorShade(TH_BACK, 16); glRecti(x, y, x + boxw, y - boxh); /* Set the top 'item' of the visible list */ for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ; for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) { int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, NULL) - item->name; y -= lheight; BLI_strncpy(str, item->name, len + 1); w = st->cwidth * text_get_char_pos(st, str, len); if (item == sel) { UI_ThemeColor(TH_SHADE2); glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3); } format_draw_color(item->type); text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, NULL); if (item == last) break; } }
static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int sy, ImBuf *imb, FileLayout *layout, bool is_icon, bool drag) { uiBut *but; float fx, fy; float dx, dy; int xco, yco; float ui_imbx, ui_imby; float scaledx, scaledy; float scale; int ex, ey; bool use_dropshadow = !is_icon && (file->flags & FILE_TYPE_IMAGE); BLI_assert(imb != NULL); ui_imbx = imb->x * UI_DPI_FAC; ui_imby = imb->y * UI_DPI_FAC; /* Unlike thumbnails, icons are not scaled up. */ if (((ui_imbx > layout->prv_w) || (ui_imby > layout->prv_h)) || (!is_icon && ((ui_imbx < layout->prv_w) || (ui_imby < layout->prv_h)))) { if (imb->x > imb->y) { scaledx = (float)layout->prv_w; scaledy = ((float)imb->y / (float)imb->x) * layout->prv_w; scale = scaledx / imb->x; } else { scaledy = (float)layout->prv_h; scaledx = ((float)imb->x / (float)imb->y) * layout->prv_h; scale = scaledy / imb->y; } } else { scaledx = ui_imbx; scaledy = ui_imby; scale = UI_DPI_FAC; } ex = (int)scaledx; ey = (int)scaledy; fx = ((float)layout->prv_w - (float)ex) / 2.0f; fy = ((float)layout->prv_h - (float)ey) / 2.0f; dx = (fx + 0.5f + layout->prv_border_x); dy = (fy + 0.5f - layout->prv_border_y); xco = sx + (int)dx; yco = sy - layout->prv_h + (int)dy; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* shadow */ if (use_dropshadow) { UI_draw_box_shadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey)); } glEnable(GL_BLEND); /* the image */ if (!is_icon && file->flags & FILE_TYPE_FTFONT) { UI_ThemeColor(TH_TEXT); } else { glColor4f(1.0, 1.0, 1.0, 1.0); } glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale); /* border */ if (use_dropshadow) { glColor4f(0.0f, 0.0f, 0.0f, 0.4f); fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey)); } /* dragregion */ if (drag) { but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, ""); UI_but_drag_set_image(but, file->path, get_file_icon(file), imb, scale, false); } glDisable(GL_BLEND); }