private void ReorganizeHand() { if (Cards.Count == 0) { return; } float height = 0; // we assume all the cards have the same size var cardSize = Cards[0].Value._size; // we calculate the overlap factor so that all the cards fit within the maximum width var overlapFactor = Cards.Count == 1 ? 1 : -((MaxWidth / cardSize.X) - Cards.Count) / (Cards.Count - 1); // when there are only a few cards in hand, we want them to overlap by at least the half of their width if (overlapFactor < 0.5f) { overlapFactor = 0.5f; } // compute relative position of each card to each other var overlapWidth = cardSize.X * (1 - overlapFactor); float x = 0; foreach (var card in Cards) { card._translate = new Vector2(x, 0); x += overlapWidth; height = Math.Max(height, card.Value._size.Y); } float width = Cards.Count * cardSize.X - (Cards.Count - 1) * cardSize.X * overlapFactor; // should be equal to max width most of the time height *= 2; // we want the rotation center to be below the cards so they spread nicely var rotationCenter = new Vector2(width / 2, height); // recenter the hand so that 0,0 is the rotation point foreach (var card in Cards) { card._translate -= rotationCenter; } rotationCenter = Vector2.Zero; // we want the cards to spread on the eighth of a circle, but with a maximum spread when there are only a few carsds double stepAngle = Math.Min(Math.PI / 40, MathHelper.PiOver4 / Cards.Count); // The XNA SpriteBatch works in Client Space. Where "up" is Y-, not Y+ (as in Cartesian space, projection space, and what most people usually // select for their world space). This makes the rotation appear as clockwise (not counter-clockwise as it would in Cartesian space). double angle = -stepAngle * (Cards.Count - 1) / 2; foreach (var card in Cards) { card._rotation = new Rotation2(rotationCenter - card._translate, (float)angle); angle += stepAngle; } SizeChangedCallback?.Invoke(new Vector2(width, height)); }
internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true) { callback = cb; if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public bool RemoveSizeChangedListener(SizeChangedCallback callback, object userData) { SizeChangedListener item = new SizeChangedListener(); item.SetCallback(callback); item.SetUserData(userData); return(this.m_sizeChangedListeners.Remove(item)); }
public bool AddSizeChangedListener(SizeChangedCallback callback, object userData) { SizeChangedListener item = new SizeChangedListener(); item.SetCallback(callback); item.SetUserData(userData); if (this.m_sizeChangedListeners.Contains(item)) { return(false); } this.m_sizeChangedListeners.Add(item); return(true); }
static extern void Noesis_Win32Display_RegisterCallbacks( LocationChangedCallback locationChangedCallback, SizeChangedCallback sizeChangedCallback, StateChangedCallback stateChangedCallback, FileDroppedCallback fileDroppedCallback, ActivatedCallback activatedCallback, DeactivatedCallback deactivatedCallback, RenderCallback renderCallback, MouseMoveCallback mouseMoveCallback, MouseButtonDownCallback mouseButtonDownCallback, MouseButtonUpCallback mouseButtonUpCallback, MouseDoubleClickCallback mouseDoubleClickCallback, MouseWheelCallback mouseWheelCallback, KeyDownCallback keyDownCallback, KeyUpCallback keyUpCallback, CharCallback charCallback, TouchMoveCallback touchMoveCallback, TouchDownCallback touchDownCallback, TouchUpCallback touchUpCallback);
internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth) { }
public bool RemoveSizeChangedListener(SizeChangedCallback callback) { return(this.RemoveSizeChangedListener(callback, null)); }
public bool AddSizeChangedListener(SizeChangedCallback callback) { return(this.AddSizeChangedListener(callback, null)); }