Ejemplo n.º 1
0
static void iMatrixDrawSort(Ihandle* ih, int x2, int y1, int y2, int xc, int lin, int col, char* sort)
{
  int yc;

  /* Create an space between text and cell margin */
  x2 -= IMAT_DECOR_X / 2;       xc -= IMAT_DECOR_X / 2;

  /* 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
    iMatrixDrawSetFgColor(ih, lin, col, 0);

  yc = (int)( (y1 + y2 ) / 2.0 - .5);

  cdCanvasBegin(ih->data->cddbuffer, CD_FILL);

  if(iupStrEqualNoCase(sort, "UP"))
  {
    CdVertex(x2 - 5, yc + 2);
    CdVertex(x2 - 1, yc - 2);
    CdVertex(x2 - 9, yc - 2);
  }
  else
  {
    CdVertex(x2 - 1, yc + 2);
    CdVertex(x2 - 9, yc + 2);
    CdVertex(x2 - 5, yc - 2);
  }

  cdCanvasEnd(ih->data->cddbuffer);
}
Ejemplo n.º 2
0
static int iMatrixDrawSortSign(Ihandle* ih, int x2, int y1, int y2, int col, int active)
{
  int yc;
  char* sort = iupAttribGetId(ih, "SORTSIGN", col);
  if (!sort || iupStrEqualNoCase(sort, "NO"))
    return 0;

  /* Remove the space between text and cell frame */
  x2 -= IMAT_PADDING_W/2 + IMAT_FRAME_W/2;

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, 0, col, 0, active);

  yc = (int)( (y1 + y2 ) / 2.0 - .5);

  cdCanvasBegin(ih->data->cd_canvas, CD_FILL);

  if (iupStrEqualNoCase(sort, "DOWN"))
  {
    iupMATRIX_VERTEX(ih, x2 - 5, yc + 2);
    iupMATRIX_VERTEX(ih, x2 - 1, yc - 2);
    iupMATRIX_VERTEX(ih, x2 - 9, yc - 2);
  }
  else  /* UP */
  {
    iupMATRIX_VERTEX(ih, x2 - 1, yc + 2);
    iupMATRIX_VERTEX(ih, x2 - 9, yc + 2);
    iupMATRIX_VERTEX(ih, x2 - 5, yc - 2);
  }

  cdCanvasEnd(ih->data->cd_canvas);
  return 1;
}
Ejemplo n.º 3
0
/* Draw the representation of a cell that have the focus, for cells that
   are not in the edit mode
   -> lin, col : the cell
   -> set: 1 to put the draw of the focus
           0 to remove the draw
*/
void iupMatrixDrawFocus(Ihandle* ih, int lin, int col, int set)
{
  int x1, y1, x2, y2, dx, dy, oldbgc;

  if(iupAttribGetInt(ih, "HIDEFOCUS"))
    return;

  if(!iupMatrixAuxGetCellDim(ih, lin, col, &x1, &y1, &dx, &dy))
    return;

  ih->data->redraw = 1;

  if(set)          /* put the draw of the focus */
    oldbgc = iMatrixDrawSetFgColor(ih, lin+1, col+1, iupMatrixMarkCellGet(ih, lin, col));
  else                /* remove the draw of the focus */
    oldbgc = iMatrixDrawSetBgColor(ih, lin+1, col+1, IMAT_ELEM_COLOR, iupMatrixMarkCellGet(ih, lin, col));

  x2 = x1 + dx - 1;
  y2 = y1 + dy - 1;

  CdRect(x1, x2, y1, y2);
  CdRect(x1+1, x2-1, y1+1, y2-1);
  
  CdRestoreBgColor();
}
Ejemplo n.º 4
0
static void iMatrixDrawFill(Ihandle* ih, int x1, int x2, int y1, int y2, int marked, int active, int lin, int col, const char* value, long framecolor)
{    
  int empty, fill=0;

  iupStrToInt(value, &fill);
  if (fill < 0) fill = 0;
  if (fill > 100) fill = 100;

  /* 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;

  empty = ((x2-x1)*(100-fill))/100;

  /* Fill the box with the color */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);
  iupMATRIX_BOX(ih, x1, x2 - empty, y1, y2);

  if (ih->data->show_fill_value)
  {
    int y = (int)((y1 + y2) / 2.0 - 0.5);
    int empty1 = ((x2-x1)*fill)/100;
    char text[50];
    sprintf(text, "%d%%", fill);
    IupCdSetFont(ih, ih->data->cd_canvas, iupMatrixGetFont(ih, lin, col));
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_CENTER);

    iMatrixDrawSetCellClipping(ih, x1 + empty1, x2, y1, y2);
    iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    iMatrixDrawResetCellClipping(ih);

    iMatrixDrawSetBgColor(ih, lin, col, marked, active);
    iMatrixDrawSetCellClipping(ih, x1, x2 - empty, y1, y2);
    iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    iMatrixDrawResetCellClipping(ih);
  }


  /* Draw the frame */
  cdCanvasForeground(ih->data->cd_canvas, framecolor);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);
}
Ejemplo n.º 5
0
static int iMatrixDrawSortSign(Ihandle* ih, int x2, int y1, int y2, int col, int active, char* str)
{
    int yc;
    char* sort;

    sprintf(str, "SORTSIGN%d", col);
    sort = iupAttribGet(ih, str);
    if (!sort || iupStrEqualNoCase(sort, "NO"))
        return 0;

    /* Remove the space between text and cell frame */
    x2 -= IMAT_PADDING_W/2 + IMAT_FRAME_W/2;

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

    yc = (int)( (y1 + y2 ) / 2.0 - .5);

    cdCanvasBegin(ih->data->cddbuffer, CD_FILL);

    if (iupStrEqualNoCase(sort, "DOWN"))
    {
        iupMATRIX_VERTEX(ih, x2 - 5, yc + 2);
        iupMATRIX_VERTEX(ih, x2 - 1, yc - 2);
        iupMATRIX_VERTEX(ih, x2 - 9, yc - 2);
    }
    else
    {
        iupMATRIX_VERTEX(ih, x2 - 1, yc + 2);
        iupMATRIX_VERTEX(ih, x2 - 9, yc + 2);
        iupMATRIX_VERTEX(ih, x2 - 5, yc - 2);
    }

    cdCanvasEnd(ih->data->cddbuffer);
    return 1;
}
Ejemplo n.º 6
0
static void iMatrixDrawToggle(Ihandle* ih, int x2, int y1, int y2, int lin, int col, int marked, int active)
{
  int x1;
  long bgcolor = ih->data->bgcolor_cd;

  /* toggle area */
  iupMatrixDrawSetToggleArea(&x1, &y1, &x2, &y2);

  /* toggle background */
  if (marked)
  {
    unsigned char bg_r, bg_g, bg_b;
    cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);
    bg_r = IMAT_ATENUATION(bg_r);
    bg_g = IMAT_ATENUATION(bg_g);
    bg_b = IMAT_ATENUATION(bg_b);
    bgcolor = cdEncodeColor(bg_r, bg_g, bg_b);
  }
  cdCanvasForeground(ih->data->cd_canvas, bgcolor);
  iupMATRIX_BOX(ih, x1, x2, y1, y2);

  /* toggle frame */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);

  /* toggle check */
  if (iupAttribGetIntId2(ih, "TOGGLEVALUE", lin, col))
  {
    int half = IMAT_TOGGLE_SIZE/2;
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 2, x1 + half - 2 + 6, y2 - 2 - 6);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 3, x1 + half - 2 + 6, y2 - 3 - 6);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 4, x1 + half - 2 + 5, y2 - 4 - 5);

    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 2, x1 + half - 2 - 2, y2 - 2 - 2);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 3, x1 + half - 2 - 2, y2 - 3 - 2);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 4, x1 + half - 2 - 1, y2 - 4 - 1);
  }
}
Ejemplo n.º 7
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, const char* text)
{
  int num_line, line_height, total_height;
  int charheight, y, 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_ALIGN_LEFT;

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

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);

  /* 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);

  IupCdSetFont(ih, ih->data->cd_canvas, 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_ALIGN_CENTER)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_CENTER);
  else if(alignment == IMAT_ALIGN_LEFT)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_WEST);
  else  /* RIGHT */
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);

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

    /* Put the text */
    if (alignment == IMAT_ALIGN_CENTER)
      iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    else if(alignment == IMAT_ALIGN_LEFT)
      iupMATRIX_TEXT(ih, x1, y, text);
    else  /* RIGHT */
      iupMATRIX_TEXT(ih, x2, y, 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 */
    y = (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_ALIGN_CENTER)
        iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, p);
      else if(alignment == IMAT_ALIGN_LEFT)
        iupMATRIX_TEXT(ih, x1, y, p);
      else  /* RIGHT */
        iupMATRIX_TEXT(ih, x2, y, p);

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

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

    free(newtext);
  }

  iMatrixDrawResetCellClipping(ih);

  if (hidden_text_marks)
  {
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);
    y = (int)((y1 + y2) / 2.0 - 0.5);
    iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, y, "...");
  }
}
Ejemplo n.º 8
0
/* 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();
}
Ejemplo n.º 9
0
static unsigned long iMatrixDrawSetTitleFgColor(Ihandle* ih, int lin, int col)
{
  return iMatrixDrawSetFgColor(ih, lin, col, 0);
}
Ejemplo n.º 10
0
/* 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, "...");
        }
    }
}
Ejemplo n.º 11
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int col_alignment, int lin_alignment, int marked, int active, int lin, int col, const char* text)
{
  int text_alignment;
  int charheight, x, y, hidden_text_marks = 0;

  iupdrvFontGetCharSize(ih, NULL, &charheight);

  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)
        col_alignment = IMAT_ALIGN_START;

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

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);

  /* Set the clip area to the cell region informed, the text maybe greater 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);

  IupCdSetFont(ih, ih->data->cd_canvas, 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;

  iMatrixGetCellAlign(ih, lin, col, &col_alignment, &lin_alignment);

  if (lin_alignment == IMAT_ALIGN_CENTER)
  {
    y = iupROUND((y1 + y2) / 2.0);

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_CENTER;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_EAST;
    }
  }
  else if (lin_alignment == IMAT_ALIGN_START)
  {
    y = y1;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_NORTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_NORTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_NORTH_EAST;
    }
  }
  else /* lin_alignment == IMAT_ALIGN_END */
  {
    y = y2;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_SOUTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_SOUTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_SOUTH_EAST;
    }
  }

  cdCanvasTextAlignment(ih->data->cd_canvas, text_alignment);
  iupMATRIX_TEXT(ih, x, y, text);

  iMatrixDrawResetCellClipping(ih);

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