static int iMatrixDrawCallDrawCB(Ihandle* ih, int lin, int col, int x1, int x2, int y1, int y2, IFniiiiiiC draw_cb) { int ret; cdCanvas* old_cnv; IUPMAT_CLIPAREA(ih, x1, x2, y1, y2); cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); old_cnv = cdActiveCanvas(); if (old_cnv != ih->data->cddbuffer) /* backward compatibility code */ cdActivate(ih->data->cddbuffer); ret = draw_cb(ih, lin, col, x1, x2, iupMatrixInvertYAxis(ih, y1), iupMatrixInvertYAxis(ih, y2), ih->data->cddbuffer); cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF); if (old_cnv && old_cnv != ih->data->cddbuffer) /* backward compatibility code */ { cdActivate(old_cnv); cdCanvasActivate(ih->data->cddbuffer); } if (ret == IUP_DEFAULT) return 0; return 1; }
static void iMatrixDrawSetCellClipping(Ihandle* ih, int x1, int x2, int y1, int y2) { int old_clip = cdCanvasClip(ih->data->cddbuffer, CD_QUERY); if (old_clip == CD_CLIPAREA) { cdCanvasGetClipArea(ih->data->cddbuffer, &(ih->data->clip_x1), &(ih->data->clip_x2), &(ih->data->clip_y1), &(ih->data->clip_y2)); y1 = iupMATRIX_INVERTYAXIS(ih, y1); y2 = iupMATRIX_INVERTYAXIS(ih, y2); if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } if (x1 < ih->data->clip_x1) x1 = ih->data->clip_x1; if (x2 > ih->data->clip_x2) x2 = ih->data->clip_x2; if (y1 < ih->data->clip_y1) y1 = ih->data->clip_y1; if (y2 > ih->data->clip_y2) y2 = ih->data->clip_y2; cdCanvasClipArea(ih->data->cddbuffer, x1, x2, y1, y2); cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); } }
void iupPlot::DrawBackground(cdCanvas* canvas) const { cdCanvasOrigin(canvas, 0, 0); cdCanvasClip(canvas, CD_CLIPOFF); cdCanvasSetForeground(canvas, mBack.mColor); cdCanvasBox(canvas, mViewportBack.mX, mViewportBack.mX + mViewportBack.mWidth - 1, mViewportBack.mY, mViewportBack.mY + mViewportBack.mHeight - 1); }
static void _wdHdcpyDoit(cdCanvas *canvas, cdCanvas *canvas_copy, void (*draw_func)(cdCanvas *canvas_copy)) { cdCanvas *old_active; double left, right, bottom, top; /* canvas visualization window */ int canvas_hsize, canvas_vsize; /* canvas sizes in pixels */ int hdcpy_hsize, hdcpy_vsize; /* paper sizes in points */ double canvas_vpr; /* canvas viewport distortion ratio */ double hdcpy_vpr; /* paper viewport distortion ratio */ int xc, yc; /* paper center in pixels */ int xmin, xmax, ymin, ymax; /* paper viewport */ /* Activate canvas visualization surface. */ if (cdCanvasActivate(canvas) != CD_OK) return; /* Get current canvas window parameters and sizes. */ wdCanvasGetWindow(canvas, &left, &right, &bottom, &top); cdCanvasGetSize(canvas, &canvas_hsize, &canvas_vsize, 0L, 0L); /* Activate hardcopy visualization surface. */ if (cdCanvasActivate(canvas_copy) != CD_OK) return; /* Set window parameters on hardcopy surface. */ wdCanvasWindow(canvas_copy, left, right, bottom, top); /* Adjust paper viewport, centralized, matching canvas viewport. */ canvas_vpr = (double)canvas_vsize / (double)canvas_hsize; cdCanvasGetSize(canvas_copy, &hdcpy_hsize, &hdcpy_vsize, 0L, 0L); hdcpy_vpr = (double)hdcpy_vsize / (double)hdcpy_hsize; xc = (int)((double)hdcpy_hsize/2.0); yc = (int)((double)hdcpy_vsize/2.0); if (canvas_vpr < hdcpy_vpr) { xmin = 0; xmax = hdcpy_hsize; ymin = yc - (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0); ymax = yc + (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0); } else { xmin = xc - (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0); xmax = xc + (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0); ymin = 0; ymax = hdcpy_vsize; } cdCanvasClipArea(canvas_copy, xmin, xmax, ymin, ymax); cdCanvasClip(canvas_copy, CD_CLIPAREA); wdCanvasViewport(canvas_copy, xmin, xmax, ymin, ymax); /* for backward compatibility */ old_active = cdActiveCanvas(); cdActivate(canvas_copy); /* Draw on hardcopy surface. */ draw_func(canvas_copy); if (old_active) cdActivate(old_active); }
void iupPlot::DrawInactive(cdCanvas* canvas) const { cdCanvasOrigin(canvas, 0, 0); cdCanvasClip(canvas, CD_CLIPOFF); long inactive_color = cdEncodeAlpha(CD_GRAY, 96); cdCanvasSetForeground(canvas, inactive_color); cdCanvasBox(canvas, mViewportBack.mX, mViewportBack.mX + mViewportBack.mWidth - 1, mViewportBack.mY, mViewportBack.mY + mViewportBack.mHeight - 1); }
static int iMatrixDrawCallDrawCB(Ihandle* ih, int cor, int lin, int col, int x1, int x2, int y1, int y2) { IFniiiiiiC cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); if(cb) { int ret; cdCanvas* old_cnv = cdActiveCanvas(); if(cor == IMAT_TITLE_COLOR) { x1+=1; x2-=1; y1+=1; y2-=1; } else if(!iupAttribGetInt(ih, "HIDEFOCUS")) { x1+=2; x2-=2; y1+=2; y2-=2; } CdClipArea(x1, x2, y1, y2); cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); if(old_cnv != ih->data->cddbuffer) /* backward compatibility code */ cdActivate(ih->data->cddbuffer); ret = cb(ih, lin, col, x1, x2, (ih->data->YmaxC - (y1)), INVY(y2), ih->data->cddbuffer); cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF); if(old_cnv && old_cnv != ih->data->cddbuffer) { cdActivate(old_cnv); cdCanvasActivate(ih->data->cddbuffer); } if (ret == IUP_DEFAULT) return 0; } return 1; }
static void iGaugeDrawText(Ihandle* ih, int xmid) { int x, y, xmin, xmax, ymin, ymax; char* text = ih->data->text; cdIupSetFont(ih, ih->data->cddbuffer, IupGetAttribute(ih, "FONT")); cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER); cdCanvasBackOpacity(ih->data->cddbuffer, CD_TRANSPARENT); x = (int)(0.5 * ih->data->w); y = (int)(0.5 * ih->data->h); if(text == NULL) { char* m = iupStrGetMemory(30); sprintf(m, "%.1f%%", 100 * (ih->data->value - ih->data->vmin) / (ih->data->vmax - ih->data->vmin)); text = m; } cdCanvasGetTextBox(ih->data->cddbuffer, x, y, text, &xmin, &xmax, &ymin, &ymax); if(xmid < xmin) { cdCanvasForeground(ih->data->cddbuffer, ih->data->fgcolor); cdCanvasText(ih->data->cddbuffer, x, y, text); } else if(xmid > xmax) { cdCanvasForeground(ih->data->cddbuffer, ih->data->bgcolor); cdCanvasText(ih->data->cddbuffer, x, y, text); } else { cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); cdCanvasClipArea(ih->data->cddbuffer, xmin, xmid, ymin, ymax); cdCanvasForeground(ih->data->cddbuffer, ih->data->bgcolor); cdCanvasText(ih->data->cddbuffer, x, y, text); cdCanvasClipArea(ih->data->cddbuffer, xmid, xmax, ymin, ymax); cdCanvasForeground(ih->data->cddbuffer, ih->data->fgcolor); cdCanvasText(ih->data->cddbuffer, x, y, text); cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF); } }
/* Function used to call the client; is used when a cell must be repainted. */ static void iCellsCallDrawCb(Ihandle* ih, int xmin, int xmax, int ymin, int ymax, int i, int j) { int oldxmin, oldxmax, oldymin, oldymax, oldclip; int w = ih->data->w; int h = ih->data->h; IFniiiiiiC draw_cb; cdCanvas* old_cnv = cdActiveCanvas(); /* Getting clipping area for post restore */ oldclip = cdCanvasClip(ih->data->cd_canvas, CD_QUERY); cdCanvasGetClipArea(ih->data->cd_canvas, &oldxmin, &oldxmax, &oldymin, &oldymax); if (ih->data->clipped) /* Clipping the cell area */ { int cxmin, cxmax, cymin, cymax; cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); cxmin = xmin < 0 ? 0 : xmin; cymin = ymin < 0 ? 0 : ymin; cxmax = xmax > w ? w : xmax; cymax = ymax > h ? h : ymax; cdCanvasClipArea(ih->data->cd_canvas, cxmin, cxmax, cymin, cymax); } draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); if (draw_cb) { if (old_cnv != ih->data->cd_canvas) /* backward compatibility code */ cdActivate(ih->data->cd_canvas); draw_cb(ih, i, j, xmin, xmax, ymin, ymax, ih->data->cd_canvas); if (old_cnv && old_cnv != ih->data->cd_canvas) { cdActivate(old_cnv); cdCanvasActivate(ih->data->cd_canvas); } } cdCanvasClip(ih->data->cd_canvas, oldclip); cdCanvasClipArea(ih->data->cd_canvas, oldxmin, oldxmax, oldymin, oldymax); }
/** * Function used to call the client; is used when a cell must be repainted. */ static void call_apl_draw(TCells* obj, int xmin, int xmax, int ymin, int ymax, int i, int j) { int cxmin, cxmax, cymin, cymax; int oldxmin, oldxmax, oldymin, oldymax; int w = obj->width; int h = obj->height; /* Getting clipping area for post restore */ int oldclip = cdCanvasClip(obj->cddbuffer,CD_QUERY); cdCanvasGetClipArea(obj->cddbuffer,&oldxmin, &oldxmax, &oldymin, &oldymax); /* Clipoing the cell area */ if (obj->clipped) { cdCanvasClip(obj->cddbuffer, CD_CLIPAREA); cxmin = xmin < 0 ? 0 : xmin; cymin = ymin < 0 ? 0 : ymin; cxmax = xmax > w ? w : xmax; cymax = ymax > h ? h : ymax; cdCanvasClipArea(obj->cddbuffer, xmin, xmax, ymin, ymax); } /* Calling the application draw callback. */ { TDrawCb func = (TDrawCb)IupGetCallback(obj->self, IUP_DRAW_CB); if (func) { cdCanvas* old_cnv = cdActiveCanvas(); if (old_cnv != obj->cddbuffer) /* backward compatibility code */ cdActivate(obj->cddbuffer); func(obj->self, i, j, xmin, xmax, ymin, ymax, obj->cddbuffer); if (old_cnv != obj->cddbuffer) cdActivate(old_cnv); } } /* Restoring clipping attributes */ cdCanvasClip(obj->cddbuffer,oldclip); cdCanvasClipArea(obj->cddbuffer, oldxmin, oldxmax, oldymin, oldymax); }
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; } }
/* Draw the line titles, visible, between lin and lastlin, include it. Line titles marked will be draw with the appropriate feedback. -> lin1 - First line to have its title drawn -> lin2 - Last line to have its title drawn */ void iupMatrixDrawTitleLines(Ihandle* ih, int lin1, int lin2) { int x1, y1, x2, y2, first_lin; int lin, alignment, active, framehighlight; long framecolor; IFniiiiiiC draw_cb; if (!ih->data->columns.dt[0].size) return; if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1) { first_lin = 0; y1 = 0; } else { if (lin1 > ih->data->lines.last || lin2 < ih->data->lines.first) return; if (lin1 < ih->data->lines.first) lin1 = ih->data->lines.first; if (lin2 > ih->data->lines.last) lin2 = ih->data->lines.last; first_lin = ih->data->lines.first; y1 = 0; for (lin = 0; lin< ih->data->lines.num_noscroll; lin++) y1 += ih->data->lines.dt[lin].size; } /* Start the position of the line title */ x1 = 0; x2 = ih->data->columns.dt[0].size; iupMATRIX_CLIPAREA(ih, x1, x2, y1, ih->data->h-1); cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /* Find the initial position of the first line */ if (first_lin == ih->data->lines.first) y1 -= ih->data->lines.first_offset; for(lin = first_lin; lin < lin1; lin++) y1 += ih->data->lines.dt[lin].size; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); framehighlight = iupAttribGetInt(ih, "FRAMETITLEHIGHLIGHT"); active = iupdrvIsActive(ih); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); alignment = iMatrixDrawGetColAlignment(ih, 0); /* Draw the titles */ for(lin = lin1; lin <= lin2; lin++) { /* If it is a hidden line (size = 0), don't draw the title */ if(ih->data->lines.dt[lin].size == 0) continue; y2 = y1 + ih->data->lines.dt[lin].size; /* If it doesn't have title, the loop just calculate the final position */ if (ih->data->columns.dt[0].size) { int marked = iupMatrixLineIsMarked(ih, lin); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, 0); iMatrixDrawFrameRectTitle(ih, lin, 0, x1, x2, y1, y2, framecolor, framehighlight); iMatrixDrawCellValue(ih, x1, x2, y1, y2, alignment, marked, active, lin, 0, draw_cb, framecolor); } y1 = y2; } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
static void iMatrixDrawResetCellClipping(Ihandle* ih) { int old_clip = cdCanvasClip(ih->data->cd_canvas, CD_QUERY); if (old_clip == CD_CLIPAREA) cdCanvasClipArea(ih->data->cd_canvas, ih->data->clip_x1, ih->data->clip_x2, ih->data->clip_y1, ih->data->clip_y2); }
/* Redraw a block of cells of the matrix. Handle marked cells, change automatically the background color of them. - lin1, col1 : cell coordinates that mark the left top corner of the area to be redrawn - lin2, col2 : cell coordinates that mark the right bottom corner of the area to be redrawn */ void iupMatrixDrawCells(Ihandle* ih, int lin1, int col1, int lin2, int col2) { int x1, y1, x2, y2, old_x2, old_y1, old_y2; int alignment, lin, col, active, first_col, first_lin; long framecolor, emptyarea_color = -1; IFnii mark_cb; IFnii dropcheck_cb; IFniiiiiiC draw_cb; x2 = ih->data->w-1; y2 = ih->data->h-1; old_x2 = x2; old_y1 = 0; old_y2 = y2; if (ih->data->lines.num <= 1 || ih->data->columns.num <= 1) return; if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1) { first_col = 0; x1 = 0; } else { if (col1 > ih->data->columns.last || col2 < ih->data->columns.first) return; if (col1 < ih->data->columns.first) col1 = ih->data->columns.first; if (col2 > ih->data->columns.last) col2 = ih->data->columns.last; first_col = ih->data->columns.first; x1 = 0; for (col = 0; col< ih->data->columns.num_noscroll; col++) x1 += ih->data->columns.dt[col].size; } if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1) { first_lin = 0; y1 = 0; } else { if (lin1 > ih->data->lines.last || lin2 < ih->data->lines.first) return; if (lin1 < ih->data->lines.first) lin1 = ih->data->lines.first; if (lin2 > ih->data->lines.last) lin2 = ih->data->lines.last; first_lin = ih->data->lines.first; y1 = 0; for (lin = 0; lin< ih->data->lines.num_noscroll; lin++) y1 += ih->data->lines.dt[lin].size; } iupMATRIX_CLIPAREA(ih, x1, x2, y1, y2); cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); /* wait for background */ /* Find the initial position of the first column */ if (first_col==ih->data->columns.first) x1 -= ih->data->columns.first_offset; for(col = first_col; col < col1; col++) x1 += ih->data->columns.dt[col].size; /* Find the initial position of the first line */ if (first_lin == ih->data->lines.first) y1 -= ih->data->lines.first_offset; for(lin = first_lin; lin < lin1; lin++) y1 += ih->data->lines.dt[lin].size; /* Find the final position of the last column */ x2 = x1; for( ; col <= col2; col++) x2 += ih->data->columns.dt[col].size; /* Find the final position of the last line */ y2 = y1; for( ; lin <= lin2; lin++) y2 += ih->data->lines.dt[lin].size; if ((col2 == ih->data->columns.num-1) && (old_x2 > x2)) { emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent); cdCanvasForeground(ih->data->cd_canvas, emptyarea_color); /* If it was drawn until the last column and remains space in the right of it, then delete this area with the the background color. */ iupMATRIX_BOX(ih, x2, old_x2, old_y1, old_y2); } if ((lin2 == ih->data->lines.num-1) && (old_y2 > y2)) { if (emptyarea_color == -1) emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent); cdCanvasForeground(ih->data->cd_canvas, emptyarea_color); /* If it was drawn until the last line visible and remains space below it, then delete this area with the the background color. */ iupMATRIX_BOX(ih, 0, old_x2, y2, old_y2); } /* after the background */ cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /***** Draw the cell values and frame */ old_y1 = y1; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); active = iupdrvIsActive(ih); mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB"); dropcheck_cb = (IFnii)IupGetCallback(ih, "DROPCHECK_CB"); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); for(col = col1; col <= col2; col++) /* For all the columns in the region */ { if (ih->data->columns.dt[col].size == 0) continue; alignment = iMatrixDrawGetColAlignment(ih, col); x2 = x1 + ih->data->columns.dt[col].size; for(lin = lin1; lin <= lin2; lin++) /* For all lines in the region */ { int drop = 0; int marked = 0; if (ih->data->lines.dt[lin].size == 0) continue; y2 = y1 + ih->data->lines.dt[lin].size; /* If the cell is marked, then draw it with attenuation color */ marked = iupMatrixMarkCellGet(ih, lin, col, mark_cb); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, col); iMatrixDrawFrameRectCell(ih, lin, col, x1, x2, y1, y2, framecolor); if (dropcheck_cb) { int ret = dropcheck_cb(ih, lin, col); if (ret == IUP_DEFAULT) { drop = IMAT_DROPBOX_W+IMAT_PADDING_W/2; iMatrixDrawDropFeedback(ih, x2, y1, y2, active, framecolor); } else if (ret == IUP_CONTINUE) { drop = IMAT_TOGGLE_SIZE + IMAT_PADDING_W; iMatrixDrawToggle(ih, x2, y1, y2, lin, col, marked, active); } } /* draw the cell contents */ iMatrixDrawCellValue(ih, x1, x2-drop, y1, y2, alignment, marked, active, lin, col, draw_cb, framecolor); y1 = y2; } x1 = x2; y1 = old_y1; /* must reset also y */ } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
bool iupPlot::Render(cdCanvas* canvas) { if (!mRedraw) return true; // Shift the drawing area to the plot viewport cdCanvasOrigin(canvas, mViewport.mX, mViewport.mY); // There are no additional transformations set in the CD canvas, // all transformations are done here. cdCanvasClip(canvas, CD_CLIPAREA); // Draw the background, axis and grid restricted only by the viewport cdCanvasClipArea(canvas, 0, mViewport.mWidth - 1, 0, mViewport.mHeight - 1); // draw entire plot viewport DrawBackground(canvas); if (!mDataSetListCount) return true; cdCanvasNativeFont(canvas, IupGetAttribute(ih, "FONT")); ConfigureAxis(); if (!CalculateAxisRange()) return false; if (!CheckRange(mAxisX)) return false; if (!CheckRange(mAxisY)) return false; CalculateTitlePos(); // Must be before calculate margins CalculateTickSize(canvas, mAxisX.mTick); CalculateTickSize(canvas, mAxisY.mTick); CalculateMargins(canvas); iupPlotRect theDatasetArea; theDatasetArea.mX = mBack.mMargin.mLeft; theDatasetArea.mY = mBack.mMargin.mBottom; theDatasetArea.mWidth = mViewport.mWidth - mBack.mMargin.mLeft - mBack.mMargin.mRight; theDatasetArea.mHeight = mViewport.mHeight - mBack.mMargin.mTop - mBack.mMargin.mBottom; if (!CalculateTickSpacing(theDatasetArea, canvas)) return false; if (!CalculateXTransformation(theDatasetArea)) return false; if (!CalculateYTransformation(theDatasetArea)) return false; IFnC pre_cb = (IFnC)IupGetCallback(ih, "PREDRAW_CB"); if (pre_cb) pre_cb(ih, canvas); if (mBack.GetImage()) DrawBackgroundImage(canvas); if (!mGrid.DrawX(mAxisX.mTickIter, mAxisX.mTrafo, theDatasetArea, canvas)) return false; if (mGrid.mShowX) mGridMinor.DrawX(mAxisX.mTickIter, mAxisX.mTrafo, theDatasetArea, canvas); if (!mGrid.DrawY(mAxisY.mTickIter, mAxisY.mTrafo, theDatasetArea, canvas)) return false; if (mGrid.mShowY) mGridMinor.DrawY(mAxisY.mTickIter, mAxisY.mTrafo, theDatasetArea, canvas); if (!mAxisX.DrawX(theDatasetArea, canvas, mAxisY)) return false; if (!mAxisY.DrawY(theDatasetArea, canvas, mAxisX)) return false; if (mBox.mShow) mBox.Draw(theDatasetArea, canvas); // draw the datasets, legend, crosshair and selection restricted to the dataset area cdCanvasClipArea(canvas, theDatasetArea.mX, theDatasetArea.mX + theDatasetArea.mWidth - 1, theDatasetArea.mY, theDatasetArea.mY + theDatasetArea.mHeight - 1); IFniiddi drawsample_cb = (IFniiddi)IupGetCallback(ih, "DRAWSAMPLE_CB"); for (int ds = 0; ds < mDataSetListCount; ds++) { iupPlotDataSet* dataset = mDataSetList[ds]; if (drawsample_cb) { iupPlotSampleNotify inNotify = { ih, ds, drawsample_cb }; dataset->DrawData(mAxisX.mTrafo, mAxisY.mTrafo, canvas, &inNotify); } else dataset->DrawData(mAxisX.mTrafo, mAxisY.mTrafo, canvas, NULL); } if (mCrossHairH) DrawCrossHairH(theDatasetArea, canvas); else if (mCrossHairV) DrawCrossHairV(theDatasetArea, canvas); if (mShowSelectionBand) { if (mSelectionBand.mX < theDatasetArea.mX) { mSelectionBand.mWidth = mSelectionBand.mX + mSelectionBand.mWidth - theDatasetArea.mX; mSelectionBand.mX = theDatasetArea.mX; } if (mSelectionBand.mY < theDatasetArea.mY) { mSelectionBand.mHeight = mSelectionBand.mY + mSelectionBand.mHeight - theDatasetArea.mY; mSelectionBand.mY = theDatasetArea.mY; } if (mSelectionBand.mX + mSelectionBand.mWidth > theDatasetArea.mX + theDatasetArea.mWidth) mSelectionBand.mWidth = theDatasetArea.mX + theDatasetArea.mWidth - mSelectionBand.mX; if (mSelectionBand.mY + mSelectionBand.mHeight > theDatasetArea.mY + theDatasetArea.mHeight) mSelectionBand.mHeight = theDatasetArea.mY + theDatasetArea.mHeight - mSelectionBand.mY; mBox.Draw(mSelectionBand, canvas); } IFnC post_cb = (IFnC)IupGetCallback(ih, "POSTDRAW_CB"); if (post_cb) post_cb(ih, canvas); if (!DrawLegend(theDatasetArea, canvas, mLegend.mPos)) return false; // Draw title restricted only by the viewport cdCanvasClipArea(canvas, 0, mViewport.mWidth - 1, 0, mViewport.mHeight - 1); DrawTitle(canvas); if (!IupGetInt(ih, "ACTIVE")) DrawInactive(canvas); mRedraw = false; return true; }
/* Put a text in the screen, using the specified color and alignment. Receive the size of cell and also the visible part of the cell, because need to clip with this visible part and calculate, correctly, the center position and right margin of the cell, using the entire size of it. -> y1, y2 : vertical limits of the cell -> x1, x2 : horizontal limits of the complete cell -> xc : point where the text is clipped -> alignment : alignment type (horizontal) assigned to the text. The options are: [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT] -> cor : color schema that will be used: IMAT_TITLE_COLOR -> Black letters in gray background (for the titles) IMAT_ELEM_COLOR -> Letters with FGCOLOR and background with BGCOLOR IMAT_REVERSE_COLOR -> Letters with BGCOLOR and background with FGCOLOR -> lin, col - cell coordinates, in IUP format - i.e., l,l represents the left top cell of the matrix; lin and col values = 0 represents the title lines and columns. */ static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, char *text, int alignment, int xc, int cor, int lin, int col) { int oldbgc = -1; int ypos; int oldx1 = x1, /* Full limit of the cell, */ oldx2 = x2 - 1, /* considering the decorations */ oldy1 = y1, oldy2 = y2, oldxc = xc; /* Create an space between text and cell margin */ x1 += IMAT_DECOR_X / 2; x2 -= IMAT_DECOR_X / 2; xc -= IMAT_DECOR_X / 2; y1 += IMAT_DECOR_Y / 2; y2 -= IMAT_DECOR_Y / 2; /* Clear the cell */ if(cor == IMAT_TITLE_COLOR) { oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0); CdBox(oldx1 + 2, oldxc - 2, oldy1 + 2, oldy2 - 2); /* Clear cell box, considering the xc */ } else if(cor == IMAT_ELEM_COLOR) { oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 0); CdBox(oldx1, oldx2, oldy1, oldy2); /* Clear cell box */ } else { oldbgc = iMatrixDrawSetBgColor(ih, lin, col, cor, 1); /* Clear the text box, with the attenuated color... */ CdBox(oldx1, oldx2, oldy1, oldy2); iMatrixDrawSetFgColor(ih, lin, col, 1); } if(!iMatrixDrawCallDrawCB(ih, cor, lin, col, oldx1, oldx2, oldy1, oldy2)) return; /* Put the text */ if(text && *text) { int numl; int lineh, totalh, spacing; /* Set the clip area to the cell region informed */ CdClipArea(x1, xc, oldy1, oldy2); cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); /* Set the color used to draw the text */ if((lin > 0 && ih->data->lin.inactive[lin-1]) || (col > 0 && ih->data->col.inactive[col-1]) || !IupGetInt(ih, "ACTIVE")) cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_COLOR); else if(cor == IMAT_ELEM_COLOR) iMatrixDrawSetFgColor(ih, lin, col, 0); else if(cor == IMAT_REVERSE_COLOR) oldbgc = iMatrixDrawSetFgColor(ih, lin, col, 1); else iMatrixDrawSetFgColor(ih, lin, col, 0); numl = iupMatrixAuxTextHeight(ih, text, &totalh, &lineh, &spacing); iMatrixDrawSetFont(ih, lin, col); if(numl == 1) { ypos = (int)((y1 + y2) / 2.0 - .5); /* Put the text */ if(alignment == IMAT_T_CENTER) CdPutText((x1 + x2) / 2, ypos, text, CD_CENTER); else if(alignment == IMAT_T_LEFT) CdPutText(x1, ypos, text, CD_WEST); else CdPutText(x2, ypos, text, CD_EAST); } else { int i; char *p, *q, *newtext = NULL; if(text != NULL) { p = (char*) iupStrDup(text); newtext = p; } else p = NULL; /* Get the position of the first text to be put in the screen */ ypos = (int)( (y1 + y2) / 2.0 - .5) - totalh / 2 + lineh / 2; for(i = 0; i < numl; i++) { q = strchr(p, '\n'); if(q) *q = 0; /* Cut the string to contain a line */ /* Put the text */ if(alignment == IMAT_T_CENTER) CdPutText((x1 + x2) / 2, ypos, p, CD_CENTER); else if(alignment == IMAT_T_LEFT) CdPutText(x1, ypos, p, CD_WEST); else CdPutText(x2, ypos, p, CD_EAST); if(q) *q = '\n'; /* Restore the string */ p = q + 1; /* Advance a line */ ypos += lineh + spacing; } if(newtext) free(newtext); } cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF); } if(cor != IMAT_TITLE_COLOR) CdRestoreBgColor(); }
void cdCanvasEnd(cdCanvas* canvas) { assert(canvas); if (!_cdCheckCanvas(canvas)) return; if (canvas->new_region && canvas->poly_n == 0) { canvas->new_region = 0; if (canvas->clip_mode == CD_CLIPREGION) cdCanvasClip(canvas, CD_CLIPREGION); return; } if (canvas->poly_mode==CD_PATH && canvas->poly_n < 2) { canvas->poly_n = 0; canvas->path_n = 0; return; } if (canvas->poly_mode==CD_OPEN_LINES && canvas->poly_n < 2) { canvas->poly_n = 0; return; } if (canvas->poly_mode==CD_BEZIER && (canvas->poly_n < 4 || ((canvas->poly_n-4)%3 != 0))) { canvas->poly_n = 0; return; } if ((canvas->poly_mode == CD_CLOSED_LINES || canvas->poly_mode == CD_FILL || canvas->poly_mode == CD_CLIP) && canvas->poly_n < 3) { canvas->poly_n = 0; return; } if (canvas->use_fpoly) canvas->cxFPoly(canvas->ctxcanvas, canvas->poly_mode, canvas->fpoly, canvas->poly_n); else cdCanvasPoly(canvas, canvas->poly_mode, canvas->poly, canvas->poly_n); if (canvas->poly_mode == CD_CLIP) { canvas->clip_poly_n = canvas->poly_n; if (canvas->clip_fpoly) { free(canvas->clip_fpoly); canvas->clip_fpoly = NULL; } if (canvas->clip_poly) { free(canvas->clip_poly); canvas->clip_poly = NULL; } if (canvas->use_fpoly) { canvas->clip_fpoly = (cdfPoint*)malloc((canvas->poly_n+1) * sizeof(cdfPoint)); memcpy(canvas->clip_fpoly, canvas->fpoly, canvas->poly_n * sizeof(cdfPoint)); } else { canvas->clip_poly = (cdPoint*)malloc((canvas->poly_n+1) * sizeof(cdPoint)); memcpy(canvas->clip_poly, canvas->poly, canvas->poly_n * sizeof(cdPoint)); } } canvas->path_n = 0; canvas->poly_n = 0; canvas->use_fpoly = -1; }
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); }
/* Draw the column titles, visible, between col and lastcol, include it. Column titles marked will be draw with the appropriate feedback. -> col1 - First column to have its title drawn -> col2 - Last column to have its title drawn */ void iupMatrixDrawTitleColumns(Ihandle* ih, int col1, int col2) { int x1, y1, x2, y2, first_col; int col, active, alignment, framehighlight; long framecolor; IFniiiiiiC draw_cb; if (!ih->data->lines.dt[0].size) return; if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1) { first_col = 0; x1 = 0; } else { if (col1 > ih->data->columns.last || col2 < ih->data->columns.first) return; if (col1 < ih->data->columns.first) col1 = ih->data->columns.first; if (col2 > ih->data->columns.last) col2 = ih->data->columns.last; first_col = ih->data->columns.first; x1 = 0; for (col = 0; col< ih->data->columns.num_noscroll; col++) x1 += ih->data->columns.dt[col].size; } /* Start the position of the first column title */ y1 = 0; y2 = ih->data->lines.dt[0].size; iupMATRIX_CLIPAREA(ih, x1, ih->data->w-1, y1, y2); cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /* Find the initial position of the first column */ if (first_col==ih->data->columns.first) x1 -= ih->data->columns.first_offset; for(col = first_col; col < col1; col++) x1 += ih->data->columns.dt[col].size; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); framehighlight = iupAttribGetInt(ih, "FRAMETITLEHIGHLIGHT"); active = iupdrvIsActive(ih); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); alignment = iMatrixDrawGetAlignmentLin0(ih); /* Draw the titles */ for(col = col1; col <= col2; col++) { /* If it is an hide column (size = 0), no draw the title */ if(ih->data->columns.dt[col].size == 0) continue; x2 = x1 + ih->data->columns.dt[col].size; /* If it doesn't have title, the loop just calculate the final position */ if (ih->data->lines.dt[0].size) { int sort = 0; int marked = iupMatrixColumnIsMarked(ih, col); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, 0, col); iMatrixDrawFrameRectTitle(ih, 0, col, x1, x2, y1, y2, framecolor, framehighlight); if (iMatrixDrawSortSign(ih, x2, y1, y2, col, active)) sort = IMAT_DROPBOX_W; /* same space is used by the sort sign */ iMatrixDrawCellValue(ih, x1, x2-sort, y1, y2, alignment, marked, active, 0, col, draw_cb, framecolor); } x1 = x2; } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
static void cdcgm_ClipIndicator(int clip, cdCGM* cd_cgm) { int style = clip? CD_CLIPAREA: CD_CLIPOFF; cdCanvasClip(cd_cgm->canvas, style); }
/* Put the cell contents in the screen, using the specified color and alignment. -> y1, y2 : vertical limits of the cell -> x1, x2 : horizontal limits of the complete cell -> alignment : alignment type (horizontal) assigned to the text. The options are: [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT] -> marked : mark state -> lin, col - cell coordinates */ static void iMatrixDrawCellValue(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, IFniiiiiiC draw_cb) { char *text; /* avoid drawing over the frame of the next cell */ x2 -= IMAT_FRAME_W/2; y2 -= IMAT_FRAME_H/2; /* avoid drawing over the frame of the cell */ x2 -= IMAT_FRAME_W/2; y2 -= IMAT_FRAME_H/2; if (lin==0 || col==0) { /* avoid drawing over the frame of the cell */ x1 += IMAT_FRAME_W/2; y1 += IMAT_FRAME_H/2; if (col==0) x1 += IMAT_FRAME_W/2; if (lin==0) y1 += IMAT_FRAME_H/2; } else if ((col==1 && ih->data->columns.sizes[0] == 0) || (lin==1 && ih->data->lines.sizes[0] == 0)) { /* avoid drawing over the frame of the cell */ x1 += IMAT_FRAME_W/2; y1 += IMAT_FRAME_H/2; } if (draw_cb && !iMatrixDrawCallDrawCB(ih, lin, col, x1, x2, y1, y2, draw_cb)) return; text = iupMatrixCellGetValue(ih, lin, col); /* Put the text */ if (text && *text) { int num_line, line_height, total_height; int charheight, ypos; num_line = iupStrLineCount(text); iupdrvFontGetCharSize(ih, NULL, &charheight); line_height = charheight; total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2; if (lin==0) { int text_w; iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL); if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W) alignment = IMAT_T_LEFT; } /* Set the color used to draw the text */ if (!active) cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_FGCOLOR); else iMatrixDrawSetFgColor(ih, lin, col, marked); /* Set the clip area to the cell region informed, the text maybe greatter than the cell */ IUPMAT_CLIPAREA(ih, x1, x2, y1, y2); cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA); cdCanvasNativeFont(ih->data->cddbuffer, iupMatrixGetFont(ih, lin, col)); /* Create an space between text and cell frame */ x1 += IMAT_PADDING_W/2; x2 -= IMAT_PADDING_W/2; y1 += IMAT_PADDING_H/2; y2 -= IMAT_PADDING_H/2; if (alignment == IMAT_T_CENTER) cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER); else if(alignment == IMAT_T_LEFT) cdCanvasTextAlignment(ih->data->cddbuffer, CD_WEST); else cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST); if (num_line == 1) { ypos = (int)((y1 + y2) / 2.0 - 0.5); /* Put the text */ if (alignment == IMAT_T_CENTER) IUPMAT_TEXT(ih, (x1 + x2) / 2, ypos, text); else if(alignment == IMAT_T_LEFT) IUPMAT_TEXT(ih, x1, ypos, text); else IUPMAT_TEXT(ih, x2, ypos, text); } else { int i; char *p, *q, *newtext; newtext = iupStrDup(text); p = newtext; /* Get the position of the first text to be put in the screen */ ypos = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2; for(i = 0; i < num_line; i++) { q = strchr(p, '\n'); if (q) *q = 0; /* Cut the string to contain only one line */ /* Draw the text */ if(alignment == IMAT_T_CENTER) IUPMAT_TEXT(ih, (x1 + x2) / 2, ypos, p); else if(alignment == IMAT_T_LEFT) IUPMAT_TEXT(ih, x1, ypos, p); else IUPMAT_TEXT(ih, x2, ypos, p); /* Advance the string */ if (q) p = q + 1; /* Advance a line */ ypos += line_height + IMAT_PADDING_H/2; } free(newtext); } cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF); } }
void cdCanvasRestoreState(cdCanvas* canvas, cdState* state) { assert(canvas); assert(state); if (!state || !_cdCheckCanvas(canvas)) return; /* clippling must be done in low level because origin and invert y axis */ canvas->clip_poly_n = state->clip_poly_n; if (canvas->clip_poly) { free(canvas->clip_poly); canvas->clip_poly = NULL; } if (canvas->clip_fpoly) { free(canvas->clip_fpoly); canvas->clip_fpoly = NULL; } if (state->clip_poly) { int size = state->clip_poly_n*sizeof(cdPoint); canvas->clip_poly = (cdPoint*)malloc(size); memcpy(canvas->clip_poly, state->clip_poly, size); } if (state->clip_fpoly) { int size = state->clip_poly_n*sizeof(cdfPoint); canvas->clip_fpoly = (cdfPoint*)malloc(size); memcpy(canvas->clip_fpoly, state->clip_fpoly, size); } cdCanvasClip(canvas, CD_CLIPOFF); if (canvas->clip_fpoly) canvas->cxFPoly(canvas->ctxcanvas, CD_CLIP, state->clip_fpoly, state->clip_poly_n); else if (canvas->clip_poly) canvas->cxPoly(canvas->ctxcanvas, CD_CLIP, state->clip_poly, state->clip_poly_n); cdCanvasClipArea(canvas, state->clip_rect.xmin, state->clip_rect.xmax, state->clip_rect.ymin, state->clip_rect.ymax); if (canvas->cxFClipArea) canvas->cxFClipArea(canvas->ctxcanvas, state->clip_frect.xmin, state->clip_frect.xmax, state->clip_frect.ymin, state->clip_frect.ymax); else if (canvas->cxClipArea) canvas->cxClipArea(canvas->ctxcanvas, state->clip_rect.xmin, state->clip_rect.xmax, state->clip_rect.ymin, state->clip_rect.ymax); cdCanvasClip(canvas, state->clip_mode); /* regular attributes */ cdCanvasSetBackground(canvas, state->background); cdCanvasSetForeground(canvas, state->foreground); cdCanvasBackOpacity(canvas, state->back_opacity); cdCanvasWriteMode(canvas, state->write_mode); cdCanvasLineStyle(canvas, state->line_style); cdCanvasLineWidth(canvas, state->line_width); cdCanvasLineCap(canvas, state->line_cap); cdCanvasLineJoin(canvas, state->line_join); cdCanvasFillMode(canvas, state->fill_mode); cdCanvasLineStyleDashes(canvas, state->line_dashes, state->line_dashes_count); cdCanvasHatch(canvas, state->hatch_style); if (state->stipple) cdCanvasStipple(canvas, state->stipple_w, state->stipple_h, state->stipple); if (state->pattern) cdCanvasPattern(canvas, state->pattern_w, state->pattern_h, state->pattern); cdCanvasInteriorStyle(canvas, state->interior_style); if (state->native_font[0]) cdCanvasNativeFont(canvas, state->native_font); else cdCanvasFont(canvas, state->font_type_face, state->font_style, state->font_size); cdCanvasTextAlignment(canvas, state->text_alignment); cdCanvasTextOrientation(canvas, state->text_orientation); cdCanvasMarkType(canvas, state->mark_type); cdCanvasMarkSize(canvas, state->mark_size); cdCanvasOrigin(canvas, state->origin.x, state->origin.y); if (state->use_matrix) cdCanvasTransform(canvas, state->matrix); wdCanvasWindow(canvas, state->window.xmin, state->window.xmax, state->window.ymin, state->window.ymax); wdCanvasViewport(canvas, state->viewport.xmin, state->viewport.xmax, state->viewport.ymin, state->viewport.ymax); cdCanvasSimulate(canvas, state->sim_mode); /* complex clipping regions are not saved */ /* driver internal attributes are not saved */ }
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; }