[prev in list] [next in list] [prev in thread] [next in thread] 

List:       enlightenment-svn
Subject:    E CVS: libs/estyle rbdpngn
From:       enlightenment-cvs () lists ! sourceforge ! net
Date:       2002-01-29 21:27:16
[Download RAW message or body]

Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/estyle

Dir     : e17/libs/estyle/src


Modified Files:
	Estyle.h Estyle_private.h estyle.c estyle_color.c 
	estyle_font.c estyle_style.c 
Removed Files:
	estyle_font.h 


Log Message:
Made some minor updates to the docs to give credit where it is due, and filled
out the api a bit more.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/Estyle.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- Estyle.h	2002/01/26 07:37:24	1.1.1.1
+++ Estyle.h	2002/01/29 21:26:45	1.2
@@ -18,29 +18,60 @@
 };
 
 /*
- * The bit holds all information necessary for display and layout of the text
+ * The estyle holds all information necessary for display and layout of the text
  */
 typedef struct _estyle Estyle;
 
+/*
+ * Constructor/destructor
+ */
 Estyle *estyle_new(Evas evas, char *text, char *style);
 void estyle_free(Estyle * es);
-void estyle_set_text(Estyle * es, char *text);
+
+/*
+ * Visibility modifiers
+ */
 void estyle_show(Estyle * es);
 void estyle_hide(Estyle * es);
-void estyle_set_layer(Estyle * es, int layer);
+
+/*
+ * Content and appearance manipulators
+ */
+char *estyle_get_text(Estyle * es);
 void estyle_set_text(Estyle * es, char *text);
-void estyle_merge(Estyle * es1, Estyle * es2);
+int estyle_get_layer(Estyle * es);
+void estyle_set_layer(Estyle * es, int layer);
+char *estyle_get_style(Estyle * es);
 void estyle_set_style(Estyle * es, char *name);
 void estyle_set_color(Estyle * es, int r, int g, int b, int a);
 void estyle_set_color_db(Estyle * es, char *name);
+int estyle_get_color_red(Estyle * es);
+int estyle_get_color_green(Estyle * es);
+int estyle_get_color_blue(Estyle * es);
+int estyle_get_color_alpha(Estyle * es);
+
+/*
+ * Geometry querying
+ */
 void estyle_geometry(Estyle *es, int *x, int *y, int *w, int *h);
 void estyle_text_at(Estyle *es, int index, int *char_x, int *char_y,
 		int *char_w, int *char_h);
 int estyle_text_at_position(Estyle *es, int x, int y, int *char_x, int *char_y,
 		int *char_w, int *char_h);
+
+/*
+ * Fixing the reported geometry to set values.
+ */
+inline int estyle_fixed(Estyle *es);
+void estyle_fix_geometry(Estyle *es, int x, int y, int w, int h);
+void estyle_unfix_geometry(Estyle *es);
+
+/*
+ * Joining and splitting estyles.
+ */
+Estyle *estyle_split(Estyle * es, int index);
+void estyle_merge(Estyle * es1, Estyle * es2);
 
-#define BIT_MERGEABLE(es1, es2) (es1 && es2 && \
-		!(es1->flags & ESTYLE_BIT_FIXED) && \
-		!(es2->flags & ESTYLE_BIT_FIXED) && es1 != es2)
+#define ESTYLE_HASH_COLOR(r, g, b, a) ((r << 24) | (g << 16) | (b << 8) | a)
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/Estyle_private.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- Estyle_private.h	2002/01/26 07:37:24	1.1.1.1
+++ Estyle_private.h	2002/01/29 21:26:45	1.2
@@ -32,7 +32,6 @@
 	Ewd_List *bits;
 };
 
-#include "estyle_font.h"
 #include "estyle_style.h"
 #include "estyle_color.h"
 
@@ -51,9 +50,14 @@
 	/*
 	 * The bits can also have different fonts
 	 */
