00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "window.h"
00014 #include <alloc.h>
00015 #include <assert.h>
00016 #include <stdlib.h>
00017 #include <string.h>
00018
00019
00020
00021
00022
00023
00024 Window::Window (void)
00025 {
00026 XDim = YDim = 0;
00027 CliX1 = CliY1 = CliX2 = CliY2 = 0;
00028 TX1 = TY1 = TX2 = TY2 = 0;
00029 BorderColor = BkColor = 0;
00030 TitleColor = 0;
00031 Title = NULL;
00032 ClientD = TitleD = NULL;
00033 Drawn = False;
00034 }
00035
00036 Window::Window (int dx, int dy, int bc, int bkc)
00037 {
00038 XDim = dx; YDim = dy;
00039 CliX1 = CliY1 = CliX2 = CliY2 = 0;
00040 TX1 = TY1 = TX2 = TY2 = 0;
00041 BorderColor = bc;
00042 BkColor = bkc;
00043 TitleColor = 0;
00044 Title = NULL;
00045 ClientD = TitleD = NULL;
00046 Drawn = False;
00047 }
00048
00049 Window::Window (int dx, int dy, int bc, int bkc, char* t, int tc)
00050 {
00051 XDim = dx; YDim = dy;
00052 CliX1 = CliY1 = CliX2 = CliY2 = 0;
00053 TX1 = TY1 = TX2 = TY2 = 0;
00054 BorderColor = bc;
00055 BkColor = bkc;
00056 TitleColor = tc;
00057 Title = new char [strlen (t)+1];
00058 assert (Title != 0);
00059 strcpy (Title, t);
00060 ClientD = TitleD = NULL;
00061 Drawn = False;
00062 }
00063
00064
00065
00066
00067
00068
00069 Window::~Window ()
00070 {
00071 Erase ();
00072 delete Title;
00073 delete ClientD;
00074 delete TitleD;
00075 }
00076
00077
00078
00079
00080
00081
00082 void Window::CalcBorder (void)
00083 {
00084 CliX1 += X + BorderWidth+1;
00085 CliY1 += Y + BorderWidth+1;
00086 CliX2 += X + XDim - BorderWidth - 1;
00087 CliY2 += Y + YDim - BorderWidth - 1;
00088 }
00089
00090 void Window::CalcTitle (void)
00091 {
00092 TX1 += CliX1;
00093 TY1 += CliY1;
00094 TX2 += CliX2;
00095 TY2 += TY1 + TitleWidth;
00096 CliY1 += TitleWidth + 2;
00097 }
00098
00099
00100
00101
00102
00103
00104 void Window::Init (Display *d, int x, int y)
00105 {
00106 Disp = d;
00107 X = x; Y = y;
00108
00109 CalcBorder ();
00110 if (Title)
00111 {
00112 CalcTitle ();
00113 TitleD = new Display (Disp, TX1, TY1, TX2, TY2);
00114 assert (TitleD != 0);
00115 TitleD->SetBkColor (BorderColor);
00116 TitleD->SetTextJustify (CENTER_TEXT, TOP_TEXT);
00117 TitleD->SetTextStyle (TitleFont, HORIZ_DIR, TitleFontSize);
00118 TitleD->SetColor (TitleColor);
00119 }
00120 ClientD = new Display (Disp, CliX1, CliY1, CliX2, CliY2);
00121 assert (ClientD != 0);
00122 ClientD->SetBkColor (BkColor);
00123 }
00124
00125
00126
00127
00128
00129
00130 void Window::DrawBorder (void)
00131 {
00132 Disp->SetLineStyle (SOLID_LINE, 1, 1);
00133 Disp->SetColor (BorderColor);
00134 for (int i=0; i<BorderWidth; i++)
00135 Disp->Rectangle (X+i, Y+i, X+XDim-i, Y+YDim-i);
00136 Disp->SetColor (BLACK);
00137 Disp->Rectangle (X+BorderWidth, Y+BorderWidth,
00138 X+XDim-BorderWidth, Y+YDim-BorderWidth);
00139 }
00140
00141
00142 void Window::DrawTitle (void)
00143 {
00144 Disp->SetColor (BLACK);
00145 Disp->Line (TX1, TY2+1, TX2, TY2+1);
00146 TitleD->Clear ();
00147 TitleD->OutTextXY (TitleD->GetMaxX()/2, 0, Title);
00148 }
00149
00150
00151 void Window::Draw (void)
00152 {
00153 if (!Drawn)
00154 {
00155 assert (Disp != NULL);
00156 Disp->FastDraw ();
00157 PrepScreen ();
00158 DrawBorder ();
00159 if (TitleD)
00160 DrawTitle ();
00161 ClientD->Clear ();
00162 ClientD->Draw ();
00163 Disp->Done ();
00164 Drawn = True;
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173 void Window::Erase (void)
00174 {
00175 if (Drawn)
00176 {
00177 assert (Disp != NULL);
00178 ClientD->Erase ();
00179 Disp->SetFillStyle (SOLID_FILL, Disp->GetBkColor());
00180 Disp->Bar (X, Y, X+XDim, Y+YDim);
00181 Drawn = False;
00182 }
00183 }
00184
00185
00186
00187
00188
00189
00190 Message Window::Dispatch (Message& msg)
00191 {
00192 if (ClientD)
00193 return ClientD->Dispatch (msg);
00194 else
00195 return NullMsg;
00196 }
00197