[Tux4kids-commits] r898 - in tuxmath/trunk: . src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Wed Feb 18 21:29:42 UTC 2009
Author: dbruce-guest
Date: 2009-02-18 21:29:42 +0000 (Wed, 18 Feb 2009)
New Revision: 898
Modified:
tuxmath/trunk/Makefile.am
tuxmath/trunk/Makefile.in
tuxmath/trunk/src/credits.c
tuxmath/trunk/src/credits.h
tuxmath/trunk/src/linewrap.c
tuxmath/trunk/src/linewrap.h
tuxmath/trunk/src/setup.c
Log:
linewrap fix
Modified: tuxmath/trunk/Makefile.am
===================================================================
--- tuxmath/trunk/Makefile.am 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/Makefile.am 2009-02-18 21:29:42 UTC (rev 898)
@@ -13,6 +13,7 @@
tuxmath.desktop \
config.rpath \
m4/ChangeLog \
+ Info.plist \
CMakeLists.txt
datadir = @datadir@
Modified: tuxmath/trunk/Makefile.in
===================================================================
--- tuxmath/trunk/Makefile.in 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/Makefile.in 2009-02-18 21:29:42 UTC (rev 898)
@@ -257,6 +257,7 @@
tuxmath.desktop \
config.rpath \
m4/ChangeLog \
+ Info.plist \
CMakeLists.txt
MAKENSIS = @NSIS@
Modified: tuxmath/trunk/src/credits.c
===================================================================
--- tuxmath/trunk/src/credits.c 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/src/credits.c 2009-02-18 21:29:42 UTC (rev 898)
@@ -31,74 +31,74 @@
#include "SDL_extras.h"
-char * credit_text[] = {
- "-TUX, OF MATH COMMAND", /* '-' at beginning makes highlighted: */
- "COPYRIGHT 2001-2006",
- " ",
- "PART OF THE 'TUX4KIDS' PROJECT",
- " ",
- "-DESIGNED BY",
- "SAM 'CRISWELL' HART",
- " ",
- "-LEAD PROGRAMMERS",
- "BILL KENDRICK,",
- "NEW BREED SOFTWARE",
- "DAVID BRUCE",
- "TIM HOLY",
- " ",
- "-ADDITIONAL CODE",
- "GLEN DITCHFIELD",
- "MICHAEL BEHRISCH",
- "DONNY VISZNEKI",
- "YVES COMBE",
- "DAVID YODER",
- "KARL OVE HUFTHAMMER",
- "AHMED SAYED",
- "BRENDAN LUCHEN",
- "JESUS M. MAGER H.",
- " ",
- "-LEAD ARTIST",
- "SAM HART",
- "",
- "-ADDITIONAL ART",
- "BILL KENDRICK",
- "KENDRA SWANSON & LINNEA HOLY",
- " ",
- "-SOUND EFFECTS",
- "TBA",
- " ",
- "-MUSIC",
- "BEYOND THE HORIZON",
- "BY MYSTRA OF STONE ARTS, 1994",
- " ",
- "CCCP MAIN",
- "BY GROO OF CNCD, 1994",
- " ",
- "SOFT BRILLIANCE",
- "TJOPPBASS, 1994",
- " ",
- "-PACKAGERS",
- "JESSE ANDREWS",
- "HOLGER LEVSEN",
- " ",
- "-'TUX' THE PENGUIN CREATED BY",
- "LARRY EWING",
- " ",
- "-TESTERS",
- "PETE SALZMAN",
- "ST. CATHERINE ELEM., CINCINNATI, OH",
- "WESTWOOD ELEMENTARY, CINCINNATI, OH",
- "LAURA BRUCE",
- "ROOSEVELT ELEMENTARY, TAMPA, FL",
- "KENDRA SWANSON AND LINNEA HOLY",
- "OLD BONHOMME ELEMENTARY,",
- "ST. LOUIS, MO",
- "STEPHANIE CHAPIE & HOWARD NATHANSON",
- " ",
- " ",
- "-WEBSITE",
- "WWW.TUX4KIDS.COM",
- NULL
+char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
+ {"-TUX, OF MATH COMMAND"}, /* '-' at beginning makes highlighted: */
+ {"COPYRIGHT 2001-2009 "},
+ {" "},
+ {"PART OF THE 'TUX4KIDS' PROJECT "},
+ {" "},
+ {"-DESIGNED BY "},
+ {"SAM 'CRISWELL' HART "},
+ {" "},
+ {"-LEAD PROGRAMMERS "},
+ {"BILL KENDRICK, "},
+ {"NEW BREED SOFTWARE "},
+ {"DAVID BRUCE "},
+ {"TIM HOLY "},
+ {" "},
+ {"-ADDITIONAL CODE "},
+ {"GLEN DITCHFIELD "},
+ {"MICHAEL BEHRISCH "},
+ {"DONNY VISZNEKI "},
+ {"YVES COMBE "},
+ {"DAVID YODER "},
+ {"KARL OVE HUFTHAMMER "},
+ {"AHMED SAYED "},
+ {"BRENDAN LUCHEN "},
+ {"JESUS M. MAGER H. "},
+ {" "},
+ {"-LEAD ARTIST "},
+ {"SAM HART "},
+ {" "},
+ {"-ADDITIONAL ART "},
+ {"BILL KENDRICK "},
+ {"KENDRA SWANSON & LINNEA HOLY "},
+ {" "},
+ {"-SOUND EFFECTS "},
+ {"TBA "},
+ {" "},
+ {"-MUSIC "},
+ {"BEYOND THE HORIZON "},
+ {"BY MYSTRA OF STONE ARTS, 1994 "},
+ {" "},
+ {"CCCP MAIN "},
+ {"BY GROO OF CNCD, 1994 "},
+ {" "},
+ {"SOFT BRILLIANCE "},
+ {"TJOPPBASS, 1994 "},
+ {" "},
+ {"-PACKAGERS "},
+ {"JESSE ANDREWS "},
+ {"HOLGER LEVSEN "},
+ {" "},
+ {"-'TUX' THE PENGUIN CREATED BY "},
+ {"LARRY EWING "},
+ {" "},
+ {"-TESTERS "},
+ {"PETE SALZMAN "},
+ {"ST. CATHERINE ELEM., CINCINNATI, OH "},
+ {"WESTWOOD ELEMENTARY, CINCINNATI, OH "},
+ {"LAURA BRUCE "},
+ {"ROOSEVELT ELEMENTARY, TAMPA, FL "},
+ {"KENDRA SWANSON AND LINNEA HOLY "},
+ {"OLD BONHOMME ELEMENTARY, "},
+ {"ST. LOUIS, MO "},
+ {"STEPHANIE CHAPIE & HOWARD NATHANSON "},
+ {" "},
+ {" "},
+ {"-WEBSITE "},
+ {"WWW.TUX4KIDS.COM "},
+ {NULL}
};
@@ -386,7 +386,7 @@
return quit;
}
-int scroll_text(char* text[], SDL_Rect subscreen, int speed)
+int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int speed)
{
int done = 0, quit = 0, scroll = 0, clearing = 0;
SDL_Event event;
@@ -396,96 +396,85 @@
line = 0;
do
+ {
+ /* Handle any incoming events: */
+ while (SDL_PollEvent(&event) > 0)
{
- /* Handle any incoming events: */
- while (SDL_PollEvent(&event) > 0)
+ if (event.type == SDL_QUIT)
+ {
+ /* Window close event - quit! */
+ quit = 1;
+ done = 1;
+ }
+ else if (event.type == SDL_KEYDOWN)
+ {
+ if (event.key.keysym.sym == SDLK_ESCAPE)
{
- if (event.type == SDL_QUIT)
- {
- /* Window close event - quit! */
-
- quit = 1;
- done = 1;
- }
- else if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_ESCAPE)
- {
- /* Escape key - quit! */
- done = 1;
- }
- }
- else if (event.type == SDL_MOUSEBUTTONDOWN)
- {
- done = 1;
- }
+ /* Escape key - quit! */
+ done = 1;
}
+ }
+ else if (event.type == SDL_MOUSEBUTTONDOWN)
+ {
+ done = 1;
+ }
+ }
-
- /* Scroll: */
+ /* Scroll: */
+ src = dest = subscreen;
+ src.y += speed; //amount to scroll by
- src = dest = subscreen;
- src.y += speed; //amount to scroll by
-
- SDL_BlitSurface(screen, &src, screen, &dest);
-
- dest.x = subscreen.x;
- dest.y = subscreen.y + subscreen.h - speed;
- dest.w = subscreen.w;
- dest.h = speed;
+ SDL_BlitSurface(screen, &src, screen, &dest);
- SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 0, 0, 0));
-
- ++scroll;
+ dest.x = subscreen.x;
+ dest.y = subscreen.y + subscreen.h - speed;
+ dest.w = subscreen.w;
+ dest.h = speed;
- if (clearing) //scroll/check, but don't display any more text
- {
- if (scroll > subscreen.h / speed)
+ SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 0, 0, 0));
+
+ ++scroll;
+
+ if (clearing) //scroll/check, but don't display any more text
+ {
+ if (scroll > subscreen.h/speed)
done = 1;
- }
- else
- {
- dest.x = subscreen.x + subscreen.w / 2;
- dest.y = subscreen.y + (subscreen.h - scroll * speed);
- dest.w = 1;
- dest.h = 1;
-//#ifdef LINEBREAK
- draw_text(text[line], dest); // translation should have already occurred
-//#else
-// if (strlen(text[line]) > 0)
-// draw_text(gettext(text[line]), dest);
-// else
-// draw_text(text[line], dest);
-//#endif
+ }
+ else
+ {
+ dest.x = subscreen.x + subscreen.w / 2;
+ dest.y = subscreen.y + (subscreen.h - scroll * speed);
+ dest.w = 1;
+ dest.h = 1;
+ draw_text(text[line], dest); // translation should have already occurred
- if (scroll * speed >= TTF_FontHeight(default_font) )
- {
- scroll = 0;
- line++;
-
- if (text[line][0] == '\0') //end of text
- {
- clearing = 1; //scroll to blank
- }
- else
- tmdprintf("text[line]: %s\n", text[line]);
- }
- }
-
-
- SDL_Flip(screen);
-
-
- /* Pause (keep frame-rate event) */
-
- now_time = SDL_GetTicks();
- if (now_time < last_time + (1000 / 20))
+ if (scroll * speed >= TTF_FontHeight(default_font) )
+ {
+ scroll = 0;
+ line++;
+
+ if (text[line][0] == '\0') //end of text
{
- SDL_Delay(last_time + (1000 / 20) - now_time);
- }
- last_time = SDL_GetTicks();
+ clearing = 1; //scroll to blank
+ }
+ else
+ tmdprintf("text[line]: %s\n", text[line]);
+ }
}
+
+ SDL_Flip(screen);
+
+ /* Pause (keep frame-rate event) */
+ now_time = SDL_GetTicks();
+ if (now_time < last_time + (1000 / 20))
+ {
+ SDL_Delay(last_time + (1000 / 20) - now_time);
+ }
+ last_time = SDL_GetTicks();
+
+ }
while (!done);
+
return quit;
}
#if 0 //really cool effect, but not translatable. I'll leave it in in case we
Modified: tuxmath/trunk/src/credits.h
===================================================================
--- tuxmath/trunk/src/credits.h 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/src/credits.h 2009-02-18 21:29:42 UTC (rev 898)
@@ -20,7 +20,10 @@
#ifndef CREDITS_H
#define CREDITS_H
+//needed for MAX_LINES and MAX_LINEWIDTH
+#include "linewrap.h"
+
int credits(void);
-int scroll_text(char* text[], SDL_Rect subscreen, int speed);
+int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int speed);
void draw_text(char* str, SDL_Rect dest);
#endif
Modified: tuxmath/trunk/src/linewrap.c
===================================================================
--- tuxmath/trunk/src/linewrap.c 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/src/linewrap.c 2009-02-18 21:29:42 UTC (rev 898)
@@ -27,51 +27,29 @@
#include "../linebreak/linebreak.h"
#include "linewrap.h"
-static char *wrapped_lines0[MAX_LINES]; // for internal storage
-char *wrapped_lines[MAX_LINES]; // publicly available!
+static char wrapped_lines0[MAX_LINES][MAX_LINEWIDTH]; // for internal storage
+char wrapped_lines[MAX_LINES][MAX_LINEWIDTH]; // publicly available!
-void linewrap_initialize()
-{
- int i;
- for (i = 0; i < MAX_LINES; i++) {
- wrapped_lines[i] = (char *) malloc(sizeof(char)*MAX_LINEWIDTH);
- wrapped_lines0[i] = (char *) malloc(sizeof(char)*MAX_LINEWIDTH);
- }
-}
-void linewrap_cleanup()
+int linewrap(const char *input, char str_list[MAX_LINES][MAX_LINEWIDTH],
+ int width, int max_lines, int max_width)
{
- int i;
- fprintf(stderr, "enter linewrap_cleanup()\n");
-
- for (i = 0; i < MAX_LINES; i++) {
-
- if (wrapped_lines[i] != NULL) {
- fprintf(stderr, "about to try to free wrapped_lines[%d]: %s\n", i, wrapped_lines[i]);
- free(wrapped_lines[i]);
- wrapped_lines[i] = NULL;
- }
-
- if(wrapped_lines0[i] != NULL) {
- fprintf(stderr, "about to try to free wrapped_lines0[%d]: %s\n", i, wrapped_lines0[i]);
- free(wrapped_lines0[i]);
- wrapped_lines0[i] = NULL;
- }
- }
-
- fprintf(stderr, "done linewrap_cleanup()\n");
-}
-
-
-int linewrap(const char *input,char *str_list[],int width,int max_lines,int max_width)
-{
int length = strlen (input);
- char *breaks = malloc (length*sizeof(char));
+// char *breaks = malloc (length);
+ char breaks[MAX_LINES * MAX_LINEWIDTH];
+
int i;
int listIndex;
int strIndex;
-
+
+ if (length > MAX_LINES * MAX_LINEWIDTH)
+ {
+ fprintf(stderr, "warning: in linewrap(), length of input %d exceeds maximum %d, truncating\n",
+ length, MAX_LINES * MAX_LINEWIDTH);
+ length = MAX_LINES * MAX_LINEWIDTH;
+ }
+
// Generate the positions with line breaks
//mbs_width_linebreaks (input, length, width, 0, 0, NULL, locale_charset (), breaks);
mbs_width_linebreaks (input, length, width, 0, 0, NULL, "UTF-8", breaks);
@@ -80,8 +58,10 @@
// values at the first character of the next line, not at the space
// between words.
listIndex = 0;
- for (strIndex = 0, i = 0; i < length; strIndex++, i++) {
- if (breaks[i] == UC_BREAK_POSSIBLE || breaks[i] == UC_BREAK_MANDATORY) {
+ for (strIndex = 0, i = 0; i < length; strIndex++, i++)
+ {
+ if (breaks[i] == UC_BREAK_POSSIBLE || breaks[i] == UC_BREAK_MANDATORY)
+ {
str_list[listIndex][strIndex] = '\0'; // terminate the previous string
strIndex = 0; // start the next line
listIndex++;
@@ -93,16 +73,17 @@
}
str_list[listIndex][strIndex] = '\0';
- free(breaks);
+// free(breaks);
// Return the number of lines
if (listIndex < max_lines)
- return listIndex+1;
+ return listIndex + 1;
else
return max_lines;
}
-void linewrap_list(const char *input[],char *str_list[],int width,int max_lines,int max_width)
+void linewrap_list(const char *input[], char str_list[MAX_LINES][MAX_LINEWIDTH],
+ int width, int max_lines, int max_width)
{
int inputIndex;
int outputIndex;
Modified: tuxmath/trunk/src/linewrap.h
===================================================================
--- tuxmath/trunk/src/linewrap.h 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/src/linewrap.h 2009-02-18 21:29:42 UTC (rev 898)
@@ -1,6 +1,12 @@
#ifndef LINEWRAP_H
#define LINEWRAP_H
+
+/* Storage for linewrapping */
+#define MAX_LINES 128
+#define MAX_LINEWIDTH 40
+extern char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
+
/* linewrap takes an input string (can be in essentially arbitrary
encoding) and loads it into an array of strings, each corresponding
to one line of output text. Arguments:
@@ -17,21 +23,13 @@
On output, linewrap returns the number of lines used to format the
string.
*/
-extern int linewrap(const char *input, char **str_list, int width, int max_lines, int max_width);
+extern int linewrap(const char *input, char str_list[MAX_LINES][MAX_LINEWIDTH], int width, int max_lines, int max_width);
/* This takes a NULL-terminated array of strings and performs
translation and linewrapping, outputting another NULL-terminated
array. */
-extern void linewrap_list(const char *input[], char *str_list[], int width, int max_lines, int max_width);
+extern void linewrap_list(const char *input[], char str_list[MAX_LINES][MAX_LINEWIDTH], int width, int max_lines, int max_width);
-/* Storage for linewrapping */
-#define MAX_LINES 40
-#define MAX_LINEWIDTH 40
-extern char *wrapped_lines[];
-/* Initialization and cleanup of storage */
-void linewrap_initialize();
-void linewrap_cleanup();
-
#endif
Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c 2009-02-18 21:01:31 UTC (rev 897)
+++ tuxmath/trunk/src/setup.c 2009-02-18 21:29:42 UTC (rev 898)
@@ -116,10 +116,6 @@
initialize_options();
/* Command-line code now in own function: */
handle_command_args(argc, argv);
- /* Allocate memory for line wrapping */
-//#ifdef LINEBREAK
- linewrap_initialize();
-//#endif
/* SDL setup in own function:*/
initialize_SDL();
/* Read image and sound files: */
@@ -675,11 +671,6 @@
int frequency,channels,n_timesopened;
Uint16 format;
- /* Free memory used for line breaking */
-//#ifdef LINEBREAK
- linewrap_cleanup();
-//#endif
-
/* Free all images and sounds used by SDL: */
if(default_font)
{
More information about the Tux4kids-commits
mailing list