aboutsummaryrefslogtreecommitdiff
path: root/generic/Text.c
diff options
context:
space:
mode:
authorlecoanet2002-05-16 09:40:36 +0000
committerlecoanet2002-05-16 09:40:36 +0000
commitf8c4a63cf27597af47f88363b45abfc0f869e660 (patch)
treeb1e13b5cf3c08f6f391501a2c7306d638060c6e8 /generic/Text.c
parentfc5443fb490fcb2c4eafc084db91000a08068c71 (diff)
downloadtkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.zip
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.gz
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.bz2
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.xz
Adaptation suite au remaniement du code des images.
Ajout de l'attribut -composealpha. Mise en correspondance des types d'attributs avec la doc. Adaptation des prototypes de ToArea et Pick pour accomoder les nouvelles fonctionalit�s des commandes de find/addtag. Suppression de la variable de classe has_fields
Diffstat (limited to 'generic/Text.c')
-rw-r--r--generic/Text.c105
1 files changed, 57 insertions, 48 deletions
diff --git a/generic/Text.c b/generic/Text.c
index 64e0c21..e5aaa97 100644
--- a/generic/Text.c
+++ b/generic/Text.c
@@ -84,7 +84,7 @@ typedef struct _TextItemStruct {
ZnAnchor connection_anchor;
ZnGradient *color;
char *text;
- Pixmap fill_pattern;
+ ZnImage fill_pattern;
ZnFont font;
ZnJustify alignment;
ZnDim width;
@@ -98,19 +98,22 @@ typedef struct _TextItemStruct {
ZnList text_info;
int max_width;
#ifdef GLX
- TexFont *txf;
+ ZnTexFontInfo *tfi;
#endif
} TextItemStruct, *TextItem;
static ZnAttrConfig text_attrs[] = {
- { ZN_CONFIG_JUSTIFY, "-alignment", NULL,
+ { ZN_CONFIG_ALIGNMENT, "-alignment", NULL,
Tk_Offset(TextItemStruct, alignment), 0,
ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False },
{ ZN_CONFIG_ANCHOR, "-anchor", NULL,
Tk_Offset(TextItemStruct, anchor), 0, ZN_COORDS_FLAG, False },
{ ZN_CONFIG_GRADIENT, "-color", NULL,
Tk_Offset(TextItemStruct, color), 0, ZN_DRAW_FLAG, False },
+ { ZN_CONFIG_BOOL, "-composealpha", NULL,
+ Tk_Offset(TextItemStruct, header.flags), COMPOSE_ALPHA_BIT,
+ ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-composerotation", NULL,
Tk_Offset(TextItemStruct, header.flags), COMPOSE_ROTATION_BIT,
ZN_COORDS_FLAG, False },
@@ -122,7 +125,7 @@ static ZnAttrConfig text_attrs[] = {
ZN_COORDS_FLAG|ZN_ITEM_FLAG, False },
{ ZN_CONFIG_ANCHOR, "-connectionanchor", NULL,
Tk_Offset(TextItemStruct, connection_anchor), 0, ZN_COORDS_FLAG, False },
- { ZN_CONFIG_PATTERN, "-fillpattern", NULL,
+ { ZN_CONFIG_BITMAP, "-fillpattern", NULL,
Tk_Offset(TextItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_FONT, "-font", NULL,
Tk_Offset(TextItemStruct, font), 0,
@@ -140,9 +143,9 @@ static ZnAttrConfig text_attrs[] = {
{ ZN_CONFIG_DIM, "-spacing", NULL,
Tk_Offset(TextItemStruct, spacing), 0,
ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False },
- { ZN_CONFIG_TAGS, "-tags", NULL,
+ { ZN_CONFIG_TAG_LIST, "-tags", NULL,
Tk_Offset(TextItemStruct, header.tags), 0, 0, False },
- { ZN_CONFIG_TEXT, "-text", NULL,
+ { ZN_CONFIG_STRING, "-text", NULL,
Tk_Offset(TextItemStruct, text), 0,
ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False },
{ ZN_CONFIG_BOOL, "-underlined", NULL,
@@ -178,6 +181,7 @@ Init(Item item,
/* Init attributes */
SET(item->flags, VISIBLE_BIT);
SET(item->flags, SENSITIVE_BIT);
+ SET(item->flags, COMPOSE_ALPHA_BIT);
SET(item->flags, COMPOSE_ROTATION_BIT);
SET(item->flags, COMPOSE_SCALE_BIT);
item->priority = DEFAULT_TEXT_PRIORITY;
@@ -185,17 +189,20 @@ Init(Item item,
text->pos.x = text->pos.y = 0.0;
text->text = "";
text->num_chars = 0;
- text->fill_pattern = ZnUnspecifiedPattern;
+ text->fill_pattern = ZnUnspecifiedImage;
text->anchor = ZnAnchorNW;
text->connection_anchor = ZnAnchorSW;
text->color = ZnGetGradientByValue(wi->fore_color);
text->alignment = ZnJustifyLeft;
text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font));
- text->width = 0;
- text->spacing = 0;
#ifdef GLX
- text->txf = NULL;
+ text->tfi = NULL;
+ if (wi->render) {
+ text->tfi = ZnGetTexFont(wi, text->font);
+ }
#endif
+ text->width = 0;
+ text->spacing = 0;
text->insert_index = 0;
CLEAR(text->flags, UNDERLINED);
CLEAR(text->flags, OVERSTRIKED);
@@ -223,13 +230,17 @@ Clone(Item item)
strcpy(str, text->text);
text->text = str;
}
- if (text->fill_pattern != ZnUnspecifiedPattern) {
- text->fill_pattern = Tk_GetBitmap(wi->interp, wi->win,
- Tk_NameOfBitmap(wi->dpy, text->fill_pattern));
+ if (text->fill_pattern != ZnUnspecifiedImage) {
+ text->fill_pattern = ZnGetImageByValue(text->fill_pattern);
}
text->color = ZnGetGradientByValue(text->color);
text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(text->font));
-
+#ifdef GLX
+ if (wi->render) {
+ text->tfi = ZnGetTexFont(wi, text->font);
+ }
+#endif
+
/*
* We always need to invalidate, either because the model
* has not done its layout (text_info == NULL) or because
@@ -251,18 +262,22 @@ Clone(Item item)
static void
Destroy(Item item)
{
- WidgetInfo *wi = item->wi;
TextItem text = (TextItem) item;
if (strlen(text->text) != 0) {
ZnFree(text->text);
}
- if (text->fill_pattern != ZnUnspecifiedPattern) {
- Tk_FreeBitmap(wi->dpy, text->fill_pattern);
- text->fill_pattern = ZnUnspecifiedPattern;
+ if (text->fill_pattern != ZnUnspecifiedImage) {
+ ZnFreeImage(text->fill_pattern);
+ text->fill_pattern = ZnUnspecifiedImage;
}
ZnFreeGradient(text->color);
Tk_FreeFont(text->font);
+#ifdef GLX
+ if (text->tfi) {
+ ZnFreeTexFont(text->tfi);
+ }
+#endif
if (text->text_info) {
ZnListFree(text->text_info);
@@ -297,7 +312,15 @@ Configure(Item item,
#ifdef GLX
if (old_font != text->font) {
- text->txf = NULL;
+ if (text->tfi) {
+ ZnFreeTexFont(text->tfi);
+ }
+ if (item->wi->render) {
+ text->tfi = ZnGetTexFont(item->wi, text->font);
+ if (!text->tfi) {
+ return ZN_ERROR;
+ }
+ }
}
#endif
num_chars = strlen(text->text);
@@ -544,10 +567,7 @@ ComputeCoordinates(Item item,
*/
static int
ToArea(Item item,
- ZnBBox *area,
- Tk_Uid tag_uid,
- int enclosed,
- ZnBool report)
+ ZnToArea ta)
{
TextItem text = (TextItem) item;
int inside = -1;
@@ -556,7 +576,7 @@ ToArea(Item item,
TextLineInfo lines, lines_ptr;
Tk_FontMetrics fm;
int font_height;
- ZnBBox line_bbox;
+ ZnBBox line_bbox, *area = ta->area;
ZnPoint o;
if (!text->text_info) {
@@ -762,9 +782,9 @@ Draw(Item item)
values.font = ZnFontId(text->font);
values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0, NULL));
gc_mask = GCFont | GCForeground;
- if (text->fill_pattern != ZnUnspecifiedPattern) {
+ if (text->fill_pattern != ZnUnspecifiedImage) {
values.fill_style = FillStippled;
- values.stipple = text->fill_pattern;
+ values.stipple = ZnImagePixmap(text->fill_pattern, NULL);
gc_mask |= GCFillStyle | GCStipple;
}
else {
@@ -832,13 +852,7 @@ Render(Item item)
int sel_first_line=-1, sel_last_line=-1, cursor_line=-1;
int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0;
- if (!text->text_info) {
- return;
- }
- if (!text->txf) {
- text->txf = GetTexFont(wi->win, text->font);
- }
- if (!text->txf) {
+ if (!text->text_info || !text->tfi) {
return;
}
@@ -869,12 +883,12 @@ Render(Item item)
/*
* Render the selection.
*/
- color = ZnGetGradientColor(ti->sel_color, 0, &alpha);
- alpha = ZnComposeAlpha(alpha, wi->alpha);
- glColor4us(color->red, color->green, color->blue, alpha);
if ((ti->sel_item == item) && (sel_first_line >= 0)) {
ZnReal xo, yo, xc, yc;
+ color = ZnGetGradientColor(ti->sel_color, 0, &alpha);
+ alpha = ZnComposeAlpha(alpha, wi->alpha);
+ glColor4us(color->red, color->green, color->blue, alpha);
glBegin(GL_QUADS);
if (sel_first_line == sel_last_line) {
xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset;
@@ -921,13 +935,13 @@ Render(Item item)
/*
* Render the cursor.
*/
- color = ZnGetGradientColor(ti->insert_color, 0, &alpha);
- alpha = ZnComposeAlpha(alpha, wi->alpha);
- glColor4us(color->red, color->green, color->blue, alpha);
if ((cursor_line >= 0) &&
(wi->focus_item == item) && ti->cursor_on) {
int xs, ys;
+ color = ZnGetGradientColor(ti->insert_color, 0, &alpha);
+ alpha = ZnComposeAlpha(alpha, wi->alpha);
+ glColor4us(color->red, color->green, color->blue, alpha);
glLineWidth(ti->insert_width);
xs = text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset;
ys = text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1;
@@ -942,7 +956,7 @@ Render(Item item)
*/
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, text->txf->texobj);
+ glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(text->tfi));
color = ZnGetGradientColor(text->color, 0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
@@ -955,7 +969,7 @@ Render(Item item)
glPushMatrix();
glTranslatef(xs, ys, 0.0);
- txfRenderString(text->txf, lines_ptr->start, lines_ptr->num_chars);
+ ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_chars);
glPopMatrix();
if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) {
@@ -1007,11 +1021,7 @@ IsSensitive(Item item,
*/
static double
Pick(Item item,
- ZnPoint *p,
- Item start_item,
- int aperture,
- Item *a_item,
- int *part)
+ ZnPick ps)
{
TextItem text = (TextItem) item;
double dist = 1.0e40, new_dist;
@@ -1020,7 +1030,7 @@ Pick(Item item,
Tk_FontMetrics fm;
int font_height;
ZnBBox line_bbox;
- ZnPoint o;
+ ZnPoint o, *p = ps->point;
if (!text->text_info) {
return dist;
@@ -1566,7 +1576,6 @@ Selection(Item item,
*/
static ItemClassStruct TEXT_ITEM_CLASS = {
sizeof(TextItemStruct),
- False, /* has_fields */
0, /* num_parts */
True, /* has_anchors */
"text",