static void winLabelDrawImage(Ihandle* ih, HDC hDC, int rect_width, int rect_height) { int xpad = ih->data->horiz_padding, ypad = ih->data->vert_padding; int x, y, width, height, bpp; HBITMAP hBitmap, hMask = NULL; char *name; int make_inactive = 0; if (iupdrvIsActive(ih)) name = iupAttribGet(ih, "IMAGE"); else { name = iupAttribGet(ih, "IMINACTIVE"); if (!name) { name = iupAttribGet(ih, "IMAGE"); make_inactive = 1; } } hBitmap = iupImageGetImage(name, ih, make_inactive); if (!hBitmap) return; /* must use this info, since image can be a driver image loaded from resources */ iupdrvImageGetInfo(hBitmap, &width, &height, &bpp); if (ih->data->horiz_alignment == IUP_ALIGN_ARIGHT) x = rect_width - (width + 2*xpad); else if (ih->data->horiz_alignment == IUP_ALIGN_ACENTER) x = (rect_width - (width + 2*xpad))/2; else /* ALEFT */ x = 0; if (ih->data->vert_alignment == IUP_ALIGN_ABOTTOM) y = rect_height - (height + 2*ypad); else if (ih->data->vert_alignment == IUP_ALIGN_ATOP) y = 0; else /* ACENTER */ y = (rect_height - (height + 2*ypad))/2; x += xpad; y += ypad; if (bpp == 8) hMask = iupdrvImageCreateMask(IupGetHandle(name)); iupwinDrawBitmap(hDC, hBitmap, hMask, x, y, width, height, bpp); if (hMask) DeleteObject(hMask); }
void iupDrawImage(IdrawCanvas* dc, const char* name, int make_inactive, int x, int y, int *img_w, int *img_h) { int bpp; HBITMAP hMask = NULL; HBITMAP hBitmap = (HBITMAP)iupImageGetImage(name, dc->ih, make_inactive); if (!hBitmap) return; /* must use this info, since image can be a driver image loaded from resources */ iupdrvImageGetInfo(hBitmap, img_w, img_h, &bpp); if (bpp == 8) hMask = iupdrvImageCreateMask(IupGetHandle(name)); iupwinDrawBitmap(dc->hBitmapDC, hBitmap, hMask, x, y, *img_w, *img_h, bpp); if (hMask) DeleteObject(hMask); }
static void winButtonDrawImage(Ihandle* ih, HDC hDC, int rect_width, int rect_height, int border, UINT itemState) { int xpad = ih->data->horiz_padding + border, ypad = ih->data->vert_padding + border; int x, y, width, height, bpp, shift = 0; HBITMAP hBitmap, hMask; if (itemState & ODS_SELECTED && !iupwin_comctl32ver6) shift = 1; hBitmap = winButtonGetBitmap(ih, itemState, &shift, &width, &height, &bpp, &hMask); if (!hBitmap) return; x = winButtonCalcAlignPosX(ih->data->horiz_alignment, rect_width, width, xpad, shift); y = winButtonCalcAlignPosY(ih->data->vert_alignment, rect_height, height, ypad, shift); iupwinDrawBitmap(hDC, hBitmap, hMask, x, y, width, height, bpp); if (hMask) DeleteObject(hMask); }
static void winButtonDrawImageText(Ihandle* ih, HDC hDC, int rect_width, int rect_height, int border, UINT itemState) { int xpad = ih->data->horiz_padding + border, ypad = ih->data->vert_padding + border; int x, y, width, height, txt_x, txt_y, txt_width, txt_height, img_x, img_y, img_width, img_height, bpp, shift = 0, style = 0; HFONT hFont = (HFONT)iupwinGetHFontAttrib(ih); HBITMAP hBitmap, hMask; COLORREF fgcolor; char* title = iupAttribGet(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &txt_width, &txt_height); if (str && str!=title) free(str); if (itemState & ODS_DISABLED) fgcolor = GetSysColor(COLOR_GRAYTEXT); else fgcolor = ih->data->fgcolor; hBitmap = winButtonGetBitmap(ih, itemState, NULL, &img_width, &img_height, &bpp, &hMask); if (!hBitmap) return; if (ih->data->img_position == IUP_IMGPOS_RIGHT || ih->data->img_position == IUP_IMGPOS_LEFT) { width = img_width + txt_width + ih->data->spacing; height = iupMAX(img_height, txt_height); } else { width = iupMAX(img_width, txt_width); height = img_height + txt_height + ih->data->spacing; } if (itemState & ODS_SELECTED && !iupwin_comctl32ver6) shift = 1; if (itemState & ODS_NOACCEL && !iupwinGetKeyBoardCues()) style |= DT_HIDEPREFIX; x = winButtonCalcAlignPosX(ih->data->horiz_alignment, rect_width, width, xpad, shift); y = winButtonCalcAlignPosY(ih->data->vert_alignment, rect_height, height, ypad, shift); switch(ih->data->img_position) { case IUP_IMGPOS_TOP: img_y = y; txt_y = y + img_height + ih->data->spacing; if (img_width > txt_width) { img_x = x; txt_x = x + (img_width-txt_width)/2; } else { img_x = x + (txt_width-img_width)/2; txt_x = x; } break; case IUP_IMGPOS_BOTTOM: img_y = y + txt_height + ih->data->spacing; txt_y = y; if (img_width > txt_width) { img_x = x; txt_x = x + (img_width-txt_width)/2; } else { img_x = x + (txt_width-img_width)/2; txt_x = x; } break; case IUP_IMGPOS_RIGHT: img_x = x + txt_width + ih->data->spacing; txt_x = x; if (img_height > txt_height) { img_y = y; txt_y = y + (img_height-txt_height)/2; } else { img_y = y + (txt_height-img_height)/2; txt_y = y; } break; default: /* IUP_IMGPOS_LEFT */ img_x = x; txt_x = x + img_width + ih->data->spacing; if (img_height > txt_height) { img_y = y; txt_y = y + (img_height-txt_height)/2; } else { img_y = y + (txt_height-img_height)/2; txt_y = y; } break; } if (ih->data->horiz_alignment == IUP_ALIGN_ACENTER) style |= DT_CENTER; /* let DrawText do the internal horizontal alignment, usefull for multiple lines */ else if (ih->data->horiz_alignment == IUP_ALIGN_ARIGHT) style |= DT_RIGHT; iupwinDrawBitmap(hDC, hBitmap, hMask, img_x, img_y, img_width, img_height, bpp); iupwinDrawText(hDC, title, txt_x, txt_y, txt_width, txt_height, hFont, fgcolor, style); if (hMask) DeleteObject(hMask); }
static void winToggleDrawImage(Ihandle* ih, HDC hDC, int rect_width, int rect_height, int border, UINT itemState) { /* called only when (ih->data->type==IUP_TOGGLE_IMAGE && (iupwin_comctl32ver6 || ih->data->flat)) */ int xpad = ih->data->horiz_padding + border, ypad = ih->data->vert_padding + border; int horiz_alignment, vert_alignment; int x, y, width, height, bpp; HBITMAP hBitmap, hMask = NULL; char *name; int make_inactive = 0; if (itemState & ODS_DISABLED) { name = iupAttribGet(ih, "IMINACTIVE"); if (!name) { name = iupAttribGet(ih, "IMAGE"); make_inactive = 1; } } else { name = iupAttribGet(ih, "IMPRESS"); if (!(itemState & ODS_SELECTED && name)) name = iupAttribGet(ih, "IMAGE"); } hBitmap = iupImageGetImage(name, ih, make_inactive); if (!hBitmap) return; /* must use this info, since image can be a driver image loaded from resources */ iupdrvImageGetInfo(hBitmap, &width, &height, &bpp); winToggleGetAlignment(ih, &horiz_alignment, &vert_alignment); if (horiz_alignment == IUP_ALIGN_ARIGHT) x = rect_width - (width + 2*xpad); else if (horiz_alignment == IUP_ALIGN_ACENTER) x = (rect_width - (width + 2*xpad))/2; else /* ALEFT */ x = 0; if (vert_alignment == IUP_ALIGN_ABOTTOM) y = rect_height - (height + 2*ypad); else if (vert_alignment == IUP_ALIGN_ATOP) y = 0; else /* ACENTER */ y = (rect_height - (height + 2*ypad))/2; x += xpad; y += ypad; if (itemState & ODS_SELECTED && !iupwin_comctl32ver6) { if (iupAttribGet(ih, "_IUPWIN_PRESSED")) { x++; y++; iupAttribSet(ih, "_IUPWIN_PRESSED", NULL); } } if (bpp == 8) hMask = iupdrvImageCreateMask(IupGetHandle(name)); iupwinDrawBitmap(hDC, hBitmap, hMask, x, y, width, height, bpp); if (hMask) DeleteObject(hMask); }
static void winListDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem) { char* text; int txt_w, txt_h; winListItemData* itemdata; HFONT hFont = (HFONT)iupwinGetHFontAttrib(ih); iupwinBitmapDC bmpDC; HDC hDC; RECT rect; COLORREF fgcolor, bgcolor; int x = drawitem->rcItem.left; int y = drawitem->rcItem.top; int width = drawitem->rcItem.right - drawitem->rcItem.left; int height = drawitem->rcItem.bottom - drawitem->rcItem.top; /* If there are no list box items, skip this message */ if (drawitem->itemID == -1) return; hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, x, y, width, height); if (drawitem->itemState & ODS_SELECTED) bgcolor = GetSysColor(COLOR_HIGHLIGHT); else if (!iupwinGetColorRef(ih, "BGCOLOR", &bgcolor)) bgcolor = GetSysColor(COLOR_WINDOW); SetDCBrushColor(hDC, bgcolor); SetRect(&rect, 0, 0, width, height); FillRect(hDC, &rect, (HBRUSH)GetStockObject(DC_BRUSH)); if (iupdrvIsActive(ih)) { if (drawitem->itemState & ODS_SELECTED) fgcolor = GetSysColor(COLOR_HIGHLIGHTTEXT); else if (!iupwinGetColorRef(ih, "FGCOLOR", &fgcolor)) fgcolor = GetSysColor(COLOR_WINDOWTEXT); } else fgcolor = GetSysColor(COLOR_GRAYTEXT); /* Get the bitmap associated with the item */ itemdata = winListGetItemData(ih, drawitem->itemID); /* Get and draw the string associated with the item */ text = winListGetText(ih, drawitem->itemID); iupdrvFontGetMultiLineStringSize(ih, text, &txt_w, &txt_h); x = ih->data->maximg_w + 3; /* spacing between text and image */ y = (height - txt_h)/2; /* vertically centered */ iupwinDrawText(hDC, text, x, y, txt_w, txt_h, hFont, fgcolor, 0); /* Draw the bitmap associated with the item */ if (itemdata->hBitmap) { int bpp, img_w, img_h; HBITMAP hMask = NULL; iupdrvImageGetInfo(itemdata->hBitmap, &img_w, &img_h, &bpp); if (bpp == 8) { char name[50]; sprintf(name, "IMAGE%d", (int)drawitem->itemID+1); hMask = iupdrvImageCreateMask(IupGetAttributeHandle(ih, name)); } x = 0; y = (height - img_h)/2; /* vertically centered */ iupwinDrawBitmap(hDC, itemdata->hBitmap, hMask, x, y, img_w, img_h, bpp); if (hMask) DeleteObject(hMask); } /* If the item has the focus, draw the focus rectangle */ if (drawitem->itemState & ODS_FOCUS) iupdrvDrawFocusRect(ih, hDC, 0, 0, width, height); free(text); iupwinDrawDestroyBitmapDC(&bmpDC); }