[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42439] trunk/blender/source/blender: Fix #28107: save screenshot operator option to save full screen or only a single

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Dec 5 17:37:41 CET 2011


Revision: 42439
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42439
Author:   blendix
Date:     2011-12-05 16:37:31 +0000 (Mon, 05 Dec 2011)
Log Message:
-----------
Fix #28107: save screenshot operator option to save full screen or only a single
editor was not working. Solution is to take full screenshot and crop it on save.
Also fixed screenshot showing popup menu used to execute operator.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/screen/screendump.c
    trunk/blender/source/blender/windowmanager/WM_api.h
    trunk/blender/source/blender/windowmanager/intern/wm_draw.c

Modified: trunk/blender/source/blender/editors/screen/screendump.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screendump.c	2011-12-05 15:57:57 UTC (rev 42438)
+++ trunk/blender/source/blender/editors/screen/screendump.c	2011-12-05 16:37:31 UTC (rev 42439)
@@ -68,28 +68,20 @@
 typedef struct ScreenshotData {
 	unsigned int *dumprect;
 	int dumpsx, dumpsy;
+	rcti crop;
 } ScreenshotData;
 
 /* get shot from frontbuffer */
-static unsigned int *screenshot(bContext *C, int *dumpsx, int *dumpsy, int fscreen)
+static unsigned int *screenshot(bContext *C, int *dumpsx, int *dumpsy)
 {
 	wmWindow *win= CTX_wm_window(C);
-	ScrArea *curarea= CTX_wm_area(C);
 	int x=0, y=0;
 	unsigned int *dumprect= NULL;
 	
-	if(fscreen) {	/* full screen */
-		x= 0;
-		y= 0;
-		*dumpsx= win->sizex;
-		*dumpsy= win->sizey;
-	} 
-	else {
-		x= curarea->totrct.xmin;
-		y= curarea->totrct.ymin;
-		*dumpsx= curarea->totrct.xmax-x;
-		*dumpsy= curarea->totrct.ymax-y;
-	}
+	x= 0;
+	y= 0;
+	*dumpsx= win->sizex;
+	*dumpsy= win->sizey;
 
 	if (*dumpsx && *dumpsy) {
 		
@@ -108,15 +100,23 @@
 {
 	unsigned int *dumprect;
 	int dumpsx, dumpsy;
+
+	/* do redraw so we don't show popups/menus */
+	WM_redraw_windows(C);
 	
-	dumprect= screenshot(C, &dumpsx, &dumpsy, RNA_boolean_get(op->ptr, "full"));
+	dumprect= screenshot(C, &dumpsx, &dumpsy);
+
 	if(dumprect) {
 		ScreenshotData *scd= MEM_callocN(sizeof(ScreenshotData), "screenshot");
+		ScrArea *sa= CTX_wm_area(C);
 		
 		scd->dumpsx= dumpsx;
 		scd->dumpsy= dumpsy;
 		scd->dumprect= dumprect;
+		if(sa)
+			scd->crop= sa->totrct;
 		op->customdata= scd;
+
 		return TRUE;
 	}
 	else {
@@ -137,6 +137,21 @@
 	}
 }
 
+static void screenshot_crop(ImBuf *ibuf, rcti crop)
+{
+	unsigned int *to= ibuf->rect;
+	unsigned int *from= ibuf->rect + crop.ymin*ibuf->x + crop.xmin;
+	int y, cropw= crop.xmax - crop.xmin, croph = crop.ymax - crop.ymin;
+
+	if(cropw > 0 && croph > 0) {
+		for(y=0; y<croph; y++, to+=cropw, from+=ibuf->x)
+			memmove(to, from, sizeof(unsigned int)*cropw);
+
+		ibuf->x= cropw;
+		ibuf->y= croph;
+	}
+}
+
 static int screenshot_exec(bContext *C, wmOperator *op)
 {
 	ScreenshotData *scd= op->customdata;
@@ -166,6 +181,10 @@
 			ibuf= IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0);
 			ibuf->rect= scd->dumprect;
 
+			/* crop to show only single editor */
+			if(!RNA_boolean_get(op->ptr, "full"))
+				screenshot_crop(ibuf, scd->crop);
+
 			BKE_write_ibuf(ibuf, path, &scene->r.im_format);
 
 			IMB_freeImBuf(ibuf);
@@ -213,7 +232,6 @@
 	
 	WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH);
 	prop= RNA_def_boolean(ot->srna, "full", 1, "Full Screen", "");
-	RNA_def_property_flag(prop, PROP_HIDDEN); /* hide because once the file sel is displayed, the option no longer does anything */
 }
 
 /* *************** screenshot movie job ************************* */

Modified: trunk/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_api.h	2011-12-05 15:57:57 UTC (rev 42438)
+++ trunk/blender/source/blender/windowmanager/WM_api.h	2011-12-05 16:37:31 UTC (rev 42439)
@@ -331,6 +331,9 @@
 void		WM_console_toggle(struct bContext *C, short show);
 #endif
 
+			/* Draw (for screenshot) */
+void		WM_redraw_windows(struct bContext *C);
+
 /* debugging only, convenience function to write on crash */
 int write_crash_blend(void);
 

Modified: trunk/blender/source/blender/windowmanager/intern/wm_draw.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_draw.c	2011-12-05 15:57:57 UTC (rev 42438)
+++ trunk/blender/source/blender/windowmanager/intern/wm_draw.c	2011-12-05 16:37:31 UTC (rev 42439)
@@ -835,3 +835,16 @@
 	win->screen->do_draw= 1;
 }
 
+void WM_redraw_windows(bContext *C)
+{
+	wmWindow *win_prev= CTX_wm_window(C);
+	ScrArea *area_prev= CTX_wm_area(C);
+	ARegion *ar_prev= CTX_wm_region(C);
+
+	wm_draw_update(C);
+
+	CTX_wm_window_set(C, win_prev);
+	CTX_wm_area_set(C, area_prev);
+	CTX_wm_region_set(C, ar_prev);
+}
+




More information about the Bf-blender-cvs mailing list