Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.12 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // TGUI - Texus's Graphical User Interface
  4. // Copyright (C) 2012 Bruno Van de Velde (vdv_b@tgui.eu)
  5. //
  6. // This software is provided 'as-is', without any express or implied warranty.
  7. // In no event will the authors be held liable for any damages arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it freely,
  11. // subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented;
  14. //    you must not claim that you wrote the original software.
  15. //    If you use this software in a product, an acknowledgment
  16. //    in the product documentation would be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such,
  19. //    and must not be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  24.  
  25.  
  26. #ifndef TGUI_CHILD_WINDOW_HPP
  27. #define TGUI_CHILD_WINDOW_HPP
  28.  
  29. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30.  
  31. namespace tgui
  32. {
  33.     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34.     /// \brief Movable Panel with title bar.
  35.     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36.     class TGUI_API ChildWindow : public GroupObject, public ObjectBorders
  37.     {
  38.       public:
  39.  
  40.         typedef SharedObjectPtr<ChildWindow> Ptr;
  41.  
  42.  
  43.         /// Title alignments, possible options for the setTitleAlignment function
  44.         enum TitleAlignment
  45.         {
  46.             /// Places the title on the left side of the title bar
  47.             TitleAlignmentLeft,
  48.  
  49.             /// Places the title in the middle of the title bar
  50.             TitleAlignmentCentered,
  51.  
  52.             /// Places the title on the right side of the title bar
  53.             TitleAlignmentRight
  54.         };
  55.  
  56.  
  57.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58.         /// \brief Default constructor
  59.         ///
  60.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61.         ChildWindow();
  62.  
  63.  
  64.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65.         /// \brief Copy constructor
  66.         ///
  67.         /// \param copy  Instance to copy
  68.         ///
  69.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70.         ChildWindow(const ChildWindow& copy);
  71.  
  72.  
  73.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74.         /// \brief Destructor
  75.         ///
  76.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77.         virtual ~ChildWindow();
  78.  
  79.  
  80.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81.         /// \brief Overload of assignment operator
  82.         ///
  83.         /// \param right  Instance to assign
  84.         ///
  85.         /// \return Reference to itself
  86.         ///
  87.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88.         ChildWindow& operator= (const ChildWindow& right);
  89.  
  90.  
  91.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92.         // Makes a copy of the object by calling the copy constructor.
  93.         // This function calls new and if you use this function then you are responsible for calling delete.
  94.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  95.         virtual ChildWindow* clone();
  96.  
  97.  
  98.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  99.         /// \brief Creates the child window.
  100.         ///
  101.         /// \param width            Sets the width of the child window.
  102.         /// \param height           Sets the height of the child window.
  103.         /// \param backgroundColor  Sets the background color of the child window.
  104.         /// \param pathname         The path to the folder that contains the images for the titlebar and an optional background image.
  105.         ///                         The folder must also contain an info.txt file, which will give more information about the child window.
  106.         ///
  107.         /// The width and height are the size of the child window, without the title bar nor the borders.
  108.         ///
  109.         /// \return
  110.         ///        - true on success
  111.         ///        - false when the pathname was empty
  112.         ///        - false when the info.txt file was not found
  113.         ///        - false when the images couldn't be loaded
  114.         ///
  115.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  116.         virtual bool load(const std::string& pathname, float width, float height, const sf::Color& backgroundColor = sf::Color::White);
  117.  
  118.  
  119.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120.         /// \brief Changes the size of the child window.
  121.         ///
  122.         /// \param width   Sets the new width of the child window
  123.         /// \param height  Sets the new height of the child window
  124.         ///
  125.         /// The width and height are the size of the child window, without the title bar nor the borders.
  126.         ///
  127.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  128.         virtual void setSize(float width, float height);
  129.  
  130.  
  131.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  132.         /// \brief Returns the size of the panel.
  133.         ///
  134.         /// \return Size of the panel
  135.         ///
  136.         /// The size returned by this function is the size of the child window, without the title bar nor the borders.
  137.         ///
  138.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  139.         virtual Vector2f getSize() const;
  140.  
  141.  
  142.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  143.         /// \brief Returns the pathname that was used to load the child window.
  144.         ///
  145.         /// \return Pathname used to load the child window.
  146.         ///         When the child window has not been loaded yet then this function will return an empty string.
  147.         ///
  148.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  149.         virtual std::string getLoadedPathname() const;
  150.  
  151.  
  152.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  153.         /// \brief Changes the background texture of the child window.
  154.         ///
  155.         /// \param texture  Pointer to the texture that should be used as background of the child window
  156.         ///
  157.         /// \warning You should make sure that the texture stays alive.
  158.         ///
  159.         /// If the texture has a different size than the child window then it will be scaled to fill the whole window.
  160.         /// Pass NULL to this function to remove the background texture.
  161.         ///
  162.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  163.         virtual void setBackgroundTexture(sf::Texture *const texture = NULL);
  164.  
  165.  
  166.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167.         /// \brief Returns the background texture of the child window.
  168.         ///
  169.         /// \return Pointer to the texture that is being used as background of the child window.
  170.         ///         This pointer is NULL when no background texture was set.
  171.         ///
  172.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  173.         virtual sf::Texture* getBackgroundTexture();
  174.  
  175.  
  176.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  177.         /// \brief Change the height of the title bar.
  178.         ///
  179.         /// \param height  New height of the title bar
  180.         ///
  181.         /// The default height is the height of the title bar image that is loaded with the load function.
  182.         ///
  183.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  184.         virtual void setTitlebarHeight(unsigned int height);
  185.  
  186.  
  187.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  188.         /// \brief Returns the height of the title bar.
  189.         ///
  190.         /// \return Height of the title bar
  191.         ///
  192.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  193.         virtual unsigned int getTitleBarHeight() const;
  194.  
  195.  
  196.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  197.         /// \brief Changes the background color of the child window.
  198.         ///
  199.         /// \param backgroundColor  New background color
  200.         ///
  201.         /// The background is fully transparent by default.
  202.         ///
  203.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  204.         virtual void setBackgroundColor(const sf::Color& backgroundColor);
  205.  
  206.  
  207.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  208.         /// \brief Returns the background color of the panel.
  209.         ///
  210.         /// The background is fully transparent by default.
  211.         ///
  212.         /// \return The current background color
  213.         ///
  214.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  215.         virtual const sf::Color& getBackgroundColor() const;
  216.  
  217.  
  218.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  219.         /// \brief Changes the transparency of the window.
  220.         ///
  221.         /// \param transparency  The transparency of the window.
  222.         ///                      0 is completely transparent, while 255 means fully opaque.
  223.         ///
  224.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225.         virtual void setTransparency(unsigned char transparency);
  226.  
  227.  
  228.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  229.         /// \brief Returns the transparency of the window.
  230.         ///
  231.         /// \return The transparency of the window.
  232.         ///         0 is completely transparent, while 255 means fully opaque.
  233.         ///
  234.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  235.         virtual unsigned char getTransparency() const;
  236.  
  237.  
  238.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  239.         /// \brief Changes the title that is displayed in the title bar of the child window.
  240.         ///
  241.         /// \param title  New title for the child window
  242.         ///
  243.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  244.         virtual void setTitle(const sf::String& title);
  245.  
  246.  
  247.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  248.         /// \brief Returns the title that is displayed in the title bar of the child window.
  249.         ///
  250.         /// \return Title of the child window
  251.         ///
  252.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  253.         virtual const sf::String& getTitle() const;
  254.  
  255.          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256.         /// \brief Change the title color that is displayed in the title bar of the child window.
  257.         ///
  258.         /// \param Color title of the child window
  259.         ///
  260.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  261.         virtual void setTitleColor(const sf::Color & titleColor);
  262.        
  263.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  264.         /// \brief Returns the title color that is displayed in the title bar of the child window.
  265.         ///
  266.         /// \return Title color of the child window
  267.         ///
  268.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  269.         virtual const sf::Color& getTitleColor() const;
  270.        
  271.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  272.         /// \brief Set the border color.
  273.         ///
  274.         /// \param borderColor  The color of the borders
  275.         ///
  276.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  277.         virtual void setBorderColor(const sf::Color& borderColor);
  278.  
  279.  
  280.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  281.         /// \brief Returns the borde color.
  282.         ///
  283.         /// \return The color of the borders
  284.         ///
  285.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  286.         virtual const sf::Color& getBorderColor() const;
  287.  
  288.  
  289.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  290.         /// \brief Changes the size of the borders.
  291.         ///
  292.         /// \param leftBorder    The width of the left border
  293.         /// \param topBorder     The height of the top border
  294.         /// \param rightBorder   The width of the right border
  295.         /// \param bottomBorder  The height of the bottom border
  296.         ///
  297.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  298.         virtual void setBorders(unsigned int leftBorder   = 0,
  299.                                 unsigned int topBorder    = 0,
  300.                                 unsigned int rightBorder  = 0,
  301.                                 unsigned int bottomBorder = 0);
  302.  
  303.  
  304.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305.         /// \brief Changes the distance between the title and the side of the title bar.
  306.         ///
  307.         /// \param distanceToSide  distance between the title and the side of the title bar
  308.         ///
  309.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  310.         virtual void setDistanceToSide(unsigned int distanceToSide);
  311.  
  312.  
  313.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  314.         /// \brief Returns the distance between the title and the side of the title bar.
  315.         ///
  316.         /// \return distance between the title and the side of the title bar
  317.         ///
  318.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  319.         virtual unsigned int getDistanceToSide() const;
  320.  
  321.  
  322.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  323.         /// \brief Changes the title alignment.
  324.         ///
  325.         /// \param alignment  How should the title be aligned in the title bar?
  326.         ///
  327.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  328.         virtual void setTitleAlignment(TitleAlignment alignment);
  329.  
  330.  
  331.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  332.         /// \brief Returns the title alignment.
  333.         ///
  334.         /// \return How the title is aligned in the title bar
  335.         ///
  336.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  337.         virtual TitleAlignment getTitleAlignment() const;
  338.  
  339.  
  340.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  341.         /// \brief Destroys the window.
  342.         ///
  343.         /// When no callback is requested when closing the window, this function will be called automatically.
  344.         ///
  345.         /// When you requested a callback then you get the opportunity to cancel the closure of the window.
  346.         /// If you want to keep it open then don't do anything, if you want to close it then just call this function.
  347.         ///
  348.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  349.         void destroy();
  350.  
  351.  
  352.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  353.         // Used internally to get the size of the child window.
  354.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  355.         virtual Vector2f getDisplaySize();
  356.  
  357.  
  358.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  359.         // Used to communicate with EventManager.
  360.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  361.         virtual bool mouseOnObject(float x, float y);
  362.  
  363.  
  364.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  365.       protected:
  366.  
  367.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  368.         // Send the event to all underlying objects.
  369.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  370.         virtual void handleEvent(sf::Event& event, float mouseX = 0, float mouseY = 0);
  371.  
  372.  
  373.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  374.         // Because this class is derived from sf::Drawable, you can just call the draw function from your sf::RenderTarget.
  375.         // This function will be called and it will draw the child window on the render target.
  376.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  377.         virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
  378.  
  379.  
  380.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  381.       public:
  382.  
  383.         enum ChildWindowCallbacks
  384.         {
  385.             Closed = ObjectCallbacksCount * 1,
  386.             Moved = ObjectCallbacksCount * 2,
  387. //            Resized = ObjectCallbacksCount * 4,
  388.             AllChildWindowCallbacks = ObjectCallbacksCount * 8 - 1,
  389.             ChildWindowCallbacksCount = ObjectCallbacksCount * 8
  390.         };
  391.  
  392.  
  393.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  394.       protected:
  395.  
  396.         Vector2f       m_Size;
  397.         sf::Color      m_BackgroundColor;
  398.         sf::Texture*   m_Texture;
  399.         sf::Sprite     m_Sprite;
  400.  
  401.         sf::String     m_Title;
  402.         sf::Color      m_TitleColor;
  403.         unsigned int   m_TitleBarHeight;
  404.         std::string    m_LoadedPathname;
  405.         bool           m_SplitImage;
  406.         Vector2f       m_DraggingPosition;
  407.         unsigned char  m_Opacity;
  408.         unsigned int   m_DistanceToSide;
  409.         TitleAlignment m_TitleAlignment;
  410.         sf::Color      m_BorderColor;
  411.  
  412.         sf::Texture*   m_TextureTitleBar_L;
  413.         sf::Texture*   m_TextureTitleBar_M;
  414.         sf::Texture*   m_TextureTitleBar_R;
  415.  
  416.         sf::Sprite     m_SpriteTitleBar_L;
  417.         sf::Sprite     m_SpriteTitleBar_M;
  418.         sf::Sprite     m_SpriteTitleBar_R;
  419.  
  420.         tgui::Button*  m_CloseButton;
  421.  
  422.         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  423.     };
  424.  
  425.     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  426. }
  427.  
  428. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  429.  
  430. #endif // TGUI_CHILD_WINDOW_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement