Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/messagefield.c

Go to the documentation of this file.
00001 /* {{{
00002  * CalcRogue, a roguelike game for PCs, calculators and PDAs
00003  * Copyright (C) 2003 Jim Babcock
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * }}} */
00019 // messagefield.c
00022 
00023 #include "crogue.h"
00024 #include "export.h"
00025 
00026 #define MESSAGEFIELD_X 0
00027 #define MESSAGEFIELD_Y 0
00028 #define MESSAGEFIELD_ROWS 2
00029 #define MESSAGEFIELD_HEIGHT 16
00030 #define MESSAGEFIELD_WIDTH SCREEN_WIDTH
00031 
00032 static void _UI_MF_savemsg(const char *msg);
00033 static draw_string_info MF_state;
00034 
00035 //{{{
00043 void message(const char *format, ...)
00044 {
00045     va_list args;
00046     va_start(args, format);
00047     vmessage(format, args);
00048 }
00049 //}}}
00050 //{{{
00056 void vmessage(const char *format, va_list args)
00057 {
00058     char buf[512];
00059     
00060     w->interrupt = 1;
00061     
00062     vsprintf(buf, format, args);
00063     
00064     if(!w->messagevis)
00065         UI_MF_clear();
00066 
00067     _UI_MF_savemsg(buf);
00068     UI_MF_sendmsg(buf);
00069     w->messagevis = 1;
00070 }
00071 //}}}
00072 
00073 //{{{
00075 void UI_MF_clear(void)
00076 {
00077 #ifdef USE_CURSES
00078     int i;
00079 #endif
00080     // Reset pos
00081     MF_state.curX = 0;
00082     MF_state.curRow = 0;
00083     
00084 #ifdef IS_CALCULATOR
00085     SetFont(w->options[OPTION_FONTSIZE]);
00086     clear_string(0, 0, MESSAGEFIELD_WIDTH, MESSAGEFIELD_ROWS);
00087 #endif
00088 #ifdef USE_CURSES
00089     for(i=0; i<MESSAGEFIELD_ROWS; i++)
00090         clear_line(i);
00091 #endif
00092 #ifdef PALMOS
00093     Graph_ClearRect(MESSAGEFIELD_X, MESSAGEFIELD_Y,
00094                     MESSAGEFIELD_WIDTH, MESSAGEFIELD_HEIGHT);
00095 #endif
00096 }
00097 //}}}
00098 
00099 static char message_buf[MESSAGEBUF_SIZE];
00100 
00101 //{{{
00103 static void _UI_MF_savemsg(const char *msg)
00104 {
00105     int i;
00106     
00107     // Make room for new message
00108     while(strlen(message_buf) + strlen(msg) + 2 > MESSAGEBUF_SIZE)
00109     {
00110         // Find start of next string
00111         for(i=0; i<strlen(message_buf); i++)
00112             if(message_buf[i] == '\n')
00113                 break;
00114         strcpy(message_buf, message_buf+i+1);
00115     }
00116     
00117     strcat(message_buf, msg);
00118     strcat(message_buf, "\n");
00119 }
00120 //}}}
00121 //{{{
00123 void UI_MF_history(void)
00124 {
00125     char converted_buf[MESSAGEBUF_SIZE]; // For converting newlines to spaces
00126     draw_string_info state = {0, 0};
00127     int i;
00128     strcpy(converted_buf, message_buf);
00129     
00130     for(i=0; i<MESSAGEBUF_SIZE; i++)
00131         if(converted_buf[i] == '\n') converted_buf[i] = ' ';
00132     
00133     Graph_ClrScr();
00134 #ifdef IS_CALCULATOR
00135     SetFont(w->options[OPTION_FONTSIZE]);
00136 #endif
00137     draw_string(converted_buf, &state, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 1);
00138     read_char();
00139     full_redraw();
00140 }
00141 //}}}
00142 //{{{
00152 void UI_MF_sendmsg(const char *msg)
00153 {
00154 #ifdef IS_CALCULATOR
00155     SetFont(w->options[OPTION_FONTSIZE]);
00156 #endif
00157     
00158     if(MF_state.curX)
00159         draw_string(" ", &MF_state, MESSAGEFIELD_X, MESSAGEFIELD_Y, MESSAGEFIELD_WIDTH, MESSAGEFIELD_HEIGHT, 1);
00160     
00161     draw_string(msg, &MF_state, MESSAGEFIELD_X, MESSAGEFIELD_Y, MESSAGEFIELD_WIDTH, MESSAGEFIELD_HEIGHT, 1);
00162     
00163 #ifdef CURSES
00164     refresh();
00165 #endif
00166 }
00167 //}}}
00168 //{{{
00173 void UI_MF_wait(void)
00174 {
00175     UI_MF_sendmsg(gettext("-More-"));
00176     read_char();
00177     UI_MF_clear();
00178 }
00179 //}}}
00180 

Generated on Thu May 20 13:12:10 2004 for CalcRogue by doxygen 1.3.6