aboutsummaryrefslogtreecommitdiff
path: root/generic/Text.c
diff options
context:
space:
mode:
authorlecoanet2002-12-09 14:47:45 +0000
committerlecoanet2002-12-09 14:47:45 +0000
commit5699492723148fcc0d7ba0b1919475c5e2318537 (patch)
treef4a7f574e2e8749a9f19feebe699c3c5da7fa645 /generic/Text.c
parent7df7f404f7f4634b8137ff554dbff504cc9ad49e (diff)
downloadtkzinc-5699492723148fcc0d7ba0b1919475c5e2318537.zip
tkzinc-5699492723148fcc0d7ba0b1919475c5e2318537.tar.gz
tkzinc-5699492723148fcc0d7ba0b1919475c5e2318537.tar.bz2
tkzinc-5699492723148fcc0d7ba0b1919475c5e2318537.tar.xz
* Passage en display list du code de dessin.
Diffstat (limited to 'generic/Text.c')
-rw-r--r--generic/Text.c251
1 files changed, 130 insertions, 121 deletions
diff --git a/generic/Text.c b/generic/Text.c
index e7e1c47..804670c 100644
--- a/generic/Text.c
+++ b/generic/Text.c
@@ -866,141 +866,150 @@ Render(Item item)
return;
}
- lines = (TextLineInfo) ZnListArray(text->text_info);
- num_lines = ZnListSize(text->text_info);
- Tk_GetFontMetrics(text->font, &fm);
- font_height = fm.ascent+fm.descent;
-
- /*
- * These 3 values should be fetched from the font.
- * Currently I don't know how without diving into
- * Tk internals.
- */
- underline_thickness = 2;
- underline_pos = fm.descent/2;
- overstrike_pos = fm.ascent*3/10;
-
- /*
- * Compute the selection and the cursor geometry.
- */
- ComputeCursorAndSel(item, lines, num_lines,
- &sel_first_line, &sel_last_line,
- &cursor_line, &sel_start_offset,
- &sel_stop_offset, &cursor_offset);
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- /*
- * Render the selection.
- */
- 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;
- yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent;
- xc = xo + sel_stop_offset - sel_start_offset;
- yc = yo + font_height;
- glVertex2f(xo, yo);
- glVertex2f(xc, yo);
- glVertex2f(xc, yc);
- glVertex2f(xo, yc);
- }
- else {
- xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset;
- yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent;
- xc = xo + text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset;
- yc = yo + font_height;
- glVertex2f(xo, yo);
- glVertex2f(xc, yo);
- glVertex2f(xc, yc);
- glVertex2f(xo, yc);
- for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1];
- i < sel_last_line; i++, lines_ptr++) {
+ if (!item->gl_list) {
+ item->gl_list = glGenLists(1);
+ glNewList(item->gl_list, GL_COMPILE);
+
+ lines = (TextLineInfo) ZnListArray(text->text_info);
+ num_lines = ZnListSize(text->text_info);
+ Tk_GetFontMetrics(text->font, &fm);
+ font_height = fm.ascent+fm.descent;
+
+ /*
+ * These 3 values should be fetched from the font.
+ * Currently I don't know how without diving into
+ * Tk internals.
+ */
+ underline_thickness = 2;
+ underline_pos = fm.descent/2;
+ overstrike_pos = fm.ascent*3/10;
+
+ /*
+ * Compute the selection and the cursor geometry.
+ */
+ ComputeCursorAndSel(item, lines, num_lines,
+ &sel_first_line, &sel_last_line,
+ &cursor_line, &sel_start_offset,
+ &sel_stop_offset, &cursor_offset);
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
+ /*
+ * Render the selection.
+ */
+ 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;
+ yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent;
+ xc = xo + sel_stop_offset - sel_start_offset;
+ yc = yo + font_height;
+ glVertex2f(xo, yo);
+ glVertex2f(xc, yo);
+ glVertex2f(xc, yc);
+ glVertex2f(xo, yc);
+ }
+ else {
+ xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset;
+ yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent;
+ xc = xo + text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset;
+ yc = yo + font_height;
+ glVertex2f(xo, yo);
+ glVertex2f(xc, yo);
+ glVertex2f(xc, yc);
+ glVertex2f(xo, yc);
+ for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1];
+ i < sel_last_line; i++, lines_ptr++) {
+ xo = text->pos_dev.x;
+ yo = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent;
+ xc = xo + text->max_width;
+ yc = yo + font_height;
+ glVertex2f(xo, yo);
+ glVertex2f(xc, yo);
+ glVertex2f(xc, yc);
+ glVertex2f(xo, yc);
+ }
xo = text->pos_dev.x;
- yo = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent;
- xc = xo + text->max_width;
+ yo = text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent;
+ xc = xo + lines[sel_last_line].text_origin.x+sel_stop_offset;
yc = yo + font_height;
glVertex2f(xo, yo);
glVertex2f(xc, yo);
glVertex2f(xc, yc);
glVertex2f(xo, yc);
}
- xo = text->pos_dev.x;
- yo = text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent;
- xc = xo + lines[sel_last_line].text_origin.x+sel_stop_offset;
- yc = yo + font_height;
- glVertex2f(xo, yo);
- glVertex2f(xc, yo);
- glVertex2f(xc, yc);
- glVertex2f(xo, yc);
+ glEnd();
}
- glEnd();
- }
- /*
- * Render the cursor.
- */
- if ((cursor_line >= 0) &&
- (wi->focus_item == item) && ti->cursor_on) {
- int xs, ys;
-
- color = ZnGetGradientColor(ti->insert_color, 0, &alpha);
+ /*
+ * Render the cursor.
+ */
+ 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;
+ glBegin(GL_LINES);
+ glVertex2f(xs, ys);
+ glVertex2f(xs, ys + font_height - 1);
+ glEnd();
+ }
+
+ /*
+ * Render the text.
+ */
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ 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);
- 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;
- glBegin(GL_LINES);
- glVertex2f(xs, ys);
- glVertex2f(xs, ys + font_height - 1);
- glEnd();
- }
-
- /*
- * Render the text.
- */
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- 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);
-
- for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) {
- ZnReal xs, ys;
-
- xs = text->pos_dev.x + lines_ptr->text_origin.x;
- ys = text->pos_dev.y + lines_ptr->text_origin.y;
-
- glPushMatrix();
- glTranslatef(xs, ys, 0.0);
- ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_chars);
- glPopMatrix();
-
- if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) {
- glLineWidth(underline_thickness);
- glDisable(GL_TEXTURE_2D);
- if (ISSET(text->flags, UNDERLINED)) {
- glBegin(GL_LINES);
- glVertex2f(xs, ys+underline_pos);
- glVertex2f(xs+lines_ptr->width, ys+underline_pos);
- glEnd();
- }
- if (ISSET(text->flags, OVERSTRIKED)) {
- glBegin(GL_LINES);
- glVertex2f(xs, ys-overstrike_pos);
- glVertex2f(xs+lines_ptr->width, ys-overstrike_pos);
- glEnd();
+
+ for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) {
+ ZnReal xs, ys;
+
+ xs = text->pos_dev.x + lines_ptr->text_origin.x;
+ ys = text->pos_dev.y + lines_ptr->text_origin.y;
+
+ glPushMatrix();
+ glTranslatef(xs, ys, 0.0);
+ ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_chars);
+ glPopMatrix();
+
+ if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) {
+ glLineWidth(underline_thickness);
+ glDisable(GL_TEXTURE_2D);
+ if (ISSET(text->flags, UNDERLINED)) {
+ glBegin(GL_LINES);
+ glVertex2f(xs, ys+underline_pos);
+ glVertex2f(xs+lines_ptr->width, ys+underline_pos);
+ glEnd();
+ }
+ if (ISSET(text->flags, OVERSTRIKED)) {
+ glBegin(GL_LINES);
+ glVertex2f(xs, ys-overstrike_pos);
+ glVertex2f(xs+lines_ptr->width, ys-overstrike_pos);
+ glEnd();
+ }
+ glEnable(GL_TEXTURE_2D);
}
- glEnable(GL_TEXTURE_2D);
}
+ glDisable(GL_TEXTURE_2D);
+
+ glEndList();
}
- glDisable(GL_TEXTURE_2D);
+
+ glCallList(item->gl_list);
#endif
}