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; }
static void motValCallAction(Ihandle* ih, int ival, int cb_state) { double old_val = ih->data->val; IFn cb; ih->data->val = (((double)ival/(double)SHRT_MAX)*(ih->data->vmax - ih->data->vmin)) + ih->data->vmin; iupValCropValue(ih); cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB"); if (cb) { if (ih->data->val == old_val) return; cb(ih); } else { IFnd cb_old; if (cb_state == 0) cb_old = (IFnd) IupGetCallback(ih, "MOUSEMOVE_CB"); else if (cb_state == -1) cb_old = (IFnd) IupGetCallback(ih, "BUTTON_RELEASE_CB"); else cb_old = (IFnd) IupGetCallback(ih, "BUTTON_PRESS_CB"); if (cb_old) cb_old(ih, ih->data->val); } }
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; }
static int winValCustomScroll(Ihandle* ih, int msg) { double old_val = ih->data->val; int ival; IFn cb; ival = (int)SendMessage(ih->handle, TBM_GETPOS, 0, 0); if (ih->data->inverted) ival = SHRT_MAX-ival; ih->data->val = (((double)ival/(double)SHRT_MAX)*(ih->data->vmax - ih->data->vmin)) + ih->data->vmin; iupValCropValue(ih); cb = (IFn)IupGetCallback(ih, "VALUECHANGED_CB"); if (cb) { if (ih->data->val == old_val) return 0; cb(ih); } else { IFnd cb_old = NULL; switch (msg) { case TB_BOTTOM: case TB_TOP: case TB_LINEDOWN: case TB_LINEUP: case TB_PAGEDOWN: case TB_PAGEUP: { cb_old = (IFnd) IupGetCallback(ih, "BUTTON_PRESS_CB"); break; } case TB_THUMBPOSITION: { cb_old = (IFnd) IupGetCallback(ih, "BUTTON_RELEASE_CB"); break; } case TB_THUMBTRACK: { cb_old = (IFnd) IupGetCallback(ih, "MOUSEMOVE_CB"); break; } } if (cb_old) cb_old(ih, ih->data->val); } return 0; /* not used */ }
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; }
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; }
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; }
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 */ }