static void iMatrixDrawImage(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, const char* name) { long bgcolor; int x, y; Ihandle* image; iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2); /* Create an space between image and cell frame */ x1 += IMAT_PADDING_W/2; x2 -= IMAT_PADDING_W/2; y1 += IMAT_PADDING_H/2; y2 -= IMAT_PADDING_H/2; image = IupGetHandle(name); if (image) { int width = IupGetInt(image, "WIDTH"); int height = IupGetInt(image, "HEIGHT"); unsigned char r = 255, g = 255, b = 255; iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b, marked, active); bgcolor = cdEncodeColor(r, g, b); y = (y2+y1 + height)/2; if (alignment == IMAT_ALIGN_CENTER) x = x1 + (x2-x1)/2 - width/2; else if(alignment == IMAT_ALIGN_LEFT) x = x1; else /* RIGHT */ x = x2 - width; cdIupDrawImage(ih->data->cd_canvas, image, x, iupMATRIX_INVERTYAXIS(ih, y), 0, 0, !active, bgcolor); } iMatrixDrawResetCellClipping(ih); }
static void iMatrixDrawFeedbackImage(Ihandle* ih, int x1, int x2, int y1, int y2, int lin, int col, int active, int marked, const char*name, unsigned char* alpha) { int x, y; Ihandle* image = IupGetHandle(name); if (image) { long bgcolor; int image_width = IupGetInt(image, "WIDTH"); int image_height = IupGetInt(image, "HEIGHT"); unsigned char r = 255, g = 255, b = 255; iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b, marked, active); bgcolor = cdEncodeColor(r, g, b); y = (y2 + y1 + image_height) / 2; x = (x2 + x1 - image_width) / 2; cdIupDrawImage(ih->data->cd_canvas, image, x, iupMATRIX_INVERTYAXIS(ih, y), 0, 0, !active, bgcolor); } else { static unsigned char red[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE]; static unsigned char green[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE]; static unsigned char blue[IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE]; static unsigned char last_r = 0, last_g = 0, last_b = 0; static int first = 1; unsigned char r = 0, g = 0, b = 0; iupMatrixGetFgRGB(ih, lin, col, &r, &g, &b, marked, active); if (first || last_r != r || last_g != g || last_b != b) { int count = IMAT_FEEDBACK_SIZE * IMAT_FEEDBACK_SIZE; memset(red, r, count); memset(green, g, count); memset(blue, b, count); last_r = r; last_g = g; last_b = b; first = 0; } y = (y2 + y1 + IMAT_FEEDBACK_SIZE) / 2; x = (x2 + x1 - IMAT_FEEDBACK_SIZE) / 2; cdCanvasPutImageRectRGBA(ih->data->cd_canvas, IMAT_FEEDBACK_SIZE, IMAT_FEEDBACK_SIZE, red, green, blue, alpha, x, iupMATRIX_INVERTYAXIS(ih, y), IMAT_FEEDBACK_SIZE, IMAT_FEEDBACK_SIZE, 0, 0, 0, 0); } }
/* Change the CD foreground color, for the selected color to draw a cell with its BACKGROUND COLOR. This involves checking if there is a color attribute that cell. If no, uses a color attribute for the line, else if no for the column, else if no for the entire matrix. Finally, if not find any of these, use the default color. -> 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. -> mark - indicate if a cell is marked. If yes, its color is attenuated. */ static unsigned long iMatrixDrawSetBgColor(Ihandle* ih, int lin, int col, int mark, int active) { unsigned char r = 255, g = 255, b = 255; iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b); if (mark) { r = IMAT_ATENUATION(r); g = IMAT_ATENUATION(g); b = IMAT_ATENUATION(b); } if (!active) { r = cdIupLIGTHER(r); g = cdIupLIGTHER(g); b = cdIupLIGTHER(b); } return cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(r, g, b)); }
/* Change the CD foreground color, for the selected color to draw a cell with its BACKGROUND COLOR. This involves checking if there is a color attribute that cell. If no, uses a color attribute for the line, else if no for the column, else if no for the entire matrix. Finally, if not find any of these, use the default color. -> 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. -> marked - indicate if a cell is marked. If yes, its color is attenuated. */ static unsigned long iMatrixDrawSetBgColor(Ihandle* ih, int lin, int col, int marked, int active) { unsigned char r = 255, g = 255, b = 255; iupMatrixGetBgRGB(ih, lin, col, &r, &g, &b, marked, active); return cdCanvasForeground(ih->data->cd_canvas, cdEncodeColor(r, g, b)); }