add subtitle widget
[enigma2.git] / lib / gui / esubtitle.cpp
1 #include <lib/gui/esubtitle.h>
2 #include <lib/gdi/grc.h>
3
4         /*
5                 ok, here's much room for improvements.
6         
7                 first, the placing of the individual elements is sub-optimal.
8                 then maybe a colored background would be an option.
9                 ....
10         */      
11
12 eSubtitleWidget::eSubtitleWidget(eWidget *parent)
13         : eWidget(parent)
14 {
15         setBackgroundColor(gRGB(0,0,0,255));
16 }
17
18 void eSubtitleWidget::addPage(const eDVBTeletextSubtitlePage &p)
19 {
20         eDebug("ADD Subtitle Page!!");
21         m_pages.clear();
22         m_pages.push_back(p);
23         checkTiming();
24 }
25
26 void eSubtitleWidget::checkTiming()
27 {
28         activatePage();
29 }
30
31 void eSubtitleWidget::activatePage()
32 {
33         invalidate();
34 }
35
36 int eSubtitleWidget::event(int event, void *data, void *data2)
37 {
38         switch (event)
39         {
40         case evtPaint:
41         {
42                 ePtr<eWindowStyle> style;
43                 gPainter &painter = *(gPainter*)data2;
44
45                 getStyle(style);
46                 
47                 eWidget::event(event, data, data2);
48                 ePtr<gFont> font = new gFont("Regular", 30);
49                 painter.setFont(font);
50                 
51                 std::list<eDVBTeletextSubtitlePage>::iterator pi = m_pages.begin();
52                 if (pi == m_pages.end())
53                         painter.renderText(eRect(ePoint(0, 0), size()), "waiting for subtitles...", gPainter::RT_WRAP);
54                 else
55                 {
56                         const eDVBTeletextSubtitlePage &page = *pi;
57                         int elements = page.m_elements.size();
58                         int height = size().height();
59                         int size_per_element = height / (elements ? elements : 1);
60                         for (int i=0; i<elements; ++i)
61                         {
62                                 painter.setForegroundColor(gRGB(0,0,0));
63                                 painter.renderText(eRect(2, size_per_element * i + 2, size().width(), size_per_element), page.m_elements[i].m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
64                                 painter.setForegroundColor(page.m_elements[i].m_color);
65                                 painter.renderText(eRect(0, size_per_element * i, size().width(), size_per_element), page.m_elements[i].m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
66                         }
67                 }
68                 return 0;
69         }
70         default:
71                 return eWidget::event(event, data, data2);
72         }
73 }