示例#1
0
文件: iup_dial.c 项目: Vulcanior/IUP
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;
}
示例#2
0
文件: iup_dial.c 项目: Vulcanior/IUP
static int iDialButtonPress(Ihandle* ih, int button, int x, int y)
{
  IFn cb;
  
  if (button!=IUP_BUTTON1)    
    return IUP_DEFAULT;

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

  if (ih->data->orientation != IDIAL_CIRCULAR)
    ih->data->angle=0;

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

  return IUP_DEFAULT;
}
示例#3
0
文件: iup_dial.c 项目: Vulcanior/IUP
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;
}
示例#4
0
文件: iup_cells.c 项目: Vulcanior/IUP
static int iCellsButton_CB(Ihandle* ih, int b, int m, int x, int y, char* r)
{
  int i, j;
  IFniiiiiis cb;

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

  /* Treating the button event. The application will receive
   * a button press callback. */
  cb = (IFniiiiiis)IupGetCallback(ih, "MOUSECLICK_CB");
  if (!cb)
    return IUP_DEFAULT;

  iCellsGetCoord(ih, x, y, &i, &j);
  return cb(ih, b, m, i, j, x, y, r);
}
示例#5
0
static int iColorbarButton_CB(Ihandle* ih, int b, int m, int x, int y, char* r)
{
  int idx;

  if (m == 0)
    return IUP_DEFAULT;

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

  if (b == IUP_BUTTON1 && iup_isdouble(r)) 
  { 
    idx = iColorbarGetIndexColor(ih, x, y); 
    if (idx < 0  || idx >= ih->data->num_cells) 
    {
      int ret = iColorbarCheckPreview(ih, x, y);
      if (ret)
      {
        if (ret == 1)
        {
          IFnii switch_cb = (IFnii)IupGetCallback(ih, "SWITCH_CB");

          if (!ih->data->show_secondary)
            return IUP_DEFAULT;

          if (switch_cb && switch_cb(ih, ih->data->fgcolor_idx, ih->data->bgcolor_idx) == IUP_IGNORE) 
            return IUP_DEFAULT;

          /* the application allow to switch the indices */
          idx = ih->data->fgcolor_idx;
          ih->data->fgcolor_idx = ih->data->bgcolor_idx;
          ih->data->bgcolor_idx = idx;

          iColorbarRenderPartsRepaint(ih, 1, ICOLORBAR_RENDER_NONE);   /* only the preview area is rendered */
        }
        else
        {
          if (ret == IUP_PRIMARY)
            idx = ih->data->fgcolor_idx;
          else
            idx = ih->data->bgcolor_idx;

          iColorbarCallCellCb(ih, idx);
        }
      }

      return IUP_DEFAULT;
    }

    ih->data->focus_cell = idx;

    iColorbarCallCellCb(ih, idx);
  }
  else if (b == IUP_BUTTON1)
  { 
    idx = iColorbarGetIndexColor(ih, x, y);
    if (idx < 0  || idx >= ih->data->num_cells)
      return IUP_DEFAULT;

    ih->data->focus_cell = idx;

    iColorbarCallSelectCb(ih, idx, IUP_PRIMARY);
  }
  else if (b == IUP_BUTTON3 && iup_isshift(r)) 
  { 
    idx = iColorbarGetIndexColor(ih, x, y); 
    if (idx < 0  || idx >= ih->data->num_cells)
      return IUP_DEFAULT;

    ih->data->focus_cell = idx;

    iColorbarCallExtentedCb(ih, idx);
  }
  else if (b == IUP_BUTTON3) 
  { 
    idx = iColorbarGetIndexColor(ih, x, y); 
    if (idx < 0  || idx >= ih->data->num_cells)
      return IUP_DEFAULT;

    ih->data->focus_cell = idx;

    iColorbarCallSelectCb(ih, idx, IUP_SECONDARY);
  }

  return IUP_DEFAULT;
}