protected override void _OnChildRemove(GUIControl child) { base._OnChildRemove(child); _UpdateBounds(); }
/// <summary> /// Returns true if this control is the parent. /// </summary> public virtual bool IsParentOf(GUIControl child) { // loop through checking each child to see if it is or contains the ctrl foreach (GUIControl ctrl in Itr<GUIControl>(false)) { if (ctrl == child || ctrl.IsParentOf(child)) return true; } // not found return false; }
private float maxHealthBarSize; // used to calculate size of health #endregion Fields #region Constructors public HealthBar_GUI() { #region Styles // Create Base Style GUIStyle playStyle = new GUIStyle(); Name = "GuiPlay"; Style = playStyle; Size = new Microsoft.Xna.Framework.Vector2(1024, 768); Folder = GUICanvas.Instance; // Create Text Style GUITextStyle styleText = new GUITextStyle(); styleText.FontType = "Arial22"; // Change to desired styleText.TextColor[CustomColor.ColorBase] = Color.White; // Change to desired styleText.SizeToText = true; styleText.Alignment = TextAlignment.JustifyLeft; styleText.PreserveAspectRatio = true; // Create Pic Style GUIBitmapStyle bitmapStyle = new GUIBitmapStyle(); bitmapStyle.SizeToBitmap = false; // Modify the bitmap Style to draw the health GUIStyle healthStyle = new GUIStyle(); healthStyle.FillColor[CustomColor.ColorBase] = Color.Red; healthStyle.IsOpaque = true; #endregion #region GUIObjects // Create health text object GUIText healthText = new GUIText(); healthText.Style = styleText; // Created above healthText.Text = "Health"; // Change to desired healthText.Size = new Vector2(75, 30); // If smaller than text, will be cut off healthText.Position = new Vector2(20, 20); // Change to desired healthText.Folder = this; // needed to draw healthText.Visible = true; // needed to draw // Create cyrstal text object crystalText = new GUIText(); crystalText.Style = styleText; crystalText.Text = ""; crystalText.Size = new Vector2(75, 30); // If smaller than text, will be cut off crystalText.Position = new Vector2(920, 57); // Change to desired crystalText.Folder = this; crystalText.Visible = true; // Create "x" text object, to make independent of the no. of crystals GUIText crossText = new GUIText(); crossText.Style = styleText; crossText.Text = " x "; crossText.Size = new Vector2(75, 30); // If smaller than text, will be cut off crossText.Position = new Vector2(crystalText.Position.X + 30, crystalText.Position.Y); // offset position from crystalText crossText.Folder = this; crossText.Visible = true; // Create picture object GUIBitmap healthBarBorder = new GUIBitmap(); healthBarBorder.Style = bitmapStyle; healthBarBorder.Size = new Vector2(310, 40); // The size of the health bar healthBarBorder.Bitmap = @"data\images\lifebar"; healthBarBorder.Folder = this; healthBarBorder.Visible = true; healthBarBorder.Position = new Vector2(20, 60); // Create picture object GUIBitmap crystalBitmap = new GUIBitmap(); crystalBitmap.Style = bitmapStyle; crystalBitmap.Size = new Vector2(30, 65); // The size of the crystal crystalBitmap.Bitmap = @"data\images\crystal"; crystalBitmap.Folder = this; crystalBitmap.Visible = true; crystalBitmap.Position = new Vector2(crystalText.Position.X + 55, crystalText.Position.Y - 15); // offset position from crystalText // Create base object to fill with colour healthBar = new GUIControl(); healthBar.Style = healthStyle; //healthBar.Size = new Vector2(healthBarBorder.Size.X - 8, healthBarBorder.Size.Y - 5); healthBar.Size = new Vector2(301, 34); // offset size to fit inside health bar healthBar.Folder = this; healthBar.Visible = true; //healthBar.Position = new Vector2(healthBarBorder.Position.X + 5, healthBarBorder.Position.Y + 3); healthBar.Position = new Vector2(25, 64); // offset pos to fit inside health bar // used calculate health bar size (see draw) maxHealthBarSize = healthBar.Size.X; #endregion }
protected override void _ChildResized(GUIControl child) { base._ChildResized(child); _UpdateBounds(); }
/// <summary> /// Called when one of this control's children is removed. /// </summary> /// <param name="child">The child control that was removed from this control's hierarchy.</param> protected virtual void _OnChildRemove(GUIControl child) { }
public override void OnLoseFocus(GUIControl newFocusCtrl) { base.OnLoseFocus(newFocusCtrl); // only change state if the button is selected if (_buttonState == ButtonState.Selected) _buttonState = ButtonState.Normal; }
/// <summary> /// Adds a dialog control onto the GUICanvas stack. /// </summary> /// <param name="gui">The dialog control to add.</param> /// <param name="layer">The layer to put the dialog control on. Usually layer 0.</param> public void PushDialogControl(GUIControl gui, int layer) { // set the dialog layer gui.Layer = layer; gui.Folder = this; int idx; int numObjects = GetNumObjects(); // reorder the controls into the correct layers for (idx = 0; idx < numObjects; idx++) { GUIControl ctrl = (GUIControl)GetObject(idx); if (ctrl == null) return; if (ctrl.Layer > gui.Layer) { ReOrder(gui, ctrl); break; } } }
/// <summary> /// Called when a child control of this object is resized. /// </summary> /// <param name="child"></param> protected virtual void _ChildResized(GUIControl child) { }
/// <summary> /// Called when the GUICanvas needs to render. /// </summary> /// <param name="offset">The location of the canvas.</param> /// <param name="updateRect">The size of the canvas.</param> public override void OnRender(Vector2 offset, RectangleF updateRect) { #if DEBUG Profiler.Instance.StartBlock("GUICanvas.OnRender"); #endif numObjects = GetNumObjects(); // pre-render phase renderLetterbox = false; for (idx = 0; idx < numObjects; idx++) { contentCtrl = (GUIControl)GetObject(idx); if (contentCtrl == null) break; // pre-render the content contentCtrl.OnPreRender(); if (contentCtrl.Style.PreserveAspectRatio && _letterBoxControl != null) { if (contentCtrl.Bounds != _bounds) renderLetterbox = true; } } // letterbox render phase if (renderLetterbox) { DrawUtil.ClipRect = _bounds; _letterBoxControl.Bounds = _bounds; _letterBoxControl.OnRender(_letterBoxControl.Position, _bounds); } // render phase for (idx = 0; idx < numObjects; idx++) { contentCtrl = (GUIControl)GetObject(idx); if (contentCtrl == null) break; // clip to the control's bounds DrawUtil.ClipRect = contentCtrl.Bounds; // render the content contentCtrl.OnRender(contentCtrl.Position, contentCtrl.Bounds); } // safe area render phase if (_safeAreaRendering != SafeAreas.None) { DrawUtil.ClipRect = _bounds; _RenderSafeAreas(); } // important, because controls can change the clip DrawUtil.ClipRect = _bounds; #if DEBUG Profiler.Instance.EndBlock("GUICanvas.OnRender"); #endif }
/// <summary> /// Removes a dialog control from the GUICanvas stack. /// </summary> /// <param name="gui">The dialog control to remove.</param> public void PopDialogControl(GUIControl gui) { if (gui == null) return; // remove the dialog from the canvas gui hierarchy gui.Folder = TorqueObjectDatabase.Instance.RootFolder; ClearFocusControl(); }
/// <summary> /// Determines if a given control has focus. /// </summary> /// <param name="ctrl">The GUIControl to test.</param> /// <returns>True if the given control is the current focus control.</returns> public bool ControlHasFocus(GUIControl ctrl) { return ctrl == _focusControl; }
/// <summary> /// Clears the current focus control. /// </summary> public void ClearFocusControl() { if (_focusControl != null) _focusControl.OnLoseFocus(null); _focusControl = null; }
public override void OnLoseFocus(GUIControl newFocusCtrl) { base.OnLoseFocus(newFocusCtrl); _heldKey = Keys.None; }
/// <summary> /// Called when this control gains focus. /// </summary> /// <param name="oldFocusCtrl">The control that is losing focus(if any).</param> public virtual void OnGainFocus(GUIControl oldFocusCtrl) { // notify any interested parties that this control now has focus if (_onGainFocusDelegate != null) _onGainFocusDelegate(this); }
/// <summary> /// Changes the currently rendering content control. /// </summary> /// <param name="ctrl">The content control object to change to.</param> public void SetContentControl(GUIControl ctrl) { if (ctrl == null) return; // remove all dialogs on layer 0 int index = 0; while (GetNumObjects() > index) { GUIControl child = (GUIControl)GetObject(index); if (child == null) continue; if (child == ctrl || child.Layer != 0) { index++; continue; } child.Folder = TorqueObjectDatabase.Instance.RootFolder; } // lose the first responder from the old content ClearFocusControl(); // add the ctrl to the front if (GetNumObjects() == 0 || ctrl != GetObject(0)) { if (ctrl == null) return; ctrl.Folder = this; if (GetNumObjects() >= 2) ReOrder(ctrl, GetObject(0)); } }
/// <summary> /// Called when this control loses focus. /// </summary> /// <param name="newFocusCtrl">The control that is gaining focus(if any).</param> public virtual void OnLoseFocus(GUIControl newFocusCtrl) { // notify any interested parties that this control now has lost focus if (_onLoseFocusDelegate != null) _onLoseFocusDelegate(this); }
/// <summary> /// Changes the current focus control. /// </summary> /// <param name="control">The GUIControl to change focus to.</param> public void SetFocusControl(GUIControl control) { // can't set focus to a non existing control // use ClearFocusControl to clear focus if (control == null) return; // if the control can't focus or it already has focus if (!control.CanFocus || ControlHasFocus(control)) return; // set the new focus control GUIControl oldFocus = _focusControl; _focusControl = control; // let the current focus control know it's giving up its focus if (oldFocus != null) oldFocus.OnLoseFocus(_focusControl); // let the new focus control know it has gained focus _focusControl.OnGainFocus(oldFocus); }
/// <summary> /// Called when a control becomes a child of this control. /// </summary> /// <param name="child">The control that was added to this control's hierarchy.</param> protected virtual void _OnChildAdd(GUIControl child) { }
/// <summary> /// Initializes the console gui. /// </summary> public void Initialize() { if (_isInitialized) { TorqueConsole.Warn("ConsoleGui.InitializeGui - Gui is already initialized!"); return; } // define gui styles GUIStyle rootStyle = new GUIStyle(); rootStyle.IsOpaque = true; rootStyle.FillColor[CustomColor.ColorBase] = new Color(0, 0, 0, 128); GUIStyle scrollerStyle = new GUIStyle(); scrollerStyle.HasBorder = true; scrollerStyle.BorderColor[CustomColor.ColorBase] = new Color(0, 0, 0, 255); scrollerStyle.Focusable = false; GUIMLTextStyle bodyStyle = new GUIMLTextStyle(); bodyStyle.Alignment = TextAlignment.JustifyLeft; bodyStyle.TextColor[CustomColor.ColorUser0] = Color.White; bodyStyle.TextColor[CustomColor.ColorUser1] = Color.Yellow; bodyStyle.TextColor[CustomColor.ColorUser2] = Color.Red; bodyStyle.SizeToText = true; bodyStyle.AutoSizeHeightOnly = false; bodyStyle.FontType = "Arial12"; GUITextStyle textStyle = new GUITextStyle(); textStyle.Alignment = TextAlignment.JustifyLeft; textStyle.TextColor[CustomColor.ColorBase] = Color.White; textStyle.SizeToText = false; textStyle.Focusable = true; textStyle.FontType = "Arial14"; // init gui controls _root = new GUIControl(); _root.Style = rootStyle; _root.HorizSizing = HorizSizing.Width; _root.VertSizing = VertSizing.Height; _root.Size = new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y); _scroll = new GUIScroll(); _scroll.Style = scrollerStyle; _scroll.HorizSizing = HorizSizing.Width; _scroll.VertSizing = VertSizing.Relative; _scroll.Size = new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y - 30.0f); _scroll.Visible = true; _scroll.Folder = _root; _textEdit = new GUIConsoleTextEdit(); _textEdit.Style = textStyle; _textEdit.HorizSizing = HorizSizing.Relative; _textEdit.VertSizing = VertSizing.Relative; _textEdit.Position = new Vector2(10.0f, GUICanvas.Instance.Size.Y - 30.0f); _textEdit.Size = new Vector2(GUICanvas.Instance.Size.X - 20.0f, 30.0f); _textEdit.FocusOnWake = true; _textEdit.Visible = true; _textEdit.Folder = _root; _textEdit.OnValidateText = _ValidateText; int keyboardId = InputManager.Instance.FindDevice("keyboard"); _textEdit.InputMap.BindAction(keyboardId, (int)Keys.Up, _NextHistory); _textEdit.InputMap.BindAction(keyboardId, (int)Keys.Down, _PreviousHistory); _text = new GUIConsoleText(); _text.Style = bodyStyle; _text.HorizSizing = HorizSizing.Relative; _text.VertSizing = VertSizing.Relative; _text.Position = new Vector2(10.0f, 10.0f); _text.Size = new Vector2(400.0f, 20.0f); _text.Visible = true; _text.Folder = _scroll; _text.Text = _consoleText; _isInitialized = true; }
private ProfileGUI() { // define gui styles GUIStyle rootStyle = new GUIStyle(); rootStyle.IsOpaque = false; GUIStyle scrollerStyle = new GUIStyle(); scrollerStyle.IsOpaque = true; scrollerStyle.FillColor[CustomColor.ColorBase] = new Color(0, 0, 0, 150); scrollerStyle.HasBorder = true; scrollerStyle.BorderColor[CustomColor.ColorBase] = new Color(0, 0, 0, 200); scrollerStyle.Focusable = true; GUIMLTextStyle bodyStyle = new GUIMLTextStyle(); bodyStyle.Alignment = TextAlignment.JustifyLeft; bodyStyle.TextColor[CustomColor.ColorBase] = Color.White; bodyStyle.SizeToText = true; bodyStyle.AutoSizeHeightOnly = true; bodyStyle.FontType = "Courier14"; GUITextStyle textStyle = new GUITextStyle(); textStyle.Alignment = TextAlignment.JustifyRight; textStyle.TextColor[CustomColor.ColorBase] = Color.White; textStyle.SizeToText = true; textStyle.FontType = "Courier14"; // init gui controls _root = new GUIControl(); _root.Style = rootStyle; _root.HorizSizing = HorizSizing.Width; _root.VertSizing = VertSizing.Height; _scroll = new GUIScroll(); _scroll.Style = scrollerStyle; _scroll.HorizSizing = HorizSizing.Relative; _scroll.VertSizing = VertSizing.Relative; _scroll.Position = new Vector2(10.0f, 10.0f); _scroll.Size = new Vector2(GUICanvas.Instance.Size.X - 20.0f, GUICanvas.Instance.Size.Y - 20.0f); _scroll.FocusOnWake = true; _scroll.Visible = true; _scroll.Folder = _root; _scroll.InputMap = new InputMap(); int gamepadId = InputManager.Instance.FindDevice("gamepad0"); _scroll.InputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Left, _OnLeft); _scroll.InputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Right, _OnRight); _scroll.InputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Start, _OnStart); _page = new GUIText(); _page.Style = textStyle; _page.HorizSizing = HorizSizing.Relative; _page.VertSizing = VertSizing.Relative; _page.Position = new Vector2(GUICanvas.Instance.Size.X - 180.0f, 40.0f); _page.Text = string.Empty; _page.Visible = true; _page.Folder = _root; _saveToFile = new GUIText(); _saveToFile.Style = textStyle; _saveToFile.HorizSizing = HorizSizing.Relative; _saveToFile.VertSizing = VertSizing.Relative; _saveToFile.Position = new Vector2(GUICanvas.Instance.Size.X - 260, 20.0f); _saveToFile.Text = string.Empty; #if !XBOX _saveToFile.Visible = true; _saveToFile.Folder = _root; #endif // !XBOX _text = new GUIMLText(); _text.Style = bodyStyle; _text.HorizSizing = HorizSizing.Width; _text.VertSizing = VertSizing.Height; _text.Position = new Vector2(3.0f, 3.0f); _text.Size = new Vector2(GUICanvas.Instance.Size.X - 40.0f, GUICanvas.Instance.Size.Y - 20.0f); _text.Text = "Torque X Profiler\n\nNo profiles have been taken yet.\nPress (F2) to take a snapshot since the last profile.\n\nIf the profiler doesn't seem to be responding, there may be a stack overflow. Make sure that \nfor each StartBlock call there is an EndBlock call. If the code you're profiling has multiple \nreturn paths you will need multiple EndBlock calls: one before each return statement. If \nthis is an issue, try profiling with a debug build to catch the overflow assert (you might \nneed to run your app for a while before you get it, depending on the cause of the overflow).\n\nEnjoy! ;)"; _text.Visible = true; _text.Folder = _scroll; }
public override void OnGainFocus(GUIControl oldFocusCtrl) { base.OnGainFocus(oldFocusCtrl); // only change state if the button is in normal mode if (_buttonState == ButtonState.Normal) _buttonState = ButtonState.Selected; }