Ejemplo n.º 1
0
static int iMatrixDrawCallDrawCB(Ihandle* ih, int lin, int col, int x1, int x2, int y1, int y2, IFniiiiiiC draw_cb)
{
  int ret;
  cdCanvas* old_cnv;

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

  old_cnv = cdActiveCanvas();
  if (old_cnv != ih->data->cd_canvas) /* backward compatibility code */
    cdActivate(ih->data->cd_canvas);

  ret = draw_cb(ih, lin, col, x1, x2, iupMATRIX_INVERTYAXIS(ih, y1), iupMATRIX_INVERTYAXIS(ih, y2), ih->data->cd_canvas);

  iMatrixDrawResetCellClipping(ih);

  if (old_cnv && old_cnv != ih->data->cd_canvas) /* backward compatibility code */
  {
    cdActivate(old_cnv);
    cdCanvasActivate(ih->data->cd_canvas);
  }

  if (ret == IUP_DEFAULT)
    return 0;

  return 1;
}
Ejemplo n.º 2
0
static int iMatrixDrawCallDrawCB(Ihandle* ih, int lin, int col, int x1, int x2, int y1, int y2, IFniiiiiiC draw_cb)
{
  int ret;
  cdCanvas* old_cnv;

  IUPMAT_CLIPAREA(ih, x1, x2, y1, y2);
  cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);

  old_cnv = cdActiveCanvas();
  if (old_cnv != ih->data->cddbuffer) /* backward compatibility code */
    cdActivate(ih->data->cddbuffer);

  ret = draw_cb(ih, lin, col, x1, x2, iupMatrixInvertYAxis(ih, y1), iupMatrixInvertYAxis(ih, y2), ih->data->cddbuffer);

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

  if (old_cnv && old_cnv != ih->data->cddbuffer) /* backward compatibility code */
  {
    cdActivate(old_cnv);
    cdCanvasActivate(ih->data->cddbuffer);
  }

  if (ret == IUP_DEFAULT)
    return 0;

  return 1;
}
Ejemplo n.º 3
0
Archivo: wdhdcpy.c Proyecto: LuaDist/cd
static void _wdHdcpyDoit(cdCanvas *canvas, cdCanvas *canvas_copy, void (*draw_func)(cdCanvas *canvas_copy))
{
  cdCanvas *old_active;
  double  left, right, bottom, top;   /* canvas visualization window       */
  int     canvas_hsize, canvas_vsize; /* canvas sizes in pixels            */
  int     hdcpy_hsize, hdcpy_vsize;   /* paper sizes in points             */
  double  canvas_vpr;                 /* canvas viewport distortion ratio  */
  double  hdcpy_vpr;                  /* paper viewport distortion ratio   */
  int     xc, yc;                     /* paper center in pixels            */
  int     xmin, xmax, ymin, ymax;     /* paper viewport                    */

  /* Activate canvas visualization surface. */
  if (cdCanvasActivate(canvas) != CD_OK) return;

  /* Get current canvas window parameters and sizes. */
  wdCanvasGetWindow(canvas, &left, &right, &bottom, &top);
  cdCanvasGetSize(canvas, &canvas_hsize, &canvas_vsize, 0L, 0L);

  /* Activate hardcopy visualization surface. */
  if (cdCanvasActivate(canvas_copy) != CD_OK) return;

  /* Set window parameters on hardcopy surface. */
  wdCanvasWindow(canvas_copy, left, right, bottom, top);

  /* Adjust paper viewport, centralized, matching canvas viewport. */
  canvas_vpr = (double)canvas_vsize / (double)canvas_hsize;
  cdCanvasGetSize(canvas_copy, &hdcpy_hsize, &hdcpy_vsize, 0L, 0L);
  hdcpy_vpr = (double)hdcpy_vsize / (double)hdcpy_hsize;
  xc = (int)((double)hdcpy_hsize/2.0);
  yc = (int)((double)hdcpy_vsize/2.0);

  if (canvas_vpr < hdcpy_vpr)
  {
    xmin = 0;
    xmax = hdcpy_hsize;
    ymin = yc - (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0);
    ymax = yc + (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0);
  }
  else
  {
    xmin = xc - (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0);
    xmax = xc + (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0);
    ymin = 0;
    ymax = hdcpy_vsize;
  }

  cdCanvasClipArea(canvas_copy, xmin, xmax, ymin, ymax);
  cdCanvasClip(canvas_copy, CD_CLIPAREA);
  wdCanvasViewport(canvas_copy, xmin, xmax, ymin, ymax);

  /* for backward compatibility */
  old_active = cdActiveCanvas();
  cdActivate(canvas_copy);

  /* Draw on hardcopy surface.  */
  draw_func(canvas_copy);

  if (old_active) cdActivate(old_active);
}
Ejemplo n.º 4
0
void cdKillCanvas(cdCanvas *canvas)
{
  assert(canvas);
  if (!_cdCheckCanvas(canvas)) return;

  if (canvas == cdActiveCanvas())
    cdActivate(NULL);
  else
    cdCanvasDeactivate(canvas);
  
  canvas->cxKillCanvas(canvas->ctxcanvas);

  if (canvas->pattern) free(canvas->pattern);
  if (canvas->stipple) free(canvas->stipple);
  if (canvas->poly) free(canvas->poly);
  if (canvas->clip_poly) free(canvas->clip_poly);
  if (canvas->fpoly) free(canvas->fpoly);
  if (canvas->clip_fpoly) free(canvas->clip_fpoly);
  if (canvas->line_dashes) free(canvas->line_dashes);
  if (canvas->path) free(canvas->path);

  cdKillVectorFont(canvas->vector_font);
  cdKillSimulation(canvas->simulation);

  memset(canvas, 0, sizeof(cdCanvas));
  free(canvas);
}
Ejemplo n.º 5
0
static int select_cb(Ihandle* ih, int cell, int type)
{
  long cd_color;
  char str[30];
  int ri, gi, bi;

  sprintf(str, "CELL%d", cell);
  sscanf(IupGetAttribute(ih, str), "%d %d %d", &ri, &gi, &bi);
  printf("select_cb(%d, %d): %d, %d, %d\n", cell, type, ri, gi, bi);

  cd_color = cdEncodeColor((unsigned char)ri,(unsigned char)gi,(unsigned char)bi);

  if (!cdcanvas)
    return IUP_DEFAULT;
  
  cdActivate( cdcanvas ) ;
  if (type == -1)
    cdForeground(cd_color);
  else
    cdBackground(cd_color);

  redraw_cb(canvas);

  return IUP_DEFAULT;
}
Ejemplo n.º 6
0
void main(void)
{
	cdCanvas *canvas;
	canvas = cdCreateCanvas(CD_METAFILE,"TESTE.MF 100x100");
	cdActivate(canvas);
	draw();
	cdKillCanvas(canvas);
}
Ejemplo n.º 7
0
static int iMatrixDrawCallDrawCB(Ihandle* ih, int cor, int lin, int col, int x1, int x2, int y1, int y2)
{
  IFniiiiiiC cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");
  if(cb)
  {
    int ret;

    cdCanvas* old_cnv = cdActiveCanvas();
    if(cor == IMAT_TITLE_COLOR)
    {
      x1+=1;
      x2-=1;
      y1+=1;
      y2-=1;
    }
    else if(!iupAttribGetInt(ih, "HIDEFOCUS"))
    {
      x1+=2;
      x2-=2;
      y1+=2;
      y2-=2;
    }

    CdClipArea(x1, x2, y1, y2);
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);

    if(old_cnv != ih->data->cddbuffer) /* backward compatibility code */
      cdActivate(ih->data->cddbuffer);

    ret = cb(ih, lin, col, x1, x2, (ih->data->YmaxC - (y1)), INVY(y2), ih->data->cddbuffer);

    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);
    if(old_cnv && old_cnv != ih->data->cddbuffer)
    {
      cdActivate(old_cnv);
      cdCanvasActivate(ih->data->cddbuffer);
    }

    if (ret == IUP_DEFAULT)
      return 0;
  }

  return 1;
}
Ejemplo n.º 8
0
int switch_cb(Ihandle* self, int primcell, int seccell)
{
    long fgcolor;
    cdActivate(cdcanvas);
    fgcolor = cdForeground(CD_QUERY);
    cdForeground(cdBackground(CD_QUERY));
    cdBackground(fgcolor);
    redraw_cb(cnvs);
    return IUP_DEFAULT;
}
Ejemplo n.º 9
0
/* Function used to call the client; is used when a cell must be repainted. */
static void iCellsCallDrawCb(Ihandle* ih, int xmin, int xmax, int ymin, int ymax, int i, int j)
{
  int oldxmin, oldxmax, oldymin, oldymax, oldclip;
  int w = ih->data->w;
  int h = ih->data->h;
  IFniiiiiiC draw_cb;
  cdCanvas* old_cnv = cdActiveCanvas();

  /* Getting clipping area for post restore */
  oldclip = cdCanvasClip(ih->data->cd_canvas, CD_QUERY);
  cdCanvasGetClipArea(ih->data->cd_canvas, &oldxmin, &oldxmax, &oldymin, &oldymax);

  if (ih->data->clipped)  /* Clipping the cell area */
  { 
    int cxmin, cxmax, cymin, cymax;
    cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA);
    cxmin = xmin < 0 ? 0 : xmin;
    cymin = ymin < 0 ? 0 : ymin;
    cxmax = xmax > w ? w : xmax;
    cymax = ymax > h ? h : ymax;
    cdCanvasClipArea(ih->data->cd_canvas, cxmin, cxmax, cymin, cymax);
  }

  draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB");
  if (draw_cb)
  {
    if (old_cnv != ih->data->cd_canvas) /* backward compatibility code */
      cdActivate(ih->data->cd_canvas);

    draw_cb(ih, i, j, xmin, xmax, ymin, ymax, ih->data->cd_canvas);

    if (old_cnv && old_cnv != ih->data->cd_canvas)
    {
      cdActivate(old_cnv);
      cdCanvasActivate(ih->data->cd_canvas);
    }
  }

  cdCanvasClip(ih->data->cd_canvas, oldclip);
  cdCanvasClipArea(ih->data->cd_canvas, oldxmin, oldxmax, oldymin, oldymax);
}
Ejemplo n.º 10
0
/** 
 * Function used to call the client; is used when a cell must be repainted.
 */
