Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-04-24 06:01:23 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-04-24 06:01:23 +0400
commit4ff038c4119327f3b0c472b71356d5e0cf2e0ed6 (patch)
tree395b8be489c012d9e2cf55d11a69303544bb6d68
parentb374d9b20fc7b5e320da4c00ba7e21976da6b0d3 (diff)
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).
-rw-r--r--source/blender/blenkernel/BKE_image.h2
-rw-r--r--source/blender/blenkernel/intern/image.c9
-rw-r--r--source/blender/editors/screen/screendump.c65
-rw-r--r--source/blender/editors/space_image/image_ops.c14
-rw-r--r--source/blender/makesdna/DNA_scene_types.h2
-rw-r--r--source/blender/windowmanager/WM_api.h1
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c17
7 files changed, 83 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index f5437645551..c2112d1e169 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -68,6 +68,8 @@ char BKE_imtype_valid_depths(const char imtype);
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);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 27779ef8107..6e0330f5316 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1163,6 +1163,15 @@ int BKE_add_image_extension(char *string, const char imtype)
}
}
+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];
diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c
index e12e6b0ef82..22a1770412f 100644
--- a/source/blender/editors/screen/screendump.c
+++ b/source/blender/editors/screen/screendump.c
@@ -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 @@ typedef struct ScreenshotData {
unsigned int *dumprect;
int dumpsx, dumpsy;
rcti crop;
+
+ ImageFormatData im_format;
} ScreenshotData;
/* get shot from frontbuffer */
@@ -113,9 +117,13 @@ static int screenshot_data_create(bContext *C, wmOperator *op)
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;
}
@@ -164,20 +172,13 @@ static int screenshot_exec(bContext *C, wmOperator *op)
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 @@ static int screenshot_exec(bContext *C, wmOperator *op)
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,8 +205,9 @@ static int screenshot_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)
if (screenshot_data_create(C, op)) {
if (RNA_struct_property_is_set(op->ptr, "filepath"))
return screenshot_exec(C, op);
-
- RNA_string_set(op->ptr, "filepath", G.ima);
+
+ /* extension is added by 'screenshot_check' after */
+ RNA_string_set(op->ptr, "filepath", G.relbase_valid ? G.main->name : "//screen");
WM_event_add_fileselect(C, op);
@@ -210,21 +216,52 @@ static int screenshot_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)
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->poll = WM_operator_winactive;
ot->cancel = screenshot_cancel;
+ ot->ui = screenshot_draw;
+ ot->poll = WM_operator_winactive;
ot->flag = 0;
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 8b1ff4136b9..2c688990a8f 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1001,11 +1001,7 @@ typedef struct {
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_exec(bContext *C, wmOperator *op)
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))
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index e21ca52ecb3..d2df799bc94 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -249,7 +249,7 @@ typedef struct ImageFormatData {
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 */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index a794cf10a86..4c81a0a8654 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -166,6 +166,7 @@ int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, struct wm
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 */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index c9306f6dcf7..514c159c87b 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -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(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
}
}
+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)
{