コード例 #1
0
ファイル: iupmat_draw.c プロジェクト: sanikoyes/iup
/* Put the cell contents in the screen, using the specified color and alignment.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_ALIGN_CENTER,IMAT_ALIGN_LEFT,IMAT_ALIGN_RIGHT]
   -> marked : mark state
   -> lin, col - cell coordinates */
static void iMatrixDrawCellValue(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, IFniiiiiiC draw_cb, long framecolor)
{
  char *value;

  /* avoid drawing over the frame of the next cell */
  x2 -= IMAT_FRAME_W/2;
  y2 -= IMAT_FRAME_H/2;

  /* avoid drawing over the frame of the cell */
  x2 -= IMAT_FRAME_W/2;
  y2 -= IMAT_FRAME_H/2;

  if (lin==0 || col==0)
  {
    /* avoid drawing over the frame of the cell */
    x1 += IMAT_FRAME_W/2;
    y1 += IMAT_FRAME_H/2;

    if (col==0) x1 += IMAT_FRAME_W/2;
    if (lin==0) y1 += IMAT_FRAME_H/2;
  }
  else if ((col==1 && ih->data->columns.dt[0].size == 0) || (lin==1 && ih->data->lines.dt[0].size == 0))
  {
    /* avoid drawing over the frame of the cell */
    x1 += IMAT_FRAME_W/2;
    y1 += IMAT_FRAME_H/2;
  }

  if (draw_cb && !iMatrixDrawCallDrawCB(ih, lin, col, x1, x2, y1, y2, draw_cb))
    return;

  value = iupMatrixGetValueDisplay(ih, lin, col);

  /* Put the text */
  if (value && *value)
  {
    int type = iupMatrixGetType(ih, lin, col);
    if (type == IMAT_TYPE_TEXT)
      iMatrixDrawText(ih, x1, x2, y1, y2, alignment, marked, active, lin, col, value);
    else if (type == IMAT_TYPE_COLOR)
      iMatrixDrawColor(ih, x1, x2, y1, y2, marked, active, value, framecolor);
    else if (type == IMAT_TYPE_FILL)
      iMatrixDrawFill(ih, x1, x2, y1, y2, marked, active, lin, col, value, framecolor);
    else if (type == IMAT_TYPE_IMAGE)
      iMatrixDrawImage(ih, x1, x2, y1, y2, alignment, marked, active, lin, col, value);
  }
}
コード例 #2
0
ファイル: iupmat_draw.c プロジェクト: svn2github/iup-iup
/* Put a text in the screen, using the specified color and alignment.
   Receive the size of cell and also the visible part of the cell,
   because need to clip with this visible part and calculate, correctly,
   the center position and right margin of the cell, using the entire
   size of it.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> xc : point where the text is clipped
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT]
   -> cor : color schema that will be used:
           IMAT_TITLE_COLOR  ->  Black letters in gray background (for the titles)
           IMAT_ELEM_COLOR    -> Letters with FGCOLOR and background with BGCOLOR
           IMAT_REVERSE_COLOR -> Letters with BGCOLOR and background with FGCOLOR
   -> lin, col - cell coordinates, in IUP format - i.e., l,l represents the left
                 top cell of the matrix; lin and col values = 0 represents the
                 title lines and columns.
*/
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, char *text, int alignment, int xc, int cor, int lin, int col)
{
  int oldbgc = -1;
  int ypos;

  int oldx1 = x1,                  /* Full limit of the cell,     */
      oldx2 = x2 - 1,              /* considering the decorations */
      oldy1 = y1,
      oldy2 = y2,
      oldxc = xc;

  /* Create an space between text and cell margin */
  x1 += IMAT_DECOR_X / 2;       x2 -= IMAT_DECOR_X / 2;       xc -= IMAT_DECOR_X / 2;          
  y1 += IMAT_DECOR_Y / 2;       y2 -= IMAT_DECOR_Y / 2;

  /* Clear the cell */
  if(cor == IMAT_TITLE_COLOR)
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0);
    CdBox(oldx1 + 2, oldxc - 2, oldy1 + 2, oldy2 - 2); /* Clear cell box, considering the xc */
  }
  else if(cor == IMAT_ELEM_COLOR)
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0);
    CdBox(oldx1, oldx2, oldy1, oldy2); /* Clear cell box */
  }
  else
  {
    oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 1);
    /* Clear the text box, with the attenuated color... */
    CdBox(oldx1, oldx2, oldy1, oldy2);
    iMatrixDrawSetFgColor(ih, lin, col, 1);
  }

  if(!iMatrixDrawCallDrawCB(ih, cor, lin, col, oldx1, oldx2, oldy1, oldy2))
    return;

  /* Put the text */
  if(text && *text)
  {
    int numl;
    int lineh, totalh, spacing;

    /* Set the clip area to the cell region informed */
    CdClipArea(x1, xc, oldy1, oldy2);
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);

    /* Set the color used to draw the text */
    if((lin > 0 && ih->data->lin.inactive[lin-1]) ||
       (col > 0 && ih->data->col.inactive[col-1]) ||
       !IupGetInt(ih, "ACTIVE"))
      cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_COLOR);
    else if(cor == IMAT_ELEM_COLOR)
      iMatrixDrawSetFgColor(ih, lin, col, 0);
    else if(cor == IMAT_REVERSE_COLOR)
      oldbgc = iMatrixDrawSetFgColor(ih, lin, col, 1);
    else
      iMatrixDrawSetFgColor(ih, lin, col, 0);

    numl = iupMatrixAuxTextHeight(ih, text, &totalh, &lineh, &spacing);

    iMatrixDrawSetFont(ih, lin, col);

    if(numl == 1)
    {
      ypos = (int)((y1 + y2) / 2.0 - .5);

      /* Put the text */
      if(alignment == IMAT_T_CENTER)
        CdPutText((x1 + x2) / 2, ypos, text, CD_CENTER);
      else if(alignment == IMAT_T_LEFT)
        CdPutText(x1, ypos, text, CD_WEST);
      else
        CdPutText(x2, ypos, text, CD_EAST);
    }
    else
    {
      int   i;
      char *p, *q, *newtext = NULL;

      if(text != NULL)
      {
        p = (char*) iupStrDup(text);
        newtext = p;
      }
      else
        p = NULL;

      /* Get the position of the first text to be put in the screen */
      ypos = (int)( (y1 + y2) / 2.0 - .5) - totalh / 2 + lineh / 2;
      for(i = 0; i < numl; i++)
      {
        q = strchr(p, '\n');
        if(q)
          *q = 0;  /* Cut the string to contain a line */

        /* Put the text */
        if(alignment == IMAT_T_CENTER)
          CdPutText((x1 + x2) / 2, ypos, p, CD_CENTER);
        else if(alignment == IMAT_T_LEFT)
          CdPutText(x1, ypos, p, CD_WEST);
        else
          CdPutText(x2, ypos, p, CD_EAST);

        if(q)
          *q = '\n'; /* Restore the string */
        p = q + 1;

        /* Advance a line */
        ypos += lineh + spacing;
      }

      if(newtext)
        free(newtext);
    }

    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);
  }

  if(cor != IMAT_TITLE_COLOR)
    CdRestoreBgColor();
}
コード例 #3
0
ファイル: iupmat_draw.c プロジェクト: xushiwei/iup
/* Put the cell contents in the screen, using the specified color and alignment.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT]
   -> marked : mark state
   -> lin, col - cell coordinates */
