[Bf-blender-cvs] [422c3303902] soc-2022-text-usability: UI: Select regions of text and toggle its style 1. Text can be selected along the mouse pointer by dragging the cursor . 2. After the selection we can toggle the style of the selected region. 3. Word can be selected using double click.

Yash Dabhade noreply at git.blender.org
Thu Sep 1 14:02:49 CEST 2022


Commit: 422c3303902f6cf1390fb12f70cf1036de8f5e91
Author: Yash Dabhade
Date:   Thu Sep 1 17:31:37 2022 +0530
Branches: soc-2022-text-usability
https://developer.blender.org/rB422c3303902f6cf1390fb12f70cf1036de8f5e91

UI: Select regions of text and toggle its style
1. Text can be selected along the mouse pointer by dragging the cursor .
2. After the selection we can toggle the style of the selected region.
3. Word can be selected using double click.

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

M	release/scripts/startup/bl_ui/properties_data_curve.py
M	source/blender/blenkernel/BKE_vfont.h
M	source/blender/blenkernel/intern/vfont.c
M	source/blender/editors/curve/editfont.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_curve.py b/release/scripts/startup/bl_ui/properties_data_curve.py
index e986afd2f3d..bc8d07e8b13 100644
--- a/release/scripts/startup/bl_ui/properties_data_curve.py
+++ b/release/scripts/startup/bl_ui/properties_data_curve.py
@@ -364,10 +364,11 @@ class DATA_PT_font(CurveButtonsPanelText, Panel):
                 row.prop(char, "use_underline", toggle=True)
                 row.prop(char, "use_small_caps", toggle=True)
             else:
-                layout.operator("font.style_toggle", text="Bold", icon='BOLD' , depress = text.select_is_bold).style = 'BOLD'
-                layout.operator("font.style_toggle", text="Italic", icon='ITALIC' , depress = text.select_is_italics).style = 'ITALIC'
-                layout.operator("font.style_toggle", text="Underline", icon='UNDERLINE' , depress = text.select_is_underline).style = 'UNDERLINE'
-                layout.operator("font.style_toggle", text="Small Caps", icon='SMALL_CAPS' , depress = text.select_is_smallcaps).style = 'SMALL_CAPS'
+                row = layout.row(align=True)
+                row.operator("font.style_toggle", text="Bold", icon='BOLD' , depress = text.select_is_bold).style = 'BOLD'
+                row.operator("font.style_toggle", text="Italic", icon='ITALIC' , depress = text.select_is_italics).style = 'ITALIC'
+                row.operator("font.style_toggle", text="Underline", icon='UNDERLINE' , depress = text.select_is_underline).style = 'UNDERLINE'
+                row.operator("font.style_toggle", text="Small Caps", icon='SMALL_CAPS' , depress = text.select_is_smallcaps).style = 'SMALL_CAPS'
 
 
 class DATA_PT_font_transform(CurveButtonsPanelText, Panel):
diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h
index 4cb3a595140..1b2166411a6 100644
--- a/source/blender/blenkernel/BKE_vfont.h
+++ b/source/blender/blenkernel/BKE_vfont.h
@@ -82,6 +82,19 @@ bool BKE_vfont_to_curve_ex(struct Object *ob,
                            bool *r_text_free,
                            struct CharTrans **r_chartransdata);
 bool BKE_vfont_to_curve_nubase(struct Object *ob, int mode, struct ListBase *r_nubase);
+
+bool BKE_vfont_to_curve_ex2(struct Object *ob,
+                           struct Curve *cu,
+                           int mode,
+                           struct ListBase *r_nubase,
+                           const char32_t **r_text,
+                           int *r_text_len,
+                           bool *r_text_free,
+                           struct CharTrans **r_chartransdata,
+                           float cursor_location[2], int *r_cursor_locaiton_pos);
+
+bool BKE_vfont_to_curve_curloc(struct Object *ob, int mode,float cursor_location[2], int *r_cursor_locaiton_pos);                           
+
 /**
  * \warning Expects to have access to evaluated data (i.e. passed object should be evaluated one).
  */
