2019-07-26 11:57:28 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-03 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
#include "GUI.h"
|
|
|
|
|
|
2019-08-21 03:12:33 -07:00
|
|
|
IGUIButtonBehavior::IGUIButtonBehavior(CGUI& pGUI)
|
2019-08-01 16:55:10 -07:00
|
|
|
: IGUIObject(pGUI), m_Pressed(false)
|
2003-11-23 18:18:41 -08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IGUIButtonBehavior::~IGUIButtonBehavior()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
|
2003-11-23 18:18:41 -08:00
|
|
|
{
|
2019-08-26 05:25:07 -07:00
|
|
|
const bool enabled = GetSetting<bool>("enabled");
|
2019-08-23 07:43:10 -07:00
|
|
|
|
2013-12-29 12:46:02 -08:00
|
|
|
CStrW soundPath;
|
2004-05-28 21:06:50 -07:00
|
|
|
// TODO Gee: easier access functions
|
2003-12-26 22:26:03 -08:00
|
|
|
switch (Message.type)
|
2003-11-23 18:18:41 -08:00
|
|
|
{
|
2013-06-30 21:15:09 -07:00
|
|
|
case GUIM_MOUSE_ENTER:
|
2019-08-22 15:34:12 -07:00
|
|
|
if (enabled)
|
|
|
|
|
PlaySound("sound_enter");
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2013-06-30 21:15:09 -07:00
|
|
|
|
|
|
|
|
case GUIM_MOUSE_LEAVE:
|
2019-08-22 15:34:12 -07:00
|
|
|
if (enabled)
|
|
|
|
|
PlaySound("sound_leave");
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2013-06-30 21:15:09 -07:00
|
|
|
|
2013-12-29 11:31:48 -08:00
|
|
|
case GUIM_MOUSE_DBLCLICK_LEFT:
|
2013-12-31 22:05:41 -08:00
|
|
|
if (!enabled)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Since GUIM_MOUSE_PRESS_LEFT also gets called twice in a
|
|
|
|
|
// doubleclick event, we let it handle playing sounds.
|
|
|
|
|
SendEvent(GUIM_DOUBLE_PRESSED, "doublepress");
|
|
|
|
|
break;
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
case GUIM_MOUSE_PRESS_LEFT:
|
2004-05-28 21:06:50 -07:00
|
|
|
if (!enabled)
|
2013-06-30 21:15:09 -07:00
|
|
|
{
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_disabled");
|
2003-12-26 22:26:03 -08:00
|
|
|
break;
|
2013-06-30 21:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_pressed");
|
2013-12-29 11:31:48 -08:00
|
|
|
SendEvent(GUIM_PRESSED, "press");
|
2003-11-23 18:18:41 -08:00
|
|
|
m_Pressed = true;
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2013-01-03 14:53:46 -08:00
|
|
|
|
|
|
|
|
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
2013-12-31 22:05:41 -08:00
|
|
|
if (!enabled)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Since GUIM_MOUSE_PRESS_RIGHT also gets called twice in a
|
|
|
|
|
// doubleclick event, we let it handle playing sounds.
|
|
|
|
|
SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright");
|
|
|
|
|
break;
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2013-12-29 11:31:48 -08:00
|
|
|
case GUIM_MOUSE_PRESS_RIGHT:
|
2013-01-03 14:53:46 -08:00
|
|
|
if (!enabled)
|
|
|
|
|
{
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_disabled");
|
2013-12-29 11:31:48 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 22:05:41 -08:00
|
|
|
// Button was right-clicked
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_pressed");
|
2013-12-29 11:31:48 -08:00
|
|
|
SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
|
|
|
|
|
m_PressedRight = true;
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2013-01-03 14:53:46 -08:00
|
|
|
|
2013-12-29 11:31:48 -08:00
|
|
|
case GUIM_MOUSE_RELEASE_RIGHT:
|
2013-01-03 14:53:46 -08:00
|
|
|
if (!enabled)
|
2013-12-29 11:31:48 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (m_PressedRight)
|
2013-06-30 21:15:09 -07:00
|
|
|
{
|
2013-12-29 11:31:48 -08:00
|
|
|
m_PressedRight = false;
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_released");
|
2013-06-30 21:15:09 -07:00
|
|
|
}
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
|
|
|
case GUIM_MOUSE_RELEASE_LEFT:
|
2004-05-28 21:06:50 -07:00
|
|
|
if (!enabled)
|
2003-12-26 22:26:03 -08:00
|
|
|
break;
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
if (m_Pressed)
|
|
|
|
|
{
|
|
|
|
|
m_Pressed = false;
|
2019-08-22 15:34:12 -07:00
|
|
|
PlaySound("sound_released");
|
2003-11-23 18:18:41 -08:00
|
|
|
}
|
2013-12-31 22:05:41 -08:00
|
|
|
break;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-05-28 21:06:50 -07:00
|
|
|
|
Stop copying color every draw call for every GUI object using colors.
Avoid color copies for rendering Draw calls in
GUIRenderer::UpdateDrawCallCache, CButton::Draw, CChart::DrawAxes,
CDropDown::Draw, CList::DrawList, COList::DrawList, refs #1984,
8f4f8e240f, 3028551b91, a905fbbc98.
Avoid color copies during XML loading in CGUI::Xeromyces_ReadImage,
CGUI::Xeromyces_ReadEffects, COList::HandleAdditionalChildren.
Add CGUI::HasPreDefinedColor and mark m_PreDefinedColors,
CGUI::GetPreDefinedColor, IGUIButtonBehavior::ChooseColor() as const for
consistency with the other "databases", refs 3028551b91.
Mark CGUIColor as NONCOPYABLE to add compiler errors if there is an
unexplicit copy, refs 3028551b91.
Explicit ugly copy in CGUI::Xeromyces_ReadColor and
CGUIColor::ParseString.
Deregister copying <CGUIColor>GetSetting functions, refs 8f4f8e240f.
Uses the const ref GetSetting from 3dfa23cd25.
This was SVN commit r22694.
2019-08-19 05:53:58 -07:00
|
|
|
const CGUIColor& IGUIButtonBehavior::ChooseColor()
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
|
|
|
|
// Yes, the object must possess these settings. They are standard
|
2019-08-26 05:25:07 -07:00
|
|
|
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2019-08-26 05:25:07 -07:00
|
|
|
if (!GetSetting<bool>("enabled"))
|
|
|
|
|
return GetSetting<CGUIColor>("textcolor_disabled") || color;
|
Stop copying color every draw call for every GUI object using colors.
Avoid color copies for rendering Draw calls in
GUIRenderer::UpdateDrawCallCache, CButton::Draw, CChart::DrawAxes,
CDropDown::Draw, CList::DrawList, COList::DrawList, refs #1984,
8f4f8e240f, 3028551b91, a905fbbc98.
Avoid color copies during XML loading in CGUI::Xeromyces_ReadImage,
CGUI::Xeromyces_ReadEffects, COList::HandleAdditionalChildren.
Add CGUI::HasPreDefinedColor and mark m_PreDefinedColors,
CGUI::GetPreDefinedColor, IGUIButtonBehavior::ChooseColor() as const for
consistency with the other "databases", refs 3028551b91.
Mark CGUIColor as NONCOPYABLE to add compiler errors if there is an
unexplicit copy, refs 3028551b91.
Explicit ugly copy in CGUI::Xeromyces_ReadColor and
CGUIColor::ParseString.
Deregister copying <CGUIColor>GetSetting functions, refs 8f4f8e240f.
Uses the const ref GetSetting from 3dfa23cd25.
This was SVN commit r22694.
2019-08-19 05:53:58 -07:00
|
|
|
|
|
|
|
|
if (m_MouseHovering)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
|
|
|
|
if (m_Pressed)
|
2019-08-26 05:25:07 -07:00
|
|
|
return GetSetting<CGUIColor>("textcolor_pressed") || color;
|
2004-05-28 21:06:50 -07:00
|
|
|
else
|
2019-08-26 05:25:07 -07:00
|
|
|
return GetSetting<CGUIColor>("textcolor_over") || color;
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
Stop copying color every draw call for every GUI object using colors.
Avoid color copies for rendering Draw calls in
GUIRenderer::UpdateDrawCallCache, CButton::Draw, CChart::DrawAxes,
CDropDown::Draw, CList::DrawList, COList::DrawList, refs #1984,
8f4f8e240f, 3028551b91, a905fbbc98.
Avoid color copies during XML loading in CGUI::Xeromyces_ReadImage,
CGUI::Xeromyces_ReadEffects, COList::HandleAdditionalChildren.
Add CGUI::HasPreDefinedColor and mark m_PreDefinedColors,
CGUI::GetPreDefinedColor, IGUIButtonBehavior::ChooseColor() as const for
consistency with the other "databases", refs 3028551b91.
Mark CGUIColor as NONCOPYABLE to add compiler errors if there is an
unexplicit copy, refs 3028551b91.
Explicit ugly copy in CGUI::Xeromyces_ReadColor and
CGUIColor::ParseString.
Deregister copying <CGUIColor>GetSetting functions, refs 8f4f8e240f.
Uses the const ref GetSetting from 3dfa23cd25.
This was SVN commit r22694.
2019-08-19 05:53:58 -07:00
|
|
|
|
|
|
|
|
return color;
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2019-08-26 05:25:07 -07:00
|
|
|
if (!GetSetting<bool>("enabled"))
|
2019-08-21 03:12:33 -07:00
|
|
|
m_pGUI.DrawSprite(sprite_disabled || sprite, cell_id, z, rect);
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (m_MouseHovering)
|
|
|
|
|
{
|
|
|
|
|
if (m_Pressed)
|
2019-08-21 03:12:33 -07:00
|
|
|
m_pGUI.DrawSprite(sprite_pressed || sprite, cell_id, z, rect);
|
2013-12-29 12:46:02 -08:00
|
|
|
else
|
2019-08-21 03:12:33 -07:00
|
|
|
m_pGUI.DrawSprite(sprite_over || sprite, cell_id, z, rect);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
2015-08-21 10:08:41 -07:00
|
|
|
else
|
2019-08-21 03:12:33 -07:00
|
|
|
m_pGUI.DrawSprite(sprite, cell_id, z, rect);
|
2004-06-10 19:14:18 -07:00
|
|
|
}
|