mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-19 14:53:56 -07:00
Avoids one or two dozen unoptimizable string copies and two CPos copies, mostly in SetupText. The reference return allows to mark values as const where the previous one prevented that. This also reveals unused variables where the previous code hid them. Thus use unused variable "buffer_zone" in the otherwise unused (sinceb1422137e5, refs0f807c643a) CCheckBox::SetupText() fromb5f6d19332and use the unused variable "scrollbar" in CInput GUIM_MOUSE_PRESS_LEFT from4113aa0a36. Refs unintentionally copied DrawCall cache due to GetSetting copying inc19f3608a5, fixed in8f4f8e240f. Differential Revision: https://code.wildfiregames.com/D2215 This was SVN commit r22765.
79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
/* Copyright (C) 2019 Wildfire Games.
|
|
* This file is part of 0 A.D.
|
|
*
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "precompiled.h"
|
|
|
|
#include "GUI.h"
|
|
#include "CProgressBar.h"
|
|
|
|
#include "lib/ogl.h"
|
|
|
|
CProgressBar::CProgressBar(CGUI& pGUI)
|
|
: IGUIObject(pGUI)
|
|
{
|
|
AddSetting<CGUISpriteInstance>("sprite_background");
|
|
AddSetting<CGUISpriteInstance>("sprite_bar");
|
|
AddSetting<float>("caption"); // aka value from 0 to 100
|
|
AddSetting<CStrW>("tooltip");
|
|
AddSetting<CStr>("tooltip_style");
|
|
}
|
|
|
|
CProgressBar::~CProgressBar()
|
|
{
|
|
}
|
|
|
|
void CProgressBar::HandleMessage(SGUIMessage& Message)
|
|
{
|
|
// Important
|
|
IGUIObject::HandleMessage(Message);
|
|
|
|
switch (Message.type)
|
|
{
|
|
case GUIM_SETTINGS_UPDATED:
|
|
// Update scroll-bar
|
|
// TODO Gee: (2004-09-01) Is this really updated each time it should?
|
|
if (Message.value == CStr("caption"))
|
|
{
|
|
const float value = GUI<float>::GetSetting(this, "caption");
|
|
if (value > 100.f)
|
|
GUI<float>::SetSetting(this, "caption", 100.f);
|
|
else if (value < 0.f)
|
|
GUI<float>::SetSetting(this, "caption", 0.f);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void CProgressBar::Draw()
|
|
{
|
|
CGUISpriteInstance& sprite_bar = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_bar");
|
|
CGUISpriteInstance& sprite_background = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_background");
|
|
|
|
float bz = GetBufferedZ();
|
|
|
|
int cell_id = 0;
|
|
const float value = GUI<float>::GetSetting(this, "caption");
|
|
|
|
m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize);
|
|
|
|
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
|
|
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
|
|
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
|
|
m_pGUI.DrawSprite(sprite_bar, cell_id, bz+0.01f, bar_size);
|
|
}
|