// constructor for placement relative to a widget. use screen widget for screen placement. public Position(Widget parent, ePlacement placement, Vector2 size) { XUtils.Assert(placement != ePlacement.Absolute, "wrong constructor for absolute"); Init(parent, placement); switch (placement) { case ePlacement.Centered: Place(size, 0.5f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f); break; case ePlacement.CenteredLeft: Place(size, 0.0f, 0.5f, 0.0f, -0.5f, 1.0f, 0.0f); break; case ePlacement.CenteredRight: Place(size, 1.0f, 0.5f, -1.0f, -0.5f, -1.0f, 0.0f); break; case ePlacement.CenteredTop: Place(size, 0.5f, 0.0f, -0.5f, 0.0f, 0.0f, 1.0f); break; case ePlacement.CenteredBottom: Place(size, 0.5f, 1.0f, -0.5f, -1.0f, 0.0f, -1.0f); break; case ePlacement.TopLeft: Place(size, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f); break; case ePlacement.TopRight: Place(size, 1.0f, 0.0f, -1.0f, 0.0f, -1.0f, 1.0f); break; case ePlacement.BottomLeft: Place(size, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f); break; case ePlacement.BottomRight: Place(size, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f); break; default: XUtils.Assert(false, "placement type not yet supported"); break; } ValidateAABB(); }
public void Add(Trigger trigger, XState to_state, TransitionCallback callback) { XUtils.Assert(!mTransitions.ContainsKey(trigger)); XTransition transition = new XTransition(to_state, callback); mTransitions.Add(trigger, transition); }
private void InitWidgetCommon(Style style) { XUtils.Assert(!mInitialized); mStyle = style; mInputEnabled = true; mInitialized = true; }
public void AddRootWidget(Widget w) { Widget existing = mRootWidgets.Find(XUI.Widget.CompareWidgets(w)); XUtils.Assert(existing == null); mRootWidgets.Add(w); }
public bool IsNonDegenerate() { XUtils.Assert(mIsValid); Vector2 span = GetSize(); return(span.X > 0f && span.Y > 0f); }
public void Resize(Vector2 change, bool assert_on_invert = false) { XUtils.Assert(mIsValid); mMin -= change; mMax += change; bool inverted = false; if (mMin.X > mMax.X) { inverted = true; float avg = 0.5f * (mMin.X + mMax.X); mMin.X = avg; mMax.X = avg; } if (mMin.Y > mMax.Y) { inverted = true; float avg = 0.5f * (mMin.Y + mMax.Y); mMin.Y = avg; mMax.Y = avg; } Validate(mMin, mMax); if (assert_on_invert && inverted) { XUtils.Assert(false); } }
public static String GetNSpaces(int n) { XUtils.Assert(n > -1); switch (n) { case 0: return(""); case 1: return(" "); case 2: return(" "); case 3: return(" "); case 4: return(" "); case 5: return(" "); case 6: return(" "); case 7: return(" "); default: return(" " + GetNSpaces(n - 8)); } }
public void ScaleLocal(float f) { XUtils.Assert(mIsValid && f >= 0f); Vector2 new_radius = f * GetRadius(); Vector2 center = GetCenter(); Set(center - new_radius, center + new_radius); }
public void Init(xCoord bounds, T init_value) { XUtils.Assert(bounds.x > 0 && bounds.y > 0); mData = new T[bounds.x, bounds.y]; mBounds = bounds; Iterate((grid, x, y) => { grid.mData[x, y] = init_value; }); }
private void ValidateAABB() { if (mParent != null) { xAABB2 parent_aabb = new xAABB2(Vector2.Zero, mParent.GetPosition().GetRelatveAABB().GetSize()); XUtils.Assert(parent_aabb.Contains(mRelativeAABB.GetMin()) && parent_aabb.Contains(mRelativeAABB.GetMax())); } }
public xCoord clamp(xCoord min, xCoord max) { XUtils.Assert(!(min.x > max.x || min.y > max.y)); int clamped_x = System.Math.Max(System.Math.Min(max.x, this.x), min.x); int clamped_y = System.Math.Max(System.Math.Min(max.y, this.y), min.y); return(new xCoord(clamped_x, clamped_y)); }
private XState GetState(txStateID state_id) { XState state; bool found = mStates.TryGetValue(state_id, out state); XUtils.Assert(found); return(state); }
public txStateID CreateState(StateCallback callback) { XUtils.Assert(!mLocked, "Modifying state machine while in use not allowed."); XState state = new XState(callback, mNeverTransitionValue); mStates.Add(state.mStateID, state); return(state.mStateID); }
public static T Instance() { if (sInstance == null) { XUtils.Assert(false, "instance doesn't exist"); } return(sInstance); }
public void Set(Vector2 center, float radius) { XUtils.Assert(radius >= 0f); Vector2 half_span = new Vector2(radius, radius); mMin = center - half_span; mMax = center + half_span; mIsValid = true; }
public void Init() { if (mID > 0) { XUtils.Assert(false, "txStateID only initializes once"); } mID = sNext; ++sNext; }
public void RemoveTransition(txStateID from, Trigger trigger) { XUtils.Assert(!mLocked, "Modifying state machine while in use not allowed."); XState from_state; bool found_from = mStates.TryGetValue(from, out from_state); XUtils.Assert(found_from); from_state.Remove(trigger); }
private static T CreateInstanceNoLock(Key key) { XUtils.Assert(sInstances != null, "must initialize XPluralton"); // Create an instance via the private constructor Type t = typeof(T); T instance = (T)Activator.CreateInstance(t, true); sInstances.Add(key, instance); return(instance); }
public void ValidateParent(Widget parent) { if (mParent == null) { XUtils.Assert(parent == null); } else { XUtils.Assert(Widget.CompareWidgets(parent)(this.mParent)); } }
private void SendButtonEvent <T>(bool pressed_now, XBroadcaster <T> b, T e) where T : class { XUtils.Assert(_mCurrentlyPressed != null); _mCurrentlyPressed.SetPressed(pressed_now); b.Post(e); if (!pressed_now) { _mCurrentlyPressed = null; } }
private Vector2 CalcAvgTouchPos() { XUtils.Assert(mTouches.Count > 0); Vector2 result = Vector2.Zero; for (int i = 0; i < mTouches.Count; ++i) { result += mTouches[i].Position; } return((1.0f / mTouches.Count) * result); }
public static T GetInstance(Key key) { lock ( sInitLock ) { XUtils.Assert(sInstances != null, "must initialize XPluralton"); T value; if (sInstances.TryGetValue(key, out value) == false) { value = XPluralton <Key, T> .CreateInstanceNoLock(key); } return(value); } }
public void Update() { // check for create menu var enumerator_fiveContacts = mListener_FiveContacts.CreateEnumerator(); if (enumerator_fiveContacts.MoveNext()) { if (mRootSelector == null) { mRootSelector = XUI.Instance().CreateSelector(new XUI._Position(), "Debug Menu", XUI.eStyle.Frontend, XUI.eStyle.FrontendButton, XUI.eStyle.FrontendTitle, mOptions); } } // check for menu selection var selection_data = mListener_SelectorSelection.GetMaxOne(); if (selection_data != null) { if (selection_data.mSelectorID == mRootSelector.GetID()) { // destroy this selector XUI.Instance().DestroySelector(mRootSelector.GetID()); mRootSelector = null; switch (selection_data.mIndexSelected) { case 0: // map selected, sent message for that system to do what it wants Console.WriteLine("map selected"); mBroadcaster_MenuSelection.Post(new MenuSelectionEvent(selection_data.mSelectorID, mOptions[0])); break; case 2: // exit selected, do nothing, menu will close break; case 4: // quit selected, send message to end program. this menu will close XBulletinBoard.Instance().mBroadcaster_ExitGameEvent.Post(new Game1.ExitGameEvent()); break; default: // problem XUtils.Assert(false); break; } } } }
public static void Initialize() { Type t = typeof(T); // Ensure there are no public constructors... ConstructorInfo[] ctors = t.GetConstructors(); if (ctors.Length > 0) { throw new InvalidOperationException(String.Format("{0} has at least one accesible ctor making it impossible to enforce pluralton behaviour", t.Name)); } XUtils.Assert(sInstances == null); sInstances = new SortedDictionary <Key, T>(); }
// TODO: templatize this to improve what is passed in for trigger, cast it to int public void CreateTransition(txStateID from, txStateID to, Trigger trigger, TransitionCallback callback) { XUtils.Assert(!mLocked, "Modifying state machine while in use not allowed."); // make sure 'from' already exists // make sure 'from' state doesn't already have that trigger (Add() will do that) XState from_state, to_state; bool found_from = mStates.TryGetValue(from, out from_state); bool found_to = mStates.TryGetValue(to, out to_state); XUtils.Assert(found_from && found_to); from_state.Add(trigger, to_state, callback); }
public static T Instance(Key key) { // Technically, the sInstances object isn't thread safe, as you can be // adding an object to it in CreateInstance while reading from it // here. To be truly safe, you should be locking the same object // (sInitLock), at which point it isn't really an initialization lock. // Alternately, if the create is very sporadic, the reads are fast, and // don't want to lock on read, you could lock up write, update a clone, // then copy the clone over to the Pluralton object. XUtils.Assert(sInstances != null, "must initialize XPluralton"); T value; XUtils.Assert(sInstances.TryGetValue(key, out value), "instance doesn't exist"); return(value); }
private double CalcMaxSeparation() { XUtils.Assert(mTouches.Count > 0); float max_separation_sqr = 0f; for (int i = 0; i < mTouches.Count; ++i) { for (int j = i + 1; j < mTouches.Count; ++j) { float separation_sqr = (mTouches[i].Position - mTouches[j].Position).LengthSquared(); max_separation_sqr = Math.Max(separation_sqr, max_separation_sqr); } } return(Math.Sqrt(max_separation_sqr)); }
public void DrawLine(Vector3 start_pos, Vector3 end_pos, Color color) { if (mNumLines == mMaxLines) { XUtils.Assert(false, "max lines exceeded"); return; } VertexPositionColor start = new VertexPositionColor(start_pos, color); VertexPositionColor end = new VertexPositionColor(end_pos, color); int start_vert = 2 * mNumLines; mLines[start_vert] = start; mLines[start_vert + 1] = end; ++mNumLines; }
public EventData GetMaxOne() { if (mEvents.Count == 0) { return(null); } else if (mEvents.Count == 1) { return(mEvents.Dequeue()); } else { // incorrect assumption about this listener XUtils.Assert(false); return(null); } }
// watch the winding order for which way the normal goes, by right hand rule public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color color) { if (mNumTriangles == mMaxTriangles) { XUtils.Assert(false, "max triangles exceeded"); } VertexPositionColor va = new VertexPositionColor(a, color); VertexPositionColor vb = new VertexPositionColor(b, color); VertexPositionColor vc = new VertexPositionColor(c, color); int start_vert = 3 * mNumTriangles; mTriangles[start_vert] = va; mTriangles[start_vert + 1] = vb; mTriangles[start_vert + 2] = vc; ++mNumTriangles; }