diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp index 7ca866cd15adbb602258b6e5231114fd4db7c114..c7d7c1ea39b3539dec92f065edf04a6f5ab38969 100644 --- a/Fltk/Opengl.cpp +++ b/Fltk/Opengl.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl.cpp,v 1.45 2004-12-28 20:37:19 geuzaine Exp $ +// $Id: Opengl.cpp,v 1.46 2004-12-28 23:59:48 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -102,14 +102,18 @@ void Draw_String(char *s, double style) if(size) CTX.gl_fontsize = size; if(align > 0){ - GLfloat pos[4]; - glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); - gl_font(CTX.gl_font_enum, CTX.gl_fontsize); - float width = gl_width(s); - if(align == 1) // center - glRasterPos2d(pos[0]-width/2., pos[1]); - else if(align == 2) // right - glRasterPos2d(pos[0]-width, pos[1]); + GLboolean valid; + glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); + if(valid == GL_TRUE){ + GLfloat pos[4]; + glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); + gl_font(CTX.gl_font_enum, CTX.gl_fontsize); + float width = gl_width(s); + if(align == 1) // center + glRasterPos2d(pos[0]-width/2., pos[1]); + else if(align == 2) // right + glRasterPos2d(pos[0]-width, pos[1]); + } } Draw_String(s); diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp index ffdd249ecb8d814598776f75f5b98e4503ed0193..4173801e0b0e2094ddbd5cee82aefb88411535b3 100644 --- a/Graphics/Graph2D.cpp +++ b/Graphics/Graph2D.cpp @@ -1,4 +1,4 @@ -// $Id: Graph2D.cpp,v 1.40 2004-12-28 20:37:19 geuzaine Exp $ +// $Id: Graph2D.cpp,v 1.41 2004-12-28 23:59:48 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -458,11 +458,15 @@ void Draw_Text2D3D(int dim, int timestep, int nb, List_T * td, List_T * tc) d2 = (double *)List_Pointer_Test(td, (j + 1) * nbd); if(dim == 2) { x = d1[0]; - if(x < 0) + if(x < 0) // measure from right border x = CTX.viewport[2] + x; + else if(x > 99999) // by convention, x-centered + x = CTX.viewport[2]/2; y = CTX.viewport[3] - d1[1]; - if(d1[1] < 0) + if(d1[1] < 0) // measure from bottom border y = -d1[1]; + else if(d1[1] > 99999) // by convention, y-centered + y = CTX.viewport[3]/2.; z = 0.; style = d1[2]; index = (int)d1[3]; diff --git a/doc/texinfo/gmsh.texi b/doc/texinfo/gmsh.texi index e47c18c5d17197169140130f4fc812bcf8cdffc3..4d26217e2b53e97c0e06217bfd2bf02779a3d6ff 100644 --- a/doc/texinfo/gmsh.texi +++ b/doc/texinfo/gmsh.texi @@ -1,5 +1,5 @@ \input texinfo.tex @c -*-texinfo-*- -@c $Id: gmsh.texi,v 1.154 2004-12-28 20:37:19 geuzaine Exp $ +@c $Id: gmsh.texi,v 1.155 2004-12-28 23:59:48 geuzaine Exp $ @c @c Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle @c @@ -3106,13 +3106,18 @@ The values are given by time step, by node and by component, i.e.: @end example For the 2D text objects, the two first @var{expression}s in -@var{list-of-coords} give the position of the string in screen coordinates. -If the third @var{expression} is equal to zero, the text is left-aligned and -displayed using the default font and size. Otherwise, the third -@var{expression} is converted into an integer whose eight lower bits give -the font size, whose eight next bits select the font (the index corresponds -to the position in the font menu in the GUI), and whose eight next bits -define the text alignment (0=left, 1=center, 2=right). +@var{list-of-coords} give the X-Y position of the string in screen +coordinates, measured from the top-left corner of the window. If the first +(respectively second) @var{expression} is negative, the position is measured +from the right (respectively left) edge of the window. If the value of the +first (respectively second) @var{expression} is larger than 99999, the +string is centered horizontally (respectively vertically). If the third +@var{expression} is equal to zero, the text is left-aligned and displayed +using the default font and size. Otherwise, the third @var{expression} is +converted into an integer whose eight lower bits give the font size, whose +eight next bits select the font (the index corresponds to the position in +the font menu in the GUI), and whose eight next bits define the text +alignment (0=left, 1=center, 2=right). For the 3D text objects, the three first @var{expression}s in @var{list-of-coords} give the position of the leftmost element of the string @@ -3250,14 +3255,19 @@ is a list of 4 double precision numbers: @example @var{coord1} @var{coord2} @var{style} @var{index} @end example -where @var{coord1} and @var{coord2} give the position of the 2D string in -screen coordinates and @var{index} gives the starting index of the string in -@var{text2d-chars}. If @var{style} is equal to zero, the text is -left-aligned and displayed using the default font and size. Otherwise, -@var{style} is converted into an integer whose eight lower bits give the -font size, whose eight next bits select the font (the index corresponds to -the position in the font menu in the GUI), and whose eight next bits define -the text alignment (0=left, 1=center, 2=right). +where @var{coord1} and @var{coord2} give the X-Y position of the 2D string +in screen coordinates (measured from the top-left corner of the window) and +where @var{index} gives the starting index of the string in +@var{text2d-chars}. If @var{coord1} (respectively @var{coord2}) is negative, +the position is measured from the right (respectively left) edge of the +window. If @var{coord1} (respectively @var{coord2}) is larger than 99999, +the string is centered horizontally (respectively vertically). If +@var{style} is equal to zero, the text is left-aligned and displayed using +the default font and size. Otherwise, @var{style} is converted into an +integer whose eight lower bits give the font size, whose eight next bits +select the font (the index corresponds to the position in the font menu in +the GUI), and whose eight next bits define the text alignment (0=left, +1=center, 2=right). @item @var{text2d-chars} is a list of @var{nb-text2d-chars} characters. Substrings are separated with diff --git a/tutorial/t9.geo b/tutorial/t9.geo index 16f48eb343a3c98c6b29fa4a404d3c7904c9eb64..d874f6eec0877e381c22c3030b5cf1de19d0d0af 100644 --- a/tutorial/t9.geo +++ b/tutorial/t9.geo @@ -38,7 +38,10 @@ Plugin(CutPlane).Run ; // Add a title Plugin(Annotate).Text = "A nice title" ; -Plugin(Annotate).X = General.GraphicsWidth/2 ; +// By convention, a value greater than 99999 represents the center (we +// could also use `General.GraphicsWidth/2', but that would only center +// the string for the current window size): +Plugin(Annotate).X = 1.e6; Plugin(Annotate).Y = 50 ; Plugin(Annotate).Font = "Times-BoldItalic" ; Plugin(Annotate).FontSize = 28 ;