/* if rect set, do not draw */ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) { wmWindowManager *wm= CTX_wm_manager(C); wmDrag *drag; int cursorx, cursory, x, y; cursorx= win->eventstate->x; cursory= win->eventstate->y; if(rect) { rect->xmin= rect->xmax= cursorx; rect->ymin= rect->ymax= cursory; } /* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */ glEnable(GL_BLEND); for(drag= wm->drags.first; drag; drag= drag->next) { /* image or icon */ if(drag->imb) { x= cursorx - drag->sx/2; y= cursory - drag->sy/2; if(rect) drag_rect_minmax(rect, x, y, x+drag->sx, y+drag->sy); else { glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */ glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_UNSIGNED_BYTE, drag->imb->rect, drag->scale, drag->scale); } } else { x= cursorx - 8; y= cursory - 2; /* icons assumed to be 16 pixels */ if(rect) drag_rect_minmax(rect, x, y, x+16, y+16); else UI_icon_draw_aspect(x, y, drag->icon, 1.0, 0.8); } /* item name */ if(drag->imb) { x= cursorx - drag->sx/2; y= cursory - drag->sy/2 - 16; } else { x= cursorx + 10; y= cursory + 1; } if(rect) { int w= UI_GetStringWidth(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x+w, y+16); } else { glColor4ub(255, 255, 255, 255); UI_DrawString(x, y, wm_drag_name(drag)); } /* operator name with roundbox */ if(drag->opname[0]) { if(drag->imb) { x= cursorx - drag->sx/2; y= cursory + drag->sy/2 + 4; } else { x= cursorx - 8; y= cursory + 16; } if(rect) { int w= UI_GetStringWidth(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x+w, y+16); } else wm_drop_operator_draw(drag->opname, x, y); } } glDisable(GL_BLEND); }
void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect) { glaDrawPixelsTexScaled(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f); }
/* if rect set, do not draw */ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) { wmWindowManager *wm = CTX_wm_manager(C); wmDrag *drag; const int winsize_y = WM_window_pixels_y(win); int cursorx, cursory, x, y; cursorx = win->eventstate->x; cursory = win->eventstate->y; if (rect) { rect->xmin = rect->xmax = cursorx; rect->ymin = rect->ymax = cursory; } /* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */ glEnable(GL_BLEND); for (drag = wm->drags.first; drag; drag = drag->next) { int iconsize = 16 * UI_DPI_FAC; /* assumed to be 16 pixels */ int padding = 4 * UI_DPI_FAC; /* image or icon */ if (drag->imb) { x = cursorx - drag->sx / 2; y = cursory - drag->sy / 2; if (rect) drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy); else { glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */ glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, drag->imb->rect, drag->scale, drag->scale); } } else { x = cursorx - 2 * padding; y = cursory - 2 * UI_DPI_FAC; if (rect) drag_rect_minmax(rect, x, y, x + iconsize, y + iconsize); else UI_icon_draw_aspect(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8); } /* item name */ if (drag->imb) { x = cursorx - drag->sx / 2; y = cursory - drag->sy / 2 - iconsize; } else { x = cursorx + 10 * UI_DPI_FAC; y = cursory + 1 * UI_DPI_FAC; } if (rect) { int w = UI_fontstyle_string_width(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else { glColor4ub(255, 255, 255, 255); UI_draw_string(x, y, wm_drag_name(drag)); } /* operator name with roundbox */ if (drag->opname[0]) { if (drag->imb) { x = cursorx - drag->sx / 2; if (cursory + drag->sy / 2 + padding + iconsize < winsize_y) y = cursory + drag->sy / 2 + padding; else y = cursory - drag->sy / 2 - padding - iconsize - padding - iconsize; } else { x = cursorx - 2 * padding; if (cursory + iconsize + iconsize < winsize_y) y = cursory + iconsize; else y = cursory - iconsize - 2 * UI_DPI_FAC; } if (rect) { int w = UI_fontstyle_string_width(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else wm_drop_operator_draw(drag->opname, x, y); } } glDisable(GL_BLEND); }
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; } }
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); }