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-01-05 15:23:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-05 15:23:24 +0400
commit348f116fe574ee38a70e8c9bdff7fc62ad1ec2e8 (patch)
tree1052824afb1efc07da2e17ade92ee1a6ae16cf4a /source/gameengine
parent67db64bf818f9cc1dddbcef9dbb7213422d82feb (diff)
parent7f555daa64d5e80f8d9dd2acf592d18dc8986309 (diff)
svn merge ^/trunk/blender -r43124:43160
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.cpp86
-rw-r--r--source/gameengine/Ketsji/KX_FontObject.cpp86
2 files changed, 157 insertions, 15 deletions
diff --git a/source/gameengine/Converter/KX_ConvertProperties.cpp b/source/gameengine/Converter/KX_ConvertProperties.cpp
index 7a574276eb4..8eea39c4956 100644
--- a/source/gameengine/Converter/KX_ConvertProperties.cpp
+++ b/source/gameengine/Converter/KX_ConvertProperties.cpp
@@ -48,11 +48,21 @@
#include "SCA_TimeEventManager.h"
#include "SCA_IScene.h"
+#include "KX_FontObject.h"
+#include "DNA_curve_types.h"
+
/* This little block needed for linking to Blender... */
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
+extern "C" {
+ #include "BKE_property.h"
+}
+
+/* prototype */
+void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer);
+
void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
{
@@ -155,4 +165,80 @@ void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventMan
// reserve name for object state
scene->AddDebugProperty(gameobj,STR_String("__state__"));
}
+
+ /* Font Objects need to 'copy' the Font Object data body to ["Text"] */
+ if (object->type == OB_FONT)
+ {
+ BL_ConvertTextProperty(object, (KX_FontObject *)gameobj, timemgr, scene, isInActiveLayer);
+ }
+}
+
+void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
+{
+ CValue* tprop = fontobj->GetProperty("Text");
+ if(!tprop) return;
+ bProperty* prop = get_ob_property(object, "Text");
+ if(!prop) return;
+
+ Curve *curve = static_cast<Curve *>(object->data);
+ STR_String str = curve->str;
+ CValue* propval = NULL;
+
+ switch(prop->type) {
+ case GPROP_BOOL:
+ {
+ int value = atoi(str);
+ propval = new CBoolValue((bool)(value != 0));
+ tprop->SetValue(propval);
+ break;
+ }
+ case GPROP_INT:
+ {
+ int value = atoi(str);
+ propval = new CIntValue(value);
+ tprop->SetValue(propval);
+ break;
+ }
+ case GPROP_FLOAT:
+ {
+ float floatprop = atof(str);
+ propval = new CFloatValue(floatprop);
+ tprop->SetValue(propval);
+ break;
+ }
+ case GPROP_STRING:
+ {
+ propval = new CStringValue(str, "");
+ tprop->SetValue(propval);
+ break;
+ }
+ case GPROP_TIME:
+ {
+ float floatprop = atof(str);
+
+ CValue* timeval = new CFloatValue(floatprop);
+ // set a subproperty called 'timer' so that
+ // we can register the replica of this property
+ // at the time a game object is replicated (AddObjectActuator triggers this)
+ CValue *bval = new CBoolValue(true);
+ timeval->SetProperty("timer",bval);
+ bval->Release();
+ if (isInActiveLayer)
+ {
+ timemgr->AddTimeProperty(timeval);
+ }
+
+ propval = timeval;
+ tprop->SetValue(timeval);
+ }
+ default:
+ {
+ // todo make an assert etc.
+ }
+ }
+
+ if (propval) {
+ propval->Release();
+ }
}
+
diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp
index 5a4d9065605..8cce9471587 100644
--- a/source/gameengine/Ketsji/KX_FontObject.cpp
+++ b/source/gameengine/Ketsji/KX_FontObject.cpp
@@ -34,6 +34,14 @@
#include "KX_Scene.h"
#include "KX_PythonInit.h"
#include "BLI_math.h"
+#include "StringValue.h"
+
+/* paths needed for font load */
+#include "BLI_blenlib.h"
+#include "BKE_global.h"
+#include "BKE_font.h"
+#include "BKE_main.h"
+#include "DNA_packedFile_types.h"
extern "C" {
#include "BLF_api.h"
@@ -41,6 +49,9 @@ extern "C" {
#define BGE_FONT_RES 100
+/* proptotype */
+int GetFontId(VFont *font);
+
std::vector<STR_String> split_string(STR_String str)
{
std::vector<STR_String> text = std::vector<STR_String>();
@@ -61,6 +72,7 @@ std::vector<STR_String> split_string(STR_String str)
return text;
}
+
KX_FontObject::KX_FontObject( void* sgReplicationInfo,
SG_Callbacks callbacks,
RAS_IRenderTools* rendertools,
@@ -76,20 +88,9 @@ KX_FontObject::KX_FontObject( void* sgReplicationInfo,
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 */
- /* with unicode support for ui and OB_FONT */
- /* once we have packed working we can load the FO_BUILTIN_NAME font */
- const char* filepath = text->vfont->name;
- if (strcmp(FO_BUILTIN_NAME, filepath) == 0)
- filepath = "default";
-
- /* XXX - if it's packed it will not work. waiting for bdiego (Diego) fix for that. */
- m_fontid = BLF_load(filepath);
- if (m_fontid == -1)
- m_fontid = BLF_load("default");
-
+
+ m_fontid = GetFontId(text->vfont);
+
/* initialize the color with the object color and store it in the KX_Object class
This is a workaround waiting for the fix:
[#25487] BGE: Object Color only works when it has a keyed frame */
@@ -115,6 +116,50 @@ void KX_FontObject::ProcessReplica()
KX_GetActiveScene()->AddFont(this);
}
+int GetFontId (VFont *font) {
+ PackedFile *packedfile=NULL;
+ int fontid = -1;
+
+ if (font->packedfile) {
+ packedfile= font->packedfile;
+ fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
+
+ if (fontid == -1) {
+ printf("ERROR: packed font \"%s\" could not be loaded.\n", font->name);
+ fontid = BLF_load("default");
+ }
+ return fontid;
+ }
+
+ /* once we have packed working we can load the FO_BUILTIN_NAME font */
+ const char *filepath = font->name;
+ if (strcmp(FO_BUILTIN_NAME, filepath) == 0) {
+ fontid = BLF_load("default");
+
+ /* XXX the following code is supposed to work (after you add get_builtin_packedfile to BKE_font.h )
+ * unfortunately it's crashing on blf_glyph.c:173 because gc->max_glyph_width is 0
+ */
+ // packedfile=get_builtin_packedfile();
+ // fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
+ // return fontid;
+
+ return BLF_load("default");
+ }
+
+ /* convert from absolute to relative */
+ char expanded[256]; // font names can be bigger than FILE_MAX (240)
+ BLI_strncpy(expanded, filepath, 256);
+ BLI_path_abs(expanded, G.main->name);
+
+ fontid = BLF_load(expanded);
+
+ /* fallback */
+ if (fontid == -1)
+ fontid = BLF_load("default");
+
+ return fontid;
+}
+
void KX_FontObject::DrawText()
{
/* Allow for some logic brick control */
@@ -224,7 +269,18 @@ int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrd
if(!PyUnicode_Check(value))
return PY_SET_ATTR_FAIL;
char* chars = _PyUnicode_AsString(value);
- self->m_text = split_string(STR_String(chars));
+
+ /* Allow for some logic brick control */
+ CValue* tprop = self->GetProperty("Text");
+ if(tprop) {
+ CValue *newstringprop = new CStringValue(STR_String(chars), "Text");
+ self->SetProperty("Text", newstringprop);
+ newstringprop->Release();
+ }
+ else {
+ self->m_text = split_string(STR_String(chars));
+ }
+
return PY_SET_ATTR_SUCCESS;
}