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:
Diffstat (limited to 'source/blender/editors/curve/editfont.c')
-rw-r--r--source/blender/editors/curve/editfont.c83
1 files changed, 39 insertions, 44 deletions
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index 611dbb2e80c..03c485a7671 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -26,12 +26,15 @@
#include "BKE_context.h"
#include "BKE_curve.h"
+#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_vfont.h"
+#include "BLT_translation.h"
+
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
@@ -59,7 +62,7 @@ static int kill_selection(Object *obedit, int ins);
/** \name Internal Utilities
* \{ */
-static char32_t findaccent(char32_t char1, uint code)
+static char32_t findaccent(char32_t char1, const char code)
{
char32_t new = 0;
@@ -619,18 +622,19 @@ static void txt_add_object(bContext *C,
ViewLayer *view_layer = CTX_data_view_layer(C);
Curve *cu;
Object *obedit;
- Base *base;
+ Object *object;
const struct TextLine *tmp;
int nchars = 0, nbytes = 0;
char *s;
int a;
const float rot[3] = {0.0f, 0.0f, 0.0f};
- obedit = BKE_object_add(bmain, view_layer, OB_FONT, NULL);
- base = view_layer->basact;
+ obedit = BKE_object_add(bmain, scene, view_layer, OB_FONT, NULL);
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ object = BKE_view_layer_active_object_get(view_layer);
/* seems to assume view align ? TODO: look into this, could be an operator option. */
- ED_object_base_init_transform_on_add(base->object, NULL, rot);
+ ED_object_base_init_transform_on_add(object, NULL, rot);
BKE_object_where_is_calc(depsgraph, scene, obedit);
@@ -1638,12 +1642,11 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Object *obedit = CTX_data_edit_object(C);
Curve *cu = obedit->data;
EditFont *ef = cu->editfont;
- static int accentcode = 0;
- uintptr_t ascii = event->ascii;
+ static bool accentcode = false;
const bool alt = event->modifier & KM_ALT;
const bool shift = event->modifier & KM_SHIFT;
const bool ctrl = event->modifier & KM_CTRL;
- int event_type = event->type, event_val = event->val;
+ char32_t insert_char_override = 0;
char32_t inserted_text[2] = {0};
if (RNA_struct_property_is_set(op->ptr, "text")) {
@@ -1652,48 +1655,47 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (RNA_struct_property_is_set(op->ptr, "accent")) {
if (ef->len != 0 && ef->pos > 0) {
- accentcode = 1;
+ accentcode = true;
}
return OPERATOR_FINISHED;
}
- /* tab should exit editmode, but we allow it to be typed using modifier keys */
- if (event_type == EVT_TABKEY) {
- if ((alt || ctrl || shift) == 0) {
- return OPERATOR_PASS_THROUGH;
- }
-
- ascii = 9;
- }
-
- if (event_type == EVT_BACKSPACEKEY) {
+ if (event->type == EVT_BACKSPACEKEY) {
if (alt && ef->len != 0 && ef->pos > 0) {
- accentcode = 1;
+ accentcode = true;
}
return OPERATOR_PASS_THROUGH;
}
- if (event_val && (ascii || event->utf8_buf[0])) {
- /* handle case like TAB (== 9) */
- if ((ascii > 31 && ascii < 254 && ascii != 127) || (ELEM(ascii, 13, 10)) || (ascii == 8) ||
- (event->utf8_buf[0])) {
+ /* Tab typically exit edit-mode, but we allow it to be typed using modifier keys. */
+ if (event->type == EVT_TABKEY) {
+ if ((alt || ctrl || shift) == 0) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ insert_char_override = '\t';
+ }
+ if (insert_char_override || event->utf8_buf[0]) {
+ if (insert_char_override) {
+ /* Handle case like TAB ('\t'). */
+ inserted_text[0] = insert_char_override;
+ insert_into_textbuf(obedit, insert_char_override);
+ text_update_edited(C, obedit, FO_EDIT);
+ }
+ else {
+ BLI_assert(event->utf8_buf[0]);
if (accentcode) {
if (ef->pos > 0) {
- inserted_text[0] = findaccent(ef->textbuf[ef->pos - 1], ascii);
+ inserted_text[0] = findaccent(ef->textbuf[ef->pos - 1],
+ BLI_str_utf8_as_unicode(event->utf8_buf));
ef->textbuf[ef->pos - 1] = inserted_text[0];
}
- accentcode = 0;
+ accentcode = false;
}
else if (event->utf8_buf[0]) {
inserted_text[0] = BLI_str_utf8_as_unicode(event->utf8_buf);
- ascii = inserted_text[0];
- insert_into_textbuf(obedit, ascii);
- accentcode = 0;
- }
- else if (ascii) {
- insert_into_textbuf(obedit, ascii);
- accentcode = 0;
+ insert_into_textbuf(obedit, inserted_text[0]);
+ accentcode = false;
}
else {
BLI_assert(0);
@@ -1702,11 +1704,6 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
kill_selection(obedit, 1);
text_update_edited(C, obedit, FO_EDIT);
}
- else {
- inserted_text[0] = ascii;
- insert_into_textbuf(obedit, ascii);
- text_update_edited(C, obedit, FO_EDIT);
- }
}
else {
return OPERATOR_PASS_THROUGH;
@@ -1720,11 +1717,6 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
RNA_string_set(op->ptr, "text", inserted_utf8);
}
- /* reset property? */
- if (event_val == 0) {
- accentcode = 0;
- }
-
return OPERATOR_FINISHED;
}
@@ -1974,6 +1966,8 @@ static int set_case_exec(bContext *C, wmOperator *op)
void FONT_OT_case_set(wmOperatorType *ot)
{
+ PropertyRNA *prop;
+
/* identifiers */
ot->name = "Set Case";
ot->description = "Set font case";
@@ -1987,7 +1981,8 @@ void FONT_OT_case_set(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
- RNA_def_enum(ot->srna, "case", case_items, CASE_LOWER, "Case", "Lower or upper case");
+ prop = RNA_def_enum(ot->srna, "case", case_items, CASE_LOWER, "Case", "Lower or upper case");
+ RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_TEXT);
}
/** \} */