2021-05-06 01:22:37 -07:00
|
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
|
* 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.
|
|
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
|
* 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
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Interface class that enhance the IGUIObject with
|
|
|
|
|
|
buttony behavior (click and release to click a button),
|
|
|
|
|
|
and the GUI message GUIM_PRESSED.
|
|
|
|
|
|
When creating a class with extended settings and
|
|
|
|
|
|
buttony behavior, just do a multiple inheritance.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
|
#ifndef INCLUDED_IGUIBUTTONBEHAVIOR
|
|
|
|
|
|
#define INCLUDED_IGUIBUTTONBEHAVIOR
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
2019-10-02 02:44:00 -07:00
|
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
2020-11-21 03:20:29 -08:00
|
|
|
|
#include "ps/CStr.h"
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
|
class CGUISpriteInstance;
|
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
|
/**
|
|
|
|
|
|
* Appends button behaviours to the IGUIObject.
|
|
|
|
|
|
* Can be used with multiple inheritance alongside
|
|
|
|
|
|
* IGUISettingsObject and such.
|
|
|
|
|
|
*/
|
2019-09-30 07:08:14 -07:00
|
|
|
|
class IGUIButtonBehavior
|
2003-11-23 18:18:41 -08:00
|
|
|
|
{
|
2019-09-30 07:08:14 -07:00
|
|
|
|
NONCOPYABLE(IGUIButtonBehavior);
|
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
|
public:
|
2019-09-30 07:08:14 -07:00
|
|
|
|
IGUIButtonBehavior(IGUIObject& pObject);
|
2003-11-23 18:18:41 -08:00
|
|
|
|
virtual ~IGUIButtonBehavior();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @see IGUIObject#HandleMessage()
|
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
|
virtual void HandleMessage(SGUIMessage& Message);
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* This is a function that lets a button being drawn,
|
|
|
|
|
|
* it regards if it's over, disabled, pressed and such.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param sprite Sprite drawn when not pressed, hovered or disabled
|
|
|
|
|
|
* @param sprite_over Sprite drawn when m_MouseHovering is true
|
|
|
|
|
|
* @param sprite_pressed Sprite drawn when m_Pressed is true
|
|
|
|
|
|
* @param sprite_disabled Sprite drawn when "enabled" is false
|
|
|
|
|
|
*/
|
2019-09-28 04:33:58 -07:00
|
|
|
|
const CGUISpriteInstance& GetButtonSprite(const CGUISpriteInstance& sprite, const CGUISpriteInstance& sprite_over, const CGUISpriteInstance& sprite_pressed, const CGUISpriteInstance& sprite_disabled) const;
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
|
protected:
|
2020-01-15 08:00:37 -08:00
|
|
|
|
static const CStr EventNamePress;
|
|
|
|
|
|
static const CStr EventNamePressRight;
|
2020-11-14 10:16:24 -08:00
|
|
|
|
static const CStr EventNamePressRightDisabled;
|
2020-01-15 08:00:37 -08:00
|
|
|
|
static const CStr EventNameDoublePress;
|
|
|
|
|
|
static const CStr EventNameDoublePressRight;
|
2020-01-23 16:56:51 -08:00
|
|
|
|
static const CStr EventNameRelease;
|
|
|
|
|
|
static const CStr EventNameReleaseRight;
|
2020-01-15 08:00:37 -08:00
|
|
|
|
|
2011-04-28 13:42:11 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @see IGUIObject#ResetStates()
|
|
|
|
|
|
*/
|
2019-09-30 07:08:14 -07:00
|
|
|
|
virtual void ResetStates();
|
2003-11-24 18:47:12 -08:00
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
|
/**
|
|
|
|
|
|
* Everybody knows how a button works, you don't simply press it,
|
|
|
|
|
|
* you have to first press the button, and then release it...
|
|
|
|
|
|
* in between those two steps you can actually leave the button
|
|
|
|
|
|
* area, as long as you release it within the button area... Anyway
|
|
|
|
|
|
* this lets us know we are done with step one (clicking).
|
|
|
|
|
|
*/
|
2019-09-22 07:53:27 -07:00
|
|
|
|
bool m_Pressed;
|
|
|
|
|
|
bool m_PressedRight;
|
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 05:49:59 -07:00
|
|
|
|
|
2021-05-06 01:22:37 -07:00
|
|
|
|
CGUISimpleSetting<CStrW> m_SoundDisabled;
|
|
|
|
|
|
CGUISimpleSetting<CStrW> m_SoundEnter;
|
|
|
|
|
|
CGUISimpleSetting<CStrW> m_SoundLeave;
|
|
|
|
|
|
CGUISimpleSetting<CStrW> m_SoundPressed;
|
|
|
|
|
|
CGUISimpleSetting<CStrW> m_SoundReleased;
|
2019-09-30 07:08:14 -07:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Reference to the IGUIObject.
|
|
|
|
|
|
* Private, because we don't want to inherit it in multiple classes.
|
|
|
|
|
|
*/
|
|
|
|
|
|
IGUIObject& m_pObject;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
|
#endif // INCLUDED_IGUIBUTTONBEHAVIOR
|