#include <lib/gui/ewidgetdesktop.h>
#include <lib/gui/ewidget.h>
+#include <lib/base/ebase.h>
void eWidgetDesktop::addRootWidget(eWidget *root, int top)
{
void eWidgetDesktop::recalcClipRegions()
{
- gRegion screen = gRegion(eRect(ePoint(0, 0), m_screen_size));
+ m_background_region = gRegion(eRect(ePoint(0, 0), m_screen_size));
for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); ++i)
- calcWidgetClipRegion(*i, screen);
-// dumpRegion(screen);
+ calcWidgetClipRegion(*i, m_background_region);
}
void eWidgetDesktop::invalidate(const gRegion ®ion)
{
+ if (m_timer && m_dirty_region.empty())
+ m_timer->start(0, 1); // start singleshot redraw timer
m_dirty_region |= region;
}
+void eWidgetDesktop::setBackgroundColor(gRGB col)
+{
+ m_background_color = col;
+
+ /* if there's something visible from the background, redraw it with the new color. */
+ if (m_dc && m_background_region.valid() && !m_background_region.empty())
+ {
+ /* todo: split out "setBackgroundColor / clear"... maybe? */
+ gPainter painter(m_dc);
+ painter.resetClip(m_background_region);
+ painter.setBackgroundColor(m_background_color);
+ painter.clear();
+ }
+}
+
+void eWidgetDesktop::setPalette(gPixmap &pm)
+{
+ ASSERT(m_dc);
+ gPainter painter(m_dc);
+ painter.setPalette(&pm);
+}
+
void eWidgetDesktop::paint()
{
gPainter painter(m_dc);
/* walk all root windows. */
for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); ++i)
i->doPaint(painter, m_dirty_region);
+ m_dirty_region &= m_background_region;
+
+ painter.resetClip(m_dirty_region);
+ painter.setBackgroundColor(m_background_color);
+ painter.clear();
+
+ painter.flush();
+
m_dirty_region = gRegion();
}
m_dc = dc;
}
-eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size)
+void eWidgetDesktop::setRedrawTask(eMainloop &ml)
+{
+ if (m_mainloop)
+ {
+ delete m_timer;
+ m_timer = 0;
+ m_mainloop = 0;
+ }
+ m_mainloop = &ml;
+ m_timer = new eTimer(m_mainloop);
+ CONNECT(m_timer->timeout, eWidgetDesktop::paint);
+
+ if (!m_dirty_region.empty())
+ m_timer->start(0, 1);
+}
+
+void eWidgetDesktop::makeCompatiblePixmap(gPixmap &pm)
+{
+ eDebug("widgetDesktop: make compatible pixmap of %p\n", &pm);
+ if (!m_dc)
+ {
+ eWarning("eWidgetDesktop: no DC to make pixmap compatible with!");
+ return;
+ }
+
+ ePtr<gDC> pixmap_dc = new gDC(&pm);
+ gPainter pixmap_painter(pixmap_dc);
+
+ ePtr<gPixmap> target_pixmap;
+ m_dc->getPixmap(target_pixmap);
+
+ assert(target_pixmap);
+
+ pixmap_painter.mergePalette(target_pixmap);
+}
+
+eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size), m_mainloop(0), m_timer(0)
{
+ m_dirty_region = gRegion(eRect(ePoint(0, 0), m_screen_size));
}
eWidgetDesktop::~eWidgetDesktop()