1 #include <lib/gui/esubtitle.h>
2 #include <lib/gdi/grc.h>
3 #include <lib/base/estring.h>
6 ok, here's much room for improvements.
8 first, the placing of the individual elements is sub-optimal.
9 then maybe a colored background would be an option.
13 eSubtitleWidget::eSubtitleWidget(eWidget *parent)
14 : eWidget(parent), m_hide_subtitles_timer(eApp)
16 setBackgroundColor(gRGB(0,0,0,255));
19 CONNECT(m_hide_subtitles_timer.timeout, eSubtitleWidget::clearPage);
23 void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
27 invalidate(m_visible_region); // invalidate old visible regions
28 m_visible_region.rects.clear();
30 int elements = m_page.m_elements.size();
33 int startY = elements > 1
35 : size().height() / 3 * 2;
36 int width = size().width() - startX * 2;
37 int height = size().height() - startY;
38 int size_per_element = height / (elements ? elements : 1);
39 for (int i=0; i<elements; ++i)
41 eRect &area = m_page.m_elements[i].m_area;
43 area.setTop(size_per_element * i + startY);
45 area.setHeight(size_per_element);
46 m_visible_region.rects.push_back(area);
49 m_hide_subtitles_timer.start(7500, true);
50 invalidate(m_visible_region); // invalidate new regions
53 void eSubtitleWidget::setPage(const eDVBSubtitlePage &p)
56 invalidate(m_visible_region); // invalidate old visible regions
57 m_visible_region.rects.clear();
58 for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
59 m_visible_region.rects.push_back(eRect(it->m_position, it->m_pixmap->size()));
61 m_hide_subtitles_timer.start(7500, true);
62 invalidate(m_visible_region); // invalidate new regions
65 void eSubtitleWidget::clearPage()
67 eDebug("subtitle timeout... hide");
70 invalidate(m_visible_region);
71 m_visible_region.rects.clear();
74 int eSubtitleWidget::event(int event, void *data, void *data2)
80 ePtr<eWindowStyle> style;
81 gPainter &painter = *(gPainter*)data2;
85 eWidget::event(event, data, data2);
86 ePtr<gFont> font = new gFont("Regular", 38);
87 painter.setFont(font);
91 int elements = m_page.m_elements.size();
92 for (int i=0; i<elements; ++i)
94 eDVBTeletextSubtitlePageElement &element = m_page.m_elements[i];
95 eRect &area = element.m_area;
98 painter.setForegroundColor(gRGB(0,0,0));
99 painter.renderText(shadow, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
100 painter.setForegroundColor(element.m_color);
101 painter.renderText(area, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
104 else if (m_dvb_page_ok)
106 for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
107 painter.blit(it->m_pixmap, it->m_position);
112 return eWidget::event(event, data, data2);