diff --git a/source/blender/blenkernel/intern/vfont.c b/source/blender/blenkernel/intern/vfont.c
index b1fd3d3c0e8..ec80a53dca7 100644
--- a/source/blender/blenkernel/intern/vfont.c
+++ b/source/blender/blenkernel/intern/vfont.c
@@ -765,7 +765,7 @@ static float vfont_descent(const VFontData *vfd)
   return vfd->em_height - vfont_ascent(vfd);
 }
 
-static bool vfont_to_curve(Object *ob,
+static bool vfont_to_curve_ex(Object *ob,
                            Curve *cu,
                            int mode,
                            VFontToCurveIter *iter_data,
@@ -773,7 +773,8 @@ static bool vfont_to_curve(Object *ob,
                            const char32_t **r_text,
                            int *r_text_len,
                            bool *r_text_free,
-                           struct CharTrans **r_chartransdata)
+                           struct CharTrans **r_chartransdata,
+                           float cursor_location[2], int *r_cursor_locaiton_pos)
 {
   EditFont *ef = cu->editfont;
   EditFontSelBox *selboxes = NULL;
@@ -826,6 +827,14 @@ static bool vfont_to_curve(Object *ob,
     return ok;
   }
 
+  if(cursor_location==NULL)
+  {  
+    float cur_loc_temp[2];
+    cur_loc_temp[0]=0.0;
+    cur_loc_temp[1]=0.0;
+    cursor_location=cur_loc_temp;
+  } 
+
   vfd = vfont_get_data(vfont);
 
   /* The VFont Data can not be found */
@@ -908,8 +917,13 @@ static bool vfont_to_curve(Object *ob,
   }
 
   i = 0;
-  int ret=0;
-  float min_dist=0.0f;
+  int ret=-1;
+  float min_dist;
+  if(ef!=NULL && ob!=NULL)
+  { float ffx=cursor_location[0];
+    float ffy=cursor_location[1]; 
+    min_dist=ffx*ffx+ffy*ffy;
+  }
   while (i <= slen) {
     /* Characters in the list */
     info = &custrinfo[i];
@@ -1125,33 +1139,39 @@ static bool vfont_to_curve(Object *ob,
     }
     ct++;
     if (ef != NULL && ob != NULL){
-      float fx=ef->m_loc[0];
-      float fy=ef->m_loc[1];
+      float fx=cursor_location[0];
+      float fy=cursor_location[1];
       float di= (fx-xof)*(fx-xof)+(fy-yof)*(fy-yof);
-      if(i==0)
+      float di2=fx*fx+fy*fy;
+
+      if(di2<=min_dist && di2<di)
       {
-        min_dist=di;
-        ret=i;
+        min_dist=di2;
+        ret=-1;
       }
-      if(di<min_dist)
+      else if(di<min_dist)
       {
         min_dist=di;
         ret=i;
       } 
+
     }
     i++;
   }
   if (ef != NULL && ob != NULL)
   {
-    if(ret==0)
+
+    if(ret==-1)
     {
       ret++;
-      ef->m_pos=ret;
+      if(r_cursor_locaiton_pos)
+        *r_cursor_locaiton_pos=ret;
     }
-    else if(ret>0 && ret<=ef->len-1)
+    else if(ret>=0 && ret<=ef->len-1)
     {
       ret++;
-      ef->m_pos=ret;
+      if(r_cursor_locaiton_pos)
+        *r_cursor_locaiton_pos=ret;
     }
   }
   current_line_length += xof + twidth - MARGIN_X_MIN;
@@ -1754,6 +1774,20 @@ finally:
 #undef MARGIN_Y_MIN
 }
 
+
+static bool vfont_to_curve(Object *ob,
+                           Curve *cu,
+                           int mode,
+                           VFontToCurveIter *iter_data,
+                           ListBase *r_nubase,
+                           const char32_t **r_text,
+                           int *r_text_len,
+                           bool *r_text_free,
+                           struct CharTrans **r_chartransdata)
+{
+  return vfont_to_curve_ex(ob,cu,mode,iter_data,r_nubase,r_text,r_text_len,r_text_free,r_chartransdata,NULL,NULL);
+
+}
 #undef DESCENT
 #undef ASCENT
 
@@ -1775,8 +1809,34 @@ bool BKE_vfont_to_curve_ex(Object *ob,
   };
 
   do {
-    data.ok &= vfont_to_curve(
-        ob, cu, mode, &data, r_nubase, r_text, r_text_len, r_text_free, r_chartransdata);
+    data.ok &= vfont_to_curve_ex(
+        ob, cu, mode, &data, r_nubase, r_text, r_text_len, r_text_free, r_chartransdata,NULL,NULL);
+  } while (data.ok && ELEM(data.status, VFONT_TO_CURVE_SCALE_ONCE, VFONT_TO_CURVE_BISECT));
+
+  return data.ok;
+}
+
+bool BKE_vfont_to_curve_ex2(Object *ob,
+                           Curve *cu,
+                           int mode,
+                           ListBase *r_nubase,
+                           const char32_t **r_text,
+                           int *r_text_len,
+                           bool *r_text_free,
+                           struct CharTrans **r_chartransdata,
+                           float cursor_location[2], int *r_cursor_locaiton_pos)
+{
+  VFontToCurveIter data = {
+      .iteraction = cu->totbox * FONT_TO_CURVE_SCALE_ITERATIONS,
+      .scale_to_fit = 1.0f,
+      .word_wrap = true,
+      .ok = true,
+      .status = VFONT_TO_CURVE_INIT,
+  };
+
+  do {
+    data.ok &= vfont_to_curve_ex(
+        ob, cu, mode, &data, r_nubase, r_text, r_text_len, r_text_free, r_chartransdata,cursor_location,r_cursor_locaiton_pos);
   } while (data.ok && ELEM(data.status, VFONT_TO_CURVE_SCALE_ONCE, VFONT_TO_CURVE_BISECT));
 
   return data.ok;
@@ -1799,6 +1859,13 @@ bool BKE_vfont_to_curve(Object *ob, int mode)
   return BKE_vfont_to_curve_ex(ob, ob->data, mode, &cu->nurb, NULL, NULL, NULL, NULL);
 }
 
