TGUI Forum

General Category => Installation help => Topic started by: Charsmud on 20 September 2015, 06:52:22

Title: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 06:52:22
I am trying to compile TGUI for Visual Studio 2015 because the version I was using previously seemed to not work for VS2015.  However, I keep getting this error when I try to use CMAKE:

Code: [Select]
SFML found but version too low (requested: 2, found: 1.x.x)
CMake Error at CMakeLists.txt:290 (message):
  CMake couldn't find SFML.  Set the SFML_ROOT entry to SFML's root directory
  (containing "include" and "lib" directories).


Configuring incomplete, errors occurred!
See also "E:/Downloads/TGUI/CMakeFiles/CMakeOutput.log".

I am using SFML 2.3.2.
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 11:40:35
Could you check the value of SFML_INCLUDE_DIR in cmake?
I'm not sure if the value shows up in the cmake gui when finding it fails, so perhaps you should add the following line in TGUI/cmake/Modules/FindSFML.cmake at line 348 where your error is coming from:
Code: [Select]
message(STATUS "SFML_INCLUDE_DIR: ${SFML_INCLUDE_DIR}")
I suspect that folder is going to be a wrong SFML directory. The SFML version will probably be 2.0 or 2.1 instead of 1.x as the error describes, but this has to do with a bug in FindSFML.cmake that was recently (partially) solved in SFML but I haven't copied the new file to TGUI yet.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 17:47:57
The path is "E:/OpenGL/include".  Inside that folder is a folder called SFML, and in that folder are all the SFML header and cpp files.
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 17:50:23
And the Config.hpp file in those headers is the one from SFML 2.3.2 (the version is defined on top of that file)?
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 17:51:39
The file says 2.1 (Major version 2, minor 1).
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 17:54:21
Then those header files are from SFML 2.1 and not from 2.3.2. The cmake script is only compatible from sfml 2.2 onwards.
So you should remove these headers (or temporarily move them if you still need them) and let tgui find your sfml 2.3.2 headers.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 18:25:02
OK, it was able to be created with CMake.  However, now when I build in VS2015, I get the following:


Error   LNK1112   module machine type 'x64' conflicts with target machine type 'X86'   tgui   E:\Downloads\TGUI-0.7-alpha1\TGUI-0.7-alpha1\build\src\TGUI\sfml-graphics.lib(sfml-graphics-2.dll)

Any ideas?
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 18:27:30
One or two of the three is build in 32-bit while the other is 64-bit: your project, tgui, sfml
They all have to match, if tgui is the 32-bit one (it builds as 32-bit by default) and you are using 64-bit for everything else then you should check the settings in Visual Studio when you open tgui.sln and see if you can select Win64 somewhere.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 18:56:34
I have x64 SFML and I used that to build TGUI, but I didn't see an option to change TGUI from 32 bit to 64 bit.  I went into Configuration Manager, tried with Win32, and it threw this error.  I changed the Active Solution Platform to a new one, Changed it from ARM to x64, set all the projects to x64, and it still throws the same error. 
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 18:59:35
I actually have no idea how to do it inside VS, I build my libraries from the command line (with a batch script).
I have to recompile TGUI anyway, if you send me your SFML libraries then I'll build TGUI here with those sfml libs.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 19:16:23
Thanks so much!  Yeah, I have no idea why it's not working, because that is how the microsoft website says to set up a project for 64 bit.... 

https://www.dropbox.com/sh/fgs8zt7uq10afsg/AABfr7Ita1VGmAZ_W7mCqMiCa?dl=0
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 21:11:26
Since the Config.hpp in your files states 2.3.1 instead of 2.3.2 I couldn't build it automatically together with the rest so it took a bit longer.

The files can be found here: https://www.dropbox.com/s/87z36lz145pew8c/tgui-alpha2-Win64-VS2015-custom.zip?dl=1

The TGUI version is newer than the tutorials and documentation on my site. The website will be updated in a few hours or in worst case tomorrow. But the only thing you should keep in mind until then is that you have to use setFont instead of setGlobalFont, you probably won't notice any difference.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 21:47:27
Thank you very much for your help!
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 23:04:03
Hm... I seem to get 269 errors when I try it with my project.  For example:

Code: [Select]
'load': is not a member of 'tgui::Picture'

but it has methods like askToolTip, so I'm not sure what's going on.  the code worked previously, but I'm not sure what's throwing it off now. 
Title: Re: Compiling TGUI with VS2015
Post by: texus on 20 September 2015, 23:06:32
Oh you wanted tgui 0.6? :)
The load function is from tgui 0.6, I gave you libraries and header files for tgui 0.7-alpha2.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 20 September 2015, 23:07:35
Ah, makes sense, I derped.  I'll look around and see what I can figure out.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 22 September 2015, 03:34:01
Hm, I seem to be getting errors in the TGUI header files, like

Error   C2238   unexpected token(s) preceding ';'   Byte   E:\OpenGL\include\TGUI\Button.hpp, Line   44

Any suggestions?  I can't seem to figure out why the actual library is erring. 
Title: Re: Compiling TGUI with VS2015
Post by: texus on 22 September 2015, 06:14:32
Button.hpp line 44 is in the middle of a comment in the file: https://github.com/texus/TGUI/blob/master/include/TGUI/Widgets/Button.hpp#L44

Make sure that you use the include folder that I included in the zip file and not some other version.
Title: Re: Compiling TGUI with VS2015
Post by: Charsmud on 25 September 2015, 03:07:09
Yep, I am using the files from the .zip. My Button.hpp looks like this:

Code: [Select]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TGUI - Texus's Graphical User Interface
// Copyright (C) 2012-2013 Bruno Van de Velde (vdv_b@tgui.eu)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef TGUI_BUTTON_HPP
#define TGUI_BUTTON_HPP


