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:
authorMatt Ebb <matt@mke3.net>2010-01-11 08:10:57 +0300
committerMatt Ebb <matt@mke3.net>2010-01-11 08:10:57 +0300
commite0dd3fe5872ba37ff188e292b80b46fcf8df413c (patch)
treee19ba24ad589b30160a663e26a6ac00068c5a4f2
parent9d67c720d5328f1918cc01d86a326c0aca3e0d06 (diff)
* Restored font selection functionality with open font and unlink font operators,
so you can change the font of 3D text objects.
-rw-r--r--release/scripts/ui/properties_data_curve.py10
-rw-r--r--source/blender/blenkernel/intern/font.c6
-rw-r--r--source/blender/blenlib/intern/freetypefont.c2
-rw-r--r--source/blender/editors/curve/curve_intern.h3
-rw-r--r--source/blender/editors/curve/curve_ops.c3
-rw-r--r--source/blender/editors/curve/editfont.c167
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c5
-rw-r--r--source/blender/makesrna/intern/rna_ID.c13
-rw-r--r--source/blender/makesrna/intern/rna_curve.c3
-rw-r--r--source/blender/makesrna/intern/rna_vfont.c2
10 files changed, 205 insertions, 9 deletions
diff --git a/release/scripts/ui/properties_data_curve.py b/release/scripts/ui/properties_data_curve.py
index 442590b8946..4071c7b0412 100644
--- a/release/scripts/ui/properties_data_curve.py
+++ b/release/scripts/ui/properties_data_curve.py
@@ -282,10 +282,12 @@ class DATA_PT_font(DataButtonsPanel):
char = context.curve.edit_format
wide_ui = context.region.width > narrowui
- if wide_ui:
- layout.prop(text, "font")
- else:
- layout.prop(text, "font", text="")
+ layout.template_ID(text, "font", open="font.open", unlink="font.unlink")
+
+ #if wide_ui:
+ # layout.prop(text, "font")
+ #else:
+ # layout.prop(text, "font", text="")
split = layout.split()
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 1a63f97e310..41e5178d6cb 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -398,7 +398,11 @@ VFont *load_vfont(char *name)
if (vfd) {
vfont = alloc_libblock(&G.main->vfont, ID_VF, filename);
vfont->data = vfd;
-
+
+ /* if there's a font name, use it for the ID name */
+ if (strcmp(vfd->name, "")!=0) {
+ BLI_strncpy(vfont->id.name+2, vfd->name, 21);
+ }
BLI_strncpy(vfont->name, name, sizeof(vfont->name));
// if autopack is on store the packedfile in de font structure
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index f2727f6f259..35b9c86892a 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -359,7 +359,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
// get the name
fontname = FT_Get_Postscript_Name(face);
- strcpy(vfd->name, (fontname == NULL) ? "Fontname not available" : fontname);
+ strcpy(vfd->name, (fontname == NULL) ? "" : fontname);
// Extract the first 256 character from TTF
lcode= charcode= FT_Get_First_Char(face, &glyph_index);
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index 6c477bd011a..ca5aa213d36 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -63,6 +63,9 @@ void FONT_OT_delete(struct wmOperatorType *ot);
void FONT_OT_change_character(struct wmOperatorType *ot);
void FONT_OT_change_spacing(struct wmOperatorType *ot);
+void FONT_OT_open(struct wmOperatorType *ot);
+void FONT_OT_unlink(struct wmOperatorType *ot);
+
/* editcurve.c */
void CURVE_OT_hide(struct wmOperatorType *ot);
void CURVE_OT_reveal(struct wmOperatorType *ot);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 660db2f0951..a3b620ef7b5 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -87,6 +87,9 @@ void ED_operatortypes_curve(void)
WM_operatortype_append(FONT_OT_change_character);
WM_operatortype_append(FONT_OT_change_spacing);
+
+ WM_operatortype_append(FONT_OT_open);
+ WM_operatortype_append(FONT_OT_unlink);
WM_operatortype_append(CURVE_OT_hide);
WM_operatortype_append(CURVE_OT_reveal);
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index da794eb1c25..101f0e2074c 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -54,6 +54,7 @@
#include "BKE_depsgraph.h"
#include "BKE_font.h"
#include "BKE_global.h"
+#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_report.h"
@@ -70,6 +71,8 @@
#include "ED_screen.h"
#include "ED_util.h"
+#include "UI_interface.h"
+
#include "curve_intern.h"
#define MAXTEXT 32766
@@ -1538,6 +1541,169 @@ void FONT_OT_case_toggle(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+/* **************** Open Font ************** */
+
+static void open_init(bContext *C, wmOperator *op)
+{
+ PropertyPointerRNA *pprop;
+
+ op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
+ uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
+}
+
+static int open_cancel(bContext *C, wmOperator *op)
+{
+ MEM_freeN(op->customdata);
+ op->customdata= NULL;
+ return OPERATOR_CANCELLED;
+}
+
+static int open_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = CTX_data_active_object(C);
+ Curve *cu;
+ VFont *font;
+ PropertyPointerRNA *pprop;
+ PointerRNA idptr;
+ char str[FILE_MAX];
+
+ RNA_string_get(op->ptr, "path", str);
+
+ font = load_vfont(str);
+
+ if(!font) {
+ if(op->customdata) MEM_freeN(op->customdata);
+ return OPERATOR_CANCELLED;
+ }
+
+ if(!op->customdata)
+ open_init(C, op);
+
+ /* hook into UI */
+ pprop= op->customdata;
+
+ if(pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ font->id.us--;
+
+ RNA_id_pointer_create(&font->id, &idptr);
+ RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+ RNA_property_update(C, &pprop->ptr, pprop->prop);
+ } else if(ob && ob->type == OB_FONT) {
+ cu = ob->data;
+ id_us_min(&cu->vfont->id);
+ cu->vfont = font;
+ }
+
+ DAG_id_flush_update(ob->data, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
+
+ MEM_freeN(op->customdata);
+
+ return OPERATOR_FINISHED;
+}
+
+static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ Object *ob = CTX_data_active_object(C);
+ Curve *cu;
+ VFont *font=NULL;
+ char *path;
+ if (ob && ob->type == OB_FONT) {
+ cu = ob->data;
+ font = cu->vfont;
+ }
+ path = (font && font->name)? font->name: U.fontdir;
+
+ if(RNA_property_is_set(op->ptr, "path"))
+ return open_exec(C, op);
+
+ open_init(C, op);
+
+ RNA_string_set(op->ptr, "path", path);
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void FONT_OT_open(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Open";
+ ot->idname= "FONT_OT_open";
+
+ /* api callbacks */
+ ot->exec= open_exec;
+ ot->invoke= open_invoke;
+ ot->cancel= open_cancel;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL);
+}
+
+/******************* delete operator *********************/
+static int font_unlink_poll(bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ Curve *cu;
+
+ if (!ED_operator_object_active_editable(C) ) return 0;
+ if (ob->type != OB_FONT) return 0;
+
+ cu = ob->data;
+ if (cu && strcmp(cu->vfont->name, "<builtin>")==0) return 0;
+ return 1;
+}
+
+static int font_unlink_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = CTX_data_active_object(C);
+ Curve *cu;
+ VFont *font, *builtin_font;
+
+ cu = ob->data;
+ font = cu->vfont;
+
+ if (!font) {
+ BKE_report(op->reports, RPT_ERROR, "No font datablock available to unlink.");
+ return OPERATOR_CANCELLED;
+ }
+
+ if (strcmp(font->name, "<builtin>")==0) {
+ BKE_report(op->reports, RPT_WARNING, "Can't unlink the default builtin font.");
+ return OPERATOR_FINISHED;
+ }
+
+ /* revert back to builtin font */
+ builtin_font = get_builtin_font();
+
+ cu->vfont = builtin_font;
+ id_us_plus(&cu->vfont->id);
+ id_us_min(&font->id);
+
+ DAG_id_flush_update(ob->data, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
+
+ return OPERATOR_FINISHED;
+}
+
+void FONT_OT_unlink(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Unlink";
+ ot->idname= "FONT_OT_unlink";
+ ot->description= "Unlink active font data block.";
+
+ /* api callbacks */
+ ot->exec= font_unlink_exec;
+ ot->poll= font_unlink_poll;
+}
+
+
/* **************** undo for font object ************** */
static void undoFont_to_editFont(void *strv, void *ecu)
@@ -1595,4 +1761,3 @@ void undo_push_font(bContext *C, char *name)
{
undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL);
}
-
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 6ee0e341849..31c02be6621 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -483,6 +483,11 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
ED_region_tag_redraw(ar);
break;
}
+ switch(wmn->action) {
+ case NA_EDITED:
+ ED_region_tag_redraw(ar);
+ break;
+ }
break;
case NC_GROUP:
/* all group ops for now */
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index e931f08c3a3..ac354366c25 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -93,6 +93,18 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value)
test_idbutton(id->name+2);
}
+static int rna_ID_name_editable(PointerRNA *ptr)
+{
+ ID *id= (ID*)ptr->data;
+
+ if (GS(id->name) == ID_VF) {
+ if (strcmp(id->name+2, "<builtin>")==0)
+ return 0;
+ }
+
+ return 1;
+}
+
short RNA_type_to_ID_code(StructRNA *type)
{
if(RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
@@ -365,6 +377,7 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name.");
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
RNA_def_property_string_maxlength(prop, sizeof(((ID*)NULL)->name)-2);
+ RNA_def_property_editable_func(prop, "rna_ID_name_editable");
RNA_def_property_update(prop, NC_ID|NA_RENAME, NULL);
RNA_def_struct_name_property(srna, prop);
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c
index d3a56661813..98c2963a110 100644
--- a/source/blender/makesrna/intern/rna_curve.c
+++ b/source/blender/makesrna/intern/rna_curve.c
@@ -73,7 +73,7 @@ static StructRNA *rna_Curve_refine(PointerRNA *ptr)
{
Curve *cu= (Curve*)ptr->data;
short obtype= curve_type(cu);
-
+
if(obtype == OB_FONT) return &RNA_TextCurve;
else if(obtype == OB_SURF) return &RNA_SurfaceCurve;
else return &RNA_Curve;
@@ -634,6 +634,7 @@ static void rna_def_font(BlenderRNA *brna, StructRNA *srna)
prop= RNA_def_property(srna, "font", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "vfont");
RNA_def_property_ui_text(prop, "Font", "");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
prop= RNA_def_property(srna, "edit_format", PROP_POINTER, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_vfont.c b/source/blender/makesrna/intern/rna_vfont.c
index aa2aaaf6342..db576207eae 100644
--- a/source/blender/makesrna/intern/rna_vfont.c
+++ b/source/blender/makesrna/intern/rna_vfont.c
@@ -43,7 +43,7 @@ void RNA_def_vfont(BlenderRNA *brna)
srna= RNA_def_struct(brna, "VectorFont", "ID");
RNA_def_struct_ui_text(srna, "Vector Font", "Vector font for Text objects.");
RNA_def_struct_sdna(srna, "VFont");
- RNA_def_struct_ui_icon(srna, ICON_FONT_DATA);
+ RNA_def_struct_ui_icon(srna, ICON_FILE_FONT);
prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);