X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Ffps.c;h=44171730461de142a3d80c6cd9528bc075f3b1c7;hb=8afc01a67be4fbf3f1cc0fce9adf01b5289a21c6;hp=2e1ba3f715a2f4125c5564c85ece9d2b4fc3a744;hpb=c1b9b55ad8d59dc05ef55e316aebf5863e7dfa56;p=xscreensaver diff --git a/hacks/fps.c b/hacks/fps.c index 2e1ba3f7..44171730 100644 --- a/hacks/fps.c +++ b/hacks/fps.c @@ -1,4 +1,4 @@ -/* fps, Copyright (c) 2001-2008 Jamie Zawinski +/* fps, Copyright (c) 2001-2011 Jamie Zawinski * Draw a frames-per-second display (Xlib and OpenGL). * * Permission to use, copy, modify, distribute, and sell this software and its @@ -23,7 +23,6 @@ fps_init (Display *dpy, Window window) fps_state *st; const char *font; XFontStruct *f; - int first, last; if (! get_boolean_resource (dpy, "doFPS", "DoFPS")) return 0; @@ -40,9 +39,6 @@ fps_init (Display *dpy, Window window) f = XLoadQueryFont (dpy, font); if (!f) f = XLoadQueryFont (dpy, "fixed"); - first = f->min_char_or_byte2; - last = f->max_char_or_byte2; - { XWindowAttributes xgwa; XGCValues gcv; @@ -60,7 +56,8 @@ fps_init (Display *dpy, Window window) st->x = 10; st->y = 10; if (get_boolean_resource (dpy, "fpsTop", "FPSTop")) - st->y = - (st->font->ascent + st->font->descent + 10); + /* don't leave a blank line in GL top-fps. */ + st->y = - (/*st->font->ascent +*/ st->font->descent + 10); strcpy (st->string, "FPS: ... "); @@ -85,7 +82,7 @@ fps_slept (fps_state *st, unsigned long usecs) double -fps_compute (fps_state *st, unsigned long polys) +fps_compute (fps_state *st, unsigned long polys, double depth) { if (! st) return 0; /* too early? */ @@ -153,6 +150,18 @@ fps_compute (fps_state *st, unsigned long polys) else sprintf (st->string + strlen(st->string), "%lu%s ", polys, s); } + + if (depth >= 0.0) + { + unsigned long L = strlen (st->string); + char *s = st->string + L; + strcat (s, "\nDepth: "); + sprintf (s + strlen(s), "%.1f", depth); + L = strlen (s); + /* Remove trailing ".0" in case depth is not a fraction. */ + if (s[L-2] == '.' && s[L-1] == '0') + s[L-2] = 0; + } } return st->last_fps; @@ -190,7 +199,7 @@ string_width (XFontStruct *f, const char *c, int *height_ret) } -/* This function is used only in Xlib mode. For GL mode, see glx/fps-glx.c. +/* This function is used only in Xlib mode. For GL mode, see glx/fps-gl.c. */ void fps_draw (fps_state *st) @@ -219,7 +228,6 @@ fps_draw (fps_state *st) if (st->clear_p) { int w, h; - int lh = st->font->ascent + st->font->descent; w = string_width (st->font, string, &h); XFillRectangle (st->dpy, st->window, st->erase_gc, x - st->font->descent, @@ -234,7 +242,7 @@ fps_draw (fps_state *st) s = strchr (string, '\n'); if (! s) s = string + strlen(string); XDrawString (st->dpy, st->window, st->draw_gc, - x, y, string, s - string); + x, y, string, (int) (s - string)); string = s; string++; lines--;