Example #1
0
void SimpleDraw(cdCanvas* canvas)
{
#ifdef USE_OPENGL
  if (use_opengl)
    SimpleUpdateSize(canvas);
#endif

  /* refresh CD canvas size, when window size has changed */
  cdCanvasActivate(canvas);

  if (simple_draw == DRAW_TEXTFONTS)
    SimpleDrawTextFonts(canvas);
  else if (simple_draw == DRAW_TEXTALIGN)
    SimpleDrawTextAlign(canvas);
  else if (simple_draw == DRAW_TEST)
    SimpleDrawTest(canvas);
  else
    SimpleDrawAll(canvas);

  /* Adds a new page, or 
     flushes the file, or
     flushes the screen, or
     swap the double buffer. */
  cdCanvasFlush(canvas);

#ifdef USE_OPENGL
  if (use_opengl)
    SimpleFlush();
#endif
}
Example #2
0
/* This callback is called when some action is performed on the
   scrollbar.
   -> action : type of action that call the event.
   -> x,y    : scrollbar thumb positions, value between 0 and 1
*/
int iupMatrixScrollCB(Ihandle* ih, int action, float x, float y)
{
  int err;

  x = IupGetFloat(ih, "POSX");
  y = IupGetFloat(ih, "POSY");

  IsCanvasSet(ih, err);
  if(err == CD_OK)
  {
    switch(action)
    {
      case IUP_SBUP      : ScrollUp(ih);       break;
      case IUP_SBDN      : ScrollDown(ih);     break;
      case IUP_SBPGUP    : ScrollPgUp(ih);     break;
      case IUP_SBPGDN    : ScrollPgDown(ih);   break;
      case IUP_SBRIGHT   : ScrollRight(ih);    break;
      case IUP_SBLEFT    : ScrollLeft(ih);     break;
      case IUP_SBPGRIGHT : ScrollPgRight(ih);  break;
      case IUP_SBPGLEFT  : ScrollPgLeft(ih);   break;
      case IUP_SBPOSV    : ScrollPosVer(ih,y); break;
      case IUP_SBPOSH    : ScrollPosHor(ih,x); break;
      case IUP_SBDRAGV   : ScrollPosVer(ih,y); break;
      case IUP_SBDRAGH   : ScrollPosHor(ih,x); break;
    }
  }

  {
    cdCanvasFlush(ih->data->cddbuffer);
    ih->data->redraw = 0;
  } /* always update */

  return IUP_DEFAULT;
}
Example #3
0
void iupMatrixDrawUpdate(Ihandle* ih)
{
    cdCanvasFlush(ih->data->cddbuffer);

    if (ih->data->has_focus)
        iMatrixDrawFocus(ih);
}
Example #4
0
int canvas_action_cb(Ihandle* canvas)
{
  int x, y, canvas_width, canvas_height;
  unsigned int ri, gi, bi;
  imImage* image;
  cdCanvas* cd_canvas = (cdCanvas*)IupGetAttribute(canvas, "cdCanvas");
  Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG");
  const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255");

  IupGetIntInt(canvas, "DRAWSIZE", &canvas_width, &canvas_height);

  cdCanvasActivate(cd_canvas);

  /* draw the background */
  sscanf(background, "%u %u %u", &ri, &gi, &bi);
  cdCanvasBackground(cd_canvas, cdEncodeColor((unsigned char)ri, (unsigned char)gi, (unsigned char)bi));
  cdCanvasClear(cd_canvas);

  /* draw the image at the center of the canvas */
  image = (imImage*)IupGetAttribute(canvas, "IMAGE");
  if (image)
  {
    int view_width, view_height;
    Ihandle* zoom_val = IupGetDialogChild(canvas, "ZOOMVAL");
    double zoom_index = IupGetDouble(zoom_val, "VALUE");
    double zoom_factor = pow(2, zoom_index);

    float posy = IupGetFloat(canvas, "POSY");
    float posx = IupGetFloat(canvas, "POSX");

    view_width = (int)(zoom_factor * image->width);
    view_height = (int)(zoom_factor * image->height);

    if (canvas_width < view_width)
      x = (int)floor(-posx*view_width);
    else
      x = (canvas_width - view_width) / 2;

    if (canvas_height < view_height)
    {
      /* posy is top-bottom, CD is bottom-top.
         invert posy reference (YMAX-DY - POSY) */
      float dy = IupGetFloat(canvas, "DY");
      posy = 1.0f - dy - posy;
      y = (int)floor(-posy*view_height);
    }
    else
      y = (canvas_height - view_height) / 2;

    /* black line around the image */
    cdCanvasForeground(cd_canvas, CD_BLACK);
    cdCanvasRect(cd_canvas, x - 1, x + view_width, y - 1, y + view_height);

    imcdCanvasPutImage(cd_canvas, image, x, y, view_width, view_height, 0, 0, 0, 0);
  }

  cdCanvasFlush(cd_canvas);
  return IUP_DEFAULT;
}
Example #5
0
static int iCellsRedraw_CB(Ihandle* ih)
{
  if (!ih->data->cd_canvas)
    return IUP_DEFAULT;

  /* update display */
  cdCanvasFlush(ih->data->cd_canvas);
  return IUP_DEFAULT;
}
Example #6
0
static int iGaugeRedraw_CB(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return IUP_DEFAULT;

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  return IUP_DEFAULT;
}
Example #7
0
void iupMatrixDrawUpdate(Ihandle* ih)
{
  cdCanvasFlush(ih->data->cd_canvas);

  if (ih->data->has_focus)
    iMatrixDrawFocus(ih);

  if (!ih->data->edit_hide_onfocus && ih->data->editing)
    IupUpdate(ih->data->datah);
}
Example #8
0
static void iGaugeRepaint(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return;

  /* update render */
  iGaugeDrawGauge(ih);

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
}
Example #9
0
static int iColorbarRedraw_CB(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return IUP_DEFAULT;

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  if (ih->data->has_focus)
    iColorbarDrawFocusCell(ih);

  return IUP_DEFAULT;
}
Example #10
0
static int iDialRedraw_CB(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return IUP_DEFAULT;

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  if (ih->data->has_focus)
    IupCdDrawFocusRect(ih, ih->data->cdcanvas, 0, 0, ih->data->w-1, ih->data->h-1);

  return IUP_DEFAULT;
}
Example #11
0
static int iColorbarFocus_CB(Ihandle* ih, int focus)
{
  ih->data->has_focus = focus;

  if (ih->data->cddbuffer)
  {
    cdCanvasFlush(ih->data->cddbuffer);
    if (ih->data->has_focus)
      iColorbarDrawFocusCell(ih);
  }

  return IUP_DEFAULT;
}
Example #12
0
static void iDialRepaint(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return;

  /* update render */
  cdCanvasBackground(ih->data->cddbuffer, ih->data->bgcolor);
  cdCanvasClear(ih->data->cddbuffer);
  ih->data->Draw(ih);

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  if (ih->data->has_focus)
    IupCdDrawFocusRect(ih, ih->data->cdcanvas, 0, 0, ih->data->w-1, ih->data->h-1);
}
Example #13
0
static void iCellsRepaint(Ihandle* ih)
{
  if (ih->data->cd_canvas == NULL)
    return;

  /* If object is buffering, it will not be drawn */
  if (ih->data->bufferize == 1)
    return;

  /* update render */
  iCellsRenderCells(ih);

  /* update display */
  cdCanvasFlush(ih->data->cd_canvas);
}
Example #14
0
static int iDialRedraw_CB(Ihandle* ih)
{
  if (!ih->data->cd_canvas)
    return IUP_DEFAULT;

  /* update display */
  cdCanvasFlush(ih->data->cd_canvas);

  if (ih->data->has_focus)
  {
    cdCanvas* cd_canvas_front = (cdCanvas*)IupGetAttribute(ih, "_CD_CANVAS");  /* front buffer canvas */
    IupCdDrawFocusRect(ih, cd_canvas_front, 0, 0, ih->data->w - 1, ih->data->h - 1);
  }

  return IUP_DEFAULT;
}
static void iColorBrowserDlgColorCnvRepaint(IcolorDlgData* colordlg_data)
{
  int x, y, w, h, width, height, box_size = 10;

  if (!colordlg_data->cd_canvas_color)
    return;

  cdCanvasActivate(colordlg_data->cd_canvas_color);

  cdCanvasGetSize(colordlg_data->cd_canvas_color, &width, &height, NULL, NULL);

  cdCanvasBackground(colordlg_data->cd_canvas_color, CD_WHITE);
  cdCanvasClear(colordlg_data->cd_canvas_color);

  w = (width+box_size-1)/box_size;
  h = (height+box_size-1)/box_size;

  cdCanvasForeground(colordlg_data->cd_canvas_color, CD_GRAY);

  for (y = 0; y < h; y++)
  {                              
    for (x = 0; x < w; x++)
    {
      if (((x%2) && (y%2)) || (((x+1)%2) && ((y+1)%2)))
      {
        int xmin, xmax, ymin, ymax;

        xmin = x*box_size;
        xmax = xmin+box_size;
        ymin = y*box_size;
        ymax = ymin+box_size;

        cdCanvasBox(colordlg_data->cd_canvas_color, xmin, xmax, ymin, ymax);
      }
    }
  }

  cdCanvasForeground(colordlg_data->cd_canvas_color, colordlg_data->previous_color);
  cdCanvasBox(colordlg_data->cd_canvas_color, 0, width/2, 0, height);

  cdCanvasForeground(colordlg_data->cd_canvas_color, colordlg_data->color);
  cdCanvasBox(colordlg_data->cd_canvas_color, width/2+1, width, 0, height);

  cdCanvasFlush(colordlg_data->cd_canvas_color);
}
Example #16
0
/* Callback called when the tree is scrolled.  */
static int iTreeScrollCB(Ihandle* ih)
{
  if (ih->data->cddbuffer)
  {
    cdCanvasActivate(ih->data->cddbuffer);
  
    iupTreeEditCheckHidden(ih);

    cdCanvasNativeFont(ih->data->cddbuffer, IupGetAttribute(ih, "FONT"));
    iupTreeDrawTree(ih);
    cdCanvasFlush(ih->data->cddbuffer);
  }

  if(ih && ih->data->selected && ih->data->selected->visible == NO)
    iupTreeGSSetValue(ih, "PREVIOUS", 0);
  
  return IUP_DEFAULT;
}
Example #17
0
static void iColorbarRenderPartsRepaint(Ihandle* ih, int preview, int idx)
{
  /* update render */
  if (preview)
    iColorbarRenderPreview(ih);
  
  if (idx != ICOLORBAR_RENDER_NONE)
  {
    if (idx == ICOLORBAR_RENDER_ALL)
      iColorbarRenderCells(ih);
    else
      iColorbarRenderCell(ih, idx);
  }

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  if (ih->data->has_focus)
    iColorbarDrawFocusCell(ih);
}
Example #18
0
static int redraw_cb(Ihandle *ih)
{
  int width, height;
  cdCanvas *cdcanvas = (cdCanvas*)IupGetAttribute(ih, "_APP_CDCANVAS");

  cdCanvasActivate(cdcanvas);

  cdCanvasBackground(cdcanvas, CD_WHITE);
  cdCanvasClear(cdcanvas);

  cdCanvasForeground(cdcanvas, CD_RED);
  cdCanvasGetSize(cdcanvas, &width, &height, NULL, NULL);
  cdCanvasLine(cdcanvas, 0, 0, width-1, height-1);
  cdCanvasLine(cdcanvas, 0, height-1, width-1, 0);

  cdCanvasFlush(cdcanvas);

  return IUP_DEFAULT;
}
Example #19
0
static int cbCanvasRepaint(Ihandle* iup_canvas)
{
  cdCanvas* cd_canvas = (cdCanvas*)IupGetAttribute(iup_canvas, "cdCanvas");
  imImage* image = (imImage*)IupGetAttribute(iup_canvas, "imImage");

  if (!cd_canvas || disable_repaint)
    return IUP_DEFAULT;

  cdCanvasActivate(cd_canvas);
  cdCanvasClear(cd_canvas);

  if (!image)
    return IUP_DEFAULT;

  imcdCanvasPutImage(cd_canvas, image, 0, 0, image->width, image->height, 0, 0, 0, 0);
  
  cdCanvasFlush(cd_canvas);
  
  return IUP_DEFAULT;
}
Example #20
0
/* Callback called when the tree needs to be redrawn. */
int iupTreeRepaint(Ihandle* ih)
{
  if(!ih->data->cddbuffer)
    return IUP_DEFAULT;

  cdCanvasActivate(ih->data->cddbuffer);
  
  cdCanvasNativeFont(ih->data->cddbuffer, IupGetAttribute(ih, "FONT"));
  iupTreeDrawTree(ih);  /* TODO: split the calcsize from the redraw */
  iTreeUpdateScrollPos(ih);

  cdCanvasActivate(ih->data->cddbuffer);
  iupTreeDrawTree(ih);
  cdCanvasFlush(ih->data->cddbuffer);

  if(ih && ih->data->selected && ih->data->selected->visible == NO)
    iupTreeGSSetValue(ih, "PREVIOUS", 1);

  return IUP_DEFAULT;
}
Example #21
0
static void cdcgm_BeginPicture(const char* name, cdCGM* cd_cgm)
{
  int width, height;

  if (cd_cgm->first_pic) 
    cd_cgm->first_pic = 0;
  else
    cdCanvasFlush(cd_cgm->canvas); /* do it only if it has more than one picture */

  /* default clipping is ON */
  cdCanvasGetSize(cd_cgm->canvas, &width, &height, NULL, NULL);
  cdCanvasClipArea(cd_cgm->canvas, 0, width-1, 0, height-1);
  cdCanvasClip(cd_cgm->canvas, CD_CLIPAREA);

  if (cdcgmbegpictcb)
  {
    int ret = cdcgmbegpictcb(cd_cgm->canvas, name);
    if (ret == CD_ABORT)
      cd_cgm->abort = 1;
  }
}
Example #22
0
static void iDialRepaint(Ihandle* ih)
{
  if (!ih->data->cd_canvas)
    return;

  cdCanvasActivate(ih->data->cd_canvas);

  /* update render */
  cdCanvasBackground(ih->data->cd_canvas, ih->data->bgcolor);
  cdCanvasClear(ih->data->cd_canvas);
  ih->data->Draw(ih);

  /* update display */
  cdCanvasFlush(ih->data->cd_canvas);

  if (ih->data->has_focus)
  {
    cdCanvas* cd_canvas_front = (cdCanvas*)IupGetAttribute(ih, "_CD_CANVAS");  /* front buffer canvas */
    IupCdDrawFocusRect(ih, cd_canvas_front, 0, 0, ih->data->w - 1, ih->data->h - 1);
  }
}
Example #23
0
static void iColorbarRepaint(Ihandle* ih)
{
  /* Checking errors or not initialized conditions */
  if (ih->data->cddbuffer == NULL)
    return;

  /* If object is buffering, it will be not drawn */
  if (ih->data->bufferize == 1)
    return;

  /* update render */
  cdCanvasBackground(ih->data->cddbuffer, ih->data->bgcolor);
  cdCanvasClear(ih->data->cddbuffer);
  iColorbarRenderPreview(ih);
  iColorbarRenderCells(ih);

  /* update display */
  cdCanvasFlush(ih->data->cddbuffer);
  if (ih->data->has_focus)
    iColorbarDrawFocusCell(ih);
}
Example #24
0
/** 
 * Repaint function, but it is the only one that activates the cd canvas 
 */
