dont ignore background color when transparent=1 is set.. (needed for font
[enigma2.git] / lib / gui / elabel.cpp
index 018ce95b521cfe2b342eefa3c94b146a486f3e08..6e53c851ba6434fbb136fec3828aac00183bf9f5 100644 (file)
@@ -14,6 +14,9 @@ eLabel::eLabel(eWidget *parent, int markedPos): eWidget(parent)
        m_halign = alignLeft;
        
        m_have_foreground_color = 0;
+       m_have_shadow_color = 0;
+       
+       m_nowrap = 0;
 }
 
 int eLabel::event(int event, void *data, void *data2)
@@ -35,8 +38,17 @@ int eLabel::event(int event, void *data, void *data2)
                        style->setStyle(painter, eWindowStyle::styleLabel);
                        ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height()));
                        para->setFont(m_font);
-                       para->renderString(m_text, 0);
-                       para->realign(eTextPara::dirLeft);
+                       para->renderString(m_text.empty()?0:m_text.c_str(), 0);
+
+                       if (m_halign == alignLeft)
+                               para->realign(eTextPara::dirLeft);
+                       else if (m_halign == alignCenter)
+                               para->realign(eTextPara::dirCenter);
+                       else if (m_halign == alignRight)
+                               para->realign(eTextPara::dirRight);
+                       else if (m_halign == alignBlock)
+                               para->realign(eTextPara::dirBlock);
+
                        int glyphs = para->size();
 
                        if ((m_pos < 0) || (m_pos >= glyphs))
@@ -52,13 +64,14 @@ int eLabel::event(int event, void *data, void *data2)
 
                        painter.renderPara(para, ePoint(0, 0));
                        return 0;
-               }
-               else
-               {               
+               } else
+               {
                        painter.setFont(m_font);
                        style->setStyle(painter, eWindowStyle::styleLabel);
                        
-                       if (m_have_foreground_color)
+                       if (m_have_shadow_color)
+                               painter.setForegroundColor(m_shadow_color);
+                       else if (m_have_foreground_color)
                                painter.setForegroundColor(m_foreground_color);
                        
                        int flags = 0;
@@ -78,8 +91,21 @@ int eLabel::event(int event, void *data, void *data2)
                        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);
+                       if (!m_nowrap)
+                               flags |= gPainter::RT_WRAP;
+                       
+                               /* if we don't have shadow, m_shadow_offset will be 0,0 */
+                       painter.renderText(eRect(-m_shadow_offset.x(), -m_shadow_offset.y(), size().width(), size().height()), m_text, flags);
+                       
+                       if (m_have_shadow_color)
+                       {
+                               if (!m_have_foreground_color)
+                                       style->setStyle(painter, eWindowStyle::styleLabel);
+                               else
+                                       painter.setForegroundColor(m_foreground_color);
+                               painter.setBackgroundColor(m_shadow_color);
+                               painter.renderText(eRect(0, 0, size().width(), size().height()), m_text, flags);
+                       }
                        
                        return 0;
                }
@@ -142,6 +168,30 @@ void eLabel::setForegroundColor(const gRGB &col)
        }
 }
 
+void eLabel::setShadowColor(const gRGB &col)
+{
+       if ((!m_have_shadow_color) || !(m_shadow_color == col))
+       {
+               m_shadow_color = col;
+               m_have_shadow_color = 1;
+               invalidate();
+       }
+}
+
+void eLabel::setShadowOffset(const ePoint &offset)
+{
+       m_shadow_offset = offset;
+}
+
+void eLabel::setNoWrap(int nowrap)
+{
+       if (m_nowrap != nowrap)
+       {
+               m_nowrap = nowrap;
+               invalidate();
+       }
+}
+
 void eLabel::clearForegroundColor()
 {
        if (m_have_foreground_color)
@@ -156,7 +206,7 @@ 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);
+       p->renderString(m_text.empty()?0:m_text.c_str(), m_nowrap ? 0 : RS_WRAP);
        
        eRect bbox = p->getBoundBox();
        return bbox.size();