#include <TGUI/ClickableWidget.hpp>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace tgui
{
    class Container;

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    class TGUI_API Button : public ClickableWidget
    {
      public:

        typedef SharedWidgetPtr<Button> Ptr;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Default constructor
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Button();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Copy constructor
        ///
        /// \param copy  Instance to copy
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Button(const Button& copy);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Destructor
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual ~Button();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Overload of assignment operator
        ///
        /// \param right  Instance to assign
        ///
        /// \return Reference to itself
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Button& operator= (const Button& right);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // Makes a copy of the widget by calling the copy constructor.
        // This function calls new and if you use this function then you are responsible for calling delete.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual Button* clone();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Loads the widget.
        ///
        /// \param configFileFilename  Filename of the config file.
        ///
        /// The config file must contain a Button section with the needed information.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        bool load(const std::string& configFileFilename);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Returns the filename of the config file that was used to load the widget.
        ///
        /// \return Filename of loaded config file.
        ///         Empty string when no config file was loaded yet.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        const std::string& getLoadedConfigFile() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Set the position of the widget
        ///
        /// This function completely overwrites the previous position.
        /// See the move function to apply an offset based on the previous position instead.
        /// The default position of a transformable widget is (0, 0).
        ///
        /// \param x X coordinate of the new position
        /// \param y Y coordinate of the new position
        ///
        /// \see move, getPosition
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void setPosition(float x, float y);
        using Transformable::setPosition;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the size of the button.
        ///
        /// \param width   The new width of the button
        /// \param height  The new height of the button
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void setSize(float width, float height);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the caption of the button.
        ///
        /// \param text  New text to draw on top of the button.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void setText(const sf::String& text);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Returns the caption of the button.
        ///
        /// \return Text that is drawn on top of the button.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        sf::String getText() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the font of the text.
        ///
        /// When you don't call this function then the global font will be use.
        /// This global font can be changed with the setGlobalFont function from the parent.
        ///
        /// \param font  The new font
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void setTextFont(const sf::Font& font);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Returns the font of the text.
        ///
        /// \return  Pointer to the font that is currently being used
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        const sf::Font* getTextFont() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the color of the text.
        ///
        /// \param color  New text color
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void setTextColor(const sf::Color& color);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Returns the color of the text.
        ///
        /// \return The current text color
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        const sf::Color& getTextColor() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the character size of the text.
        ///
        /// \param size  The new text size.
        ///              If the size is set to 0 then the text will be auto-sized to fit inside the button.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void setTextSize(unsigned int size);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Returns the character size of the text.
        ///
        /// \return The current text size.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        unsigned int getTextSize() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \brief Changes the transparency of the widget.
        ///
        /// \param transparency  The transparency of the widget.
        ///                      0 is completely transparent, while 255 (default) means fully opaque.
        ///
        /// Note that this will only change the transparency of the images. The parts of the widgets that use a color will not
        /// be changed. You must change them yourself by setting the alpha channel of the color.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void setTransparency(unsigned char transparency);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void keyPressed(sf::Keyboard::Key key);

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void widgetFocused();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // This function is a (slow) way to set properties on the widget, no matter what type it is.
        // When the requested property doesn't exist in the widget then the functions will return false.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual bool setProperty(std::string property, const std::string& value);

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // This function is a (slow) way to get properties of the widget, no matter what type it is.
        // When the requested property doesn't exist in the widget then the functions will return false.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual bool getProperty(std::string property, std::string& value) const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // Returns a list of all properties that can be used in setProperty and getProperty.
        // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      protected:

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // This function is called when the widget is added to a container.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void initialize(Container *const container);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \internal
        // Draws the widget on the render target.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      public:

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Defines specific triggers to Button.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        enum ButtonCallbacks
        {
            SpaceKeyPressed      = ClickableWidgetCallbacksCount * 1,     ///< Space key was pressed
            ReturnKeyPressed     = ClickableWidgetCallbacksCount * 2,     ///< Return key was pressed
            AllButtonCallbacks   = ClickableWidgetCallbacksCount * 4 - 1, ///< All triggers defined in Button and its base classes
            ButtonCallbacksCount = ClickableWidgetCallbacksCount * 4
        };


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      protected:

        std::string m_LoadedConfigFile;

        Texture m_TextureNormal_L;
        Texture m_TextureHover_L;
        Texture m_TextureDown_L;
        Texture m_TextureFocused_L;

        Texture m_TextureNormal_M;
        Texture m_TextureHover_M;
        Texture m_TextureDown_M;
        Texture m_TextureFocused_M;

        Texture m_TextureNormal_R;
        Texture m_TextureHover_R;
        Texture m_TextureDown_R;
        Texture m_TextureFocused_R;

        // If this is true then the L, M and R images will be used.
        // If it is false then the button is just one big image that will be stored in the M image.
        bool m_SplitImage;

        // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
        bool m_SeparateHoverImage;

        // The SFML text
        sf::Text m_Text;

        // This will store the size of the text ( 0 to auto size )
        unsigned int m_TextSize;


        friend class ChildWindow;
    };

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#endif // TGUI_BUTTON_HPP


Title: Re: Compiling TGUI with VS2015
Post by: texus on 25 September 2015, 10:30:04
To be absolutely clear: you need the Button.hpp (and the other headers) from the tgui-alpha2-Win64-VS2015-custom.zip file that I send.

I can tell that the file you are showing is not the correct one, because the one in that zip has the following where the class declaration starts:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Button widget
///
/// Signals:
///     - Pressed (the button was pressed)
///         * Optional parameter sf::String: Caption of the button
///         * Uses Callback member 'text'
///
///     - Inherited signals from ClickableWidget
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class TGUI_API Button : public ClickableWidget