2011-07-02 23:03:18 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
|
|
|
|
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero 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 Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2011-07-03 19:45:08 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
#include "mytimeoutlabel.h"
|
2009-04-19 20:23:20 +00:00
|
|
|
#include "gametableimpl.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
MyTimeoutLabel::MyTimeoutLabel(QGroupBox* parent)
|
2011-02-11 20:02:08 +00:00
|
|
|
: QLabel(parent), timeOutAnimation(FALSE), timeOutValue(0), timeOutFrame(0), waitFrames(0), timerIntervall(0), isBeep(0), isBeepPlayed(0)
|
2009-04-19 20:23:20 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
timeOutAnimationTimer = new QTimer;
|
|
|
|
|
|
|
|
|
|
connect(timeOutAnimationTimer, SIGNAL(timeout()), this, SLOT(nextTimeOutAnimationFrame()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MyTimeoutLabel::~MyTimeoutLabel()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void MyTimeoutLabel::startTimeOutAnimation(int secs, bool beep)
|
|
|
|
|
{
|
2009-04-19 20:23:20 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (secs >= 4) { // smaller timeouts may lead to errors/endless loops below
|
2011-02-06 14:03:45 +00:00
|
|
|
isBeepPlayed = FALSE;
|
|
|
|
|
isBeep = beep;
|
2009-04-19 20:23:20 +00:00
|
|
|
|
2011-02-06 14:03:45 +00:00
|
|
|
timeOutValue = secs;
|
|
|
|
|
timeOutFrame = 1;
|
|
|
|
|
timeOutAnimationWidth = 52;
|
2009-04-19 20:23:20 +00:00
|
|
|
|
2011-02-06 14:03:45 +00:00
|
|
|
int preTimerIntervall = ((timeOutValue-3) * 1000)/timeOutAnimationWidth;
|
|
|
|
|
|
|
|
|
|
timerIntervall = preTimerIntervall;
|
|
|
|
|
|
|
|
|
|
//save gfx ressources and never play more the 10 pps
|
|
|
|
|
while(timerIntervall < 100) {
|
|
|
|
|
if(secs <= 9 && secs >= 6) {
|
|
|
|
|
//fix inaccuracies caused by integer division
|
|
|
|
|
timerIntervall = timerIntervall + preTimerIntervall + 5;
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2011-02-06 14:03:45 +00:00
|
|
|
timerIntervall = timerIntervall + preTimerIntervall;
|
|
|
|
|
}
|
2009-04-19 20:23:20 +00:00
|
|
|
}
|
2011-02-06 14:03:45 +00:00
|
|
|
|
|
|
|
|
waitFrames = 3000/timerIntervall;
|
|
|
|
|
|
|
|
|
|
//start the real timer
|
|
|
|
|
realTimer.reset();
|
|
|
|
|
realTimer.start();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
// std::cout << timerIntervall << endl;
|
2011-02-06 14:03:45 +00:00
|
|
|
timeOutAnimation = TRUE;
|
|
|
|
|
timeOutAnimationTimer->start(timerIntervall);
|
2009-04-19 20:23:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void MyTimeoutLabel::startTimeOutAnimationNow()
|
|
|
|
|
{
|
2009-04-19 20:23:20 +00:00
|
|
|
|
|
|
|
|
timeOutAnimation = TRUE;
|
|
|
|
|
timeOutAnimationTimer->start(83);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void MyTimeoutLabel::stopTimeOutAnimation()
|
|
|
|
|
{
|
2009-04-19 20:23:20 +00:00
|
|
|
|
|
|
|
|
// timeOutAnimationKickOnTimer->stop();
|
|
|
|
|
timeOutAnimationTimer->stop();
|
|
|
|
|
timeOutAnimation = FALSE;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void MyTimeoutLabel::nextTimeOutAnimationFrame()
|
|
|
|
|
{
|
2009-04-19 20:23:20 +00:00
|
|
|
|
|
|
|
|
if(timeOutAnimationWidth >=0) {
|
2011-02-11 20:02:08 +00:00
|
|
|
if(timeOutFrame > waitFrames) {
|
2009-04-19 20:23:20 +00:00
|
|
|
//play beep after waitFrames one time
|
2011-02-11 20:02:08 +00:00
|
|
|
if(isBeep && !isBeepPlayed) {
|
2009-04-19 20:23:20 +00:00
|
|
|
myW->getMySDLPlayer()->playSound("yourturn",0);
|
|
|
|
|
isBeepPlayed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
//save gfx ressources and never play more the 10 pps
|
|
|
|
|
unsigned int realTimerValue = realTimer.elapsed().total_milliseconds();
|
2011-02-11 20:02:08 +00:00
|
|
|
timeOutAnimationWidth = 52-(((realTimerValue-3000)*52)/((timeOutValue-3)*1000));
|
2009-04-19 20:23:20 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
timeOutFrame++;
|
|
|
|
|
update();
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2009-04-19 20:23:20 +00:00
|
|
|
stopTimeOutAnimation();
|
|
|
|
|
// no callback is called here.
|
|
|
|
|
// the server initiates any action required.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void MyTimeoutLabel::paintEvent(QPaintEvent * event)
|
|
|
|
|
{
|
2009-04-19 20:23:20 +00:00
|
|
|
|
|
|
|
|
if(!timeOutAnimation || timeOutFrame <= waitFrames) {
|
|
|
|
|
QLabel::paintEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timeOutAnimation && timeOutFrame > waitFrames) {
|
|
|
|
|
|
|
|
|
|
QPainter painter(this);
|
2011-02-11 20:02:08 +00:00
|
|
|
|
|
|
|
|
QLinearGradient linearGrad(QPointF(0, 10), QPointF(47, 10));
|
2009-04-19 20:23:20 +00:00
|
|
|
linearGrad.setColorAt(0, Qt::red);
|
|
|
|
|
linearGrad.setColorAt(0.5, Qt::yellow);
|
|
|
|
|
linearGrad.setColorAt(1, Qt::green);
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2009-04-19 20:23:20 +00:00
|
|
|
painter.setBrush(linearGrad);
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2009-04-19 20:23:20 +00:00
|
|
|
painter.setPen(QColor(0,0,0));
|
2011-02-11 20:02:08 +00:00
|
|
|
painter.drawRect(0,1,timeOutAnimationWidth-1,8);
|
2009-04-19 20:23:20 +00:00
|
|
|
}
|
|
|
|
|
}
|