예제 #1
0
파일: iupmat_draw.c 프로젝트: sanikoyes/iup
static void iMatrixDrawDropFeedback(Ihandle* ih, int x2, int y1, int y2, int active, long framecolor)
{
  int xh2, yh2, x1;

  /* feedback area */
  iupMatrixDrawSetDropFeedbackArea(&x1, &y1, &x2, &y2);

  /* feedback background */
  iMatrixDrawSetBgColor(ih, 0, 0, 0, active);
  iupMATRIX_BOX(ih, x1, x2, y1, y2);

  /* feedback frame */
  cdCanvasForeground(ih->data->cd_canvas, framecolor);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);

  /* feedback arrow */
  xh2 = x2 - IMAT_DROPBOX_W/2;
  yh2 = y2 - (y2 - y1)/2;

  cdCanvasBegin(ih->data->cd_canvas, CD_FILL);
  iupMATRIX_VERTEX(ih, xh2, yh2 + 3);
  iupMATRIX_VERTEX(ih, xh2 + 4, yh2 - 1);
  iupMATRIX_VERTEX(ih, xh2 - 4, yh2 - 1);
  cdCanvasEnd(ih->data->cd_canvas);
}
예제 #2
0
파일: iupmat_draw.c 프로젝트: xushiwei/iup
static void iMatrixDrawComboFeedback(Ihandle* ih, int x2, int y1, int y2, int active, long framecolor)
{
    int xh2, yh2, x1;

    /* feedback area */
    x2 -= IMAT_PADDING_W/2 + IMAT_FRAME_W/2;
    x1  = x2 - IMAT_COMBOBOX_W;
    y1 += IMAT_PADDING_H/2 + IMAT_FRAME_H/2;
    y2 -= IMAT_PADDING_H/2 + IMAT_FRAME_H/2;

    /* feedback background */
    iMatrixDrawSetBgColor(ih, 0, 0, 0, active);
    iupMATRIX_BOX(ih, x1, x2, y1, y2);

    /* feedback frame */
    cdCanvasForeground(ih->data->cddbuffer, framecolor);
    iupMATRIX_RECT(ih, x1, x2, y1, y2);

    /* feedback arrow */
    xh2 = x2 - IMAT_COMBOBOX_W / 2;
    yh2 = y2 - (y2 - y1) / 2;

    cdCanvasBegin(ih->data->cddbuffer, CD_FILL);
    iupMATRIX_VERTEX(ih, xh2, yh2 + 3);
    iupMATRIX_VERTEX(ih, xh2 + 4, yh2 - 1);
    iupMATRIX_VERTEX(ih, xh2 - 4, yh2 - 1);
    cdCanvasEnd(ih->data->cddbuffer);
}
예제 #3
0
파일: iupmat_draw.c 프로젝트: sanikoyes/iup
static void iMatrixDrawBackground(Ihandle* ih, int x1, int x2, int y1, int y2, int marked, int active, int lin, int col)
{
  /* avoid drawing over the frame of the next cell */
  x2 -= IMAT_FRAME_W/2;
  y2 -= IMAT_FRAME_H/2;

  iMatrixDrawSetBgColor(ih, lin, col, marked, active);
  iupMATRIX_BOX(ih, x1, x2, y1, y2);
}
예제 #4
0
파일: iupmat_draw.c 프로젝트: sanikoyes/iup
static void iMatrixDrawColor(Ihandle* ih, int x1, int x2, int y1, int y2, int marked, int active, const char* color, long framecolor)
{    
  x1 += IMAT_PADDING_W/2 + IMAT_FRAME_H/2;
  x2 -= IMAT_PADDING_W/2 + IMAT_FRAME_W/2;
  y1 += IMAT_PADDING_H/2 + IMAT_FRAME_H/2;
  y2 -= IMAT_PADDING_H/2 + IMAT_FRAME_H/2;

  /* Fill the box with the color */
  iMatrixDrawSetTypeColor(ih, color, marked, active);
  iupMATRIX_BOX(ih, x1, x2, y1, y2);

  /* Draw the frame */
  cdCanvasForeground(ih->data->cd_canvas, framecolor);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);
}
예제 #5
0
파일: iupmat_draw.c 프로젝트: sanikoyes/iup
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);
}
예제 #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);
  }
}
예제 #7
0
파일: iupmat_draw.c 프로젝트: sanikoyes/iup
/* Redraw a block of cells of the matrix. Handle marked cells, change
   automatically the background color of them.
   - lin1, col1 : cell coordinates that mark the left top corner of the area to be redrawn
   - lin2, col2 : cell coordinates that mark the right bottom corner of the area to be redrawn */
