Psi GUI - GUI controls for XNA 4.0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 4156 Views - Last Post: 13 January 2011 - 05:11 PM

#1 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Psi GUI - GUI controls for XNA 4.0

Posted 27 December 2010 - 06:45 PM

I've been working with XNA since version 2.0 came out. I tried XNA 2.0 and I was hooked. One thing about XNA is you have to write any controls you want to use, like text boxes, picture boxes, list boxes, etc. I do know there are other GUI libraries out there but I've been working on GUI controls for my role playing game tutorials. I'm still working on the kinks but I plan to release my GUI system as a free open source software. If you'd like to get involved in this project leave a reply here.

Is This A Good Question/Topic? 0
  • +

Replies To: Psi GUI - GUI controls for XNA 4.0

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 27 December 2010 - 06:52 PM

I'd be happy to help you out. Just let me know where you need some assistance, Jamie.
Was This Post Helpful? 0
  • +
  • -

#3 X@MPP  Icon User is offline

  • 僕わ馬鹿ですね?
  • member icon

Reputation: 32
  • View blog
  • Posts: 1,010
  • Joined: 20-February 09

Re: Psi GUI - GUI controls for XNA 4.0

Posted 28 December 2010 - 01:33 AM

sounds awesome that is kinda whats been keeping me away from XNA. do you plan to make a public class that we can inherit from to make our own controls as well?
Was This Post Helpful? 0
  • +
  • -

#4 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1212
  • View blog
  • Posts: 4,128
  • Joined: 27-January 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 28 December 2010 - 07:27 AM

I'd like to contribute Six. If you upload the entire project to BitBucket we can collaborate much easier using Mercurial.

This sounds like a great idea. :)
Was This Post Helpful? 0
  • +
  • -

#5 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 28 December 2010 - 07:59 AM

Sounds good to me guys. I'll try and get something up like Sergio suggested today. There is a base class that I use for all controls. There is then a set of interfaces that can be implemented to add functionality. For example, I have an ITextControl interface that can be implemented for a control that has a text component. I'll leave a reply when I have a project set up.
Was This Post Helpful? 0
  • +
  • -

#6 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 28 December 2010 - 02:10 PM

So, I have created a Bitbucket account and a public repository. If you have a Bitbucket account let me know your user name and I will add you as a writer to the project. The URL for the project is:

https://bitbucket.or...psigui/overview

The way I'm handling the controls is there is an abstract base class Control. That all controls inherit from. There is another class ControlManager that manages the active controls. To implement the different types of controls you use interfaces. At the moment I'm still ironing out the interfaces and would appreciate any feedback you have on them. They were originally meant for the Xbox 360 so there is no mouse support at the moment. The project works for just Windows at the moment. I will be adding in a version of my input handler for common input handling tasks.

Base class Control:
    public abstract class Control
    {
        #region Field Region

        string name;
        object tag;

        #endregion

        #region Property Region

        public string Name
        {
            get { return name; }
            set { if (!string.IsNullOrEmpty(value)) name = value; }
        }

        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        #endregion

        #region Constructor Region

        public Control(string name)
        {
            this.name = name;
        }

        #endregion

        #region Method Region
        #endregion
    }



Interfaces that I have at the moment are:
  • IDrawableControl for a control that can be drawn
  • IUpdatableControl for a control that can be updated
  • ITextControl for a control that has text
  • IPictureControl for a control that has an image
  • ISelectableControl for a control that can be selected/clicked
  • IListControl for a control that has a list associated with it


These are the interfaces at the moment. If you have an idea on these let me know.

    public interface IDrawableControl
    {
        Vector2 Size { get; set; }
        bool Visible { get; set; }
        Color Color { get; set; }
        Color DisabledColor { get; set; }

        void Draw(GameTime gameTime, SpriteBatch spriteBatch);
    }

    public interface IUpdatableControl
    {
        bool Enabled { get; set; }

        void Update(GameTime gameTime);
    }

    public interface ITextControl
    {
        Vector2 Position { get; set; }
        SpriteFont Font { get; set; }
        string Text { get; set; }
    }

    public interface IPictureControl
    {
        Texture2D Image { get; set; }
        Rectangle? SourceRectangle { get; set; }
        Rectangle DestinationRectangle { get; set; }
    }

    public interface ISelectableControl
    {
        event EventHandler Selected;
        event EventHandler GotFocus;
        event EventHandler LostFocus;

        bool HasFocus { get; set; }
        bool TabStop { get; set; }

        Color SelectedColor { get; set; }

        void HandleInput(PlayerIndex? playerIndex);
    }

    public interface IListControl
    {
        event EventHandler Selectionchange;

        List<object> Items { get; }
        string SelectedItem { get; }
        int SelectedIndex { get; }
    }



So, say you want to make a Label control. You create a class that inherits from Control and implements say the IDrawableControl interface and the ITextControl interface.

