void CUITrackBar::UpdatePos() { #ifdef DEBUG if(m_b_is_float) R_ASSERT2(m_f_val >= m_f_min && m_f_val <= m_f_max, "CUITrackBar::UpdatePos() - m_val >= m_min && m_val <= m_max" ); else R_ASSERT2(m_i_val >= m_i_min && m_i_val <= m_i_max, "CUITrackBar::UpdatePos() - m_val >= m_min && m_val <= m_max" ); #endif float btn_width = m_pSlider->GetWidth(); float window_width = GetWidth(); float free_space = window_width - btn_width; Fvector2 pos = m_pSlider->GetWndPos(); float __fval = (m_b_is_float)?m_f_val:(float)m_i_val; float __fmax = (m_b_is_float)?m_f_max:(float)m_i_max; float __fmin = (m_b_is_float)?m_f_min:(float)m_i_min; pos.x = (__fval - __fmin)*free_space/(__fmax - __fmin); if( GetInvert() ) pos.x = free_space-pos.x; m_pSlider->SetWndPos (pos); SaveValue (); }
void CUITrackBar::UpdatePosRelativeToMouse() { float _bkf = 0.0f; int _bki = 0; if(m_b_is_float) { _bkf = m_f_val; }else { _bki = m_i_val; } float btn_width = m_pSlider->GetWidth(); float window_width = GetWidth(); //float fpos = cursor_pos.x; // Start.Real Wolf.06.11.14. Fvector2 pos; GetAbsolutePos(pos); float fpos = GetUICursor()->GetCursorPosition().x - pos.x; // Finish.Real Wolf.06.11.14. if( GetInvert() ) fpos = window_width - fpos; if (fpos < btn_width/2) fpos = btn_width/2; else if (fpos > window_width - btn_width/2) fpos = window_width - btn_width/2; float __fval; float __fmax = (m_b_is_float)?m_f_max:(float)m_i_max; float __fmin = (m_b_is_float)?m_f_min:(float)m_i_min; float __fstep = (m_b_is_float)?m_f_step:(float)m_i_step; __fval = (__fmax - __fmin)*(fpos - btn_width/2)/(window_width - btn_width)+ __fmin; float _d = (__fval-__fmin); float _v = _d/__fstep; int _vi = iFloor(_v); float _vf = __fstep*_vi; if(_d-_vf>__fstep/2.0f) _vf += __fstep; __fval = __fmin+_vf; clamp (__fval, __fmin, __fmax); if(m_b_is_float) m_f_val = __fval; else m_i_val = iFloor(__fval); bool b_ch = false; if(m_b_is_float) { b_ch = !fsimilar(_bkf, m_f_val); }else { b_ch = (_bki != m_i_val); } if(b_ch) GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, NULL); UpdatePos (); }
bool CUITrackBar::OnMouseAction(float x, float y, EUIMessages mouse_action) { CUIWindow::OnMouseAction(x, y, mouse_action); switch (mouse_action) { case WINDOW_MOUSE_MOVE: { if(m_bCursorOverWindow && m_b_mouse_capturer) { if (pInput->iGetAsyncBtnState(0)) UpdatePosRelativeToMouse(); } }break; case WINDOW_LBUTTON_DOWN: { m_b_mouse_capturer = m_bCursorOverWindow; if(m_b_mouse_capturer) UpdatePosRelativeToMouse(); }break; case WINDOW_LBUTTON_UP: { m_b_mouse_capturer = false; } break; case WINDOW_MOUSE_WHEEL_UP: { if(m_b_is_float) { m_f_val -= GetInvert()?-m_f_step:m_f_step; clamp(m_f_val, m_f_min, m_f_max); } else { m_i_val -= GetInvert()?-m_i_step:m_i_step; clamp(m_i_val, m_i_min, m_i_max); } GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, NULL); UpdatePos (); OnChangedOptValue (); } break; case WINDOW_MOUSE_WHEEL_DOWN: { if(m_b_is_float) { m_f_val += GetInvert()?-m_f_step:m_f_step; clamp(m_f_val, m_f_min, m_f_max); } else { m_i_val += GetInvert()?-m_i_step:m_i_step; clamp(m_i_val, m_i_min, m_i_max); } GetMessageTarget()->SendMessage(this, BUTTON_CLICKED, NULL); UpdatePos(); OnChangedOptValue (); } break; }; return true; }