Beispiel #1
0
static void draw_suggestion_list(SpaceText *st, 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 */
	uiDrawBoxShadow(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, str, 0, 0, x + margin_x, y - 1, NULL);

		if (item == last) break;
	}
}
Beispiel #2
0
static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int sy, ImBuf *imb, FileLayout *layout, short dropshadow)
{
	if (imb) {
		uiBut *but;
		float fx, fy;
		float dx, dy;
		int xco, yco;
		float scaledx, scaledy;
		float scale;
		int ex, ey;
		
		if ( (imb->x > layout->prv_w) || (imb->y > 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 = (float)imb->x;
			scaledy = (float)imb->y;
			scale = 1.0;
		}
		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 (dropshadow)
			uiDrawBoxShadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));

		glEnable(GL_BLEND);
		
		/* the image */
		glColor4f(1.0, 1.0, 1.0, 1.0);
		glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
		
		/* border */
		if (dropshadow) {
			glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
			fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
		}
		
		/* dragregion */
		but = uiDefBut(block, LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
		uiButSetDragImage(but, file->path, get_file_icon(file), imb, scale);
		
		glDisable(GL_BLEND);
		imb = NULL;
	}
}