2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 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/>.
|
|
|
|
*/
|
|
|
|
|
2003-11-24 03:18:41 +01:00
|
|
|
/*
|
|
|
|
IGUIButtonBehavior
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2003-11-24 03:18:41 +01:00
|
|
|
#include "GUI.h"
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Constructor / Destructor
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUIButtonBehavior::~IGUIButtonBehavior()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
void IGUIButtonBehavior::HandleMessage(const 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
|
|
|
{
|
|
|
|
case GUIM_MOUSE_PRESS_LEFT:
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
GUI<bool>::GetSetting(this, "enabled", enabled);
|
|
|
|
|
|
|
|
if (!enabled)
|
2003-12-27 07:26:03 +01:00
|
|
|
break;
|
|
|
|
|
2003-11-24 03:18:41 +01:00
|
|
|
m_Pressed = true;
|
2004-05-29 06:06:50 +02:00
|
|
|
} break;
|
2003-11-24 03:18:41 +01:00
|
|
|
|
2010-08-22 03:00:57 +02:00
|
|
|
case GUIM_MOUSE_DBLCLICK_LEFT:
|
2003-11-24 03:18:41 +01:00
|
|
|
case GUIM_MOUSE_RELEASE_LEFT:
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
GUI<bool>::GetSetting(this, "enabled", enabled);
|
|
|
|
|
|
|
|
if (!enabled)
|
2003-12-27 07:26:03 +01:00
|
|
|
break;
|
|
|
|
|
2003-11-24 03:18:41 +01:00
|
|
|
if (m_Pressed)
|
|
|
|
{
|
|
|
|
m_Pressed = false;
|
|
|
|
// BUTTON WAS CLICKED
|
|
|
|
HandleMessage(GUIM_PRESSED);
|
2004-07-11 18:22:35 +02:00
|
|
|
ScriptEvent("press");
|
2003-11-24 03:18:41 +01:00
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
} break;
|
2003-11-24 03:18:41 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
CColor IGUIButtonBehavior::ChooseColor()
|
|
|
|
{
|
2005-04-24 01:20:50 +02:00
|
|
|
CColor color, color2;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
// Yes, the object must possess these settings. They are standard
|
|
|
|
GUI<CColor>::GetSetting(this, "textcolor", color);
|
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
GUI<bool>::GetSetting(this, "enabled", enabled);
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
{
|
2005-04-24 01:20:50 +02:00
|
|
|
GUI<CColor>::GetSetting(this, "textcolor_disabled", color2);
|
|
|
|
return GUI<>::FallBackColor(color2, color);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (m_MouseHovering)
|
|
|
|
{
|
|
|
|
if (m_Pressed)
|
2005-04-24 01:20:50 +02:00
|
|
|
{
|
|
|
|
GUI<CColor>::GetSetting(this, "textcolor_pressed", color2);
|
|
|
|
return GUI<>::FallBackColor(color2, color);
|
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
else
|
2005-04-24 01:20:50 +02:00
|
|
|
{
|
|
|
|
GUI<CColor>::GetSetting(this, "textcolor_over", color2);
|
|
|
|
return GUI<>::FallBackColor(color2, color);
|
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
else return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IGUIButtonBehavior::DrawButton(const CRect &rect,
|
|
|
|
const float &z,
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance& sprite,
|
|
|
|
CGUISpriteInstance& sprite_over,
|
|
|
|
CGUISpriteInstance& sprite_pressed,
|
2004-12-17 17:20:08 +01:00
|
|
|
CGUISpriteInstance& sprite_disabled,
|
2004-12-18 14:32:00 +01:00
|
|
|
int cell_id)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
if (GetGUI())
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
GUI<bool>::GetSetting(this, "enabled", enabled);
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
{
|
2004-12-18 14:32:00 +01:00
|
|
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (m_MouseHovering)
|
|
|
|
{
|
|
|
|
if (m_Pressed)
|
2004-12-18 14:32:00 +01:00
|
|
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
|
2004-05-29 06:06:50 +02:00
|
|
|
else
|
2004-12-18 14:32:00 +01:00
|
|
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
2004-12-18 14:32:00 +01:00
|
|
|
else GetGUI()->DrawSprite(sprite, cell_id, z, rect);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
2004-06-11 04:14:18 +02:00
|
|
|
}
|