better marking of current cursor in Components.Input
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 19 Jan 2006 03:19:41 +0000 (03:19 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 19 Jan 2006 03:19:41 +0000 (03:19 +0000)
change eLabel to being able to mark a character

lib/gui/elabel.cpp
lib/gui/elabel.h
lib/python/Components/Input.py
lib/python/Components/VariableText.py
lib/python/Plugins/test/plugin.py

index 17239fb..970669c 100644 (file)
@@ -1,8 +1,9 @@
 #include <lib/gui/elabel.h>
 #include <lib/gdi/font.h>
 
 #include <lib/gui/elabel.h>
 #include <lib/gdi/font.h>
 
-eLabel::eLabel(eWidget *parent): eWidget(parent)
+eLabel::eLabel(eWidget *parent, int markedPos): eWidget(parent)
 {
 {
+       m_pos = markedPos;
        ePtr<eWindowStyle> style;
        getStyle(style);
        
        ePtr<eWindowStyle> 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;
                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<eTextPara> 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 evtChangedFont:
        case evtChangedText:
        case evtChangedAlignment:
+       case evtChangedMarkedPos:
                invalidate();
                return 0;
        default:
                invalidate();
                return 0;
        default:
@@ -74,6 +98,12 @@ void eLabel::setText(const std::string &string)
        event(evtChangedText);
 }
 
        event(evtChangedText);
 }
 
+void eLabel::setMarkedPos(int markedPos)
+{
+       m_pos = markedPos;
+       event(evtChangedMarkedPos);
+}
+
 void eLabel::setFont(gFont *font)
 {
        m_font = font;
 void eLabel::setFont(gFont *font)
 {
        m_font = font;
index f3d280a..df57e7b 100644 (file)
@@ -6,8 +6,9 @@
 class eLabel: public eWidget
 {
 public:
 class eLabel: public eWidget
 {
 public:
-       eLabel(eWidget *parent);
+       eLabel(eWidget *parent, int markedPos = -1);
        void setText(const std::string &string);
        void setText(const std::string &string);
+       void setMarkedPos(int markedPos);
        void setFont(gFont *font);
        gFont* eLabel::getFont();
 
        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_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;
 private:
        int m_have_foreground_color;
        gRGB m_foreground_color;
@@ -41,7 +43,8 @@ private:
        {
                evtChangedText = evtUserWidget,
                evtChangedFont,
        {
                evtChangedText = evtUserWidget,
                evtChangedFont,
-               evtChangedAlignment
+               evtChangedAlignment,
+               evtChangedMarkedPos
        };
 };
 
        };
 };
 
index d3b0661..7ffc5c7 100644 (file)
@@ -16,10 +16,13 @@ class Input(HTMLComponent, GUIComponent, VariableText):
                self.update()
 
        def update(self):
                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):
        
        def createWidget(self, parent):
-               return eLabel(parent)
+               return eLabel(parent, self.currPos)
        
        def getSize(self):
                s = self.instance.calculateSize()
        
        def getSize(self):
                s = self.instance.calculateSize()
index 76dc201..e2a755c 100644 (file)
@@ -12,6 +12,10 @@ class VariableText:
                if self.instance:
                        self.instance.setText(self.message)
 
                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
        
        def getText(self):
                return self.message
        
index c08a986..d85a80c 100644 (file)
@@ -11,7 +11,7 @@ import os
 class Test(Screen):
        skin = """
                <screen position="100,100" size="550,400" title="Test" >
 class Test(Screen):
        skin = """
                <screen position="100,100" size="550,400" title="Test" >
-                       <widget name="text" position="0,0" size="550,400" font="Regular;20" />
+                       <widget name="text" position="0,0" size="550,25" font="Regular;20" />
                </screen>"""
                
        def __init__(self, session, args = None):
                </screen>"""
                
        def __init__(self, session, args = None):