-	Estyle_Font *font;
+	char *font;
 
 	/*
+	 * Or different font sizes
+	 */
+	int font_size;
+
+	/*
 	 * Keep track of the geometry of the text to aid in layout. In the
 	 * case of a tab character, the width of the bit does not match the
 	 * width of the actual character printed.
@@ -82,5 +86,15 @@
 	 */
 	int length;
 };
+
+char *estyle_font_instance(char *name);
+
+/*
+ * This rounds the double to the nearest integer and returns it as an int
+ */
+#define D2I_ROUND(d) (int)(d + 0.5)
+#define BIT_MERGEABLE(es1, es2) (es1 && es2 && \
+		!(es1->flags & ESTYLE_BIT_FIXED) && \
+		!(es2->flags & ESTYLE_BIT_FIXED) && es1 != es2)
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/estyle.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- estyle.c	2002/01/26 07:37:25	1.1.1.1
+++ estyle.c	2002/01/29 21:26:45	1.2
@@ -42,7 +42,7 @@
 	 */
 	es->color = estyle_color_instance(255, 255, 255, 255);
 	es->font = estyle_font_instance("nationff");
-	es->font->size = 14;
+	es->font_size = 14;
 
 	if (style)
 		es->style = estyle_style_instance(style);
@@ -206,6 +206,26 @@
 }
 
 /**
+ * estyle_get_text - retrieve the text in the specified estyle
+ * @es: the estyle to retrieve text
+ *
+ * Returns a pointer to a copy of the text in the estyle @es on success, NULL
+ * on failure.
+ */
+char *estyle_get_text(Estyle *es)
+{
+	char *ret;
+
+	CHECK_PARAM_POINTER_RETURN("es", es, NULL);
+
+	ret = evas_get_text_string(es->evas, es->bit);
+	if (ret)
+		ret = strdup(ret);
+
+	return ret;
+}
+
+/**
  * estyle_set_text - change the text on a specified estyle
  * @es: the estyle to change text
  * @text: the new text for the estyle
@@ -225,24 +245,27 @@
 	 */
 	if (es->bit)
 		evas_set_text(es->evas, es->bit, text);
-
 	else {
-		es->bit = evas_add_text(es->evas, es->font->name,
-					 es->font->size, text);
+		es->bit = evas_add_text(es->evas, es->font,
+					 es->font_size, text);
 	}
 
 	es->length = strlen(text);
-	evas_get_geometry(es->evas, es->bit, &x, &y, &w, &h);
 
 	/*
-	 * This essentially performs a round operation, since
-	 * casting a double's value to an int discards the decimal
-	 * portion of the number. Adding 0.5 to the value will round
-	 * it up if it is appropriate.
+	 * If the estyle doesn't have fixed dimensions then set it to the
+	 * geometry of it's contents.
 	 */
-	es->w = (int) (w + 0.5);
-	es->h = (int) (h + 0.5);
+	if (!(es->flags & ESTYLE_BIT_FIXED)) {
+		evas_get_geometry(es->evas, es->bit, &x, &y, &w, &h);
+
+		es->w = D2I_ROUND(w);
+		es->h = D2I_ROUND(h);
+	}
 
+	/*
+	 * Setup the color of the evas object and move it into position.
+	 */
 	evas_set_color(es->evas, es->bit, es->color->r, es->color->g,
 			es->color->b, es->color->a);
 	evas_move(es->evas, es->bit, (double)(es->x), (double)(es->y));
