~ubuntu-branches/ubuntu/quantal/xscreensaver/quantal

« back to all changes in this revision

Viewing changes to hacks/glx/glxfonts.c

  • Committer: Bazaar Package Importer
  • Author(s): Ted Gould
  • Date: 2008-08-28 16:15:25 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080828161525-mxga521aoezxjq8h
Tags: 5.07-0ubuntu1
* Upgrade upstream version
* debian/control: Remove suggest xdaliclock as it is no longer
  included
* Remove 10_jwz-screensaver-randr-patch-3.patch as it has been merged
  upstream.
* Add 24_hacks_xsublim_enable.patch as it seems that xsublim was dropped
  from the build files.  There is nothing in the Changelog about it
  so I believe it was accidental.
* Updating the .desktop files from the XML files using gnome-screensaver's
  utility to do so.  Lots of text updates.  Also:
    * Added: abstractile.desktop
    * Added: cwaves.desktop
    * Added: m6502.desktop
    * Added: skytentacles.desktop
    * Removed: xteevee.desktop
* xscreensaver-gl-extra.files: Added skytentacles
* xscreensaver-data-extra.files: Added abstractile, cwaves and m6502
* xscreensaver-data.files: Remove partial abstractile, m6502 and cwaves

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
extern char *progname;
41
41
 
42
42
 
 
43
#undef DEBUG  /* Defining this causes check_gl_error() to be called inside
 
44
                 time-critical sections, which could slow things down (since
 
45
                 it might result in a round-trip, and stall of the pipeline.)
 
46
               */
 
47
 
 
48
 
43
49
/* Loads the font named by the X resource "res".
44
50
   Returns an XFontStruct.
45
51
   Also converts the font to a set of GL lists and returns the first list.
50
56
  XFontStruct *f;
51
57
 
52
58
  const char *font = get_string_resource (dpy, res, "Font");
53
 
  const char *def1 = "-*-times-bold-r-normal-*-180-*";
 
59
  const char *def1 = "-*-helvetica-medium-r-normal-*-180-*";
54
60
  const char *def2 = "fixed";
55
61
  Font id;
56
62
  int first, last;
128
134
}
129
135
 
130
136
 
131
 
/* Width of the string in pixels.
 
137
/* Width (and optionally height) of the string in pixels.
132
138
 */
133
139
int
134
 
string_width (XFontStruct *f, const char *c)
 
140
string_width (XFontStruct *f, const char *c, int *height_ret)
135
141
{
136
 
  int w = 0;
 
142
  int x = 0;
 
143
  int max_w = 0;
 
144
  int h = f->ascent + f->descent;
137
145
  while (*c)
138
146
    {
139
147
      int cc = *((unsigned char *) c);
140
 
      w += (f->per_char
141
 
            ? f->per_char[cc-f->min_char_or_byte2].rbearing
142
 
            : f->min_bounds.rbearing);
 
148
      if (*c == '\n')
 
149
        {
 
150
          if (x > max_w) max_w = x;
 
151
          x = 0;
 
152
          h += f->ascent + f->descent;
 
153
        }
 
154
      else
 
155
        x += (f->per_char
 
156
              ? f->per_char[cc-f->min_char_or_byte2].width
 
157
              : f->min_bounds.rbearing);
143
158
      c++;
144
159
    }
145
 
  return w;
 
160
  if (x > max_w) max_w = x;
 
161
  if (height_ret) *height_ret = h;
 
162
 
 
163
  return max_w;
146
164
}
147
165
 
148
166
 
157
175
                 GLuint font_dlist,
158
176
                 int window_width, int window_height,
159
177
                 GLfloat x, GLfloat y,
160
 
                 const char *string)
 
178
                 const char *string,
 
179
                 Bool clear_background_p)