void iupMatrixDrawCells(Ihandle* ih, int lin1, int col1, int lin2, int col2)
{
  int x1, y1, x2, y2, old_x2, old_y1, old_y2;
  int alignment, lin, col, active, first_col, first_lin;
  long framecolor, emptyarea_color = -1;
  IFnii mark_cb;
  IFnii dropcheck_cb;
  IFniiiiiiC draw_cb;

  x2 = ih->data->w-1;
  y2 = ih->data->h-1;

  old_x2 = x2;
  old_y1 = 0;
  old_y2 = y2;

  if (ih->data->lines.num <= 1 ||
      ih->data->columns.num <= 1)
    return;

  if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1)
  {
    first_col = 0;
    x1 = 0;
  }
  else
  {
    if (col1 > ih->data->columns.last ||
        col2 < ih->data->columns.first)
      return;

    if (col1 < ih->data->columns.first)
      col1 = ih->data->columns.first;
    if (col2 > ih->data->columns.last)
      col2 = ih->data->columns.last;

    first_col = ih->data->columns.first;
    x1 = 0;
    for (col = 0; col< ih->data->columns.num_noscroll; col++)
      x1 += ih->data->columns.dt[col].size;
  }

  if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1)
  {
    first_lin = 0;
    y1 = 0;
  }
  else
  {
    if (lin1 > ih->data->lines.last ||
        lin2 < ih->data->lines.first)
      return;

    if (lin1 < ih->data->lines.first)
      lin1 = ih->data->lines.first;
    if (lin2 > ih->data->lines.last)
      lin2 = ih->data->lines.last;

    first_lin = ih->data->lines.first;
    y1 = 0;
    for (lin = 0; lin< ih->data->lines.num_noscroll; lin++)
      y1 += ih->data->lines.dt[lin].size;
  }

  iupMATRIX_CLIPAREA(ih, x1, x2, y1, y2);
  cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF);  /* wait for background */

  /* Find the initial position of the first column */
  if (first_col==ih->data->columns.first)
    x1 -= ih->data->columns.first_offset;
  for(col = first_col; col < col1; col++)
    x1 += ih->data->columns.dt[col].size;

  /* Find the initial position of the first line */
  if (first_lin == ih->data->lines.first)
    y1 -= ih->data->lines.first_offset;
  for(lin = first_lin; lin < lin1; lin++)
    y1 += ih->data->lines.dt[lin].size;

  /* Find the final position of the last column */
  x2 = x1;
  for( ; col <= col2; col++)
    x2 += ih->data->columns.dt[col].size;

  /* Find the final position of the last line */
  y2 = y1;
  for( ; lin <= lin2; lin++)
    y2 += ih->data->lines.dt[lin].size;

  if ((col2 == ih->data->columns.num-1) && (old_x2 > x2))
  {
    emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
    cdCanvasForeground(ih->data->cd_canvas, emptyarea_color);

    /* If it was drawn until the last column and remains space in the right of it,
       then delete this area with the the background color. */
    iupMATRIX_BOX(ih, x2, old_x2, old_y1, old_y2);
  }

  if ((lin2 == ih->data->lines.num-1) && (old_y2 > y2))
  {
    if (emptyarea_color == -1)
      emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent);
    cdCanvasForeground(ih->data->cd_canvas, emptyarea_color);

    /* If it was drawn until the last line visible and remains space below it,
       then delete this area with the the background color. */
    iupMATRIX_BOX(ih, 0, old_x2, y2, old_y2);
  }

  /* after the background */
  cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA);

  /***** Draw the cell values and frame */
  old_y1 = y1;
  framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR"));
  active = iupdrvIsActive(ih);

  mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB");
  dropcheck_cb = (IFnii)IupGetCallback(ih, "DROPCHECK_CB");
  draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");

  for(col = col1; col <= col2; col++)  /* For all the columns in the region */
  {
    if (ih->data->columns.dt[col].size == 0)
      continue;

    alignment = iMatrixDrawGetColAlignment(ih, col);

    x2 = x1 + ih->data->columns.dt[col].size;

    for(lin = lin1; lin <= lin2; lin++)     /* For all lines in the region */
    {
      int drop = 0;
      int marked = 0;

      if (ih->data->lines.dt[lin].size == 0)
        continue;

      y2 = y1 + ih->data->lines.dt[lin].size;

      /* If the cell is marked, then draw it with attenuation color */
      marked = iupMatrixMarkCellGet(ih, lin, col, mark_cb);

      iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, col);

      iMatrixDrawFrameRectCell(ih, lin, col, x1, x2, y1, y2, framecolor);

      if (dropcheck_cb)
      {
        int ret = dropcheck_cb(ih, lin, col);
        if (ret == IUP_DEFAULT)
        {
          drop = IMAT_DROPBOX_W+IMAT_PADDING_W/2;
          iMatrixDrawDropFeedback(ih, x2, y1, y2, active, framecolor);
        }
        else if (ret == IUP_CONTINUE)
        {
          drop = IMAT_TOGGLE_SIZE + IMAT_PADDING_W;
          iMatrixDrawToggle(ih, x2, y1, y2, lin, col, marked, active);
        }
      }
        
      /* draw the cell contents */
      iMatrixDrawCellValue(ih, x1, x2-drop, y1, y2, alignment, marked, active, lin, col, draw_cb, framecolor);

      y1 = y2;
    }

    x1 = x2;
    y1 = old_y1;  /* must reset also y */
  }

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