/** * Sets the object's parent. Makes sure there are no null. * To unset the parent, use the RemoveParent() method. */ public virtual void SetParent(MyOnScreenObject ParentObject) { if (ParentObject != null) { this.ParentObject = ParentObject; } }
public void AddChildAtLocation(MyOnScreenObject ChildObject, int x, int y) { if (ChildObject != null) { ChildObject.SetPosition(x, y); AddChild(ChildObject); } }
/** * Adds the referenced object to the list of child objects while * also setting its parent object reference to this object */ public virtual void AddChild(MyOnScreenObject ChildObject) { if (ChildObject != null) { ChildObjects.Add(ChildObject); ChildObject.SetParent(this); } }
/** * Removes the referenced child from the list of child objects and * sets its parent reference to null */ public virtual void RemoveChild(MyOnScreenObject ChildObject) { if (ChildObject != null) { ChildObjects.Remove(ChildObject); ChildObject.RemoveParent(); } }
public MyOnScreenObject(MyOnScreenObject ParentObject, int x, int y, bool isVisible) { this.SetParent(ParentObject); this.x = x; this.y = y; this.isVisible = isVisible; if (ParentObject != null) { ParentObject.AddChild(this); } }
public override void RemoveChild(MyOnScreenObject Item) { base.RemoveChild(Item); if (Item == SelectedItem) { SetInitialSelectedItem(ChildObjects[0]); UpdateScrollbarPosition(); } Items.Remove(Item); UpdateItemPositions(); }
public override void AddChild(MyOnScreenObject Item) { base.AddChild(Item); if (SelectedItem == null) { SetInitialSelectedItem(Item); UpdateScrollbarPosition(); } Items.Add(Item); UpdateItemPositions(); }
private int ComputeItemHorizontalPosition(MyOnScreenObject Item) { if (horizontalAlignment == Constants.HORIZONTAL_ALIGN_RIGHT) { return(GetWidth() - Scrollbar.GetWidth() - padding - Item.GetWidth()); } else if (horizontalAlignment == Constants.HORIZONTAL_ALIGN_CENTER) { return((GetWidth() - Scrollbar.GetWidth() - Item.GetWidth()) / 2); } else { return(padding); } }
public MyOnScreenObject SelectPreviousItem() { if (SelectedItem != null) { selectedItemIndex = Items.IndexOf(SelectedItem); // if it doesn't work, use this: int index = myList.FindIndex(a => a.Prop == oProp); if (selectedItemIndex > 0) { selectedItemIndex--; SelectedItem = Items[selectedItemIndex]; UpdateItemPositions(); UpdateScrollbarPosition(); } } return(SelectedItem); }
public MyOnScreenObject SelectNextItem() { if (SelectedItem != null) { selectedItemIndex = Items.IndexOf(SelectedItem); // if it doesn't work, use this: int index = myList.FindIndex(a => a.Prop == oProp); if (selectedItemIndex >= 0 && selectedItemIndex < Items.Count() - 1) { selectedItemIndex++; SelectedItem = Items[selectedItemIndex]; UpdateItemPositions(); UpdateScrollbarPosition(); } } return(SelectedItem); }
private MySprite[] ResolveFont() { if (Font == null) { MyOnScreenObject TopLevelParent = GetTopLevelParent(); if (TopLevelParent is MyPage) { return(((MyPage)TopLevelParent).GetApplication().GetCanvas().GetDefaultFont()); } else { return(null); } } else { return(Font); } }
/** * Removes the object's parent */ public void RemoveParent() { this.ParentObject = null; }
public MyScrollbar(MyOnScreenObject ParentObject) : base(ParentObject, 0, 0, true) { }
private void SetInitialSelectedItem(MyOnScreenObject Item) { SelectedItem = Item; selectedItemIndex = 0; startPosY = padding; }