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-03 17:22:45 +01:00
|
|
|
/*
|
|
|
|
CButton
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
#include "GUI.h"
|
2004-05-29 06:06:50 +02:00
|
|
|
#include "CButton.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/ogl.h"
|
2003-11-25 03:47:12 +01:00
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Constructor / Destructor
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
CButton::CButton()
|
|
|
|
{
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_float, "buffer_zone");
|
2004-12-28 13:17:04 +01:00
|
|
|
AddSetting(GUIST_CGUIString, "caption");
|
2005-07-24 00:27:55 +02:00
|
|
|
AddSetting(GUIST_int, "cell_id");
|
2009-11-03 22:46:35 +01:00
|
|
|
AddSetting(GUIST_CStrW, "font");
|
2004-12-15 22:24:46 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_disabled");
|
|
|
|
AddSetting(GUIST_EAlign, "text_align");
|
|
|
|
AddSetting(GUIST_EVAlign, "text_valign");
|
2004-12-28 13:17:04 +01:00
|
|
|
AddSetting(GUIST_CColor, "textcolor");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CColor, "textcolor_over");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_pressed");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_disabled");
|
2011-02-18 23:36:39 +01:00
|
|
|
AddSetting(GUIST_CStrW, "tooltip");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CStr, "tooltip_style");
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
// Add text
|
|
|
|
AddText(new SGUIText());
|
2003-11-03 17:22:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CButton::~CButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
void CButton::SetupText()
|
|
|
|
{
|
|
|
|
if (!GetGUI())
|
|
|
|
return;
|
|
|
|
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(m_GeneratedTexts.size()==1);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW font;
|
|
|
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
2004-07-31 15:37:35 +02:00
|
|
|
// Use the default if none is specified
|
2004-08-31 04:09:58 +02:00
|
|
|
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
|
2009-11-03 22:46:35 +01:00
|
|
|
font = L"default";
|
2004-07-31 15:37:35 +02:00
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
CGUIString caption;
|
|
|
|
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
|
|
|
|
2004-12-28 13:38:45 +01:00
|
|
|
float buffer_zone=0.f;
|
2005-01-01 13:06:17 +01:00
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
2004-12-28 13:38:45 +01:00
|
|
|
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2004-12-28 13:17:04 +01:00
|
|
|
CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
|
2011-04-28 22:42:11 +02:00
|
|
|
void CButton::HandleMessage(SGUIMessage &Message)
|
2003-11-03 17:22:45 +01:00
|
|
|
{
|
2003-11-25 03:47:12 +01:00
|
|
|
// Important
|
2003-11-24 03:18:41 +01:00
|
|
|
IGUIButtonBehavior::HandleMessage(Message);
|
2004-05-29 06:06:50 +02:00
|
|
|
IGUITextOwner::HandleMessage(Message);
|
2003-11-03 17:22:45 +01:00
|
|
|
}
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
void CButton::Draw()
|
2003-11-03 17:22:45 +01:00
|
|
|
{
|
2004-05-29 06:06:50 +02:00
|
|
|
float bz = GetBufferedZ();
|
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
2004-12-18 14:32:00 +01:00
|
|
|
int cell_id;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2010-01-07 20:00:56 +01:00
|
|
|
// Statically initialise some strings, so we don't have to do
|
|
|
|
// lots of allocation every time this function is called
|
|
|
|
static CStr strSprite("sprite");
|
|
|
|
static CStr strSpriteOver("sprite_over");
|
|
|
|
static CStr strSpritePressed("sprite_pressed");
|
|
|
|
static CStr strSpriteDisabled("sprite_disabled");
|
|
|
|
static CStr strCellId("cell_id");
|
|
|
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite);
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over);
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpritePressed, sprite_pressed);
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteDisabled, sprite_disabled);
|
|
|
|
GUI<int>::GetSetting(this, strCellId, cell_id);
|
2004-12-15 22:24:46 +01:00
|
|
|
|
|
|
|
DrawButton(m_CachedActualSize,
|
|
|
|
bz,
|
2004-12-17 01:05:37 +01:00
|
|
|
*sprite,
|
|
|
|
*sprite_over,
|
|
|
|
*sprite_pressed,
|
2004-12-17 17:20:08 +01:00
|
|
|
*sprite_disabled,
|
2004-12-18 14:32:00 +01:00
|
|
|
cell_id);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
CColor color = ChooseColor();
|
2011-07-17 19:30:07 +02:00
|
|
|
DrawText(0, color, m_TextPos, bz+0.1f);
|
2003-11-24 18:13:37 +01:00
|
|
|
}
|