[Bf-python] bpy.ops.wm.redraw() - an implementation of Blender 2.4*'s Redraw() function for Blender 2.5*...
Dietrich Bollmann
diresu at web.de
Sat Jul 24 04:36:12 CEST 2010
Hi,
Searching for an equivalent of Blender 2.4*'s Redraw() function I found
plenty of people missing it - but no response explaining how it can be
done in Blender 2.5*...
So finally I wrote my own redraw operator: bpy.ops.wm.redraw()
I used 'wm_draw_update()' as model and it works. But as I am not very
acquainted with the blender wm code, I am sure that there are better
ways to implement it...
For the case there is interest in this feature, I append the patch
implementing 'bpy.ops.wm.redraw()' to this email. Please let me know if
you want me to submit it to the patch tracker as well.
Thanks, Dietrich
-------------- next part --------------
=== modified file 'source/blender/windowmanager/intern/wm_draw.c'
--- source/blender/windowmanager/intern/wm_draw.c 2010-07-22 10:02:02 +0000
+++ source/blender/windowmanager/intern/wm_draw.c 2010-07-24 02:08:30 +0000
@@ -768,6 +768,58 @@
}
}
+/** Unconditionally redraw all windows. */ /* dietrich */
+void wm_redraw(bContext *C)
+{
+ /*
+ NOTES:
+
+ * This function is a copy of 'wm_draw_update()' stripped of all
+ tests for draw requests so that all redraw functions are
+ executed unconditionally...
+
+ * 'wm_method_draw_full()' is used for redrawing windows.
+
+ TODO:
+
+ * Somebody who knows the window manager better should check if
+ the usage of the functions for an unconditional redraw of the
+ blender GUI is adequate...
+
+ * Move the function to some more adequate place. Currently it
+ is positioned directly after its model: 'wm_draw_update()'...
+
+ (dietrich)
+ */
+
+ wmWindowManager *wm= CTX_wm_manager(C);
+ wmWindow *win;
+ int drawmethod;
+
+ GPU_free_unused_buffers();
+
+ /* draw all windows */
+ for(win= wm->windows.first; win; win= win->next) {
+
+ if(win->drawmethod != U.wmdrawmethod) {
+ wm_draw_window_clear(win);
+ win->drawmethod= U.wmdrawmethod;
+ }
+
+ CTX_wm_window_set(C, win);
+
+ /* sets context window+screen */
+ wm_window_make_drawable(C, win);
+
+ /* draw window */
+ ED_screen_refresh(wm, win);
+ drawmethod= wm_automatic_draw_method(win);
+ wm_method_draw_full(C, win);
+ wm_window_swap_buffers(win);
+ CTX_wm_window_set(C, NULL);
+ }
+}
+
void wm_draw_window_clear(wmWindow *win)
{
bScreen *screen= win->screen;
=== modified file 'source/blender/windowmanager/intern/wm_operators.c'
--- source/blender/windowmanager/intern/wm_operators.c 2010-07-21 11:12:26 +0000
+++ source/blender/windowmanager/intern/wm_operators.c 2010-07-24 02:09:15 +0000
@@ -1969,6 +1969,16 @@
ot->poll= WM_operator_winactive;
}
+/** Unconditionally redraw all windows. */ /* dietrich */
+static void WM_OT_redraw(wmOperatorType *ot)
+{
+ ot->name= "Redraw all windows";
+ ot->idname= "WM_OT_redraw";
+ ot->description="Redraw all windows";
+
+ ot->exec= wm_redraw_op;
+}
+
static int wm_exit_blender_op(bContext *C, wmOperator *op)
{
WM_operator_free(op);
@@ -3050,6 +3060,7 @@
WM_operatortype_append(WM_OT_read_homefile);
WM_operatortype_append(WM_OT_save_homefile);
WM_operatortype_append(WM_OT_window_fullscreen_toggle);
+ WM_operatortype_append(WM_OT_redraw); /* dietrich */
WM_operatortype_append(WM_OT_exit_blender);
WM_operatortype_append(WM_OT_open_mainfile);
WM_operatortype_append(WM_OT_link_append);
=== modified file 'source/blender/windowmanager/intern/wm_window.c'
--- source/blender/windowmanager/intern/wm_window.c 2010-07-23 08:21:44 +0000
+++ source/blender/windowmanager/intern/wm_window.c 2010-07-24 02:09:34 +0000
@@ -509,6 +509,16 @@
}
+/** Unconditionally redraw all windows. */ /* dietrich */
+int wm_redraw_op(bContext *C, wmOperator *op)
+{
+ /* unconditionally redraw all windows... */
+ wm_redraw(C);
+
+ return OPERATOR_FINISHED;
+}
+
+
/* ************ events *************** */
static int query_qual(char qual)
=== modified file 'source/blender/windowmanager/wm_draw.h'
--- source/blender/windowmanager/wm_draw.h 2010-03-22 11:59:36 +0000
+++ source/blender/windowmanager/wm_draw.h 2010-07-24 02:09:52 +0000
@@ -35,6 +35,7 @@
/* wm_draw.c */
void wm_draw_update (struct bContext *C);
+void wm_redraw (struct bContext *C); /* dietrich */
void wm_draw_window_clear (struct wmWindow *win);
void wm_draw_region_clear (struct wmWindow *win, struct ARegion *ar);
=== modified file 'source/blender/windowmanager/wm_window.h'
--- source/blender/windowmanager/wm_window.h 2010-03-26 06:26:02 +0000
+++ source/blender/windowmanager/wm_window.h 2010-07-24 02:10:13 +0000
@@ -65,6 +65,7 @@
/* *************** window operators ************** */
int wm_window_duplicate_op (bContext *C, struct wmOperator *op);
int wm_window_fullscreen_toggle_op(bContext *C, struct wmOperator *op);
+int wm_redraw_op(bContext *C, struct wmOperator *op); /* dietrich */
#endif /* WM_WINDOW_H */
More information about the Bf-python
mailing list