/******************************************************************************/
/*                                                                            */
/*  MAINWIND - Paint routine for main window                                  */
/*                                                                            */
/******************************************************************************/

#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <new.h>
#include <float.h>

#include "const.h"
#include "classes.h"
#include "extern.h"
#include "funcdefs.h"
#include "julia.rh"

void paint_main_window ( HWND hWnd )
{
   int n_lines ;
   int font_height ;
   HDC hdc ;
   RECT rect ;
   PAINTSTRUCT ps ;
   LOGFONT lf ;
   HFONT old_font, this_font ;
   HPEN old_pen, pen ;
   HBRUSH old_brush, brush ;
   LOGBRUSH logbrush ;

   if (dib != NULL) {
      dib->draw ( hWnd , 0 ) ;
      return ;
      }

   hdc = BeginPaint ( hWnd , &ps ) ;
   GetClientRect ( hWnd , &rect ) ;
   SetMapMode ( hdc , MM_TEXT ) ;
   SetROP2 ( hdc , R2_COPYPEN ) ;
   SetBkMode ( hdc , OPAQUE ) ;
   SetTextAlign ( hdc , TA_TOP | TA_LEFT ) ;
   SetBkColor ( hdc , RGB ( 0 , 0 , 0 ) ) ;
   SetTextColor ( hdc , RGB ( 255 , 255 , 255 ) ) ;

/*
   Initialize for creating fonts
*/

   lf.lfWidth = 0 ;
   lf.lfEscapement = 0 ;
   lf.lfOrientation = 0 ;
   lf.lfWeight = FW_NORMAL ;
   lf.lfItalic = 0 ;
   lf.lfUnderline = 0 ;
   lf.lfStrikeOut = 0 ;
   lf.lfCharSet = ANSI_CHARSET ;
   lf.lfOutPrecision = OUT_DEFAULT_PRECIS ;
   lf.lfClipPrecision = CLIP_DEFAULT_PRECIS ;
   lf.lfQuality = DEFAULT_QUALITY ;
   strcpy_s ( lf.lfFaceName , "" ) ;

/*
   Clear background
*/

   pen = (HPEN) CreatePen ( PS_SOLID , 1 , RGB ( 0 , 0 , 0 ) ) ;
   old_pen = (HPEN) SelectObject ( hdc , pen ) ;

   logbrush.lbStyle = BS_SOLID ;
   logbrush.lbHatch = 0 ;
   logbrush.lbColor = GetNearestColor ( hdc , RGB ( 0 , 0 , 0 )) ;
   brush = (HBRUSH) CreateBrushIndirect ( &logbrush ) ;
   old_brush = (HBRUSH) SelectObject ( hdc , brush ) ;

   Rectangle ( hdc , 0 , 0 , rect.right , rect.bottom ) ;

   SelectObject ( hdc , old_pen ) ;
   SelectObject ( hdc , old_brush ) ;
   DeleteObject ( pen ) ;
   DeleteObject ( brush ) ;

   n_lines = 1 ;
   font_height = (rect.bottom - rect.top) / n_lines ;
   if (font_height < 10)
      font_height = 10 ;
   if (font_height > 24)
      font_height = 24 ;
   lf.lfHeight = font_height ;
   lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS ;
   this_font = CreateFontIndirect ( &lf ) ;
   old_font = (HFONT) SelectObject ( hdc , this_font ) ;

#if 0
   xpos = 2 ;
   ypos = (n_lines - 1) * (font_height + 2) + 1 ;
   if (ypos > rect.bottom - font_height - 1)
      ypos = rect.bottom - font_height - 1 ;
   TextOut ( hdc , xpos , ypos , "Message" , strlen("Message") ) ;
#endif

   SelectObject ( hdc , old_font ) ;
   DeleteObject ( this_font ) ;

   EndPaint ( hWnd , &ps ) ;
   return ;
}