@@ -257,6 +280,19 @@
 }
 
 /**
+ * estyle_get_layer - retrieve the layer of the estyle
+ * @es: the estyle to retrieve the current layer
+ *
+ * Returns the current layer of the estyle @es.
+ */
+int estyle_get_layer(Estyle *es)
+{
+	CHECK_PARAM_POINTER_RETURN("es", es, 0);
+
+	return evas_get_layer(es->evas, es->bit);
+}
+
+/**
  * estyle_set_layer - change the layer of a estyle and it's style
  * @es: the estyle to change layer
  * @layer: the new layer for the estyle
@@ -284,16 +320,39 @@
 }
 
 /**
+ * estyle_get_font - retrieve a copy of the current font for an estyle
+ * @es: the estyle to retrieve the current font
+ *
+ * Returns a pointer to a copy of the current font of the estyle @es.
+ */
+char *estyle_get_font(Estyle *es)
+{
+	char *ret = NULL;
+
+	CHECK_PARAM_POINTER_RETURN("es", es, NULL);
+
+	if (es->font)
+		ret = strdup(es->font);
+
+	return ret;
+}
+
+/**
  * estyle_set_font - change the font used for the specified estyle
  * @es: the estyle to change fonts
  * @font: the name of the font to use for the estyle
  *
  * Returns no value. Changes the font for the specified estyle to @name.
  */
