/* %F Muda a largura da coluna interativamente, so muda a linha na tela. Qando o usuario termina o drag, a funcao iupmatColresFinish e chamada para realmente mudar a largura da coluna. %i h : handle da matriz, x : coordenada x do mouse (coordenadas do canvas). */ void iupmatColresMove(Ihandle *h, int x) { Tmat *mat=(Tmat*)matrix_data(h); int y1,y2, charwidth,charheight; iupdrvGetCharSize(h,&charwidth,&charheight); /* Se tamanho da coluna ficou muito pequeno, nao muda tamanho da coluna */ if (x < DragColStartPos+charwidth+DECOR_X) return; y1 = mat_ht(mat); y2 = YmaxCanvas(mat); cdCanvasWriteMode(mat->cdcanvas, CD_XOR); cdCanvasForeground(mat->cdcanvas, RESIZE_COLOR); /* Se nao e a primeira vez, retira linha antiga */ if (Lastxpos != -1) cdCanvasLine(mat->cdcanvas,Lastxpos,INVY(y1),Lastxpos,INVY(y2)); cdCanvasLine(mat->cdcanvas,x,INVY(y1),x,INVY(y2)); Lastxpos = x; cdCanvasWriteMode(mat->cdcanvas, CD_REPLACE); }
/* Change the column width interactively, just change the line in the screen. When the user finishes the drag, the iupMatrixColResFinish function is called to truly change the column width. */ void iupMatrixColResMove(Ihandle* ih, int x) { int y1, y2; int delta = x - ih->data->colres_drag_col_start_x; int width = ih->data->columns.dt[ih->data->colres_drag_col].size + delta; if (width < 0) return; y1 = ih->data->lines.dt[0].size; /* from the bottom of the line of titles */ y2 = ih->data->h-1; /* to the bottom of the matrix */ cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, ih->data->colres_color); /* If it is not the first time, move old line */ if (ih->data->colres_drag_col_last_x != -1) { cdCanvasLine(ih->data->cdcanvas, ih->data->colres_drag_col_last_x, iupMATRIX_INVERTYAXIS(ih, y1), ih->data->colres_drag_col_last_x, iupMATRIX_INVERTYAXIS(ih, y2)); } cdCanvasLine(ih->data->cdcanvas, x, iupMATRIX_INVERTYAXIS(ih, y1), x, iupMATRIX_INVERTYAXIS(ih, y2)); ih->data->colres_drag_col_last_x = x; cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); }
void cdIupDrawVertSunkenMark(cdCanvas *canvas, int x, int y1, int y2, long light_shadow, long dark_shadow) { cdCanvasForeground(canvas, dark_shadow); cdCanvasLine(canvas, x-1, y1, x-1, y2); cdCanvasForeground(canvas, light_shadow); cdCanvasLine(canvas, x, y1, x, y2); }
/* Change the column width interactively, just change the line in the screen. When the user finishes the drag, the iupMatrixColResFinish function is called to truly change the column width (x : x mouse coordinate (canvas coordinate)). */ void iupMatrixColResMove(Ihandle* ih, int x) { int y1, y2, charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); /* If the size column was tiny, no change the size column */ if(x < DragColStartPos + charwidth + IMAT_DECOR_X) return; y1 = ih->data->lin.titlewh; y2 = ih->data->YmaxC; cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); /* If it is not the first time, move old line */ if(Lastxpos != -1) cdCanvasLine(ih->data->cdcanvas, Lastxpos, (ih->data->YmaxC - (y1)), Lastxpos, (ih->data->YmaxC - (y2))); cdCanvasLine(ih->data->cdcanvas, x, (ih->data->YmaxC - (y1)), x, (ih->data->YmaxC - (y2))); Lastxpos = x; cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); }
void cdIupDrawHorizSunkenMark(cdCanvas *canvas, int x1, int x2, int y, long light_shadow, long dark_shadow) { cdCanvasForeground(canvas, dark_shadow); cdCanvasLine(canvas, x1, y+1, x2, y+1); cdCanvasForeground(canvas, light_shadow); cdCanvasLine(canvas, x1, y, x2, y); }
/* Change the column width interactively, just change the line in the screen. When the user finishes the drag, the iupMatrixColResFinish function is called to truly change the column width. */ void iupMatrixColResMove(Ihandle* ih, int x) { int y1, y2; int width = x - ih->data->colres_drag_col_start_x; if (width < 0) return; y1 = ih->data->lines.sizes[0]; /* from the bottom of the line of titles */ y2 = ih->data->h-1; /* to the bottom of the matrix */ cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); /* If it is not the first time, move old line */ if (ih->data->colres_drag_col_last_x != -1) { cdCanvasLine(ih->data->cdcanvas, ih->data->colres_drag_col_last_x, iupMatrixInvertYAxis(ih, y1), ih->data->colres_drag_col_last_x, iupMatrixInvertYAxis(ih, y2)); } cdCanvasLine(ih->data->cdcanvas, x, iupMatrixInvertYAxis(ih, y1), x, iupMatrixInvertYAxis(ih, y2)); ih->data->colres_drag_col_last_x = x; cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); }
static void drawTestCD(Ihandle* ih) { cdCanvas* canvas = cdCreateCanvas(CD_IUP, ih); int w = IupGetInt(ih, "PREVIEWWIDTH"); int h = IupGetInt(ih, "PREVIEWHEIGHT"); cdCanvasClear(canvas); cdCanvasForeground(canvas, cdEncodeColor(255, 0 , 0)); cdCanvasLine(canvas, 0, 0, w-1, h-1); cdCanvasLine(canvas, 0, h-1, w-1, 0); cdKillCanvas(canvas); }
static void iDialDrawCircular(Ihandle* ih) { double delta = 2 * M_PI / ih->data->num_div, a = ih->data->angle; int i, xc = ih->data->w / 2, yc = ih->data->h / 2, wide; ih->data->radius = dialmin(ih->data->w, ih->data->h) / 2 - 2 * IDIAL_SPACE; wide = (int)(2 * ih->data->radius); cdCanvasForeground(ih->data->cd_canvas, ih->data->mid_shadow); cdCanvasLineWidth(ih->data->cd_canvas, 2); cdCanvasArc(ih->data->cd_canvas, xc, yc, wide-1, wide-1, -135, 45.0); cdCanvasLineWidth(ih->data->cd_canvas, 1); cdCanvasForeground(ih->data->cd_canvas, ih->data->bgcolor); cdCanvasSector(ih->data->cd_canvas, xc, yc, wide-2, wide-2, 0.0, 360.0); cdCanvasForeground(ih->data->cd_canvas, ih->data->light_shadow); cdCanvasArc(ih->data->cd_canvas, xc, yc, wide, wide, 45, 225); cdCanvasForeground(ih->data->cd_canvas, ih->data->dark_shadow); cdCanvasArc(ih->data->cd_canvas, xc, yc, wide, wide, -135, 45); for (i = 0; i < ih->data->num_div; ++i) { int x2 = (int)(xc + (ih->data->radius - 6) * cos(a)); int y2 = (int)(yc + (ih->data->radius - 6) * sin(a)); if (i == 0) { cdCanvasForeground(ih->data->cd_canvas, CD_BLACK); cdCanvasLine(ih->data->cd_canvas, xc, yc, x2, y2); } iDialDrawCircularMark(ih, x2-2, y2-2); a += delta; } iDialDrawCircularMark(ih, xc-2, yc-2); }
void iupMatrixColResFinish(Ihandle* ih, int x) { char str[100]; int width = x - ih->data->colres_drag_col_start_x; if (width < 0) width = 0; /* delete feedback */ if (ih->data->colres_drag_col_last_x != -1) { int y1 = ih->data->lines.sizes[0]; /* from the bottom of the line of titles */ int y2 = ih->data->h-1; /* to the bottom of the matrix */ cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); cdCanvasLine(ih->data->cdcanvas, ih->data->colres_drag_col_last_x, iupMatrixInvertYAxis(ih, y1), ih->data->colres_drag_col_last_x, iupMatrixInvertYAxis(ih, y2)); cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); } ih->data->colres_dragging = 0; sprintf(str, "RASTERWIDTH%d", ih->data->colres_drag_col); iupAttribSetInt(ih, str, width-IMAT_PADDING_W-IMAT_FRAME_W); sprintf(str, "WIDTH%d", ih->data->colres_drag_col); iupAttribSetStr(ih, str, NULL); ih->data->need_calcsize = 1; iupMatrixDraw(ih, 0); }
/* Finish the interactive resize of columns. Call ChangeMatrixWidth to truly change the column size (x : x mouse coordinate (canvas coordinate)). */ void iupMatrixColResFinish(Ihandle* ih, int x) { int charwidth, charheight, width; int y1, y2; iupdrvFontGetCharSize(ih, &charwidth, &charheight); width = x - DragColStartPos - IMAT_DECOR_X; if(width < charwidth) width = charwidth ; /* min size to the cell */ /* delete feedback */ if(Lastxpos != -1) { y1 = ih->data->lin.titlewh; y2 = ih->data->YmaxC; cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); cdCanvasLine(ih->data->cdcanvas, Lastxpos, (ih->data->YmaxC - (y1)), Lastxpos, (ih->data->YmaxC - (y2))); cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); } iMatrixColResChangeMatrixWH(ih, DragCol, width + IMAT_DECOR_X, IMAT_MAT_COL); Dragging = 0; }
/* %F Termina o resize interativo de colunas. Chama a funcao ChangeMatrixWidth para mudar realmente o tamanho da coluna. %i h : handle da matriz, x : coordenada x do mouse (coordenadas do canvas). */ void iupmatColresFinish(Ihandle *h, int x) { int charwidth,charheight, width; int y1, y2; Tmat *mat=(Tmat*)matrix_data(h); iupdrvGetCharSize(h,&charwidth,&charheight); width = x - DragColStartPos-DECOR_X; if (width < charwidth) width = charwidth ; /* Tamanho minimo para a celula */ /* Apaga feedback */ if (Lastxpos != -1) { y1 = mat_ht(mat); y2 = YmaxCanvas(mat); cdCanvasWriteMode(mat->cdcanvas,CD_XOR); cdCanvasForeground(mat->cdcanvas,RESIZE_COLOR); cdCanvasLine(mat->cdcanvas,Lastxpos,INVY(y1),Lastxpos,INVY(y2)); cdCanvasWriteMode(mat->cdcanvas,CD_REPLACE); } ChangeMatrixWH(h,DragCol,width+DECOR_X,MAT_COL); Dragging = 0; }
void iupMatrixColResFinish(Ihandle* ih, int x) { int delta = x - ih->data->colres_drag_col_start_x; int width = ih->data->columns.dt[ih->data->colres_drag_col].size + delta; if (width < 0) width = 0; /* delete feedback */ if (ih->data->colres_drag_col_last_x != -1) { int y1 = ih->data->lines.dt[0].size; /* from the bottom of the line of titles */ int y2 = ih->data->h-1; /* to the bottom of the matrix */ cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, ih->data->colres_color); cdCanvasLine(ih->data->cdcanvas, ih->data->colres_drag_col_last_x, iupMATRIX_INVERTYAXIS(ih, y1), ih->data->colres_drag_col_last_x, iupMATRIX_INVERTYAXIS(ih, y2)); cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); } ih->data->colres_dragging = 0; iupAttribSetIntId(ih, "RASTERWIDTH", ih->data->colres_drag_col, width-IMAT_PADDING_W-IMAT_FRAME_W); iupAttribSetId(ih, "WIDTH", ih->data->colres_drag_col, NULL); ih->data->need_calcsize = 1; iupMatrixDraw(ih, 0); { IFni cb = (IFni)IupGetCallback(ih, "COLRESIZE_CB"); if (cb) cb(ih, ih->data->colres_drag_col); } }
int cgm_line_circle ( double xc, double yc, double radius, double angi, double angf, int fechado ) { double coseno, seno; double xant, yant, firstx, firsty; double xs, ys; /* GERA O DESENHO DO CIRCULO/ARCO */ coseno = cos (VARCS); seno = sin (VARCS); xs = radius * cos(angi); ys = radius * sin(angi); if ( fechado==CLOSED_PIE ) cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) ); xant = firstx = xc+xs; yant = firsty = yc+ys; while ( (angi+VARCS) < angf ) { double xe = xs; xs = xs * coseno - ys * seno; ys = ys * coseno + xe * seno; cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) ); xant = xc+xs; yant = yc+ys; angi += VARCS; } cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc+radius*cos(angf)), cgm_vdcy2canvas(yc+radius*sin(angf)) ); xant = xc+radius*cos(angf); yant = yc+radius*sin(angf); if ( fechado==CLOSED_PIE ) cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) ); else if ( fechado==CLOSED_CHORD ) cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(firstx), cgm_vdcy2canvas(firsty) ); return 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; }
void cdCanvasSector(cdCanvas* canvas, int xc, int yc, int w, int h, double angle1, double angle2) { assert(canvas); if (!_cdCheckCanvas(canvas)) return; if (angle1 == angle2 || w == 0 || h == 0) return; sNormAngles(&angle1, &angle2); if (canvas->interior_style == CD_HOLLOW) { cdCanvasArc(canvas, xc, yc, w, h, angle1, angle2); if (fabs(angle2-angle1) < 360) { int xi,yi,xf,yf; xi = xc + cdRound(w*cos(CD_DEG2RAD*angle1)/2.0); yi = yc + cdRound(h*sin(CD_DEG2RAD*angle1)/2.0); xf = xc + cdRound(w*cos(CD_DEG2RAD*angle2)/2.0); yf = yc + cdRound(h*sin(CD_DEG2RAD*angle2)/2.0); cdCanvasLine(canvas, xi, yi, xc, yc); cdCanvasLine(canvas, xc, yc, xf, yf); } return; } if (canvas->use_origin) { xc += canvas->origin.x; yc += canvas->origin.y; } if (canvas->invert_yaxis) yc = _cdInvertYAxis(canvas, yc); canvas->cxSector(canvas->ctxcanvas, xc, yc, w, h, angle1, angle2); }
int action(Ihandle *ih, float posx, float posy) { int iposx = (int)posx; int iposy = (int)posy; if (!cdcanvas) return IUP_DEFAULT; /* update CD canvas size */ cdCanvasActivate(cdcanvas); /* invert scroll reference (YMAX-DY - POSY) */ iposy = 399-IupGetInt(ih, "DY") - iposy; cdCanvasClear(cdcanvas); cdCanvasForeground(cdcanvas, CD_RED); cdCanvasLine(cdcanvas, 0-iposx, 0-iposy, 599-iposx, 399-iposy); cdCanvasLine(cdcanvas, 0-iposx, 399-iposy, 599-iposx, 0-iposy); return IUP_DEFAULT; }
void DrawVectorTextBox(cdCanvas* canvas, int x, int y, char* text) { int rect[8], draw_box; cdCanvasLineWidth(canvas, 1); cdCanvasLineStyle(canvas, CD_CONTINUOUS); draw_box = 0; if (draw_box) { int xmin, xmax, ymin, ymax; cdCanvasGetVectorTextBox(canvas, x, y, text, &xmin, &xmax, &ymin, &ymax); cdCanvasForeground(canvas, CD_GREEN); cdCanvasRect(canvas, xmin, xmax, ymin, ymax); if (cdCanvasTextOrientation(canvas, CD_QUERY) == 0) { cdCanvasForeground(canvas, CD_RED); cdCanvasLine(canvas, xmin, y, xmax, y); } } else { /* bounding box */ cdCanvasGetVectorTextBounds(canvas, text, x, y, rect); cdCanvasForeground(canvas, CD_GREEN); cdCanvasBegin(canvas, CD_CLOSED_LINES); cdCanvasVertex(canvas, rect[0], rect[1]); cdCanvasVertex(canvas, rect[2], rect[3]); cdCanvasVertex(canvas, rect[4], rect[5]); cdCanvasVertex(canvas, rect[6], rect[7]); cdCanvasEnd(canvas); } /* reference point */ cdCanvasForeground(canvas, CD_BLUE); cdCanvasMarkType(canvas, CD_PLUS); cdCanvasMarkSize(canvas, 30); cdCanvasMark(canvas, x, y); cdCanvasForeground(canvas, CD_BLACK); cdCanvasVectorText(canvas, x, y, text); }
void cdIupDrawRaiseRect(cdCanvas *canvas, int x1, int y1, int x2, int y2, long light_shadow, long mid_shadow, long dark_shadow) { cdCanvasForeground(canvas, light_shadow); cdCanvasLine(canvas, x1, y1+1, x1, y2); cdCanvasLine(canvas, x1, y2, x2-1, y2); cdCanvasForeground(canvas, dark_shadow); cdCanvasLine(canvas, x1, y1, x2, y1); cdCanvasLine(canvas, x2, y1, x2, y2); cdCanvasForeground(canvas, mid_shadow); cdCanvasLine(canvas, x1+1, y1+1, x2-1, y1+1); cdCanvasLine(canvas, x2-1, y1+2, x2-1, y2-1); }
void iupPlot::DrawCrossHairV(const iupPlotRect &inRect, cdCanvas* canvas) const { cdCanvasSetForeground(canvas, mAxisX.mColor); iPlotSetLine(canvas, CD_CONTINUOUS, 1); // Draw an horizontal line at cursor Y coordinate cdCanvasLine(canvas, inRect.mX, mCrossHairY, inRect.mX + inRect.mWidth - 1, mCrossHairY); for (int ds = 0; ds < mDataSetListCount; ds++) { iupPlotDataSet* dataset = mDataSetList[ds]; const iupPlotDataBase *theXData = dataset->GetDataX(); const iupPlotDataBase *theYData = dataset->GetDataY(); cdCanvasSetForeground(canvas, dataset->mColor); DrawCrossSamplesV(inRect, theXData, theYData, canvas); } }
void iupPlot::DrawCrossHairH(const iupPlotRect &inRect, cdCanvas* canvas) const { cdCanvasSetForeground(canvas, mAxisY.mColor); iPlotSetLine(canvas, CD_CONTINUOUS, 1); // Draw a vertical line at cursor X coordinate cdCanvasLine(canvas, mCrossHairX, inRect.mY, mCrossHairX, inRect.mY + inRect.mHeight - 1); for (int ds = 0; ds < mDataSetListCount; ds++) { iupPlotDataSet* dataset = mDataSetList[ds]; const iupPlotDataBase *theXData = dataset->GetDataX(); const iupPlotDataBase *theYData = dataset->GetDataY(); cdCanvasSetForeground(canvas, dataset->mColor); DrawCrossSamplesH(inRect, theXData, theYData, canvas); } }
static void iDialDrawCircularMark(Ihandle* ih, int x1, int y1) { cdCanvasForeground(ih->data->cd_canvas, ih->data->bgcolor); cdCanvasBox(ih->data->cd_canvas,x1, x1+4, y1, y1+4); cdCanvasForeground(ih->data->cd_canvas, ih->data->light_shadow); cdCanvasLine(ih->data->cd_canvas, x1, y1+1, x1, y1+3); cdCanvasLine(ih->data->cd_canvas, x1+1, y1+4, x1+3, y1+4); cdCanvasForeground(ih->data->cd_canvas, ih->data->mid_shadow); cdCanvasLine(ih->data->cd_canvas, x1+1, y1, x1+4, y1); cdCanvasLine(ih->data->cd_canvas, x1+4, y1, x1+4, y1+3); cdCanvasForeground(ih->data->cd_canvas, ih->data->dark_shadow); cdCanvasLine(ih->data->cd_canvas, x1+2, y1, x1+3, y1); cdCanvasLine(ih->data->cd_canvas, x1+4, y1+1, x1+4, y1+2); }
/************************************************************\ * Gera um plasma de todos os valores de h em um circulo. * \************************************************************/ void hls_hplasma(int iw, int ih, int cl, uchar *ur, uchar *ug, uchar *ub) { int i, j; float h; float fr, fg, fb; int r, g, b; long int os; int x, y; float x1, y1, x2, y2; int rd; int rs, rb; cdCanvas *rgb; char buf[200]; sprintf(buf, "%dx%d %p %p %p", iw, ih, ur, ug, ub); rgb = cdCreateCanvas(CD_IMAGERGB, buf); /* desenha o plasma */ os = 0; for (i = 0; i < ih; i++) { for (j = 0; j < iw; j++) { x = iw/2 - j; y = ih/2 - i; rd = sq(x) + sq(y); rb = sq(iw/2); rs = sq(iw/2 - cl); if ((rd < rb) && (rd > rs)) {; h = (float) (atan2(i - ih/2, j - iw/2) * pi_180); hls_hls2rgb(h, 0.5f, 1.0f, &fr, &fg, &fb); r = (int) (fr * 255.0f); g = (int) (fg * 255.0f); b = (int) (fb * 255.0f); ur[os + j] = touchar(r); ug[os + j] = touchar(g); ub[os + j] = touchar(b); } else { ur[os + j] = shade_r; ug[os + j] = shade_g; ub[os + j] = shade_b; } } os += iw; } /* desenha marcaccoes de 60 em 60 */ cdCanvasForeground(rgb, cdEncodeColor(shade_dr, shade_dg, shade_db)); x1 = 0.0f; y1 = ih/2.0f; x2 = 6.0f; y2 = ih/2.0f; cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); rot(&x1, &y1, &x2, &y2, ih); cdCanvasForeground(rgb, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); rot(&x1, &y1, &x2, &y2, ih); cdCanvasForeground(rgb, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); rot(&x1, &y1, &x2, &y2, ih); cdCanvasForeground(rgb, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); rot(&x1, &y1, &x2, &y2, ih); cdCanvasForeground(rgb, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); rot(&x1, &y1, &x2, &y2, ih); cdCanvasLine(rgb, (int) x1, (int) y1, (int) x2, (int) y2); /* desenha a borda */ cdCanvasForeground(rgb, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasArc(rgb, iw/2, iw/2, iw, iw, 45.0, 225.0); cdCanvasForeground(rgb, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasArc(rgb, iw/2, iw/2, iw, iw, 225.0, 45.0); cdCanvasForeground(rgb, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasArc(rgb, iw/2, iw/2, iw-2*cl, iw-2*cl, 45.0, 225.0); cdCanvasForeground(rgb, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasArc(rgb, iw/2, iw/2, iw-2*cl, iw-2*cl, 225.0, 45.0); cdKillCanvas(rgb); }
void SimpleDrawAll(cdCanvas* canvas) { int w, h; cdCanvasGetSize(canvas, &w, &h, NULL, NULL); /* Clear the background to be white */ cdCanvasBackground(canvas, CD_WHITE); // cdBackground(CD_GREEN); cdCanvasClear(canvas); /* Draw a reactangle and a polyline at the bottom-left area, using a thick line with transparency. Observe that transparency is only supported in a few drivers, and line join is not supported in the IMAGERGB driver. */ cdCanvasLineWidth(canvas, 3); cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasForeground(canvas, cdEncodeAlpha(CD_DARK_MAGENTA, 128)); cdCanvasRect(canvas, 100, 200, 100, 200); cdCanvasBegin(canvas, CD_OPEN_LINES); cdCanvasVertex(canvas, 300, 250); cdCanvasVertex(canvas, 320, 270); cdCanvasVertex(canvas, 350, 260); cdCanvasVertex(canvas, 340, 200); cdCanvasVertex(canvas, 310, 210); cdCanvasEnd(canvas); /* Draw the red diagonal line with a custom line style. Observe that line styles are not supported in the IMAGERGB driver. */ cdCanvasForeground(canvas, CD_RED); cdCanvasLineWidth(canvas, 3); { int dashes[] = {20, 15, 5, 5}; cdCanvasLineStyleDashes(canvas, dashes, 4); } cdCanvasLineStyle(canvas, CD_CUSTOM); cdCanvasLine(canvas, 0, 0, w-1, h-1); /* Draw the blue diagonal line with a pre-defined line style. Observe that the pre-defined line style is dependent on the driver. */ cdCanvasForeground(canvas, CD_BLUE); cdCanvasLineWidth(canvas, 10); cdCanvasLineStyle(canvas, CD_DOTTED); cdCanvasLine(canvas, 0, h-1, w-1, 0); switch(clipping) { case CD_CLIPOFF: cdCanvasClip(canvas, CD_CLIPOFF); break; case CD_CLIPAREA: /* Defines the clipping area equals the canvas area minus a 100 pixels margin. */ cdCanvasClipArea(canvas, 100, w - 100, 100, h - 100); cdCanvasClip(canvas, CD_CLIPAREA); break; case CD_CLIPPOLYGON: cdCanvasBegin(canvas, CD_CLIP); cdCanvasVertex(canvas, 100, 100); cdCanvasVertex(canvas, w - 100, 100); cdCanvasVertex(canvas, w / 2, h - 100); cdCanvasEnd(canvas); cdCanvasClip(canvas, CD_CLIPPOLYGON); break; case CD_CLIPREGION: cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasFont(canvas, "Times", CD_BOLD, 50); cdCanvasBegin(canvas, CD_REGION); cdCanvasRegionCombineMode(canvas, CD_UNION); cdCanvasBox(canvas, 100, 200, 100, 200); cdCanvasSector(canvas, w/2-50, h/2+50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2-50, h/2-50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2+50, h/2+50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2+50, h/2-50, 150, 150, 0, 360); cdCanvasRegionCombineMode(canvas, CD_DIFFERENCE); cdCanvasText(canvas, w/2, h/2, "TEXT"); cdCanvasEnd(canvas); // cdCanvasOffsetRegion(canvas, -50, 50); cdCanvasClip(canvas, CD_CLIPREGION); cdCanvasForeground(canvas, CD_DARK_RED); cdCanvasBox(canvas, 0,w,0,h); break; } switch(write_mode) { case CD_REPLACE: cdCanvasWriteMode(canvas, CD_REPLACE); break; case CD_XOR: cdCanvasWriteMode(canvas, CD_XOR); break; case CD_NOT_XOR: cdCanvasWriteMode(canvas, CD_NOT_XOR); break; } if (use_transform) { cdCanvasTransform(canvas, NULL); cdCanvasTransformTranslate(canvas, w/2, h/2); cdCanvasTransformRotate(canvas, 30); cdCanvasTransformScale(canvas, 0.5, 0.5); cdCanvasTransformTranslate(canvas, -w/2, -h/2); } // cdSetfAttribute("ROTATE", "15 %d %d", w/2, h/2); /* Reset line style and width */ cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasLineWidth(canvas, 1); // cdBackOpacity(CD_TRANSPARENT); /* Draw an arc at bottom-left, and a sector at bottom-right. Notice that counter-clockwise orientation of both. */ cdCanvasInteriorStyle(canvas, CD_SOLID); cdCanvasForeground(canvas, CD_MAGENTA); cdCanvasSector(canvas, w-100, 100, 100, 100, 50, 180); cdCanvasForeground(canvas, CD_RED); cdCanvasArc(canvas, 100, 100, 100, 100, 50, 180); /* Draw a solid filled rectangle at center. */ cdCanvasForeground(canvas, CD_YELLOW); cdCanvasBox(canvas, w/2 - 100, w/2 + 100, h/2 - 100, h/2 + 100); /* Prepare font for text. */ cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasTextOrientation(canvas, 70); cdCanvasFont(canvas, "Times", CD_BOLD, 24); /* Draw text at center, with orientation, and draw its bounding box. Notice that in some drivers the bounding box is not precise. */ { int rect[8]; cdCanvasGetTextBounds(canvas, w/2, h/2, "Simple Draw (pçãí)", rect); cdCanvasForeground(canvas, CD_RED); cdCanvasBegin(canvas, CD_CLOSED_LINES); cdCanvasVertex(canvas, rect[0], rect[1]); cdCanvasVertex(canvas, rect[2], rect[3]); cdCanvasVertex(canvas, rect[4], rect[5]); cdCanvasVertex(canvas, rect[6], rect[7]); cdCanvasEnd(canvas); } cdCanvasForeground(canvas, CD_BLUE); cdCanvasText(canvas, w/2, h/2, "Simple Draw (pçãí)"); cdCanvasTextOrientation(canvas, 0); /* Prepare World Coordinates */ wdCanvasViewport(canvas, 0,w-1,0,h-1); if (w>h) wdCanvasWindow(canvas, 0,(double)w/(double)h,0,1); else wdCanvasWindow(canvas, 0,1,0,(double)h/(double)w); /* Draw a filled blue rectangle in WC */ wdCanvasBox(canvas, 0.20, 0.30, 0.40, 0.50); cdCanvasForeground(canvas, CD_RED); /* Draw the diagonal of that rectangle in WC */ wdCanvasLine(canvas, 0.20, 0.40, 0.30, 0.50); // wdVectorTextDirection(0, 0, 1, 1); /* Prepare Vector Text in WC. */ wdCanvasVectorCharSize(canvas, 0.07); // wdVectorText(0.1, 0.4, "ñç áéíóú àèìòù âêîôû äëïöü"); // wdVectorText(0.1, 0.2, "ÑÇ ÁÉÍÓÚ ÀÈÌÒÙ ÂÊÎÔÛ ÄËÏÖÜ"); //{ // int i; // char t[2]; // char s[10]; // int x = 20; // int y = 0; // t[1] = 0; // for (i = 0; i < 256; i++) // { // int dx = 90; // t[0] = (char)i; // sprintf(s, "%d", i); // cdText(x, y, s); // cdText(x+dx, y, t); // cdVectorText(x+2*dx, y, t); // // x += 3*dx + 2*dx/3; // if ((i+1) % 7 == 0) // { // x = 20; // y += 90; // } // } //} /* Draw vector text, and draw its bounding box. We also use this text to show when we are using a contextplus driver. */ { double rect[8]; cdCanvasForeground(canvas, CD_RED); if (contextplus) wdCanvasGetVectorTextBounds(canvas, "WDj-Plus", 0.25, 0.35, rect); else wdCanvasGetVectorTextBounds(canvas, "WDj", 0.25, 0.35, rect); cdCanvasBegin(canvas, CD_CLOSED_LINES); wdCanvasVertex(canvas, rect[0], rect[1]); wdCanvasVertex(canvas, rect[2], rect[3]); wdCanvasVertex(canvas, rect[4], rect[5]); wdCanvasVertex(canvas, rect[6], rect[7]); cdCanvasEnd(canvas); cdCanvasLineWidth(canvas, 2); cdCanvasLineStyle(canvas, CD_CONTINUOUS); if (contextplus) wdCanvasVectorText(canvas, 0.25, 0.35, "WDj-Plus"); else wdCanvasVectorText(canvas, 0.25, 0.35, "WDj"); cdCanvasLineWidth(canvas, 1); } /* Draw a filled path at center-right (looks like a weird fish). Notice that in PDF the arc is necessarily a circle arc, and not an ellipse. */ cdCanvasForeground(canvas, CD_GREEN); cdCanvasBegin(canvas, CD_PATH); cdCanvasPathSet(canvas, CD_PATH_MOVETO); cdCanvasVertex(canvas, w/2 + 200, h/2); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2 + 230, h/2 + 50); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2 + 250, h/2 + 50); cdCanvasPathSet(canvas, CD_PATH_CURVETO); cdCanvasVertex(canvas, w/2+150+150, h/2+200-50); /* control point for start */ cdCanvasVertex(canvas, w/2+150+180, h/2+250-50); /* control point for end */ cdCanvasVertex(canvas, w/2+150+180, h/2+200-50); /* end point */ cdCanvasPathSet(canvas, CD_PATH_CURVETO); cdCanvasVertex(canvas, w/2+150+180, h/2+150-50); cdCanvasVertex(canvas, w/2+150+150, h/2+100-50); cdCanvasVertex(canvas, w/2+150+300, h/2+100-50); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2+150+300, h/2-50); cdCanvasPathSet(canvas, CD_PATH_ARC); cdCanvasVertex(canvas, w/2+300, h/2); /* center */ cdCanvasVertex(canvas, 200, 100); /* width, height */ cdCanvasVertex(canvas, -30*1000, -170*1000); /* start angle, end angle (degrees / 1000) */ // cdCanvasPathSet(canvas, CD_PATH_CLOSE); // cdCanvasPathSet(canvas, CD_PATH_STROKE); cdCanvasPathSet(canvas, CD_PATH_FILL); // cdCanvasPathSet(canvas, CD_PATH_FILLSTROKE); cdCanvasEnd(canvas); /* Draw 3 pixels at center left. */ cdCanvasPixel(canvas, 10, h/2+0, CD_RED); cdCanvasPixel(canvas, 11, h/2+1, CD_GREEN); cdCanvasPixel(canvas, 12, h/2+2, CD_BLUE); /* Draw 4 mark types, distributed near each corner. */ cdCanvasForeground(canvas, CD_RED); cdCanvasMarkSize(canvas, 30); cdCanvasMarkType(canvas, CD_PLUS); cdCanvasMark(canvas, 200, 200); cdCanvasMarkType(canvas, CD_CIRCLE); cdCanvasMark(canvas, w - 200, 200); cdCanvasMarkType(canvas, CD_HOLLOW_CIRCLE); cdCanvasMark(canvas, 200, h - 200); cdCanvasMarkType(canvas, CD_DIAMOND); cdCanvasMark(canvas, w - 200, h - 200); /* Draw all the line style possibilities at bottom. Notice that they have some small differences between drivers. */ cdCanvasLineWidth(canvas, 1); cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasLine(canvas, 0, 10, w, 10); cdCanvasLineStyle(canvas, CD_DASHED); cdCanvasLine(canvas, 0, 20, w, 20); cdCanvasLineStyle(canvas, CD_DOTTED); cdCanvasLine(canvas, 0, 30, w, 30); cdCanvasLineStyle(canvas, CD_DASH_DOT); cdCanvasLine(canvas, 0, 40, w, 40); cdCanvasLineStyle(canvas, CD_DASH_DOT_DOT); cdCanvasLine(canvas, 0, 50, w, 50); /* Draw all the hatch style possibilities in the top-left corner. Notice that they have some small differences between drivers. */ cdCanvasHatch(canvas, CD_VERTICAL); cdCanvasBox(canvas, 0, 50, h - 60, h); cdCanvasHatch(canvas, CD_FDIAGONAL); cdCanvasBox(canvas, 50, 100, h - 60, h); cdCanvasHatch(canvas, CD_BDIAGONAL); cdCanvasBox(canvas, 100, 150, h - 60, h); cdCanvasHatch(canvas, CD_CROSS); cdCanvasBox(canvas, 150, 200, h - 60, h); cdCanvasHatch(canvas, CD_HORIZONTAL); cdCanvasBox(canvas, 200, 250, h - 60, h); cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBox(canvas, 250, 300, h - 60, h); /* Draw 4 regions, in diamond shape, at top, bottom, left, right, using different interior styles. */ /* At top, not filled polygon, notice that the last line style is used. */ cdCanvasBegin(canvas, CD_CLOSED_LINES); cdCanvasVertex(canvas, w/2, h - 100); cdCanvasVertex(canvas, w/2 + 50, h - 150); cdCanvasVertex(canvas, w/2, h - 200); cdCanvasVertex(canvas, w/2 - 50, h - 150); cdCanvasEnd(canvas); /* At left, hatch filled polygon */ cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, 100, h/2); cdCanvasVertex(canvas, 150, h/2 + 50); cdCanvasVertex(canvas, 200, h/2); cdCanvasVertex(canvas, 150, h/2 - 50); cdCanvasEnd(canvas); /* At right, pattern filled polygon */ cdCanvasPattern(canvas, STYLE_SIZE, STYLE_SIZE, pattern); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w - 100, h/2); cdCanvasVertex(canvas, w - 150, h/2 + 50); cdCanvasVertex(canvas, w - 200, h/2); cdCanvasVertex(canvas, w - 150, h/2 - 50); cdCanvasEnd(canvas); /* At bottom, stipple filled polygon */ cdCanvasStipple(canvas, STYLE_SIZE, STYLE_SIZE, stipple); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w/2, 100); cdCanvasVertex(canvas, w/2 + 50, 150); cdCanvasVertex(canvas, w/2, 200); cdCanvasVertex(canvas, w/2 - 50, 150); cdCanvasEnd(canvas); /* Draw two beziers at bottom-left */ cdCanvasBegin(canvas, CD_BEZIER); cdCanvasVertex(canvas, 100, 100); cdCanvasVertex(canvas, 150, 200); cdCanvasVertex(canvas, 180, 250); cdCanvasVertex(canvas, 180, 200); cdCanvasVertex(canvas, 180, 150); cdCanvasVertex(canvas, 150, 100); cdCanvasVertex(canvas, 300, 100); cdCanvasEnd(canvas); /* Initialize the image buffer contents */ //#define IMAGE_SIZE 16 memset(red, 0xFF, IMAGE_SIZE*IMAGE_SIZE/2); memset(green, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(blue, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(red+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(green+IMAGE_SIZE*IMAGE_SIZE/2, 0x8F, IMAGE_SIZE*IMAGE_SIZE/2); memset(blue+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(red+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(green+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(blue+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(red, 0, IMAGE_SIZE); memset(green, 0, IMAGE_SIZE); memset(blue, 0, IMAGE_SIZE); { int i, offset; for (i = 0; i < IMAGE_SIZE; i++) { offset = i*IMAGE_SIZE; red[offset] = 0; green[offset] = 0; blue[offset] = 0; red[offset+IMAGE_SIZE-1] = 0; green[offset+IMAGE_SIZE-1] = 0; blue[offset+IMAGE_SIZE-1] = 0; } } //cdSetAttribute("ANTIALIAS", "0"); // cdGetImageRGB(red, green, blue, w/2 - 50, h/2-50, 100, 100); // cdPutImageRectRGB(14, 13, red, green, blue, -20, -15, 649, 603, 0, 13, 0, 12); // cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 608, 608, 5, 10, 5, 10); // cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 64, 64, 5, 10, 5, 10); // cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE); // cdPutImageRGBA(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE); // cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE); /* Draw the image on the top-right corner but increasing its actual size, and uses its full area */ cdCanvasPutImageRectRGBA(canvas, IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE, 0, 0, 0, 0); cdCanvasSetAttribute(canvas, "ROTATE", NULL); if (use_transform) cdCanvasTransform(canvas, NULL); cdCanvasClip(canvas, CD_CLIPOFF); }
bool iupPlot::DrawLegend(const iupPlotRect &inRect, cdCanvas* canvas, iupPlotRect &ioPos) const { if (mLegend.mShow) { int ds; int theFontHeight; SetFont(canvas, mLegend.mFontStyle, mLegend.mFontSize); cdCanvasGetFontDim(canvas, NULL, &theFontHeight, NULL, NULL); int theMargin = theFontHeight / 2; if (mLegend.mPosition == IUP_PLOT_BOTTOMCENTER) theMargin = 0; int theTotalHeight = mDataSetListCount*theFontHeight + 2 * theMargin; int theLineSpace = 20; int theWidth, theMaxWidth = 0; for (ds = 0; ds < mDataSetListCount; ds++) { iupPlotDataSet* dataset = mDataSetList[ds]; cdCanvasGetTextSize(canvas, dataset->GetName(), &theWidth, NULL); if (dataset->mMode == IUP_PLOT_MARK || dataset->mMode == IUP_PLOT_MARKLINE) { if (dataset->mMarkSize + 6 > theLineSpace) theLineSpace = dataset->mMarkSize + 6; } theWidth += theLineSpace; if (theWidth > theMaxWidth) theMaxWidth = theWidth; } if (theMaxWidth == 0) return false; theMaxWidth += 2 * theMargin; if (mLegend.mPosition != IUP_PLOT_XY) { int theScreenX = inRect.mX; int theScreenY = inRect.mY; switch (mLegend.mPosition) { case IUP_PLOT_TOPLEFT: theScreenX += 2; theScreenY += inRect.mHeight - theTotalHeight - 2; break; case IUP_PLOT_BOTTOMLEFT: theScreenX += 2; theScreenY += 2; break; case IUP_PLOT_BOTTOMRIGHT: theScreenX += inRect.mWidth - theMaxWidth - 2; theScreenY += 2; break; case IUP_PLOT_BOTTOMCENTER: theScreenX += (inRect.mWidth - theMaxWidth) / 2; theScreenY = theFontHeight / 4; break; default: // IUP_PLOT_TOPRIGHT theScreenX += inRect.mWidth - theMaxWidth - 2; theScreenY += inRect.mHeight - theTotalHeight - 2; break; } ioPos.mX = theScreenX; ioPos.mY = theScreenY; } ioPos.mWidth = theMaxWidth; ioPos.mHeight = theTotalHeight; // Clip to the legend box cdCanvasClipArea(canvas, ioPos.mX, ioPos.mX + ioPos.mWidth - 1, ioPos.mY, ioPos.mY + ioPos.mHeight - 1); if (mLegend.mBoxShow) { cdCanvasSetForeground(canvas, mLegend.mBoxBackColor); iPlotDrawBox(canvas, ioPos.mX + 1, ioPos.mY + 1, ioPos.mWidth - 2, ioPos.mHeight - 2); cdCanvasSetForeground(canvas, mLegend.mBoxColor); iPlotSetLine(canvas, mLegend.mBoxLineStyle, mLegend.mBoxLineWidth); iPlotDrawRectI(canvas, ioPos.mX, ioPos.mY, ioPos.mWidth, ioPos.mHeight); } for (ds = 0; ds < mDataSetListCount; ds++) { iupPlotDataSet* dataset = mDataSetList[ds]; cdCanvasSetForeground(canvas, dataset->mColor); int theLegendX = ioPos.mX + theMargin; int theLegendY = ioPos.mY + (mDataSetListCount - 1 - ds)*theFontHeight + theMargin; theLegendY += theFontHeight / 2; if (dataset->mMode == IUP_PLOT_MARK || dataset->mMode == IUP_PLOT_MARKLINE) { iPlotSetMark(canvas, dataset->mMarkStyle, dataset->mMarkSize); cdCanvasMark(canvas, theLegendX + (theLineSpace - 3) / 2, theLegendY - theFontHeight / 8); } if (dataset->mMode != IUP_PLOT_MARK) { iPlotSetLine(canvas, dataset->mLineStyle, dataset->mLineWidth); cdCanvasLine(canvas, theLegendX, theLegendY - theFontHeight / 8, theLegendX + theLineSpace - 3, theLegendY - theFontHeight / 8); } iPlotDrawText(canvas, theLegendX + theLineSpace, theLegendY, CD_WEST, dataset->GetName()); } } return true; }
void cdSimMark(cdCanvas* canvas, int x, int y) { int oldinteriorstyle = canvas->interior_style; int oldlinestyle = canvas->line_style; int oldlinewidth = canvas->line_width; int size, half_size, bottom, top, left, right; if (canvas->mark_type == CD_DIAMOND || canvas->mark_type == CD_HOLLOW_DIAMOND) { if (canvas->use_origin) { x += canvas->origin.x; y += canvas->origin.y; } if (canvas->invert_yaxis) y = _cdInvertYAxis(canvas, y); } size = canvas->mark_size; half_size = size/2; bottom = y-half_size; top = y+half_size; left = x-half_size; right = x+half_size; if (canvas->interior_style != CD_SOLID && (canvas->mark_type == CD_CIRCLE || canvas->mark_type == CD_BOX || canvas->mark_type == CD_DIAMOND)) cdCanvasInteriorStyle(canvas, CD_SOLID); if (canvas->line_style != CD_CONTINUOUS && (canvas->mark_type == CD_STAR || canvas->mark_type == CD_PLUS || canvas->mark_type == CD_X || canvas->mark_type == CD_HOLLOW_BOX || canvas->mark_type == CD_HOLLOW_CIRCLE || canvas->mark_type == CD_HOLLOW_DIAMOND)) cdCanvasLineStyle(canvas, CD_CONTINUOUS); if (canvas->line_width != 1 && (canvas->mark_type == CD_STAR || canvas->mark_type == CD_PLUS || canvas->mark_type == CD_X || canvas->mark_type == CD_HOLLOW_BOX || canvas->mark_type == CD_HOLLOW_CIRCLE || canvas->mark_type == CD_HOLLOW_DIAMOND)) cdCanvasLineWidth(canvas, 1); switch (canvas->mark_type) { case CD_STAR: cdCanvasLine(canvas, left, bottom, right, top); cdCanvasLine(canvas, left, top, right, bottom); /* continue */ case CD_PLUS: cdCanvasLine(canvas, left, y, right, y); cdCanvasLine(canvas, x, bottom, x, top); break; case CD_X: cdCanvasLine(canvas, left, bottom, right, top); cdCanvasLine(canvas, left, top, right, bottom); break; case CD_HOLLOW_CIRCLE: cdCanvasArc(canvas, x, y, size, size, 0, 360); break; case CD_HOLLOW_BOX: cdCanvasRect(canvas, left, right, bottom, top); break; case CD_CIRCLE: cdCanvasSector(canvas, x, y, size, size, 0, 360); break; case CD_BOX: cdCanvasBox(canvas, left, right, bottom, top); break; case CD_HOLLOW_DIAMOND: case CD_DIAMOND: { /* Do not use Begin/End here so Mark can be used inside a regular BeginEnd loop */ cdPoint poly[5]; /* leave room for one more point */ poly[0].x = left; poly[0].y = y; poly[1].x = x; poly[1].y = top; poly[2].x = right; poly[2].y = y; poly[3].x = x; poly[3].y = bottom; if (canvas->mark_type == CD_DIAMOND) cdPoly(canvas, CD_FILL, poly, 4); else cdPoly(canvas, CD_CLOSED_LINES, poly, 4); } break; } if (canvas->interior_style != oldinteriorstyle && (canvas->mark_type == CD_CIRCLE || canvas->mark_type == CD_BOX || canvas->mark_type == CD_DIAMOND)) cdCanvasInteriorStyle(canvas, oldinteriorstyle); if (canvas->line_style != oldlinestyle && (canvas->mark_type == CD_STAR || canvas->mark_type == CD_PLUS || canvas->mark_type == CD_X || canvas->mark_type == CD_HOLLOW_BOX || canvas->mark_type == CD_HOLLOW_CIRCLE || canvas->mark_type == CD_HOLLOW_DIAMOND)) cdCanvasLineStyle(canvas, oldlinestyle); if (canvas->line_width != oldlinewidth && (canvas->mark_type == CD_STAR || canvas->mark_type == CD_PLUS || canvas->mark_type == CD_X || canvas->mark_type == CD_HOLLOW_BOX || canvas->mark_type == CD_HOLLOW_CIRCLE || canvas->mark_type == CD_HOLLOW_DIAMOND)) cdCanvasLineWidth(canvas, oldlinewidth); }
static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data) { tPrimNode *prim; cdCanvas* pic_canvas = (cdCanvas*)data; cdCtxCanvas* ctxcanvas = pic_canvas->ctxcanvas; int p, i, n, scale = 0, pic_xmin = ctxcanvas->xmin, pic_ymin = ctxcanvas->ymin; double factorX = 1, factorY = 1; if ((ctxcanvas->xmax-ctxcanvas->xmin+1)>1 && (ctxcanvas->ymax-ctxcanvas->ymin+1)>1 && (xmax-xmin+1)>1 && (ymax-ymin+1)>1) { scale = 1; factorX = ((double)(xmax-xmin+1)) / ((double)(ctxcanvas->xmax-ctxcanvas->xmin+1)); factorY = ((double)(ymax-ymin+1)) / ((double)(ctxcanvas->ymax-ctxcanvas->ymin+1)); } if (cdsizecb) { int err; err = cdsizecb(canvas, pic_canvas->w, pic_canvas->h, pic_canvas->w_mm, pic_canvas->h_mm); if (err) return CD_ERROR; } prim = ctxcanvas->prim_first; for (i = 0; i < ctxcanvas->prim_n; i++) { switch (prim->type) { case CDPIC_LINE: primUpdateAttrib_Line(prim, canvas); cdCanvasLine(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleY(prim->param.lineboxrect.y1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y2)); break; case CDPIC_FLINE: primUpdateAttrib_Line(prim, canvas); cdfCanvasLine(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleY(prim->param.lineboxrectf.y1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y2)); break; case CDPIC_RECT: primUpdateAttrib_Line(prim, canvas); cdCanvasRect(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y1), sScaleY(prim->param.lineboxrect.y2)); break; case CDPIC_FRECT: primUpdateAttrib_Line(prim, canvas); cdfCanvasRect(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y1), sfScaleY(prim->param.lineboxrectf.y2)); break; case CDPIC_BOX: primUpdateAttrib_Fill(prim, canvas); cdCanvasBox(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y1), sScaleY(prim->param.lineboxrect.y2)); break; case CDPIC_FBOX: primUpdateAttrib_Fill(prim, canvas); cdfCanvasBox(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y1), sfScaleY(prim->param.lineboxrectf.y2)); break; case CDPIC_ARC: primUpdateAttrib_Line(prim, canvas); cdCanvasArc(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_FARC: primUpdateAttrib_Line(prim, canvas); cdfCanvasArc(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_SECTOR: primUpdateAttrib_Fill(prim, canvas); cdCanvasSector(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_FSECTOR: primUpdateAttrib_Fill(prim, canvas); cdfCanvasSector(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_CHORD: primUpdateAttrib_Fill(prim, canvas); cdCanvasChord(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_FCHORD: primUpdateAttrib_Fill(prim, canvas); cdfCanvasChord(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2); break; case CDPIC_TEXT: primUpdateAttrib_Text(prim, canvas); cdCanvasText(canvas, sScaleX(prim->param.text.x), sScaleY(prim->param.text.y), prim->param.text.s); break; case CDPIC_FTEXT: primUpdateAttrib_Text(prim, canvas); cdfCanvasText(canvas, sfScaleX(prim->param.textf.x), sfScaleY(prim->param.textf.y), prim->param.text.s); break; case CDPIC_POLY: if (prim->param.poly.mode == CD_FILL) primUpdateAttrib_Fill(prim, canvas); else primUpdateAttrib_Line(prim, canvas); cdCanvasBegin(canvas, prim->param.poly.mode); for (p = 0; p < prim->param.poly.n; p++) cdCanvasVertex(canvas, sScaleX(prim->param.poly.points[p].x), sScaleY(prim->param.poly.points[p].y)); cdCanvasEnd(canvas); break; case CDPIC_FPOLY: if (prim->param.poly.mode == CD_FILL) primUpdateAttrib_Fill(prim, canvas); else primUpdateAttrib_Line(prim, canvas); cdCanvasBegin(canvas, prim->param.polyf.mode); for (p = 0; p < prim->param.polyf.n; p++) cdfCanvasVertex(canvas, sfScaleX(prim->param.polyf.points[p].x), sfScaleY(prim->param.polyf.points[p].y)); cdCanvasEnd(canvas); break; case CDPIC_PATH: if (prim->param.path.fill) primUpdateAttrib_Fill(prim, canvas); else primUpdateAttrib_Line(prim, canvas); cdCanvasBegin(canvas, CD_PATH); n = 0; for (p=0; p<prim->param.path.path_n; p++) { cdCanvasPathSet(canvas, prim->param.path.path[p]); switch(prim->param.path.path[p]) { case CD_PATH_MOVETO: case CD_PATH_LINETO: cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n].x), sScaleY(prim->param.path.points[n].y)); n++; break; case CD_PATH_CURVETO: case CD_PATH_ARC: { cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n].x), sScaleY(prim->param.path.points[n].y)); cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n+1].x), sScaleY(prim->param.path.points[n+1].y)); cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n+2].x), sScaleY(prim->param.path.points[n+2].y)); n += 3; } break; } } cdCanvasEnd(canvas); break; case CDPIC_FPATH: if (prim->param.path.fill) primUpdateAttrib_Fill(prim, canvas); else primUpdateAttrib_Line(prim, canvas); cdCanvasBegin(canvas, CD_PATH); n = 0; for (p=0; p<prim->param.pathf.path_n; p++) { cdCanvasPathSet(canvas, prim->param.pathf.path[p]); switch(prim->param.pathf.path[p]) { case CD_PATH_MOVETO: case CD_PATH_LINETO: cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n].x), sfScaleY(prim->param.pathf.points[n].y)); n++; break; case CD_PATH_CURVETO: case CD_PATH_ARC: { cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n].x), sfScaleY(prim->param.pathf.points[n].y)); cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n+1].x), sfScaleY(prim->param.pathf.points[n+1].y)); cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n+2].x), sfScaleY(prim->param.pathf.points[n+2].y)); n += 3; } break; } } cdCanvasEnd(canvas); break; case CDPIC_IMAGERGB: cdCanvasPutImageRectRGB(canvas, prim->param.imagergba.iw, prim->param.imagergba.ih, prim->param.imagergba.r, prim->param.imagergba.g, prim->param.imagergba.b, sScaleX(prim->param.imagergba.x), sScaleY(prim->param.imagergba.y), sScaleW(prim->param.imagergba.w), sScaleH(prim->param.imagergba.h), 0, 0, 0, 0); break; case CDPIC_IMAGERGBA: cdCanvasPutImageRectRGBA(canvas, prim->param.imagergba.iw, prim->param.imagergba.ih, prim->param.imagergba.r, prim->param.imagergba.g, prim->param.imagergba.b, prim->param.imagergba.a, sScaleX(prim->param.imagergba.x), sScaleY(prim->param.imagergba.y), sScaleW(prim->param.imagergba.w), sScaleH(prim->param.imagergba.h), 0, 0, 0, 0); break; case CDPIC_IMAGEMAP: cdCanvasPutImageRectMap(canvas, prim->param.imagemap.iw, prim->param.imagemap.ih, prim->param.imagemap.index, prim->param.imagemap.colors, sScaleX(prim->param.imagemap.x), sScaleY(prim->param.imagemap.y), sScaleW(prim->param.imagemap.w), sScaleH(prim->param.imagemap.h), 0, 0, 0, 0); break; case CDPIC_PIXEL: cdCanvasPixel(canvas, sScaleX(prim->param.pixel.x), sScaleY(prim->param.pixel.y), prim->param.pixel.color); break; } prim = prim->next; } return CD_OK; }
static void iColorBrowserRenderImageHue(Ihandle* ih) { int x, y, active = 1; unsigned char *red, *green, *blue; unsigned char bg_red, bg_green, bg_blue; if (!ih->data->cddbuffer) return; cdCanvasBackground(ih->data->cddbuffer, ih->data->bgcolor); cdCanvasClear(ih->data->cddbuffer); if (!iupdrvIsActive(ih)) active = 0; if (ih->data->has_focus) cdDrawFocusRect(ih->data->cddbuffer, 0, 0, ih->data->w-1, ih->data->h-1); red = cdRedImage(ih->data->cddbuffer); green = cdGreenImage(ih->data->cddbuffer); blue = cdBlueImage(ih->data->cddbuffer); cdDecodeColor(ih->data->bgcolor, &bg_red, &bg_green, &bg_blue); for (y = 0; y < ih->data->h; y++) { float sx_max = iColorBrowserSXmax(ih, y); for (x = 0; x < ih->data->w; x++) { int xl, yl; float radius, diff1, diff2; if (y > ih->data->Iy1 && y < ih->data->Iy2 && x > ih->data->Ix && x < ih->data->Ix+(int)sx_max) continue; xl = x - ih->data->xc; yl = y - ih->data->yc; radius = sqrtf(xl*xl + yl*yl); diff1 = radius - (ih->data->R-ICB_SPACE-ICB_HUEWIDTH); diff2 = (ih->data->R-ICB_SPACE) - radius; if (diff1>0 && diff2>0) { float h, s, i; int offset = y*ih->data->w + x; unsigned char* r = red + offset; unsigned char* g = green + offset; unsigned char* b = blue + offset; h = atan2f(yl, xl); h = (float)(h * CD_RAD2DEG); s = 1.0f; /* maximum saturation */ i = 0.5f; /* choose I where S is maximum */ iupColorHSI2RGB(h, s, i, r, g, b); if (diff1<1 || diff2<1) /* anti-aliasing */ { float diff = (float)(diff1<1? diff1: diff2); *r = (unsigned char)((*r)*diff + bg_red*(1.0f-diff)); *g = (unsigned char)((*g)*diff + bg_green*(1.0f-diff)); *b = (unsigned char)((*b)*diff + bg_blue*(1.0f-diff)); } if (!active) { *r = cdIupLIGTHER(*r); *g = cdIupLIGTHER(*g); *b = cdIupLIGTHER(*b); } } } } if (active) { float x1, x2, y1, y2; unsigned char shade_lr, shade_lg, shade_lb, shade_dr, shade_dg, shade_db; shade_dr = (unsigned char)((2 * bg_red) / 3); shade_dg = (unsigned char)((2 * bg_green) / 3); shade_db = (unsigned char)((2 * bg_blue) / 3); shade_lr = (unsigned char)((255 + bg_red) / 2); shade_lg = (unsigned char)((255 + bg_green) / 2); shade_lb = (unsigned char)((255 + bg_blue) / 2); cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db)); x1 = (float)(ih->data->xc-ih->data->R+ICB_SPACE); y1 = (float)ih->data->yc; x2 = (float)(x1+ICB_HUEWIDTH/2); y2 = (float)ih->data->yc; cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc); cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc); cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc); cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_lr, shade_lg, shade_lb)); cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc); cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db)); cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc); cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2); } }
void SimpleDrawTest(cdCanvas* canvas) //void SimpleDrawMainTest(cdCanvas* canvas) { long pattern[16]; /* 4x4 pattern */ int w, h; int xmin, xmax, ymin, ymax; /* notice that if we are not using world coordinates it is harder to position all the objetcs we want. */ cdCanvasGetSize(canvas, &w, &h, 0, 0); cdCanvasBackground(canvas, CD_WHITE); cdCanvasClear(canvas); /* pattern initialization */ pattern[0] = CD_RED; pattern[1] = CD_RED; /* first line */ pattern[2] = CD_YELLOW; pattern[3] = CD_YELLOW; pattern[4] = CD_RED; pattern[5] = CD_RED; /* second line */ pattern[6] = CD_YELLOW; pattern[7] = CD_YELLOW; pattern[8] = CD_YELLOW; pattern[9] = CD_YELLOW; /* third line */ pattern[10] = CD_YELLOW; pattern[11] = CD_YELLOW; pattern[12] = CD_YELLOW; pattern[13] = CD_YELLOW; /* fourth line */ pattern[14] = CD_YELLOW; pattern[15] = CD_YELLOW; /* set the line attributes */ cdCanvasLineWidth(canvas, 4); cdCanvasLineStyle(canvas, CD_CONTINUOUS); /* in the center draw a pattern pizza with a slice mising */ cdCanvasPattern(canvas, 4, 4, pattern); cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0); /* draws a dark red border */ cdCanvasForeground(canvas, CD_DARK_RED); cdCanvasInteriorStyle(canvas, CD_HOLLOW); cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0); /* on the left a red hash diamond */ /* notice the the default back opacity is transparent and the pattern of the sector will still be visible inside the hatch where the two objects intersect */ cdCanvasForeground(canvas, CD_RED); cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w/4, h/4); cdCanvasVertex(canvas, w/2-w/8, h/2); cdCanvasVertex(canvas, w/4, 3*h/4); cdCanvasVertex(canvas, w/8, h/2); cdCanvasEnd(canvas); /* draws a blue roof.*/ cdCanvasForeground(canvas, CD_BLUE); cdCanvasLine(canvas, w/8, h/2, w/4, 3*h/4); cdCanvasLine(canvas, w/4, 3*h/4, w/2-w/8, h/2); /* draws a dashed ribbon on the right with a custom color */ cdCanvasForeground(canvas, cdEncodeColor(100, 25, 200)); cdCanvasLineStyle(canvas, CD_DASH_DOT); cdCanvasBegin(canvas, CD_BEZIER); cdCanvasVertex(canvas, 3*w/4-20, h/2-50); cdCanvasVertex(canvas, 3*w/4+150, 3*h/4-50); cdCanvasVertex(canvas, 3*w/4-150, 3*h/4-50); cdCanvasVertex(canvas, 3*w/4+20, h/2-50); cdCanvasEnd(canvas); cdCanvasFont(canvas, "Helvetica", CD_BOLD, 40); cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasText(canvas, w/2, h/4-50, "Canvas Draw"); cdCanvasGetTextBox(canvas, w/2, h/4-50, "Canvas Draw", &xmin, &xmax, &ymin, &ymax); cdCanvasRect(canvas, xmin, xmax, ymin, ymax); }
/* Make the scroll of a number of columns to the left or right side or lines on top or down, using the ScrollImage primitive. To the left, just move one column - to the right, can move more than one. On top, just move only one column - on down, can move more than one. -> dir : [IMAT_SCROLL_LEFT| IMAT_SCROLL_RIGHT | IMAT_SCROLL_UP | IMAT_SCROLL_DOWN] -> ref : First column/line to be redrawn when the move is to right or on down. -> num : Number of columns/lines to be moved, when the move is to right or on down. */ void iupMatrixScroll(Ihandle* ih, int dir, int ref, int num) { int x1, x2, y1, y2, xt2, yt2; int i; x1 = 0; x2 = ih->data->XmaxC; y1 = 0; y2 = ih->data->YmaxC; ih->data->redraw = 1; if(dir == IMAT_SCROLL_LEFT) { x1 = ih->data->col.titlewh; /* skip the line title */ x2 -= ih->data->col.wh[ih->data->col.first]; if(x1 >= x2) { iupMatrixDrawMatrix(ih, IMAT_DRAW_COL); return; } cdCanvasScrollArea(ih->data->cddbuffer, x1, x2, y1, y2, ih->data->col.wh[ih->data->col.first], 0); iupMatrixDrawColumnTitle(ih, ih->data->col.first, ih->data->col.first); iupMatrixCDSetCdFrameColor(ih); cdCanvasLine(ih->data->cddbuffer, ih->data->XmaxC, y1, ih->data->XmaxC, y2); iupMatrixDrawCells(ih, ih->data->lin.first, ih->data->col.first, ih->data->lin.last, ih->data->col.first); } else if(dir == IMAT_SCROLL_UP) { y2 -= ih->data->lin.titlewh; /* skip the column title */ y1 += ih->data->lin.wh[ih->data->lin.first]; if(y1 >= y2) { iupMatrixDrawMatrix(ih, IMAT_DRAW_LIN); return; } cdCanvasScrollArea(ih->data->cddbuffer, x1, x2, y1, y2, 0, -ih->data->lin.wh[ih->data->lin.first]); iupMatrixDrawLineTitle(ih, ih->data->lin.first, ih->data->lin.first); iupMatrixDrawCells(ih, ih->data->lin.first, ih->data->col.first, ih->data->lin.first, ih->data->col.last); } else if(dir == IMAT_SCROLL_RIGHT) { x1 = ih->data->col.titlewh; /* skip the line title */ for(i = 1; i <= num; i++) x1 += ih->data->col.wh[ih->data->col.first-i]; if(x1 >= x2) { iupMatrixDrawMatrix(ih, IMAT_DRAW_COL); return; } cdCanvasScrollArea(ih->data->cddbuffer, x1, x2/*-1*/, y1, y2, ih->data->col.titlewh-x1, 0); xt2 = iupMatrixDrawColumnTitle(ih, ref, ih->data->col.last); if(xt2 < x2) /* clear the right area that doesn't have column */ { iupMatrixDrawEmptyArea(ih, xt2, x2, y1, y2); } else { iupMatrixCDSetCdFrameColor(ih); cdCanvasLine(ih->data->cddbuffer, x2, y1, x2, y2); } /* draw the cells */ iupMatrixDrawCells(ih, ih->data->lin.first, ref, ih->data->lin.last, ih->data->col.last); } else if(dir == IMAT_SCROLL_DOWN) { y2 -= ih->data->lin.titlewh; /* skip the column title */ for(i = 1; i <= num; i++) y2 -= ih->data->lin.wh[ih->data->lin.first-i]; if(y1 >= y2) { iupMatrixDrawMatrix(ih, IMAT_DRAW_LIN); return; } cdCanvasScrollArea(ih->data->cddbuffer, x1, x2/*-1*/, y1, y2, 0, ih->data->YmaxC-ih->data->lin.titlewh-y2); yt2 = iupMatrixDrawLineTitle(ih, ref, ih->data->lin.last); if(yt2 < y1) /* clear the right area that doesn't have column */ { iupMatrixDrawEmptyArea(ih, x1, x2, y1, yt2); } else { iupMatrixCDSetCdFrameColor(ih); cdCanvasLine(ih->data->cddbuffer, x1, y1, x2, y1); } /* desenha as celulas */ iupMatrixDrawCells(ih, ref, ih->data->col.first, ih->data->lin.last, ih->data->col.last); } }
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; }