Ejemplo n.º 1
0
static void iFlatButtonDrawBorder(IdrawCanvas* dc, int xmin, int xmax, int ymin, int ymax, int border_width, const char* color, char* bgcolor, int active)
{
  unsigned char r = 0, g = 0, b = 0;

  if (!color || border_width == 0 || xmin == xmax || ymin == ymax)
    return;

  if (xmin > xmax) { int _t = xmin; xmin = xmax; xmax = _t; }
  if (ymin > ymax) { int _t = ymin; ymin = ymax; ymax = _t; }

  iupStrToRGB(color, &r, &g, &b);
  if (!active)
  {
    unsigned char bg_r = 0, bg_g = 0, bg_b = 0;
    iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);
    iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);
  }

  iupDrawRectangle(dc, xmin, ymin, xmax, ymax, r, g, b, IUP_DRAW_STROKE);
  while (border_width > 1)
  {
    border_width--;
    iupDrawRectangle(dc, xmin + border_width, 
                         ymin + border_width, 
                         xmax - border_width, 
                         ymax - border_width, r, g, b, IUP_DRAW_STROKE);
  } 
}
Ejemplo n.º 2
0
void iFlatButtonDrawText(Ihandle* ih, IdrawCanvas* dc, int x, int y, const char* str, const char* color, const char* bgcolor, int active)
{
  unsigned char r = 0, g = 0, b = 0;

  if (!color || !str || str[0] == 0)
    return;

  iupStrToRGB(color, &r, &g, &b);
  if (!active)
  {
    unsigned char bg_r = 0, bg_g = 0, bg_b = 0;
    iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);
    iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);
  }

  iupDrawText(dc, str, (int)strlen(str), x, y, r, g, b, IupGetAttribute(ih, "FONT"));
}
Ejemplo n.º 3
0
static void cdIupInitPalette(Ihandle* image, long* palette, long bgcolor, int make_inactive)
{
  int i;
  unsigned char r, g, b, bg_r, bg_g, bg_b;

  cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);

  for(i = 0; i < 256; i++)
  {
    char* color = IupGetAttributeId(image, "", i);
    r = bg_r; g = bg_g; b = bg_b;
    iupStrToRGB(color, &r, &g, &b);  /* no need to test for BGCOLOR, if this failed it will not set the parameters */

    if (make_inactive)
      iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

    palette[i] = cdEncodeColor(r, g, b);
  }
}
Ejemplo n.º 4
0
static int iMatrixListDrawColorCol(Ihandle *ih, int lin, int x1, int x2, int y1, int y2, cdCanvas *cnv)
{
  unsigned char red, green, blue;
  char* color = iupAttribGetId(ih, "COLOR", lin);

  if (iupStrToRGB(color, &red, &green, &blue))
  {
    static const int DX_BORDER = 2;
    static const int DY_BORDER = 3;
    static const int DX_FILL = 3;
    static const int DY_FILL = 4;
    int active = iupdrvIsActive(ih);
    int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin);
    long framecolor;

    if (!itemactive)
    {
      red = IMAT_LIGHTER(red);
      green = IMAT_LIGHTER(green);
      blue = IMAT_LIGHTER(blue);
    }

    if (!active)
    {
      unsigned char bg_r, bg_g, bg_b;
      iupStrToRGB(ih->data->bgcolor, &bg_r, &bg_g, &bg_b);
      iupImageColorMakeInactive(&red, &green, &blue, bg_r, bg_g, bg_b);
    }

    /* Fill the box with the color */
    cdCanvasForeground(cnv, cdEncodeColor(red, green, blue));
    cdCanvasBox(cnv, x1 + DX_FILL, x2 - DX_FILL, y1 - DY_FILL, y2 + DY_FILL);

    /* Draw the border */
    framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR"));
    cdCanvasForeground(cnv, framecolor);

    cdCanvasRect(cnv, x1 + DX_BORDER, x2 - DX_BORDER, y1 - DY_BORDER, y2 + DY_BORDER);
  }

  return IUP_DEFAULT;  /* draw nothing more */
}
Ejemplo n.º 5
0
static void iFlatButtonDrawBox(IdrawCanvas* dc, int xmin, int xmax, int ymin, int ymax, const char* color, char* bgcolor, int active)
{
  unsigned char r = 0, g = 0, b = 0;

  if (!color || xmin == xmax || ymin == ymax)
    return;

  if (xmin > xmax) { int _t = xmin; xmin = xmax; xmax = _t; }
  if (ymin > ymax) { int _t = ymin; ymin = ymax; ymax = _t; }

  iupStrToRGB(color, &r, &g, &b);
  if (!active)
  {
    unsigned char bg_r = 0, bg_g = 0, bg_b = 0;
    iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);
    iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);
  }

  iupDrawRectangle(dc, xmin, ymin, xmax, ymax, r, g, b, IUP_DRAW_FILL);
}
Ejemplo n.º 6
0
/* This function is used to draw a box for a cell. */
static void iColorbarDrawBox(Ihandle* ih, int xmin, int xmax, int ymin, int ymax, int idx)
{
  long int color = ih->data->colors[idx];
  cdCanvasInteriorStyle(ih->data->cddbuffer, CD_SOLID);

  if (color == ih->data->transparency)
  { 
    int xm = (xmin+xmax)/2;
    int ym = (ymin+ymax)/2;
    cdCanvasForeground(ih->data->cddbuffer,0xeeeeee);
    cdCanvasBox(ih->data->cddbuffer,xmin, xm, ymin, ym);
    cdCanvasBox(ih->data->cddbuffer,xm, xmax, ym, ymax);
    cdCanvasForeground(ih->data->cddbuffer,0xcccccc);
    cdCanvasBox(ih->data->cddbuffer,xmin, xm, ym, ymax);
    cdCanvasBox(ih->data->cddbuffer,xm, xmax, ymin, ym);
  }
  else
  {
    if (!iupdrvIsActive(ih))
    {
      unsigned char r, g, b, bg_r, bg_g, bg_b;
      cdDecodeColor(color, &r, &g, &b);
      cdDecodeColor(ih->data->bgcolor, &bg_r, &bg_g, &bg_b);
      iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);
      color = cdEncodeColor(r, g, b);
    }
    cdCanvasForeground(ih->data->cddbuffer,color);
    cdCanvasBegin(ih->data->cddbuffer,CD_FILL);
    cdCanvasVertex(ih->data->cddbuffer,xmin, ymin); cdCanvasVertex(ih->data->cddbuffer,xmin, ymax);
    cdCanvasVertex(ih->data->cddbuffer,xmax, ymax); cdCanvasVertex(ih->data->cddbuffer,xmax, ymin);
    cdCanvasEnd(ih->data->cddbuffer);
  }

  cdCanvasForeground(ih->data->cddbuffer,CD_BLACK);
  cdCanvasBegin(ih->data->cddbuffer,CD_CLOSED_LINES);
  cdCanvasVertex(ih->data->cddbuffer,xmin, ymin); cdCanvasVertex(ih->data->cddbuffer,xmin, ymax);
  cdCanvasVertex(ih->data->cddbuffer,xmax, ymax); cdCanvasVertex(ih->data->cddbuffer,xmax, ymin);
  cdCanvasEnd(ih->data->cddbuffer);
}
Ejemplo n.º 7
0
void* iupdrvImageCreateImage(Ihandle *ih, const char* bgcolor, int make_inactive)
{
  GdkPixbuf* pixbuf;
  guchar *pixdata, *pixline_data;
  int rowstride, channels;
  unsigned char *imgdata, *line_data, bg_r=0, bg_g=0, bg_b=0;
  int x, y, i, bpp, colors_count = 0, has_alpha = 0;
  iupColor colors[256];

  bpp = iupAttribGetInt(ih, "BPP");

  if (bpp == 8)
    has_alpha = iupImageInitColorTable(ih, colors, &colors_count);
  else if (bpp == 32)
    has_alpha = 1;

  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, ih->currentwidth, ih->currentheight);
  if (!pixbuf)
    return NULL;

  pixdata = gdk_pixbuf_get_pixels(pixbuf);
  rowstride = gdk_pixbuf_get_rowstride(pixbuf);
  channels = gdk_pixbuf_get_n_channels(pixbuf);
  imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");

  if (make_inactive)  
    iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);

  if (bpp == 8)
  {
    if (make_inactive)
    {
      for (i=0;i<colors_count;i++)
      {
        if (colors[i].a == 0)
        {
          colors[i].r = bg_r;
          colors[i].g = bg_g;
          colors[i].b = bg_b;
          colors[i].a = 255;
        }

        iupImageColorMakeInactive(&(colors[i].r), &(colors[i].g), &(colors[i].b), 
                                  bg_r, bg_g, bg_b);
      }
    }

    for (y=0; y<ih->currentheight; y++)
    {
      pixline_data = pixdata + y * rowstride;
      line_data = imgdata + y * ih->currentwidth;

      for (x=0; x<ih->currentwidth; x++)
      {
        unsigned char index = line_data[x];
        iupColor* c = &colors[index];
        guchar *r = &pixline_data[channels*x],
               *g = r+1,
               *b = g+1,
               *a = b+1;

        *r = c->r;
        *g = c->g;
        *b = c->b;

        if (has_alpha)
          *a = c->a;
      }
    }
  }
  else /* bpp == 32 or bpp == 24 */
  {
    for (y=0; y<ih->currentheight; y++)
    {
      pixline_data = pixdata + y * rowstride;
      line_data = imgdata + y * ih->currentwidth*channels;

      memcpy(pixline_data, line_data, ih->currentwidth*channels);

      if (make_inactive)
      {
        for (x=0; x<ih->currentwidth; x++)
        {
          guchar *r = &pixline_data[channels*x],
                 *g = r+1,
                 *b = g+1,
                 *a = b+1;

          if (has_alpha)
          {
            if (*a != 255)
            {
              *r = iupALPHABLEND(*r, bg_r, *a);
              *g = iupALPHABLEND(*g, bg_g, *a);
              *b = iupALPHABLEND(*b, bg_b, *a);
            }
            else
              *a = 255;
          }

          iupImageColorMakeInactive(r, g, b, 
                                    bg_r, bg_g, bg_b);
        }
      }
    }
  }

  return pixbuf;
}
Ejemplo n.º 8
0
static unsigned char* cdIupBuildImageBuffer(Ihandle *image, int width, int height, int depth, int make_inactive, long bgcolor)
{
  int size, plane_size, i, j;
  unsigned char bg_r, bg_g, bg_b;
  unsigned char* image_buffer;
  /* images from stock or resources are not supported */
  unsigned char* data = (unsigned char*)IupGetAttribute(image, "WID");
  if (!data)
    return NULL;

  plane_size = width*height;
  size = plane_size*depth;

  image_buffer = malloc(size);
  if (!image_buffer)
    return NULL;

  cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);

  /* IUP image is top-down, CD image is bottom up */
  if (depth==1)
  {
    /* inactive will be set at the palette */
    for (i=0; i<height; i++)
      memcpy(image_buffer + i*width, data + (height-1 - i)*width, width);
  }
  else if (depth==3)
  {
    int pos;
    unsigned char r, g, b;
    unsigned char *dst_r = image_buffer + 0*plane_size;
    unsigned char *dst_g = image_buffer + 1*plane_size;
    unsigned char *dst_b = image_buffer + 2*plane_size;

    for (i=0; i<height; i++)
    {
      int line_offset = i*width;
      unsigned char *line_r = dst_r + line_offset;
      unsigned char *line_g = dst_g + line_offset;
      unsigned char *line_b = dst_b + line_offset;
      unsigned char *src_rgb = data + (height-1 - i)*(3*width);

      for (j=0; j<width; j++)
      {
        pos = j*3;
        r = src_rgb[pos+0];
        g = src_rgb[pos+1];
        b = src_rgb[pos+2];

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        line_r[j] = r;
        line_g[j] = g;
        line_b[j] = b;
      }
    }
  }
  else /* depth==4 */
  {
    int pos;
    unsigned char r, g, b, a;
    unsigned char *dst_r = image_buffer + 0*plane_size;
    unsigned char *dst_g = image_buffer + 1*plane_size;
    unsigned char *dst_b = image_buffer + 2*plane_size;
    unsigned char *dst_a = image_buffer + 3*plane_size;

    for (i=0; i<height; i++)
    {
      int line_offset = i*width;
      unsigned char *line_r = dst_r + line_offset;
      unsigned char *line_g = dst_g + line_offset;
      unsigned char *line_b = dst_b + line_offset;
      unsigned char *line_a = dst_a + line_offset;
      unsigned char *src_rgba = data + (height-1 - i)*(4*width);

      for (j=0; j<width; j++)
      {
        pos = j*4;
        r = src_rgba[pos+0];
        g = src_rgba[pos+1];
        b = src_rgba[pos+2];
        a = src_rgba[pos+3];

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        line_r[j] = r;
        line_g[j] = g;
        line_b[j] = b;
        line_a[j] = a;
      }
    }
  }

  return image_buffer;
}
Ejemplo n.º 9
0
void* iupdrvImageCreateImage(Ihandle *ih, const char* bgcolor, int make_inactive)
{
  int y, x, bpp, bgcolor_depend = 0,
      width = ih->currentwidth,
      height = ih->currentheight;
  unsigned char *imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");
  Pixmap pixmap;
  unsigned char bg_r=0, bg_g=0, bg_b=0;
  GC gc;
  Pixel color2pixel[256];

  bpp = iupAttribGetInt(ih, "BPP");

  iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);

  if (bpp == 8)
  {
    int i, colors_count = 0;
    iupColor colors[256];

    iupImageInitColorTable(ih, colors, &colors_count);

    for (i=0;i<colors_count;i++)
    {
      if (colors[i].a == 0)
      {
        colors[i].r = bg_r;
        colors[i].g = bg_g;
        colors[i].b = bg_b;
        colors[i].a = 255;
        bgcolor_depend = 1;
      }

      if (make_inactive)
        iupImageColorMakeInactive(&(colors[i].r), &(colors[i].g), &(colors[i].b), bg_r, bg_g, bg_b);

      color2pixel[i] = iupmotColorGetPixel(colors[i].r, colors[i].g, colors[i].b);
    }
  }

  pixmap = XCreatePixmap(iupmot_display,
          RootWindow(iupmot_display,iupmot_screen),
          width, height, iupdrvGetScreenDepth());
  if (!pixmap)
    return NULL;

  gc = XCreateGC(iupmot_display,pixmap,0,NULL);
  for (y=0;y<height;y++)
  {
    for(x=0;x<width;x++)
    {
      unsigned long p;
      if (bpp == 8)
        p = color2pixel[imgdata[y*width+x]];
      else
      {
        int channels = (bpp==24)? 3: 4;
        unsigned char *pixel_data = imgdata + y*width*channels + x*channels;
        unsigned char r = *(pixel_data),
                      g = *(pixel_data+1),
                      b = *(pixel_data+2);

        if (bpp == 32)
        {
          unsigned char a = *(pixel_data+3);
          if (a != 255)
          {
            /* flat alpha */
            r = iupALPHABLEND(r, bg_r, a);
            g = iupALPHABLEND(g, bg_g, a);
            b = iupALPHABLEND(b, bg_b, a);
            bgcolor_depend = 1;
          }
        }

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        p = iupmotColorGetPixel(r, g, b);
      }

      XSetForeground(iupmot_display,gc,p);
      XDrawPoint(iupmot_display,pixmap,gc,x,y);
    }
  }
  XFreeGC(iupmot_display,gc);

  if (bgcolor_depend || make_inactive)
    iupAttribSet(ih, "_IUP_BGCOLOR_DEPEND", "1");

  return (void*)pixmap;
}