Skip to content

Commit

Permalink
UPBGE: Restore background API for retrocompatibility
Browse files Browse the repository at this point in the history
bge.render.setBackgroundColor
ImageRender.background
KX_WorldInfo.backgroundColor
  • Loading branch information
youle31 authored and panzergame committed Apr 18, 2016
1 parent 1f00efd commit b9069c4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/python_api/rst/bge.render.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Functions

.. function:: setBackgroundColor(rgba)

Deprecated and no longer functional. Use :py:meth:`bge.types.KX_WorldInfo.backgroundColor` instead.
Deprecated and no longer functional. Use :py:meth:`bge.types.KX_WorldInfo.horizonColor` or :py:meth:`bge.types.KX_WorldInfo.zenithColor` instead.


.. function:: setEyeSeparation(eyesep)
Expand Down
12 changes: 12 additions & 0 deletions doc/python_api/rst/bge.texture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ Image classes

:type: float list [r, g, b, a] in [0.0, 1.0]

.. attribute:: background

:type: float list [r, g, b, a] in [0.0, 1.0]

Deprecated use :py:meth:`bge.texture.ImageMirror.horizon` or :py:meth:`bge.texture.ImageMirror.zenith` instead.

.. attribute:: capsize

Size of render area.
Expand Down Expand Up @@ -578,6 +584,12 @@ Image classes

:type: float list [r, g, b, a] in [0.0, 1.0]

.. attribute:: background

:type: float list [r, g, b, a] in [0.0, 1.0]

Deprecated use :py:meth:`bge.texture.ImageRender.horizon` or :py:meth:`bge.texture.ImageRender.zenith` instead.

.. attribute:: capsize

Size of render area.
Expand Down
18 changes: 18 additions & 0 deletions source/gameengine/Ketsji/KX_PythonInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,23 @@ static PyObject *gPyGetWindowWidth(PyObject *, PyObject *args)
return PyLong_FromLong((canvas ? canvas->GetWidth() : 0));
}

static PyObject *gPySetBackgroundColor(PyObject *, PyObject *value)
{
MT_Vector4 vec;
if (!PyVecTo(value, vec))
return NULL;

KX_WorldInfo *wi = KX_GetActiveScene()->GetWorldInfo();
if (!wi->hasWorld()) {
PyErr_SetString(PyExc_RuntimeError, "bge.render.SetBackgroundColor(color), World not available");
return NULL;
}
ShowDeprecationWarning("setBackgroundColor()", "KX_WorldInfo.horizonColor/zenithColor");
wi->setHorizonColor(vec.to3d());
wi->setZenithColor(vec.to3d());
Py_RETURN_NONE;
}

static PyObject *gPyEnableVisibility(PyObject *, PyObject *args)
{
int visible;
Expand Down Expand Up @@ -1389,6 +1406,7 @@ static struct PyMethodDef rasterizer_methods[] = {
METH_VARARGS, "showMouse(bool visible)"},
{"setMousePosition",(PyCFunction) gPySetMousePosition,
METH_VARARGS, "setMousePosition(int x,int y)"},
{"setBackgroundColor", (PyCFunction)gPySetBackgroundColor, METH_O, "set Background Color (rgb)"},
{"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"},
{"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"},

Expand Down
24 changes: 24 additions & 0 deletions source/gameengine/Ketsji/KX_WorldInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ PyAttributeDef KX_WorldInfo::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_INV_QUADRATIC", KX_WorldInfo, pyattr_get_mist_typeconst),
KX_PYATTRIBUTE_RW_FUNCTION("mistColor", KX_WorldInfo, pyattr_get_mist_color, pyattr_set_mist_color),
KX_PYATTRIBUTE_RW_FUNCTION("horizonColor", KX_WorldInfo, pyattr_get_horizon_color, pyattr_set_horizon_color),
KX_PYATTRIBUTE_RW_FUNCTION("backgroundColor", KX_WorldInfo, pyattr_get_background_color, pyattr_set_background_color), // DEPRECATED use horizoncolor/zenithColor instead.
KX_PYATTRIBUTE_RW_FUNCTION("zenithColor", KX_WorldInfo, pyattr_get_zenith_color, pyattr_set_zenith_color),
KX_PYATTRIBUTE_RW_FUNCTION("ambientColor", KX_WorldInfo, pyattr_get_ambient_color, pyattr_set_ambient_color),
{ NULL } /* Sentinel */
Expand Down Expand Up @@ -505,6 +506,29 @@ int KX_WorldInfo::pyattr_set_horizon_color(void *self_v, const KX_PYATTRIBUTE_DE
return PY_SET_ATTR_FAIL;
}

PyObject *KX_WorldInfo::pyattr_get_background_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
ShowDeprecationWarning("KX_WorldInfo.backgroundColor", "KX_WorldInfo.horizonColor/zenithColor");
KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
return PyObjectFrom(MT_Vector3(self->m_horizoncolor));
}

