BGE: Adding a screenshot function to game actuator

Extending the existing game actuator with a screenshot function, to give also non programmers the ability to take screenshots in the BGE.

Reviewers: lordloki, campbellbarton, moguri

Reviewed By: lordloki, moguri

Subscribers: lordloki, Genome36

Projects: #game_engine

Differential Revision: https://developer.blender.org/D651
This commit is contained in:
Thomas Szepe 2015-10-11 13:41:38 +02:00
parent 3748bbf2d9
commit d1ee195260
7 changed files with 25 additions and 3 deletions

View File

@ -1696,7 +1696,7 @@ static void draw_actuator_filter_2d(uiLayout *layout, PointerRNA *ptr)
static void draw_actuator_game(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "mode") == ACT_GAME_LOAD)
if (ELEM(RNA_enum_get(ptr, "mode"), ACT_GAME_LOAD, ACT_GAME_SCREENSHOT))
uiItemR(layout, ptr, "filename", 0, NULL, ICON_NONE);
}

View File

@ -512,6 +512,7 @@ typedef struct bActuator {
#define ACT_GAME_QUIT 3
#define ACT_GAME_SAVECFG 4
#define ACT_GAME_LOADCFG 5
#define ACT_GAME_SCREENSHOT 6
/* visibilityact->flag */
/* Set means the object will become invisible */

View File

@ -1706,6 +1706,7 @@ static void rna_def_game_actuator(BlenderRNA *brna)
{ACT_GAME_QUIT, "QUIT", 0, "Quit Game", ""},
{ACT_GAME_SAVECFG, "SAVECFG", 0, "Save bge.logic.globalDict", ""},
{ACT_GAME_LOADCFG, "LOADCFG", 0, "Load bge.logic.globalDict", ""},
{ACT_GAME_SCREENSHOT, "SCREENSHOT", 0, "Screenshot", ""},
{0, NULL, 0, NULL, NULL}
};
@ -1722,8 +1723,8 @@ static void rna_def_game_actuator(BlenderRNA *brna)
/* ACT_GAME_LOAD */
prop = RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
RNA_def_property_ui_text(prop, "File",
"Load this blend file, use the \"//\" prefix for a path relative to the current "
"blend file");
"The file to use depending on the mode (e.g., the blend file to load or a destination "
"for saving a screenshot). Use the \"//\" prefix for a relative path.");
RNA_def_property_update(prop, NC_LOGIC, NULL);
/*XXX to do: an operator that calls file_browse with relative_path on and blender filtering active */
}

View File

@ -806,6 +806,12 @@ void BL_ConvertActuators(const char* maggiename,
mode = KX_GameActuator::KX_GAME_LOADCFG;
break;
}
case ACT_GAME_SCREENSHOT:
{
mode = KX_GameActuator::KX_GAME_SCREENSHOT;
filename = gameact->filename;
break;
}
default:
; /* flag error */
}

View File

@ -41,6 +41,7 @@
#include "KX_Scene.h"
#include "KX_KetsjiEngine.h"
#include "KX_PythonInit.h" /* for config load/saving */
#include "RAS_ICanvas.h"
#include <stdio.h>
#include <stdlib.h>
@ -204,6 +205,17 @@ bool KX_GameActuator::Update()
break;
#endif // WITH_PYTHON
}
case KX_GAME_SCREENSHOT:
{
RAS_ICanvas *canvas = m_ketsjiengine->GetCanvas();
if (canvas) {
canvas->MakeScreenShot(m_filename);
}
else {
printf("KX_GAME_SCREENSHOT error: Rasterizer not available");
}
break;
}
default:
; /* do nothing? this is an internal error !!! */
}

View File

@ -59,6 +59,7 @@ protected:
KX_GAME_QUIT,
KX_GAME_SAVECFG,
KX_GAME_LOADCFG,
KX_GAME_SCREENSHOT,
KX_GAME_MAX
};

View File

@ -1804,6 +1804,7 @@ PyMODINIT_FUNC initGameLogicPythonBinding()
KX_MACRO_addTypesToDict(d, KX_GAME_QUIT, KX_GameActuator::KX_GAME_QUIT);
KX_MACRO_addTypesToDict(d, KX_GAME_SAVECFG, KX_GameActuator::KX_GAME_SAVECFG);
KX_MACRO_addTypesToDict(d, KX_GAME_LOADCFG, KX_GameActuator::KX_GAME_LOADCFG);
KX_MACRO_addTypesToDict(d, KX_GAME_SCREENSHOT, KX_GameActuator::KX_GAME_SCREENSHOT);
/* Scene Actuator Modes */
KX_MACRO_addTypesToDict(d, KX_SCENE_RESTART, KX_SceneActuator::KX_SCENE_RESTART);