[Tux4kids-commits] r1373 - branches/commonification/tuxmath/trunk/src

Bolesław Kulbabiński bolekk-guest at alioth.debian.org
Wed Aug 5 19:09:06 UTC 2009


Author: bolekk-guest
Date: 2009-08-05 19:09:06 +0000 (Wed, 05 Aug 2009)
New Revision: 1373

Modified:
   branches/commonification/tuxmath/trunk/src/SDL_extras.c
   branches/commonification/tuxmath/trunk/src/SDL_extras.h
   branches/commonification/tuxmath/trunk/src/setup.c
   branches/commonification/tuxmath/trunk/src/titlescreen.c
   branches/commonification/tuxmath/trunk/src/titlescreen.h
   branches/commonification/tuxmath/trunk/src/tuxmath.h
Log:
removed TransWipe() from titlescreen.c (in TuxMath)

Modified: branches/commonification/tuxmath/trunk/src/SDL_extras.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/SDL_extras.c	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/SDL_extras.c	2009-08-05 19:09:06 UTC (rev 1373)
@@ -9,7 +9,6 @@
 * Copyright: GPL v3 or later
 *
 */
-#ifndef HAVE_LIBT4KCOMMON
 #include <math.h>
 
 #include "SDL_extras.h"
@@ -19,9 +18,10 @@
 #include "options.h"
 
 
-SDL_Surface* screen = NULL;
 
+#ifndef HAVE_LIBT4KCOMMON
 
+SDL_Surface* screen = NULL;
 /* window size */
 int win_res_x = 640;
 int win_res_y = 480;
@@ -29,7 +29,6 @@
 /* full screen size (set in initialize_SDL() ) */
 int fs_res_x = 0;
 int fs_res_y = 0;
-
 /*
 Return a pointer to the screen we're using, as an alternative to making screen
 global. Not sure what is involved performance-wise in SDL_GetVideoSurface,
@@ -37,14 +36,11 @@
 */
 SDL_Surface* GetScreen()
 {
-  DEBUGCODE(debug_sdl)
-  {
     if (screen != SDL_GetVideoSurface() )
     {
       fprintf(stderr, "Video Surface changed from outside of SDL_Extras!\n");
       screen = SDL_GetVideoSurface();
     }
-  }
   return screen;
 }
 
@@ -187,7 +183,6 @@
   SDL_UnlockSurface(s);
 }
 
