[Bf-blender-cvs] [3443686] master: Sequencer: changes to text effect strip

Campbell Barton noreply at git.blender.org
Fri Jul 10 18:35:52 CEST 2015


Commit: 3443686399feb4f96a9ea85f52f6750388b883a2
Author: Campbell Barton
Date:   Sat Jul 11 02:17:06 2015 +1000
Branches: master
https://developer.blender.org/rB3443686399feb4f96a9ea85f52f6750388b883a2

Sequencer: changes to text effect strip

- default alignment to lower center.
- placement is now relative,
  so changing output size keeps correct placement.
- instead of center override, add align option (left/right/center).

Also don't use pixel-size for setting the font size, on new strips.
Better not have UI prefs impact low level API's.

===================================================================

M	release/scripts/startup/bl_ui/space_sequencer.py
M	source/blender/blenkernel/intern/seqeffects.c
M	source/blender/makesdna/DNA_sequence_types.h
M	source/blender/makesrna/intern/rna_sequencer.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py
index 6c84eaf..5379d5b 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -632,13 +632,10 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel):
         elif strip.type == 'TEXT':
             col = layout.column()
             col.prop(strip, "text")
-            col.prop(strip, "text_size")
+            col.prop(strip, "font_size")
             col.prop(strip, "use_shadow")
-            col.prop(strip, "use_autocenter")
-            row = layout.row(align=True)
-            if not strip.use_autocenter:
-                row.prop(strip, "xpos")
-            row.prop(strip, "ypos")
+            col.prop(strip, "align")
+            col.prop(strip, "location")
             layout.operator("sequencer.export_subtitles")
 
         col = layout.column(align=True)
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 2d1ea53..3e6edbe 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -2888,8 +2888,11 @@ static void init_text_effect(Sequence *seq)
 		MEM_freeN(seq->effectdata);
 
 	data = seq->effectdata = MEM_callocN(sizeof(TextVars), "textvars");
-	data->text_size = U.pixelsize * 30;
+	data->text_size = 30;
 	BLI_strncpy(data->text, "Text", sizeof(data->text));
+
+	data->loc[0] = 0.5f;
+	data->align = SEQ_TEXT_ALIGN_CENTER;
 }
 
 static int num_inputs_text(void)
@@ -2916,7 +2919,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
 	struct ColorManagedDisplay *display;
 	const char *display_device;
 	const int mono = blf_mono_font_render; // XXX
-	int y_ofs, x, y, w;
+	int y_ofs, x, y;
 
 	display_device = context->scene->display_settings.display_device;
 	display = IMB_colormanagement_display_get_named(display_device);
@@ -2928,17 +2931,25 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
 
 	y_ofs = -BLF_descender(mono);
 
-	w = BLF_width(mono, data->text, sizeof(data->text));
+	x = (data->loc[0] * width);
+	y = (data->loc[1] * height) + y_ofs;
 
-	if (data->flags & TEXT_SEQ_AUTO_CENTER)
-		x = width / 2 - w / 2;
-	else
-		x = (context->scene->r.size / 100.0f) * data->xpos;
+	if (data->align == SEQ_TEXT_ALIGN_LEFT) {
+		/* pass */
+	}
+	else {
+		const int w = BLF_width(mono, data->text, sizeof(data->text));
 
-	y = y_ofs + (context->scene->r.size / 100.0f) * data->ypos;
+		if (data->align == SEQ_TEXT_ALIGN_RIGHT) {
+			x -= w;
+		}
+		else {  /* SEQ_TEXT_ALIGN_CENTER */
+			x -= w / 2;
+		}
+	}
 
 	/* BLF_SHADOW won't work with buffers, instead use cheap shadow trick */
-	if (data->flags & TEXT_SEQ_SHADOW) {
+	if (data->flag & SEQ_TEXT_SHADOW) {
 		int fontx, fonty;
 		fontx = BLF_width_max(mono);
 		fonty = BLF_height_max(mono);
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 377da2a..3f3bfdf 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -274,14 +274,24 @@ typedef struct GaussianBlurVars {
 typedef struct TextVars {
 	char text[512];
 	int text_size;
-	int xpos, ypos;
-	int flags;
+	float loc[2];
+	short flag;
+	char align;
+	char pad;
 } TextVars;
 
+/* TextVars.flag */
 enum {
-	TEXT_SEQ_SHADOW =      (1 << 0),
-	TEXT_SEQ_AUTO_CENTER = (1 << 1),
+	SEQ_TEXT_SHADOW =       (1 << 0),
 };
+
+/* TextVars.align */
+enum {
+	SEQ_TEXT_ALIGN_LEFT = 0,
+	SEQ_TEXT_ALIGN_CENTER = 1,
+	SEQ_TEXT_ALIGN_RIGHT = 2,
+};
+
 /* ***************** Sequence modifiers ****************** */
 
 typedef struct SequenceModifierData {
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index d7311b9..535428e 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -2307,23 +2307,34 @@ static void rna_def_gaussian_blur(StructRNA *srna)
 
 static void rna_def_text(StructRNA *srna)
 {
+	static EnumPropertyItem text_align_items[] = {
+		{SEQ_TEXT_ALIGN_LEFT, "LEFT", 0, "Left", ""},
+		{SEQ_TEXT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
+		{SEQ_TEXT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	PropertyRNA *prop;
 
 	RNA_def_struct_sdna_from(srna, "TextVars", "effectdata");
 
-	prop = RNA_def_property(srna, "text_size", PROP_INT, PROP_UNSIGNED);
+	prop = RNA_def_property(srna, "font_size", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_int_sdna(prop, NULL, "text_size");
 	RNA_def_property_ui_text(prop, "Size", "Size of the text");
 	RNA_def_property_ui_range(prop, 0.0f, 1000, 1, -1);
 	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
 
-	prop = RNA_def_property(srna, "xpos", PROP_INT, PROP_NONE);
-	RNA_def_property_ui_text(prop, "X Position", "X position of the text");
-	RNA_def_property_ui_range(prop, -1000, 1000, 1, -1);
+	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "loc");
+	RNA_def_property_ui_text(prop, "Location", "Location of the text");
+	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1);
 	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
 
-	prop = RNA_def_property(srna, "ypos", PROP_INT, PROP_NONE);
-	RNA_def_property_ui_text(prop, "Y Position", "Y position of the text");
-	RNA_def_property_ui_range(prop, -1000, 1000, 1, -1);
+	prop = RNA_def_property(srna, "align", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "align");
+	RNA_def_property_enum_items(prop, text_align_items);
+	RNA_def_property_ui_text(prop, "Align", "");
 	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
 
 	prop = RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
@@ -2331,14 +2342,9 @@ static void rna_def_text(StructRNA *srna)
 	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
 
 	prop = RNA_def_property(srna, "use_shadow", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flags", TEXT_SEQ_SHADOW);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_TEXT_SHADOW);
 	RNA_def_property_ui_text(prop, "Shadow", "draw text with shadow");
 	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
-
-	prop = RNA_def_property(srna, "use_autocenter", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flags", TEXT_SEQ_AUTO_CENTER);
-	RNA_def_property_ui_text(prop, "Auto-Center", "draw text centered in x axis");
-	RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
 }
 
 static EffectInfo def_effects[] = {




More information about the Bf-blender-cvs mailing list