1 #include <lib/gui/elabel.h>
3 #include <lib/gdi/fb.h>
4 #include <lib/gdi/font.h>
5 #include <lib/gdi/lcd.h>
6 #include <lib/gui/eskin.h>
7 #include <lib/base/init.h>
8 #include <lib/base/init_num.h>
10 eLabel::eLabel(eWidget *parent, int flags, int takefocus, const char *deco ):
11 eDecoWidget(parent, takefocus, deco), blitFlags(0), flags(flags),
12 para(0), align( eTextPara::dirLeft ), shortcutPixmap(0)
25 void eLabel::setPixmapPosition( const ePoint &p )
31 void eLabel::validate( const eSize* s )
36 para=new eTextPara( eRect(text_position.x(), text_position.y(), s->width() - text_position.x(), s->height() - text_position.y()));
38 para=new eTextPara( eRect(text_position.x(), text_position.y(), size.width() - text_position.x(), size.height() - text_position.y()));
41 para->renderString(text, flags);
46 void eLabel::invalidate()
54 eDecoWidget::invalidate(); // we must redraw...
57 void eLabel::setFlags(int flag)
64 void eLabel::setBlitFlags( int flags )
69 void eLabel::removeFlags(int flag)
76 void eLabel::setAlign(int align)
82 void eLabel::redrawWidget(gPainter *target, const eRect &rc)
84 /* eDebug("decoStr = %s, text=%s, name=%s, %p left = %d, top = %d, width=%d, height = %d", strDeco?strDeco.c_str():"no", text?text.c_str():"no" , name?name.c_str():"no", this, this->getPosition().x(), this->getPosition().y(), this->getSize().width(), this->getSize().height() );
85 eDebug("renderContext left = %d, top = %d, width = %d, height = %d", rc.left(), rc.top(), rc.width(), rc.height() );*/
87 target->clip( gRegion(rc) );
88 eRect area=eRect(ePoint(0, 0), ePoint(width(), height()));
89 /* eDebug("area left = %d, top = %d, width = %d, height = %d",
90 area.left(), area.top(),
91 area.width(), area.height() );*/
93 if (deco_selected && have_focus)
95 deco_selected.drawDecoration(target, ePoint(width(), height()));
99 deco.drawDecoration(target, ePoint(width(), height()));
102 /* eDebug("area left = %d, top = %d, width = %d, height = %d",
103 area.left(), area.top(),
104 area.width(), area.height() );*/
108 //area.setWidth(area.width()-area.height());
109 area.setX(area.height());
114 if ( area.size().height() < size.height() ||
115 area.size().width() < size.width() )
117 // then deco is drawed
123 if (flags & flagVCenter)
124 yOffs = ( (area.height() - para->getBoundBox().height() ) / 2 + 0) - para->getBoundBox().top();
129 if ((blitFlags & BF_ALPHATEST) && (transparentBackgroundColor >= 0))
132 target->setBackgroundColor(transparentBackgroundColor);
135 w=getNonTransparentBackground();
136 target->setBackgroundColor(w->getBackgroundColor());
138 target->setFont(font);
139 target->renderPara(para, ePoint( area.left(), area.top()+yOffs) );
143 // eDebug("blit pixmap area left=%d, top=%d, right=%d, bottom=%d", rc.left(), rc.top(), rc.right(), rc.bottom() );
144 // eDebug("pixmap_pos x = %d, y = %d, xsize=%d, ysize=%d", pixmap_position.x(), pixmap_position.y(), pixmap->x, pixmap->y );
145 target->blit(pixmap, shortcutPixmap?pixmap_position+ePoint( area.left(), 0):pixmap_position, area, (blitFlags & BF_ALPHATEST) ? gPixmap::blitAlphaTest : 0);
148 target->blit(shortcutPixmap,
149 ePoint((area.height()-shortcutPixmap->getSize().width())/2, area.top()+(area.height()-shortcutPixmap->getSize().height())/2),
151 gPixmap::blitAlphaTest);
155 int eLabel::eventHandler(const eWidgetEvent &event)
159 case eWidgetEvent::changedFont:
160 case eWidgetEvent::changedText:
166 if ( have_focus && deco_selected )
167 eDecoWidget::invalidate( crect_selected );
169 eDecoWidget::invalidate( crect );
171 eDecoWidget::invalidate();
174 case eWidgetEvent::changedSize:
179 return eDecoWidget::eventHandler(event);
185 eSize eLabel::getExtend()
188 return eSize(para->getBoundBox().width()+(shortcutPixmap?shortcutPixmap->x*2:0), para->getBoundBox().height());
191 ePoint eLabel::getLeftTop()
194 return ePoint(para->getBoundBox().left(), para->getBoundBox().top());
197 int eLabel::setProperty(const eString &prop, const eString &value)
199 if (prop=="wrap" && value == "on")
201 else if (prop=="alphatest" && value == "on")
203 transparentBackgroundColor=getBackgroundColor();
204 setBackgroundColor(-1);
205 blitFlags |= BF_ALPHATEST;
206 } else if (prop=="align")
209 setAlign(eTextPara::dirLeft);
210 else if (value=="center")
211 setAlign(eTextPara::dirCenter);
212 else if (value=="right")
213 setAlign(eTextPara::dirRight);
214 else if (value=="block")
215 setAlign(eTextPara::dirBlock);
217 setAlign(eTextPara::dirLeft);
219 else if (prop=="vcenter")
220 setFlags( flagVCenter );
221 else if (prop == "shortcut")
223 setShortcutPixmap(value);
224 return eWidget::setProperty(prop, value);
226 return eDecoWidget::setProperty(prop, value);
230 void eLabel::setShortcutPixmap(const eString &shortcut)
232 eSkin::getActive()->queryImage(shortcutPixmap, "shortcut." + shortcut);
235 static eWidget *create_eLabel(eWidget *parent)
237 return new eLabel(parent);
245 eSkin::addWidgetCreator("eLabel", create_eLabel);
249 eSkin::removeWidgetCreator("eLabel", create_eLabel);
253 eAutoInitP0<eLabelSkinInit> init_eLabelSkinInit(eAutoInitNumbers::guiobject, "eLabel");