stratagus-cvs
[Top][All Lists]
Advanced

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

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


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/video font.c sprite.c
Date: Wed, 12 Nov 2003 15:33:43 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/11/12 15:33:42

Modified files:
        src/video      : font.c sprite.c 

Log message:
        Started lua support

Patches:
Index: stratagus/src/video/font.c
diff -u stratagus/src/video/font.c:1.58 stratagus/src/video/font.c:1.59
--- stratagus/src/video/font.c:1.58     Fri Oct 17 14:45:27 2003
+++ stratagus/src/video/font.c  Wed Nov 12 15:33:42 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: font.c,v 1.58 2003/10/17 18:45:27 jsalmon3 Exp $
+//     $Id: font.c,v 1.59 2003/11/12 20:33:42 jsalmon3 Exp $
 
 //@{
 
@@ -919,6 +919,7 @@
 **
 **     @return         Integer as font identifier.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 global int CclFontByIdentifier(SCM type)
 {
     if (gh_eq_p(type, gh_symbol2scm("game"))) {
@@ -946,6 +947,36 @@
     }
     return 0;
 }
+#elif defined(USE_LUA)
+global int CclFontByIdentifier(const char* type)
+{
+    if (!strcmp(type, "game")) {
+       return GameFont;
+    } else if (!strcmp(type, "small")) {
+       return SmallFont;
+    } else if (!strcmp(type, "large")) {
+       return LargeFont;
+    } else if (!strcmp(type, "small-title")) {
+       return SmallTitleFont;
+    } else if (!strcmp(type, "large-title")) {
+       return LargeTitleFont;
+    } else if (!strcmp(type, "user1")) {
+       return User1Font;
+    } else if (!strcmp(type, "user2")) {
+       return User2Font;
+    } else if (!strcmp(type, "user3")) {
+       return User3Font;
+    } else if (!strcmp(type, "user4")) {
+       return User4Font;
+    } else if (!strcmp(type, "user5")) {
+       return User5Font;
+    } else {
+       fprintf(stderr, "Unsupported font tag: %s", type);
+       exit(1);
+    }
+    return 0;
+}
+#endif
 
 /**
 **     Define the used fonts.
@@ -957,6 +988,7 @@
 **
 **     @todo   make the font name functions more general, support more fonts.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineFont(SCM type, SCM file, SCM width, SCM height)
 {
     int i;
@@ -971,10 +1003,32 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+local int CclDefineFont(lua_State* l)
+{
+    int i;
+
+    if (lua_gettop(l) != 4 || !lua_isstring(l, 1) || !lua_isstring(l, 2) ||
+           !lua_isnumber(l, 3) || !lua_isnumber(l, 4)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    i = CclFontByIdentifier(lua_tostring(l, 1));
+    free(Fonts[i].File);
+    VideoSaveFree(Fonts[i].Graphic);
+    Fonts[i].Graphic = NULL;
+    Fonts[i].File = strdup(lua_tostring(l, 2));
+    Fonts[i].Width = lua_tonumber(l, 3);
+    Fonts[i].Height = lua_tonumber(l, 4);
+
+    return 0;
+}
+#endif
 
 /**
 **     Define a font color.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineFontColor(SCM list)
 {
     SCM value;
@@ -1022,6 +1076,70 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+local int CclDefineFontColor(lua_State* l)
+{
+    char* color;
+    int i;
+    FontColorMapping* fcm;
+    FontColorMapping** fcmp;
+
+    if (lua_gettop(l) != 2 || !lua_isstring(l, 1) || !lua_istable(l, 2)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    color = strdup(lua_tostring(l, 1));
+
+    if (!FontColorMappings) {
+       FontColorMappings = calloc(sizeof(*FontColorMappings), 1);
+       fcm = FontColorMappings;
+    } else {
+       fcmp = &FontColorMappings;
+       while (*fcmp) {
+           if (!strcmp((*fcmp)->Color, color)) {
+               fprintf(stderr, "Warning: Redefining color '%s'\n", color);
+               free((*fcmp)->Color);
+               fcm = *fcmp;
+               break;
+           }
+           fcmp = &(*fcmp)->Next;
+       }
+       *fcmp = calloc(sizeof(*FontColorMappings), 1);
+       fcm = *fcmp;
+    }
+    fcm->Color = color;
+    fcm->Next = NULL;
+
+    if (luaL_getn(l, 2) != NumFontColors * 3) {
+       fprintf(stderr, "Wrong vector length\n");
+    }
+    for (i = 0; i < NumFontColors; ++i) {
+       lua_rawgeti(l, 2, i * 3 + 1);
+       if (!lua_isnumber(l, -1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       fcm->RGB[i].R = lua_tonumber(l, -1);
+       lua_pop(l, 1);
+       lua_rawgeti(l, 2, i * 3 + 2);
+       if (!lua_isnumber(l, -1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       fcm->RGB[i].G = lua_tonumber(l, -1);
+       lua_pop(l, 1);
+       lua_rawgeti(l, 2, i * 3 + 3);
+       if (!lua_isnumber(l, -1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       fcm->RGB[i].B = lua_tonumber(l, -1);
+       lua_pop(l, 1);
+    }
+
+    return 0;
+}
+#endif
 
 /**
 **     Register CCL features for fonts.
@@ -1030,6 +1148,7 @@
 */
 global void FontsCclRegister(void)
 {
+#if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedure4_0("define-font", CclDefineFont);
     gh_new_procedureN("define-font-color", CclDefineFontColor);
 
@@ -1041,6 +1160,10 @@
     //gh_new_procedure4_0("draw-reverse-text-centered", 
CclDrawReverseTextCentered);
     //gh_new_procedure4_0("draw-number", CclDrawNumber);
     //gh_new_procedure4_0("draw-reverse-number", CclDrawReverseNumber);
+#elif defined(USE_LUA)
+    lua_register(Lua, "DefineFont", CclDefineFont);
+    lua_register(Lua, "DefineFontColor", CclDefineFontColor);
+#endif
 }
 
 /**
Index: stratagus/src/video/sprite.c
diff -u stratagus/src/video/sprite.c:1.37 stratagus/src/video/sprite.c:1.38
--- stratagus/src/video/sprite.c:1.37   Tue Oct  7 20:06:44 2003
+++ stratagus/src/video/sprite.c        Wed Nov 12 15:33:42 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: sprite.c,v 1.37 2003/10/08 00:06:44 jsalmon3 Exp $
+//     $Id: sprite.c,v 1.38 2003/11/12 20:33:42 jsalmon3 Exp $
 
 //@{
 
@@ -3055,7 +3055,7 @@
     if (((graphic->Width / width) * width != graphic->Width) ||
            ((graphic->Height / height) * height != graphic->Height)) {
        fprintf(stderr, "Invalid graphic (width, height) %s\n", name);
-       fprintf(stderr, "Expected: (%d,%d)  Found: (%d,%d)",
+       fprintf(stderr, "Expected: (%d,%d)  Found: (%d,%d)\n",
            width, height, graphic->Width, graphic->Height);
     }
        




reply via email to

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