Ejemplo n.º 1
0
static Ihandle* iGLCanvasBoxPickChild(Ihandle* ih, int x, int y, int top)
{
  Ihandle* child = ih->firstchild;

  if (child)
  {
    /* ih is a container then must check first for the client area */
    int client_x = 0, client_y = 0, client_w = 0, client_h = 0;
    IupGetIntInt(ih, "CLIENTSIZE", &client_w, &client_h);
    IupGetIntInt(ih, "CLIP_MIN", &client_x, &client_y);
    if (!top)
    {
      client_x += ih->x;
      client_y += ih->y;
    }

    if (x >= client_x && x < client_x + client_w &&
        y >= client_y && y < client_y + client_h)
    {
      Ihandle* child_array[100];
      int i=0;
      while (child)
      {
        child_array[i] = child;
        child = child->brother;
        i++;
      }
      i--;

      while (i >= 0)
      {
        child = child_array[i];

        if (iupAttribGetInt(child, "VISIBLE") &&
            x >= child->x && x < child->x + child->currentwidth &&
            y >= child->y && y < child->y + child->currentheight)
        {
          ih = iGLCanvasBoxPickChild(child, x, y, 0);
          if (ih)
            return ih;
          else
            return child;
        }

        i--;
      }
    }
  }

  return NULL;
}
Ejemplo n.º 2
0
static int iMatrixExSetPasteDataAttrib(Ihandle *ih, const char* data)
{
  int lin=0, col=0;
  IupGetIntInt(ih, "FOCUS_CELL", &lin, &col);
  iMatrixExPasteData(ih, data, lin, col, "PASTEDATA");
  return 0;
}
Ejemplo n.º 3
0
/* extracted from the SCROLLBAR attribute documentation */
void scrollbar_update(Ihandle* ih, int view_width, int view_height)
{
  /* view_width and view_height is the virtual space size */
  /* here we assume XMIN=0, XMAX=1, YMIN=0, YMAX=1 */
  int elem_width, elem_height;
  int canvas_width, canvas_height;
  int scrollbar_size = IupGetInt(NULL, "SCROLLBARSIZE");
  int border = IupGetInt(ih, "BORDER");

  IupGetIntInt(ih, "RASTERSIZE", &elem_width, &elem_height);

  /* if view is greater than canvas in one direction,
  then it has scrollbars,
  but this affects the opposite direction */
  elem_width -= 2 * border;  /* remove BORDER (always size=1) */
  elem_height -= 2 * border;
  canvas_width = elem_width;
  canvas_height = elem_height;
  if (view_width > elem_width)  /* check for horizontal scrollbar */
    canvas_height -= scrollbar_size;  /* affect vertical size */
  if (view_height > elem_height)
    canvas_width -= scrollbar_size;
  if (view_width <= elem_width && view_width > canvas_width)  /* check if still has horizontal scrollbar */
    canvas_height -= scrollbar_size;
  if (view_height <= elem_height && view_height > canvas_height)
    canvas_width -= scrollbar_size;
  if (canvas_width < 0) canvas_width = 0;
  if (canvas_height < 0) canvas_height = 0;

  IupSetFloat(ih, "DX", (float)canvas_width / (float)view_width);
  IupSetFloat(ih, "DY", (float)canvas_height / (float)view_height);
}
Ejemplo n.º 4
0
static int iMatrixSetFitToSizeAttrib(Ihandle* ih, const char* value)
{
  int w, h;
  int sb_w = 0, sb_h = 0;

  if (!ih->handle)
    ih->data->canvas.sb = iupBaseGetScrollbar(ih);

  /* add scrollbar */
  if (ih->data->canvas.sb)
  {
    int sb_size = iupdrvGetScrollbarSize();
    if (ih->data->canvas.sb & IUP_SB_HORIZ)
      sb_h += sb_size;  /* sb horizontal affects vertical size */
    if (ih->data->canvas.sb & IUP_SB_VERT)
      sb_w += sb_size;  /* sb vertical affects horizontal size */
  }

  IupGetIntInt(ih, "RASTERSIZE", &w, &h);

  if (iupStrEqualNoCase(value, "LINES"))
    iMatrixFitLines(ih, h-sb_h);
  else if (iupStrEqualNoCase(value, "COLUMNS"))
    iMatrixFitColumns(ih, w-sb_w);
  else
  {
    iMatrixFitLines(ih, h-sb_h);
    iMatrixFitColumns(ih, w-sb_w);
  }

  ih->data->need_calcsize = 1;
  if (ih->handle)
    iupMatrixDraw(ih, 1);
  return 0;
}
Ejemplo n.º 5
0
static int iMatrixExSetPasteAttrib(Ihandle *ih, const char* value)
{
  int lin=0, col=0;

  Ihandle* clipboard = IupClipboard();
  char* data = IupGetAttribute(clipboard, "TEXT");
  IupDestroy(clipboard);

  if (iupStrEqualNoCase(value, "FOCUS"))
    IupGetIntInt(ih, "FOCUS_CELL", &lin, &col);
  else if (iupStrEqualNoCase(value, "MARKED"))
  {
    char *marked = IupGetAttribute(ih,"MARKED");
    if (marked)
    {
      int num_lin = IupGetInt(ih, "NUMLIN");
      int num_col = IupGetInt(ih, "NUMCOL");
      iMatrixExCellMarkedStart(marked, num_lin, num_col, &lin, &col);
    }
  }
  else
  {
    if (iupStrToIntInt(value, &lin, &col, ':')!=2)
      return 0;
  }

  iMatrixExPasteData(ih, data, lin, col, "PASTECLIP");
  return 0;
}
Ejemplo 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;
}
Ejemplo n.º 7
0
static void iScrollBoxLayoutUpdate(Ihandle* ih)
{
  int w, h;
  IupGetIntInt(ih, "DRAWSIZE", &w, &h);
  IupSetfAttribute(ih, "DX", "%d", w);
  IupSetfAttribute(ih, "DY", "%d", h);

  if (ih->firstchild)
  {
    iScrollBoxUpdatePosition(ih, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY"));
    iupLayoutUpdate(ih->firstchild);
  }
}
Ejemplo n.º 8
0
void SimpleUpdateSize(cdCanvas* cnv)
{
  Ihandle* canvas = IupGetHandle("SimpleCanvas");
  IupGLMakeCurrent(canvas);

  if (cnv)
  {
    int w, h;
    double res = IupGetDouble(NULL, "SCREENDPI") / 25.4;
    IupGetIntInt(canvas, "DRAWSIZE", &w, &h);

    cdCanvasSetfAttribute(cnv, "SIZE", "%dx%d %g", w, h, res);  /* no need to update resolution */
  }
}
Ejemplo n.º 9
0
static int bt1_cb(Ihandle* self)
{
  imImage* image;
  int w, h;
  void* gldata;
  int ii = tabs_get_index();
  IupGetIntInt(plot[ii], "DRAWSIZE", &w, &h);
  gldata = malloc(w*h*3);
  image = imImageCreate(w, h, IM_RGB, IM_BYTE);
  IupMglPlotPaintTo(plot[ii], "RGB", w, h, 0, gldata);
  imConvertPacking(gldata, image->data[0], w, h, 3, 3, IM_BYTE, 1);
  imProcessFlip(image, image);
  imFileImageSave("../mglplot.png", "PNG", image);
  free(gldata);
  imImageDestroy(image);
  (void)self;
  return IUP_DEFAULT;
}
Ejemplo n.º 10
0
static int resize_cb(Ihandle *ih, int canvas_w, int canvas_h)
{
  cdCanvas *canvas = (cdCanvas*)IupGetAttribute(ih, "_CD_CANVAS");

printf("RESIZE_CB(%d, %d) RASTERSIZE=%s DRAWSIZE=%s \n", canvas_w, canvas_h, IupGetAttribute(ih, "RASTERSIZE"), IupGetAttribute(ih, "DRAWSIZE"));
  /* When *AUTOHIDE=Yes, this can hide a scrollbar and so change the canvas drawsize */
  update_scrollbar(ih, canvas_w, canvas_h);  
printf("                                DRAWSIZE=%s \n", IupGetAttribute(ih, "DRAWSIZE"));
  /* update the canvas size */
  IupGetIntInt(ih, "DRAWSIZE", &canvas_w, &canvas_h);

  /* update the application */
  cdCanvasActivate(canvas);
  update_scrollbar(ih, canvas_w, canvas_h);  
  update_viewport(ih, canvas, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY"));

  return IUP_DEFAULT;
}
Ejemplo n.º 11
0
int canvas_action_cb(Ihandle* canvas)
{
  int x, y, canvas_width, canvas_height;
  void* gldata;
  unsigned int ri, gi, bi;
  imImage* image;
  Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG");
  const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255");

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

  IupGLMakeCurrent(canvas);

  /* OpenGL configuration */
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);           /* image data alignment is 1 */

  glViewport(0, 0, canvas_width, canvas_height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, canvas_width, 0, canvas_height, -1, 1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  /* draw the background */
  sscanf(background, "%u %u %u", &ri, &gi, &bi);
  glClearColor(ri / 255.f, gi / 255.f, bi / 255.f, 1);
  glClear(GL_COLOR_BUFFER_BIT);

  /* draw the image at the center of the canvas */
  image = (imImage*)IupGetAttribute(canvas, "IMAGE");
  if (image)
  {
    x = (canvas_width - image->width) / 2;
    y = (canvas_height - image->height) / 2;
    gldata = (void*)imImageGetAttribute(image, "GLDATA", NULL, NULL);
    glRasterPos2i(x, y);  /* this will not work for negative values, OpenGL limitation */
    glDrawPixels(image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, gldata);  /* no zoom support, must use texture */
  }

  IupGLSwapBuffers(canvas);
  return IUP_DEFAULT;
}
Ejemplo n.º 12
0
static int iCellsResize_CB(Ihandle* ih, int w, int h)
{
  /* recalculate scrollbars limits */
  iCellsAdjustScroll(ih, w, h);  

  /* This could have changed the scrollbar visibility, 
     so the canvas client size can change, so updated it twice. */
  IupGetIntInt(ih, "DRAWSIZE", &w, &h);
  IupSetInt(ih, "DX", w);
  IupSetInt(ih, "DY", h);

  /* update canvas size */
  cdCanvasActivate(ih->data->cd_canvas);
  cdCanvasGetSize(ih->data->cd_canvas, &ih->data->w, &ih->data->h, NULL, NULL);

  /* update render */
  iCellsRenderCells(ih);

  return IUP_DEFAULT;
}
Ejemplo n.º 13
0
static void drawTest(Ihandle *ih, int posx)
{
  int w, h;
  Display* dpy = (Display*)IupGetAttribute(ih, "XDISPLAY");   /* works for Motif and GTK */
  Drawable wnd = (Drawable)IupGetAttribute(ih, "XWINDOW");
  GC gc = XCreateGC(dpy, wnd, 0, NULL);

  IupGetIntInt(ih, "DRAWSIZE", &w, &h);

  XSetForeground(dpy, gc, xGetPixel(dpy, 255, 255, 255));
  XFillRectangle(dpy, wnd, gc, 0, 0, w, h);

  XSetForeground(dpy, gc, xGetPixel(dpy, 255, 0, 0));

  w = 600; /* virtual size */
  XDrawLine(dpy, wnd, gc, -posx, 0, w-posx, h);
  XDrawLine(dpy, wnd, gc, -posx, h, w-posx, 0);

  XFreeGC(dpy, gc); 
}
Ejemplo n.º 14
0
static void drawTest(Ihandle *ih, int posx)
{
  GtkWidget* widget = (GtkWidget*)IupGetAttribute(ih, "WID");
  GdkGC* gc = widget->style->fg_gc[GTK_WIDGET_STATE(widget)];
  int w, h;
  GdkColor color;

  IupGetIntInt(ih, "DRAWSIZE", &w, &h);

  /* white background */
  color.red = 65535;  color.green = 65535;  color.blue  = 65535;
  gdk_gc_set_rgb_fg_color(gc, &color);
  gdk_draw_rectangle(widget->window, gc, TRUE, 0, 0, w, h);

  /* red X */
  w = 600; /* virtual size */
  color.red = 65535;  color.green = 0;  color.blue  = 0;
  gdk_gc_set_rgb_fg_color(gc, &color);
  gdk_draw_line(widget->window, gc, -posx, 0, w-posx, h);
  gdk_draw_line(widget->window, gc, -posx, h, w-posx, 0);
}
Ejemplo n.º 15
0
static void iGLCanvasBoxSetChildrenPositionMethod(Ihandle* ih, int x, int y)
{
  Ihandle* child;
  int horiz_margin = 0, vert_margin = 0;

  IupGetIntInt(ih, "MARGIN", &horiz_margin, &vert_margin);

  /* since GLCanvas is a native container ignore parameters x and y */

  for (child = ih->firstchild; child; child = child->brother)
  {
    int border = iupAttribGetBoolean(ih, "BORDER");

    int vert_pos = iGLCanvasBoxGetVerticalAlign(child);
    int horiz_pos = iGLCanvasBoxGetHorizontalAlign(child);

    if (vert_pos == IUP_ALIGN_ACENTER)
      y = (ih->currentheight - 2* border - child->currentheight) / 2;
    else if (vert_pos == IUP_ALIGN_ABOTTOM)
      y = ih->currentheight - 2 * border - child->currentheight - vert_margin;
    else if (vert_pos == IUP_ALIGN_ATOP)
      y = vert_margin;
    else  /* FLOAT */
      y = child->y;

    if (horiz_pos == IUP_ALIGN_ACENTER)
      x = (ih->currentwidth - 2 * border - child->currentwidth) / 2;
    else if (horiz_pos == IUP_ALIGN_ARIGHT)
      x = ih->currentwidth - 2 * border - child->currentwidth - horiz_margin;
    else if (horiz_pos == IUP_ALIGN_ALEFT)
      x = horiz_margin;
    else  /* FLOAT */ 
      x = child->x;

    /* do not include border in the positioning. It is already considered in CLIENTOFFSET. */

    iupBaseSetPosition(child, x, y);
  }
}
Ejemplo n.º 16
0
static void drawTest(Ihandle *ih, int posx)
{
  RECT rect;
  int w, h;
  HWND hWnd = (HWND)IupGetAttribute(ih, "HWND");
  HDC hDC = GetDC(hWnd);

  IupGetIntInt(ih, "DRAWSIZE", &w, &h);

  SetRect(&rect, 0, 0, w, h);
  FillRect(hDC, &rect, GetStockObject(WHITE_BRUSH));

  SelectObject(hDC, GetStockObject(DC_PEN));
  SetDCPenColor(hDC, RGB(255, 0, 0));

  w = 600; /* virtual size */
  MoveToEx(hDC, -posx, 0, NULL);
  LineTo(hDC, w-posx, h);
  MoveToEx(hDC, -posx, h, NULL);
  LineTo(hDC, w-posx, 0);

  ReleaseDC(hWnd, hDC);
}
Ejemplo n.º 17
0
static void drawTest(Ihandle *ih, int posx)
{
  GdkWindow* wnd = (GdkWindow*)IupGetAttribute(ih, "DRAWABLE");
  GdkGC* gc = gdk_gc_new(wnd);
  int w, h;
  GdkColor color;

  IupGetIntInt(ih, "DRAWSIZE", &w, &h);

  /* white background */
  color.red = 65535;  color.green = 65535;  color.blue  = 65535;
  gdk_gc_set_rgb_fg_color(gc, &color);
  gdk_draw_rectangle(wnd, gc, TRUE, 0, 0, w, h);

  w = 600; /* virtual size */

  /* red X */
  color.red = 65535;  color.green = 0;  color.blue  = 0;
  gdk_gc_set_rgb_fg_color(gc, &color);
  gdk_draw_line(wnd, gc, -posx, 0, w-posx, h);
  gdk_draw_line(wnd, gc, -posx, h, w-posx, 0);

  g_object_unref(gc); 
}
Ejemplo n.º 18
0
static int iMatrixSetSortColumnAttrib(Ihandle* ih, int col, const char* value)
{
  int lines_num = ih->data->lines.num;
  int lin, lin1=1, lin2=lines_num-1;   /* ALL */
  int ascending;
  int* sort_line_index;
  IFniii sort_cb;

  /* Notice that sort_line_index[0] is always 0 */

  if (!ih->data->sort_line_index)
    ih->data->sort_line_index = (int*)calloc(ih->data->lines.num_alloc, sizeof(int));

  sort_line_index = ih->data->sort_line_index;

  if (!ih->data->sort_has_index)
  {
    for (lin = 0; lin < lines_num; lin++)
      sort_line_index[lin] = lin;
  }

  if (iupStrEqualNoCase(value, "RESET"))
  {
    ih->data->sort_has_index = 0;
    iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL);
    ih->data->last_sort_col = 0;

    iupMatrixDraw(ih, 1);
    iupAttribSet(ih, "SORTCOLUMNINTERVAL", NULL);
    return 0;
  }

  if (iupStrEqualNoCase(value, "INVERT"))
  {
    int l1, l2;

    if (!ih->data->sort_has_index)
      return 0;

    IupGetIntInt(ih, "SORTCOLUMNINTERVAL", &lin1, &lin2);

    for (l1=lin1,l2=lin2; l1<l2; ++l1,--l2)
    {
      int tmp = sort_line_index[l1];
      sort_line_index[l1] = sort_line_index[l2];
      sort_line_index[l2] = tmp;
    }

    if (iupStrEqualNoCase(iupAttribGetId(ih, "SORTSIGN", ih->data->last_sort_col), "UP"))
      iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "DOWN");
    else
      iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "UP");

    iupMatrixDraw(ih, 1);
    return 0;
  }

  if (!iupMATRIX_CHECK_COL(ih, col))
    return 0;

  if (!iupStrEqualNoCase(value, "ALL"))
    iupStrToIntInt(value, &lin1, &lin2, '-');

  iupAttribSetStrf(ih, "SORTCOLUMNINTERVAL", "%d,%d", lin1, lin2);

  if (lin1 < 1) lin1 = 1;
  if (lin2 < lin1) lin2 = lin1;

  ascending = iupStrEqualNoCase(iupAttribGetStr(ih, "SORTCOLUMNORDER"), "ASCENDING");
  
  sort_cb = (IFniii)IupGetCallback(ih, "SORTCOLUMNCOMPARE_CB");
  if (sort_cb)
  {
    iMatrixQSort_sort_cb = sort_cb;
    iMatrixQSort_ih = ih;
    iMatrixQSort_col = col;
    qsort(sort_line_index+lin1,lin2-lin1+1,sizeof(int),iMatrixCompareCallbackFunc);
  }
  else
  {
    if (ih->data->numeric_columns && ih->data->numeric_columns[col].flags & IMAT_IS_NUMERIC)
    {
      ImatSortNumber* sort_line_number = (ImatSortNumber*)malloc((lin2-lin1+1)*sizeof(ImatSortNumber));

      for (lin=lin1; lin<=lin2; lin++)
      {
        sort_line_number[lin-lin1].lin = sort_line_index[lin];
        sort_line_number[lin-lin1].number = iupMatrixGetValueNumeric(ih, lin, col);
      }

      qsort(sort_line_number,lin2-lin1+1,sizeof(ImatSortNumber), iMatrixCompareNumberFunc);

      for (lin=lin1; lin<=lin2; lin++)
      {
        if (ascending)
          sort_line_index[lin] = sort_line_number[lin-lin1].lin;
        else
          sort_line_index[lin2 - (lin-lin1)] = sort_line_number[lin-lin1].lin;
      }

      free(sort_line_number);
    }
    else
    {
      ImatSortText* sort_line_text = (ImatSortText*)malloc((lin2-lin1+1)*sizeof(ImatSortText));

      for (lin=lin1; lin<=lin2; lin++)
      {
        sort_line_text[lin-lin1].lin = sort_line_index[lin];
        sort_line_text[lin-lin1].text = iupMatrixGetValueDisplay(ih, lin, col);

        if (ih->data->callback_mode)
          sort_line_text[lin-lin1].text = iupStrDup(sort_line_text[lin-lin1].text);
      }

      iMatrixQSort_utf8 = IupGetInt(NULL, "UTF8MODE");
      iMatrixQSort_casesensitive = iupAttribGetInt(ih, "SORTCOLUMNCASESENSITIVE");
      qsort(sort_line_text,lin2-lin1+1,sizeof(ImatSortText), iMatrixCompareTextFunc);

      for (lin=lin1; lin<=lin2; lin++)
      {
        if (ascending)
          sort_line_index[lin] = sort_line_text[lin-lin1].lin;
        else
          sort_line_index[lin2 - (lin-lin1)] = sort_line_text[lin-lin1].lin;

        if (ih->data->callback_mode && sort_line_text[lin-lin1].text)
          free(sort_line_text[lin-lin1].text);
      }

      free(sort_line_text);
    }
  }

  iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL);
  if (ascending)
    iupAttribSetId(ih, "SORTSIGN", col, "DOWN");
  else
    iupAttribSetId(ih, "SORTSIGN", col, "UP");

  ih->data->sort_has_index = 1;
  ih->data->last_sort_col = col;
  iupMatrixDraw(ih, 1);
  return 0;
}