Exemplo n.º 1
0
/*********************************************************************
*
*       _CalcPositions
*
*  Calculates all positions required for drawing or for mouse / touch
*  evaluation.
*/
static void _CalcPositions(SCROLLBAR_Obj* pObj, SCROLLBAR_POSITIONS* pPos) {
  int xSizeArrow, xSize, xSizeMoveable, ThumbSize, NumItems, xSizeThumbArea;
  WM_HWIN hWin;
  GUI_RECT r, rSub;
  int x0, y0;
  r = pObj->Widget.Win.Rect;
  x0 = r.x0;
  y0 = r.y0;
  pPos->x1  = (pObj->Widget.State & WIDGET_STATE_VERTICAL) ? r.y1 : r.x1;
  /* Subtract the rectangle of the other scrollbar (if existing and visible) */
  if (pObj->Widget.Id == GUI_ID_HSCROLL) {
    hWin = WM_GetScrollbarV(pObj->Widget.Win.hParent);
    if (hWin) {
      WM_GetWindowRectEx(hWin, &rSub);
      if (r.x1 == rSub.x1) {
        r.x1 = rSub.x0 -1;
      }
    }
  }
  if (pObj->Widget.Id == GUI_ID_VSCROLL) {
    hWin = WM_GetScrollbarH(pObj->Widget.Win.hParent);
    if (hWin) {
      WM_GetWindowRectEx(hWin, &rSub);
      if (r.y1 == rSub.y1) {
        r.y1 = rSub.y0 -1;
      }
    }
  }
  /* Convert coordinates of this window */
  GUI_MoveRect(&r, -x0, -y0);
  /* Convert real into virtual coordinates */
  _WIDGET__RECT2VRECT(&pObj->Widget, &r);
  NumItems      = pObj->NumItems;
  xSize         = r.x1 - r.x0 + 1;
  xSizeArrow    = _GetArrowSize(pObj);
  xSizeThumbArea= xSize - 2 * xSizeArrow;     /* Number of pixels available for thumb and movement */
  ThumbSize     = GUI__DivideRound(xSizeThumbArea * pObj->PageSize, NumItems);
  if (ThumbSize < 4) {
    ThumbSize = 4;
  }
  if (ThumbSize > xSizeThumbArea) {
    ThumbSize = xSizeThumbArea;
  }
  xSizeMoveable = xSizeThumbArea - ThumbSize;
  pPos->x0_LeftArrow  = r.x0;
  pPos->x1_LeftArrow  = xSizeArrow - 1;
  pPos->x1_RightArrow = xSize - 1;
  pPos->x0_RightArrow = xSize - xSizeArrow;
  pPos->x0_Thumb      = pPos->x1_LeftArrow + 1+ GUI__DivideRound(xSizeMoveable * pObj->v, NumItems - pObj->PageSize);
  pPos->x1_Thumb      = pPos->x0_Thumb + ThumbSize - 1;
  pPos->xSizeMoveable = xSizeMoveable;
  pPos->ThumbSize     = ThumbSize;
}
Exemplo n.º 2
0
/*********************************************************************
*
*       _OnTouch
*/
static void _OnTouch(SLIDER_Handle hObj, SLIDER_Obj* pObj, WM_MESSAGE*pMsg) {
  GUI_TOUCH_tState* pState = (GUI_TOUCH_tState*)pMsg->Data.p;
  if (pMsg->Data.p) {  /* Something happened in our area (pressed or released) */
    if (pState->Pressed) {
      int Sel;
      int Range = (pObj->Max - pObj->Min);
      int x0, xsize;
      int x;
      x0 = 1 + pObj->Width/2;  /* 1 pixel focus rectangle + width of actual slider */
      x = (pObj->Widget.State & WIDGET_STATE_VERTICAL) ? pState->y : pState->x;
      x -= x0;
      xsize = WIDGET__GetWindowSizeX(hObj) - 2 * x0;
      if (x <= 0) {
        Sel = pObj->Min;
      } else if (x >= xsize) {
        Sel = pObj->Max;
      } else {
        Sel = GUI__DivideRound(Range* x, xsize);
        Sel += pObj->Min;
      }
      WM_SetFocus(hObj);
      WM_SetCapture(hObj, 1);
      SLIDER_SetValue(hObj, Sel);
    } 
  }
}
Exemplo n.º 3
0
/*********************************************************************
*
*       _OnTouch
*/
static void _OnTouch(SCROLLBAR_Handle hObj, SCROLLBAR_Obj* pObj, WM_MESSAGE*pMsg) {
  SCROLLBAR_POSITIONS Pos;
  GUI_PID_STATE* pState = (GUI_PID_STATE*)pMsg->Data.p;
  if (pMsg->Data.p) {  /* Something happened in our area (pressed or released) */
    if (pState->Pressed) {
      int Sel;
      int Range;
      int x;
      Sel = pObj->v;
      _CalcPositions(pObj, &Pos);
      Range = pObj->NumItems - pObj->PageSize;
      /* Swap mouse coordinates if necessary */
      if (pObj->Widget.State & WIDGET_STATE_VERTICAL) {
        int t = pState->x;
        pState->x = pState->y;
        pState->y = t;
      }
      x = pState->x;
      if (x <= Pos.x1_LeftArrow) {         /* left arrow (line left) */
        Sel--;
      } else if (x < Pos.x0_Thumb) {       /* left area  (page left) */
        Sel -= pObj->PageSize;
      } else if (x <= Pos.x1_Thumb) {      /* Thumb area */
        if (Pos.xSizeMoveable > 0) {
          x = x - Pos.ThumbSize/2 - Pos.x1_LeftArrow-1;
          Sel = GUI__DivideRound(Range * x, Pos.xSizeMoveable);
        }
      } else if (x < Pos.x0_RightArrow) {  /* right area (page right) */
        Sel += pObj->PageSize;
      } else  if (x <= Pos.x1_RightArrow) {
        Sel++;
      }
      /* WM_SetFocus(hObj); */
      WM_SetCapture(hObj, 1);
      SCROLLBAR_SetValue(hObj, Sel);
      if ((pObj->Widget.State & SCROLLBAR_STATE_PRESSED) == 0){   
        _ScrollbarPressed(hObj, pObj);
      }
    } else {
      /* React only if button was pressed before ... avoid problems with moving / hiding windows above (such as dropdown) */
      if (pObj->Widget.State & SCROLLBAR_STATE_PRESSED) {   
        _ScrollbarReleased(hObj, pObj);
      }
    }
  }
}