fix
[enigma2.git] / lib / gui / elabel.cpp
index f9dcf31b378a4a94dd609f300d0c60ec6440d58b..17239fbcb46a9f3b98412d32c8ff1d490fc4d6fe 100644 (file)
@@ -1,8 +1,18 @@
 #include <lib/gui/elabel.h>
+#include <lib/gdi/font.h>
 
 eLabel::eLabel(eWidget *parent): eWidget(parent)
 {
+       ePtr<eWindowStyle> style;
+       getStyle(style);
        
+       style->getFont(eWindowStyle::fontStatic, m_font);
+       
+               /* default to topleft alignment */
+       m_valign = alignTop;
+       m_halign = alignLeft;
+       
+       m_have_foreground_color = 0;
 }
 
 int eLabel::event(int event, void *data, void *data2)
@@ -18,14 +28,37 @@ int eLabel::event(int event, void *data, void *data2)
                eWidget::event(event, data, data2);
 
                gPainter &painter = *(gPainter*)data2;
-               ePtr<gFont> fnt = new gFont("Arial", 14);
-               painter.setFont(fnt);
-               style->setForegroundStyle(painter);
-               painter.renderText(eRect(0, 0, size().width(), size().height()), m_text);
+               painter.setFont(m_font);
+               style->setStyle(painter, eWindowStyle::styleLabel);
+               
+               if (m_have_foreground_color)
+                       painter.setForegroundColor(m_foreground_color);
+               
+               int flags = 0;
+               if (m_valign == alignTop)
+                       flags |= gPainter::RT_VALIGN_TOP;
+               else if (m_valign == alignCenter)
+                       flags |= gPainter::RT_VALIGN_CENTER;
+               else if (m_valign == alignBottom)
+                       flags |= gPainter::RT_VALIGN_BOTTOM;
+
+               if (m_halign == alignLeft)
+                       flags |= gPainter::RT_HALIGN_LEFT;
+               else if (m_halign == alignCenter)
+                       flags |= gPainter::RT_HALIGN_CENTER;
+               else if (m_halign == alignRight)
+                       flags |= gPainter::RT_HALIGN_RIGHT;
+               else if (m_halign == alignBlock)
+                       flags |= gPainter::RT_HALIGN_BLOCK;
+               
+               flags |= gPainter::RT_WRAP;
+               painter.renderText(eRect(0, 0, size().width(), size().height()), m_text, flags);
                
                return 0;
        }
+       case evtChangedFont:
        case evtChangedText:
+       case evtChangedAlignment:
                invalidate();
                return 0;
        default:
@@ -40,3 +73,48 @@ void eLabel::setText(const std::string &string)
        m_text = string;
        event(evtChangedText);
 }
+
+void eLabel::setFont(gFont *font)
+{
+       m_font = font;
+       event(evtChangedFont);
+}
+
+gFont* eLabel::getFont()
+{
+       return m_font;
+}
+
+void eLabel::setVAlign(int align)
+{
+       m_valign = align;
+       event(evtChangedAlignment);
+}
+
+void eLabel::setHAlign(int align)
+{
+       m_halign = align;
+       event(evtChangedAlignment);
+}
+
+void eLabel::setForegroundColor(const gRGB &col)
+{
+       m_foreground_color = col;
+       m_have_foreground_color = 1;
+}
+
+void eLabel::clearForegroundColor()
+{
+       m_have_foreground_color = 0;
+}
+
+eSize eLabel::calculateSize()
+{
+       ePtr<eTextPara> p = new eTextPara(eRect(0, 0, size().width(), size().height()));
+       
+       p->setFont(m_font);
+       p->renderString(m_text, RS_WRAP);
+       
+       eRect bbox = p->getBoundBox();
+       return bbox.size();
+}