private IScrollableControl ChooseAutoscrollContext(Control control, out RectF parentRect, out RectF controlRect, out RectF intersectedRect) { parentRect = controlRect = intersectedRect = default(RectF); if (control == null) { return(null); } var _ = control; controlRect = control.GetRect(); while (control.TryGetParent(out control)) { var result = control as IScrollableControl; if (result == null) { continue; } parentRect = control.GetRect(contentRect: true); controlRect.Intersection(in parentRect, out intersectedRect); if (!intersectedRect.Equals(controlRect)) { return(result); } } return(null); }
public Transition GenerateNextTransition(RectF drawableBounds, RectF viewport) { bool firstTransition = _mLastGenTrans == null; bool drawableBoundsChanged = true; bool viewportRatioChanged = true; RectF srcRect = null; RectF dstRect = null; if (!firstTransition) { dstRect = _mLastGenTrans.GetDestinyRect(); drawableBoundsChanged = !drawableBounds.Equals(_mLastDrawableBounds); viewportRatioChanged = !MathUtils.HaveSameAspectRatio(dstRect, viewport); } if (dstRect == null || drawableBoundsChanged || viewportRatioChanged) { srcRect = GenerateRandomRect(drawableBounds, viewport); } else { /* Sets the destiny rect of the last transition as the source one * if the current drawable has the same dimensions as the one of * the last transition. */ srcRect = dstRect; } dstRect = GenerateRandomRect(drawableBounds, viewport); _mLastGenTrans = new Transition(srcRect, dstRect, _mTransitionDuration, _mTransitionIInterpolator); _mLastDrawableBounds = drawableBounds; return(_mLastGenTrans); }
// Resizing Behavior public static void resizingBehaviorApply(ResizingBehavior behavior, RectF rect, RectF target, RectF result) { if (rect.Equals(target) || target == null) { result.Set(rect); return; } if (behavior == ResizingBehavior.Stretch) { result.Set(target); return; } float xRatio = Math.Abs(target.Width() / rect.Width()); float yRatio = Math.Abs(target.Height() / rect.Height()); float scale = 0f; switch (behavior) { case ResizingBehavior.AspectFit: { scale = Math.Min(xRatio, yRatio); break; } case ResizingBehavior.AspectFill: { scale = Math.Max(xRatio, yRatio); break; } case ResizingBehavior.Center: { scale = 1f; break; } } float newWidth = Math.Abs(rect.Width() * scale); float newHeight = Math.Abs(rect.Height() * scale); result.Set(target.CenterX() - newWidth / 2, target.CenterY() - newHeight / 2, target.CenterX() + newWidth / 2, target.CenterY() + newHeight / 2); }
public Tuple <int, IndexBuffer, DynamicVertexBuffer> GetOccludersBuffers(RectF rect) { if (!isDirty_ && rect.Equals(lastRectF_)) //TODO rectf ==, TODO mark dirty when occluders change/ctor { Dbg.Log("returning cached occluders data"); goto ReturnData; //TODO } isDirty_ = false; allOccludersSegments.Clear(); //TODO use array - low/med prior //collect all occluders segments in range foreach (LightOccluder occluder in GetComponentsInRect(rect)) { allOccludersSegments.AddRange(occluder.GlobalSegments); //TODO slooooow, pass list? } int verticesNeeded = allOccludersSegments.Count * 4 + 4; //each segment is a quad in vbo, PLUS the projector (first 4) // each miss we double our buffers ;) while (verticesNeeded > vb.VertexCount) { int newVtxQty = vb.VertexCount * 2; int newIdxQty = ib.IndexCount * 2; vb = new DynamicVertexBuffer(Graphics.Device, OccluderVertexFormat.VertexDeclaration, newVtxQty, BufferUsage.WriteOnly); ib = new IndexBuffer(Graphics.Device, IndexElementSize.ThirtyTwoBits, newIdxQty, BufferUsage.WriteOnly); int[] indices = new int[newIdxQty]; for (int i = 0, v = 0; i < newIdxQty; i += 6, v += 4) { indices[i + 0] = v + 0; indices[i + 1] = v + 1; indices[i + 2] = v + 2; indices[i + 3] = v + 0; indices[i + 4] = v + 2; indices[i + 5] = v + 3; } ib.SetData(indices); // copy to gfx, create actual IBO, once per resize } List <OccluderVertexFormat> verts = new List <OccluderVertexFormat>(verticesNeeded); //add projector (first 4 verts) verts.Add(new OccluderVertexFormat(new Vector3(0, 0, 0), 0, OccluderVertexFormat.Corner0)); //TODO use vert idx for id? verts.Add(new OccluderVertexFormat(new Vector3(1, 0, 0), 0, OccluderVertexFormat.Corner1)); verts.Add(new OccluderVertexFormat(new Vector3(1, 1, 0), 0, OccluderVertexFormat.Corner2)); verts.Add(new OccluderVertexFormat(new Vector3(0, 1, 0), 0, OccluderVertexFormat.Corner3)); //add shadow casters foreach (OccluderSegment segment in allOccludersSegments) { verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), shadowBias)); verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), shadowBias)); verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), 1)); verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), 1)); Dbg.AddDebugLine(segment.A, segment.B, Color.Cyan); } vb.SetData(verts.ToArray()); // copy to gfx, once per draw call ReturnData: return(new Tuple <int, IndexBuffer, DynamicVertexBuffer>(allOccludersSegments.Count, ib, vb)); //TODO descriptive object }
public void EqualsEpsilon() { Assert.IsTrue(RectD.Equals(rectD, new RectD(1.1, 1.9, 3.9, 5.1), 0.2)); Assert.IsTrue(RectF.Equals(rectF, new RectF(1.1f, 1.9f, 3.9f, 5.1f), 0.2f)); }