Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TGUI for C#  (Read 11223 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
TGUI for C#
« on: June 21, 2013, 04:11:33 pm »
Update:

TGUI.Net is now released and can be found on tgui.net.


Original post:
--------------------------------------------------------------

Some time ago someone requested a c# port for TGUI.
I wanted to ask if anyone is still interested in this.

Code would look like the following (can still be changed if needed).
using System;
using SFML.Window;
using SFML.Graphics;
using TGUI;

namespace window
{
    static class Program
    {
        static public void LoadObjects ( Gui gui )
        {
            // Create the background image
            Picture picture = gui.Add (new Picture("xubuntu_bg_aluminium.jpg"));
            picture.Size = new Vector2f(800, 600);

            // Create the username label
            Label labelUsername = gui.Add (new Label());
            labelUsername.Text = "Username:";
            labelUsername.Position = new Vector2f(200, 100);

            // Create the password label
            Label labelPassword = gui.Add (new Label());
            labelPassword.Text = "Password:";
            labelPassword.Position = new Vector2f(200, 250);

            // Create the username edit box
            EditBox editBoxUsername = gui.Add (new EditBox("objects/Black.conf"), "Username");
            editBoxUsername.Size = new Vector2f(400, 40);
            editBoxUsername.Position = new Vector2f(200, 140);

            // Create the password edit box (we will copy the previously created edit box)
            EditBox editBoxPassword = gui.Add(new EditBox(editBoxUsername), "Password");
            editBoxPassword.Position = new Vector2f(200, 290);
            editBoxPassword.PasswordCharacter = "*";

            // Create the login button
            Button button = gui.Add (new Button("objects/Black.conf"));
            button.Size = new Vector2f(260, 60);
            button.Position = new Vector2f(270, 440);
            button.Text = "Login";
            button.CallbackId = 1;
            button.LeftMouseClickedCallback += OnButtonClick;
        }

        static void Main ()
        {
            // Create the window
            RenderWindow window = new RenderWindow (new VideoMode(800, 600), "TGUI.Net Login Screen Example");
            Gui gui = new Gui (window);

            window.Closed += OnClosed;

            // Load the font
            gui.GlobalFont = new Font("Fonts/DejaVuSans.ttf");

            // Load the objects
            LoadObjects (gui);

            // Main loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents ();

                window.Clear();
                gui.Draw();
                window.Display();
            }
        }

        static void OnClosed(object sender, EventArgs e)
        {
            ((Window)sender).Close ();
        }

        static void OnButtonClick(object sender, MouseCallbackArgs e)
        {
            // Get the username and password
            EditBox editBoxUsername = ((Button)sender).Parent.Get<EditBox>("Username");
            EditBox editBoxPassword = ((Button)sender).Parent.Get<EditBox>("Password");

            System.Console.WriteLine("Username: " + editBoxUsername.Text);
            System.Console.WriteLine("Password: " + editBoxPassword.Text);
        }
    }
}
 

Which would give the following result:
« Last Edit: August 27, 2013, 01:28:32 pm by texus »
TGUI: C++ SFML GUI

DarkSummon

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: TGUI for C#
« Reply #1 on: June 23, 2013, 04:16:50 pm »
I'd be very much interested in being able to have the following controls in the C# bindings of SFML:

Combo Box
Slider
Tab Pages

Is this something you can provide? :)

P.S. Awesome work with TGUI!

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI for C#
« Reply #2 on: June 23, 2013, 04:29:35 pm »
These objects are in the c++ version so they would eventually be in the c# version as well.
Tab pages aren't directly supported, but can be made with a combination of the tab object and panels. Then you just show the correct panel when some tab gets selected.

I can probably make it work in c# in just a few days (maybe even tomorrow), but if you need tutorials and documentation then it will take some more time.
TGUI: C++ SFML GUI

DarkSummon

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: TGUI for C#
« Reply #3 on: June 23, 2013, 04:39:54 pm »
Right ok, that makes sense.

Well, I have a project in C# using VS 2012 that uses the SFML C# bindings. I have some simple controls like TextBoxes, but yes, I'd love it if I could include the above mentioned control classes into my project.

Thank you, I really appreciate it. I look forward to seeing the results :).

Mad

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: TGUI for C#
« Reply #4 on: August 26, 2013, 04:18:11 pm »
Hello!

Is there any chance to get a windows port of the library?
website says: 'Windows users will have to wait until I am in the mood to boot up my windows.'   :-[
best regards,

Mad

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI for C#
« Reply #5 on: August 26, 2013, 04:50:56 pm »
The code itself will work on windows, I just haven't tried it yet. Nor do I know how to get it working in visual studio.

It has been reported working if you recompile the library though. I just can't help you yet with how to configure visual studio to use the library.
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI for C#
« Reply #6 on: August 26, 2013, 05:47:33 pm »
Alright, I got it working in visual studio.
I will need a lot more time to do testing and write a proper tutorial, but for now you can just follow these instructions.

Recompile tgui.net
- Create a new project (C# Class Library).
- Add all files from the src folder to the project.
- Add the sfmlnet-graphics-2.dll and sfmlnet-window-2.dll from SFML.Net 2.1 to the references.
- Add the Tao.OpenGl and Tao.OpenGl.ExtentionLoader from the lib folder to the references.
- Build the project

Your project
- Create your project (C# Empty project).
- Add the sfmlnet-graphics-2.dll and sfmlnet-window-2.dll from SFML.Net 2.1 to the references.
- Add the just created tguinet.dll to the references.
- Make sure you have copied csfml-graphics-2.dll and csfml-window-2.dll from the extlib folder from SFML.Net 2.1 next to your executable.
- That should be it. You should now be able to use tgui.net!
« Last Edit: August 27, 2013, 01:28:43 pm by texus »
TGUI: C++ SFML GUI

Mad

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: TGUI for C#
« Reply #7 on: August 27, 2013, 10:12:59 am »
Hi Texus!

Thank you very much! I followed your steps and it works well!  :D

Do you have any plans to add modal windows and messagboxes?


best regards,

Mad

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI for C#
« Reply #8 on: August 27, 2013, 01:28:50 pm »
Quote
Do you have any plans to add modal windows and messagboxes?
ChildWindow is already in tgui.net, so by adding a few widgets to it you can make these yourself.
But MessageBox is already in the c++ version, so you can expect it in the c# version as well when I have some more time.

The three widgets that still have to be ported to c# are MessageBox, Grid and TextBox. So you can still expect these.
TGUI: C++ SFML GUI

 

anything