/* * Copyright (C) 2006-2009 Alex Lasnier * * This file is part of Radio Info * * 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 2 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 * along with this program. If not, see . */ #include #include #include #include "osd.h" #include "tools.h" #include "config.h" #include "images/header.xpm" #include "images/notes.xpm" /////////////////////////////////////////////////////////////////////////////// #define HEIGHT 300 cBitmap cRadioInfoOsd::header(radioinfobg_xpm); cBitmap cRadioInfoOsd::notes(notes_xpm); /////////////////////////////////////////////////////////////////////////////// cRadioInfoOsd::cRadioInfoOsd(cRadioInfoData* Ri) : cThread("RadioInfo OSD"), canvas(520, HEIGHT, 2) { dprint(L_OSD, "Creating OSD"); rOsd = NULL; radioInfoData = Ri; font = cFont::GetFont(fontOsd); canvas.SetColor(0, clrTransparent); canvas.SetColor(1, (tColor) 0xFF6F649A); canvas.SetColor(2, (tColor) 0xFF625584); canvas.SetColor(3, clrWhite); header.SetColor(0, clrTransparent); header.SetColor(1, (tColor) 0xFF6F649A); header.SetColor(2, (tColor) 0xFF625584); header.SetColor(3, clrWhite); notes.SetColor(0, clrWhite); notes.SetColor(1, (tColor) 0xFF6F649A); offsetY = 50; offsetX = 100; dirY = 1; eventName = NULL; GetEventName(); //TODO: Event name should be updated... Show(); Start(); } //----------------------------------------------------------------------------- cRadioInfoOsd::~cRadioInfoOsd() { dprint(L_OSD, "Killing OSD"); Stop(); cMutexLock ml(&osdMutex); delete rOsd; rOsd = NULL; } //----------------------------------------------------------------------------- void cRadioInfoOsd::Stop(void) { Cancel(-1); condWait.Signal(); } //----------------------------------------------------------------------------- void cRadioInfoOsd::Show(void) { cMutexLock ml(&osdMutex); rOsd = cOsdProvider::NewOsd(0, 0, 15); tArea Area = { 0, 0, 719, 479, 2 }; if (rOsd) { eOsdError e = rOsd->CanHandleAreas(&Area, 1); if (e != oeOk) { dprint(L_ERR, "RadioInfo: OSD Error (#%d) %s\n", e, OsdErrorToString(e)); return; } rOsd->SetAreas(&Area, 1); Draw(); } else dprint(L_ERR, "RadioInfo: Could not create OSD\n"); } //----------------------------------------------------------------------------- void cRadioInfoOsd::Action(void) { while( Running() ) { condWait.Wait(1000*config.osdDelay); if (!Running()) break; if (offsetY + HEIGHT == 479) dirY = -1; if (offsetY == 50) dirY = 1; offsetY += dirY; cMutexLock ml(&osdMutex); Draw(); } } //----------------------------------------------------------------------------- void cRadioInfoOsd::Draw(void) { if (!rOsd) return; rOsd->DrawRectangle(0, 0, 719, 479, clrTransparent); canvas.DrawRectangle(0, 0, 520, HEIGHT, clrTransparent); canvas.DrawBitmap(0, 0, header); canvas.DrawText(52, 0, eventName, clrWhite, clrTransparent, font, 447, 51, taCenter); radioInfoData->Lock(); if (radioInfoData->newSong) canvas.DrawBitmap(0, 0, notes); if (strncmp("Title:", radioInfoData->infoData[0], 6) == 0) { int w = max(font->Width("Artist"), font->Width("Label")); canvas.DrawText(65, 80, "Title", clrWhite, clrTransparent, font); canvas.DrawText(65, 110, "Artist", clrWhite, clrTransparent, font); canvas.DrawText(65, 140, "CD", clrWhite, clrTransparent, font); canvas.DrawText(65, 170, "Label", clrWhite, clrTransparent, font); canvas.DrawText(70+w, 80, radioInfoData->infoData[0]+5, clrWhite, clrTransparent, font); canvas.DrawText(70+w, 110, radioInfoData->infoData[1]+6, clrWhite, clrTransparent, font); canvas.DrawText(70+w, 140, radioInfoData->infoData[2]+2, clrWhite, clrTransparent, font); canvas.DrawText(70+w, 170, radioInfoData->infoData[3]+5, clrWhite, clrTransparent, font); } else { for (int i=0; iinfoData[i], clrWhite, clrTransparent, font); } radioInfoData->Unlock(); rOsd->DrawBitmap(offsetX, offsetY, canvas); rOsd->Flush(); } //----------------------------------------------------------------------------- void cRadioInfoOsd::GetEventName(void) { cChannel* c = Channels.GetByNumber(cDevice::CurrentChannel()); cSchedulesLock SchedulesLock; const cSchedules* Schedules = cSchedules::Schedules(SchedulesLock); const cSchedule* schedule = Schedules->GetSchedule(c->GetChannelID()); const cEvent* event = NULL; if (schedule) event = schedule->GetPresentEvent(); eventName = event ? event->Title() : "No Title"; } ///////////////////////////////////////////////////////////////////////////////