static void iMatrixDrawCellValue(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, IFniiiiiiC draw_cb)
{
    char *text;

    /* avoid drawing over the frame of the next cell */
    x2 -= IMAT_FRAME_W/2;
    y2 -= IMAT_FRAME_H/2;

    /* avoid drawing over the frame of the cell */
    x2 -= IMAT_FRAME_W/2;
    y2 -= IMAT_FRAME_H/2;

    if (lin==0 || col==0)
    {
        /* avoid drawing over the frame of the cell */
        x1 += IMAT_FRAME_W/2;
        y1 += IMAT_FRAME_H/2;

        if (col==0) x1 += IMAT_FRAME_W/2;
        if (lin==0) y1 += IMAT_FRAME_H/2;
    }
    else if ((col==1 && ih->data->columns.sizes[0] == 0) || (lin==1 && ih->data->lines.sizes[0] == 0))
    {
        /* avoid drawing over the frame of the cell */
        x1 += IMAT_FRAME_W/2;
        y1 += IMAT_FRAME_H/2;
    }

    if (draw_cb && !iMatrixDrawCallDrawCB(ih, lin, col, x1, x2, y1, y2, draw_cb))
        return;

    text = iupMatrixCellGetValue(ih, lin, col);

    /* Put the text */
    if (text && *text)
    {
        int num_line, line_height, total_height;
        int charheight, ypos, hidden_text_marks = 0;

        num_line = iupStrLineCount(text);
        iupdrvFontGetCharSize(ih, NULL, &charheight);

        line_height  = charheight;
        total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2;

        if (lin==0 || ih->data->hidden_text_marks)
        {
            int text_w;
            iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL);
            if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W)
            {
                if (lin == 0)
                    alignment = IMAT_T_LEFT;

                if (ih->data->hidden_text_marks)
                    hidden_text_marks = 1;
            }
        }

        /* Set the color used to draw the text */
        if (!active)
            cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_FGCOLOR);
        else
            iMatrixDrawSetFgColor(ih, lin, col, marked);

        /* Set the clip area to the cell region informed, the text maybe greatter than the cell */
        if (hidden_text_marks)
        {
            int crop = iupdrvFontGetStringWidth(ih, "...") + 2;
            iMatrixDrawSetCellClipping(ih, x1, x2-crop, y1, y2);
        }
        else
            iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

        cdCanvasNativeFont(ih->data->cddbuffer, iupMatrixGetFont(ih, lin, col));

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

        if (alignment == IMAT_T_CENTER)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER);
        else if(alignment == IMAT_T_LEFT)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_WEST);
        else
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);

        if (num_line == 1)
        {
            ypos = (int)((y1 + y2) / 2.0 - 0.5);

            /* Put the text */
            if (alignment == IMAT_T_CENTER)
                iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, text);
            else if(alignment == IMAT_T_LEFT)
                iupMATRIX_TEXT(ih, x1, ypos, text);
            else
                iupMATRIX_TEXT(ih, x2, ypos, text);
        }
        else
        {
            int i;
            char *p, *q, *newtext;

            newtext = iupStrDup(text);
            p = newtext;

            /* Get the position of the first text to be put in the screen */
            ypos = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2;

            for(i = 0; i < num_line; i++)
            {
                q = strchr(p, '\n');
                if (q) *q = 0;  /* Cut the string to contain only one line */

                /* Draw the text */
                if(alignment == IMAT_T_CENTER)
                    iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, p);
                else if(alignment == IMAT_T_LEFT)
                    iupMATRIX_TEXT(ih, x1, ypos, p);
                else
                    iupMATRIX_TEXT(ih, x2, ypos, p);

                /* Advance the string */
                if (q) p = q + 1;

                /* Advance a line */
                ypos += line_height + IMAT_PADDING_H/2;
            }

            free(newtext);
        }

        iMatrixDrawResetCellClipping(ih);

        if (hidden_text_marks)
        {
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);
            ypos = (int)((y1 + y2) / 2.0 - 0.5);
            iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, ypos, "...");
        }
    }
}