2019-07-26 20:57:28 +02:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 19:00:33 +02: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 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2019-09-22 16:53:27 +02:00
|
|
|
#include "IGUIButtonBehavior.h"
|
|
|
|
|
2019-09-18 22:51:45 +02:00
|
|
|
#include "gui/CGUI.h"
|
2019-09-20 15:11:18 +02:00
|
|
|
#include "gui/CGUISprite.h"
|
2019-09-18 22:51:45 +02:00
|
|
|
|
2019-08-21 12:12:33 +02:00
|
|
|
IGUIButtonBehavior::IGUIButtonBehavior(CGUI& pGUI)
|
2019-09-22 16:53:27 +02:00
|
|
|
: IGUIObject(pGUI),
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
m_Pressed(),
|
|
|
|
m_PressedRight(),
|
|
|
|
m_SoundDisabled(),
|
|
|
|
m_SoundEnter(),
|
|
|
|
m_SoundLeave(),
|
|
|
|
m_SoundPressed(),
|
|
|
|
m_SoundReleased()
|
2003-11-24 03:18:41 +01:00
|
|
|
{
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
RegisterSetting("sound_disabled", m_SoundDisabled);
|
|
|
|
RegisterSetting("sound_enter", m_SoundEnter);
|
|
|
|
RegisterSetting("sound_leave", m_SoundLeave);
|
|
|
|
RegisterSetting("sound_pressed", m_SoundPressed);
|
|
|
|
RegisterSetting("sound_released", m_SoundReleased);
|
2003-11-24 03:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IGUIButtonBehavior::~IGUIButtonBehavior()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
|
2003-11-24 03:18:41 +01:00
|
|
|
{
|
2004-05-29 06:06:50 +02:00
|
|
|
// TODO Gee: easier access functions
|
2003-12-27 07:26:03 +01:00
|
|
|
switch (Message.type)
|
2003-11-24 03:18:41 +01:00
|
|
|
{
|
2013-07-01 06:15:09 +02:00
|
|
|
case GUIM_MOUSE_ENTER:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (m_Enabled)
|
|
|
|
PlaySound(m_SoundEnter);
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2013-07-01 06:15:09 +02:00
|
|
|
|
|
|
|
case GUIM_MOUSE_LEAVE:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (m_Enabled)
|
|
|
|
PlaySound(m_SoundLeave);
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2013-07-01 06:15:09 +02:00
|
|
|
|
2013-12-29 20:31:48 +01:00
|
|
|
case GUIM_MOUSE_DBLCLICK_LEFT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2014-01-01 07:05:41 +01:00
|
|
|
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-24 03:18:41 +01:00
|
|
|
case GUIM_MOUSE_PRESS_LEFT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2013-07-01 06:15:09 +02:00
|
|
|
{
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundDisabled);
|
2003-12-27 07:26:03 +01:00
|
|
|
break;
|
2013-07-01 06:15:09 +02:00
|
|
|
}
|
|
|
|
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundPressed);
|
2013-12-29 20:31:48 +01:00
|
|
|
SendEvent(GUIM_PRESSED, "press");
|
2003-11-24 03:18:41 +01:00
|
|
|
m_Pressed = true;
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2013-01-03 23:53:46 +01:00
|
|
|
|
|
|
|
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2014-01-01 07:05:41 +01:00
|
|
|
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 19:08:41 +02:00
|
|
|
|
2013-12-29 20:31:48 +01:00
|
|
|
case GUIM_MOUSE_PRESS_RIGHT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2013-01-03 23:53:46 +01:00
|
|
|
{
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundDisabled);
|
2013-12-29 20:31:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-01 07:05:41 +01:00
|
|
|
// Button was right-clicked
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundPressed);
|
2013-12-29 20:31:48 +01:00
|
|
|
SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
|
|
|
|
m_PressedRight = true;
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2013-01-03 23:53:46 +01:00
|
|
|
|
2013-12-29 20:31:48 +01:00
|
|
|
case GUIM_MOUSE_RELEASE_RIGHT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2013-12-29 20:31:48 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (m_PressedRight)
|
2013-07-01 06:15:09 +02:00
|
|
|
{
|
2013-12-29 20:31:48 +01:00
|
|
|
m_PressedRight = false;
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundReleased);
|
2013-07-01 06:15:09 +02:00
|
|
|
}
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2003-11-24 03:18:41 +01:00
|
|
|
|
|
|
|
case GUIM_MOUSE_RELEASE_LEFT:
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2003-12-27 07:26:03 +01:00
|
|
|
break;
|
|
|
|
|
2003-11-24 03:18:41 +01:00
|
|
|
if (m_Pressed)
|
|
|
|
{
|
|
|
|
m_Pressed = false;
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
PlaySound(m_SoundReleased);
|
2003-11-24 03:18:41 +01:00
|
|
|
}
|
2014-01-01 07:05:41 +01:00
|
|
|
break;
|
2003-11-24 03:18:41 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2019-09-28 13:33:58 +02:00
|
|
|
const CGUISpriteInstance& IGUIButtonBehavior::GetButtonSprite(const CGUISpriteInstance& sprite, const CGUISpriteInstance& sprite_over, const CGUISpriteInstance& sprite_pressed, const CGUISpriteInstance& sprite_disabled) const
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 14:49:59 +02:00
|
|
|
if (!m_Enabled)
|
2019-09-28 13:33:58 +02:00
|
|
|
return sprite_disabled || sprite;
|
|
|
|
|
|
|
|
if (!m_MouseHovering)
|
|
|
|
return sprite;
|
|
|
|
|
|
|
|
if (m_Pressed)
|
|
|
|
return sprite_pressed || sprite;
|
|
|
|
|
|
|
|
return sprite_over || sprite;
|
2004-06-11 04:14:18 +02:00
|
|
|
}
|