int KX_WorldInfo::pyattr_set_background_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);

ShowDeprecationWarning("KX_WorldInfo.backgroundColor", "KX_WorldInfo.horizonColor/zenithColor");

MT_Vector3 color;
if (PyVecTo(value, color))
{
self->setHorizonColor(color);
self->setZenithColor(color);
return PY_SET_ATTR_SUCCESS;
}
return PY_SET_ATTR_FAIL;
}

PyObject *KX_WorldInfo::pyattr_get_zenith_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{

Expand Down
2 changes: 2 additions & 0 deletions source/gameengine/Ketsji/KX_WorldInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class KX_WorldInfo : public PyObjectPlus
static int pyattr_set_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject *pyattr_get_horizon_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_horizon_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject *pyattr_get_background_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_background_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject *pyattr_get_zenith_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_zenith_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject *pyattr_get_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
Expand Down
13 changes: 13 additions & 0 deletions source/gameengine/VideoTexture/ImageRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,17 @@ static int setZenith(PyImage *self, PyObject *value, void *closure)
return 0;
}

static PyObject *getBackground(PyImage *self, void *closure)
{
ShowDeprecationWarning("Image.background", "Image.horizon/zenith");
return getHorizon(self, closure);
}

static int setBackground(PyImage *self, PyObject *value, void *closure)
{
ShowDeprecationWarning("Image.background", "Image.horizon/zenith");
return (setHorizon(self, value, closure) && setZenith(self, value, closure));
}

// methods structure
static PyMethodDef imageRenderMethods[] =
Expand All @@ -487,6 +498,7 @@ static PyMethodDef imageRenderMethods[] =
static PyGetSetDef imageRenderGetSets[] =
{
{(char*)"horizon", (getter)getHorizon, (setter)setHorizon, (char*)"horizon color", NULL},
{(char*)"background", (getter)getBackground, (setter)setBackground, (char*)"horizon color", NULL}, //DEPRECATED use horizon instead
{(char*)"zenith", (getter)getZenith, (setter)setZenith, (char*)"zenith color", NULL},
// attribute from ImageViewport
{(char*)"capsize", (getter)ImageViewport_getCaptureSize, (setter)ImageViewport_setCaptureSize, (char*)"size of render area", NULL},
Expand Down Expand Up @@ -651,6 +663,7 @@ static PyGetSetDef imageMirrorGetSets[] =
{(char*)"clip", (getter)getClip, (setter)setClip, (char*)"clipping distance", NULL},
// attribute from ImageRender
{(char*)"horizon", (getter)getHorizon, (setter)setHorizon, (char*)"horizon color", NULL},
{(char*)"background", (getter)getBackground, (setter)setBackground, (char*)"horizon color", NULL}, //DEPRECATED use horizon/zenith instead.
{(char*)"zenith", (getter)getZenith, (setter)setZenith, (char*)"zenith color", NULL},
// attribute from ImageViewport
{(char*)"capsize", (getter)ImageViewport_getCaptureSize, (setter)ImageViewport_setCaptureSize, (char*)"size of render area", NULL},
Expand Down

0 comments on commit b9069c4

Please sign in to comment.