2012-03-19 11:44:39 +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-21 21:21:08 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// gauge.cpp
|
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 "ui/gauge.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CGauge::CGauge(CInstanceManager* iMan) : CControl(iMan)
|
|
|
|
{
|
|
|
|
m_level = 0.0f;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
// Object's destructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CGauge::~CGauge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
// Creates a new button.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CGauge::Create(FPOINT pos, FPOINT dim, int icon, EventMsg eventMsg)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg();
|
|
|
|
|
|
|
|
CControl::Create(pos, dim, icon, eventMsg);
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CGauge::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CControl::EventProcess(event);
|
|
|
|
|
|
|
|
if ( event.event == EVENT_LBUTTONDOWN )
|
|
|
|
{
|
|
|
|
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-21 21:21:08 +00:00
|
|
|
// Draw the gauge.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CGauge::Draw()
|
|
|
|
{
|
|
|
|
FPOINT pos, dim, ddim, uv1, uv2, corner;
|
|
|
|
float dp;
|
|
|
|
|
|
|
|
if ( (m_state & STATE_VISIBLE) == 0 ) return;
|
|
|
|
|
|
|
|
m_engine->SetTexture("button2.tga");
|
|
|
|
m_engine->SetState(D3DSTATENORMAL);
|
|
|
|
|
|
|
|
dp = 0.5f/256.0f;
|
|
|
|
|
|
|
|
pos = m_pos;
|
|
|
|
dim = m_dim;
|
|
|
|
|
|
|
|
uv1.x = 32.0f/256.0f;
|
|
|
|
uv1.y = 32.0f/256.0f;
|
|
|
|
uv2.x = 64.0f/256.0f;
|
|
|
|
uv2.y = 64.0f/256.0f;
|
|
|
|
|
|
|
|
uv1.x += dp;
|
|
|
|
uv1.y += dp;
|
|
|
|
uv2.x -= dp;
|
|
|
|
uv2.y -= dp;
|
|
|
|
|
|
|
|
corner.x = 10.0f/640.0f;
|
|
|
|
corner.y = 10.0f/480.0f;
|
|
|
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2, corner, 8.0f/256.0f);
|
|
|
|
|
|
|
|
|
|
|
|
pos.x += 3.0f/640.0f;
|
|
|
|
pos.y += 3.0f/480.0f;
|
|
|
|
dim.x -= 6.0f/640.0f;
|
|
|
|
dim.y -= 6.0f/480.0f;
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
if ( m_dim.x < m_dim.y ) // vertical gauge?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
uv1.x = (0.0f+m_icon*16.0f)/256.0f;
|
|
|
|
uv2.x = uv1.x+16.0f/256.0f;
|
|
|
|
uv1.y = 128.0f/256.0f+m_level*(64.0f/256.0f);
|
|
|
|
uv2.y = uv1.y+64.0f/256.0f;
|
|
|
|
}
|
2012-03-21 21:21:08 +00:00
|
|
|
else // horizontal gauge?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
uv1.x = 64.0f/256.0f+(1.0f-m_level)*(64.0f/256.0f);
|
|
|
|
uv2.x = uv1.x+64.0f/256.0f;
|
|
|
|
uv1.y = (128.0f+m_icon*16.0f)/256.0f;
|
|
|
|
uv2.y = uv1.y+16.0f/256.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
uv1.x += dp;
|
|
|
|
uv1.y += dp;
|
|
|
|
uv2.x -= dp;
|
|
|
|
uv2.y -= dp;
|
|
|
|
|
|
|
|
DrawIcon(pos, dim, uv1, uv2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 21:21:08 +00:00
|
|
|
// Management of level of the gauge.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CGauge::SetLevel(float level)
|
|
|
|
{
|
|
|
|
if ( level < 0.0f ) level = 0.0f;
|
|
|
|
if ( level > 1.0f ) level = 1.0f;
|
|
|
|
m_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CGauge::RetLevel()
|
|
|
|
{
|
|
|
|
return m_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
|