home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / elements / CEGUIStaticText.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-08-05  |  13.3 KB  |  412 lines

  1. /************************************************************************
  2.     filename:     CEGUIStaticText.h
  3.     created:    4/6/2004
  4.     author:        Paul D Turner
  5.     
  6.     purpose:    Defines interface for a static text widget
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. #ifndef _CEGUIStaticText_h_
  27. #define _CEGUIStaticText_h_
  28.  
  29. #include "elements/CEGUIStatic.h"
  30. #include "elements/CEGUIStaticTextProperties.h"
  31.  
  32.  
  33. #if defined(_MSC_VER)
  34. #    pragma warning(push)
  35. #    pragma warning(disable : 4251)
  36. #endif
  37.  
  38.  
  39. // Start of CEGUI namespace section
  40. namespace CEGUI
  41. {
  42. /*!
  43. \brief
  44.     Base class for a static text widget.
  45. */
  46. class CEGUIEXPORT StaticText : public Static
  47. {
  48. public:
  49.     static const String EventNamespace;                //!< Namespace for global events
  50.  
  51.  
  52.     /*************************************************************************
  53.         Formatting Enumerations
  54.     *************************************************************************/
  55.     /*!
  56.     \brief
  57.         Enumeration of horizontal formatting options for static text widgets
  58.     */
  59.     enum HorzFormatting
  60.     {
  61.         LeftAligned,            //!< Text is output as a single line of text with the first character aligned with the left edge of the widget.
  62.         RightAligned,            //!< Text is output as a single line of text with the last character aligned with the right edge of the widget.
  63.         HorzCentred,            //!< Text is output as a single line of text horizontally centred within the widget.
  64.         HorzJustified,            //!< Text is output as a single line of text with the first and last characters aligned with the edges of the widget.
  65.         WordWrapLeftAligned,    //!< Text is output as multiple word-wrapped lines of text with the first character of each line aligned with the left edge of the widget.
  66.         WordWrapRightAligned,    //!< Text is output as multiple word-wrapped lines of text with the last character of each line aligned with the right edge of the widget.
  67.         WordWrapCentred,        //!< Text is output as multiple word-wrapped lines of text with each line horizontally centered within the widget.
  68.         WordWrapJustified        //!< Text is output as multiple word-wrapped lines of text with the first and last characters of each line aligned with the edges of the widget.
  69.     };
  70.  
  71.  
  72.     /*!
  73.     \brief
  74.         Enumeration of vertical formatting options for a static text widgets
  75.     */
  76.     enum VertFormatting
  77.     {
  78.         TopAligned,        //!< Text is output with the top of first line of text aligned with the top edge of the widget.
  79.         BottomAligned,    //!< Text is output with the bottom of last line of text aligned with the bottom edge of the widget.
  80.         VertCentred     //!< Text is output vertically centred within the widget.
  81.     };
  82.  
  83.  
  84.     /*************************************************************************
  85.         Construction and Destruction
  86.     *************************************************************************/
  87.     /*!
  88.     \brief
  89.         Constructor for static text widgets.
  90.     */
  91.     StaticText(const String& type, const String& name);
  92.  
  93.  
  94.     /*!
  95.     \brief
  96.         Destructor for static text widgets.
  97.     */
  98.     virtual ~StaticText(void);
  99.  
  100.  
  101.     /*************************************************************************
  102.         Accessors
  103.     *************************************************************************/
  104.     /*!
  105.     \brief
  106.         Return a ColourRect object containing the colours used when rendering this widget.
  107.  
  108.     \return
  109.         ColourRect object initialised with the colours used when rendering the text for this widget.
  110.     */
  111.     ColourRect    getTextColours(void) const        {return d_textCols;}
  112.  
  113.     
  114.     /*!
  115.     \brief
  116.         Return the current horizontal formatting option set for this widget.
  117.  
  118.     \return
  119.         One of the StaticText::HorzFormatting enumerated values specifying the horizontal formatting currently set.
  120.     */
  121.     HorzFormatting    getHorizontalFormatting(void) const        {return    d_horzFormatting;}
  122.  
  123.  
  124.     /*!
  125.     \brief
  126.         Return the current vertical formatting option set for this widget.
  127.  
  128.     \return
  129.         One of the StaticText::VertFormatting enumerated values specifying the vertical formatting currently set.
  130.     */
  131.     VertFormatting    getVerticalFormatting(void) const        {return    d_vertFormatting;}
  132.  
  133.  
  134.     /*!
  135.     \brief
  136.         Return whether the vertical scroll bar is set to be shown if needed.
  137.  
  138.     \return
  139.         - true if the vertical scroll bar will be shown if needed (top or bottom aligned formatting only).
  140.         - false if the vertical scroll bar will never be shown (default behaviour).
  141.     */
  142.     bool    isVerticalScrollbarEnabled(void) const;
  143.  
  144.  
  145.     /*!
  146.     \brief
  147.         Return whether the horizontal scroll bar is set to be shown if needed.
  148.  
  149.     \return
  150.         - true if the horizontal scroll bar will be shown if needed (non-word wrapped, left or right aligned formatting only).
  151.         - false if the horizontal scroll bar will never be shown (default behaviour).
  152.     */
  153.     bool    isHorizontalScrollbarEnabled(void) const;
  154.  
  155.  
  156.     // overridden (again) so scroll bars are not clipped when they are active
  157.     virtual Rect    getUnclippedInnerRect(void) const;
  158.  
  159.  
  160.     /*************************************************************************
  161.         Manipulators
  162.     *************************************************************************/
  163.     /*!
  164.     \brief
  165.         Initialise the Window based object ready for use.
  166.  
  167.     \note
  168.         This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
  169.  
  170.     \return
  171.         Nothing
  172.     */
  173.     virtual void    initialise(void);
  174.  
  175.  
  176.     /*!
  177.     \brief
  178.         Sets the colours to be applied when rendering the text.
  179.  
  180.     \param colours
  181.         ColourRect object describing the colours to be used for each text glyph rendered.
  182.  
  183.     \return 
  184.         Nothing.
  185.     */
  186.     void    setTextColours(const ColourRect& colours);
  187.  
  188.  
  189.     /*!
  190.     \brief
  191.         Sets the colours to be applied when rendering the text.
  192.  
  193.     \param top_left_colour
  194.         Colour to be applied to the top-left corner of each text glyph rendered.
  195.  
  196.     \param top_right_colour
  197.         Colour to be applied to the top-right corner of each text glyph rendered.
  198.  
  199.     \param bottom_left_colour
  200.         Colour to be applied to the bottom-left corner of each text glyph rendered.
  201.  
  202.     \param bottom_right_colour
  203.         Colour to be applied to the bottom-right corner of each text glyph rendered.
  204.  
  205.     \return 
  206.         Nothing.
  207.     */
  208.     void    setTextColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour);
  209.  
  210.  
  211.     /*!
  212.     \brief
  213.         Sets the colour to be applied when rendering the text.
  214.  
  215.     \param col
  216.         colour value to be used when rendering.
  217.  
  218.     \return
  219.         Nothing.
  220.     */
  221.     void    setTextColours(const colour& col)        {setTextColours(col, col, col, col);}
  222.  
  223.  
  224.     /*!
  225.     \brief
  226.         Set the formatting required for the text.
  227.  
  228.     \param h_fmt
  229.         One of the HorzFormatting enumerated values specifying the formatting required.
  230.  
  231.     \param v_fmt
  232.         One of the VertFormatting enumerated values specifying the formatting required.
  233.  
  234.     \return
  235.         Nothing
  236.     */
  237.     void    setFormatting(HorzFormatting h_fmt, VertFormatting v_fmt);
  238.  
  239.  
  240.     /*!
  241.     \brief
  242.         Set the formatting required for the text.
  243.  
  244.     \param v_fmt
  245.         One of the VertFormatting enumerated values specifying the formatting required.
  246.  
  247.     \return
  248.         Nothing
  249.     */
  250.     void    setVerticalFormatting(VertFormatting v_fmt);
  251.  
  252.  
  253.     /*!
  254.     \brief
  255.         Set the formatting required for the text.
  256.  
  257.     \param h_fmt
  258.         One of the HorzFormatting enumerated values specifying the formatting required.
  259.  
  260.     \return
  261.         Nothing
  262.     */
  263.     void    setHorizontalFormatting(HorzFormatting h_fmt);
  264.  
  265.  
  266.     /*!
  267.     \brief
  268.         Set whether the vertical scroll bar will be shown if needed.
  269.  
  270.     \param setting
  271.         - true if the vertical scroll bar should be shown if needed (top or bottom aligned formatting only).
  272.         - false if the vertical scroll bar should never be shown (default behaviour).
  273.     */
  274.     void    setVerticalScrollbarEnabled(bool setting);
  275.  
  276.  
  277.     /*!
  278.     \brief
  279.         Set whether the horizontal scroll bar will be shown if needed.
  280.  
  281.     \param setting
  282.         - true if the horizontal scroll bar should be shown if needed (non-word wrapped, left or right aligned formatting only).
  283.         - false if the horizontal scroll bar should never be shown (default behaviour).
  284.     */
  285.     void    setHorizontalScrollbarEnabled(bool setting);
  286.  
  287.  
  288. protected:
  289.     /*************************************************************************
  290.         Overridden from base class
  291.     *************************************************************************/
  292.     virtual void populateRenderCache();
  293.  
  294.  
  295.     /*************************************************************************
  296.         Overridden events
  297.     *************************************************************************/
  298.     virtual void    onTextChanged(WindowEventArgs& e);
  299.     virtual void    onSized(WindowEventArgs& e);
  300.     virtual    void    onFontChanged(WindowEventArgs& e);
  301.     virtual void    onMouseWheel(MouseEventArgs& e);
  302.  
  303.  
  304.     /*************************************************************************
  305.         Implementation methods
  306.     *************************************************************************/
  307.     /*!
  308.     \brief
  309.         Return a Rect object describing, in un-clipped pixels, the window relative area
  310.         that the text should be rendered in to.
  311.  
  312.     \return
  313.         Rect object describing the area of the Window to be used for rendering text.
  314.     */
  315.     virtual    Rect    getTextRenderArea(void) const;
  316.  
  317.  
  318.     /*!
  319.     \brief
  320.         display required integrated scroll bars according to current state of the edit box and update their values.
  321.     */
  322.     void    configureScrollbars(void);
  323.  
  324.  
  325.     /*!
  326.     \brief
  327.         Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
  328.  
  329.     \param class_name
  330.         The class name that is to be checked.
  331.  
  332.     \return
  333.         true if this window was inherited from \a class_name. false if not.
  334.     */
  335.     virtual bool    testClassName_impl(const String& class_name) const
  336.     {
  337.         if (class_name==(const utf8*)"StaticText")    return true;
  338.         return Static::testClassName_impl(class_name);
  339.     }
  340.  
  341.  
  342.     /*************************************************************************
  343.         Implementation Methods (abstract)
  344.     *************************************************************************/
  345.     /*!
  346.     \brief
  347.         create and return a pointer to a Scrollbar widget for use as vertical scroll bar
  348.  
  349.     \param name
  350.        String containing the name to be given to the created component.
  351.  
  352.     \return
  353.         Pointer to a Scrollbar to be used for scrolling vertically.
  354.     */
  355.     virtual Scrollbar*    createVertScrollbar(const String& name) const        = 0;
  356.  
  357.  
  358.     /*!
  359.     \brief
  360.         create and return a pointer to a Scrollbar widget for use as horizontal scroll bar
  361.  
  362.     \param name
  363.        String containing the name to be given to the created component.
  364.  
  365.     \return
  366.         Pointer to a Scrollbar to be used for scrolling horizontally.
  367.     */
  368.     virtual Scrollbar*    createHorzScrollbar(const String& name) const        = 0;
  369.  
  370.  
  371.     /*************************************************************************
  372.         Event subscribers
  373.     *************************************************************************/
  374.     bool    handleScrollbarChange(const EventArgs& e);
  375.  
  376.  
  377.     /*************************************************************************
  378.         Implementation Data
  379.     *************************************************************************/
  380.     HorzFormatting    d_horzFormatting;        //!< Horizontal formatting to be applied to the text.
  381.     VertFormatting    d_vertFormatting;        //!< Vertical formatting to be applied to the text.
  382.     ColourRect        d_textCols;                //!< Colours used when rendering the text.
  383.     Scrollbar*        d_vertScrollbar;        //!< Widget used as vertical scrollbar;
  384.     Scrollbar*        d_horzScrollbar;        //!< Widget used as horizontal scrollbar;
  385.     bool            d_enableVertScrollbar;    //!< true if vertical scroll bar is enabled.
  386.     bool            d_enableHorzScrollbar;    //!< true if horizontal scroll bar is enabled.
  387.  
  388. private:
  389.     /*************************************************************************
  390.         Static Properties for this class
  391.     *************************************************************************/
  392.     static StaticTextProperties::TextColours    d_textColoursProperty;
  393.     static StaticTextProperties::VertFormatting    d_vertFormattingProperty;
  394.     static StaticTextProperties::HorzFormatting    d_horzFormattingProperty;
  395.     static StaticTextProperties::VertScrollbar    d_vertScrollbarProperty;
  396.     static StaticTextProperties::HorzScrollbar    d_horzScrollbarProperty;
  397.  
  398.  
  399.     /*************************************************************************
  400.         Private methods
  401.     *************************************************************************/
  402.     void    addStaticTextProperties(void);
  403. };
  404.  
  405. } // End of  CEGUI namespace section
  406.  
  407. #if defined(_MSC_VER)
  408. #    pragma warning(pop)
  409. #endif
  410.  
  411. #endif    // end of guard _CEGUIStaticText_h_
  412.