/// <summary> /// Renders text to the screen /// </summary> /// <param name="rect">The shape of box to render the text in</param> /// <param name="text">The text to render</param> /// <param name="style">The TextAreaStyle used to render this text</param> internal static void InternalTextArea(RectangleShape rect, string text, GUITextArea.GUITextAreaStyle style) { Bitmap textBitmap = new Bitmap((int)rect.Width, (int)rect.Height); Graphics g = Graphics.FromImage(textBitmap); g.FillRectangle(ActiveInstance.GetColouredBrush(style.Colour), 0, 0, rect.Width, rect.Height); g.DrawString(text, new Font(GetFontFamily(style.FontFamilyId), style.FontSize, FontStyle.Regular), ActiveInstance.GetColouredBrush(style.FontColour), new Rectangle(0, 0, (int)rect.Width, (int)rect.Height), ActiveInstance.GenerateTextFormat(style.HorizontalAlignment, style.VerticalAlignment)); Sprite textSprite = Sprite.LoadFromBitmap(textBitmap); textSprite.Create(false); // Border operation GUIOperation borderOperation = new GUIOperation(0, 1); borderOperation.Bounds = rect; borderOperation.DrawLevel = 1; borderOperation.Sprite = Sprite.DefaultSprite; borderOperation.Colour = style.Border.Colour; // Text operation GUIOperation operation = new GUIOperation(1, 1); operation.Bounds = new RectangleShape(rect.X + style.Border.Left, rect.Y + style.Border.Up, rect.Width - (style.Border.Left + style.Border.Right), rect.Height - (style.Border.Up + style.Border.Bottom)); operation.DrawLevel = 1; operation.Sprite = textSprite; operation.Colour = Colour4b.White; g.Dispose(); textBitmap.Dispose(); ActiveInstance.m_guiOperations.Add(borderOperation); ActiveInstance.m_guiOperations.Add(operation); }
/// <summary> /// Draws a box on the screen /// </summary> /// <param name="rect">The shape (Position and size) of the box</param> /// <param name="style">The BoxStyle used to render this box</param> internal static void InternalBox(RectangleShape rect, GUIBox.GUIBoxStyle style) { GUIOperation operation = new GUIOperation(0, 0); operation.Border = style.Border; operation.Bounds = rect; operation.DrawLevel = 1; operation.Sprite = style.Texture; operation.Colour = style.Colour; ActiveInstance.m_guiOperations.Add(operation); }
public static string InputField(RectangleShape rect, string textToRender, ref InputFieldStyle style) { if (style == null) { style = new InputFieldStyle(); } // Instead of calling TextArea(), just run the dup code from the method, cause lazy //TextArea(rect, textToRender, style.GetTextStyle()); Bitmap textBitmap = new Bitmap((int)rect.Width, (int)rect.Height); Graphics g = Graphics.FromImage(textBitmap); g.FillRectangle(ActiveInstance.GetColouredBrush(style.BackgroundColour), 0, 0, rect.Width, rect.Height); g.DrawString(textToRender, new Font(GetFontFamily(style.FontFamilyId), style.FontSize, FontStyle.Regular), ActiveInstance.GetColouredBrush(style.FontColour), new Rectangle(0, 0, (int)rect.Width, (int)rect.Height), ActiveInstance.GenerateTextFormat(style.HorizontalAlignment, style.VerticalAlignment)); Sprite textSprite = Sprite.LoadFromBitmap(textBitmap); textSprite.Create(false); GUIOperation operation = new GUIOperation(1, 2); operation.Bounds = rect; operation.DrawLevel = 1; operation.Sprite = textSprite; operation.Colour = Colour4b.White; g.Dispose(); textBitmap.Dispose(); ActiveInstance.m_guiOperations.Add(operation); // Finished creating text operation bool registeredADownClick = false; //Console.WriteLine("{0} mouse events on ({1})", ActiveInstance.m_currentMouseEvents.Count, TackEngine.RenderCycleCount); for (int i = 0; i < ActiveInstance.m_currentMouseEvents.Count; i++) { //Console.WriteLine("Pos: {0}, X: {1}, X + Width: {2}", ActiveInstance.m_currentMouseEvents[i].Position.X, rect.X, (rect.X + rect.Width)); if (ActiveInstance.m_currentMouseEvents[i].Position.X >= rect.X && ActiveInstance.m_currentMouseEvents[i].Position.X <= (rect.X + rect.Width)) { //Console.WriteLine("Is X"); if (ActiveInstance.m_currentMouseEvents[i].Position.Y >= rect.Y && ActiveInstance.m_currentMouseEvents[i].Position.Y <= (rect.Y + rect.Height)) { if (ActiveInstance.m_currentMouseEvents[i].EventType == 0) { registeredADownClick = true; Console.WriteLine("Found a GUI mouse event of type: {0} involving the InputField", ActiveInstance.m_currentMouseEvents[i].EventType); } } } } if (registeredADownClick) { TackInput.GUIInputRequired = true; } else if (!registeredADownClick && ActiveInstance.m_currentMouseEvents.Count(x => x.EventType == 0) > 0) { Console.WriteLine("Found that a mouse down happened outside this inputfield"); TackInput.GUIInputRequired = false; } KeyboardKey[] bufferOperations = TackInput.GetInputBufferArray(); string newString; if (textToRender == null) { newString = ""; } else { newString = textToRender; } for (int i = 0; i < bufferOperations.Length; i++) { if (bufferOperations[i] == KeyboardKey.Left) { if (style.CaretPosition > 0) { style.CaretPosition -= 1; } } else if (bufferOperations[i] == KeyboardKey.Right) { if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] == KeyboardKey.BackSpace) { if (style.CaretPosition > 0) { newString = newString.Remove((int)style.CaretPosition - 1, 1); } if (style.CaretPosition > 0) { style.CaretPosition -= 1; } } else if (bufferOperations[i] == KeyboardKey.Delete) { if (style.CaretPosition < newString.Length) { newString = newString.Remove((int)style.CaretPosition, 1); } } else if (bufferOperations[i] == KeyboardKey.Space) { newString = newString.Insert((int)style.CaretPosition, " "); if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] == KeyboardKey.Period) { newString = newString.Insert((int)style.CaretPosition, "."); if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] == KeyboardKey.Quote) { newString = newString.Insert((int)style.CaretPosition, "\""); if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] == KeyboardKey.Minus) { if (TackInput.InputBufferShift) { newString = newString.Insert((int)style.CaretPosition, "_"); } else { newString = newString.Insert((int)style.CaretPosition, "-"); } if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] >= KeyboardKey.Number0 && bufferOperations[i] <= KeyboardKey.Number9) { newString = newString.Insert((int)style.CaretPosition, ((char)((int)bufferOperations[i] - 61)).ToString()); if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } else if (bufferOperations[i] >= KeyboardKey.A && bufferOperations[i] <= KeyboardKey.Z) { if (TackInput.InputBufferCapsLock || TackInput.InputBufferShift) { newString = newString.Insert((int)style.CaretPosition, ((char)((int)bufferOperations[i] - 18)).ToString()); } else { newString = newString.Insert((int)style.CaretPosition, ((char)((int)bufferOperations[i] + 14)).ToString()); } if (style.CaretPosition < newString.Length) { style.CaretPosition += 1; } } } TackInput.ClearInputBuffer(); return(newString); }