public class Label : Control, IDrawableControl, ITextControl
{
}



I will get to the managers another time.
Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 29 December 2010 - 01:53 PM

No comments or suggestions or Bitbucket accounts for me to add?
Was This Post Helpful? 0
  • +
  • -

#8 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 29 December 2010 - 02:31 PM

Sorry bud, haven't gotten around to creating an account on there yet. I'll do that tonight and let you know.
Was This Post Helpful? 0
  • +
  • -

#9 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 29 December 2010 - 02:36 PM

Ok. Was hoping for a little feedback on the interfaces and such as well. I still have a bit of work to do on the basic project but didn't want to get too much further into it until the interfaces are pretty much solid. I don't want to include the same functionality in two interface but using a lot of interfaces may not be the best approach as well.
Was This Post Helpful? 0
  • +
  • -

#10 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 29 December 2010 - 02:58 PM

Very true. I'll take a look through it a little closer tonight when I get from work and let you know what I think.
Was This Post Helpful? 0
  • +
  • -

#11 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 29 December 2010 - 07:42 PM

I have a quick question. Is there a specific reason why the IDrawableControl interface doesn't have a texture? I'm just curious. I've also wondered if maybe a Vector2 for positioning should be placed in the base class or if it would be better elsewhere. Other than that, it all appears to be in order. What other interfaces do you have plans for at the moment?

EDIT: Also, I created an account on bitbucket, name is Kilorn.

This post has been edited by Kilorn: 29 December 2010 - 07:51 PM

Was This Post Helpful? 0
  • +
  • -

#12 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 30 December 2010 - 03:28 PM

I've added you to the Bitbucket project as an admin Kilorn. You have read/write access and you should be able to add others.

I had kept the Texture2D out of the IDrawableControl because the IPictureControl allows for using source and destination rectangles. I could see adding in a Texture2D and a SpriteFont to the IDrawableControl. I kept the Vector2 for position out of the base class as I planned to include controls that wouldn't be visible, like a Timer control. I can't count the number of times people have asked about timing something. I plan to add a basic Timer class with a Tick event that could be fired when the Timer reaches it Interval than can be added to the control manager. I'm also trying to keep the interfaces pretty simple so that a user can create their own controls using the base class and the interfaces. The control manager will know what interfaces can be implemented, like IUpdateableControl can be updated and IDrawableControl can be drawn. Their Update and Draw methods will be called automatically if they are visible or enabled.

So, after updating things a bit I have this for the interfaces. I haven't updated the project yet but I will try and do that this evening.

public interface IDrawableControl
{
    Texture2D Image { get; set; }
    SpriteFont Font { get; set; }

    Vector2 Position { get; set; }
    Vector2 Size { get; set; }

    bool Visible { get; set; }

    Color Color { get; set; }
    Color DisabledColor { get; set; }

    void Draw(GameTime gameTime, SpriteBatch spriteBatch);
}

public interface IUpdatableControl
{
    bool Enabled { get; set; }

    void Update(GameTime gameTime);
}

public interface ITextControl
{
    string Text { get; set; }
}

public interface IPictureControl
{
    Rectangle? SourceRectangle { get; set; }
    Rectangle DestinationRectangle { get; set; }
}

public interface ISelectableControl
{
    event EventHandler Selected;
    event EventHandler GotFocus;
    event EventHandler LostFocus;

    bool HasFocus { get; set; }
    bool TabStop { get; set; }

    Color SelectedColor { get; set; }

    void HandleInput(PlayerIndex? playerIndex);
}

public interface IListControl
{
    event EventHandler Selectionchange;

    List<object> Items { get; }
    string SelectedItem { get; }
    int SelectedIndex { get; }
}

public interface ITimerControl
{
    event EventHandler Tick;
    
    TimeSpan Interval; // possibly float or double?
    void Start();
    void Stop();
    void Reset();
}


Was This Post Helpful? 0
  • +
  • -

#13 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 05 January 2011 - 09:21 AM

Somehow I managed to miss that last post altogether, SixOfEleven. I hadn't thought of timer controls, so now it makes sense that there isn't a positional vector2 in the base class. Not to mention controls like the IUpdateableControl that you've written. That wouldn't have a position. Have you done anything else since the 30th?
Was This Post Helpful? 0
  • +
  • -

#14 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Psi GUI - GUI controls for XNA 4.0

Posted 05 January 2011 - 11:40 AM

Unfortunately no, I haven't done much with this lately. I have updated the Bitbucket project with those changes. I added in a skeleton for the input handler as well. I'm trying to decide if we should require the end user to add the input handler to their list of components or if we should manage that on our own. I'm leaning toward managing it on our own.
Was This Post Helpful? 0
  • +
  • -

#15 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Psi GUI - GUI controls for XNA 4.0

Posted 05 January 2011 - 11:43 AM

What are the benefits of doing it each way?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3