LCOV - code coverage report
Current view: top level - source/gui/ObjectTypes - CProgressBar.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 21 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 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             : #include "precompiled.h"
      19             : 
      20             : #include "CProgressBar.h"
      21             : 
      22             : #include "gui/CGUI.h"
      23             : #include "gui/SGUIMessage.h"
      24             : #include "maths/Rect.h"
      25             : #include "ps/CStr.h"
      26             : 
      27             : #include <string>
      28             : 
      29           0 : CProgressBar::CProgressBar(CGUI& pGUI)
      30             :     : IGUIObject(pGUI),
      31           0 :       m_SpriteBackground(this, "sprite_background"),
      32           0 :       m_SpriteBar(this, "sprite_bar"),
      33           0 :       m_Progress(this, "progress") // Between 0 and 100.
      34             : {
      35           0 : }
      36             : 
      37           0 : void CProgressBar::HandleMessage(SGUIMessage& Message)
      38             : {
      39           0 :     IGUIObject::HandleMessage(Message);
      40             : 
      41           0 :     switch (Message.type)
      42             :     {
      43           0 :     case GUIM_SETTINGS_UPDATED:
      44           0 :         if (Message.value == "progress")
      45             :         {
      46           0 :             if (m_Progress > 100.f)
      47           0 :                 m_Progress.Set(100.f, true);
      48           0 :             else if (m_Progress < 0.f)
      49           0 :                 m_Progress.Set(0.f, true);
      50             :         }
      51             :         break;
      52             :     default:
      53             :         break;
      54             :     }
      55           0 : }
      56             : 
      57           0 : void CProgressBar::Draw(CCanvas2D& canvas)
      58             : {
      59           0 :     m_pGUI.DrawSprite(m_SpriteBackground, canvas, GetActualSize(), m_VisibleArea);
      60             : 
      61             :     // Get size of bar (notice it is drawn slightly closer, to appear above the background)
      62           0 :     CRect size = GetActualSize();
      63           0 :     size.right = size.left + GetActualSize().GetWidth() * (m_Progress / 100.f),
      64           0 :     m_pGUI.DrawSprite(m_SpriteBar, canvas, size, m_VisibleArea);
      65           0 : }

Generated by: LCOV version 1.16