X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/241e6d3da33580a6051a0ef4fa2590f2ae4fa9d0..ebd1552cdd3e60d5eb21f97e46570de2e17ed19f:/lib/gui/elabel.cpp diff --git a/lib/gui/elabel.cpp b/lib/gui/elabel.cpp index 5b1c5b0b..018ce95b 100644 --- a/lib/gui/elabel.cpp +++ b/lib/gui/elabel.cpp @@ -1,8 +1,9 @@ #include #include -eLabel::eLabel(eWidget *parent): eWidget(parent) +eLabel::eLabel(eWidget *parent, int markedPos): eWidget(parent) { + m_pos = markedPos; ePtr style; getStyle(style); @@ -28,37 +29,65 @@ int eLabel::event(int event, void *data, void *data2) eWidget::event(event, data, data2); gPainter &painter = *(gPainter*)data2; - 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_pos != -1) + { + style->setStyle(painter, eWindowStyle::styleLabel); + ePtr para = new eTextPara(eRect(0, 0, size().width(), size().height())); + para->setFont(m_font); + para->renderString(m_text, 0); + para->realign(eTextPara::dirLeft); + int glyphs = para->size(); - 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; + if ((m_pos < 0) || (m_pos >= glyphs)) + eWarning("glyph index %d in eLabel out of bounds!", m_pos); + else + { + para->setGlyphFlag(m_pos, GS_INVERT); + eRect bbox; + bbox = para->getGlyphBBox(m_pos); + bbox = eRect(bbox.left(), 0, bbox.width(), size().height()); + painter.fill(bbox); + } + + painter.renderPara(para, ePoint(0, 0)); + return 0; + } + else + { + 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: + case evtChangedMarkedPos: invalidate(); return 0; default: @@ -74,12 +103,23 @@ void eLabel::setText(const std::string &string) event(evtChangedText); } +void eLabel::setMarkedPos(int markedPos) +{ + m_pos = markedPos; + event(evtChangedMarkedPos); +} + void eLabel::setFont(gFont *font) { m_font = font; event(evtChangedFont); } +gFont* eLabel::getFont() +{ + return m_font; +} + void eLabel::setVAlign(int align) { m_valign = align; @@ -94,13 +134,21 @@ void eLabel::setHAlign(int align) void eLabel::setForegroundColor(const gRGB &col) { - m_foreground_color = col; - m_have_foreground_color = 1; + if ((!m_have_foreground_color) || !(m_foreground_color == col)) + { + m_foreground_color = col; + m_have_foreground_color = 1; + invalidate(); + } } void eLabel::clearForegroundColor() { - m_have_foreground_color = 0; + if (m_have_foreground_color) + { + m_have_foreground_color = 0; + invalidate(); + } } eSize eLabel::calculateSize()