vdr-plugin-tvguide/messagebox.c

112 lines
3.7 KiB
C
Raw Normal View History

2013-01-17 13:16:44 +01:00
#include "messagebox.h"
cMessageBoxThread::cMessageBoxThread(cPixmap *content, int displayTime) {
2013-05-26 11:38:05 +02:00
this->content = content;
FrameTime = 30; // ms
FadeTime = 200; // ms
this->displayTime = displayTime;
2013-01-17 13:16:44 +01:00
}
cMessageBoxThread::~cMessageBoxThread(void) {
Cancel(-1);
2013-05-26 11:38:05 +02:00
while (Active())
cCondWait::SleepMs(10);
2013-01-17 13:16:44 +01:00
}
void cMessageBoxThread::Action(void) {
2013-05-26 11:38:05 +02:00
uint64_t Start = cTimeMs::Now();
while (Running()) {
uint64_t Now = cTimeMs::Now();
cPixmap::Lock();
double t = min(double(Now - Start) / FadeTime, 1.0);
int Alpha = t * ALPHA_OPAQUE;
if (Running() && content) {
content->SetAlpha(Alpha);
osdManager.flush();
}
cPixmap::Unlock();
2013-01-17 13:16:44 +01:00
int Delta = cTimeMs::Now() - Now;
if (Delta < FrameTime)
cCondWait::SleepMs(FrameTime - Delta);
2013-05-26 11:38:05 +02:00
if ((Now - Start) > FadeTime)
break;
2013-01-17 13:16:44 +01:00
}
2013-05-26 11:38:05 +02:00
cCondWait::SleepMs(displayTime - 2*FadeTime);
Start = cTimeMs::Now();
while (Running()) {
uint64_t Now = cTimeMs::Now();
cPixmap::Lock();
double t = min(double(Now - Start) / FadeTime, 1.0);
int Alpha = (1-t) * ALPHA_OPAQUE;
if (Running() && content) {
content->SetAlpha(Alpha);
osdManager.flush();
}
cPixmap::Unlock();
2013-01-17 13:16:44 +01:00
int Delta = cTimeMs::Now() - Now;
if (Delta < FrameTime)
cCondWait::SleepMs(FrameTime - Delta);
2013-05-26 11:38:05 +02:00
if ((Now - Start) > FadeTime)
break;
2013-01-17 13:16:44 +01:00
}
2013-05-26 11:38:05 +02:00
osdManager.flush();
2013-01-17 13:16:44 +01:00
}
//--cMessageBox-------------------------------------------------------------
cMessageBoxThread *cMessageBox::msgboxThread = NULL;
cPixmap *cMessageBox::content = NULL;
bool cMessageBox::Start(int displayTime, cString msg) {
2013-05-26 11:38:05 +02:00
int width = (tvguideConfig.osdWidth - 600)/2;
if (!content) {
int height = 400;
content = osdManager.requestPixmap(5, cRect((tvguideConfig.osdWidth - width)/2,
(tvguideConfig.osdHeight- height)/2,
width, height));
}
if (msgboxThread) {
delete msgboxThread;
msgboxThread = NULL;
}
if (!msgboxThread) {
msgboxThread = new cMessageBoxThread(content, displayTime);
cTextWrapper message;
message.Set(msg, tvguideConfig.FontMessageBox, width - 40);
int textHeight = tvguideConfig.FontMessageBox->Height();
int textLines = message.Lines();
int height = textLines * (textHeight+20);
cPixmap::Lock();
content->SetViewPort(cRect((tvguideConfig.osdWidth - width)/2,(tvguideConfig.osdHeight- height)/2, width, height));
content->SetAlpha(0);
content->Fill(theme.Color(clrBorder));
content->DrawRectangle(cRect(2,2,width-4, height-4), theme.Color(clrBackground));
int textWidth = 0;
for (int i=0; i<textLines; i++) {
textWidth = tvguideConfig.FontMessageBox->Width(message.GetLine(i));
content->DrawText(cPoint((width - textWidth)/2, 20 + i*textHeight), message.GetLine(i), theme.Color(clrFont), clrTransparent, tvguideConfig.FontMessageBox);
}
cPixmap::Unlock();
msgboxThread->Start();
2013-01-17 13:16:44 +01:00
return true;
2013-05-26 11:38:05 +02:00
}
return false;
2013-01-17 13:16:44 +01:00
}
void cMessageBox::Stop(void) {
2013-05-26 11:38:05 +02:00
if (msgboxThread) {
delete msgboxThread;
msgboxThread = NULL;
}
2013-01-17 13:16:44 +01:00
}
void cMessageBox::Destroy(void) {
2013-05-26 11:38:05 +02:00
if (msgboxThread) {
delete msgboxThread;
msgboxThread = NULL;
}
if (content) {
osdManager.releasePixmap(content);
content = NULL;
}
2013-01-17 13:16:44 +01:00
}