From 91deffc42966156356151dbd6a2731c79ce088bd Mon Sep 17 00:00:00 2001 From: William Reynish Date: Mon, 21 Jun 2010 23:20:44 +0000 Subject: [PATCH] Added ability to add and remove text boxes back from Blender 2.4x. One on those small things missing. --- release/scripts/ui/properties_data_curve.py | 41 ++++++--- source/blender/editors/curve/curve_intern.h | 3 + source/blender/editors/curve/curve_ops.c | 3 + source/blender/editors/curve/editfont.c | 93 +++++++++++++++++++++ 4 files changed, 127 insertions(+), 13 deletions(-) diff --git a/release/scripts/ui/properties_data_curve.py b/release/scripts/ui/properties_data_curve.py index c5bf4b8459b..d807fa1631b 100644 --- a/release/scripts/ui/properties_data_curve.py +++ b/release/scripts/ui/properties_data_curve.py @@ -367,21 +367,36 @@ class DATA_PT_textboxes(DataButtonsPanel): text = context.curve wide_ui = context.region.width > narrowui - - for box in text.textboxes: - split = layout.box().split() - - col = split.column(align=True) - col.label(text="Dimensions:") - col.prop(box, "width", text="Width") - col.prop(box, "height", text="Height") + + split = layout.split() + col = split.column() + col.operator("font.textbox_add", icon='ZOOMIN') + if wide_ui: + col = split.column() + + for i, box in enumerate(text.textboxes): + + boxy = layout.box() + + split = boxy.split() + + col = split.column() + + col2 = col.column(align=True) + col2.label(text="Dimensions:") + col2.prop(box, "width", text="Width") + col2.prop(box, "height", text="Height") if wide_ui: - col = split.column(align=True) - col.label(text="Offset:") - col.prop(box, "x", text="X") - col.prop(box, "y", text="Y") - + col = split.column() + + row = col.row() + row.label(text="Offset:") + row.operator("font.textbox_remove", text='', icon='X').index = i + + col2 = col.column(align=True) + col2.prop(box, "x", text="X") + col2.prop(box, "y", text="Y") classes = [ DATA_PT_context_curve, diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h index dc07822bde2..10c1bd84262 100644 --- a/source/blender/editors/curve/curve_intern.h +++ b/source/blender/editors/curve/curve_intern.h @@ -66,6 +66,9 @@ void FONT_OT_change_spacing(struct wmOperatorType *ot); void FONT_OT_open(struct wmOperatorType *ot); void FONT_OT_unlink(struct wmOperatorType *ot); +void FONT_OT_textbox_add(struct wmOperatorType *ot); +void FONT_OT_textbox_remove(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 7586023d012..026a10c013c 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -81,6 +81,9 @@ void ED_operatortypes_curve(void) WM_operatortype_append(FONT_OT_open); WM_operatortype_append(FONT_OT_unlink); + + WM_operatortype_append(FONT_OT_textbox_add); + WM_operatortype_append(FONT_OT_textbox_remove); 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 46970a401a8..3a5f185c550 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1363,6 +1363,99 @@ void FONT_OT_text_insert(wmOperatorType *ot) RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position."); } + +/*********************** textbox add operator *************************/ +static int textbox_poll(bContext *C) +{ + Object *ob = CTX_data_active_object(C); + + if (!ED_operator_object_active_editable(C) ) return 0; + if (ob->type != OB_FONT) return 0; + + return 1; +} + +static int textbox_add_exec(bContext *C, wmOperator *op) +{ + Object *obedit= CTX_data_active_object(C); + Curve *cu= obedit->data; + int i; + + if (cu->totbox < 256) { + for (i = cu->totbox; i>cu->actbox; i--) cu->tb[i]= cu->tb[i-1]; + cu->tb[cu->actbox]= cu->tb[cu->actbox-1]; + cu->actbox++; + cu->totbox++; + } + + WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + return OPERATOR_FINISHED; +} + +void FONT_OT_textbox_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Textbox"; + ot->description= "Add a new text box"; + ot->idname= "FONT_OT_textbox_add"; + + /* api callbacks */ + ot->exec= textbox_add_exec; + ot->poll= textbox_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + +} + + + +/*********************** textbox remove operator *************************/ + + + +static int textbox_remove_exec(bContext *C, wmOperator *op) +{ + Object *obedit= CTX_data_active_object(C); + Curve *cu= obedit->data; + int i; + int index = RNA_int_get(op->ptr, "index"); + + + if (cu->totbox > 1) { + for (i = index; i < cu->totbox; i++) cu->tb[i]= cu->tb[i+1]; + cu->totbox--; + if (cu->actbox >= index) + cu->actbox--; + } + + WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + + return OPERATOR_FINISHED; +} + +void FONT_OT_textbox_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Textbox"; + ot->description= "Remove the textbox"; + ot->idname= "FONT_OT_textbox_remove"; + + /* api callbacks */ + ot->exec= textbox_remove_exec; + ot->poll= textbox_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "The current text box.", 0, INT_MAX); + + +} + + + /***************** editmode enter/exit ********************/ void make_editText(Object *obedit)