1
1

UI: split screenshot area into a separate operator

While the screenshot operator showed an "Area" option,
it wasn't usable from the main menu (unless accessed via menu search).

Split screenshot area into an operator that depends on cursor.
This commit is contained in:
2021-09-17 12:09:25 +10:00
parent da2ba40268
commit 180bafe225
4 changed files with 45 additions and 18 deletions

View File

@@ -655,6 +655,7 @@ class TOPBAR_MT_window(Menu):
layout.separator()
layout.operator("screen.screenshot")
layout.operator("screen.screenshot_area")
if sys.platform[:3] == "win":
layout.separator()

View File

@@ -128,6 +128,7 @@ extern const char *screen_context_dir[]; /* doc access */
/* screendump.c */
void SCREEN_OT_screenshot(struct wmOperatorType *ot);
void SCREEN_OT_screenshot_area(struct wmOperatorType *ot);
/* workspace_layout_edit.c */
bool workspace_layout_set_poll(const struct WorkSpaceLayout *layout);

View File

@@ -5690,6 +5690,7 @@ void ED_operatortypes_screen(void)
WM_operatortype_append(SCREEN_OT_back_to_previous);
WM_operatortype_append(SCREEN_OT_spacedata_cleanup);
WM_operatortype_append(SCREEN_OT_screenshot);
WM_operatortype_append(SCREEN_OT_screenshot_area);
WM_operatortype_append(SCREEN_OT_userpref_show);
WM_operatortype_append(SCREEN_OT_drivers_editor_show);
WM_operatortype_append(SCREEN_OT_info_log_show);

View File

@@ -42,6 +42,7 @@
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_screen.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -57,12 +58,13 @@ typedef struct ScreenshotData {
uint *dumprect;
int dumpsx, dumpsy;
rcti crop;
bool use_crop;
ImageFormatData im_format;
} ScreenshotData;
/* call from both exec and invoke */
static int screenshot_data_create(bContext *C, wmOperator *op)
static int screenshot_data_create(bContext *C, wmOperator *op, ScrArea *area)
{
int dumprect_size[2];
@@ -76,7 +78,6 @@ static int screenshot_data_create(bContext *C, wmOperator *op)
if (dumprect) {
ScreenshotData *scd = MEM_callocN(sizeof(ScreenshotData), "screenshot");
ScrArea *area = CTX_wm_area(C);
scd->dumpsx = dumprect_size[0];
scd->dumpsy = dumprect_size[1];
@@ -110,12 +111,13 @@ static void screenshot_data_free(wmOperator *op)
static int screenshot_exec(bContext *C, wmOperator *op)
{
const bool use_crop = STREQ(op->idname, "SCREEN_OT_screenshot_area");
ScreenshotData *scd = op->customdata;
bool ok = false;
if (scd == NULL) {
/* when running exec directly */
screenshot_data_create(C, op);
screenshot_data_create(C, op, use_crop ? CTX_wm_area(C) : NULL);
scd = op->customdata;
}
@@ -132,7 +134,7 @@ static int screenshot_exec(bContext *C, wmOperator *op)
ibuf->rect = scd->dumprect;
/* crop to show only single editor */
if (!RNA_boolean_get(op->ptr, "full")) {
if (use_crop) {
IMB_rect_crop(ibuf, &scd->crop);
scd->dumprect = ibuf->rect;
}
@@ -157,9 +159,20 @@ static int screenshot_exec(bContext *C, wmOperator *op)
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
if (screenshot_data_create(C, op)) {
const bool use_crop = STREQ(op->idname, "SCREEN_OT_screenshot_area");
ScrArea *area = NULL;
if (use_crop) {
area = CTX_wm_area(C);
bScreen *screen = CTX_wm_screen(C);
ScrArea *area_test = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y);
if (area_test != NULL) {
area = area_test;
}
}
if (screenshot_data_create(C, op, area)) {
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
return screenshot_exec(C, op);
}
@@ -226,12 +239,8 @@ static bool screenshot_poll(bContext *C)
return WM_operator_winactive(C);
}
void SCREEN_OT_screenshot(wmOperatorType *ot)
static void screen_screenshot_impl(wmOperatorType *ot)
{
ot->name = "Save Screenshot";
ot->idname = "SCREEN_OT_screenshot";
ot->description = "Capture a picture of the active area or whole Blender window";
ot->invoke = screenshot_invoke;
ot->check = screenshot_check;
ot->exec = screenshot_exec;
@@ -239,8 +248,6 @@ void SCREEN_OT_screenshot(wmOperatorType *ot)
ot->ui = screenshot_draw;
ot->poll = screenshot_poll;
ot->flag = 0;
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_IMAGE,
FILE_SPECIAL,
@@ -248,9 +255,26 @@ void SCREEN_OT_screenshot(wmOperatorType *ot)
WM_FILESEL_FILEPATH,
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT);
RNA_def_boolean(ot->srna,
"full",
1,
"Full Screen",
"Capture the whole window (otherwise only capture the active area)");
}
void SCREEN_OT_screenshot(wmOperatorType *ot)
{
ot->name = "Save Screenshot";
ot->idname = "SCREEN_OT_screenshot";
ot->description = "Capture a picture of the whole Blender window";
screen_screenshot_impl(ot);
ot->flag = 0;
}
void SCREEN_OT_screenshot_area(wmOperatorType *ot)
{
ot->name = "Save Screenshot (Area)";
ot->idname = "SCREEN_OT_screenshot_area";
ot->description = "Capture a picture of the active area";
screen_screenshot_impl(ot);
ot->flag = OPTYPE_DEPENDS_ON_CURSOR;
}