| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Blender Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * Making screendumps. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/screen/screendump.c
 | 
					
						
							|  |  |  |  *  \ingroup edscr | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2016-01-11 12:32:29 +11:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:56:58 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "IMB_imbuf_types.h"
 | 
					
						
							|  |  |  | #include "IMB_imbuf.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | #include "DNA_screen_types.h"
 | 
					
						
							|  |  |  | #include "DNA_space_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-21 10:28:19 +00:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_global.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-18 06:41:16 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | #include "BKE_image.h"
 | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | #include "BKE_writeavi.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_gl.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | #include "BIF_glutil.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | #include "PIL_time.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "screen_intern.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | typedef struct ScreenshotData { | 
					
						
							|  |  |  | 	unsigned int *dumprect; | 
					
						
							|  |  |  | 	int dumpsx, dumpsy; | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 	rcti crop; | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ImageFormatData im_format; | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } ScreenshotData; | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-27 20:29:07 +00:00
										 |  |  | static void screenshot_read_pixels(int x, int y, int w, int h, unsigned char *rect) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect); | 
					
						
							|  |  |  | 	glFinish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* clear alpha, it is not set to a meaningful value in opengl */ | 
					
						
							| 
									
										
										
										
											2013-10-01 16:40:11 +00:00
										 |  |  | 	for (i = 0, rect += 3; i < w * h; i++, rect += 4) | 
					
						
							| 
									
										
										
										
											2013-09-27 20:29:07 +00:00
										 |  |  | 		*rect = 255; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | /* get shot from frontbuffer */ | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | static unsigned int *screenshot(bContext *C, int *dumpsx, int *dumpsy) | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  | 	int x = 0, y = 0; | 
					
						
							|  |  |  | 	unsigned int *dumprect = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	x = 0; | 
					
						
							|  |  |  | 	y = 0; | 
					
						
							| 
									
										
										
										
											2013-01-15 21:41:51 +00:00
										 |  |  | 	*dumpsx = WM_window_pixels_x(win); | 
					
						
							|  |  |  | 	*dumpsy = WM_window_pixels_y(win); | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (*dumpsx && *dumpsy) { | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		dumprect = MEM_mallocN(sizeof(int) * (*dumpsx) * (*dumpsy), "dumprect"); | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 		glReadBuffer(GL_FRONT); | 
					
						
							| 
									
										
										
										
											2013-10-16 04:08:20 +00:00
										 |  |  | 		screenshot_read_pixels(x, y, *dumpsx, *dumpsy, (unsigned char *)dumprect); | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | 		glReadBuffer(GL_BACK); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 	return dumprect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | /* call from both exec and invoke */ | 
					
						
							|  |  |  | static int screenshot_data_create(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int *dumprect; | 
					
						
							|  |  |  | 	int dumpsx, dumpsy; | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* do redraw so we don't show popups/menus */ | 
					
						
							|  |  |  | 	WM_redraw_windows(C); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	dumprect = screenshot(C, &dumpsx, &dumpsy); | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (dumprect) { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		ScreenshotData *scd = MEM_callocN(sizeof(ScreenshotData), "screenshot"); | 
					
						
							|  |  |  | 		ScrArea *sa = CTX_wm_area(C); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		scd->dumpsx = dumpsx; | 
					
						
							|  |  |  | 		scd->dumpsy = dumpsy; | 
					
						
							|  |  |  | 		scd->dumprect = dumprect; | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 		if (sa) { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 			scd->crop = sa->totrct; | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BKE_imformat_defaults(&scd->im_format); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		op->customdata = scd; | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void screenshot_data_free(wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	ScreenshotData *scd = op->customdata; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (scd) { | 
					
						
							|  |  |  | 		if (scd->dumprect) | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 			MEM_freeN(scd->dumprect); | 
					
						
							|  |  |  | 		MEM_freeN(scd); | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | static void screenshot_crop(ImBuf *ibuf, rcti crop) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	unsigned int *to = ibuf->rect; | 
					
						
							|  |  |  | 	unsigned int *from = ibuf->rect + crop.ymin * ibuf->x + crop.xmin; | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 	int crop_x = BLI_rcti_size_x(&crop); | 
					
						
							|  |  |  | 	int crop_y = BLI_rcti_size_y(&crop); | 
					
						
							| 
									
										
										
										
											2012-08-21 20:34:05 +00:00
										 |  |  | 	int y; | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 20:34:05 +00:00
										 |  |  | 	if (crop_x > 0 && crop_y > 0) { | 
					
						
							|  |  |  | 		for (y = 0; y < crop_y; y++, to += crop_x, from += ibuf->x) | 
					
						
							|  |  |  | 			memmove(to, from, sizeof(unsigned int) * crop_x); | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 20:34:05 +00:00
										 |  |  | 		ibuf->x = crop_x; | 
					
						
							|  |  |  | 		ibuf->y = crop_y; | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | static int screenshot_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	ScreenshotData *scd = op->customdata; | 
					
						
							| 
									
										
										
										
											2016-01-11 12:32:29 +11:00
										 |  |  | 	bool ok = false; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (scd == NULL) { | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 		/* when running exec directly */ | 
					
						
							|  |  |  | 		screenshot_data_create(C, op); | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		scd = op->customdata; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (scd) { | 
					
						
							|  |  |  | 		if (scd->dumprect) { | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 			ImBuf *ibuf; | 
					
						
							|  |  |  | 			char path[FILE_MAX]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			RNA_string_get(op->ptr, "filepath", path); | 
					
						
							| 
									
										
										
										
											2018-06-05 15:10:33 +02:00
										 |  |  | 			BLI_path_abs(path, BKE_main_blendfile_path_from_global()); | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 			/* operator ensures the extension */ | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 			ibuf = IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0); | 
					
						
							|  |  |  | 			ibuf->rect = scd->dumprect; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 			/* crop to show only single editor */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 			if (!RNA_boolean_get(op->ptr, "full")) | 
					
						
							| 
									
										
										
										
											2011-12-05 16:37:31 +00:00
										 |  |  | 				screenshot_crop(ibuf, scd->crop); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 			if (scd->im_format.planes == R_IMF_PLANES_BW) { | 
					
						
							|  |  |  | 				/* bw screenshot? - users will notice if it fails! */ | 
					
						
							|  |  |  | 				IMB_color_to_bw(ibuf); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-11 12:32:29 +11:00
										 |  |  | 			if (BKE_imbuf_write(ibuf, path, &scd->im_format)) { | 
					
						
							|  |  |  | 				ok = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			IMB_freeImBuf(ibuf); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	screenshot_data_free(op); | 
					
						
							| 
									
										
										
										
											2016-01-11 12:32:29 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (screenshot_data_create(C, op)) { | 
					
						
							|  |  |  | 		if (RNA_struct_property_is_set(op->ptr, "filepath")) | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 			return screenshot_exec(C, op); | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* extension is added by 'screenshot_check' after */ | 
					
						
							| 
									
										
										
										
											2016-02-10 13:57:54 +11:00
										 |  |  | 		char filepath[FILE_MAX] = "//screen"; | 
					
						
							|  |  |  | 		if (G.relbase_valid) { | 
					
						
							| 
									
										
										
										
											2018-06-05 15:10:33 +02:00
										 |  |  | 			BLI_strncpy(filepath, BKE_main_blendfile_path_from_global(), sizeof(filepath)); | 
					
						
							| 
									
										
										
										
											2018-06-17 16:13:24 +02:00
										 |  |  | 			BLI_path_extension_replace(filepath, sizeof(filepath), "");  /* strip '.blend' */ | 
					
						
							| 
									
										
										
										
											2016-02-10 13:57:54 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		RNA_string_set(op->ptr, "filepath", filepath); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-18 13:29:54 +00:00
										 |  |  | 		WM_event_add_fileselect(C, op); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 		return OPERATOR_RUNNING_MODAL; | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 	return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-18 15:30:51 +00:00
										 |  |  | static bool screenshot_check(bContext *UNUSED(C), wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ScreenshotData *scd = op->customdata; | 
					
						
							| 
									
										
										
										
											2012-12-23 13:57:09 +00:00
										 |  |  | 	return WM_operator_filesel_ensure_ext_imtype(op, &scd->im_format); | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-30 23:08:53 +00:00
										 |  |  | static void screenshot_cancel(bContext *UNUSED(C), wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-01-04 14:37:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-19 11:13:35 +00:00
										 |  |  | 	screenshot_data_free(op); | 
					
						
							| 
									
										
										
										
											2011-01-04 14:37:21 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 23:17:44 +00:00
										 |  |  | static bool screenshot_draw_check_prop(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	const char *prop_id = RNA_property_identifier(prop); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 23:17:44 +00:00
										 |  |  | 	return !(STREQ(prop_id, "filepath")); | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void screenshot_draw(bContext *UNUSED(C), wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	uiLayout *layout = op->layout; | 
					
						
							|  |  |  | 	ScreenshotData *scd = op->customdata; | 
					
						
							|  |  |  | 	PointerRNA ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* image template */ | 
					
						
							|  |  |  | 	RNA_pointer_create(NULL, &RNA_ImageFormatSettings, &scd->im_format, &ptr); | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 	uiTemplateImageSettings(layout, &ptr, false); | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* main draw call */ | 
					
						
							|  |  |  | 	RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); | 
					
						
							|  |  |  | 	uiDefAutoButsRNA(layout, &ptr, screenshot_draw_check_prop, '\0'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 06:21:10 +00:00
										 |  |  | static int screenshot_poll(bContext *C) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (G.background) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return WM_operator_winactive(C); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | void SCREEN_OT_screenshot(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Save Screenshot"; /* weak: opname starting with 'save' makes filewindow give save-over */ | 
					
						
							|  |  |  | 	ot->idname = "SCREEN_OT_screenshot"; | 
					
						
							| 
									
										
										
										
											2012-05-06 15:03:31 +00:00
										 |  |  | 	ot->description = "Capture a picture of the active area or whole Blender window"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = screenshot_invoke; | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 	ot->check = screenshot_check; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = screenshot_exec; | 
					
						
							|  |  |  | 	ot->cancel = screenshot_cancel; | 
					
						
							| 
									
										
										
										
											2012-04-24 02:01:23 +00:00
										 |  |  | 	ot->ui = screenshot_draw; | 
					
						
							| 
									
										
										
										
											2013-06-27 06:21:10 +00:00
										 |  |  | 	ot->poll = screenshot_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->flag = 0; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-07 22:56:20 +11:00
										 |  |  | 	WM_operator_properties_filesel( | 
					
						
							|  |  |  | 	        ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE, FILE_SPECIAL, FILE_SAVE, | 
					
						
							|  |  |  | 	        WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); | 
					
						
							| 
									
										
										
										
											2013-01-29 08:01:50 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "full", 1, "Full Screen", | 
					
						
							|  |  |  | 	                "Capture the whole window (otherwise only capture the active area)"); | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* *************** screenshot movie job ************************* */ | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | typedef struct ScreenshotJob { | 
					
						
							| 
									
										
										
										
											2011-11-20 14:38:11 +00:00
										 |  |  | 	Main *bmain; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	Scene *scene; | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	wmWindowManager *wm; | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 	unsigned int *dumprect; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	int x, y, dumpsx, dumpsy; | 
					
						
							| 
									
										
										
										
											2014-04-27 00:22:49 +10:00
										 |  |  | 	const short *stop; | 
					
						
							|  |  |  | 	const short *do_update; | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | 	ReportList reports; | 
					
						
							| 
									
										
										
										
											2015-06-20 14:53:05 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bMovieHandle *movie_handle; | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 	void *movie_ctx; | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } ScreenshotJob; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void screenshot_freejob(void *sjv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	ScreenshotJob *sj = sjv; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (sj->dumprect) | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 		MEM_freeN(sj->dumprect); | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-20 14:53:05 +10:00
										 |  |  | 	if (sj->movie_handle) { | 
					
						
							|  |  |  | 		bMovieHandle *mh = sj->movie_handle; | 
					
						
							|  |  |  | 		mh->end_movie(sj->movie_ctx); | 
					
						
							|  |  |  | 		mh->context_free(sj->movie_ctx); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 	MEM_freeN(sj); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* called before redraw notifiers, copies a new dumprect */ | 
					
						
							|  |  |  | static void screenshot_updatejob(void *sjv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	ScreenshotJob *sj = sjv; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	unsigned int *dumprect; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	if (sj->dumprect == NULL) { | 
					
						
							|  |  |  | 		dumprect = MEM_mallocN(sizeof(int) * sj->dumpsx * sj->dumpsy, "dumprect"); | 
					
						
							| 
									
										
										
										
											2013-10-01 16:40:11 +00:00
										 |  |  | 		screenshot_read_pixels(sj->x, sj->y, sj->dumpsx, sj->dumpsy, (unsigned char *)dumprect); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		sj->dumprect = dumprect; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* only this runs inside thread */ | 
					
						
							| 
									
										
										
										
											2010-10-14 12:24:08 +00:00
										 |  |  | static void screenshot_startjob(void *sjv, short *stop, short *do_update, float *UNUSED(progress)) | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	ScreenshotJob *sj = sjv; | 
					
						
							|  |  |  | 	RenderData rd = sj->scene->r; | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 	bMovieHandle *mh = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	/* we need this as local variables for renderdata */ | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	rd.frs_sec = U.scrcastfps; | 
					
						
							|  |  |  | 	rd.frs_sec_base = 1.0f; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (BKE_imtype_is_movie(rd.im_format.imtype)) { | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 		mh = BKE_movie_handle_get(sj->scene->r.im_format.imtype); | 
					
						
							| 
									
										
										
										
											2015-09-23 02:40:08 +10:00
										 |  |  | 		if (mh == NULL) { | 
					
						
							|  |  |  | 			printf("Movie format unsupported\n"); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 		sj->movie_ctx = mh->context_create(); | 
					
						
							| 
									
										
										
										
											2015-06-20 14:53:05 +10:00
										 |  |  | 		sj->movie_handle = mh; | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!mh->start_movie(sj->movie_ctx, sj->scene, &rd, sj->dumpsx, sj->dumpsy, &sj->reports, false, "")) { | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | 			printf("screencast job stopped\n"); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	sj->stop = stop; | 
					
						
							|  |  |  | 	sj->do_update = do_update; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 	*do_update = true; /* wait for opengl rect */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	while (*stop == 0) { | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (sj->dumprect) { | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 			if (mh) { | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 				if (mh->append_movie(sj->movie_ctx, &rd, rd.sfra, rd.cfra, (int *)sj->dumprect, | 
					
						
							|  |  |  | 				                     sj->dumpsx, sj->dumpsy, "", &sj->reports)) | 
					
						
							| 
									
										
										
										
											2012-01-13 09:20:13 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-01-05 18:03:48 +00:00
										 |  |  | 					BKE_reportf(&sj->reports, RPT_INFO, "Appended frame: %d", rd.cfra); | 
					
						
							|  |  |  | 					printf("Appended frame %d\n", rd.cfra); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 				ImBuf *ibuf = IMB_allocImBuf(sj->dumpsx, sj->dumpsy, rd.im_format.planes, 0); | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 				char name[FILE_MAX]; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 				int ok; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-24 16:48:23 +11:00
										 |  |  | 				BKE_image_path_from_imformat( | 
					
						
							| 
									
										
										
										
											2018-06-05 15:10:33 +02:00
										 |  |  | 				        name, rd.pic, BKE_main_blendfile_path(sj->bmain), rd.cfra, | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 				        &rd.im_format, (rd.scemode & R_EXTENSION) != 0, true, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 				ibuf->rect = sj->dumprect; | 
					
						
							|  |  |  | 				ok = BKE_imbuf_write(ibuf, name, &rd.im_format); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 				if (ok == 0) { | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 					printf("Write error: cannot save %s\n", name); | 
					
						
							| 
									
										
										
										
											2012-10-26 17:32:50 +00:00
										 |  |  | 					BKE_reportf(&sj->reports, RPT_INFO, "Write error: cannot save %s", name); | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2010-01-22 06:48:29 +00:00
										 |  |  | 				else { | 
					
						
							|  |  |  | 					printf("Saved file: %s\n", name); | 
					
						
							|  |  |  | 					BKE_reportf(&sj->reports, RPT_INFO, "Saved file: %s", name); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-22 09:30:00 +00:00
										 |  |  | 				/* imbuf knows which rects are not part of ibuf */ | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 				IMB_freeImBuf(ibuf); | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 			MEM_freeN(sj->dumprect); | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 			sj->dumprect = NULL; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 			*do_update = true; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-05 18:03:48 +00:00
										 |  |  | 			rd.cfra++; | 
					
						
							| 
									
										
										
										
											2010-01-21 10:28:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2010-01-21 10:28:19 +00:00
										 |  |  | 			PIL_sleep_ms(U.scrcastwait); | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 	if (mh) { | 
					
						
							|  |  |  | 		mh->end_movie(sj->movie_ctx); | 
					
						
							|  |  |  | 		mh->context_free(sj->movie_ctx); | 
					
						
							| 
									
										
										
										
											2015-06-20 14:53:05 +10:00
										 |  |  | 		sj->movie_handle = NULL; | 
					
						
							| 
									
										
										
										
											2015-04-06 10:40:12 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-22 06:48:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BKE_report(&sj->reports, RPT_INFO, "Screencast job stopped"); | 
					
						
							| 
									
										
										
										
											2009-01-07 17:25:17 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | /* Helper callback for drawing the cursor itself */ | 
					
						
							|  |  |  | static void screencast_draw_cursor(bContext *UNUSED(C), int x, int y, void *UNUSED(p_ptr)) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glPushMatrix(); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glTranslatef((float)x, (float)y, 0.0f); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glEnable(GL_LINE_SMOOTH); | 
					
						
							|  |  |  | 	glEnable(GL_BLEND); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glColor4ub(0, 0, 0, 32); | 
					
						
							|  |  |  | 	glutil_draw_filled_arc(0.0, M_PI * 2.0, 20, 40); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glColor4ub(255, 255, 255, 128); | 
					
						
							|  |  |  | 	glutil_draw_lined_arc(0.0, M_PI * 2.0, 20, 40); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glDisable(GL_BLEND); | 
					
						
							|  |  |  | 	glDisable(GL_LINE_SMOOTH); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	glPopMatrix(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Turn brush cursor in 3D view on/off */ | 
					
						
							|  |  |  | static void screencast_cursor_toggle(wmWindowManager *wm, short enable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static void *cursor = NULL; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	if (cursor && !enable) { | 
					
						
							|  |  |  | 		/* clear cursor */ | 
					
						
							|  |  |  | 		WM_paint_cursor_end(wm, cursor); | 
					
						
							|  |  |  | 		cursor = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (enable) { | 
					
						
							|  |  |  | 		/* enable cursor */ | 
					
						
							|  |  |  | 		cursor = WM_paint_cursor_activate(wm, NULL, screencast_draw_cursor, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void screenshot_endjob(void *sjv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ScreenshotJob *sj = sjv; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	screencast_cursor_toggle(sj->wm, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | static int screencast_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-01 17:17:57 +00:00
										 |  |  | 	wmWindowManager *wm = CTX_wm_manager(C); | 
					
						
							|  |  |  | 	wmWindow *win = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	bScreen *screen = CTX_wm_screen(C); | 
					
						
							| 
									
										
										
										
											2013-03-01 17:17:57 +00:00
										 |  |  | 	wmJob *wm_job; | 
					
						
							|  |  |  | 	ScreenshotJob *sj; | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-01 17:17:57 +00:00
										 |  |  | 	/* if called again, stop the running job */ | 
					
						
							|  |  |  | 	if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST)) | 
					
						
							|  |  |  | 		WM_jobs_stop(wm, screen, screenshot_startjob); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-01 17:17:57 +00:00
										 |  |  | 	wm_job = WM_jobs_get(wm, win, screen, "Screencast", 0, WM_JOB_TYPE_SCREENCAST); | 
					
						
							|  |  |  | 	sj = MEM_callocN(sizeof(ScreenshotJob), "screenshot job"); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	/* setup sj */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (RNA_boolean_get(op->ptr, "full")) { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		sj->x = 0; | 
					
						
							|  |  |  | 		sj->y = 0; | 
					
						
							| 
									
										
										
										
											2013-01-15 21:41:51 +00:00
										 |  |  | 		sj->dumpsx = WM_window_pixels_x(win); | 
					
						
							|  |  |  | 		sj->dumpsy = WM_window_pixels_y(win); | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 		ScrArea *curarea = CTX_wm_area(C); | 
					
						
							|  |  |  | 		sj->x = curarea->totrct.xmin; | 
					
						
							|  |  |  | 		sj->y = curarea->totrct.ymin; | 
					
						
							|  |  |  | 		sj->dumpsx = curarea->totrct.xmax - sj->x; | 
					
						
							|  |  |  | 		sj->dumpsy = curarea->totrct.ymax - sj->y; | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	sj->bmain = CTX_data_main(C); | 
					
						
							|  |  |  | 	sj->scene = CTX_data_scene(C); | 
					
						
							| 
									
										
										
										
											2013-03-01 17:17:57 +00:00
										 |  |  | 	sj->wm = wm; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-22 12:01:32 +00:00
										 |  |  | 	BKE_reports_init(&sj->reports, RPT_PRINT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | 	/* setup job */ | 
					
						
							| 
									
										
										
										
											2012-08-15 10:03:29 +00:00
										 |  |  | 	WM_jobs_customdata_set(wm_job, sj, screenshot_freejob); | 
					
						
							|  |  |  | 	WM_jobs_timer(wm_job, 0.1, 0, NC_SCREEN | ND_SCREENCAST); | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	WM_jobs_callbacks(wm_job, screenshot_startjob, NULL, screenshot_updatejob, screenshot_endjob); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	WM_jobs_start(sj->wm, wm_job); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 18:33:35 +00:00
										 |  |  | 	screencast_cursor_toggle(sj->wm, 1); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 15:43:59 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_SCREEN | ND_SCREENCAST, screen); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-14 18:31:19 +00:00
										 |  |  | void SCREEN_OT_screencast(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Make Screencast"; | 
					
						
							|  |  |  | 	ot->idname = "SCREEN_OT_screencast"; | 
					
						
							| 
									
										
										
										
											2012-05-06 15:03:31 +00:00
										 |  |  | 	ot->description = "Capture a video of the active area or whole Blender window"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = WM_operator_confirm; | 
					
						
							|  |  |  | 	ot->exec = screencast_exec; | 
					
						
							| 
									
										
										
										
											2013-06-28 05:39:05 +00:00
										 |  |  | 	ot->poll = screenshot_poll;  /* shared poll */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->flag = 0; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  | 	RNA_def_property(ot->srna, "filepath", PROP_STRING, PROP_FILEPATH); | 
					
						
							| 
									
										
										
										
											2013-01-29 08:01:50 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "full", 1, "Full Screen", | 
					
						
							|  |  |  | 	                "Capture the whole window (otherwise only capture the active area)"); | 
					
						
							| 
									
										
										
										
											2009-02-14 16:43:02 +00:00
										 |  |  | } |