161
180
{
162
181
  GLfloat line_height = font->ascent + font->descent;
163
182
  GLfloat sub_shift = (line_height * 0.3);
164
 
  int cw = string_width (font, "m");
 
183
  int cw = string_width (font, "m", 0);
165
184
  int tabs = cw * 7;
166
185
 
167
186
  y -= line_height;
168
187
 
 
188
  /* Sadly, this causes a stall of the graphics pipeline (as would the
 
189
     equivalent calls to glGet*.)  But there's no way around this, short
 
190
     of having each caller set up the specific display matrix we need
 
191
     here, which would kind of defeat the purpose of centralizing this
 
192
     code in one file.
 
193
   */
169
194
  glPushAttrib (GL_TRANSFORM_BIT |  /* for matrix contents */
170
 
                GL_ENABLE_BIT);     /* for various glDisable calls */
171
 
  glDisable (GL_LIGHTING);
172
 
  glDisable (GL_DEPTH_TEST);
173
 
  glDisable (GL_TEXTURE_2D);
 
195
                GL_ENABLE_BIT |     /* for various glDisable calls */
 
196
                GL_CURRENT_BIT |    /* for glColor3f() */
 
197
                GL_LIST_BIT);       /* for glListBase() */
174
198
  {
 
199
# ifdef DEBUG
 
200
    check_gl_error ("glPushAttrib");
 
201
# endif
 
202
 
 
203
    /* disable lighting and texturing when drawing bitmaps!
 
204
       (glPopAttrib() restores these.)
 
205
     */
 
206
    glDisable (GL_TEXTURE_2D);
 
207
    glDisable (GL_LIGHTING);
 
208
    glDisable (GL_BLEND);
 
209
    glDisable (GL_DEPTH_TEST);
 
210
    glDisable (GL_CULL_FACE);
 
211
 
 
212
    /* glPopAttrib() does not restore matrix changes, so we must
 
213
       push/pop the matrix stacks to be non-intrusive there.
 
214
     */
175
215
    glMatrixMode(GL_PROJECTION);
176
216
    glPushMatrix();
177
217
    {
 
218
# ifdef DEBUG
 
219
      check_gl_error ("glPushMatrix");
 
220
# endif
178
221
      glLoadIdentity();
179
222
 
 
223
      /* Each matrix mode has its own stack, so we need to push/pop
 
224
         them separately. */
180
225
      glMatrixMode(GL_MODELVIEW);
181
226
      glPushMatrix();
182
227
      {
183
228
        unsigned int i;
184
229
        int x2 = x;
185
230
        Bool sub_p = False;
 
231
 
 
232
# ifdef DEBUG
 
233
        check_gl_error ("glPushMatrix");
 
234
# endif
 
235
 
186
236
        glLoadIdentity();
187
 
 
188
237
        gluOrtho2D (0, window_width, 0, window_height);
189
 
 
 
238
# ifdef DEBUG
 
239
        check_gl_error ("gluOrtho2D");
 
240
# endif
 
241
 
 
242
        if (clear_background_p)
 
243
          {
 
244
            int w, h;
 
245
            int lh = font->ascent + font->descent;
 
246
            w = string_width (font, string, &h);
 
247
            glColor3f (0, 0, 0);
 
248
            glRecti (x - font->descent,
 
249
                     y + lh, 
 
250
                     x + w + 2*font->descent,
 
251
                     y + lh - h - font->descent);
 
252
            glColor3f (1, 1, 1);
 
253
          }
 
254
 
 
255
        /* draw the text */
190
256
        glRasterPos2f (x, y);
 
257
/*        glListBase (font_dlist);*/
191
258
        for (i = 0; i < strlen(string); i++)
192
259
          {
193
260
            unsigned char c = (unsigned char) string[i];
215
282
              }
216
283
            else
217
284
              {
 
285
/*            glCallLists (s - string, GL_UNSIGNED_BYTE, string);*/
218
286
                glCallList (font_dlist + (int)(c));
219
287
                x2 += (font->per_char
220
288
                       ? font->per_char[c - font->min_char_or_byte2].width
221
289
                       : font->min_bounds.width);
222
290
              }
223
291
          }
 
292
# ifdef DEBUG
 
293
        check_gl_error ("print_gl_string");
 
294
# endif
224
295
      }
225
296
      glPopMatrix();
226
297
    }
228
299
    glPopMatrix();
229
300
  }
230
301
  glPopAttrib();
 
302
# ifdef DEBUG
 
303
  check_gl_error ("glPopAttrib");
 
304
# endif
231
305
 
232
306
  glMatrixMode(GL_MODELVIEW);
233
307
}