LCOV - code coverage report
Current view: top level - source/gui/ObjectTypes - CList.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 3 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_CLIST
      19             : #define INCLUDED_CLIST
      20             : 
      21             : #include "gui/CGUISprite.h"
      22             : #include "gui/ObjectBases/IGUIObject.h"
      23             : #include "gui/ObjectBases/IGUIScrollBarOwner.h"
      24             : #include "gui/ObjectBases/IGUITextOwner.h"
      25             : #include "gui/SettingTypes/CGUIList.h"
      26             : 
      27             : #include <vector>
      28             : 
      29             : /**
      30             :  * Create a list of elements, where one can be selected
      31             :  * by the user. The control will use a pre-processed
      32             :  * text-object for each element, which will be managed
      33             :  * by the IGUITextOwner structure.
      34             :  *
      35             :  * A scroll-bar will appear when needed. This will be
      36             :  * achieved with the IGUIScrollBarOwner structure.
      37             :  */
      38             : class CList : public IGUIObject, public IGUIScrollBarOwner, public IGUITextOwner
      39             : {
      40           0 :     GUI_OBJECT(CList)
      41             : public:
      42             :     CList(CGUI& pGUI);
      43             :     virtual ~CList();
      44             : 
      45             :     /**
      46             :      * @see IGUIObject#ResetStates()
      47             :      */
      48             :     virtual void ResetStates();
      49             : 
      50             :     /**
      51             :      * @see IGUIObject#UpdateCachedSize()
      52             :      */
      53             :     virtual void UpdateCachedSize();
      54             : 
      55             :     /**
      56             :      * Adds an item last to the list.
      57             :      */
      58             :     virtual void AddItem(const CGUIString& str, const CGUIString& data);
      59             : 
      60             :     /**
      61             :      * Add an item where both parameters are identical.
      62             :      */
      63             :     void AddItem(const CGUIString& strAndData);
      64             : 
      65             : protected:
      66             :     /**
      67             :      * Sets up text, should be called every time changes has been
      68             :      * made that can change the visual.
      69             :      * @param append - if true, we assume we only need to render the new element at the end of the list.
      70             :      */
      71             :     virtual void SetupText();
      72             :     virtual void SetupText(bool append);
      73             : 
      74             :     /**
      75             :      * @see IGUIObject#HandleMessage()
      76             :      */
      77             :     virtual void HandleMessage(SGUIMessage& Message);
      78             : 
      79             :     /**
      80             :      * Handle events manually to catch keyboard inputting.
      81             :      */
      82             :     virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev);
      83             : 
      84             :     /**
      85             :      * Draws the List box
      86             :      */
      87             :     virtual void Draw(CCanvas2D& canvas);
      88             : 
      89             :     virtual void CreateJSObject();
      90             : 
      91             :     /**
      92             :      * Easy select elements functions
      93             :      */
      94             :     virtual void SelectNextElement();
      95             :     virtual void SelectPrevElement();
      96             :     virtual void SelectFirstElement();
      97             :     virtual void SelectLastElement();
      98             : 
      99             :     /**
     100             :      * Handle the \<item\> tag.
     101             :      */
     102             :     virtual bool HandleAdditionalChildren(const XMBData& xmb, const XMBElement& child);
     103             : 
     104             :     // Called every time the auto-scrolling should be checked.
     105             :     void UpdateAutoScroll();
     106             : 
     107             :     // Extended drawing interface, this is so that classes built on the this one
     108             :     //  can use other sprite names.
     109             :     virtual void DrawList(CCanvas2D& canvas, const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& spriteOverlay,
     110             :                           const CGUISpriteInstance& spriteSelectArea, const CGUISpriteInstance& spriteSelectAreaOverlay, const CGUIColor& textColor);
     111             : 
     112             :     // Get the area of the list. This is so that it can easily be changed, like in CDropDown
     113             :     //  where the area is not equal to m_CachedActualSize.
     114           0 :     virtual CRect GetListRect() const { return m_CachedActualSize; }
     115             : 
     116             :     // Returns whether SetupText() has run since the last message was received
     117             :     // (and thus whether list items have possibly changed).
     118           0 :     virtual bool GetModified() const { return m_Modified; }
     119             : 
     120             :     /**
     121             :      * List of each element's relative y position. Will be
     122             :      * one larger than m_Items, because it will end with the
     123             :      * bottom of the last element. First element will always
     124             :      * be zero, but still stored for easy handling.
     125             :      */
     126             :     std::vector<float> m_ItemsYPositions;
     127             : 
     128             :     virtual int GetHoveredItem();
     129             : 
     130             :     CGUISimpleSetting<float> m_BufferZone;
     131             :     CGUISimpleSetting<CStrW> m_Font;
     132             :     CGUISimpleSetting<bool> m_ScrollBar;
     133             :     CGUISimpleSetting<CStr> m_ScrollBarStyle;
     134             :     CGUISimpleSetting<bool> m_ScrollBottom;
     135             :     CGUISimpleSetting<CStrW> m_SoundDisabled;
     136             :     CGUISimpleSetting<CStrW> m_SoundSelected;
     137             :     CGUISimpleSetting<CGUISpriteInstance> m_Sprite;
     138             :     CGUISimpleSetting<CGUISpriteInstance> m_SpriteOverlay;
     139             :     CGUISimpleSetting<CGUISpriteInstance> m_SpriteSelectArea;
     140             :     CGUISimpleSetting<CGUISpriteInstance> m_SpriteSelectAreaOverlay;
     141             :     CGUISimpleSetting<CGUIColor> m_TextColor;
     142             :     CGUISimpleSetting<CGUIColor> m_TextColorSelected;
     143             :     CGUISimpleSetting<i32> m_Selected;
     144             :     CGUISimpleSetting<bool> m_AutoScroll;
     145             :     CGUISimpleSetting<i32> m_Hovered;
     146             :     CGUISimpleSetting<CGUIList> m_List;
     147             :     CGUISimpleSetting<CGUIList> m_ListData;
     148             : 
     149             : private:
     150             :     static const CStr EventNameSelectionChange;
     151             :     static const CStr EventNameHoverChange;
     152             :     static const CStr EventNameMouseLeftClickItem;
     153             :     static const CStr EventNameMouseLeftDoubleClickItem;
     154             : 
     155             :     // Whether the list's items have been modified since last handling a message.
     156             :     bool m_Modified;
     157             : 
     158             :     // Used for doubleclick registration
     159             :     int m_PrevSelectedItem;
     160             : 
     161             :     // Last time a click on an item was issued
     162             :     double m_LastItemClickTime;
     163             : };
     164             : 
     165             : #endif // INCLUDED_CLIST

Generated by: LCOV version 1.13