From: Stefan Pluecken Date: Thu, 19 Jan 2006 03:19:41 +0000 (+0000) Subject: better marking of current cursor in Components.Input X-Git-Tag: 2.6.0~4369 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/b4448ddb042e5f5015125597633e368f17acbcec better marking of current cursor in Components.Input change eLabel to being able to mark a character --- diff --git a/lib/gui/elabel.cpp b/lib/gui/elabel.cpp index 17239fbc..970669c1 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,60 @@ 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); - 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; + para->setGlyphFlag(m_pos, GS_INVERT); + eRect bbox; + bbox = para->getGlyphBBox(m_pos); + printf("BBOX: %d %d %d %d\n", bbox.left(), 0, bbox.width(), size().height()); + 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,6 +98,12 @@ 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; diff --git a/lib/gui/elabel.h b/lib/gui/elabel.h index f3d280ae..df57e7b5 100644 --- a/lib/gui/elabel.h +++ b/lib/gui/elabel.h @@ -6,8 +6,9 @@ class eLabel: public eWidget { public: - eLabel(eWidget *parent); + eLabel(eWidget *parent, int markedPos = -1); void setText(const std::string &string); + void setMarkedPos(int markedPos); void setFont(gFont *font); gFont* eLabel::getFont(); @@ -33,6 +34,7 @@ protected: int m_valign, m_halign; std::string m_text; int event(int event, void *data=0, void *data2=0); + int m_pos; private: int m_have_foreground_color; gRGB m_foreground_color; @@ -41,7 +43,8 @@ private: { evtChangedText = evtUserWidget, evtChangedFont, - evtChangedAlignment + evtChangedAlignment, + evtChangedMarkedPos }; }; diff --git a/lib/python/Components/Input.py b/lib/python/Components/Input.py index d3b06612..7ffc5c77 100644 --- a/lib/python/Components/Input.py +++ b/lib/python/Components/Input.py @@ -16,10 +16,13 @@ class Input(HTMLComponent, GUIComponent, VariableText): self.update() def update(self): - self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:]) + self.setMarkedPos(self.currPos) + self.setText(self.text) + #self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:]) + def createWidget(self, parent): - return eLabel(parent) + return eLabel(parent, self.currPos) def getSize(self): s = self.instance.calculateSize() diff --git a/lib/python/Components/VariableText.py b/lib/python/Components/VariableText.py index 76dc201a..e2a755c5 100644 --- a/lib/python/Components/VariableText.py +++ b/lib/python/Components/VariableText.py @@ -12,6 +12,10 @@ class VariableText: if self.instance: self.instance.setText(self.message) + def setMarkedPos(self, pos): + if self.instance: + self.instance.setMarkedPos(int(pos)) + def getText(self): return self.message diff --git a/lib/python/Plugins/test/plugin.py b/lib/python/Plugins/test/plugin.py index c08a986f..d85a80c9 100644 --- a/lib/python/Plugins/test/plugin.py +++ b/lib/python/Plugins/test/plugin.py @@ -11,7 +11,7 @@ import os class Test(Screen): skin = """ - + """ def __init__(self, session, args = None):