-void estyle_set_font(Estyle * es, char *name)
+void estyle_set_font(Estyle * es, char *name, int size)
 {
 	CHECK_PARAM_POINTER("es", es);
 	CHECK_PARAM_POINTER("name", name);
+
+	es->font = estyle_font_instance(name);
+	es->font_size = size;
+
+	evas_set_font(es->evas, es->bit, es->font, es->font_size);
 }
 
 /**
@@ -426,17 +485,12 @@
 {
 	double xx, yy, ww, hh;
 
-	*char_x = 0;
-	*char_y = 0;
-	*char_w = 0;
-	*char_h = 0;
-
 	evas_text_at(es->evas, es->bit, index, &xx, &yy, &ww, &hh);
 
-	*char_x = (int)(xx + 0.5) + es->x;
-	*char_y = (int)(yy + 0.5) + es->y;
-	*char_w = (int)(ww + 0.5);
-	*char_h = (int)(hh + 0.5);
+	*char_x = D2I_ROUND(xx) + es->x;
+	*char_y = D2I_ROUND(yy) + es->y;
+	*char_w = D2I_ROUND(ww);
+	*char_h = D2I_ROUND(hh);
 }
 
 /**
@@ -457,20 +511,70 @@
 		int *char_w, int *char_h)
 {
 	int ret;
-	double xx, yy, ww, hh;
-
-	*char_x = 0;
-	*char_y = 0;
-	*char_w = 0;
-	*char_h = 0;
+	double xx = 0, yy = 0, ww = 0, hh = 0;
 
 	ret = evas_text_at_position(es->evas, es->bit, (double)(x - es->x),
 			(double)(y - es->y), &xx, &yy, &ww, &hh);
 
-	*char_x = (int)(xx + 0.5) + es->x;
-	*char_y = (int)(yy + 0.5) + es->y;
-	*char_w = (int)(ww + 0.5);
-	*char_h = (int)(hh + 0.5);
+	*char_x = D2I_ROUND(xx) + es->x;
+	*char_y = D2I_ROUND(yy) + es->y;
+	*char_w = D2I_ROUND(ww);
+	*char_h = D2I_ROUND(hh);
 
 	return ret;
+}
+
+/**
+ * estyle_fixed - determine if the specified estyle has fixed geometry
+ * @es: the estyle to check for fixed geometry
+ *
+ * Returns 0 if the estyle does not have fixed geometry, > 0 otherwise.
+ */
+inline int estyle_fixed(Estyle *es)
+{
+	CHECK_PARAM_POINTER_RETURN("es", es, 0);
+
+	return es->flags & ESTYLE_BIT_FIXED;
+}
+
+/**
+ * estyle_fix_geometry - report a fixed geometry to querying functions
+ * @es: the estyle to fix the geometry
+ * @x: the x coordinate to report
+ * @y: the y coordinate to report
+ * @w: the width to report
+ * @h: the height to report
+ *
+ * Returns no value. Fixes the reported geometry of @es to @x, @y, @w, and @h
+ * respectively.
+ */
+void estyle_fix_geometry(Estyle *es, int x, int y, int w, int h)
+{
+	CHECK_PARAM_POINTER("es", es);
+
+	es->flags |= ESTYLE_BIT_FIXED;
+	es->x = x;
+	es->y = y;
+	es->w = w;
+	es->h = h;
+}
+
+/**
+ * estyle_unfix_geometry - remove the fixed property of the estyle
+ * @es: the estyle to remove the fixed property
+ *
+ * Returns no value. Removes the fixed property of the estyle and updates its
+ * geometry to the actual geometry of the contents.
+ */
+void estyle_unfix_geometry(Estyle *es)
+{
+	double x, y, w, h;
+
+	CHECK_PARAM_POINTER("es", es);
+
+	evas_get_geometry(es->evas, es->bit, &x, &y, &w, &h);
+	es->x = D2I_ROUND(x);
+	es->y = D2I_ROUND(y);
+	es->w = D2I_ROUND(w);
+	es->h = D2I_ROUND(h);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/estyle_color.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- estyle_color.c	2002/01/26 15:09:05	1.2
+++ estyle_color.c	2002/01/29 21:26:45	1.3
@@ -1,8 +1,6 @@
 #include "../estyle-config.h"
 #include "Estyle_private.h"
 
-#define HASH_COLOR(r, g, b, a) ((r << 24) | (g << 16) | (b << 8) | a)
-
 static Ewd_Hash *color_table = NULL;
 static E_DB_File *sys_colors = NULL;
 static E_DB_File *user_colors = NULL;
@@ -27,7 +25,7 @@
 	/*
 	 * Check the hash table for a previous malloc of the color
 	 */
-	value = HASH_COLOR(r, g, b, a);
+	value = ESTYLE_HASH_COLOR(r, g, b, a);
 	ret = (Estyle_Color *) ewd_hash_get(color_table, (void *) value);
 	if (!ret) {
 		ret = (Estyle_Color *) malloc(sizeof(Estyle_Color));
@@ -89,7 +87,7 @@
 	if (!a)
 		e_db_int_get(sys_colors, key, &a);
 
-	value = HASH_COLOR(r, g, b, a);
+	value = ESTYLE_HASH_COLOR(r, g, b, a);
 
 	/*
 	 * Check for a previous allocation for this color.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/estyle_font.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- estyle_font.c	2002/01/26 07:37:26	1.1.1.1
+++ estyle_font.c	2002/01/29 21:26:45	1.2
@@ -8,9 +8,9 @@
  *
  * Returns a pointer to a the font on success, NULL on failure.
  */
-Estyle_Font *estyle_font_instance(char *name)
+char *estyle_font_instance(char *name)
 {
-	Estyle_Font *fn;
+	char *fn;
 
 	CHECK_PARAM_POINTER_RETURN("name", name, NULL);
 
@@ -23,8 +23,7 @@
 
 	fn = ewd_hash_get(fonts, name);
 	if (!fn) {
-		fn = (Estyle_Font *)malloc(sizeof(Estyle_Font));
-		fn->name = strdup(name);
+		fn = strdup(name);
 
 		ewd_hash_set(fonts, name, fn);
 	}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/estyle/src/estyle_style.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- estyle_style.c	2002/01/26 07:37:26	1.1.1.1
+++ estyle_style.c	2002/01/29 21:26:45	1.2
@@ -512,8 +512,8 @@
 	/*
 	 * Create the text at the correct size and move it into position
 	 */
-	ret = evas_add_text(es->evas, es->font->name,
-			es->font->size + layer->size_change, text);
+	ret = evas_add_text(es->evas, es->font,
+			es->font_size + layer->size_change, text);
 
 	evas_move(es->evas, ret, (double)(es->x + layer->x_offset),
 			(double)(es->y + layer->y_offset));



_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic