1 #include <lib/gui/ewidgetdesktop.h>
2 #include <lib/gui/ewidget.h>
3 #include <lib/base/ebase.h>
5 void eWidgetDesktop::addRootWidget(eWidget *root, int top)
7 assert(!root->m_desktop);
9 m_root.push_back(root);
11 m_root.push_front(root);
12 root->m_desktop = this;
15 void eWidgetDesktop::removeRootWidget(eWidget *root)
20 void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visible)
22 /* start with our clip region, clipped with the parent's */
23 if (widget->m_vis & eWidget::wVisShow)
25 widget->m_visible_region = widget->m_clip_region;
26 widget->m_visible_region.moveBy(widget->position());
27 widget->m_visible_region &= parent_visible; // in parent space!
28 /* TODO: check transparency here! */
29 /* remove everything this widget will contain from parent's visible list */
30 parent_visible -= widget->m_visible_region; // will remove child regions too!
32 /* now prepare for recursing to childs */
33 widget->m_visible_region.moveBy(-widget->position()); // now in local space
35 widget->m_visible_region = gRegion();
37 widget->m_visible_with_childs = widget->m_visible_region;
39 for (ePtrList<eWidget>::iterator i(widget->m_childs.begin()); i != widget->m_childs.end(); ++i)
40 calcWidgetClipRegion(*i, widget->m_visible_region);
43 void eWidgetDesktop::recalcClipRegions()
45 m_background_region = gRegion(eRect(ePoint(0, 0), m_screen_size));
47 for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); ++i)
48 calcWidgetClipRegion(*i, m_background_region);
51 void eWidgetDesktop::invalidate(const gRegion ®ion)
53 if (m_timer && m_dirty_region.empty())
54 m_timer->start(0, 1); // start singleshot redraw timer
55 m_dirty_region |= region;
58 void eWidgetDesktop::setBackgroundColor(gRGB col)
60 m_background_color = col;
62 /* if there's something visible from the background, redraw it with the new color. */
63 if (m_dc && m_background_region.valid() && !m_background_region.empty())
65 /* todo: split out "setBackgroundColor / clear"... maybe? */
66 gPainter painter(m_dc);
67 painter.resetClip(m_background_region);
68 painter.setBackgroundColor(m_background_color);
73 void eWidgetDesktop::setPalette(gPixmap &pm)
76 gPainter painter(m_dc);
77 painter.setPalette(&pm);
80 void eWidgetDesktop::paint()
82 gPainter painter(m_dc);
83 /* walk all root windows. */
84 for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); ++i)
85 i->doPaint(painter, m_dirty_region);
86 m_dirty_region &= m_background_region;
88 painter.resetClip(m_dirty_region);
89 painter.setBackgroundColor(m_background_color);
94 m_dirty_region = gRegion();
97 void eWidgetDesktop::setDC(gDC *dc)
102 void eWidgetDesktop::setRedrawTask(eMainloop &ml)
111 m_timer = new eTimer(m_mainloop);
112 CONNECT(m_timer->timeout, eWidgetDesktop::paint);
114 if (!m_dirty_region.empty())
115 m_timer->start(0, 1);
118 void eWidgetDesktop::makeCompatiblePixmap(gPixmap &pm)
120 eDebug("widgetDesktop: make compatible pixmap of %p\n", &pm);
123 eWarning("eWidgetDesktop: no DC to make pixmap compatible with!");
127 gPainter painter(m_dc);
129 painter.mergePalette(&pm);
133 eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size), m_mainloop(0), m_timer(0)
137 eWidgetDesktop::~eWidgetDesktop()