Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : libs/etox

Dir     : e17/libs/etox/src


Modified Files:
        etox.c etox_line.c etox_line.h 


Log Message:


abstract the lines a bit more

added:
  etox_line_set_layer()
  etox_line_index_to_geometry()
  etox_line_apply_context()

use these functions in etox.c instead of directly going through the line's bits.


===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -3 -r1.57 -r1.58
--- etox.c      19 Aug 2003 04:00:22 -0000      1.57
+++ etox.c      19 Aug 2003 05:49:26 -0000      1.58
@@ -551,17 +551,7 @@
         */
        for (l = et->lines; l; l = l->next) {
                line = l->data;
-
-               if (line->bits) {
-
-                       /*
-                        * Set the layer for each bit in the line
-                        */
-                       for (ll = line->bits; ll; ll = ll->next) {
-                               bit = ll->data;
-                               evas_object_layer_set(bit, layer);
-                       }
-               }
+                etox_line_set_layer(line, et->layer);
        }
 }
 
@@ -710,9 +700,8 @@
 {
        Etox *et;
        int sum;
-       Evas_Object *bit = NULL;
        Etox_Line *line = NULL;
-       Evas_List *l, *ll, *lll;
+       Evas_List *l;
 
        CHECK_PARAM_POINTER("obj", obj);
 
@@ -720,51 +709,14 @@
 
        if (index > et->length) {
                sum = et->length;
-               for (lll = et->lines; lll; lll = lll->next)
-                       line = lll->data;
+                line = evas_list_last(et->lines);
 
-               *h = line->h;
-               *w = line->w / line->length;
-               *y = line->y;
-               *x = line->x + line->w;
+               if (h) *h = line->h;
+               if (w) *w = line->w / line->length;
+               if (y) *y = line->y;
+               if (x) *x = line->x + line->w;
        } else {
-               /*
-                * Find the line that contains the character
-                */
-               sum = 0;
-               for (l = et->lines; l; l = l->next) {
-                       line = l->data;
-                       if (sum + line->length < index)
-                               break;
-                       sum += line->length;
-               }
-
-               /*
-                * Find the bit that contains the character
-                */
-               for (ll = line->bits; ll; ll = ll->next) {
-                       bit = ll->data;
-                       if (sum + estyle_length(bit) < index)
-                               break;
-                       sum += estyle_length(bit);
-               }
-
-               /*
-                * No bit intersects, so set the geometry to the start of the
-                * line, with the average character width on the line.
-                */
-               if (!bit) {
-                       *h = line->h;
-                       *w = line->w / line->length;
-                       *y = line->y;
-                       *x = line->x + line->w;
-                       return;
-               }
-
-               /*
-                * Now get the actual geometry from the bit
-                */
-               estyle_text_at(bit, index - sum, x, y, w, h);
+          etox_line_index_to_geometry(line, index - sum, x, y, w, h);
        }
 }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -3 -r1.23 -r1.24
--- etox_line.c 19 Aug 2003 04:00:23 -0000      1.23
+++ etox_line.c 19 Aug 2003 05:49:26 -0000      1.24
@@ -584,3 +584,87 @@
                i++;
        }
 }
+
+void
+etox_line_set_layer(Etox_Line *line, int layer)
+{
+  Evas_List *l;
+
+  if (!line->bits) return;
+  
+  for (l = line->bits; l; l = l->next)
+  {
+    Evas_Object *bit;
+
+    bit = l->data;
+    evas_object_layer_set(bit, layer);
+  }
+}
+
+void
+etox_line_index_to_geometry(Etox_Line *line, int index, double *x, double *y,
+                            double *w, double *h)
+{
+  Evas_Object *bit = NULL;
+  Evas_List *l;
+  int sum = 0;
+
+  /* find the bit containing the character */
+  for (l = line->bits; l; l = l->next)
+  {
+    int length;
+    
+    bit = l->data;
+    length = estyle_length(bit);
+
+    if ( sum + length < index)
+      break;
+
+    sum += length;
+
+    if (!l->next)
+      bit = NULL;
+  }
+
+  /* No bit intersects, so set the geometry to the end of the
+   * line, with the average character width on the line
+   */
+  if (!bit)
+  {
+    if (h) *h = line->h;
+    if (w) *w = line->w / line->length;
+    if (y) *y = line->y;
+    if (x) *x = line->x + line->w;
+    return;
+  }
+
+  /* get the geometry from the bit */
+  estyle_text_at(bit, index - sum, x, y, w, h); 
+}
+
+void
+etox_line_apply_context(Etox_Line *line, Etox_Context *context, Evas_Object *start, 
Evas_Object *end)
+{
+  Evas_List *l, *ls = NULL, *le = NULL;
+
+  ls = evas_list_find(line->bits, start);
+  le = evas_list_find(line->bits, end);
+  
+  /* make sure start and end exist and are in line->bits */
+  if ( !ls )
+    ls = line->bits;
+  if ( !le ) 
+    le = evas_list_last(line->bits); 
+
+  for (l = ls; l && l != le; l = l->next)
+  {
+    Evas_Object *bit;
+
+    bit = l->data;
+
+    estyle_set_style(bit, context->style);
+    evas_object_color_set(bit, context->r, context->g, context->b,
+                          context->a);
+    estyle_set_font(bit, context->font, context->font_size);
+  }
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- etox_line.h 5 Aug 2003 18:45:36 -0000       1.10
+++ etox_line.h 19 Aug 2003 05:49:26 -0000      1.11
@@ -21,4 +21,9 @@
 Evas_Object *etox_line_index_to_bit(Etox_Line *line, int *i);
 void etox_line_print_bits(Etox_Line *line);
 
+void etox_line_set_layer(Etox_Line *line, int layer);
+void etox_line_index_to_geom(Etox_Line *line, double *x, double *y, 
+                             double *w, double *h);
+void etox_line_apply_context(Etox_Line *line, Etox_Context *context, Evas_Object 
*start, Evas_Object *end);
+
 #endif




-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to