2012-03-19 13:37:59 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// *
|
|
|
|
// * This program 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 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program 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
|
2012-03-11 19:49:33 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
#define STRICT
|
|
|
|
#define D3D_OVERLOADS
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <d3d.h>
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "common/struct.h"
|
|
|
|
#include "graphics/d3d/d3dengine.h"
|
|
|
|
#include "math/old/math3d.h"
|
|
|
|
#include "common/event.h"
|
|
|
|
#include "common/misc.h"
|
|
|
|
#include "common/iman.h"
|
|
|
|
#include "common/restext.h"
|
|
|
|
#include "graphics/common/text.h"
|
|
|
|
#include "ui/check.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CCheck::CCheck(CInstanceManager* iMan) : CControl(iMan)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Object's destructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CCheck::~CCheck()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Creates a new button.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CCheck::Create(FPOINT pos, FPOINT dim, int icon, EventMsg eventMsg)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
char name[100];
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg();
|
|
|
|
|
|
|
|
CControl::Create(pos, dim, icon, eventMsg);
|
|
|
|
|
|
|
|
GetResource(RES_EVENT, eventMsg, name);
|
|
|
|
p = strchr(name, '\\');
|
|
|
|
if ( p != 0 ) *p = 0;
|
|
|
|
SetName(name);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CCheck::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_state & STATE_DEAD ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CControl::EventProcess(event);
|
|
|
|
|
|
|
|
if ( event.event == EVENT_LBUTTONDOWN &&
|
|
|
|
(m_state & STATE_VISIBLE) &&
|
|
|
|
(m_state & STATE_ENABLE) )
|
|
|
|
{
|
|
|
|
if ( CControl::Detect(event.pos) )
|
|
|
|
{
|
|
|
|
Event newEvent = event;
|
|
|
|
newEvent.event = m_eventMsg;
|
|
|
|
m_event->AddEvent(newEvent);
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Draw button.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CCheck::Draw()
|
|
|
|
{
|
|
|
|
FPOINT iDim, pos;
|
|
|
|
float zoomExt, zoomInt;
|
|
|
|
int icon;
|
|
|
|
|
|
|
|
if ( (m_state & STATE_VISIBLE) == 0 ) return;
|
|
|
|
|
|
|
|
iDim = m_dim;
|
2012-03-17 15:17:24 +00:00
|
|
|
m_dim.x = m_dim.y*0.75f; // square
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
if ( m_state & STATE_SHADOW )
|
|
|
|
{
|
|
|
|
DrawShadow(m_pos, m_dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_engine->SetTexture("button1.tga");
|
|
|
|
m_engine->SetState(D3DSTATENORMAL);
|
|
|
|
|
|
|
|
zoomExt = 1.00f;
|
|
|
|
zoomInt = 0.95f;
|
|
|
|
|
|
|
|
icon = 2;
|
|
|
|
if ( m_state & STATE_DEFAULT )
|
|
|
|
{
|
|
|
|
DrawPart(23, 1.3f, 0.0f);
|
|
|
|
|
|
|
|
zoomExt *= 1.15f;
|
|
|
|
zoomInt *= 1.15f;
|
|
|
|
}
|
|
|
|
if ( m_state & STATE_HILIGHT )
|
|
|
|
{
|
|
|
|
icon = 1;
|
|
|
|
}
|
|
|
|
if ( m_state & STATE_PRESS )
|
|
|
|
{
|
|
|
|
icon = 3;
|
|
|
|
zoomInt *= 0.9f;
|
|
|
|
}
|
|
|
|
if ( (m_state & STATE_ENABLE) == 0 )
|
|
|
|
{
|
|
|
|
icon = 7;
|
|
|
|
}
|
|
|
|
if ( m_state & STATE_DEAD )
|
|
|
|
{
|
|
|
|
icon = 17;
|
|
|
|
}
|
2012-03-17 15:17:24 +00:00
|
|
|
DrawPart(icon, zoomExt, 0.0f); // draws the button
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
if ( (m_state & STATE_DEAD) == 0 )
|
|
|
|
{
|
|
|
|
m_engine->SetState(D3DSTATETTw);
|
|
|
|
|
|
|
|
if ( m_state & STATE_CHECK )
|
|
|
|
{
|
2012-03-17 15:17:24 +00:00
|
|
|
icon = 16; // seen
|
|
|
|
DrawPart(icon, zoomInt, 0.0f); // draw the icon
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dim = iDim;
|
|
|
|
|
|
|
|
if ( m_state & STATE_DEAD ) return;
|
|
|
|
|
2012-03-17 15:17:24 +00:00
|
|
|
// Draw the name.
|
2012-03-08 18:32:05 +00:00
|
|
|
pos.x = m_pos.x+m_dim.y/0.9f;
|
|
|
|
pos.y = m_pos.y+m_dim.y*0.50f;
|
|
|
|
pos.y -= m_engine->RetText()->RetHeight(m_fontSize, m_fontType)/2.0f;
|
|
|
|
m_engine->RetText()->DrawText(m_name, pos, m_dim.x, 1, m_fontSize, m_fontStretch, m_fontType, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|