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

sys/curses/sysutil.c

Go to the documentation of this file.
00001 #include "crogue.h"
00002 #include "export.h"
00003 
00004 //{{{
00005 int read_char(void)
00006 {
00007     refresh();
00008     feed_entropy(get_entropy());
00009     return wgetch(stdscr);
00010 }
00011 //}}}
00012 //{{{
00013 void delay(void)
00014 {
00015     refresh();
00016 #ifdef UNIX
00017     usleep(DELAY_AMOUNT_PC * 1000);
00018 #else
00019     delay_output(DELAY_AMOUNT_PC);
00020 #endif
00021 }
00022 //}}}
00023 
00024 //{{{
00025 #ifndef min
00026 int min(int a, int b)
00027 {
00028     if(a<b)
00029         return a;
00030     else
00031         return b;
00032 }
00033 #endif
00034 //}}}
00035 //{{{
00036 #ifndef max
00037 int max(int a, int b)
00038 {
00039     if(a<b)
00040         return b;
00041     else
00042         return a;
00043 }
00044 #endif
00045 //}}}
00046 
00047 //{{{
00048 void *malloc_throw(size_t size)
00049 {
00050     void *ret = malloc(size);
00051     if(ret == NULL)
00052         panic("Out of memory.");
00053     return ret;
00054 }
00055 //}}}
00056 //{{{
00057 void *calloc_throw(size_t N, size_t S)
00058 {
00059     void *ret = calloc(N, S);
00060     if(ret == NULL)
00061         panic("Out of memory.");
00062     return ret;
00063 }
00064 //}}}
00065 //{{{
00066 void *realloc_throw(void *ptr, size_t size)
00067 {
00068     void *ret = realloc(ptr, size);
00069     if(ret == NULL && size>0)
00070         panic("Out of memory.");
00071     return ret;
00072 }
00073 //}}}
00074 
00075 //{{{
00076 void Graph_ClrScr(void)
00077 {
00078     clrscr();
00079 }
00080 //}}}
00081 //{{{
00082 void Graph_DrawChar (short x, short y, char c)
00083 {
00084     mvaddch(y, x, c);
00085 }
00086 //}}}
00087 //{{{
00088 void Graph_DrawStr(short x, short y, const char *str)
00089 {
00090     mvaddstr(y, x, (char*)str);
00091 }
00092 //}}}
00093 //{{{
00094 void Graph_ClearRect(int left, int top, int right, int bottom)
00095 {
00096     int i, j;
00097     for(i=left; i<=right; i++)
00098     for(j=top; j<=bottom; j++) {
00099         mvaddch(j, i, ' ');
00100     }
00101 }
00102 //}}}
00103 
00104 //{{{
00105 void UI_Dialog_Default(const char *content)
00106 {
00107     UI_Dialog_Display(default_dialog_rect, content);
00108     UI_MF_clear();
00109     full_redraw();
00110 }
00111 //}}}
00112 //{{{
00113 void UI_Dialog_Display(rect r, const char *content)
00114 {
00115     coord pos = r.topleft;
00116     coord size = r.extent;
00117     clrscr();
00118     draw_string(content, NULL, pos.x+2, pos.y+2, size.x-4, size.y-4, 1);
00119     read_char();
00120 }
00121 //}}}
00122 
00123 //{{{
00124 short FontHeight(void)
00125 {
00126     return 1;
00127 }
00128 //}}}
00129 //{{{
00130 short FontWidth(unsigned char c)
00131 {
00132     return 1;
00133 }
00134 //}}}
00135 
00136 //{{{
00137 void panic(const char *fmt, ...)
00138 {
00139     const char *str;
00140     va_list varargs;
00141     va_start(varargs, fmt);
00142     str = vretprintf(fmt, varargs);
00143     va_end(varargs);
00144     
00145     sys_cleanup();
00146     clrscr();
00147     puts(str);
00148     fflush(stdout);
00149     getchar();
00150     cleanup();
00151     exit(1);
00152 }
00153 //}}}
00154 
00155 //{{{
00156 const char *get_keyname(short key)
00157 {
00158     return keyname(key);
00159 }
00160 //}}}

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