void UIJoypad::Input(UIEvent *currentInput) { if((TOUCH_INVALID_ID == mainTouch) && currentInput->phase == UIEvent::PHASE_BEGAN) { mainTouch = currentInput->tid; } if(mainTouch != currentInput->tid) { return; } if(currentInput->phase == UIEvent::PHASE_ENDED) { currentPos.x = 0; currentPos.y = 0; mainTouch = TOUCH_INVALID_ID; } else { Rect r = GetGeometricData().GetUnrotatedRect();//GetRect(true); currentPos = currentInput->point - r.GetPosition(); currentPos -= Vector2(r.dx * 0.5f, r.dy * 0.5f); if(currentPos.x < deadAreaSize && currentPos.x > -deadAreaSize && currentPos.y < deadAreaSize && currentPos.y > -deadAreaSize) { currentPos.x = 0; currentPos.y = 0; } currentPos.x = Max(currentPos.x, -size.x/2); currentPos.x = Min(currentPos.x, size.x/2); currentPos.y = Max(currentPos.y, -size.y/2); currentPos.y = Min(currentPos.y, size.y/2); } if (stick) { stick->relativePosition.x = size.x/2 + currentPos.x; stick->relativePosition.y = size.y/2 + currentPos.y; } needRecalcAnalog = true; needRecalcDigital = true; currentInput->SetInputHandledType(UIEvent::INPUT_HANDLED_HARD); // Drag is handled - see please DF-2508. }
void UIScrollBar::CalculateStartOffset(const Vector2& inputPoint) { const Rect &r = GetGeometricData().GetUnrotatedRect(); Rect sliderRect = slider->GetRect(); if(orientation == ORIENTATION_HORIZONTAL) { if (((inputPoint.x - r.x) >= sliderRect.x) && ((inputPoint.x - r.x) <= sliderRect.x + sliderRect.dx)) { // The tap happened inside the slider - start "as is". startOffset.x = (sliderRect.x - r.x); } else { // The tap happened outside of the slider - center the slider. startOffset.x = (inputPoint.x - r.x - slider->size.x/2); } } else { // The same with Y. if (((inputPoint.y - r.y) >= sliderRect.y) && ((inputPoint.y - r.y) <= sliderRect.y + sliderRect.dy)) { // The tap happened inside the slider - start "as is". startOffset.y = (sliderRect.y - r.y); } else { // The tap happened outside of the slider - center the slider. startOffset.y = (inputPoint.y - r.y - slider->size.y/2); } } if (startOffset.x < 0.0f) { startOffset.x = 0.0f; } if (startOffset.y < 0.0f) { startOffset.y = 0.0f; } }
void UISlider::Input(UIEvent *currentInput) { #if !defined(__DAVAENGINE_IPHONE__) && !defined(__DAVAENGINE_ANDROID__) if (currentInput->phase == UIEvent::PHASE_MOVE || currentInput->phase == UIEvent::PHASE_KEYCHAR) return; #endif const Rect & absRect = GetGeometricData().GetUnrotatedRect(); //absTouchPoint = currentInput->point; relTouchPoint = currentInput->point; relTouchPoint -= absRect.GetPosition(); float oldVal = currentValue; currentValue = Interpolation::Linear(minValue, maxValue, (float32)leftInactivePart, relTouchPoint.x, size.x - (float32)rightInactivePart); if(currentValue < minValue) { currentValue = minValue; } if(currentValue > maxValue) { currentValue = maxValue; } if (isEventsContinuos) // if continuos events { if(oldVal != currentValue) { PerformEvent(EVENT_VALUE_CHANGED); } }else if (currentInput->phase == UIEvent::PHASE_ENDED) { /* if not continuos always perform event because last move position almost always the same as end pos */ PerformEvent(EVENT_VALUE_CHANGED); } RecalcButtonPos(); }
void UITextField::Update(float32 timeElapsed) { #ifdef __DAVAENGINE_IPHONE__ Rect rect = GetGeometricData().GetUnrotatedRect();//GetRect(true); textFieldiPhone->UpdateRect(rect); #else cursorTime += timeElapsed; if (cursorTime >= 0.5f) { cursorTime = 0; showCursor = !showCursor; needRedraw = true; } if(this == UIControlSystem::Instance()->GetFocusedControl()) { if(needRedraw) { WideString txt = text; if (showCursor) txt += L"_"; else txt += L" "; staticText->SetText(txt); needRedraw = false; } } else { staticText->SetText(text); } #endif }
void UIList::Update(float32 timeElapsed) { if(!delegate) { return; } if(needRefresh) { FullRefresh(); } float d = newPos - oldPos; oldPos = newPos; Rect r = scrollContainer->GetRect(); if(orientation == ORIENTATION_HORIZONTAL) { r.x = scroll->GetPosition(d, SystemTimer::FrameDelta(), lockTouch); } else { r.y = scroll->GetPosition(d, SystemTimer::FrameDelta(), lockTouch); } scrollContainer->SetRect(r); List<UIControl*>::const_iterator it; Rect viewRect = GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); const List<UIControl*> &scrollList = scrollContainer->GetChildren(); List<UIControl*> removeList; //removing invisible elements for(it = scrollList.begin(); it != scrollList.end(); it++) { Rect crect = (*it)->GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); if(orientation == ORIENTATION_HORIZONTAL) { if(crect.x + crect.dx < viewRect.x - viewRect.dx || crect.x > viewRect.x + viewRect.dx*2) { removeList.push_back(*it); } } else { if(crect.y + crect.dy < viewRect.y - viewRect.dy || crect.y > viewRect.y + viewRect.dy*2) { removeList.push_back(*it); } } } for(it = removeList.begin(); it != removeList.end(); it++) { scrollContainer->RemoveControl((*it)); } if (!scrollList.empty()) { //adding elements at the list end int32 ind = -1; UIListCell *fc = NULL; for(it = scrollList.begin(); it != scrollList.end(); it++) { UIListCell *lc = (UIListCell *)(*it); int32 i = lc->GetIndex(); if(i > ind) { ind = i; fc = lc; } } if(fc) { int32 borderPos; int32 rPos; int size = 0; int32 off; if(orientation == ORIENTATION_HORIZONTAL) { borderPos = (int32)(viewRect.dx + viewRect.dx / 2.0f); off = (int32)scrollContainer->GetRect().x; rPos = (int32)(fc->GetRect().x + fc->GetRect().dx + off); } else { borderPos = (int32)(viewRect.dy + viewRect.dy / 22.0f); off = (int32)scrollContainer->GetRect().y; rPos = (int32)(fc->GetRect().y + fc->GetRect().dy + off); } while(rPos < borderPos && fc->GetIndex() < delegate->ElementsCount(this) - 1) { int32 i = fc->GetIndex() + 1; fc = delegate->CellAtIndex(this, i); if(orientation == ORIENTATION_HORIZONTAL) { size = delegate->CellWidth(this, i); } else { size = delegate->CellHeight(this, i); } AddCellAtPos(fc, rPos - off, size, i); rPos += size; // scroll->SetElementSize((float32)(rPos - off)); } } //adding elements at the list begin ind = maximumElementsCount; fc = NULL; for(it = scrollList.begin(); it != scrollList.end(); it++) { UIListCell *lc = (UIListCell *)(*it); int32 i = lc->GetIndex(); if(i < ind) { ind = i; fc = lc; } } if(fc) { int32 borderPos; int32 rPos; int size = 0; int32 off; if(orientation == ORIENTATION_HORIZONTAL) { borderPos = (int32)(-viewRect.dx/2.0f); off = (int32)scrollContainer->GetRect().x; rPos = (int32)(fc->GetRect().x + off); } else { borderPos = (int32)(-viewRect.dy/2.0f); off = (int32)scrollContainer->GetRect().y; rPos = (int32)(fc->GetRect().y + off); } while(rPos > borderPos && fc->GetIndex() > 0) { int32 i = fc->GetIndex() - 1; fc = delegate->CellAtIndex(this, i); if(orientation == ORIENTATION_HORIZONTAL) { size = delegate->CellWidth(this, i); } else { size = delegate->CellHeight(this, i); } rPos -= size; AddCellAtPos(fc, rPos - off, size, i); } } } else { FullRefresh(); } }
void UIHierarchy::Update(float32 timeElapsed) { if(!delegate) { return; } if(needRedraw) { FullRedraw(); } scroll->SetViewSize(size.y); float d = newPos - oldPos; oldPos = newPos; float32 newY = scroll->GetPosition(d, timeElapsed, lockTouch); if (scrollContainer->relativePosition.y != newY) { scrollContainer->relativePosition.y = newY; List<UIControl*>::const_iterator it; Rect viewRect = GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); const List<UIControl*> &scrollList = scrollContainer->GetChildren(); List<UIControl*> removeList; //removing invisible elements for(it = scrollList.begin(); it != scrollList.end(); it++) { Rect crect = (*it)->GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); if(crect.y <= viewRect.y - viewRect.dy || crect.y > viewRect.y + viewRect.dy*2) { removeList.push_back(*it); } } for(it = removeList.begin(); it != removeList.end(); it++) { scrollContainer->RemoveControl((*it)); } UIControl *lastCell = NULL; UIControl *firstCell = NULL; int32 maxPos = -999999; int32 minPos = 999999; for(it = scrollList.begin(); it != scrollList.end(); it++) { if ((*it)->relativePosition.y > maxPos) { maxPos = (int32)(*it)->relativePosition.y; lastCell = (*it); } if ((*it)->relativePosition.y < minPos) { minPos = (int32)(*it)->relativePosition.y; firstCell = (*it); } } if(!scrollList.empty()) { //adding elements to the list bottom if (lastCell) { addPos = (int32)lastCell->relativePosition.y + cellHeight; if(addPos + (int32)scrollContainer->relativePosition.y <= size.y * 2) { AddCellsAfter(((UIHierarchyCell *)lastCell)->node); } } //adding elements to the list top if (firstCell) { addPos = (int32)firstCell->relativePosition.y - cellHeight; if(addPos + (int32)scrollContainer->relativePosition.y + cellHeight > -size.y) { AddCellsBefore(((UIHierarchyCell *)firstCell)->node); } } } else { FullRedraw(); } } }