コード例 #1
0
ファイル: example4_4.c プロジェクト: sanikoyes/iup
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;
}
コード例 #2
0
ファイル: example4_4.c プロジェクト: sanikoyes/iup
int zoomin_action_cb(Ihandle* ih)
{
  Ihandle* zoom_val = IupGetDialogChild(ih, "ZOOMVAL");
  double zoom_index = IupGetDouble(zoom_val, "VALUE");
  zoom_index++;
  if (zoom_index > 6)
    zoom_index = 6;
  IupSetDouble(zoom_val, "VALUE", round(zoom_index));  /* fixed increments when using buttons */

  zoom_update(ih, zoom_index);
  return IUP_DEFAULT;
}
コード例 #3
0
ファイル: iupmain.c プロジェクト: Vulcanior/IUP
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 */
  }
}
コード例 #4
0
ファイル: example4_4.c プロジェクト: sanikoyes/iup
int canvas_resize_cb(Ihandle* canvas)
{
  imImage* image = (imImage*)IupGetAttribute(canvas, "IMAGE");
  if (image)
  {
    Ihandle* zoom_val = IupGetDialogChild(canvas, "ZOOMVAL");
    double zoom_index = IupGetDouble(zoom_val, "VALUE");
    double zoom_factor = pow(2, zoom_index);
    float old_center_x, old_center_y;

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

    scroll_calc_center(canvas, &old_center_x, &old_center_y);

    scrollbar_update(canvas, view_width, view_height);

    scroll_center(canvas, old_center_x, old_center_y);
  }
  return IUP_DEFAULT;
}
コード例 #5
0
ファイル: example4_4.c プロジェクト: sanikoyes/iup
int zoom_valuechanged_cb(Ihandle* val)
{
  double zoom_index = IupGetDouble(val, "VALUE");
  zoom_update(val, zoom_index);
  return IUP_DEFAULT;
}
コード例 #6
0
ファイル: iuplua_plot.c プロジェクト: mwoz/Hildim.Source
int IupPlotSetFormula(Ihandle* ih, int sample_count, const char* formula, const char* init)
{
  lua_State *L;
  int i, ds_index, ret_count = 1;
  double min, max, step, p, x, y;
  char formula_func[1024];
  IFnL init_cb;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return -1;

  /* must be an IupMatrix */
  if (ih->iclass->nativetype != IUP_TYPECANVAS ||
      !IupClassMatch(ih, "plot"))
    return -1;

  L = luaL_newstate();
  luaL_openlibs(L);

  {
    const char* register_global =
      "function openpackage(ns)\n"
      "  for n, v in pairs(ns) do _G[n] = v end\n"
      "end\n"
      "openpackage(math)\n";
    luaL_dostring(L, register_global);
  }

  if (init)
    luaL_dostring(L, init);

  init_cb = (IFnL)IupGetCallback(ih, "FORMULAINIT_CB");
  if (init_cb)
    init_cb(ih, L);

  lua_pushlightuserdata(L, ih);
  lua_setglobal(L, "plot");

  if (IupGetInt(ih, "FORMULA_PARAMETRIC"))
    ret_count = 2;

  sprintf(formula_func, "function plot_formula(sample_index, %s)\n"
          "  return %s\n"
          "end\n", ret_count == 2 ? "t" : "x", formula);

  if (luaL_dostring(L, formula_func) != 0)
  {
    ShowFormulaError(ih, L);
    lua_close(L);
    return -1;
  }

  min = IupGetDouble(ih, "FORMULA_MIN");
  max = IupGetDouble(ih, "FORMULA_MAX");
  step = (max - min) / (double)(sample_count - 1);

  IupPlotBegin(ih, 0);

  for (i = 0, p = min; i < sample_count; i++, p += step)
  {
    lua_getglobal(L, "plot_formula");
    lua_pushinteger(L, i);
    lua_pushnumber(L, p);

    if (lua_pcall(L, 2, ret_count, 0) != 0)
    {
      ShowFormulaError(ih, L);
      lua_close(L);
      return -1;
    }

    if (!lua_isnumber(L, -1))
    {
      const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA");
      IupMessageError(IupGetDialog(ih), str_message);
      lua_close(L);
      return -1;
    }

    if (ret_count == 2)
    {
      if (!lua_isnumber(L, -2))
      {
        const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA");
        IupMessageError(IupGetDialog(ih), str_message);
        lua_close(L);
        return -1;
      }

      x = lua_tonumber(L, -2);
      y = lua_tonumber(L, -1);

      lua_pop(L, 2);  /* remove the result from the stack */
    }
    else
    {
      x = p;
      y = lua_tonumber(L, -1);

      lua_pop(L, 1);  /* remove the result from the stack */
    }

    IupPlotAdd(ih, x, y);
  }

  ds_index = IupPlotEnd(ih);

  lua_close(L);
  return ds_index;
}