-
 /**********************
  Flip:
    input: a SDL_Surface, x, y
@@ -439,6 +434,7 @@
 #elif PIXEL_BITS == 16
   Uint16* p;
 #else
+  Uint16* p;
   return;
 #endif
   Uint32 rm = screen->format->Rmask;
@@ -677,8 +673,509 @@
   return s;
 }
 
+/*************************************************/
+/* TransWipe: Performs various wipes to new bkgs */
+/*************************************************/
+/*
+ * Given a wipe request type, and any variables
+ * that wipe requires, will perform a wipe from
+ * the current screen image to a new one.
+ */
+int TransWipe(const SDL_Surface* newbkg, int type, int segments, int duration)
+{
+  int i, j, x1, x2, y1, y2;
+  int step1, step2, step3, step4;
+  int frame;
+  SDL_Rect src;
+  SDL_Rect dst;
+
+  /* Input validation: ----------------------- */
+  if (!newbkg)
+  {
+    fprintf(stderr, "TransWipe() - 'newbkg' arg invalid!\n");
+    return 0;
+  }
+
+  /* FIXME should support scaling here - DSB */
+  if(newbkg->w != screen->w || newbkg->h != screen->h)
+  {
+    fprintf(stderr, "TransWipe() - wrong size newbkg* arg");
+    return 0;
+  }
+
+  /* segments is num of divisions */
+  /* duration is how many frames animation should take */
+      
+  if(segments < 1)
+    segments = 1;
+  if(duration < 1)
+    duration = 1;
+
+  /* Pick a card, any card...            */
+  while(type == RANDOM_WIPE)
+    type = rand() % NUM_WIPES;
+
+
+  ResetBlitQueue();
+  frame = 0;
+
+  switch(type)
+  {
+    case WIPE_BLINDS_VERT:
+    {
+      step1 = screen->w/segments;
+      step2 = step1/duration;
+
+      for(i = 0; i <= duration; i++)
+      {
+        for(j = 0; j <= segments; j++)
+        {
+          x1 = step1 * (j - 0.5) - i * step2 + 1;
+          x2 = step1 * (j - 0.5) + i * step2 + 1;
+          src.x = x1;
+          src.y = 0;
+          src.w = step2;
+          src.h = screen->h;
+          dst.x = x2;
+          dst.y = 0;
+          dst.w = step2;
+          dst.h = screen->h;
+          SDL_BlitSurface((SDL_Surface*)newbkg, &src, screen, &src);
+          SDL_BlitSurface((SDL_Surface*)newbkg, &dst, screen, &dst);
+          AddRect(&src, &src);
+          AddRect(&dst, &dst);
+        }
+        UpdateScreen(&frame);
+      }
+
+      src.x = 0;
+      src.y = 0;
+      src.w = screen->w;
+      src.h = screen->h;
+      SDL_BlitSurface((SDL_Surface*)newbkg, NULL, screen, &src);
+      SDL_Flip(screen);
+
+      break;
+    } 
+
+    case WIPE_BLINDS_HORIZ:
+    {
+      step1 = screen->h / segments;
+      step2 = step1 / duration;
+
+      for(i = 0; i <= duration; i++)
+      {
+        for(j = 0; j <= segments; j++)
+        {
+          y1 = step1 * (j - 0.5) - i * step2 + 1;
+          y2 = step1 * (j - 0.5) + i * step2 + 1;
+          src.x = 0;
+          src.y = y1;
+          src.w = screen->w;
+          src.h = step2;
+          dst.x = 0;
+          dst.y = y2;
+          dst.w = screen->w;
+          dst.h = step2;
+          SDL_BlitSurface((SDL_Surface*)newbkg, &src, screen, &src);
+          SDL_BlitSurface((SDL_Surface*)newbkg, &dst, screen, &dst);
+          AddRect(&src, &src);
+          AddRect(&dst, &dst);
+        }
+        UpdateScreen(&frame);
+      }
+
+      src.x = 0;
+      src.y = 0;
+      src.w = screen->w;
+      src.h = screen->h;
+      SDL_BlitSurface((SDL_Surface*)newbkg, NULL, screen, &src);
+      SDL_Flip(screen);
+
+      break;
+    }
+
+    case WIPE_BLINDS_BOX:
+    {
+      step1 = screen->w/segments;
+      step2 = step1/duration;
+      step3 = screen->h/segments;
+      step4 = step1/duration;
+
+      for(i = 0; i <= duration; i++)
+      {
+        for(j = 0; j <= segments; j++)
+        {
+          x1 = step1 * (j - 0.5) - i * step2 + 1;
+          x2 = step1 * (j - 0.5) + i * step2 + 1;
+          src.x = x1;
+          src.y = 0;
+          src.w = step2;
+          src.h = screen->h;
+          dst.x = x2;
+          dst.y = 0;
+          dst.w = step2;
+          dst.h = screen->h;
+          SDL_BlitSurface((SDL_Surface*)newbkg, &src, screen, &src);
+          SDL_BlitSurface((SDL_Surface*)newbkg, &dst, screen, &dst);
+          AddRect(&src, &src);
+          AddRect(&dst, &dst);
+          y1 = step3 * (j - 0.5) - i * step4 + 1;
+          y2 = step3 * (j - 0.5) + i * step4 + 1;
+          src.x = 0;
+          src.y = y1;
+          src.w = screen->w;
+          src.h = step4;
+          dst.x = 0;
+          dst.y = y2;
+          dst.w = screen->w;
+          dst.h = step4;
+          SDL_BlitSurface((SDL_Surface*)newbkg, &src, screen, &src);
+          SDL_BlitSurface((SDL_Surface*)newbkg, &dst, screen, &dst);
+          AddRect(&src, &src);
+          AddRect(&dst, &dst);
+        }
+        UpdateScreen(&frame);
+      }
+
+      src.x = 0;
+      src.y = 0;
+      src.w = screen->w;
+      src.h = screen->h;
+      SDL_BlitSurface((SDL_Surface*)newbkg, NULL, screen, &src);
+      SDL_Flip(screen);
+
+      break;
+    }
+    default:
+      break;
+  }
+  return 1;
+}
+
+
+
+
+
+
 /************************************************************************/
 /*                                                                      */
