Esempio n. 1
0
static void iMatrixDrawImage(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, const char* name)
{
  long bgcolor;
  int x, y;
  Ihandle* image;

  iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

  /* Create an space between image and cell frame */
  x1 += IMAT_PADDING_W/2;       x2 -= IMAT_PADDING_W/2;
  y1 += IMAT_PADDING_H/2;       y2 -= IMAT_PADDING_H/2;

  image = IupGetHandle(name);
  if (image)
  {
    int width  = IupGetInt(image, "WIDTH");
    int height = IupGetInt(image, "HEIGHT");
    unsigned char r = 255, g = 255, b = 255;
    iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b, marked, active);
    bgcolor = cdEncodeColor(r, g, b);

    y = (y2+y1 + height)/2;

    if (alignment == IMAT_ALIGN_CENTER)
      x = x1 + (x2-x1)/2 - width/2;
    else if(alignment == IMAT_ALIGN_LEFT)
      x = x1;
    else  /* RIGHT */
      x = x2 - width;

    cdIupDrawImage(ih->data->cd_canvas, image, x, iupMATRIX_INVERTYAXIS(ih, y), 0, 0, !active, bgcolor);
  }

  iMatrixDrawResetCellClipping(ih);
}
Esempio n. 2
0
static void iMatrixDrawFeedbackImage(Ihandle* ih, int x1, int x2, int y1, int y2, int lin, int col, int active, int marked, const char*name, unsigned char* alpha)
{
  int x, y;
  Ihandle* image = IupGetHandle(name);
  if (image)
  {
    long bgcolor;
    int image_width = IupGetInt(image, "WIDTH");
    int image_height = IupGetInt(image, "HEIGHT");
    unsigned char r = 255, g = 255, b = 255;
    iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b, marked, active);
    bgcolor = cdEncodeColor(r, g, b);

    y = (y2 + y1 + image_height) / 2;
    x = (x2 + x1 - image_width) / 2;

    cdIupDrawImage(ih->data->cd_canvas, image, x, iupMATRIX_INVERTYAXIS(ih, y), 0, 0, !active, bgcolor);
  }
  else
  {
    static unsigned char red[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE];
    static unsigned char green[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE];
    static unsigned char blue[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE];
    static unsigned char last_r = 0, last_g = 0, last_b = 0;
    static int first = 1;

    unsigned char r = 0, g = 0, b = 0;
    iupMatrixGetFgRGB(ih, lin, col, &r, &g, &b, marked, active);

    if (first || last_r != r || last_g != g || last_b != b)
    {
      int count = IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE;

      memset(red, r, count);
      memset(green, g, count);
      memset(blue, b, count);

      last_r = r;
      last_g = g;
      last_b = b;
      first = 0;
    }

    y = (y2 + y1 + IMAT_FEEDBACK_SIZE) / 2;
    x = (x2 + x1 - IMAT_FEEDBACK_SIZE) / 2;

    cdCanvasPutImageRectRGBA(ih->data->cd_canvas, IMAT_FEEDBACK_SIZE, IMAT_FEEDBACK_SIZE, red, green, blue, alpha, x, iupMATRIX_INVERTYAXIS(ih, y), IMAT_FEEDBACK_SIZE, IMAT_FEEDBACK_SIZE, 0, 0, 0, 0);
  }
}
Esempio n. 3
0
void iupPlot::DrawBackgroundImage(cdCanvas* canvas) const
{
  Ihandle* image = iupImageGetHandle(mBack.GetImage());
  if (image)
  {
    double theScreenMinX = mAxisX.mTrafo->Transform(mBack.mImageMinX);
    double theScreenMinY = mAxisY.mTrafo->Transform(mBack.mImageMinY);
    double theScreenMaxX = mAxisX.mTrafo->Transform(mBack.mImageMaxX);
    double theScreenMaxY = mAxisY.mTrafo->Transform(mBack.mImageMaxY);

    double theScreenW = theScreenMaxX - theScreenMinX + 1;
    double theScreenH = theScreenMaxY - theScreenMinY + 1;

    int theX = iupPlotRound(theScreenMinX);
    int theY = iupPlotRound(theScreenMinY);
    int theW = iupPlotRound(theScreenW);
    int theH = iupPlotRound(theScreenH);

    cdIupDrawImage(canvas, image, theX, theY, theW, theH, 0, mBack.mColor);
  }
}
Esempio n. 4
0
static int iMatrixListDrawImageCol(Ihandle *ih, ImatrixListData* mtxList, int lin, int col, int x1, int x2, int y1, int y2, cdCanvas *cnv)
{
  char* image_name;
  int make_inactive = 0, itemactive, imageactive, imagevalue, showdelete,
      active = iupdrvIsActive(ih), linedelete;
  int lines_num = ih->data->lines.num;
  Ihandle* image;

  itemactive = IupGetIntId(ih, "ITEMACTIVE", lin);
  imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin);
  imagevalue = IupGetIntId(ih, "IMAGEVALUE", lin);
  showdelete = IupGetInt(ih, "SHOWDELETE");
  linedelete = IupGetIntId(ih, "LINEDELETE", lin);

  if (!active || !itemactive || !imageactive)
    make_inactive = 1;

  image_name = iupAttribGetId(ih, "IMAGE", lin);
  if (!image_name)
  {
    char* attrib_name;
    if (mtxList->editable)
    {
      if (lin == lines_num-1)
        attrib_name = "IMAGEADD";
      else
      {
        if (showdelete || linedelete)
          attrib_name = "IMAGEDEL";
        else
        {
          if (imagevalue)
            attrib_name = "IMAGECHECK";
          else
            attrib_name = "IMAGEUNCHECK";
        }
      }
    }
    else
    {
      if (imagevalue)
        attrib_name = "IMAGECHECK";
      else
        attrib_name = "IMAGEUNCHECK";
    }

    image_name = iupAttribGetStr(ih, attrib_name);  /* this will check for the default values also */
  }

  image = iupImageGetHandle(image_name);
  if (image)
  {
    int width  = IupGetInt(image, "WIDTH");
    int height = IupGetInt(image, "HEIGHT");

    long bgcolor = cdIupConvertColor(IupGetAttributeId2(ih, "CELLBGCOLOR", lin, col));

    /* Calc the image_name position */
    int x = x2 - x1 - width;
    int y = y1 - y2 - 1 - height;
    x /= 2; x += x1;
    y /= 2; y += y2;

    cdIupDrawImage(cnv, image, x, y, 0, 0, make_inactive, bgcolor);
  }

  return IUP_DEFAULT;  /* draw nothing more */
}