bool C4Object::Exit(int32_t iX, int32_t iY, int32_t iR, C4Real iXDir, C4Real iYDir, C4Real iRDir, bool fCalls) { // 1. Exit the current container. // 2. Update Contents of container object and set Contained to nullptr. // 3. Set offset position/motion if desired. // 4. Call Ejection for container and Departure for object. // Not contained C4Object *pContainer=Contained; if (!pContainer) return false; // Remove object from container pContainer->Contents.Remove(this); pContainer->UpdateMass(); pContainer->SetOCF(); // No container Contained=nullptr; // Position/motion fix_x=itofix(iX); fix_y=itofix(iY); fix_r=itofix(iR); BoundsCheck(fix_x, fix_y); xdir=iXDir; ydir=iYDir; rdir=iRDir; // Misc updates Mobile=true; InLiquid=false; CloseMenu(true); UpdateFace(true); SetOCF(); // Object list callback (before script callbacks, because script callbacks may enter again) ObjectListChangeListener.OnObjectContainerChanged(this, pContainer, nullptr); // Engine calls if (fCalls) pContainer->Call(PSF_Ejection,&C4AulParSet(this)); if (fCalls) Call(PSF_Departure,&C4AulParSet(pContainer)); // Success (if the obj wasn't "re-entered" by script) return !Contained; }
/* public ZBasicString<A>::Erase Erase function. Erases characters between the given indices. @param _start - the starting index @param __end - the ending index index (exclusive) @return (void) @assert - if _start or _end out of bounds if _end < _start */ void Erase(const size_t _start, const size_t _end) { if (_start == _end) return; size_t start = BoundsCheck(_start, Length()); size_t end = BoundsCheck(_end, Length() + 1); #if !ZSTL_DISABLE_RUNTIME_CHECKS ZSTL_ASSERT(start <= end, "ZBasicString: Cannot erase with _end < _start!"); #endif StringArray.Erase(start, end); CheckIntegrity(); }
float Curve::QuadraticEaseInOut(float t, float start, float end) { BoundsCheck(t, start, end); t *= 2.f; if (t < 1.f) return end/2.f * t * t + start; t--; return -end/2.f * (t*(t-2) - 1) + start; }
/* public ZBasicString<A>::Insert Insert function. Inserts a string into this string. @param _index - index to insert at @param _other - string to insert @return (void) @assert - if index is invalid */ void Insert(const size_t _index, const ZBasicString<A>& _other) { size_t index = BoundsCheck(_index, Length() + 1); StringArray.Insert(index, _other.Array(), 0, _other.Length()); CheckIntegrity(); }
/* public ZBasicString<A>::Insert Insert function. Inserts a character into this string. @param _index - index to insert at @param _char - character to insert @return (void) @assert - if index is invalid */ void Insert(const size_t _index, const char& _char) { size_t index = BoundsCheck(_index, Length() + 1); StringArray.Insert(index, _char); CheckIntegrity(); }
float Curve::CubicEaseInOut(float t, float start, float end) { BoundsCheck(t, start, end); t *= 2.; if (t < 1.) return end/2 * t * t * t + start; t -= 2; return end/2*(t * t * t + 2) + start; }
float Curve::ExponentialEaseInOut(float t, float start, float end) { BoundsCheck(t, start, end); t *= 2.f; if (t < 1.f) return end/2.f * powf(2.f, 10.f * (t - 1.f) ) + start; t--; return end/2.f * ( -powf(2.f, -10.f * t) + 2.f ) + start; }
float Curve::CircularEaseInOut(float t, float start, float end) { BoundsCheck(t, start, end); t *= 2.f; if (t < 1.f) return -end/2.f * (sqrtf(1.f - t * t) - 1.f) + start; t -= 2.f; return end/2.f * (sqrtf(1.f - t * t) + 1.f) + start; }
void Camera::Walk(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPosition); XMFLOAT3 test; XMStoreFloat3(&test, XMVectorMultiplyAdd(s, l, p)); if (mUseConstraints){ if (BoundsCheck(test)){ mPosition = test; } } else{ mPosition = test; } }
nsSize nsBox::GetPrefSize(nsBoxLayoutState& aState) { NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context"); nsSize pref(0,0); DISPLAY_PREF_SIZE(this, pref); if (IsCollapsed(aState)) return pref; AddBorderAndPadding(pref); nsIBox::AddCSSPrefSize(aState, this, pref); nsSize minSize = GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); return BoundsCheck(minSize, pref, maxSize); }
nsSize nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState) { nsSize size = nsBoxFrame::GetPrefSize(aState); DISPLAY_PREF_SIZE(this, size); // If we are using sizetopopup="always" then // nsBoxFrame will already have enforced the minimum size if (!IsSizedToPopup(mContent, PR_TRUE) && IsSizedToPopup(mContent, PR_FALSE) && SizeToPopup(aState, size)) { // We now need to ensure that size is within the min - max range. nsSize minSize = nsBoxFrame::GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); size = BoundsCheck(minSize, size, maxSize); } return size; }
/** * Ok return our dimensions */ nsSize nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState) { nsSize size(0,0); DISPLAY_PREF_SIZE(this, size); if (DoesNeedRecalc(mImageSize)) GetImageSize(); if (!mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0)) size = nsSize(mSubRect.width, mSubRect.height); else size = mImageSize; AddBorderAndPadding(size); nsIBox::AddCSSPrefSize(aState, this, size); nsSize minSize = GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); return BoundsCheck(minSize, size, maxSize); }
nsSize nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState) { if (!DoesNeedRecalc(mPrefSize)) return mPrefSize; #ifdef DEBUG_LAYOUT PropagateDebug(aState); #endif nsSize pref(0,0); // FIXME: This inflation parameter isn't correct; we should fix it if // we want font size inflation to work well in XUL. If we do, we can // also re-enable the assertion in ComputeAutoSize when inflation is // enabled. nsresult rv = CalcIntrinsicSize(aState.GetRenderingContext(), pref, 1.0f); NS_ENSURE_SUCCESS(rv, pref); AddBorderAndPadding(pref); bool widthSet, heightSet; nsIBox::AddCSSPrefSize(this, pref, widthSet, heightSet); nsSize minSize = GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); mPrefSize = BoundsCheck(minSize, pref, maxSize); #ifdef DEBUG_rods { nsMargin borderPadding(0,0,0,0); GetBorderAndPadding(borderPadding); nsSize size(169, 24); nsSize actual(pref.width/15, pref.height/15); printf("nsGfxText(field) %d,%d %d,%d %d,%d\n", size.width, size.height, actual.width, actual.height, actual.width-size.width, actual.height-size.height); // text field } #endif return mPrefSize; }
nsSize nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState) { if (!DoesNeedRecalc(mPrefSize)) return mPrefSize; #ifdef DEBUG_LAYOUT PropagateDebug(aState); #endif nsSize pref(0,0); nsresult rv = CalcIntrinsicSize(aState.GetRenderingContext(), pref); NS_ENSURE_SUCCESS(rv, pref); AddBorderAndPadding(pref); PRBool widthSet, heightSet; nsIBox::AddCSSPrefSize(this, pref, widthSet, heightSet); nsSize minSize = GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); mPrefSize = BoundsCheck(minSize, pref, maxSize); #ifdef DEBUG_rods { nsMargin borderPadding(0,0,0,0); GetBorderAndPadding(borderPadding); nsSize size(169, 24); nsSize actual(pref.width/15, pref.height/15); printf("nsGfxText(field) %d,%d %d,%d %d,%d\n", size.width, size.height, actual.width, actual.height, actual.width-size.width, actual.height-size.height); // text field } #endif return mPrefSize; }
/* public ZBasicString<A>::Front Gets a reference to the character at the front of the string. @return (char&) - the character at the front of the string @assert - if the string is empty */ char& Front() const { return StringArray.Data()[BoundsCheck(0, Length())]; }
void nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { // This is mostly a copy of nsBoxFrame::Reflow(). // We aren't able to share an implementation because of the frame // class hierarchy. If you make changes here, please keep // nsBoxFrame::Reflow in sync. DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_ASSERTION(aReflowState.ComputedWidth() >=0 && aReflowState.ComputedHeight() >= 0, "Computed Size < 0"); #ifdef DO_NOISY_REFLOW printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n"); printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++); switch (aReflowState.reason) { case eReflowReason_Initial: printf("Ini");break; case eReflowReason_Incremental: printf("Inc");break; case eReflowReason_Resize: printf("Rsz");break; case eReflowReason_StyleChange: printf("Sty");break; case eReflowReason_Dirty: printf("Drt "); break; default:printf("<unknown>%d", aReflowState.reason);break; } printSize("AW", aReflowState.AvailableWidth()); printSize("AH", aReflowState.AvailableHeight()); printSize("CW", aReflowState.ComputedWidth()); printSize("CH", aReflowState.ComputedHeight()); printf(" *\n"); #endif aStatus = NS_FRAME_COMPLETE; // create the layout state nsBoxLayoutState state(aPresContext, aReflowState.rendContext); nsSize computedSize(aReflowState.ComputedWidth(),aReflowState.ComputedHeight()); nsMargin m; m = aReflowState.ComputedPhysicalBorderPadding(); //GetBorderAndPadding(m); // this happens sometimes. So lets handle it gracefully. if (aReflowState.ComputedHeight() == 0) { nsSize minSize = GetMinSize(state); computedSize.height = minSize.height - m.top - m.bottom; } nsSize prefSize(0,0); // if we are told to layout intrinic then get our preferred size. if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) { prefSize = GetPrefSize(state); nsSize minSize = GetMinSize(state); nsSize maxSize = GetMaxSize(state); prefSize = BoundsCheck(minSize, prefSize, maxSize); } // get our desiredSize if (aReflowState.ComputedWidth() == NS_INTRINSICSIZE) { computedSize.width = prefSize.width; } else { computedSize.width += m.left + m.right; } if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) { computedSize.height = prefSize.height; } else { computedSize.height += m.top + m.bottom; } // handle reflow state min and max sizes // XXXbz the width handling here seems to be wrong, since // mComputedMin/MaxWidth is a content-box size, whole // computedSize.width is a border-box size... if (computedSize.width > aReflowState.ComputedMaxWidth()) computedSize.width = aReflowState.ComputedMaxWidth(); if (computedSize.width < aReflowState.ComputedMinWidth()) computedSize.width = aReflowState.ComputedMinWidth(); // Now adjust computedSize.height for our min and max computed // height. The only problem is that those are content-box sizes, // while computedSize.height is a border-box size. So subtract off // m.TopBottom() before adjusting, then readd it. computedSize.height = std::max(0, computedSize.height - m.TopBottom()); computedSize.height = NS_CSS_MINMAX(computedSize.height, aReflowState.ComputedMinHeight(), aReflowState.ComputedMaxHeight()); computedSize.height += m.TopBottom(); nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height); SetBounds(state, r); // layout our children Layout(state); // ok our child could have gotten bigger. So lets get its bounds aDesiredSize.Width() = mRect.width; aDesiredSize.Height() = mRect.height; aDesiredSize.SetTopAscent(GetBoxAscent(state)); // the overflow rect is set in SetBounds() above aDesiredSize.mOverflowAreas = GetOverflowAreas(); #ifdef DO_NOISY_REFLOW { printf("%p ** nsLBF(done) W:%d H:%d ", this, aDesiredSize.Width(), aDesiredSize.Height()); if (maxElementWidth) { printf("MW:%d\n", *maxElementWidth); } else { printf("MW:?\n"); } } #endif }
float Curve::CircularEaseOut(float t, float start, float end) { BoundsCheck(t, start, end); t--; return end * sqrtf(1.f - t * t) + start; }
float Curve::CircularEaseIn(float t, float start, float end) { BoundsCheck(t, start, end); return -end * (sqrtf(1.f - t * t) - 1.f) + start; }
NS_IMETHODIMP nsPopupSetFrame::DoLayout(nsBoxLayoutState& aState) { // lay us out nsresult rv = nsBoxFrame::DoLayout(aState); // lay out all of our currently open popups. nsPopupFrameList* currEntry = mPopupList; while (currEntry) { nsIFrame* popupChild = currEntry->mPopupFrame; if (popupChild) { NS_ASSERTION(popupChild->IsBoxFrame(), "popupChild is not box!!"); // then get its preferred size nsSize prefSize(0,0); nsSize minSize(0,0); nsSize maxSize(0,0); popupChild->GetPrefSize(aState, prefSize); popupChild->GetMinSize(aState, minSize); popupChild->GetMaxSize(aState, maxSize); BoundsCheck(minSize, prefSize, maxSize); // if the pref size changed then set bounds to be the pref size // and sync the view. Also set new pref size. // if (currEntry->mLastPref != prefSize) { popupChild->SetBounds(aState, nsRect(0,0,prefSize.width, prefSize.height)); RepositionPopup(currEntry, aState); currEntry->mLastPref = prefSize; // } // is the new size too small? Make sure we handle scrollbars correctly nsIBox* child; popupChild->GetChildBox(&child); nsRect bounds(popupChild->GetRect()); nsCOMPtr<nsIScrollableFrame> scrollframe = do_QueryInterface(child); if (scrollframe && scrollframe->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_AUTO) { // if our pref height if (bounds.height < prefSize.height) { // layout the child popupChild->Layout(aState); nsMargin scrollbars = scrollframe->GetActualScrollbarSizes(); if (bounds.width < prefSize.width + scrollbars.left + scrollbars.right) { bounds.width += scrollbars.left + scrollbars.right; //printf("Width=%d\n",width); popupChild->SetBounds(aState, bounds); } } } // layout the child popupChild->Layout(aState); // only size popup if open if (currEntry->mCreateHandlerSucceeded) { nsIView* view = popupChild->GetView(); nsIViewManager* viewManager = view->GetViewManager(); nsRect r(0, 0, bounds.width, bounds.height); viewManager->ResizeView(view, r); viewManager->SetViewVisibility(view, nsViewVisibility_kShow); } } currEntry = currEntry->mNextPopup; } SyncLayout(aState); return rv; }
/** * Ok return our dimensions */ nsSize nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState) { nsSize size(0,0); DISPLAY_PREF_SIZE(this, size); if (DoesNeedRecalc(mImageSize)) GetImageSize(); if (!mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0)) size = nsSize(mSubRect.width, mSubRect.height); else size = mImageSize; nsSize intrinsicSize = size; nsMargin borderPadding(0,0,0,0); GetBorderAndPadding(borderPadding); size.width += borderPadding.LeftRight(); size.height += borderPadding.TopBottom(); PRBool widthSet, heightSet; nsIBox::AddCSSPrefSize(this, size, widthSet, heightSet); NS_ASSERTION(size.width != NS_INTRINSICSIZE && size.height != NS_INTRINSICSIZE, "non-nintrinsic size expected"); nsSize minSize = GetMinSize(aState); nsSize maxSize = GetMaxSize(aState); if (!widthSet && !heightSet) { if (minSize.width != NS_INTRINSICSIZE) minSize.width -= borderPadding.LeftRight(); if (minSize.height != NS_INTRINSICSIZE) minSize.height -= borderPadding.TopBottom(); if (maxSize.width != NS_INTRINSICSIZE) maxSize.width -= borderPadding.LeftRight(); if (maxSize.height != NS_INTRINSICSIZE) maxSize.height -= borderPadding.TopBottom(); size = nsLayoutUtils::ComputeAutoSizeWithIntrinsicDimensions(minSize.width, minSize.height, maxSize.width, maxSize.height, intrinsicSize.width, intrinsicSize.height); NS_ASSERTION(size.width != NS_INTRINSICSIZE && size.height != NS_INTRINSICSIZE, "non-nintrinsic size expected"); size.width += borderPadding.LeftRight(); size.height += borderPadding.TopBottom(); return size; } if (!widthSet) { if (intrinsicSize.height > 0) { // Subtract off the border and padding from the height because the // content-box needs to be used to determine the ratio nscoord height = size.height - borderPadding.TopBottom(); size.width = nscoord(PRInt64(height) * PRInt64(intrinsicSize.width) / PRInt64(intrinsicSize.height)); } else { size.width = intrinsicSize.width; } size.width += borderPadding.LeftRight(); } else if (!heightSet) { if (intrinsicSize.width > 0) { nscoord width = size.width - borderPadding.LeftRight(); size.height = nscoord(PRInt64(width) * PRInt64(intrinsicSize.height) / PRInt64(intrinsicSize.width)); } else { size.height = intrinsicSize.height; } size.height += borderPadding.TopBottom(); } return BoundsCheck(minSize, size, maxSize); }
float Curve::ExponentialEaseOut(float t, float start, float end) { BoundsCheck(t, start, end); return end * (-powf(2.f, -10.f * t) + 1.f ) + start; }
BoundsCheck recognizeBoundsCheck(const Jump *jump, const BasicBlock *ifPassed, const dflow::Dataflow &dataflow) { if (jump->isUnconditional()) { return BoundsCheck(); } bool inverse; if (jump->thenTarget().basicBlock() == ifPassed) { inverse = false; } else if (jump->elseTarget().basicBlock() == ifPassed) { inverse = true; } else { return BoundsCheck(); } auto condition = getFirstCopy(jump->condition(), dataflow); for (std::size_t niterations = 0; niterations < 10; ++niterations) { if (auto unary = condition->as<UnaryOperator>()) { if (unary->operatorKind() == UnaryOperator::NOT && unary->size() == 1) { condition = getFirstCopy(unary->operand(), dataflow); inverse = !inverse; } else { break; } } else { break; } } if (auto binary = condition->as<BinaryOperator>()) { if (!inverse) { switch (binary->operatorKind()) { case BinaryOperator::UNSIGNED_LESS_OR_EQUAL: { const dflow::Value *rightValue = dataflow.getValue(binary->right()); if (rightValue->abstractValue().isConcrete()) { return BoundsCheck(binary->left(), rightValue->abstractValue().asConcrete().value(), jump->elseTarget().basicBlock()); } break; } case BinaryOperator::UNSIGNED_LESS: { const dflow::Value *rightValue = dataflow.getValue(binary->right()); if (rightValue->abstractValue().isConcrete()) { return BoundsCheck(binary->left(), rightValue->abstractValue().asConcrete().value() - 1, jump->elseTarget().basicBlock()); } break; } } } else { switch (binary->operatorKind()) { case BinaryOperator::UNSIGNED_LESS: { const dflow::Value *leftValue = dataflow.getValue(binary->left()); if (leftValue->abstractValue().isConcrete()) { return BoundsCheck(binary->right(), leftValue->abstractValue().asConcrete().value(), jump->thenTarget().basicBlock()); } break; } case BinaryOperator::UNSIGNED_LESS_OR_EQUAL: { const dflow::Value *leftValue = dataflow.getValue(binary->left()); if (leftValue->abstractValue().isConcrete()) { return BoundsCheck(binary->right(), leftValue->abstractValue().asConcrete().value() - 1, jump->thenTarget().basicBlock()); } break; } } } } return BoundsCheck(); }
NS_IMETHODIMP nsPopupSetFrame::DoLayout(nsBoxLayoutState& aState) { // lay us out nsresult rv = nsBoxFrame::DoLayout(aState); // lay out all of our currently open popups. nsPopupFrameList* currEntry = mPopupList; while (currEntry) { nsMenuPopupFrame* popupChild = currEntry->mPopupFrame; if (popupChild && popupChild->IsOpen()) { // then get its preferred size nsSize prefSize = popupChild->GetPrefSize(aState); nsSize minSize = popupChild->GetMinSize(aState); nsSize maxSize = popupChild->GetMaxSize(aState); prefSize = BoundsCheck(minSize, prefSize, maxSize); popupChild->SetPreferredBounds(aState, nsRect(0,0,prefSize.width, prefSize.height)); popupChild->SetPopupPosition(nsnull); // is the new size too small? Make sure we handle scrollbars correctly nsIBox* child = popupChild->GetChildBox(); nsRect bounds(popupChild->GetRect()); nsIScrollableFrame *scrollframe = do_QueryFrame(child); if (scrollframe && scrollframe->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_AUTO) { // if our pref height if (bounds.height < prefSize.height) { // layout the child popupChild->Layout(aState); nsMargin scrollbars = scrollframe->GetActualScrollbarSizes(); if (bounds.width < prefSize.width + scrollbars.left + scrollbars.right) { bounds.width += scrollbars.left + scrollbars.right; popupChild->SetBounds(aState, bounds); } } } // layout the child popupChild->Layout(aState); // if the width or height changed, readjust the popup position. This is a // special case for tooltips where the preferred height doesn't include the // real height for its inline element, but does once it is laid out. // This is bug 228673 which doesn't have a simple fix. if (popupChild->GetRect().width > bounds.width || popupChild->GetRect().height > bounds.height) { // the size after layout was larger than the preferred size, // so set the preferred size accordingly popupChild->SetPreferredSize(popupChild->GetSize()); popupChild->SetPopupPosition(nsnull); } popupChild->AdjustView(); } currEntry = currEntry->mNextPopup; } return rv; }
float Curve::LinearInterpolation(float t, float start, float end) { BoundsCheck(t, start, end); return t * end + (1.f - t) * start; }
float Curve::QuadraticEaseOut(float t, float start, float end) { BoundsCheck(t, start, end); //return -end * t * (t - 2.f) - 1.f; return -end * t * (t - 2) + start; // FIX BY AARON }
/* public ZBasicString<A>::At Gets the character at the given signed index. Passing in an index of -1 will return the last character, not the null terminator. @param _index - the index @return (char) - the character at the provided index @assert - if the index is out of bounds */ char& At(const size_t _index) const { return StringArray.Data()[BoundsCheck(_index, Length())]; }
/* public ZBasicString<A>::Back Gets a reference to the character at the back of the string. @return (char&) - the character at the end of the string @assert - if the string is empty */ char& Back() const { return StringArray.Data()[BoundsCheck(Length() - 1, Length())]; }
/* public ZBasicString<A>::Erase Erase function. Erases the character at the provided index. @param _index - the index of the character to erase @return (void) */ void Erase(const size_t _index) { size_t index = BoundsCheck(_index, Length()); Erase(index, index + 1); }
nsSize nsBox::BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize) { return nsSize(BoundsCheck(aMinSize.width, aPrefSize.width, aMaxSize.width), BoundsCheck(aMinSize.height, aPrefSize.height, aMaxSize.height)); }
float Curve::ExponentialEaseIn(float t, float start, float end) { BoundsCheck(t, start, end); return end * powf(2.f, 10.f * (t - 1.f) ) + start; }