static void call_apl_draw(TCells* obj, int xmin, int xmax, 
int ymin, int ymax, int i, int j) {
  int cxmin, cxmax, cymin, cymax;
  int oldxmin, oldxmax, oldymin, oldymax;
  int w = obj->width;
  int h = obj->height;

  /* Getting clipping area for post restore */
  int oldclip = cdCanvasClip(obj->cddbuffer,CD_QUERY);
  cdCanvasGetClipArea(obj->cddbuffer,&oldxmin, &oldxmax, &oldymin, &oldymax);

  /* Clipoing the cell area */
  if (obj->clipped) { 
     cdCanvasClip(obj->cddbuffer, CD_CLIPAREA);
     cxmin = xmin < 0 ? 0 : xmin;
     cymin = ymin < 0 ? 0 : ymin;
     cxmax = xmax > w ? w : xmax;
     cymax = ymax > h ? h : ymax;
     cdCanvasClipArea(obj->cddbuffer, xmin, xmax, ymin, ymax);
  }

  /* Calling the application draw callback. */
  { 
     TDrawCb func = (TDrawCb)IupGetCallback(obj->self, IUP_DRAW_CB);
     if (func)
     {
       cdCanvas* old_cnv = cdActiveCanvas();
       if (old_cnv != obj->cddbuffer) /* backward compatibility code */
       cdActivate(obj->cddbuffer);

       func(obj->self, i, j, xmin, xmax, ymin, ymax, obj->cddbuffer);

       if (old_cnv != obj->cddbuffer)
         cdActivate(old_cnv);
     }
  }

  /* Restoring clipping attributes */
  cdCanvasClip(obj->cddbuffer,oldclip);
  cdCanvasClipArea(obj->cddbuffer, oldxmin, oldxmax, oldymin, oldymax);
}
Ejemplo n.º 11
0
static int switch_cb(Ihandle* ih, int primcell, int seccell)
{
  long fgcolor;
  if (!cdcanvas)
    return IUP_DEFAULT;
  printf("switch_cb(%d, %d)\n", primcell, seccell);
  cdActivate(cdcanvas) ;
  fgcolor = cdForeground(CD_QUERY);
  cdForeground(cdBackground(CD_QUERY));
  cdBackground(fgcolor);
  redraw_cb(canvas);
  return IUP_DEFAULT;
}
Ejemplo n.º 12
0
int redraw_cb( Ihandle *self)
{
    if (!cdcanvas) return IUP_DEFAULT;

    /* Activates canvas cdcanvas */
    cdActivate( cdcanvas );
    cdClear();

    /* Draws a rectangle on the canvas */
    cdBegin(CD_FILL);
    cdVertex(50, 50);
    cdVertex(150, 50);
    cdVertex(100, 150);
    cdEnd();

    /* Function executed successfully */
    return IUP_DEFAULT;
}
Ejemplo n.º 13
0
int select_cb(Ihandle* self, int cell, int type)
{
    long cd_color;
    char str[30];
    int ri, gi, bi;
    sprintf(str, "CELL%d", cell);
    sscanf(IupGetAttribute(self, str), "%d %d %d", &ri, &gi, &bi);
    cd_color = cdEncodeColor((unsigned char)ri,(unsigned char)gi,(unsigned char)bi);

    cdActivate( cdcanvas );
    if (type == IUP_PRIMARY)
        cdForeground(cd_color);
    else
        cdBackground(cd_color);

    redraw_cb(cnvs);

    return IUP_DEFAULT;
}
Ejemplo n.º 14
0
//void SimpleDrawTest(cdCanvas* canvas)
void SimpleDrawTestImageRGB(cdCanvas* canvas)
{
  int size = 2048*2048;
  unsigned char *red, *green, *blue;
  cdCanvas* canvas = cdCreateCanvas(CD_IMAGERGB, "2048x2048");
  cdActivate(canvas);

  red = calloc(size, 1);
  green = calloc(size, 1);
  blue = calloc(size, 1);

  cdPutImageRectRGB(2048, 2048, red, green, blue, 0, 3, 2048, 2017, 0, 2047, 3, 2020);

  free(red);
  free(green);
  free(blue);

  cdKillCanvas(canvas);
}
Ejemplo n.º 15
0
char* cell_cb(Ihandle* self, int cell)
{
    unsigned char r, g, b;
    int ri, gi, bi;
    static char str[30];
    sprintf(str, "CELL%d", cell);
    sscanf(IupGetAttribute(self, str), "%d %d %d", &ri, &gi, &bi);
    r = (unsigned char)ri;
    g = (unsigned char)gi;
    b = (unsigned char)bi;
    if (IupGetColor(IUP_MOUSEPOS, IUP_MOUSEPOS, &r, &g, &b))
    {
        sprintf(str, "%d %d %d", (int)r, (int)g, (int)b);
        cdActivate( cdcanvas );
        cdForeground(cdEncodeColor(r, g, b));
        redraw_cb(cnvs);
        return str;
    }
    return NULL;
}