Example #1
0
static int iDialMotionHorizontal_CB(Ihandle* ih, int x, int y, char *status)
{
  IFn cb;
  
  if (!iup_isbutton1(status))     
    return IUP_DEFAULT;

  y = cdIupInvertYAxis(y, ih->data->h);
  ih->data->angle += (double)(x-ih->data->px) / ih->data->radius;
  ih->data->px = x;

  iDialRepaint(ih);

  cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB");
  if (cb)
    cb(ih);
  else
  {
    IFnd cb_old = (IFnd) IupGetCallback(ih, "MOUSEMOVE_CB");
    if (cb_old)
      cb_old(ih, ih->data->angle * ih->data->unit);
  }

  return IUP_DEFAULT;
}
Example #2
0
static int iDialSetValueAttrib(Ihandle* ih, const char* value)
{
  if (!value) /* reset to default */
    ih->data->angle = 0;
  else
    ih->data->angle = atof(value);

  iDialRepaint(ih);
  return 0; /* do not store value in hash table */
}
Example #3
0
static int iDialSetFgColorAttrib(Ihandle* ih, const char* value)
{
  unsigned char r, g, b;

  if (!iupStrToRGB(value, &r, &g, &b))
    return 0;
  iDialUpdateFgColors(ih, r, g, b);

  iDialRepaint(ih);
  return 1;
}
Example #4
0
static int iDialSetBgColorAttrib(Ihandle* ih, const char* value)
{
  if (!value)
    value = iupControlBaseGetParentBgColor(ih);

  ih->data->bgcolor = cdIupConvertColor(value);

  cdIupCalcShadows(ih->data->bgcolor, &ih->data->light_shadow, &ih->data->mid_shadow, &ih->data->dark_shadow);
  if (!iupdrvIsActive(ih))
    ih->data->light_shadow = ih->data->mid_shadow;
  
  iDialRepaint(ih);
  return 1;
}
Example #5
0
static int iDialMotionCircular_CB(Ihandle* ih, int x, int y, char *status)
{
  int cx = ih->data->w / 2;
  int cy = ih->data->h / 2;
  double vet, xa, ya, xb, yb, ma, mb, ab;
  IFn cb;

  if (!iup_isbutton1(status))     
    return IUP_DEFAULT;

  y = cdIupInvertYAxis(y, ih->data->h);

  xa = ih->data->px-cx; 
  ya = ih->data->py-cy; 
  ma = sqrt(xa * xa + ya * ya);

  xb = x - cx;  
  yb = y - cy;  
  mb = sqrt(xb * xb + yb * yb);

  ab  = xa * xb + ya * yb;
  vet = xa * yb - xb * ya;

  ab = ab / (ma * mb);

  /* if the mouse is in the center of the dial, ignore it */
  if (ma == 0 || mb == 0 || ab < -1 || ab > 1)
    return IUP_DEFAULT;

  if (vet>0) ih->data->angle += acos(ab);
  else       ih->data->angle -= acos(ab);

  iDialRepaint(ih);
  ih->data->px = x;
  ih->data->py = y;

  cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB");
  if (cb)
    cb(ih);
  else
  {
    IFnd cb_old = (IFnd) IupGetCallback(ih, "MOUSEMOVE_CB");
    if (cb_old)
      cb_old(ih, ih->data->angle * ih->data->unit);
  }

  return IUP_DEFAULT;
}
Example #6
0
static int iDialSetActiveAttrib(Ihandle* ih, const char* value)
{
  unsigned char r, g, b;

  iupBaseSetActiveAttrib(ih, value);

  value = iupAttribGetStr(ih, "FGCOLOR");
  if (!iupStrToRGB(value, &r, &g, &b))
    return 0;
  iDialUpdateFgColors(ih, r, g, b);

  cdIupCalcShadows(ih->data->bgcolor, &ih->data->light_shadow, &ih->data->mid_shadow, &ih->data->dark_shadow);
  if (!iupdrvIsActive(ih))
    ih->data->light_shadow = ih->data->mid_shadow;

  iDialRepaint(ih);
  return 0;   /* do not store value in hash table */
}
Example #7
0
static int iDialButtonRelease(Ihandle* ih, int button)
{
  IFn cb;
  
  if (button!=IUP_BUTTON1)    
    return IUP_DEFAULT;

  iDialRepaint(ih);

  cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB");
  if (cb)
    cb(ih);
  else
  {
    IFnd cb_old = (IFnd) IupGetCallback(ih, "BUTTON_RELEASE_CB");
    if (cb_old)
      cb_old(ih, ih->data->angle * ih->data->unit);
  }

  return IUP_DEFAULT;
}
Example #8
0
static int iDialWheel_CB(Ihandle* ih, float delta)
{
  IFn cb;
  
  ih->data->angle += ((double)delta) * (M_PI / 10.0);

  if (fabs(ih->data->angle) < M_PI / 10.1)
    ih->data->angle = 0;

  iDialRepaint(ih);

  cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB");
  if (cb)
    cb(ih);
  else
  {
    IFnd cb_old = (IFnd) IupGetCallback(ih, "MOUSEMOVE_CB");
    if (cb_old)
      cb_old(ih, ih->data->angle * ih->data->unit);
  }

  return IUP_DEFAULT;
}
Example #9
0
static int iDialSetDensityAttrib(Ihandle* ih, const char* value)
{
  if (iupStrToDoubleDef(value, &(ih->data->density), 0.2))
    iDialRepaint(ih);
  return 0;   /* do not store value in hash table */
}
Example #10
0
static int iDialKeyPress_CB(Ihandle* ih, int c, int press)
{
  IFn cb;
  char* cb_name;

  if (c != K_LEFT   && c != K_UP   &&
      c != K_sLEFT  && c != K_sUP  &&
      c != K_RIGHT  && c != K_DOWN &&
      c != K_sRIGHT && c != K_sDOWN &&
      c != K_HOME)
    return IUP_DEFAULT;

  if (press && ih->data->pressing)
  {
    switch(c)
    {
    case K_sLEFT:
    case K_sDOWN:
      ih->data->angle -= M_PI / 100.0;
      break;
    case K_LEFT:
    case K_DOWN:
      ih->data->angle -= M_PI / 10.0;
      break;
    case K_sRIGHT:
    case K_sUP:
      ih->data->angle += M_PI / 100.0;
      break;
    case K_RIGHT:
    case K_UP:
      ih->data->angle += M_PI / 10.0;
      break;
    }
  }

  if (c == K_HOME)
    ih->data->angle = 0;

  if (press)
  {
    if (ih->data->pressing)
    {
      cb_name = "MOUSEMOVE_CB";
    }
    else
    {
      ih->data->pressing = 1;
      if (ih->data->orientation != IDIAL_CIRCULAR)
        ih->data->angle = 0;
      cb_name = "BUTTON_PRESS_CB";
    }
  }
  else
  {
    ih->data->pressing = 0;
    cb_name = "RELEASE_CB";
  }

  iDialRepaint(ih);

  cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB");
  if (cb)
    cb(ih);
  else
  {
    IFnd cb_old = (IFnd) IupGetCallback(ih, cb_name);
    if (cb_old)
      cb_old(ih, ih->data->angle * ih->data->unit);
  }

  return IUP_IGNORE;  /* to avoid arrow keys being processed by the system */
}
Example #11
0
static int iDialFocus_CB(Ihandle* ih, int focus)
{
  ih->data->has_focus = focus;
  iDialRepaint(ih);
  return IUP_DEFAULT;
}
Example #12
0
static int iDialSetDensityAttrib(Ihandle* ih, const char* value)
{
  ih->data->density = atof(value);
  iDialRepaint(ih);
  return 0;   /* do not store value in hash table */
}