+bool BKE_vfont_to_curve_curloc(Object *ob, int mode,float cursor_location[2], int *r_cursor_locaiton_pos)
+{
+  Curve *cu = ob->data;
+
+  return BKE_vfont_to_curve_ex2(ob,ob->data,mode,&cu->nurb,NULL,NULL,NULL,NULL,cursor_location,r_cursor_locaiton_pos);
+}
+
 /* -------------------------------------------------------------------- */
 /** \name VFont Clipboard
  * \{ */
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index c45c6887279..5dbebf1fa0e 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -423,6 +423,29 @@ static void text_update_edited(bContext *C, Object *obedit, int mode)
   WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
 }
 
+static void text_update_edited_ex(bContext *C, Object *obedit, int mode,float cursor_location[2], int *r_cursor_locaiton_pos)
+{
+  Curve *cu = obedit->data;
+  EditFont *ef = cu->editfont;
+
+  BLI_assert(ef->len >= 0);
+    Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+    BKE_vfont_to_curve_curloc(DEG_get_evaluated_object(depsgraph, obedit), mode,cursor_location,r_cursor_locaiton_pos);
+
+  cu->curinfo = ef->textbufinfo[ef->pos ? ef->pos - 1 : 0];
+
+  if (obedit->totcol > 0) {
+    obedit->actcol = cu->curinfo.mat_nr;
+    if (obedit->actcol < 1) {
+      obedit->actcol = 1;
+    }
+  }
+
+  DEG_id_tag_update(obedit->data, ID_RECALC_SELECT);
+  WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+}
+
+
 static int kill_selection(Object *obedit, int ins) /* ins == new character len */
 {
   Curve *cu = obedit->data;
@@ -1759,33 +1782,39 @@ void FONT_OT_text_insert(wmOperatorType *ot)
 /* -------------------------------------------------------------------- */
 /** \name Font Select Operator
  * \{ */
-static void font_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
+static void font_cursor_set_apply(bContext *C, const wmEvent *event)
 {
   Object *obedit = CTX_data_active_object(C);
   Curve *cu = obedit->data;
   EditFont *ef = cu->editfont;
   ARegion *region = CTX_wm_region(C);
+  int cur_loc_pos;
   float rout[3];
   float mal[2];
   mal[0]=event->mval[0];
   mal[1]=event->mval[1];
   const float *co = obedit->obmat[3];
-  const float *no 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list