Crazy Eddie's GUI System  0.8.4
TreeItem.h
00001 /***********************************************************************
00002     created:   5-13-07
00003     author:    Jonathan Welch (Based on Code by David Durant)
00004  *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUITreeItem_h_
00028 #define _CEGUITreeItem_h_
00029 
00030 #include "../Base.h"
00031 #include "../String.h"
00032 #include "../ColourRect.h"
00033 #include "../BasicRenderedStringParser.h"
00034 
00035 #if defined(_MSC_VER)
00036 #   pragma warning(push)
00037 #   pragma warning(disable : 4251)
00038 #endif
00039 
00040 // Start of CEGUI namespace section
00041 namespace CEGUI
00042 {
00057 class CEGUIEXPORT TreeItem : public
00058     AllocatedObject<TreeItem>
00059 {
00060 public:
00061     typedef std::vector<TreeItem*
00062         CEGUI_VECTOR_ALLOC(TreeItem*)>  LBItemList;
00063 
00064     /*************************************************************************
00065         Constants
00066      *************************************************************************/
00068     static const Colour DefaultTextColour;
00070     static const Colour DefaultSelectionColour;
00071 
00072     /*************************************************************************
00073         Construction and Destruction
00074      *************************************************************************/
00079     TreeItem(const String& text, uint item_id = 0, void* item_data = 0,
00080              bool disabled = false, bool auto_delete = true);
00081 
00086     virtual ~TreeItem(void);
00087 
00088     /*************************************************************************
00089         Accessors
00090      *************************************************************************/
00101     const Font* getFont(void) const;
00102 
00110     ColourRect getTextColours(void) const
00111     { return d_textCols; }
00112 
00113     /*************************************************************************
00114         Manipulator methods
00115      *************************************************************************/
00126     void setFont(const Font* font);
00127 
00139     void setFont(const String& font_name);
00140 
00151     void setTextColours(const ColourRect& cols)
00152     { d_textCols = cols; d_renderedStringValid = false; }
00153 
00177     void setTextColours(Colour top_left_colour, Colour top_right_colour,
00178                         Colour bottom_left_colour, Colour bottom_right_colour);
00179 
00190     void setTextColours(Colour col)
00191     { setTextColours(col, col, col, col); }
00192 
00203     const String& getText() const {return d_textLogical;}
00204 
00206     const String& getTextVisual() const;
00207 
00216     const String& getTooltipText(void) const
00217     { return d_tooltipText; }
00218 
00229     uint getID(void) const
00230     { return d_itemID; }
00231 
00243     void* getUserData(void) const
00244     { return d_itemData; }
00245 
00254     bool isSelected(void) const
00255     { return d_selected; }
00256 
00265     bool isDisabled(void) const
00266     { return d_disabled; }
00267 
00281     bool isAutoDeleted(void) const
00282     { return d_autoDelete; }
00283 
00294     const Window* getOwnerWindow(void)
00295     { return d_owner; }
00296 
00304     ColourRect getSelectionColours(void) const
00305     { return d_selectCols; }
00306 
00307 
00315     const Image* getSelectionBrushImage(void) const
00316     { return d_selectBrush; }
00317 
00318 
00319     /*************************************************************************
00320         Manipulators
00321      *************************************************************************/
00335     void setText(const String& text);
00336 
00348     void setTooltipText(const String& text)
00349     { d_tooltipText = text; }
00350 
00364     void setID(uint item_id)
00365     { d_itemID = item_id; }
00366 
00380     void setUserData(void* item_data)
00381     { d_itemData = item_data; }
00382 
00394     void setSelected(bool setting)
00395     { d_selected = setting; }
00396 
00408     void setDisabled(bool setting)
00409     { d_disabled = setting; }
00410 
00426     void setAutoDeleted(bool setting)
00427     { d_autoDelete = setting; }
00428 
00441     void setOwnerWindow(const Window* owner)
00442     { d_owner = owner; }
00443 
00454     void setSelectionColours(const ColourRect& cols)
00455     { d_selectCols = cols; }
00456 
00457 
00481     void setSelectionColours(Colour top_left_colour,
00482                              Colour top_right_colour,
00483                              Colour bottom_left_colour,
00484                              Colour bottom_right_colour);
00485 
00496     void setSelectionColours(Colour col)
00497     { setSelectionColours(col, col, col, col); }
00498 
00499 
00510     void setSelectionBrushImage(const Image* image)
00511     { d_selectBrush = image; }
00512 
00513 
00524     void setSelectionBrushImage(const String& name);
00525 
00534     void setButtonLocation(Rectf& buttonOffset)
00535     { d_buttonLocation = buttonOffset; }
00536 
00537     Rectf& getButtonLocation(void)
00538     { return d_buttonLocation; }
00539 
00540     bool getIsOpen(void)
00541     { return d_isOpen; }
00542 
00543     void toggleIsOpen(void)
00544     { d_isOpen = !d_isOpen; }
00545 
00546     TreeItem *getTreeItemFromIndex(size_t itemIndex);
00547 
00548     size_t getItemCount(void) const
00549     { return d_listItems.size(); }
00550 
00551     LBItemList &getItemList(void)
00552     { return d_listItems; }
00553 
00554     void addItem(TreeItem* item);
00555     void removeItem(const TreeItem* item);
00556 
00557     void setIcon(const Image &theIcon)
00558     { d_iconImage = &theIcon; }
00559 
00560     /*************************************************************************
00561         Abstract portion of interface
00562      *************************************************************************/
00570     virtual Sizef getPixelSize(void) const;
00571 
00589     virtual void draw(GeometryBuffer& buffer, const Rectf& targetRect,
00590                       float alpha, const Rectf* clipper) const;
00591 
00604     virtual bool handleFontRenderSizeChange(const Font* const font);
00605 
00606     /*************************************************************************
00607         Operators
00608      *************************************************************************/
00613     virtual bool operator<(const TreeItem& rhs) const
00614     { return getText() < rhs.getText(); }
00615 
00620     virtual bool operator>(const TreeItem& rhs) const
00621     { return getText() > rhs.getText(); }
00622 
00623 protected:
00624     /*************************************************************************
00625         Implementation methods
00626      *************************************************************************/
00632     ColourRect getModulateAlphaColourRect(const ColourRect& cols,
00633                                           float alpha) const;
00634 
00640     Colour calculateModulatedAlphaColour(Colour col, float alpha) const;
00641 
00643     void parseTextString() const;
00644 
00645     /*************************************************************************
00646         Implementation Data
00647      *************************************************************************/
00649     String               d_textLogical;            
00650 
00651     BidiVisualMapping* d_bidiVisualMapping;
00653     mutable bool d_bidiDataValid;
00655     String d_tooltipText;
00657     uint d_itemID;
00659     void* d_itemData;
00661     bool d_selected;
00663     bool d_disabled;
00665     bool d_autoDelete;
00667     Rectf d_buttonLocation;
00669     const Window* d_owner;
00671     ColourRect d_selectCols;
00673     const Image* d_selectBrush;
00675     ColourRect d_textCols;
00677     const Font* d_font;
00679     const Image* d_iconImage;
00681     LBItemList d_listItems;
00683     bool d_isOpen;
00685     static BasicRenderedStringParser d_stringParser;
00687     mutable RenderedString  d_renderedString;
00689     mutable bool d_renderedStringValid;
00690 };
00691 
00692 } // End of  CEGUI namespace section
00693 
00694 #if defined(_MSC_VER)
00695 #   pragma warning(pop)
00696 #endif
00697 
00698 #endif   // end of guard _CEGUITreeItem_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends