Esempio n. 1
0
static int select_cb(Ihandle* ih, int cell, int type)
{
  long cd_color;
  char str[30];
  int ri, gi, bi;

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

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

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

  redraw_cb(canvas);

  return IUP_DEFAULT;
}
Esempio n. 2
0
static int draw_cb(Ihandle* h, int i, int j, int xmin, int xmax, int ymin, int ymax, cdCanvas* canvas)
{
    int xm = (xmax + xmin) / 2;
    int ym = (ymax + ymin) / 2;
    static char buffer[64];

    if (i == 1 && j == 2) return IUP_DEFAULT;
    if (i == 2 && j == 1) return IUP_DEFAULT;
    if (i == 2 && j == 2) return IUP_DEFAULT;
    if (i == 5 && j == 6) return IUP_DEFAULT;
    if (i == 6 && j == 5) return IUP_DEFAULT;
    if (i == 6 && j == 6) return IUP_DEFAULT;

    if (i == 1 && j == 1)
        cdCanvasForeground(canvas, CD_WHITE);
    else
        cdCanvasForeground(canvas, cdEncodeColor(
                               (unsigned char)(i*20),
                               (unsigned char)(j*100),
                               (unsigned char)(i+100)));
    cdCanvasBox(canvas, xmin, xmax, ymin, ymax);
    cdCanvasTextAlignment(canvas, CD_CENTER);
    cdCanvasForeground(canvas, CD_BLACK);
    sprintf(buffer, "(%02d, %02d)", i, j);
    cdCanvasText(canvas, xm, ym, buffer);

    return IUP_DEFAULT;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
//void SimpleDrawTest(cdCanvas* canvas)
void SimpleDrawPoly(cdCanvas* canvas)
{
  int w, h;
  cdGetCanvasSize(&w, &h, 0, 0);

  cdBackground(CD_WHITE);
  cdClear();

  //cdSetAttribute("ANTIALIAS", "0");
  cdForeground(cdEncodeAlpha(cdEncodeColor(255, 0, 0), 100));

  cdfCanvasArc(cdActiveCanvas(), 255, 255, 100, 100, 0, 360);

  cdLine(0, 0, 200, 200);

  cdBegin(CD_BEZIER);
  cdVertex(100, 100); 
  cdVertex(150, 200); 
  cdVertex(180, 250); 
  cdVertex(180, 200); 
  cdVertex(180, 150); 
  cdVertex(150, 100); 
  cdVertex(300, 100); 
  cdEnd();


  cdEnd();
}
Esempio n. 5
0
static void cdcgm_FillAttrib(const char* type, cgmRGB color, const char* hatch, cgmPattern* pat, cdCGM* cd_cgm)
{
  int style = CD_SOLID;
  if (strcmp(type, "HOLLOW")==0)
    style = CD_HOLLOW;
  else if (strcmp(type, "SOLID")==0)
    style = CD_SOLID;
  else if (strcmp(type, "HATCH")==0)
    style = CD_HATCH;
  else if (strcmp(type, "PATTERN")==0)
    style = CD_PATTERN;

  cdCanvasInteriorStyle(cd_cgm->canvas, style);

  cdCanvasForeground(cd_cgm->canvas, cdEncodeColor(color.red, color.green, color.blue));

  if (style == CD_HATCH)
  {
    style = CD_HORIZONTAL;
    if (strcmp(hatch, "HORIZONTAL")==0)
      style = CD_HORIZONTAL;
    else if (strcmp(hatch, "VERTICAL")==0)
      style = CD_VERTICAL;
    else if (strcmp(hatch, "POSITIVE_SLOPE")==0)
      style = CD_BDIAGONAL;
    else if (strcmp(hatch, "NEGATIVE_SLOPE")==0)
      style = CD_FDIAGONAL;
    else if (strcmp(hatch, "HV_CROSS")==0)
      style = CD_CROSS;
    else if (strcmp(hatch, "SLOPE_CROSS")==0)
      style = CD_DIAGCROSS;

    cdCanvasHatch(cd_cgm->canvas, style);
  }
  else if (style == CD_PATTERN)
  {
    int i, count = pat->w*pat->h;
    long int *pattern = (long int *) malloc(count*sizeof(long int));
    
    for (i=0; i<count; i++)
      pattern[i] = cdEncodeColor(pat->pattern[i].red, pat->pattern[i].green, pat->pattern[i].blue);

    cdCanvasPattern(cd_cgm->canvas, pat->w, pat->h, pattern);

    free(pattern);
  }
}
Esempio n. 6
0
int canvas_action_cb(Ihandle* canvas)
{
  int x, y, canvas_width, canvas_height;
  unsigned int ri, gi, bi;
  imImage* image;
  cdCanvas* cd_canvas = (cdCanvas*)IupGetAttribute(canvas, "cdCanvas");
  Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG");
  const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255");

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

  cdCanvasActivate(cd_canvas);

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

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

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

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

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

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

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

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

  cdCanvasFlush(cd_canvas);
  return IUP_DEFAULT;
}
Esempio n. 7
0
long cdIupConvertColor(const char *color)
{
  unsigned char r, g, b;
  if (iupStrToRGB(color, &r, &g, &b))
    return cdEncodeColor(r, g, b);
  else
    return 0;
}
Esempio n. 8
0
void cdIupCalcShadows(long bgcolor, long *light_shadow, long *mid_shadow, long *dark_shadow)
{
  int r, bg_r = cdRed(bgcolor);
  int g, bg_g = cdGreen(bgcolor);
  int b, bg_b = cdBlue(bgcolor);

  /* light_shadow */

  int max = bg_r;
  if (bg_g > max) max = bg_g;
  if (bg_b > max) max = bg_b;

  if (255-max < 64)
  {
    r = 255;
    g = 255;
    b = 255;
  }
  else
  {
    /* preserve some color information */
    if (bg_r == max) r = 255;
    else             r = bg_r + (255-max);
    if (bg_g == max) g = 255;
    else             g = bg_g + (255-max);
    if (bg_b == max) b = 255;
    else             b = bg_b + (255-max);
  }

  if (light_shadow) *light_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); 

  /* dark_shadow */
  r = bg_r - 128;
  g = bg_g - 128;
  b = bg_b - 128;
  if (r < 0) r = 0;
  if (g < 0) g = 0;
  if (b < 0) b = 0;

  if (dark_shadow) *dark_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); 

  /*   mid_shadow = (dark_shadow+bgcolor)/2    */
  if (mid_shadow) *mid_shadow = cdEncodeColor((unsigned char)((bg_r+r)/2), (unsigned char)((bg_g+g)/2), (unsigned char)((bg_b+b)/2));
}
Esempio n. 9
0
/*****************************************\
* Sets the RGB color in the Color Canvas *
\*****************************************/
static void iColorBrowserDlgColor_Update(IcolorDlgData* colordlg_data)
{
  colordlg_data->color = cdEncodeColor(colordlg_data->red, colordlg_data->green, colordlg_data->blue);
  colordlg_data->color = cdEncodeAlpha(colordlg_data->color, colordlg_data->alpha);
  iColorBrowserDlgColorCnvRepaint(colordlg_data);

  {
    Ihandle* ih = IupGetDialog(colordlg_data->color_browser);
    Icallback cb = IupGetCallback(ih, "COLORUPDATE_CB");
    if (cb) cb(ih);
  }
}
Esempio n. 10
0
static long* cd_getgraycolormap(void)
{
  static long color_map[256] = {1};

  if (color_map[0])
  {
    int c;
    for (c = 0; c < 256; c++)
      color_map[c] = cdEncodeColor((unsigned char)c, (unsigned char)c, (unsigned char)c);
  }

  return color_map;
}
Esempio n. 11
0
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);
}
Esempio n. 12
0
static void iMatrixDrawFrameVertLineCell(Ihandle* ih, int lin, int col, int x, int y1, int y2, long framecolor, char* str)
{
  if (ih->data->checkframecolor && (ih->data->callback_mode || ih->data->cells[lin][col].flags & IUPMAT_FRAMEVCOLOR))
  {
    unsigned char r,g,b;
    sprintf(str, "FRAMEVERTCOLOR%d:%d", lin, col);
    if (iupStrToRGB(iupAttribGet(ih, str), &r, &g, &b))
      framecolor = cdEncodeColor(r, g, b);
  }

  cdCanvasForeground(ih->data->cddbuffer, framecolor);
  IUPMAT_LINE(ih, x, y1, x, y2);    /* right vertical line */
}
Esempio n. 13
0
static void iMatrixDrawFrameHorizLineCell(Ihandle* ih, int lin, int col, int x1, int x2, int y, long framecolor, char* str)
{
  if (ih->data->checkframecolor && (ih->data->callback_mode || ih->data->cells[lin][col].flags & IUPMAT_FRAMEHCOLOR))
  {
    unsigned char r,g,b;
    sprintf(str, "FRAMEHORIZCOLOR%d:%d", lin, col);
    if (iupStrToRGB(iupAttribGet(ih, str), &r, &g, &b))
      framecolor = cdEncodeColor(r, g, b);
  }

  cdCanvasForeground(ih->data->cddbuffer, framecolor);
  IUPMAT_LINE(ih, x1, y, x2, y);   /* bottom horizontal line */
}
Esempio n. 14
0
/* Change the CD foreground color, for the selected color to draw a cell with
   its FOREGROUND 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 iMatrixDrawSetFgColor(Ihandle* ih, int lin, int col, int mark)
{
    unsigned char r = 0, g = 0, b = 0;
    iupMatrixGetFgRGB(ih, lin, col, &r, &g, &b);

    if (mark)
    {
        r = IMAT_ATENUATION(r);
        g = IMAT_ATENUATION(g);
        b = IMAT_ATENUATION(b);
    }

    return cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(r, g, b));
}
Esempio n. 15
0
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);
  }
}
Esempio n. 16
0
int item_print_action_cb(Ihandle* item_print)
{
  Ihandle* canvas = IupGetDialogChild(item_print, "CANVAS");
  unsigned int ri, gi, bi;
  imImage* image;
  char* title = IupGetAttribute(IupGetDialog(item_print), "TITLE");
  Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG");
  const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255");

  cdCanvas* cd_canvas = cdCreateCanvasf(CD_PRINTER, "%s -d", title);
  if (!cd_canvas)
    return IUP_DEFAULT;

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

  /* draw the image at the center of the canvas */
  image = (imImage*)IupGetAttribute(canvas, "IMAGE");
  if (image)
  {
    int x, y, canvas_width, canvas_height, view_width, view_height;
    double canvas_width_mm, canvas_height_mm;
    Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG");
    int margin_width = IupConfigGetVariableIntDef(config, "Print", "MarginWidth", 20);
    int margin_height = IupConfigGetVariableIntDef(config, "Print", "MarginHeight", 20);

    cdCanvasGetSize(cd_canvas, &canvas_width, &canvas_height, &canvas_width_mm, &canvas_height_mm);

    /* convert to pixels */
    margin_width = (int)((margin_width * canvas_width) / canvas_width_mm);
    margin_height = (int)((margin_height * canvas_height) / canvas_height_mm);

    view_fit_rect(canvas_width - 2 * margin_width, canvas_height - 2 * margin_height, 
                  image->width, image->height, 
                  &view_width, &view_height);

    x = (canvas_width - view_width) / 2;
    y = (canvas_height - view_height) / 2;

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

  cdKillCanvas(cd_canvas);
  return IUP_DEFAULT;
}
Esempio n. 17
0
static int iColorBrowserDlgSetValueHexAttrib(Ihandle* ih, const char* value)
{
  IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA");

  if (!iupStrToRGB(value, &(colordlg_data->red), &(colordlg_data->green), &(colordlg_data->blue)))
    return 0;

  colordlg_data->previous_color = cdEncodeColor(colordlg_data->red, colordlg_data->green, colordlg_data->blue);
  colordlg_data->previous_color = cdEncodeAlpha(colordlg_data->previous_color, colordlg_data->alpha);

  iColorBrowserDlgRGB2HSI(colordlg_data);
  iColorBrowserDlgBrowserRGB_Update(colordlg_data);
  iColorBrowserDlgHSI_TXT_Update(colordlg_data);
  iColorBrowserDlgRGB_TXT_Update(colordlg_data);
  iColorBrowserDlgColor_Update(colordlg_data);
  return 0;
}
Esempio n. 18
0
void cdRGB2Gray(int width, int height, const unsigned char* red, const unsigned char* green, const unsigned char* blue, unsigned char* index, long *color)
{
  int c, i, count;
  for (c = 0; c < 256; c++)
    color[c] = cdEncodeColor((unsigned char)c, (unsigned char)c, (unsigned char)c);

  count = width*height;
  for (i=0; i<count; i++)
  {
    *index = (unsigned char)(((*red)*30 + (*green)*59 + (*blue)*11)/100);

    index++;
    red++;
    green++;
    blue++;
  }
}
Esempio n. 19
0
/* Change the CD foreground color, for the selected color to draw a cell with
   its FOREGROUND 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.
   -> type - cell type. If it is a title cell (type = IMAT_TITLE_COLOR), then
             only find a own color of the cell, and not in advanced modes to
             define colors.
   -> mark - indicate if a cell is marked. If yes, its color is attenuated.
*/
static unsigned long iMatrixDrawSetFgColor(Ihandle* ih, int lin, int col, int mark)
{
  unsigned int r = 0, g = 0, b = 0;

  if(iMatrixDrawCallFgColorCB(ih, lin, col, &r, &g, &b) == IUP_IGNORE)
    iMatrixDrawGetColor(ih, "FGCOLOR", lin, col, &r, &g, &b, 0);

  if(mark)
  {
    float att = iMatrixDrawGetAttenuation(ih);
    r = (int)(r*att);
    g = (int)(g*att);
    b = (int)(b*att);
  }
  
  return cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b));
}
Esempio n. 20
0
static void iDialUpdateFgColors(Ihandle* ih, unsigned char r, unsigned char g, unsigned char b)
{
  int i, max, deltar, deltag, deltab;

  /* this function is also called before mapping */
  max = (ih->handle && iupdrvIsActive(ih))? 255 : 192;
  deltar = (max-r) / IDIAL_NCOLORS;
  deltag = (max-g) / IDIAL_NCOLORS;
  deltab = (max-b) / IDIAL_NCOLORS;

  for (i=0; i<=IDIAL_NCOLORS; i++)
  {
    ih->data->fgcolor[i] = cdEncodeColor(r, g, b);
    r = (unsigned char)(r + deltar);
    g = (unsigned char)(g + deltag);
    b = (unsigned char)(b + deltab);
  }
}
Esempio n. 21
0
static int iColorbarCreateMethod(Ihandle* ih, void **params)
{
  int i;
  (void)params;

  /* free the data allocated by IupCanvas */
  if (ih->data) free(ih->data);
  ih->data = iupALLOCCTRLDATA();

  /* change the IupCanvas default values */
  iupAttribSetStr(ih, "BORDER", "NO");

  /* default values */
  ih->data->num_cells = 16;
  ih->data->num_parts = 1;
  ih->data->vertical  = 1;
  ih->data->squared   = 1;
  ih->data->shadowed  = 1;
  ih->data->focus_cell = 0;
  ih->data->preview_size = -1;  /* automatic */
  ih->data->fgcolor_idx  = 0;   /* black */
  ih->data->bgcolor_idx  = 15;  /* white */
  ih->data->transparency = ICOLORBAR_NO_COLOR;
  ih->data->light_shadow = CD_WHITE;
  ih->data->mid_shadow   = CD_GRAY;
  ih->data->dark_shadow  = CD_DARK_GRAY;

  /* Initialization of the color vector */
  for (i = 0; i < ICOLORBAR_DEFAULT_NUM_CELLS; i++)
  {
    ih->data->colors[i] = cdEncodeColor((unsigned char)default_colors[i].r,
                                        (unsigned char)default_colors[i].g,
                                        (unsigned char)default_colors[i].b);
  }

  /* IupCanvas callbacks */
  IupSetCallback(ih, "RESIZE_CB", (Icallback)iColorbarResize_CB);
  IupSetCallback(ih, "ACTION",    (Icallback)iColorbarRedraw_CB);
  IupSetCallback(ih, "BUTTON_CB", (Icallback)iColorbarButton_CB);
  IupSetCallback(ih, "FOCUS_CB", (Icallback)iColorbarFocus_CB);
  IupSetCallback(ih, "KEYPRESS_CB", (Icallback)iColorbarKeyPress_CB);

  return IUP_NOERROR;
}
Esempio n. 22
0
int select_cb(Ihandle* self, int cell, int type)
{
    long cd_color;
    char str[30];
    int ri, gi, bi;
    sprintf(str, "CELL%d", cell);
    sscanf(IupGetAttribute(self, str), "%d %d %d", &ri, &gi, &bi);
    cd_color = cdEncodeColor((unsigned char)ri,(unsigned char)gi,(unsigned char)bi);

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

    redraw_cb(cnvs);

    return IUP_DEFAULT;
}
Esempio n. 23
0
static int iMatrixDrawGetFrameVertColor(Ihandle* ih, int lin, int col, long *framecolor)
{
  if (ih->data->checkframecolor && (ih->data->callback_mode || 
                                    ih->data->cells[lin][col].flags & IMAT_HAS_FRAMEVERTCOLOR ||
                                    ih->data->columns.dt[col].flags & IMAT_HAS_FRAMEVERTCOLOR))
  {
    char* color;
    unsigned char r,g,b;
    color = iupAttribGetId2(ih, "FRAMEVERTCOLOR", lin, col);
    if (!color)
      color = iupAttribGetId2(ih, "FRAMEVERTCOLOR", IUP_INVALID_ID, col);
    if (iupStrEqual(color, "BGCOLOR"))
      return 1;
    if (framecolor && iupStrToRGB(color, &r, &g, &b))
      *framecolor = cdEncodeColor(r, g, b);
  }

  return 0;
}
Esempio n. 24
0
static int iColorBrowserDlgColorSelDrag_CB(Ihandle* ih, unsigned char r, unsigned char g, unsigned char b)
{
  IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA");

  colordlg_data->red   = r;
  colordlg_data->green = g;
  colordlg_data->blue  = b;

  iColorBrowserDlgRGB2HSI(colordlg_data);
  iColorBrowserDlgHex_TXT_Update(colordlg_data);
  iColorBrowserDlgHSI_TXT_Update(colordlg_data);
  iColorBrowserDlgRGB_TXT_Update(colordlg_data);

  colordlg_data->color = cdEncodeColor(colordlg_data->red,colordlg_data->green,colordlg_data->blue);
  colordlg_data->color = cdEncodeAlpha(colordlg_data->color, colordlg_data->alpha);
  iColorBrowserDlgColorCnvRepaint(colordlg_data);

  return IUP_DEFAULT;
}
Esempio n. 25
0
static int iColorBrowserDlgSetValueHSIAttrib(Ihandle* ih, const char* value)
{
  IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA");
  int hue, saturation, intensity;

  if (!iupStrToHSI_Int(value, &hue, &saturation, &intensity))
    return 0;
  
  colordlg_data->hue = (float)hue;
  colordlg_data->saturation = (float)saturation/100.0f;
  colordlg_data->intensity = (float)intensity/100.0f;

  iColorBrowserDlgHSI2RGB(colordlg_data);
  colordlg_data->previous_color = cdEncodeColor(colordlg_data->red, colordlg_data->green, colordlg_data->blue);
  colordlg_data->previous_color = cdEncodeAlpha(colordlg_data->previous_color, colordlg_data->alpha);
 
  iColorBrowserDlgHSIChanged(colordlg_data);
  return 0;
}
Esempio n. 26
0
static void cdcgm_LineAttrib(const char *type, const char *cap, const char *join, double width, const char *mode, cgmRGB color, cdCGM* cd_cgm)
{
  int style = CD_CONTINUOUS;
  int linecap = CD_CAPFLAT;
  int linejoin = CD_MITER;

  if (strcmp(type, "SOLID")==0)
    style = CD_CONTINUOUS;
  else if (strcmp(type, "DASH")==0)
    style = CD_DASHED;
  else if (strcmp(type, "DOT")==0)
    style = CD_DOTTED;
  else if (strcmp(type, "DASH_DOT")==0)
    style = CD_DASH_DOT;
  else if (strcmp(type, "DASH_DOT_DOT")==0)
    style = CD_DASH_DOT_DOT;

  if (strcmp(cap, "UNSPECIFIED")==0  || strcmp(cap, "BUTT")==0 || strcmp(cap, "TRIANGLE")==0)
    linecap = CD_CAPFLAT;
  else if (strcmp(cap, "ROUND")==0)
    linecap = CD_CAPROUND;
  else if (strcmp(cap, "PROJECTING_SQUARE")==0)
    linecap = CD_CAPSQUARE;

  if (strcmp(join, "UNSPECIFIED")==0  || strcmp(join, "MITRE")==0)
    linejoin = CD_MITER;
  else if (strcmp(join, "ROUND")==0)
    linejoin = CD_ROUND;
  else if (strcmp(join, "BEVEL")==0)
    linejoin = CD_BEVEL;

  cdCanvasLineCap(cd_cgm->canvas, linecap);

  cdCanvasLineJoin(cd_cgm->canvas, linejoin);

  cdCanvasLineStyle(cd_cgm->canvas, style);

  width = get_size_mode(cd_cgm->canvas, width, mode, cdCanvasLineWidth(cd_cgm->canvas, CD_QUERY));

  cdCanvasLineWidth(cd_cgm->canvas, sMin1(sRound(width)));

  cdCanvasForeground(cd_cgm->canvas, cdEncodeColor(color.red, color.green, color.blue));
}
Esempio n. 27
0
static void cdIupInitPalette(Ihandle* image, long* palette, long bgcolor, int make_inactive)
{
  int i;
  unsigned char r, g, b, bg_r, bg_g, bg_b;

  cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);

  for(i = 0; i < 256; i++)
  {
    char* color = IupGetAttributeId(image, "", i);
    r = bg_r; g = bg_g; b = bg_b;
    iupStrToRGB(color, &r, &g, &b);  /* no need to test for BGCOLOR, if this failed it will not set the parameters */

    if (make_inactive)
      iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

    palette[i] = cdEncodeColor(r, g, b);
  }
}
Esempio n. 28
0
static int iMatrixListDrawColorCol(Ihandle *ih, int lin, int x1, int x2, int y1, int y2, cdCanvas *cnv)
{
  unsigned char red, green, blue;
  char* color = iupAttribGetId(ih, "COLOR", lin);

  if (iupStrToRGB(color, &red, &green, &blue))
  {
    static const int DX_BORDER = 2;
    static const int DY_BORDER = 3;
    static const int DX_FILL = 3;
    static const int DY_FILL = 4;
    int active = iupdrvIsActive(ih);
    int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin);
    long framecolor;

    if (!itemactive)
    {
      red = IMAT_LIGHTER(red);
      green = IMAT_LIGHTER(green);
      blue = IMAT_LIGHTER(blue);
    }

    if (!active)
    {
      unsigned char bg_r, bg_g, bg_b;
      iupStrToRGB(ih->data->bgcolor, &bg_r, &bg_g, &bg_b);
      iupImageColorMakeInactive(&red, &green, &blue, bg_r, bg_g, bg_b);
    }

    /* Fill the box with the color */
    cdCanvasForeground(cnv, cdEncodeColor(red, green, blue));
    cdCanvasBox(cnv, x1 + DX_FILL, x2 - DX_FILL, y1 - DY_FILL, y2 + DY_FILL);

    /* Draw the border */
    framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR"));
    cdCanvasForeground(cnv, framecolor);

    cdCanvasRect(cnv, x1 + DX_BORDER, x2 - DX_BORDER, y1 - DY_BORDER, y2 + DY_BORDER);
  }

  return IUP_DEFAULT;  /* draw nothing more */
}
Esempio n. 29
0
char* cell_cb(Ihandle* self, int cell)
{
    unsigned char r, g, b;
    int ri, gi, bi;
    static char str[30];
    sprintf(str, "CELL%d", cell);
    sscanf(IupGetAttribute(self, str), "%d %d %d", &ri, &gi, &bi);
    r = (unsigned char)ri;
    g = (unsigned char)gi;
    b = (unsigned char)bi;
    if (IupGetColor(IUP_MOUSEPOS, IUP_MOUSEPOS, &r, &g, &b))
    {
        sprintf(str, "%d %d %d", (int)r, (int)g, (int)b);
        cdActivate( cdcanvas );
        cdForeground(cdEncodeColor(r, g, b));
        redraw_cb(cnvs);
        return str;
    }
    return NULL;
}
Esempio n. 30
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.
   -> type - cell type. If it is a title cell (type = IMAT_TITLE_COLOR), then
             only find a own color of the cell, and not in advanced modes to
             define colors.
   -> mark - indicate if a cell is marked. If yes, its color is attenuated.
*/
static unsigned long iMatrixDrawSetBgColor(Ihandle* ih, int lin, int col, int type, int mark)
{
  unsigned int r = 255, g = 255, b = 255;
  int parent = 0;

  if(type == IMAT_TITLE_COLOR)
    parent = 1;

  if(iMatrixDrawCallBgColorCB(ih, lin, col, &r, &g, &b) == IUP_IGNORE)
    iMatrixDrawGetColor(ih, "BGCOLOR", lin, col, &r, &g, &b, parent);
  
  if(mark)
  {
    float att = iMatrixDrawGetAttenuation(ih);
    r = (int)(r*att);
    g = (int)(g*att);
    b = (int)(b*att);
  }

  return cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b));
}