[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45903] trunk/blender/source/blender: screenshot operator now adds file extension in the file selector and has its own save options rather then using the render options (works like image save a copy).
Campbell Barton
ideasman42 at gmail.com
Tue Apr 24 04:01:25 CEST 2012
Revision: 45903
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45903
Author: campbellbarton
Date: 2012-04-24 02:01:23 +0000 (Tue, 24 Apr 2012)
Log Message:
-----------
screenshot operator now adds file extension in the file selector and has its own save options rather then using the render options (works like image save a copy).
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_image.h
trunk/blender/source/blender/blenkernel/intern/image.c
trunk/blender/source/blender/editors/screen/screendump.c
trunk/blender/source/blender/editors/space_image/image_ops.c
trunk/blender/source/blender/makesdna/DNA_scene_types.h
trunk/blender/source/blender/windowmanager/WM_api.h
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h 2012-04-24 02:01:23 UTC (rev 45903)
@@ -68,6 +68,8 @@
char BKE_imtype_from_arg(const char *arg);
+void BKE_imformat_defaults(struct ImageFormatData *im_format);
+
struct anim *openanim(const char *name, int flags, int streamindex);
void image_de_interlace(struct Image *ima, int odd);
Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/blenkernel/intern/image.c 2012-04-24 02:01:23 UTC (rev 45903)
@@ -1163,6 +1163,15 @@
}
}
+void BKE_imformat_defaults(ImageFormatData *im_format)
+{
+ memset(im_format, 0, sizeof(*im_format));
+ im_format->planes = R_IMF_PLANES_RGB;
+ im_format->imtype = R_IMF_IMTYPE_PNG;
+ im_format->quality = 90;
+ im_format->compress = 90;
+}
+
/* could allow access externally - 512 is for long names, 64 is for id names */
typedef struct StampData {
char file[512];
Modified: trunk/blender/source/blender/editors/screen/screendump.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screendump.c 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/editors/screen/screendump.c 2012-04-24 02:01:23 UTC (rev 45903)
@@ -56,6 +56,8 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "UI_interface.h"
+
#include "WM_types.h"
#include "WM_api.h"
@@ -69,6 +71,8 @@
unsigned int *dumprect;
int dumpsx, dumpsy;
rcti crop;
+
+ ImageFormatData im_format;
} ScreenshotData;
/* get shot from frontbuffer */
@@ -113,10 +117,14 @@
scd->dumpsx= dumpsx;
scd->dumpsy= dumpsy;
scd->dumprect= dumprect;
- if (sa)
+ if (sa) {
scd->crop= sa->totrct;
- op->customdata= scd;
+ }
+ BKE_imformat_defaults(&scd->im_format);
+
+ op->customdata = scd;
+
return TRUE;
}
else {
@@ -164,20 +172,13 @@
if (scd) {
if (scd->dumprect) {
- Scene *scene= CTX_data_scene(C);
ImBuf *ibuf;
char path[FILE_MAX];
RNA_string_get(op->ptr, "filepath", path);
-
- BLI_strncpy(G.ima, path, sizeof(G.ima));
BLI_path_abs(path, G.main->name);
- /* BKE_add_image_extension() checks for if extension was already set */
- if (scene->r.scemode & R_EXTENSION)
- if (strlen(path)<FILE_MAX-5)
- BKE_add_image_extension(path, scene->r.im_format.imtype);
-
+ /* operator ensures the extension */
ibuf= IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0);
ibuf->rect= scd->dumprect;
@@ -185,7 +186,11 @@
if (!RNA_boolean_get(op->ptr, "full"))
screenshot_crop(ibuf, scd->crop);
- BKE_write_ibuf(ibuf, path, &scene->r.im_format);
+ if (scd->im_format.planes == R_IMF_PLANES_BW) {
+ /* bw screenshot? - users will notice if it fails! */
+ IMB_color_to_bw(ibuf);
+ }
+ BKE_write_ibuf(ibuf, path, &scd->im_format);
IMB_freeImBuf(ibuf);
}
@@ -200,9 +205,10 @@
if (screenshot_data_create(C, op)) {
if (RNA_struct_property_is_set(op->ptr, "filepath"))
return screenshot_exec(C, op);
+
+ /* extension is added by 'screenshot_check' after */
+ RNA_string_set(op->ptr, "filepath", G.relbase_valid ? G.main->name : "//screen");
- RNA_string_set(op->ptr, "filepath", G.ima);
-
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
@@ -210,21 +216,52 @@
return OPERATOR_CANCELLED;
}
+static int screenshot_check(bContext *UNUSED(C), wmOperator *op)
+{
+ ScreenshotData *scd = op->customdata;
+ return WM_operator_filesel_ensure_ext_imtype(op, scd->im_format.imtype);
+}
+
static int screenshot_cancel(bContext *UNUSED(C), wmOperator *op)
{
screenshot_data_free(op);
return OPERATOR_CANCELLED;
}
+static int screenshot_draw_check_prop(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
+{
+ const char *prop_id = RNA_property_identifier(prop);
+
+ return !(strcmp(prop_id, "filepath") == 0);
+}
+
+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);
+ uiTemplateImageSettings(layout, &ptr);
+
+ /* main draw call */
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+ uiDefAutoButsRNA(layout, &ptr, screenshot_draw_check_prop, '\0');
+}
+
+
void SCREEN_OT_screenshot(wmOperatorType *ot)
{
ot->name = "Save Screenshot"; /* weak: opname starting with 'save' makes filewindow give save-over */
ot->idname = "SCREEN_OT_screenshot";
ot->invoke = screenshot_invoke;
+ ot->check = screenshot_check;
ot->exec = screenshot_exec;
+ ot->cancel = screenshot_cancel;
+ ot->ui = screenshot_draw;
ot->poll = WM_operator_winactive;
- ot->cancel = screenshot_cancel;
ot->flag = 0;
Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c 2012-04-24 02:01:23 UTC (rev 45903)
@@ -1001,11 +1001,7 @@
static void save_image_options_defaults(SaveImageOptions *simopts)
{
- memset(&simopts->im_format, 0, sizeof(simopts->im_format));
- simopts->im_format.planes = R_IMF_PLANES_RGB;
- simopts->im_format.imtype = R_IMF_IMTYPE_PNG;
- simopts->im_format.quality = 90;
- simopts->im_format.compress = 90;
+ BKE_imformat_defaults(&simopts->im_format);
simopts->filepath[0] = '\0';
}
@@ -1246,13 +1242,7 @@
static int image_save_as_check(bContext *UNUSED(C), wmOperator *op)
{
ImageFormatData *imf = op->customdata;
- char filepath[FILE_MAX];
- RNA_string_get(op->ptr, "filepath", filepath);
- if (BKE_add_image_extension(filepath, imf->imtype)) {
- RNA_string_set(op->ptr, "filepath", filepath);
- return TRUE;
- }
- return FALSE;
+ return WM_operator_filesel_ensure_ext_imtype(op, imf->imtype);
}
static int image_save_as_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h 2012-04-24 02:01:23 UTC (rev 45903)
@@ -249,7 +249,7 @@
char depth; /* bits per channel, R_IMF_CHAN_DEPTH_8 -> 32,
* not a flag, only set 1 at a time */
- char planes ; /* - R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA */
+ char planes; /* - R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA */
char flag; /* generic options for all image types, alpha zbuffer */
char quality; /* (0 - 100), eg: jpeg quality */
Modified: trunk/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_api.h 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/windowmanager/WM_api.h 2012-04-24 02:01:23 UTC (rev 45903)
@@ -166,6 +166,7 @@
int WM_operator_confirm (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
/* invoke callback, file selector "filepath" unset + exec */
int WM_operator_filesel (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
+int WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const char imtype);
/* poll callback, context checks */
int WM_operator_winactive (struct bContext *C);
/* invoke callback, exec + redo popup */
Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-04-24 01:52:59 UTC (rev 45902)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-04-24 02:01:23 UTC (rev 45903)
@@ -65,6 +65,7 @@
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_idprop.h"
+#include "BKE_image.h"
#include "BKE_library.h"
#include "BKE_global.h"
#include "BKE_main.h"
@@ -808,6 +809,22 @@
}
}
+int WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const char imtype)
+{
+ PropertyRNA *prop;
+ char filepath[FILE_MAX];
+ /* dont NULL check prop, this can only run on ops with a 'filepath' */
+ prop = RNA_struct_find_property(op->ptr, "filepath");
+ RNA_property_string_get(op->ptr, prop, filepath);
+ if (BKE_add_image_extension(filepath, imtype)) {
+ RNA_property_string_set(op->ptr, prop, filepath);
+ /* note, we could check for and update 'filename' here,
+ * but so far nothing needs this. */
+ return TRUE;
+ }
+ return FALSE;
+}
+
/* default properties for fileselect */
void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action, short flag, short display)
{
More information about the Bf-blender-cvs
mailing list