Ejemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Timer = new Stopwatch();
            Timer.Start();

            Internal_UpdateCycleCounter = 0;
            Internal_RenderCycleCounter = 0;

            Sprite.LoadDefaultSprite();

            //mTackConsole.OnStart();

            mAudioManager = new AudioManager();
            mAudioManager.OnStart();

            mTackObjectManager = new TackObjectManager();
            mTackObjectManager.OnStart();

            mTackRender = new TackRenderer();
            mTackRender.OnStart();

            mTackPhysics = new TackPhysics();
            mTackPhysics.Start();

            TackInput.OnStart();

            onStartFunction();

            mTackObjectManager.RunTackObjectStartMethods();
        }
Ejemplo n.º 2
0
        internal override void OnUpdate()
        {
            Vector2f       mousePosition = Input.TackInput.MousePosition();
            RectangleShape checkBoxShape = new RectangleShape(Bounds.X + 2, Bounds.Y + 2, Bounds.Height - 4, Bounds.Height - 4);

            if (mousePosition.X >= checkBoxShape.X && mousePosition.X <= (checkBoxShape.X + checkBoxShape.Width))
            {
                if (mousePosition.Y >= checkBoxShape.Y && mousePosition.Y <= (checkBoxShape.Y + checkBoxShape.Height))
                {
                    m_hovering = true;

                    if (TackInput.MouseButtonUp(MouseButtonKey.Left))
                    {
                        IsSelected = !IsSelected;

                        if (OnSelectionChangedEvent != null)
                        {
                            if (OnSelectionChangedEvent.GetInvocationList().Length > 0)
                            {
                                OnSelectionChangedEvent.Invoke(this, EventArgs.Empty);
                            }
                        }
                    }
                }
                else
                {
                    m_hovering = false;
                }
            }
            else
            {
                m_hovering = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Is the mouse in the bounds of the InputField?
        /// </summary>
        /// <returns>Returns true if mouse is in the bounds of the InputField, false otherwise</returns>
        public bool IsMouseInBounds()
        {
            Vector2f mousePos = TackInput.MousePosition();

            if (mousePos.X >= mShape.X && mousePos.X <= (mShape.X + mShape.Width))
            {
                if (mousePos.Y >= mShape.Y && mousePos.Y <= (mShape.Y + mShape.Height))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            onUpdateFunction();

            // All OnUpdate here
            mTackPhysics.Update();      // If issues arise, try running this below RunTackObjectUpdateMethods()
            mTackObjectManager.OnUpdate();
            mTackObjectManager.RunTackObjectUpdateMethods();

            mTackConsole.OnUpdate();
            mTackRender.OnUpdate();
            TackInput.OnUpdate();

            TackEngine.mUpdateCyclesPerSecond = (int)UpdateFrequency;
            Internal_UpdateCycleCounter++;
            EngineTimer.LastCycleTime = e.Time;
        }
Ejemplo n.º 5
0
        internal override void OnUpdate()
        {
            Vector2f mousePosition = Input.TackInput.MousePosition();

            if (mousePosition.X >= Bounds.X && mousePosition.X <= (Bounds.X + Bounds.Width))
            {
                if (mousePosition.Y >= Bounds.Y && mousePosition.Y <= (Bounds.Y + Bounds.Height))
                {
                    m_hovering = true;

                    if (TackInput.MouseButtonDown(MouseButtonKey.Left))
                    {
                        m_pressing = true;

                        if (OnClickEvent != null)
                        {
                            if (OnClickEvent.GetInvocationList().Length > 0)
                            {
                                OnClickEvent.Invoke(this, EventArgs.Empty);
                            }
                        }
                    }
                }
                else
                {
                    m_hovering = false;
                }
            }
            else
            {
                m_hovering = false;
            }

            if (TackInput.MouseButtonUp(MouseButtonKey.Left))
            {
                m_pressing = false;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the input from the TackInput input buffer
 /// </summary>
 /// <returns></returns>
 public string GetInput()
 {
     return(TackInput.GetInputBuffer());
 }
Ejemplo n.º 7
0
        internal void OnUpdate()
        {
            if (mConsoleTextArea == null)
            {
                mConsoleTextArea = new GUITextArea()
                {
                    Bounds      = new RectangleShape(5, 5, TackEngine.ScreenWidth - 10, 400),
                    NormalStyle = new GUITextArea.GUITextAreaStyle()
                    {
                        Colour              = new Colour4b(0, 0, 0, 255),
                        Texture             = Sprite.DefaultSprite,
                        FontColour          = new Colour4b(0, 255, 0, 255),
                        FontSize            = 9f,
                        VerticalAlignment   = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Left
                    },

                    HoverStyle = new GUITextArea.GUITextAreaStyle()
                    {
                        Colour              = new Colour4b(0, 0, 0, 255),
                        Texture             = Sprite.DefaultSprite,
                        FontColour          = new Colour4b(0, 255, 0, 255),
                        FontSize            = 9f,
                        VerticalAlignment   = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Left
                    },
                    Text   = "",
                    Active = true
                };
            }

            if (mConsoleInputField == null)
            {
                mConsoleInputField = new GUIInputField()
                {
                    Bounds = new RectangleShape(5, 415, TackEngine.ScreenWidth - 10, 25),
                    Text   = "",
                    Active = true
                };

                mConsoleInputField.OnSubmit += ProcessCommand;
            }

            mConsoleTextArea.Active   = mConsoleGUIActive;
            mConsoleInputField.Active = mConsoleGUIActive;
            mConsoleTextArea.Bounds   = new RectangleShape(5, 5, TackEngine.ScreenWidth - 10, 400);
            mConsoleInputField.Bounds = new RectangleShape(5, 410, TackEngine.ScreenWidth - 10, 25);

            // Check to see if user wants to display the TackConsole GUI
            if (TackInput.InputActiveKeyDown(mActivationKey))
            {
                mConsoleGUIActive = !mConsoleGUIActive;
            }

            if (TackInput.KeyDown(KeyboardKey.PageDown))
            {
                if (mConsoleUIStyle.ScrollPosition < mMessages.Count - 1)
                {
                    mConsoleUIStyle.ScrollPosition += 1.0f;
                }
            }

            if (TackInput.KeyDown(KeyboardKey.PageUp))
            {
                if (mConsoleUIStyle.ScrollPosition > 0)
                {
                    mConsoleUIStyle.ScrollPosition -= 1.0f;
                }
            }

            //mInputString = mInputField.InputString;
        }
Ejemplo n.º 8
0
        protected override void OnMouseMove(MouseMoveEventArgs e)
        {
            base.OnMouseMove(e);

            TackInput.MouseMoveEvent(e.X, e.Y);
        }
Ejemplo n.º 9
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);

            TackInput.MouseUpEvent((MouseButtonKey)e.Button);
        }
Ejemplo n.º 10
0
        protected override void OnKeyUp(KeyboardKeyEventArgs e)
        {
            base.OnKeyUp(e);

            TackInput.KeyUpEvent((KeyboardKey)e.Key);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        internal override void OnUpdate()
        {
            m_caretBox.Bounds = new RectangleShape(Bounds.X + 10, Bounds.Y + 10, 0, 0);

            Vector2f mousePosition = TackInput.MousePosition();

            if (TackInput.MouseButtonUp(MouseButtonKey.Left))
            {
                if (mousePosition.X >= Bounds.X && mousePosition.X <= (Bounds.X + Bounds.Width))
                {
                    if (mousePosition.Y >= Bounds.Y && mousePosition.Y <= (Bounds.Y + Bounds.Height))
                    {
                        RequiringInput             = true;
                        TackInput.GUIInputRequired = true;
                    }
                    else
                    {
                        RequiringInput             = false;
                        TackInput.GUIInputRequired = false;
                    }
                }
                else
                {
                    RequiringInput             = false;
                    TackInput.GUIInputRequired = false;
                }
            }

            KeyboardKey[] bufferOperations = TackInput.GetInputBufferArray();

            for (int i = 0; i < bufferOperations.Length; i++)
            {
                if (bufferOperations[i] == KeyboardKey.Enter)
                {
                    if (OnSubmit != null)
                    {
                        if (OnSubmit.GetInvocationList().Length > 0)
                        {
                            OnSubmit.Invoke(this, Text);
                        }
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Left)
                {
                    if (SelectionStart > 0)
                    {
                        SelectionStart -= 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Right)
                {
                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.BackSpace)
                {
                    if (SelectionStart > 0)
                    {
                        Text = Text.Remove((int)SelectionStart - 1, 1);
                    }

                    if (SelectionStart > 0)
                    {
                        SelectionStart -= 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Delete)
                {
                    if (SelectionStart < Text.Length)
                    {
                        Text = Text.Remove((int)SelectionStart, 1);
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Space)
                {
                    Text = Text.Insert((int)SelectionStart, " ");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Period)
                {
                    Text = Text.Insert((int)SelectionStart, ".");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Quote)
                {
                    Text = Text.Insert((int)SelectionStart, "\"");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Minus)
                {
                    if (TackInput.InputBufferShift)
                    {
                        Text = Text.Insert((int)SelectionStart, "_");
                    }
                    else
                    {
                        Text = Text.Insert((int)SelectionStart, "-");
                    }

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }

                else if (bufferOperations[i] >= KeyboardKey.Number0 && bufferOperations[i] <= KeyboardKey.Number9)
                {
                    Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] - 61)).ToString());

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] >= KeyboardKey.A && bufferOperations[i] <= KeyboardKey.Z)
                {
                    if (TackInput.InputBufferCapsLock || TackInput.InputBufferShift)
                    {
                        Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] - 18)).ToString());
                    }
                    else
                    {
                        Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] + 14)).ToString());
                    }

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
            }

            TackInput.ClearInputBuffer();
        }