- fixed blit in gRC
[enigma2.git] / lib / gdi / grc.cpp
index cb2a6de99006bff34f2755c9ef60741df3e1582c..3b5476a2ba85df4b51e7621f2a70d2708fc4ce2c 100644 (file)
@@ -1,5 +1,5 @@
 // for debugging use:
- #define SYNC_PAINT
+// #define SYNC_PAINT
 #include <unistd.h>
 #ifndef SYNC_PAINT
 #include <pthread.h>
@@ -188,7 +188,7 @@ void gPainter::clear()
 void gPainter::blit(gPixmap *pixmap, ePoint pos, const eRect &clip, int flags)
 {
        gOpcode o;
-
+       
        o.opcode=gOpcode::blit;
        o.dc = m_dc.grabRef();
        pixmap->AddRef();
@@ -302,6 +302,10 @@ void gPainter::clippop()
 
 void gPainter::flush()
 {
+       gOpcode o;
+       o.opcode = gOpcode::flush;
+       o.dc = m_dc.grabRef();
+       m_rc->submit(o);
 }
 
 void gPainter::end()
@@ -340,10 +344,26 @@ void gDC::exec(gOpcode *o)
        case gOpcode::renderText:
        {
                ePtr<eTextPara> para = new eTextPara(o->parm.renderText->area);
+               int flags = o->parm.renderText->flags;
                assert(m_current_font);
                para->setFont(m_current_font);
-               para->renderString(o->parm.renderText->text, o->parm.renderText->flags);
-               para->blit(*this, m_current_offset, getRGB(m_background_color), getRGB(m_foreground_color));
+               para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0);
+               
+               if (flags & gPainter::RT_HALIGN_RIGHT)
+                       para->realign(eTextPara::dirRight);
+               else if (flags & gPainter::RT_HALIGN_CENTER)
+                       para->realign(eTextPara::dirCenter);
+               else if (flags & gPainter::RT_HALIGN_BLOCK)
+                       para->realign(eTextPara::dirBlock);
+               
+               ePoint offset = m_current_offset;
+               
+               if (o->parm.renderText->flags & gPainter::RT_VALIGN_CENTER)
+               {
+                       eRect bbox = para->getBoundBox();
+                       offset += ePoint(0, (o->parm.renderText->area.height() - bbox.height()) / 2);
+               }
+               para->blit(*this, offset, getRGB(m_background_color), getRGB(m_foreground_color));
                delete o->parm.renderText;
                break;
        }
@@ -378,11 +398,16 @@ void gDC::exec(gOpcode *o)
        case gOpcode::blit:
        {
                gRegion clip;
-               if (!o->parm.blit->clip.valid())
+                               // this code should be checked again but i'm too tired now
+               
+               o->parm.blit->position += m_current_offset;
+               
+               if (o->parm.blit->clip.valid())
                {
                        clip.intersect(gRegion(o->parm.blit->clip), clip);
                } else
                        clip = m_current_clip;
+               
                m_pixmap->blit(*o->parm.blit->pixmap, o->parm.blit->position, clip, o->parm.blit->flags);
                o->parm.blit->pixmap->Release();
                delete o->parm.blit;
@@ -439,6 +464,8 @@ void gDC::exec(gOpcode *o)
                        m_current_offset  = o->parm.setOffset->value;
                delete o->parm.setOffset;
                break;
+       case gOpcode::flush:
+               break;
        default:
                eFatal("illegal opcode %d. expect memory leak!", o->opcode);
        }