diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-12-05 20:37:31 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-12-05 20:37:31 +0400 |
commit | c40d8921b8b61c0465a2fe9bca72dc418bf39c7d (patch) | |
tree | 4b148b53ead94dbbba6c5ef3438f3f730494f167 /source/blender/editors/screen/screendump.c | |
parent | 72827ee53190d74ebaa083f2bb616d9bc4b2e078 (diff) |
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.
Diffstat (limited to 'source/blender/editors/screen/screendump.c')
-rw-r--r-- | source/blender/editors/screen/screendump.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 7d0ec866456..7c76766affa 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -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 @@ static int screenshot_data_create(bContext *C, wmOperator *op) { 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_data_free(wmOperator *op) } } +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 @@ static int screenshot_exec(bContext *C, wmOperator *op) 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 @@ void SCREEN_OT_screenshot(wmOperatorType *ot) 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 ************************* */ |