JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
finish high-score entry on KP_ENTER too
[vor.git] / score.c
diff --git a/score.c b/score.c
index 406576c..b21345c 100644 (file)
--- a/score.c
+++ b/score.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "SFont.h"
+#include "font.h"
 
 #include "common.h"
 #include "config.h"
@@ -56,8 +56,6 @@ struct highscore g_scores[2][N_SCORES] = {
 
 static char *titles[2] = { "Normal\n", "Easy\n" };
 
-extern SFont_Font *g_font;
-
 int g_easy = 0;
 int cur_score = -1; // which score we're currently entering.
 
@@ -155,53 +153,57 @@ show_score(void)
        char s[16];
        int r = snprintf(s, 16, "Time: ");
        snprintscore(s+r, 16-r, score);
-       SFont_Write(surf_screen, g_font, XSIZE-250, 0, s);
+       font_write(XSIZE-250, 0, s);
 }
 
 void
-display_scores(SDL_Surface *s, uint32_t x, uint32_t y)
+display_scores(uint32_t x, uint32_t y)
 {
        char t[1024];
-       int i,h = SFont_TextHeight(g_font);
+       int i,h = font_height();
+       int display_cursor = (SDL_GetTicks() / CURSOR_BLINK_TIME) % 2;
+
 
-       SFont_Write(s,g_font,x+30,y,"High scores");
+       font_write(x+30, y, "High scores");
        y += h;
-       if(g_easy) SFont_Write(s,g_font,x+75,y,"(easy)");
-       else SFont_Write(s,g_font,x+60,y,"(normal)");
+       if(g_easy) font_write(x+75,y,"(easy)");
+       else font_write(x+60,y,"(normal)");
        for(i = 0; i<N_SCORES; i++) {
                y += h;
                snprintf(t, 1024, "#%1d",i+1);
-               SFont_Write(s, g_font, x, y, t);
+               font_write(x, y, t);
                snprintscore(t, 1024, g_scores[g_easy][i].score);
-               SFont_Write(s, g_font, x+50, y, t);
-               if(i == cur_score) snprintf(t, 1024, "%s_", g_scores[g_easy][i].name);
+               font_write(x+50, y, t);
+               if(display_cursor && i == cur_score) snprintf(t, 1024, "%s_", g_scores[g_easy][i].name);
                else snprintf(t, 1024, "%s", g_scores[g_easy][i].name);
-               SFont_Write(s, g_font, x+180, y, t);
+               font_write(x+180, y, t);
        }
 }
 
 int
-process_score_input(void)
+process_score_input(SDL_keysym *key)
 {
        char *name;
-       int c,k,n;
-       SDL_Event e;
+       int n;
        
        name = g_scores[g_easy][cur_score].name;
        n = strlen(name);
 
-       while(SDL_PollEvent(&e) && e.type == SDL_KEYDOWN) {
-               c = e.key.keysym.unicode;
-               k = e.key.keysym.sym;
-               if(k == SDLK_BACKSPACE) {
-                       if(n > 0) name[--n]=0;
-               } else {
-                       if(k == SDLK_RETURN) {
-                               SDL_EnableUNICODE(0);
-                               cur_score = -1;
-                               return false;
-                       } else name[n++] = c;
-               }
+       if(key->sym == SDLK_BACKSPACE) {
+               if(n > 0) name[--n]=0;
+       } else {
+               if(key->sym == SDLK_RETURN || key->sym == SDLK_KP_ENTER) {
+                       SDL_EnableUNICODE(0);
+                       cur_score = -1;
+                       if(n == 0) {
+                               name[0] = '-';
+                       }
+                       return false;
+               } else if(n < 12) {
+                       if(key->unicode >= 32 && key->unicode <= 126) {
+                               name[n++] = key->unicode;
+                       }
+               } // else drop it
        }
        return true;
 }