+/*        Begin blit queue support                                      */
+/*                                                                      */
+/* This code (modified from Sam Lantinga's "Alien" example program)     */
+/* implements a blit queue to perform screen updates in a more          */
+/* optimized fashion.                                                   */
+/************************************************************************/
+
+//With fullscreen, we need more updates - 180 wasn't enough
+#define MAX_UPDATES 512
+
+/* --- Data Structure for Dirty Blitting --- */
+static SDL_Rect srcupdate[MAX_UPDATES];
+static SDL_Rect dstupdate[MAX_UPDATES];
+static int numupdates = 0; // tracks how many blits to be done
+
+struct blit {
+    SDL_Surface* src;
+    SDL_Rect* srcrect;
+    SDL_Rect* dstrect;
+    unsigned char type;
+} blits[MAX_UPDATES];
+
+
+
+/***********************
+ InitBlitQueue()
+ ***********************/
+void InitBlitQueue(void)
+{
+  int i;
+
+  /* --- Set up the update rectangle pointers --- */
+  for (i = 0; i < MAX_UPDATES; ++i)
+  {
+    blits[i].srcrect = &srcupdate[i];
+    blits[i].dstrect = &dstupdate[i];
+  }
+  numupdates = 0;
+}
+
+
+/**************************
+ResetBlitQueue(): just set the number
+of pending updates to zero
+***************************/
+void ResetBlitQueue(void)
+{
+  numupdates = 0;
+}
+
+
+/******************************
+AddRect : Don't actually blit a surface,
+    but add a rect to be updated next
+    update
+*******************************/
+int AddRect(SDL_Rect* src, SDL_Rect* dst)
+{
+
+  /*borrowed from SL's alien (and modified)*/
+  struct blit* update;
+
+  if(!src)
+  {
+    fprintf(stderr, "AddRect() - invalid 'src' arg!\n");
+    return 0;
+  }
+
+  if(!dst)
+  {
+    fprintf(stderr, "AddRect() - invalid 'dst' arg!\n");
+    return 0;
+  }
+
+  if(numupdates >= MAX_UPDATES)
+  {
+    fprintf(stderr, "Warning - MAX_UPDATES exceeded, cannot add blit to queue\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "AddRect() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->srcrect->x = src->x;
+  update->srcrect->y = src->y;
+  update->srcrect->w = src->w;
+  update->srcrect->h = src->h;
+  update->dstrect->x = dst->x;
+  update->dstrect->y = dst->y;
+  update->dstrect->w = dst->w;
+  update->dstrect->h = dst->h;
+  update->type = 'I';
+
+  return 1;
+}
+
+
+
+int DrawSprite(sprite* gfx, int x, int y)
+{
+  if (!gfx || !gfx->frame[gfx->cur])
+  {
+    fprintf(stderr, "DrawSprite() - 'gfx' arg invalid!\n");
+    return 0;
+  }
+
+  return DrawObject(gfx->frame[gfx->cur], x, y);
+
+}
+
+
+
+/**********************
+DrawObject : Draw an object at the specified
+location. No respect to clipping!
+*************************/
+int DrawObject(SDL_Surface* surf, int x, int y)
+{
+  struct blit *update;
+
+  if (!surf)
+  {
+    fprintf(stderr, "DrawObject() - invalid 'surf' arg!\n");
+    return 0;
+  }
+
+  if(numupdates >= MAX_UPDATES)
+  {
+    fprintf(stderr, "Warning - MAX_UPDATES exceeded, cannot add blit to queue\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "DrawObject() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->src = surf;
+  update->srcrect->x = 0;
+  update->srcrect->y = 0;
+  update->srcrect->w = surf->w;
+  update->srcrect->h = surf->h;
+  update->dstrect->x = x;
+  update->dstrect->y = y;
+  update->dstrect->w = surf->w;
+  update->dstrect->h = surf->h;
+  update->type = 'D';
+
+  return 1;
+}
+
+
+
+/************************
+UpdateScreen : Update the screen and increment the frame num
+***************************/
+void UpdateScreen(int* frame)
+{
+  int i;
+
+
+  /* -- First erase everything we need to -- */
+  for (i = 0; i < numupdates; i++)
+  {
+    if (blits[i].type == 'E') 
+    {
+//       DEBUGCODE(debug_sdl)
+//       {
+//         fprintf(stderr, "Erasing blits[%d]\n", i);
+//         fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
+//               blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
+//         fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
+//               blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
+//       }
+
+      SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+    }
+  }
+
+//  SNOW_erase();
+
+  /* -- then draw -- */ 
+  for (i = 0; i < numupdates; i++)
+  {
+    if (blits[i].type == 'D') 
+    {
+//       DEBUGCODE(debug_sdl)
+//       {
+//         fprintf(stderr, "drawing blits[%d]\n", i);
+//         fprintf(stderr, "srcrect->x = %d\t srcrect->y = %d\t srcrect->w = %d\t srcrect->h = %d\n",
+//               blits[i].srcrect->x, blits[i].srcrect->y, blits[i].srcrect->w, blits[i].srcrect->h);
+//         fprintf(stderr, "dstrect->x = %d\t dstrect->y = %d\t dstrect->w = %d\t dstrect->h = %d\n",
+//               blits[i].dstrect->x, blits[i].dstrect->y, blits[i].dstrect->w, blits[i].dstrect->h);
+//       } 
+
+      SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+    } 
+  }
+
+//  SNOW_draw();
+
+  /* -- update the screen only where we need to! -- */
+//  if (SNOW_on) 
+//    SDL_UpdateRects(screen, SNOW_add( (SDL_Rect*)&dstupdate, numupdates ), SNOW_rects);
+//  else 
+    SDL_UpdateRects(screen, numupdates, dstupdate);
+
+  numupdates = 0;
+  *frame = *frame + 1;
+}
+
+/* basically puts in an order to overdraw sprite with corresponding */
+/* rect of bkgd img                                                 */
+int EraseSprite(sprite* img, SDL_Surface* curr_bkgd, int x, int y)
+{
+//  struct blit* update;
+
+  if( !img 
+   || img->cur < 0
+   || img->cur > MAX_SPRITE_FRAMES
+   || !img->frame[img->cur])
+  {
+    fprintf(stderr, "EraseSprite() - invalid 'img' arg!\n");
+    return 0;
+  }
+
+
+  return EraseObject(img->frame[img->cur], curr_bkgd, x, y);
+}
+
+
+
+/*************************
+EraseObject : Erase an object from the screen
+**************************/
+int EraseObject(SDL_Surface* surf, SDL_Surface* curr_bkgd, int x, int y)
+{
+  struct blit* update = NULL;
+
+  if(!surf)
+  {
+    fprintf(stderr, "EraseObject() - invalid 'surf' arg!\n");
+    return 0;
+  }
+
+  if(numupdates >= MAX_UPDATES)
+  {
+    fprintf(stderr, "Warning - MAX_UPDATES exceeded, cannot add blit to queue\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "EraseObject() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->src = curr_bkgd;
+
+  /* take dimentsions from src surface: */
+  update->srcrect->x = x;
+  update->srcrect->y = y;
+  update->srcrect->w = surf->w;
+  update->srcrect->h = surf->h;
+
+  /* NOTE this is needed because the letters may go beyond the size of */
+  /* the fish, and we only erase the fish image before we redraw the   */
+  /* fish followed by the letter - DSB                                 */
+  /* add margin of a few pixels on each side: */
+  update->srcrect->x -= ERASE_MARGIN;
+  update->srcrect->y -= ERASE_MARGIN;
+  update->srcrect->w += (ERASE_MARGIN * 2);
+  update->srcrect->h += (ERASE_MARGIN * 2);
+
+
+  /* Adjust srcrect so it doesn't go past bkgd: */
+  if (update->srcrect->x < 0)
+  {
+    update->srcrect->w += update->srcrect->x; //so right edge stays correct
+    update->srcrect->x = 0;
+  }
+  if (update->srcrect->y < 0)
+  {
+    update->srcrect->h += update->srcrect->y; //so bottom edge stays correct
+    update->srcrect->y = 0;
+  }
+
+  if (update->srcrect->x + update->srcrect->w > curr_bkgd->w)
+    update->srcrect->w = curr_bkgd->w - update->srcrect->x;
+  if (update->srcrect->y + update->srcrect->h > curr_bkgd->h)
+    update->srcrect->h = curr_bkgd->h - update->srcrect->y;
+
+
+  update->dstrect->x = update->srcrect->x;
+  update->dstrect->y = update->srcrect->y;
+  update->dstrect->w = update->srcrect->w;
+  update->dstrect->h = update->srcrect->h; 
+  update->type = 'E';
+
+  return 1;
+}
+
+
+#endif //HAVE_LIBT4KCOMMON
+/************************************************************************/
+/*                                                                      */
 /*        Begin text drawing functions                                  */
 /*                                                                      */
 /* These functions support text drawing using either SDL_Pango          */
@@ -1139,4 +1636,3 @@
 }
 #endif
 
-#endif //HAVE_LIBT4KCOMMON

Modified: branches/commonification/tuxmath/trunk/src/SDL_extras.h
===================================================================
--- branches/commonification/tuxmath/trunk/src/SDL_extras.h	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/SDL_extras.h	2009-08-05 19:09:06 UTC (rev 1373)
@@ -13,9 +13,10 @@
 #ifndef SDL_EXTRAS_H
 #define SDL_EXTRAS_H
 
+
 #include "SDL.h"
+#include "tuxmath.h"
 
-#ifndef HAVE_LIBT4KCOMMON
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 # define rmask 0xff000000
 # define gmask 0x00ff0000
@@ -28,7 +29,18 @@
 # define amask 0xff000000
 #endif
 
-/* Non-text graphics functions: */
+#ifndef HAVE_LIBT4KCOMMON
+enum
+{
+  WIPE_BLINDS_VERT,
+  WIPE_BLINDS_HORIZ,
+  WIPE_BLINDS_BOX,
+  RANDOM_WIPE,
+  NUM_WIPES
+};
+
+#define ERASE_MARGIN 5
+
 SDL_Surface*    GetScreen();
 void            DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
 void            DrawButtonOn(SDL_Surface* target, SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
@@ -50,6 +62,16 @@
 SDL_EventType   WaitForEvent(SDL_EventMask events);
 SDL_Surface*    zoom(SDL_Surface* src, int new_w, int new_h);
 
+int             TransWipe(const SDL_Surface* newbkg, int type, int segments, int duration);
+void            InitBlitQueue(void);
+void            ResetBlitQueue(void);
+int             AddRect(SDL_Rect* src, SDL_Rect* dst);
+int             DrawSprite(sprite* gfx, int x, int y);
+int             DrawObject(SDL_Surface* surf, int x, int y);
+void            UpdateScreen(int* frame);
+int             EraseSprite(sprite* img, SDL_Surface* curr_bkgd, int x, int y);
+int             EraseObject(SDL_Surface* surf, SDL_Surface* curr_bkgd, int x, int y);
+
 /*Text rendering functions: */
 int             Setup_SDL_Text(void);
 void            Cleanup_SDL_Text(void);
@@ -57,6 +79,5 @@
 SDL_Surface*    SimpleText(const char *t, int size, SDL_Color* col);
 SDL_Surface*    SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset);
 
-
 #endif
 #endif

Modified: branches/commonification/tuxmath/trunk/src/setup.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/setup.c	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/setup.c	2009-08-05 19:09:06 UTC (rev 1373)
@@ -485,9 +485,6 @@
   int frequency, channels, n_timesopened;
   Uint16 format;
 
-  /* Init SDL Video: */
-  screen = NULL;
-
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
   {
     fprintf(stderr,
@@ -570,8 +567,8 @@
 
     if (Opts_GetGlobalOpt(FULLSCREEN))
     {
-      screen = SDL_SetVideoMode(fs_res_x, fs_res_y, PIXEL_BITS, SDL_FULLSCREEN | surfaceMode);
-      if (screen == NULL)
+      SDL_SetVideoMode(fs_res_x, fs_res_y, PIXEL_BITS, SDL_FULLSCREEN | surfaceMode);
+      if (GetScreen() == NULL)
       {
         fprintf(stderr,
               "\nWarning: I could not open the display in fullscreen mode.\n"
@@ -583,10 +580,10 @@
 
     if (!Opts_GetGlobalOpt(FULLSCREEN))
     {
-      screen = SDL_SetVideoMode(win_res_x, win_res_y, PIXEL_BITS, surfaceMode);
+      SDL_SetVideoMode(win_res_x, win_res_y, PIXEL_BITS, surfaceMode);
     }
 
-    if (screen == NULL)
+    if (GetScreen() == NULL)
     {
       fprintf(stderr,
             "\nError: I could not open the display.\n"

Modified: branches/commonification/tuxmath/trunk/src/titlescreen.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/titlescreen.c	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/titlescreen.c	2009-08-05 19:09:06 UTC (rev 1373)
@@ -37,6 +37,9 @@
 #include "SDL_extras.h"
 #include "menu.h"
 
+#ifdef HAVE_LIBT4KCOMMON
+#include <t4kcommon/tux4kids-common.h>
+#endif
 
 /* these are all menu choices that are available in tuxmath.
    By using a define we can create both an enum and
@@ -79,11 +82,6 @@
 
 enum { MENU_MAIN, MENU_LESSONS, MENU_LOGIN };
 
-/* --- Data Structure for Dirty Blitting --- */
-SDL_Rect srcupdate[MAX_UPDATES];
-SDL_Rect dstupdate[MAX_UPDATES];
-int numupdates = 0; // tracks how many blits to be done
-
 // Colors we use:
 SDL_Color black;
 SDL_Color gray;
@@ -92,14 +90,6 @@
 SDL_Color white;
 SDL_Color yellow;
 
-// Type needed for trans_wipe():
-struct blit {
-    SDL_Surface *src;
-    SDL_Rect *srcrect;
-    SDL_Rect *dstrect;
-    unsigned char type;
-} blits[MAX_UPDATES];
-
 // Lessons available for play
 char **lesson_list_titles = NULL;
 char **lesson_list_filenames = NULL;
@@ -147,11 +137,11 @@
 
 SDL_Surface* current_bkg()
   /* This syntax makes my brain start to explode! */
-  { return screen->flags & SDL_FULLSCREEN ? fs_bkg : win_bkg; }
+  { return GetScreen()->flags & SDL_FULLSCREEN ? fs_bkg : win_bkg; }
 
 void set_current_bkg(SDL_Surface* new_bkg)
 {
-  if(screen->flags & SDL_FULLSCREEN)
+  if(GetScreen()->flags & SDL_FULLSCREEN)
   {
     if(fs_bkg != NULL)
       SDL_FreeSurface(fs_bkg);
@@ -180,11 +170,6 @@
 
 void free_titlescreen(void);
 
-void trans_wipe(SDL_Surface* newbkg, int type, int var1, int var2);
-void init_blits(void);
-void update_screen(int* frame);
-void add_rect(SDL_Rect* src, SDL_Rect* dst);
-
 int handle_easter_egg(const SDL_Event* evt);
 
 
@@ -217,7 +202,7 @@
   if(logo)
   {
     /* Center horizontally and vertically */
-    logo_rect.x = (screen->w - logo->w) / 2;
+    logo_rect.x = (GetScreen()->w - logo->w) / 2;
     logo_rect.y = (screen->h - logo->h) / 2;
 
     logo_rect.w = logo->w;
@@ -231,6 +216,8 @@
     SDL_FreeSurface(logo);
   }
 
+  InitBlitQueue();
+
   /* load menus */
   SetActivitiesList(N_OF_ACTIVITIES, activities);
   SetImagePathPrefix(DATA_PREFIX);
@@ -286,7 +273,7 @@
   if(current_bkg())
   {
     /* FIXME not sure trans_wipe() works in Windows: */
-    trans_wipe(current_bkg(), RANDOM_WIPE, 10, 20);
+    TransWipe(current_bkg(), RANDOM_WIPE, 10, 20);
     /* Make sure background gets drawn (since trans_wipe() doesn't */
     /* seem to work reliably as of yet):                          */
     SDL_BlitSurface(current_bkg(), NULL, screen, &bkg_rect);
@@ -359,9 +346,9 @@
 
 void DrawTitleScreen(void)
 {
-  SDL_BlitSurface(current_bkg(), NULL, screen, &bkg_rect);
-  SDL_BlitSurface(Tux->frame[0], NULL, screen, &tux_rect);
-  SDL_BlitSurface(title, NULL, screen, &title_rect);
+  SDL_BlitSurface(current_bkg(), NULL, GetScreen(), &bkg_rect);
+  SDL_BlitSurface(Tux->frame[0], NULL, GetScreen(), &tux_rect);
+  SDL_BlitSurface(title, NULL, GetScreen(), &title_rect);
   //SDL_UpdateRect(screen, 0, 0, 0, 0);
 }
 
@@ -373,15 +360,15 @@
 {
   SDL_Surface* new_bkg = NULL;
 
-  if(curr_res_x != screen->w || curr_res_y != screen->h)
+  if(curr_res_x != GetScreen()->w || curr_res_y != GetScreen()->h)
   {
     /* we need to rerender titlescreen items */
     DEBUGMSG(debug_titlescreen, "Re-rendering titlescreen items.\n");
 
     /* we keep two backgrounds to make screen mode switch faster */
-    if(current_bkg()->w != screen->w || current_bkg()->h != screen->h)
+    if(current_bkg()->w != GetScreen()->w || current_bkg()->h != GetScreen()->h)
     {
-      new_bkg = LoadBkgd(bkg_path, screen->w, screen->h);
+      new_bkg = LoadBkgd(bkg_path, GetScreen()->w, GetScreen()->h);
       if(new_bkg == NULL)
       {
         DEBUGMSG(debug_titlescreen, "RenderTitleScreen(): Failed to load new background.\n");
@@ -395,8 +382,8 @@
     }
 
     bkg_rect = current_bkg()->clip_rect;
-    bkg_rect.x = (screen->w - bkg_rect.w) / 2;
-    bkg_rect.y = (screen->h - bkg_rect.h) / 2;
+    bkg_rect.x = (GetScreen()->w - bkg_rect.w) / 2;
+    bkg_rect.y = (GetScreen()->h - bkg_rect.h) / 2;
 
     /* Tux in lower left corner of the screen */
     SetRect(&tux_rect, tux_pos);
@@ -438,9 +425,10 @@
     beak.w = beak_pos[2] * tux_rect.w;
     beak.h = beak_pos[3] * tux_rect.h;
 
-    curr_res_x = screen->w;
-    curr_res_y = screen->h;
+    curr_res_x = GetScreen()->w;
+    curr_res_y = GetScreen()->h;
 
+
     DEBUGMSG(debug_titlescreen, "Leaving RenderTitleScreen().\n");
   }
   return 1;
@@ -1052,254 +1040,6 @@
   SDL_FreeSurface(s4);
 }
 
-/* Was in playgame.c in tuxtype: */
-
-/* trans_wipe: Performs various wipes to new bkgs
-   Given a wipe request type, and any variables
-   that wipe requires, will perform a wipe from
-   the current screen image to a new one. */
-void trans_wipe(SDL_Surface* newbkg, int type, int var1, int var2)
-{
-  int i, j, x1, x2, y1, y2;
-  int step1, step2, step3, step4;
-  int frame;
-  SDL_Rect src;
-  SDL_Rect dst;
-
-  if (!screen)
-  {
-    DEBUGMSG(debug_titlescreen, "trans_wipe(): screen not valid!\n");
-    return;
-  }
-
-  if (!newbkg)
-  {
-    DEBUGMSG(debug_titlescreen, "trans_wipe(): newbkg not valid!\n");
-    return;
-  }
-
-  init_blits();
-
-  numupdates = 0;
-  frame = 0;
-
-  if(newbkg->w == screen->w && newbkg->h == screen->h) {
-    if( type == RANDOM_WIPE )
-      type = (RANDOM_WIPE * ((float) rand()) / (RAND_MAX+1.0));
-
-    switch( type ) {
-      case WIPE_BLINDS_VERT: {
-        DEBUGMSG(debug_titlescreen, "trans_wipe(): Doing 'WIPE_BLINDS_VERT'\n");
-        /*var1 isnum ofdivisions
-          var2is howmany framesanimation shouldtake */
-        if(var1 <1 )var1 =1;
-        if( var2< 1) var2= 1;
-        step1= screen->w/ var1;
-        step2= step1/ var2;
-
-        for(i= 0;i <=var2; i++)
-        {
-          for(j= 0;j <=var1; j++)
-          {
-            x1= step1* (j- 0.5)- i* step2+ 1;
-            x2= step1* (j- 0.5)+ i* step2+ 1;
-            src.x= x1;
-            src.y= 0;
-            src.w= step2;
-            src.h= screen->h;
-            dst.x= x2;
-            dst.y= 0;
-            dst.w= step2;
-            dst.h= screen->h;
-
-            SDL_BlitSurface(newbkg,&src, screen,&src);
-            SDL_BlitSurface(newbkg, &dst,screen, &dst);
-
-            add_rect(&src,&src);
-            add_rect(&dst, &dst);
-          }
-          update_screen(&frame);
-        }
-
-        src.x= 0;
-        src.y= 0;
-        src.w= screen->w;
-        src.h= screen->h;
-        SDL_BlitSurface(newbkg,NULL, screen,&src);
-        SDL_Flip(screen);
-
-        break;
-      }
-      case WIPE_BLINDS_HORIZ:{
-        DEBUGMSG(debug_titlescreen, "trans_wipe(): Doing 'WIPE_BLINDS_HORIZ'\n");
-        /* var1is numof divisions
-         var2 ishow manyframes animationshould take*/
-        if( var1< 1) var1= 1;
-        if(var2 <1 )var2 =1;
-        step1 =screen->h /var1;
-        step2 =step1 /var2;
-
-        for(i =0; i<= var2;i++) {
-          for(j= 0;j <=var1; j++){
-            y1 =step1 *(j -0.5) -i *step2 +1;
-            y2 =step1 *(j -0.5) +i *step2 +1;
-            src.x =0;
-            src.y =y1;
-            src.w =screen->w;
-            src.h =step2;
-            dst.x =0;
-            dst.y =y2;
-            dst.w =screen->w;
-            dst.h =step2;
-
-            SDL_BlitSurface(newbkg, &src,screen, &src);
-            SDL_BlitSurface(newbkg,&dst, screen,&dst);
-
-            add_rect(&src, &src);
-            add_rect(&dst,&dst);
-          }
-          update_screen(&frame);
-        }
-
-        src.x =0;
-        src.y =0;
-        src.w =screen->w;
-        src.h =screen->h;
-        SDL_BlitSurface(newbkg, NULL,screen, &src);
-        SDL_Flip(screen);
-
-        break;
-      }
-      case WIPE_BLINDS_BOX:{
-        DEBUGMSG(debug_titlescreen, "trans_wipe(): Doing 'WIPE_BLINDS_BOX'\n");
-        /* var1is numof divisions
-         var2 ishow manyframes animationshould take*/
-        if( var1< 1) var1= 1;
-        if(var2 <1 )var2 =1;
-        step1 =screen->w /var1;
-        step2 =step1 /var2;
-        step3 =screen->h /var1;
-        step4 =step1 /var2;
-
-        for(i =0; i<= var2;i++) {
-          for(j= 0;j <=var1; j++){
-            x1 =step1 *(j -0.5) -i *step2 +1;
-            x2 =step1 *(j -0.5) +i *step2 +1;
-            src.x =x1;
-            src.y =0;
-            src.w =step2;
-            src.h =screen->h;
-            dst.x =x2;
-            dst.y =0;
-            dst.w =step2;
-            dst.h =screen->h;
-
-            SDL_BlitSurface(newbkg, &src,screen, &src);
-            SDL_BlitSurface(newbkg,&dst, screen,&dst);
-
-            add_rect(&src, &src);
-            add_rect(&dst,&dst);
-            y1 =step3 *(j -0.5) -i *step4 +1;
-            y2 =step3 *(j -0.5) +i *step4 +1;
-            src.x =0;
-            src.y =y1;
-            src.w =screen->w;
-            src.h =step4;
-            dst.x =0;
-            dst.y =y2;
-            dst.w =screen->w;
-            dst.h =step4;
-            SDL_BlitSurface(newbkg, &src,screen, &src);
-            SDL_BlitSurface(newbkg,&dst, screen,&dst);
-            add_rect(&src, &src);
-            add_rect(&dst,&dst);
-          }
-          update_screen(&frame);
-        }
-
-        src.x =0;
-        src.y =0;
-        src.w =screen->w;
-        src.h =screen->h;
-        SDL_BlitSurface(newbkg, NULL,screen, &src);
-        SDL_Flip(screen);
-
-        break;
-      }
-      default:
-        break;
-    }
-  }
-  DEBUGMSG(debug_titlescreen, "trans_wipe(): FINISH\n");
-}
-
-/* InitEngine - Set up the update rectangle pointers
-   (user by trans_wipe() ) */
-void init_blits(void) {
-  int i;
-
-  for (i = 0; i < MAX_UPDATES; ++i) {
-    blits[i].srcrect = &srcupdate[i];
-    blits[i].dstrect = &dstupdate[i];
-  }
-}
-
-
-/* update_screen : Update the screen and increment the frame num
-   (used by trans_wipe() ) */
-void update_screen(int *frame) {
-  int i;
-
-  /* -- First erase everything we need to -- */
-  for (i = 0; i < numupdates; i++)
-    if (blits[i].type == 'E')
-      SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
-//        SNOW_erase();
-
-  /* -- then draw -- */
-  for (i = 0; i < numupdates; i++)
-    if (blits[i].type == 'D')
-      SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
-//        SNOW_draw();
-
-/* -- update the screen only where we need to! -- */
-//        if (SNOW_on)
-//                SDL_UpdateRects(screen, SNOW_add( (SDL_Rect*)&dstupdate, numupdates ), SNOW_rects);
-//        else
-    SDL_UpdateRects(screen, numupdates, dstupdate);
-
-  numupdates = 0;
-  *frame = *frame + 1;
-}
-
-
-/* add_rect: Don't actually blit a surface,
-   but add a rect to be updated next update
-   (used by trans_wipe() ) */
-void add_rect(SDL_Rect* src, SDL_Rect* dst) {
-  /*borrowed from SL's alien (and modified)*/
-
-  struct blit *update;
-
-  if (!src || !dst)
-  {
-    DEBUGMSG(debug_titlescreen, "add_rect(): src or dst invalid!\n");
-    return;
-  }
-
-  update = &blits[numupdates++];
-
-  update->srcrect->x = src->x;
-  update->srcrect->y = src->y;
-  update->srcrect->w = src->w;
-  update->srcrect->h = src->h;
-  update->dstrect->x = dst->x;
-  update->dstrect->y = dst->y;
-  update->dstrect->w = dst->w;
-  update->dstrect->h = dst->h;
-  update->type = 'I';
-}
-
 int handle_easter_egg(const SDL_Event* evt)
   {
   static int eggtimer = 0;

Modified: branches/commonification/tuxmath/trunk/src/titlescreen.h
===================================================================
--- branches/commonification/tuxmath/trunk/src/titlescreen.h	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/titlescreen.h	2009-08-05 19:09:06 UTC (rev 1373)
@@ -71,14 +71,6 @@
 
 #define MUSIC_FADE_OUT_MS               80
 
-enum {
-    WIPE_BLINDS_VERT,
-    WIPE_BLINDS_HORIZ,
-    WIPE_BLINDS_BOX,
-    RANDOM_WIPE,
-
-    NUM_WIPES
-};
 // End of code from tuxtype's globals.h
 
 /* --- timings for tux blinking --- */

Modified: branches/commonification/tuxmath/trunk/src/tuxmath.h
===================================================================
--- branches/commonification/tuxmath/trunk/src/tuxmath.h	2009-08-05 19:08:15 UTC (rev 1372)
+++ branches/commonification/tuxmath/trunk/src/tuxmath.h	2009-08-05 19:09:06 UTC (rev 1373)
@@ -57,6 +57,7 @@
   int cur;
 } sprite;
 
+extern SDL_Surface* screen;
 #endif //HAVE_LIBT4KCOMMON
 /* Global data gets 'externed' here: */
 
@@ -76,7 +77,6 @@
 extern SDL_Color white;
 extern SDL_Color yellow;
 
-extern SDL_Surface* screen; /* declared in setup.c; also used in game.c, options.c, fileops.c, credits.c, titlescreen.c */
 extern SDL_Surface* images[];    /* declared in setup.c, used in same files as screen */
 extern sprite* sprites[];
 extern SDL_Surface* flipped_images[];




More information about the Tux4kids-commits mailing list