Text_gump.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000 The Exult Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #ifndef ALPHA_LINUX_CXX
00024 #  include <cstring>
00025 #endif
00026 
00027 #include "gamewin.h"
00028 #include "Text_gump.h"
00029 
00030 #ifndef UNDER_CE
00031 using std::strchr;
00032 using std::strcpy;
00033 using std::strlen;
00034 #endif
00035 
00036 /*
00037  *  Add to the text, starting a newline.
00038  */
00039 
00040 void Text_gump::add_text
00041   (
00042   const char *str
00043   )
00044 {
00045   int slen = strlen(str);   // Length of new text.
00046           // Allocate new space.
00047   char *newtext = new char[textlen + (textlen != 0) + slen + 1];
00048   if (textlen)      // Copy over old.
00049     {
00050     strcpy(newtext, text);
00051     // Add new line if not starting a new page and if first char of new string is
00052     // not a new line
00053     if (newtext[textlen-1] != '*') newtext[textlen++] = '~';
00054     }
00055   strcpy(newtext + textlen, str); // Append new.
00056   delete [] text;
00057   text = newtext;
00058   textlen += slen;
00059 }
00060 
00061 /*
00062  *  Paint a page and find where its text ends.
00063  *
00064  *  Output: Index past end of displayed page.
00065  */
00066 
00067 int Text_gump::paint_page
00068   (
00069   Rectangle box,      // Display box rel. to gump.
00070   int start     // Starting offset into text.
00071   )
00072 {
00073   const int font = serpentine?8:4;  // Black.
00074   const int vlead = 1;    // Extra inter-line spacing.
00075   int ypos = 0;
00076   int textheight = sman->get_text_height(font) + vlead;
00077   char *str = text + start;
00078   while (*str && *str != '*' && ypos + textheight <= box.h)
00079   {
00080     if (*str == '~')  // Empty paragraph?
00081     {
00082       ypos += textheight;
00083       str++;
00084       continue;
00085     }
00086           // Look for page break.
00087     char *epage = strchr(str, '*');
00088           // Look for line break.
00089     char *eol = strchr(str, '~');
00090     if (epage && (!eol || eol > epage))
00091       eol = epage;
00092     if (!eol)   // No end found?
00093       eol = text + textlen;
00094     char eolchr = *eol; // Save char. at EOL.
00095     *eol = 0;
00096     int endoff = sman->paint_text_box(font, str, x + box.x,
00097         y + box.y + ypos, box.w, box.h - ypos, vlead);
00098     *eol = eolchr;    // Restore char.
00099     if (endoff > 0)   // All painted?
00100     {   // Value returned is height.
00101       str = eol + (eolchr == '~');
00102       ypos += endoff;
00103     }
00104     else      // Out of room.
00105     {
00106       str += -endoff;
00107       break;
00108     }
00109   }
00110   if (*str == '*')    // Saw end of page?
00111     str++;
00112   gwin->set_painted();    // Force blit.
00113   return (str - text);    // Return offset past end.
00114 }
00115 
00116 /*
00117  *  Show next page(s) of book or scroll.
00118  *
00119  *  Output: 0 if already at end.
00120  */
00121 
00122 int Text_gump::show_next_page
00123   (
00124   )
00125 {
00126   if (curend >= textlen)
00127     return (0);   // That's all, folks.
00128   curtop = curend;    // Start next page or pair of pages.
00129   paint();      // Paint.  This updates curend.
00130   return (1);
00131 }

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1