00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rFont.h"
00029 #include "tSysTime.h"
00030 #include "tConfiguration.h"
00031 #include "rConsole.h"
00032 #include "rScreen.h"
00033 #include <iostream>
00034
00035
00036 rConsole::rConsole()
00037 :currentTop(0),currentIn(0),
00038 lastCustomTimeout(-20),height(8),timeout(2),
00039 fullscreen(0),autoDisplayAtSwap(1),
00040 autoDisplayAtNewline(0){
00041 RegisterBetterConsole(this);
00042 }
00043
00044 static int sr_rows = 5;
00045 static tConfItem<int> sr_rowsConf("CONSOLE_ROWS",sr_rows);
00046
00047 static int sr_maxRows = 19;
00048 static tConfItem<int> sr_maxRowsConf("CONSOLE_ROWS_MAX",sr_maxRows);
00049
00050 int rConsole::MaxHeight(){
00051 int x=int(1.7/rCHEIGHT_CON)-1;;
00052 if (x>sr_maxRows)
00053 return sr_maxRows;
00054 else
00055 return x;
00056 }
00057
00058 int rConsole::Height(){
00059 if (fullscreen)
00060 return MaxHeight();
00061 else if (rSmallConsoleCallback::SmallColsole())
00062 return sr_rows;
00063 else
00064 return height > sr_rows ? height : sr_rows;
00065
00066 }
00067 REAL rConsole::Timeout(){
00068 if (fullscreen)
00069 return(100000000.0);
00070 else
00071 return timeout;
00072 }
00073
00074
00075 void rConsole::SetHeight(int h,bool stop_scroll){
00076 height=h;
00077 if (stop_scroll)
00078 lastCustomTimeout=tSysTimeFloat()-30;
00079 }
00080
00081 void rConsole::SetTimeout(REAL to){timeout=to;}
00082
00083
00084
00085
00086
00087
00088 #define MAXBACK 300
00089 #define BACKEXTRA 100
00090
00091
00092 REAL rCWIDTH_CON=REAL(16/640.0);
00093 REAL rCHEIGHT_CON=REAL(32/480.0);
00094
00095
00096
00097 tConsole & rConsole::DoPrint(const tString &s){
00098 bool print_to_stdout=false;
00099 #ifdef DEBUG
00100 print_to_stdout=true;
00101 #endif
00102 bool swap = false;
00103
00104 if (!sr_screen)
00105 print_to_stdout=true;
00106 if (print_to_stdout)
00107 {
00108 std::cout << tColoredString::RemoveColors(s);
00109 std::cout.flush();
00110 }
00111
00112 if (sr_screen){
00113 const char *c=s;
00114 while (*c!=0){
00115 lines[currentIn] << *c;
00116 if (*c=='\n'){
00117 if (currentIn<=currentTop+1)
00118 lastTimeout=tSysTimeFloat()+4;
00119 currentIn++;
00120 if (autoDisplayAtNewline && !rNoAutoDisplayAtNewlineCallback::NoAutoDisplayAtNewline() && (sr_textOut ||
00121 rForceTextCallback::ForceText()))
00122 swap = true;
00123
00124 if (currentIn >= MAXBACK+BACKEXTRA){
00125 for(int i=0;i<MAXBACK;i++)
00126 lines[i]=lines[i+BACKEXTRA];
00127
00128 for(int j=lines.Len()-1;j>=MAXBACK;j--)
00129 lines[j].Clear();
00130
00131 currentIn-=BACKEXTRA;
00132 currentTop-=BACKEXTRA;
00133 if (currentTop<0)
00134 currentTop=0;
00135 }
00136 }
00137 c++;
00138 }
00139
00140 if (rSmallConsoleCallback::SmallColsole() || lastCustomTimeout<tSysTimeFloat()-15)
00141 while ((currentIn-currentTop) > Height())
00142 currentTop++;
00143 }
00144
00145 if (swap)
00146 DisplayAtNewline();
00147
00148 return *this;
00149 }
00150
00151 void rConsole::Scroll(int dir){
00152 rCenterDisplayCallback::CenterDisplay();
00153
00154 currentTop+=dir*10;
00155 lastCustomTimeout=tSysTimeFloat();
00156 if (currentTop<0)
00157 currentTop=0;
00158
00159 if (currentTop>currentIn-10)
00160 lastCustomTimeout=tSysTimeFloat()-10;
00161
00162 if (currentTop>currentIn){
00163 currentTop=currentIn;
00164 lastCustomTimeout=tSysTimeFloat()-20;
00165 }
00166 }
00167
00168 tString rConsole::ColorString(REAL r, REAL g, REAL b) const{
00169 tColoredString ret;
00170 ret << tColoredString::ColorString(r,g,b);
00171 return ret;
00172 }
00173
00174 rConsole sr_con;
00175
00176
00177
00178 static tCallbackOr *tCallbackOr_anchor;
00179
00180 rForceTextCallback::rForceTextCallback(BOOLRETFUNC *f)
00181 :tCallbackOr(tCallbackOr_anchor, f){}
00182
00183 bool rForceTextCallback::ForceText(){
00184 return Exec(tCallbackOr_anchor);
00185 }
00186
00187 static tCallbackOr *SmallColsole_anchor;
00188
00189 rSmallConsoleCallback::rSmallConsoleCallback(BOOLRETFUNC *f)
00190 :tCallbackOr(SmallColsole_anchor, f){}
00191
00192 bool rSmallConsoleCallback::SmallColsole(){
00193 return Exec(SmallColsole_anchor);
00194 }
00195
00196
00197 static tCallback *CenterDisplay_anchor;
00198
00199 rCenterDisplayCallback::rCenterDisplayCallback(AA_VOIDFUNC *f)
00200 :tCallback(CenterDisplay_anchor, f){}
00201
00202 void rCenterDisplayCallback::CenterDisplay(){
00203 Exec(CenterDisplay_anchor);
00204 }
00205
00206 static tCallbackOr *NoAutoDisplayAtNewline_anchor;
00207
00208 rNoAutoDisplayAtNewlineCallback::rNoAutoDisplayAtNewlineCallback(BOOLRETFUNC *f)
00209 :tCallbackOr(NoAutoDisplayAtNewline_anchor, f){}
00210
00211 bool rNoAutoDisplayAtNewlineCallback::NoAutoDisplayAtNewline(){
00212 return Exec(NoAutoDisplayAtNewline_anchor);
00213 }
00214
00215
00216
00217
00218