From bf82503dcba2b12fc921040397a0387d6dea9dbb Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Mon, 28 Nov 2005 02:32:59 +0000 Subject: [PATCH] gui: add transparent widgets --- data/skin.xml | 6 +++--- lib/gui/ewidget.cpp | 37 +++++++++++++++++++++++++------------ lib/gui/ewidget.h | 3 +++ lib/gui/ewidgetdesktop.cpp | 27 +++++++++++++++++++-------- skin.py | 2 ++ 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/data/skin.xml b/data/skin.xml index f36874b2..1aa5da09 100644 --- a/data/skin.xml +++ b/data/skin.xml @@ -32,7 +32,7 @@ - """ """ + @@ -143,7 +143,7 @@ - + @@ -161,7 +161,7 @@ - + diff --git a/lib/gui/ewidget.cpp b/lib/gui/ewidget.cpp index b047f5fb..b4c24d86 100644 --- a/lib/gui/ewidget.cpp +++ b/lib/gui/ewidget.cpp @@ -177,6 +177,14 @@ void eWidget::setZPosition(int z) insertIntoParent(); /* now at the new Z position */ } +void eWidget::setTransparent(int transp) +{ + if (transp) + m_vis |= wVisTransparent; + else + m_vis &=~wVisTransparent; +} + void eWidget::mayKillFocus() { setFocus(0); @@ -224,14 +232,11 @@ void eWidget::doPaint(gPainter &painter, const gRegion &r) if (m_visible_with_childs.empty()) return; - gRegion region = r; + gRegion region = r, childs = r; /* we were in parent's space, now we are in local space */ region.moveBy(-position()); painter.moveOffset(position()); - /* walk all childs */ - for (ePtrList::iterator i(m_childs.begin()); i != m_childs.end(); ++i) - i->doPaint(painter, region); /* check if there's anything for us to paint */ region &= m_visible_region; @@ -241,6 +246,11 @@ void eWidget::doPaint(gPainter &painter, const gRegion &r) painter.resetClip(region); event(evtPaint, ®ion, &painter); } + + childs.moveBy(-position()); + /* walk all childs */ + for (ePtrList::iterator i(m_childs.begin()); i != m_childs.end(); ++i) + i->doPaint(painter, childs); painter.moveOffset(-position()); } @@ -272,15 +282,18 @@ int eWidget::event(int event, void *data, void *data2) // eDebug("eWidget::evtPaint"); // dumpRegion(*(gRegion*)data); - if (!m_have_background_color) - { - ePtr style; - if (!getStyle(style)) - style->paintBackground(painter, ePoint(0, 0), size()); - } else + if (!isTransparent()) { - painter.setBackgroundColor(m_background_color); - painter.clear(); + if (!m_have_background_color) + { + ePtr style; + if (!getStyle(style)) + style->paintBackground(painter, ePoint(0, 0), size()); + } else + { + painter.setBackgroundColor(m_background_color); + painter.clear(); + } } break; } diff --git a/lib/gui/ewidget.h b/lib/gui/ewidget.h index 879e5eaa..db86fd10 100644 --- a/lib/gui/ewidget.h +++ b/lib/gui/ewidget.h @@ -40,10 +40,13 @@ public: void clearBackgroundColor(); void setZPosition(int z); + void setTransparent(int transp); /* untested code */ int isVisible() { return (m_vis & wVisShow) && ((!m_parent) || m_parent->isVisible()); } /* ... */ + + int isTransparent() { return m_vis & wVisTransparent; } eWidgetAnimation m_animation; private: diff --git a/lib/gui/ewidgetdesktop.cpp b/lib/gui/ewidgetdesktop.cpp index afe1995c..c89cd270 100644 --- a/lib/gui/ewidgetdesktop.cpp +++ b/lib/gui/ewidgetdesktop.cpp @@ -51,10 +51,10 @@ void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visib widget->m_visible_region = widget->m_clip_region; widget->m_visible_region.moveBy(widget->position()); widget->m_visible_region &= parent_visible; // in parent space! - /* TODO: check transparency here! */ - /* remove everything this widget will contain from parent's visible list */ - parent_visible -= widget->m_visible_region; // will remove child regions too! + if (!widget->isTransparent()) + /* remove everything this widget will contain from parent's visible list, unless widget is transparent. */ + parent_visible -= widget->m_visible_region; // will remove child regions too! /* now prepare for recursing to childs */ widget->m_visible_region.moveBy(-widget->position()); // now in local space @@ -63,11 +63,22 @@ void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visib widget->m_visible_with_childs = widget->m_visible_region; - for (ePtrList::iterator i(widget->m_childs.begin()); i != widget->m_childs.end(); ++i) - if (i->m_vis & eWidget::wVisShow) - calcWidgetClipRegion(*i, widget->m_visible_region); - else - clearVisibility(*i); + /* add childs in reverse (Z) order - we're going from front-to-bottom here. */ + ePtrList::iterator i(widget->m_childs.end()); + + for (;;) + { + if (i != widget->m_childs.end()) + { + if (i->m_vis & eWidget::wVisShow) + calcWidgetClipRegion(*i, widget->m_visible_region); + else + clearVisibility(*i); + } + if (i == widget->m_childs.begin()) + break; + --i; + } } void eWidgetDesktop::recalcClipRegions(eWidget *root) diff --git a/skin.py b/skin.py index a4095204..d11cce02 100644 --- a/skin.py +++ b/skin.py @@ -128,6 +128,8 @@ def applySingleAttribute(guiObject, desktop, attrib, value): guiObject.setForegroundColor(parseColor(value)) elif attrib == "selectionDisabled": guiObject.setSelectionEnable(0) + elif attrib == "transparent": + guiObject.setTransparent(int(value)) elif attrib != 'name': print "unsupported attribute " + attrib + "=" + value except int: -- 2.30.2