Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

textwin.c

Go to the documentation of this file.
00001 /*************************************************************************
00002 *   FILE: textwin.c
00003 * AUTHOR: CAL
00004 * DATE: 26 April 1993
00005 * PURPOSE:
00006 *   A Text Window is a pop-up window which is automatically sized
00007 *   to contain given text.
00008 **************************************************************************/
00009 
00010 #include <string.h>
00011 #include <stdlib.h>
00012 #include <assert.h>
00013 #include "textwin.h"
00014 
00015 
00016 TextWin::TextWin (int minxdim, int addy, int bc, int bkc,
00017     char **txt, int txtc)
00018 {
00019   MinXDim = minxdim;  AddY = addy;
00020   BorderColor = bc;
00021   BkColor = bkc;
00022   TextColor = txtc;
00023   Text = txt;
00024   CalcDim ();
00025 }
00026 
00027 
00028 TextWin::TextWin (int minxdim, int addy, int bc, int bkc, char* t, int tc,
00029       char **txt, int txtc)
00030 {
00031   MinXDim = minxdim;  AddY = addy;
00032   BorderColor = bc;
00033   BkColor = bkc;
00034   TitleColor = tc;
00035   TextColor = txtc;
00036   Title = new char [strlen (t)];
00037   assert (Title != 0);
00038   strcpy (Title, t);
00039   Text = txt;
00040   CalcDim ();
00041 }
00042 
00043 
00044 void TextWin::CalcDim (void)
00045 {
00046   Viewport temp;
00047   temp.SetTextStyle (TextWinFont, HORIZ_DIR, TextWinFontSize);
00048   THeight = temp.TextHeight ("My") + 4;
00049   int nlines;
00050 
00051   XDim = MinXDim;
00052   for (nlines=0; strlen (Text [nlines]); nlines++)
00053   {
00054     XDim = max (XDim, temp.TextWidth (Text [nlines]) + 10);
00055     YDim += THeight;
00056   }
00057   if (Title)
00058     YDim += TitleWidth + 1;
00059   YDim += AddY + THeight + (BorderWidth*2) + 2;
00060   XDim += (BorderWidth*2) + 10;
00061 }
00062 
00063 
00064 void TextWin::Draw (void)
00065 {
00066   if (!Drawn)
00067   {
00068     assert (Disp != NULL);
00069     Disp->FastDraw ();
00070     PrepScreen ();
00071     DrawBorder ();
00072     if (TitleD)
00073       DrawTitle ();
00074     ClientD->Clear ();
00075     ClientD->SetColor (TextColor);
00076     ClientD->SetTextStyle (TextWinFont, HORIZ_DIR, TextWinFontSize);
00077     ClientD->SetTextJustify (CENTER_TEXT, TOP_TEXT);
00078     ClientD->MoveTo (ClientD->GetMaxX()/2, THeight/2);
00079     for (int i=0; strlen (Text [i]); i++)
00080     {
00081       ClientD->OutText (Text [i]);
00082       ClientD->MoveRel (0, THeight);
00083     }
00084     ClientD->Draw ();
00085     Disp->Done ();
00086     Drawn = True;
00087   }
00088 }

Generated on Sun Jul 6 23:07:16 2003 for Scotland Yard by doxygen1.2.15