static void repaint_all(TCells* obj) {

  /* If object is buffering, it will be not drawn */
  if (obj->bufferize == 1) return;

  /* Checking erros or not initialized conditions */
  if (obj->self == NULL) return;
  if (obj->cddbuffer == NULL) return;

  if (obj->no_color == -1)
    obj->no_color = cdIupConvertColor(iupGetBgColor(obj->self));

  /* Getting object background color and repainting it.*/
  cdCanvasBackground(obj->cddbuffer, obj->no_color); 
  cdCanvasClear(obj->cddbuffer);

  /* Repaiting all cells */
  repaint_cells(obj);

  /* Flushing drawing to cd double buffer canvas */
  cdCanvasFlush(obj->cddbuffer);
}
Example #25
0
static void iColorBrowserUpdateDisplay(Ihandle* ih)
{
  if (!ih->data->cddbuffer)
    return;

  cdCanvasFlush(ih->data->cddbuffer);  /* swap the RGB to the display canvas */

  if (iupdrvIsActive(ih))
  {
    cdCanvasForeground(ih->data->cdcanvas, CD_GRAY);
    cdCanvasArc(ih->data->cdcanvas, ih->data->h_x+1, ih->data->h_y, ICB_MARKSIZE, ICB_MARKSIZE, 0, 360);
    cdCanvasArc(ih->data->cdcanvas, ih->data->si_x+1, ih->data->si_y, ICB_MARKSIZE, ICB_MARKSIZE, 0, 360);
    cdCanvasForeground(ih->data->cdcanvas, CD_WHITE);
    cdCanvasArc(ih->data->cdcanvas, ih->data->h_x, ih->data->h_y, ICB_MARKSIZE, ICB_MARKSIZE, 0, 360);
    cdCanvasArc(ih->data->cdcanvas, ih->data->si_x, ih->data->si_y, ICB_MARKSIZE, ICB_MARKSIZE, 0, 360);
  }
  else
  {
    cdCanvasForeground(ih->data->cdcanvas, CD_DARK_GRAY);
    cdCanvasSector(ih->data->cdcanvas, ih->data->h_x, ih->data->h_y, ICB_MARKSIZE+1, ICB_MARKSIZE+1, 0, 360);
    cdCanvasSector(ih->data->cdcanvas, ih->data->si_x, ih->data->si_y, ICB_MARKSIZE+1, ICB_MARKSIZE+1, 0, 360);
  }
}
Example #26
0
File: cdmf.c Project: LuaDist/cd
static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data)
{
  char* filename = (char*)data;
  FILE* file;
  char TextBuffer[512];
  int iparam1, iparam2, iparam3, iparam4, iparam5, iparam6, iparam7, iparam8, iparam9, iparam10;
  int c, t, n, w, h, func;
  double dparam1, dparam2, dparam3, dparam4, dparam5, dparam6;
  unsigned char* stipple, * _stipple, *red, *green, *blue, *_red, *_green, *_blue, *index, *_index, *_alpha, *alpha;
  long int *pattern, *palette, *_pattern, *_palette, *colors, *_colors;
  int* dashes;
  double matrix[6];
  const char * font_family[] = 
  {
    "System",       /* CD_SYSTEM */
    "Courier",      /* CD_COURIER */
    "Times",        /* CD_TIMES_ROMAN */
    "Helvetica"     /* CD_HELVETICA */
  };
  
  file = fopen(filename, "r");
  if (!file)
    return CD_ERROR;

  func = -1;
  w = 0;
  h = 0;

  factorX = 1;
  factorY = 1;
  offsetX = 0;
  offsetY = 0;
  factorS = 1;

  fscanf(file, "%s %d %d", TextBuffer, &w, &h);

  if (strcmp(TextBuffer, "CDMF") != 0)
  {
    fclose(file);
    return CD_ERROR;
  }

  if (w>1 && h>1 && xmax!=0 && ymax!=0)
  {
    offsetX = xmin;
    offsetY = ymin;
    factorX = ((double)(xmax-xmin)) / (w-1);
    factorY = ((double)(ymax-ymin)) / (h-1);

    if (factorX < factorY)
      factorS = factorX;
    else
      factorS = factorY;
  }

  if (cdsizecb)
  {
    int err;
    err = cdsizecb(canvas, w, h, w, h);
    if (err)
      return CD_ERROR;
  }

  while (!feof(file))
  {
    fscanf(file, "%d", &func);
    if (feof(file))
      break;

    switch (func)
    {
    case CDMF_FLUSH:
      cdCanvasFlush(canvas);
      break;
    case CDMF_CLEAR:
      cdCanvasClear(canvas);
      break;
    case CDMF_CLIP:
      fscanf(file, "%d", &iparam1);
      cdCanvasClip(canvas, iparam1);
      break;
    case CDMF_CLIPAREA:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasClipArea(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FCLIPAREA:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasClipArea(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_MATRIX:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5]);
      cdCanvasTransform(canvas, matrix);
      break;
    case CDMF_RESETMATRIX:
      cdCanvasTransform(canvas, NULL);
      break;
    case CDMF_WCLIPAREA:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasClipArea(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_LINE:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasLine(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleX(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FLINE:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasLine(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleX(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_WLINE:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasLine(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_RECT:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasRect(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FRECT:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasRect(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_WRECT:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasRect(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_BOX:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasBox(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_WBOX:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasBox(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_FBOX:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasBox(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_ARC:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasArc(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FARC:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasArc(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WARC:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasArc(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_SECTOR:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasSector(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FSECTOR:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasSector(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WSECTOR:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasSector(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_CHORD:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasChord(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FCHORD:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasChord(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WCHORD:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasChord(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_TEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasText(canvas, sScaleX(iparam1), sScaleY(iparam2), TextBuffer);
      break;
    case CDMF_FTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      cdfCanvasText(canvas, sfScaleX(dparam1), sfScaleY(dparam2), TextBuffer);
      break;
    case CDMF_WTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_BEGIN:
      fscanf(file, "%d", &iparam1);
      cdCanvasBegin(canvas, iparam1);
      break;
    case CDMF_VERTEX:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      cdCanvasVertex(canvas, sScaleX(iparam1), sScaleY(iparam2));
      break;
    case CDMF_FVERTEX:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      cdfCanvasVertex(canvas, sfScaleX(dparam1), sfScaleY(dparam2));
      break;
    case CDMF_WVERTEX:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      wdCanvasVertex(canvas, dparam1, dparam2);
      break;
    case CDMF_END:
      cdCanvasEnd(canvas);
      break;
    case CDMF_MARK:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      cdCanvasMark(canvas, sScaleX(iparam1), sScaleY(iparam2));
      break;
    case CDMF_WMARK:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      wdCanvasMark(canvas, dparam1, dparam2);
      break;
    case CDMF_BACKOPACITY:
      fscanf(file, "%d", &iparam1);
      cdCanvasBackOpacity(canvas, iparam1);
      break;
    case CDMF_WRITEMODE:
      fscanf(file, "%d", &iparam1);
      cdCanvasWriteMode(canvas, iparam1);
      break;
    case CDMF_LINESTYLE:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineStyle(canvas, iparam1);
      break;
    case CDMF_LINEWIDTH:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineWidth(canvas, sScaleS(iparam1));
      break;
    case CDMF_LINECAP:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineCap(canvas, iparam1);
      break;
    case CDMF_LINEJOIN:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineJoin(canvas, iparam1);
      break;
    case CDMF_LINESTYLEDASHES:
      fscanf(file, "%d", &iparam1);
      dashes = (int*)malloc(iparam1*sizeof(int));
      for (c = 0; c < iparam1; c++)
        fscanf(file, "%d", &dashes[c]);
      cdCanvasLineStyleDashes(canvas, dashes, iparam1);
      free(dashes);
      break;
    case CDMF_FILLMODE:
      fscanf(file, "%d", &iparam1);
      cdCanvasFillMode(canvas, iparam1);
      break;
    case CDMF_INTERIORSTYLE:
      fscanf(file, "%d", &iparam1);
      cdCanvasInteriorStyle(canvas, iparam1);
      break;
    case CDMF_HATCH:
      fscanf(file, "%d", &iparam1);
      cdCanvasHatch(canvas, iparam1);
      break;
    case CDMF_STIPPLE:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      t = iparam1 * iparam2;
      stipple = (unsigned char*)malloc(t);
      _stipple = stipple;
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d", &iparam3);
        *_stipple++ = (unsigned char)iparam3;
      }
      cdCanvasStipple(canvas, iparam1, iparam2, stipple);
      free(stipple);
      break;
    case CDMF_PATTERN:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      t = iparam1 * iparam2;
      pattern = (long int*)malloc(t * sizeof(long));
      _pattern = pattern;
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d", &iparam3, &iparam4, &iparam5);
        *_pattern++ = cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5);
      }
      cdCanvasPattern(canvas, iparam1, iparam2, pattern);
      free(pattern);
      break;
    case CDMF_OLDFONT:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      if (iparam1 < 0 || iparam1 > 3) break;
      if (iparam3 < 0)
      {
        iparam3 = -sScaleH(abs(iparam3));
        if (iparam3 > -5) iparam3 = -5;
      }
      else
      {
        iparam3 = sScaleH(abs(iparam3));
        if (iparam3 < 5) iparam3 = 5;
      }
      cdCanvasFont(canvas, font_family[iparam1], iparam2, iparam3);
      break;
    case CDMF_FONT:
      fscanf(file, "%d %d %[^\n\r]", &iparam2, &iparam3, TextBuffer);
      if (iparam3 < 0)
      {
        iparam3 = -sScaleH(abs(iparam3));
        if (iparam3 > -5) iparam3 = -5;
      }
      else
      {
        iparam3 = sScaleH(abs(iparam3));
        if (iparam3 < 5) iparam3 = 5;
      }
      cdCanvasFont(canvas, TextBuffer, iparam2, iparam3);
      break;
    case CDMF_NATIVEFONT:
      fscanf(file, "%[^\n\r]", TextBuffer);
      cdCanvasNativeFont(canvas, TextBuffer);
      break;
    case CDMF_TEXTALIGNMENT:
      fscanf(file, "%d", &iparam1);
      cdCanvasTextAlignment(canvas, iparam1);
      break;
    case CDMF_TEXTORIENTATION:
      fscanf(file, "%lg", &dparam1);
      cdCanvasTextOrientation(canvas, dparam1);
      break;
    case CDMF_MARKTYPE:
      fscanf(file, "%d", &iparam1);
      cdCanvasMarkType(canvas, iparam1);
      break;
    case CDMF_MARKSIZE:
      fscanf(file, "%d", &iparam1);
      cdCanvasMarkSize(canvas, sScaleS(iparam1));
      break;
    case CDMF_PALETTE:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      _palette = palette = (long int*)malloc(iparam1);
      for (c = 0; c < iparam1; c++)
      {
        fscanf(file, "%d %d %d", &iparam3, &iparam4, &iparam5);
        *_palette++ = cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5);
      }
      cdCanvasPalette(canvas, iparam1, palette, iparam2);
      free(palette);
      break;
    case CDMF_BACKGROUND:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      cdCanvasSetBackground(canvas, cdEncodeColor((unsigned char)iparam1, (unsigned char)iparam2, (unsigned char)iparam3));
      break;
    case CDMF_FOREGROUND:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      cdCanvasSetForeground(canvas, cdEncodeColor((unsigned char)iparam1, (unsigned char)iparam2, (unsigned char)iparam3));
      break;
    case CDMF_PUTIMAGERGB:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      _red = red = (unsigned char*) malloc(t);
      _green = green = (unsigned char*) malloc(t);
      _blue = blue = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d", &iparam7, &iparam8, &iparam9);
        *_red++ = (unsigned char)iparam7;
        *_green++ = (unsigned char)iparam8;
        *_blue++ = (unsigned char)iparam9;
      }
      cdCanvasPutImageRectRGB(canvas, iparam1, iparam2, red, green, blue, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(red);
      free(green);
      free(blue);
      break;
    case CDMF_PUTIMAGERGBA:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      _red = red = (unsigned char*) malloc(t);
      _green = green = (unsigned char*) malloc(t);
      _blue = blue = (unsigned char*) malloc(t);
      _alpha = alpha = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d %d", &iparam7, &iparam8, &iparam9, &iparam10);
        *_red++ = (unsigned char)iparam7;
        *_green++ = (unsigned char)iparam8;
        *_blue++ = (unsigned char)iparam9;
        *_alpha++ = (unsigned char)iparam10;
      }
      cdCanvasPutImageRectRGBA(canvas, iparam1, iparam2, red, green, blue, alpha, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(red);
      free(green);
      free(blue);
      free(alpha);
      break;
    case CDMF_PUTIMAGEMAP:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      n = 0;
      _index = index = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d", &iparam7);
        *_index++ = (unsigned char)iparam7;
        if (iparam7 > n)
          n = iparam7;
      }
      _colors = colors = (long int*)malloc(n);
      for (c = 0; c < n; c++)
      {
        fscanf(file, "%d %d %d", &iparam7, &iparam8, &iparam9);
        *_colors++ = cdEncodeColor((unsigned char)iparam7, (unsigned char)iparam8, (unsigned char)iparam9);
      }
      cdCanvasPutImageRectMap(canvas, iparam1, iparam2, index, colors, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(index);
      free(colors);
      break;
    case CDMF_PIXEL:
      fscanf(file, "%d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5);
      cdCanvasPixel(canvas, sScaleX(iparam1), sScaleY(iparam2), cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5));
      break;
    case CDMF_SCROLLAREA:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      cdCanvasScrollArea(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4), sScaleX(iparam5), sScaleY(iparam6));
      break;
    case CDMF_WVECTORTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_WMULTILINEVECTORTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_VECTORTEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorText(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_MULTILINEVECTORTEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorText(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_WVECTORCHARSIZE:
      fscanf(file, "%lg", &dparam1);
      wdCanvasVectorCharSize(canvas, dparam1);
      break;
    case CDMF_WVECTORTEXTSIZE:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorTextSize(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_WVECTORTEXTDIRECTION:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasVectorTextDirection(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_VECTORCHARSIZE:
      fscanf(file, "%d", &iparam1);
      cdCanvasVectorCharSize(canvas, iparam1);
      break;
    case CDMF_VECTORTEXTSIZE:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorTextSize(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_VECTORTEXTDIRECTION:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasVectorTextDirection(canvas, iparam1, iparam2, iparam3, iparam4);
      break;
    case CDMF_VECTORFONT:
      fscanf(file, "%[^\n\r]", TextBuffer);
      cdCanvasVectorFont(canvas, TextBuffer);
      break;
    case CDMF_VECTORTEXTTRANSFORM:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5]);
      cdCanvasVectorTextTransform(canvas, matrix);
      break;
    case CDMF_WINDOW:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasWindow(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    default:
      fclose(file);
      return CD_ERROR;
    }
  }

  fclose(file);

  return CD_OK;
}
Example #27
0
static int iColorbarKeyPress_CB(Ihandle* ih, int c, int press)
{
  if (c != K_LEFT && c != K_UP && c != K_RIGHT && c != K_DOWN &&
      c != K_HOME && c != K_END &&
      c != K_SP && c != K_sCR && c != K_sSP && c != K_cSP)
    return IUP_DEFAULT;

  if (!press || !ih->data->has_focus)
    return IUP_DEFAULT;

  switch(c)
  {
  case K_LEFT:
    if (ih->data->vertical)
    {
      int cells_per_line = ih->data->num_cells / ih->data->num_parts;
      if (ih->data->focus_cell > cells_per_line)
        ih->data->focus_cell -= cells_per_line;
    }
    else
    {
      if (ih->data->focus_cell > 0)
        ih->data->focus_cell--;
    }
    break;
  case K_DOWN:
    if (ih->data->vertical)
    {
      if (ih->data->focus_cell > 0)
        ih->data->focus_cell--;
    }
    else
    {
      int cells_per_line = ih->data->num_cells / ih->data->num_parts;
      if (ih->data->focus_cell > cells_per_line)
        ih->data->focus_cell -= cells_per_line;
    }
    break;
  case K_RIGHT:
    if (ih->data->vertical)
    {
      int cells_per_line = ih->data->num_cells / ih->data->num_parts;
      if (ih->data->focus_cell+cells_per_line < ih->data->num_cells-1)
        ih->data->focus_cell += cells_per_line;
    }
    else
    {
      if (ih->data->focus_cell < ih->data->num_cells-1)
        ih->data->focus_cell++;
    }
    break;
  case K_UP:
    if (ih->data->vertical)
    {
      if (ih->data->focus_cell < ih->data->num_cells-1)
        ih->data->focus_cell++;
    }
    else
    {
      int cells_per_line = ih->data->num_cells / ih->data->num_parts;
      if (ih->data->focus_cell+cells_per_line < ih->data->num_cells-1)
        ih->data->focus_cell += cells_per_line;
    }
    break;
  case K_HOME:
    ih->data->focus_cell = 0;
    break;
  case K_END:
    ih->data->focus_cell = ih->data->num_cells-1;
    break;
  case K_sCR:
    iColorbarCallCellCb(ih, ih->data->focus_cell);
    return IUP_DEFAULT;
  case K_SP:
    iColorbarCallSelectCb(ih, ih->data->focus_cell, IUP_PRIMARY);
    return IUP_DEFAULT;
  case K_cSP:
    iColorbarCallSelectCb(ih, ih->data->focus_cell, IUP_SECONDARY);
    return IUP_DEFAULT;
  case K_sSP:
    iColorbarCallExtentedCb(ih, ih->data->focus_cell);
    return IUP_DEFAULT;
  }

  if (ih->data->cddbuffer)
  {
    cdCanvasFlush(ih->data->cddbuffer);
    if (ih->data->has_focus)
      iColorbarDrawFocusCell(ih);
  }

  return IUP_IGNORE;  /* to avoid arrow keys being processed by the system */
}