diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-31 07:07:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-31 07:07:14 +0400 |
commit | 81f5c9ed9b8193864f1c6160aed9eef9338f0d27 (patch) | |
tree | de71a52d3ed2c5a1fd47a846af5d68e1c571e606 /source/gameengine | |
parent | 50ca81154e5ead104723ba137942e92cb860ace8 (diff) | |
parent | 792452a7e53aa92361145e415491943bc91d8a6e (diff) |
svn merge ^/trunk/blender -r42991:43009
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Expressions/StringValue.h | 2 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Material.cpp | 18 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Texture.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Dome.cpp | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_FontObject.cpp | 79 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_FontObject.h | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_MeshProxy.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 2 |
11 files changed, 107 insertions, 21 deletions
diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/StringValue.h index e5a892ff82d..931858b7eed 100644 --- a/source/gameengine/Expressions/StringValue.h +++ b/source/gameengine/Expressions/StringValue.h @@ -43,7 +43,7 @@ public: virtual CValue* GetReplica(); #ifdef WITH_PYTHON virtual PyObject* ConvertValueToPython() { - return PyUnicode_FromString(m_strString.Ptr()); + return PyUnicode_From_STR_String(m_strString); } #endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index f9697a55d3f..10d8a8abd8f 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -221,7 +221,7 @@ public: //static PyObject* PyMake(PyObject*,PyObject*); virtual PyObject *py_repr(void) { - return PyUnicode_FromString((const char*)GetText()); + return PyUnicode_From_STR_String(GetText()); } virtual PyObject* ConvertValueToPython() { diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp index fd0756d067d..092f9273a6b 100644 --- a/source/gameengine/Ketsji/BL_Material.cpp +++ b/source/gameengine/Ketsji/BL_Material.cpp @@ -98,21 +98,24 @@ void BL_Material::Initialize() } } -void BL_Material::SetConversionRGB(unsigned int *nrgb) { +void BL_Material::SetConversionRGB(unsigned int *nrgb) +{ rgb[0]=*nrgb++; rgb[1]=*nrgb++; rgb[2]=*nrgb++; rgb[3]=*nrgb; } -void BL_Material::GetConversionRGB(unsigned int *nrgb) { +void BL_Material::GetConversionRGB(unsigned int *nrgb) +{ *nrgb++ = rgb[0]; *nrgb++ = rgb[1]; *nrgb++ = rgb[2]; *nrgb = rgb[3]; } -void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) { +void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) +{ uvName = name; uv[0] = *nuv++; uv[1] = *nuv++; @@ -120,13 +123,15 @@ void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) { uv[3] = *nuv; } -void BL_Material::GetConversionUV(MT_Point2 *nuv){ +void BL_Material::GetConversionUV(MT_Point2 *nuv) +{ *nuv++ = uv[0]; *nuv++ = uv[1]; *nuv++ = uv[2]; *nuv = uv[3]; } -void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) { +void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) +{ uv2Name = name; uv2[0] = *nuv++; uv2[1] = *nuv++; @@ -134,7 +139,8 @@ void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) { uv2[3] = *nuv; } -void BL_Material::GetConversionUV2(MT_Point2 *nuv){ +void BL_Material::GetConversionUV2(MT_Point2 *nuv) +{ *nuv++ = uv2[0]; *nuv++ = uv2[1]; *nuv++ = uv2[2]; diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index 6c57776cb60..2c57004e6c4 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -38,10 +38,12 @@ extern "C" { } // (n&(n-1)) zeros the least significant bit of n -static int is_power_of_2_i(int num) { +static int is_power_of_2_i(int num) +{ return ((num)&(num-1))==0; } -static int power_of_2_min_i(int num) { +static int power_of_2_min_i(int num) +{ while (!is_power_of_2_i(num)) num= num&(num-1); return num; diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 2736516bf33..18f9875a804 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -106,7 +106,7 @@ public: #ifdef WITH_PYTHON // -------------------------------- - virtual PyObject* py_repr(void) { return PyUnicode_FromString(mMaterial->matname.ReadPtr()); } + virtual PyObject* py_repr(void) { return PyUnicode_From_STR_String(mMaterial->matname); } static PyObject* pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index 828c327a228..4f959d9d2f9 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -255,7 +255,8 @@ void KX_Dome::CalculateImageSize(void) } } -bool KX_Dome::CreateDL(){ +bool KX_Dome::CreateDL() +{ dlistId = glGenLists((GLsizei) m_numimages); if (dlistId != 0) { if(m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED_FRONT || m_mode == DOME_TRUNCATED_REAR){ diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index 7e40af2f3c4..eca9a14ce7c 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -41,6 +41,26 @@ extern "C" { #define BGE_FONT_RES 100 +std::vector<STR_String> split_string(STR_String str) +{ + std::vector<STR_String> text = std::vector<STR_String>(); + + /* Split the string upon new lines */ + int begin=0, end=0; + while (end < str.Length()) + { + if(str.GetAt(end) == '\n') + { + text.push_back(str.Mid(begin, end-begin)); + begin = end+1; + } + end++; + } + //Now grab the last line + text.push_back(str.Mid(begin, end-begin)); + + return text; +} KX_FontObject::KX_FontObject( void* sgReplicationInfo, SG_Callbacks callbacks, RAS_IRenderTools* rendertools, @@ -52,8 +72,10 @@ KX_FontObject::KX_FontObject( void* sgReplicationInfo, m_rendertools(rendertools) { Curve *text = static_cast<Curve *> (ob->data); - m_text = text->str; + m_text = split_string(text->str); m_fsize = text->fsize; + m_line_spacing = text->linedist; + m_offset = MT_Vector3(text->xof, text->yof, 0); /* FO_BUILTIN_NAME != "default" */ /* I hope at some point Blender (2.5x) can have a single font */ @@ -95,20 +117,45 @@ void KX_FontObject::ProcessReplica() void KX_FontObject::DrawText() { + /* Allow for some logic brick control */ + if(this->GetProperty("text")) + m_text = split_string(this->GetProperty("text")->GetText()); + /* only draws the text if visible */ if(this->GetVisible() == 0) return; /* update the animated color */ this->GetObjectColor().getValue(m_color); - /* XXX 2DO - handle multiple lines */ /* HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly */ float RES = BGE_FONT_RES * m_resolution; float size = m_fsize * m_object->size[0] * RES; float aspect = 1.f / (m_object->size[0] * RES); - m_rendertools->RenderText3D(m_fontid, m_text, int(size), m_dpi, m_color, this->GetOpenGLMatrix(), aspect); + /* Get a working copy of the OpenGLMatrix to use */ + double mat[16]; + memcpy(mat, this->GetOpenGLMatrix(), sizeof(double)*16); + + /* Account for offset */ + MT_Vector3 offset = this->NodeGetWorldOrientation() * m_offset * this->NodeGetWorldScaling(); + mat[12] += offset[0]; mat[13] += offset[1]; mat[14] += offset[2]; + + /* Orient the spacing vector */ + MT_Vector3 spacing = MT_Vector3(0, m_fsize*m_line_spacing, 0); + spacing = this->NodeGetWorldOrientation() * spacing * this->NodeGetWorldScaling()[1]; + + /* Draw each line, taking spacing into consideration */ + for(int i=0; i<m_text.size(); ++i) + { + if (i!=0) + { + mat[12] -= spacing[0]; + mat[13] -= spacing[1]; + mat[14] -= spacing[2]; + } + m_rendertools->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, m_color, mat, aspect); + } } #ifdef WITH_PYTHON @@ -150,11 +197,35 @@ PyMethodDef KX_FontObject::Methods[] = { }; PyAttributeDef KX_FontObject::Attributes[] = { - KX_PYATTRIBUTE_STRING_RW("text", 0, 280, false, KX_FontObject, m_text), //arbitrary limit. 280 = 140 unicode chars in unicode + //KX_PYATTRIBUTE_STRING_RW("text", 0, 280, false, KX_FontObject, m_text[0]), //arbitrary limit. 280 = 140 unicode chars in unicode + KX_PYATTRIBUTE_RW_FUNCTION("text", KX_FontObject, pyattr_get_text, pyattr_set_text), KX_PYATTRIBUTE_FLOAT_RW("size", 0.0001f, 10000.0f, KX_FontObject, m_fsize), KX_PYATTRIBUTE_FLOAT_RW("resolution", 0.0001f, 10000.0f, KX_FontObject, m_resolution), /* KX_PYATTRIBUTE_INT_RW("dpi", 0, 10000, false, KX_FontObject, m_dpi), */// no real need for expose this I think { NULL } //Sentinel }; +PyObject* KX_FontObject::pyattr_get_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_FontObject* self= static_cast<KX_FontObject*>(self_v); + STR_String str = STR_String(); + for(int i=0; i<self->m_text.size(); ++i) + { + if(i!=0) + str += '\n'; + str += self->m_text[i]; + } + return PyUnicode_From_STR_String(str); +} + +int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_FontObject* self= static_cast<KX_FontObject*>(self_v); + if(!PyUnicode_Check(value)) + return PY_SET_ATTR_FAIL; + char* chars = _PyUnicode_AsString(value); + self->m_text = split_string(STR_String(chars)); + return PY_SET_ATTR_SUCCESS; +} + #endif // WITH_PYTHON diff --git a/source/gameengine/Ketsji/KX_FontObject.h b/source/gameengine/Ketsji/KX_FontObject.h index 8fc7a9e9f28..958a6cd3360 100644 --- a/source/gameengine/Ketsji/KX_FontObject.h +++ b/source/gameengine/Ketsji/KX_FontObject.h @@ -57,13 +57,15 @@ public: virtual void ProcessReplica(); protected: - STR_String m_text; + std::vector<STR_String> m_text; Object* m_object; int m_fontid; int m_dpi; float m_fsize; float m_resolution; float m_color[4]; + float m_line_spacing; + MT_Vector3 m_offset; class RAS_IRenderTools* m_rendertools; //needed for drawing routine @@ -76,6 +78,8 @@ public: */ #ifdef WITH_PYTHON + static PyObject* pyattr_get_text(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); #endif }; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 245a92a96de..cc078e96e64 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -888,7 +888,7 @@ public: */ virtual PyObject* py_repr(void) { - return PyUnicode_FromString(GetName().ReadPtr()); + return PyUnicode_From_STR_String(GetName()); } KX_PYMETHOD_O(KX_GameObject,SetWorldPosition); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index fec1d9d296c..fa1366874a3 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -247,12 +247,14 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_ return materials; } -PyObject * KX_MeshProxy::pyattr_get_numMaterials(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { +PyObject * KX_MeshProxy::pyattr_get_numMaterials(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) +{ KX_MeshProxy * self = static_cast<KX_MeshProxy *> (selfv); return PyLong_FromSsize_t(self->m_meshobj->NumMaterials()); } -PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { +PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) +{ KX_MeshProxy * self = static_cast<KX_MeshProxy *> (selfv); return PyLong_FromSsize_t(self->m_meshobj->NumPolygons()); } diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index c8070736b7f..c3e6fa376dd 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -617,7 +617,7 @@ public: static PyObject* pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_drawing_callback_post(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - virtual PyObject* py_repr(void) { return PyUnicode_FromString(GetName().ReadPtr()); } + virtual PyObject* py_repr(void) { return PyUnicode_From_STR_String(GetName()); } /* getitem/setitem */ static PyMappingMethods Mapping; |