示例#1
0
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);
}
示例#2
0
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);
}
示例#3
0
static HBITMAP winButtonGetBitmap(Ihandle* ih, UINT itemState, int *shift, int *w, int *h, int *bpp, HBITMAP *hMask)
{
  char *name;
  int make_inactive = 0;
  HBITMAP hBitmap;
  *hMask = NULL;

  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)
    {
      if (shift && !iupAttribGetBoolean(ih, "IMPRESSBORDER")) 
        *shift = 0;
    }
    else
      name = iupAttribGet(ih, "IMAGE");
  }

  hBitmap = iupImageGetImage(name, ih, make_inactive);

  /* must use this info, since image can be a driver image loaded from resources */
  iupdrvImageGetInfo(hBitmap, w, h, bpp);

  if (*bpp == 8)
    *hMask = iupdrvImageCreateMask(IupGetHandle(name));

  return hBitmap;
}
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);
}
示例#5
0
static int winTabsGetImageIndex(Ihandle* ih, const char* name)
{
  HIMAGELIST image_list;
  int count, i, bpp, ret;
  Iarray* bmp_array;
  HBITMAP *bmp_array_data, hMask=NULL;
  HBITMAP bmp = iupImageGetImage(name, ih, 0);
  if (!bmp)
    return -1;

  /* the array is used to avoi adding the same bitmap twice */
  bmp_array = (Iarray*)iupAttribGet(ih, "_IUPWIN_BMPARRAY");
  if (!bmp_array)
  {
    /* create the array if does not exist */
    bmp_array = iupArrayCreate(50, sizeof(HBITMAP));
    iupAttribSetStr(ih, "_IUPWIN_BMPARRAY", (char*)bmp_array);
  }

  bmp_array_data = iupArrayGetData(bmp_array);

  image_list = (HIMAGELIST)SendMessage(ih->handle, TCM_GETIMAGELIST, 0, 0);
  if (!image_list)
  {
    int width, height;
    UINT flags = ILC_COLOR32|ILC_MASK;

    /* must use this info, since image can be a driver image loaded from resources */
    iupdrvImageGetInfo(bmp, &width, &height, &bpp);

    /* create the image list if does not exist */
    image_list = ImageList_Create(width, height, flags, 0, 50);
    SendMessage(ih->handle, TCM_SETIMAGELIST, 0, (LPARAM)image_list);
  }
  else
    iupdrvImageGetInfo(bmp, NULL, NULL, &bpp);

  /* check if that bitmap is already added to the list,
     but we can not compare with the actual bitmap at the list since it is a copy */
  count = ImageList_GetImageCount(image_list);
  for (i=0; i<count; i++)
  {
    if (bmp_array_data[i] == bmp)
      return i;
  }

  if (bpp == 8)
  {
    Ihandle* image = IupGetHandle(name);
    if (image)
    {
      iupAttribSetStr(image, "_IUPIMG_NO_INVERT", "1");
      hMask = iupdrvImageCreateMask(image);
      iupAttribSetStr(image, "_IUPIMG_NO_INVERT", NULL);
    }
  }

  bmp_array_data = iupArrayInc(bmp_array);
  bmp_array_data[i] = bmp;
  ret = ImageList_Add(image_list, bmp, hMask);  /* the bmp is duplicated at the list */
  DeleteObject(hMask);
  return ret;
}
示例#6
0
文件: iupwin_list.c 项目: LuaDist/iup
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);
}