stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src include/font.h video/font.c


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src include/font.h video/font.c
Date: 16 Jan 2004 07:33:53 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/16 07:33:52

Modified files:
        src/include    : font.h 
        src/video      : font.c 

Log message:
        OpenGL fix, clean up number drawing

Patches:
Index: stratagus/src/include/font.h
diff -u stratagus/src/include/font.h:1.33 stratagus/src/include/font.h:1.34
--- stratagus/src/include/font.h:1.33   Fri Jan  2 08:24:08 2004
+++ stratagus/src/include/font.h        Fri Jan 16 07:33:51 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: font.h,v 1.33 2004/01/01 21:24:08 jsalmon3 Exp $
+//      $Id: font.h,v 1.34 2004/01/15 20:33:51 jsalmon3 Exp $
 
 #ifndef __FONT_H__
 #define __FONT_H__
@@ -156,14 +156,16 @@
 extern int VideoDrawTextClip(int x, int y, unsigned font, const unsigned char* 
text);
        /// Draw reverse text unclipped
 extern int VideoDrawReverseText(int x, int y, unsigned font, const unsigned 
char* text);
+       /// Draw reverse text clipped
+extern int VideoDrawReverseTextClip(int x, int y, unsigned font, const 
unsigned char* text);
        /// Draw text centered and unclipped
 extern int VideoDrawTextCentered(int x, int y, unsigned font, const unsigned 
char* text);
        /// Draw number unclipped
 extern int VideoDrawNumber(int x, int y, unsigned font, int number);
-       /// Draw reverse number unclipped
-extern int VideoDrawReverseNumber(int x, int y, unsigned font, int number);
        /// Draw number clipped
 extern int VideoDrawNumberClip(int x, int y, unsigned font, int number);
+       /// Draw reverse number unclipped
+extern int VideoDrawReverseNumber(int x, int y, unsigned font, int number);
        /// Draw reverse number clipped
 extern int VideoDrawReverseNumberClip(int x, int y, unsigned font, int number);
 
Index: stratagus/src/video/font.c
diff -u stratagus/src/video/font.c:1.78 stratagus/src/video/font.c:1.79
--- stratagus/src/video/font.c:1.78     Thu Jan 15 15:20:42 2004
+++ stratagus/src/video/font.c  Fri Jan 16 07:33:52 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: font.c,v 1.78 2004/01/15 04:20:42 jsalmon3 Exp $
+//      $Id: font.c,v 1.79 2004/01/15 20:33:52 jsalmon3 Exp $
 
 //@{
 
@@ -154,6 +154,9 @@
 
        glDisable(GL_TEXTURE_2D);
 
+       if (y + h >= VideoHeight) {
+               h = VideoHeight - y - 1;
+       }
        for (i = 0; i < NumFontColors; ++i) {
                c = FontColor->Color + i;
                glColor3ub(c->r, c->g, c->b);
@@ -453,6 +456,30 @@
 }
 
 /**
+**  Draw reverse text with font at x,y clipped.
+**
+**  @see VideoDrawText for full description.
+**
+**  @param x     X screen position
+**  @param y     Y screen position
+**  @param font  Font number
+**  @param text  Text to be displayed.
+**
+**  @return      The length of the printed text.
+*/
+global int VideoDrawReverseTextClip(int x, int y, unsigned font,
+       const unsigned char* text)
+{
+       int w;
+
+       FontColor = ReverseTextColor;
+       w = VideoDrawTextClip(x, y, font, text);
+       FontColor = DefaultTextColor;
+
+       return w;
+}
+
+/**
 **  Draw text with font at x,y centered.
 **
 **  @see VideoDrawText for full description.
@@ -476,19 +503,14 @@
 }
 
 /**
-**  Draw number with font at x,y unclipped.
-**
-**  @param x       X screen position
-**  @param y       Y screen position
-**  @param font    Font number
-**  @param number  Number to be displayed.
+**  Format a number using commas
 **
-**  @return        The length of the printed text.
+**  @param number  Number to be formatted
+**  @param buf     Buffer to save the formatted number to
 */
-global int VideoDrawNumber(int x, int y, unsigned font, int number)
+local void FormatNumber(int number, char* buf)
 {
        char bufs[sizeof(int) * 10 + 2];
-       char bufd[sizeof(int) * 10 + 2];
        int sl;
        int s;
        int d;
@@ -498,11 +520,28 @@
        sl = strlen(bufs);
        do {
                if (s > 0 && s < sl && (s - (sl % 3)) % 3 == 0) {
-                       bufd[d++] = ',';
+                       buf[d++] = ',';
                }
-               bufd[d++] = bufs[s++];
+               buf[d++] = bufs[s++];
        } while (s <= sl);
-       return VideoDrawText(x, y, font, bufd);
+}
+
+/**
+**  Draw number with font at x,y unclipped.
+**
+**  @param x       X screen position
+**  @param y       Y screen position
+**  @param font    Font number
+**  @param number  Number to be displayed.
+**
+**  @return        The length of the printed text.
+*/
+global int VideoDrawNumber(int x, int y, unsigned font, int number)
+{
+       char buf[sizeof(int) * 10 + 2];
+
+       FormatNumber(number, buf);
+       return VideoDrawText(x, y, font, buf);
 }
 
 /**
@@ -519,7 +558,7 @@
 {
        char buf[sizeof(int) * 10 + 2];
 
-       sprintf(buf, "%d", number);
+       FormatNumber(number, buf);
        return VideoDrawTextClip(x, y, font, buf);
 }
 
@@ -537,10 +576,31 @@
 {
        char buf[sizeof(int) * 10 + 2];
 
-       sprintf(buf, "%d", number);
+       FormatNumber(number, buf);
        return VideoDrawReverseText(x, y, font, buf);
 }
 
+/**
+**  Draw reverse number with font at x,y clipped.
+**
+**  @param x       X screen position
+**  @param y       Y screen position
+**  @param font    Font number
+**  @param number  Number to be displayed.
+**
+**  @return        The length of the printed text.
+*/
+global int VideoDrawReverseNumberClip(int x, int y, unsigned font, int number)
+{
+       char buf[sizeof(int) * 10 + 2];
+
+       FormatNumber(number, buf);
+       return VideoDrawReverseTextClip(x, y, font, buf);
+}
+
+/**
+**  FIXME: docu
+*/
 local void FontMeasureWidths(ColorFont* fp)
 {
        // FIXME: todo.. can this be optimized?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]