Replaced jwidget_flush_redraw recursiveness with a std::queue.

This commit is contained in:
David Capello 2010-04-19 22:42:58 -03:00
parent 19483aed3c
commit 5c00d14cc0

View File

@ -33,13 +33,14 @@
#include "config.h" #include "config.h"
#include <assert.h> #include <cassert>
#include <ctype.h> #include <cctype>
#include <limits.h> #include <climits>
#include <stdarg.h> #include <cstdarg>
#include <string.h> #include <cstring>
#include <queue>
#ifdef REPORT_SIGNALS #ifdef REPORT_SIGNALS
# include <stdio.h> # include <cstdio>
#endif #endif
#include <allegro.h> #include <allegro.h>
#ifdef ALLEGRO_WINDOWS #ifdef ALLEGRO_WINDOWS
@ -1164,45 +1165,53 @@ void jwidget_set_theme(JWidget widget, JTheme theme)
void jwidget_flush_redraw(JWidget widget) void jwidget_flush_redraw(JWidget widget)
{ {
std::queue<Widget*> processing;
int c, nrects; int c, nrects;
JMessage msg; JMessage msg;
JLink link; JLink link;
JRect rc; JRect rc;
assert_valid_widget(widget); processing.push(widget);
if (jwidget_is_hidden(widget)) while (!processing.empty()) {
return; widget = processing.front();
processing.pop();
nrects = JI_REGION_NUM_RECTS(widget->update_region); assert_valid_widget(widget);
if (nrects > 0) {
/* get areas to draw */ if (jwidget_is_hidden(widget))
JRegion region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS); continue;
jregion_intersect(widget->update_region,
widget->update_region, region); JI_LIST_FOR_EACH(widget->children, link)
jregion_free(region); processing.push((Widget*)link->data);
nrects = JI_REGION_NUM_RECTS(widget->update_region); nrects = JI_REGION_NUM_RECTS(widget->update_region);
if (nrects > 0) {
/* get areas to draw */
JRegion region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS);
jregion_intersect(widget->update_region,
widget->update_region, region);
jregion_free(region);
/* draw the widget */ nrects = JI_REGION_NUM_RECTS(widget->update_region);
for (c=0, rc=JI_REGION_RECTS(widget->update_region);
c<nrects;
c++, rc++) {
/* create the draw message */
msg = jmessage_new(JM_DRAW);
msg->draw.count = nrects-1 - c;
msg->draw.rect = *rc;
jmessage_add_dest(msg, widget);
/* enqueue the draw message */ /* draw the widget */
jmanager_enqueue_message(msg); for (c=0, rc=JI_REGION_RECTS(widget->update_region);
c<nrects;
c++, rc++) {
/* create the draw message */
msg = jmessage_new(JM_DRAW);
msg->draw.count = nrects-1 - c;
msg->draw.rect = *rc;
jmessage_add_dest(msg, widget);
/* enqueue the draw message */
jmanager_enqueue_message(msg);
}
jregion_empty(widget->update_region);
} }
jregion_empty(widget->update_region);
} }
JI_LIST_FOR_EACH(widget->children, link)
jwidget_flush_redraw((JWidget)link->data);
} }
void jwidget_invalidate(JWidget widget) void jwidget_invalidate(JWidget widget)