00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00108 while(strlen(message_buf) + strlen(msg) + 2 > MESSAGEBUF_SIZE)
00109 {
00110
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];
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