--- pmsdk/samples/bio/biopaint.c 2018/08/09 12:28:13 1.1.1.1 +++ pmsdk/samples/bio/biopaint.c 2018/08/09 12:28:34 1.1.1.2 @@ -1,9 +1,36 @@ +/* + biopaint.c - WM_PAINT processing and calendar conversion routines + + Created by Microsoft Corporation, 1989 +*/ +#define INCL_WIN +#define INCL_GPI +#include + +#include "bio.h" +#include +#include + +/* Read-only global variables */ +extern double Born; +extern long Day, SelectDay; +extern BOOL bBorn; +extern FONTMETRICS tmFontInfo; +extern int LinesPerPage; +extern RECTL rclClient; +extern SHORT cxDateField; + +/* Read-only static variables */ +static double Cycle[] = { 23.0, 28.0, 33.0 }; +static char cDayOfWeek[] = "MTWTFSS"; +extern LONG Color[]; + + + /* APPPaint() - Parent window WM_PAINT processing routine. * -* Created by Microsoft Corp., 1988 -* * Purpose: -* Routine to graph biorythm cycles and tabulate dates. +* Routine to graph biorhythm cycles and tabulate dates. * * Arguments: * hWnd - Handle of Window owning message @@ -11,26 +38,20 @@ * mp1 - Extra message-dependent info * mp2 - Extra message-dependent info * -* Return Value: -* void -* -* Globals (modified): -* none -* * Globals (static): * Cycle[] - Array holding period for phy/emot/int: 23,28,33 * cDayOfWeek[] - Array of chars holding first letter of days of week. * Color[] - Set of colored pens used to identify cycles. * * Globals (referenced): -* Born - Bithdate in julian days. Read from WIN.INI. -* SelectDay - Current day being tracked, day is highlighted. Is -* in units of days from birth date. Date of present -* day initially used in WM_CREATE. +* Born - Birthdate in julian days. Read from WIN.INI. +* SelectDay - Current day being tracked, day is highlighted. +* This is stored as the number of days from birthdate. +* Initialized to present day in WM_CREATE processing. * Day - Day number from date born which is top line being * displayed. Initially three days before SelectDay. * bBorn - Boolean indicating whether valid birtdate entered or -* rectClient - Size of client area defined by WM_SIZE message +* rclClient - Size of client area defined by WM_SIZE message * LinesPerPage - Number of system font lines on client area, defined * by WM_SIZE message handling * tmFontInfo - Text Metric structure defined during WM_CREATE @@ -39,33 +60,8 @@ * Tabulates dates and graphs cycles. On color displays, weekends * are written in red. The update rectangle is used to minimize * repaint time of affected client area. -* -* Limits: -* N/A */ - -#define INCL_WIN -#define INCL_GPI -#include - -#include "bio.h" -#include -#include - -/* Read-only global variables */ -extern double Born; -extern long Day, SelectDay; -extern BOOL bBorn; -extern FONTMETRICS tmFontInfo; -extern int LinesPerPage; -extern RECTL rectClient; - -/* Read-only static variables */ -static double Cycle[] = { 23.0, 28.0, 33.0 }; -static char cDayOfWeek[] = "MTWTFSS"; -extern LONG Color[]; - -VOID FAR PASCAL APPPaint( hWnd ) +VOID APIENTRY APPPaint( hWnd ) HWND hWnd; { HPS hPS; @@ -78,7 +74,8 @@ HWND hWnd; double day; RECTL rc, rcClip; int DayOfWeek; - HRGN hrgnClip; + HRGN hrgnClip; + POINTL ptlTextBox[5]; hPS = WinBeginPaint( hWnd, NULL, &rcClip ); @@ -87,43 +84,44 @@ HWND hWnd; WinFillRect( hPS, &rc, CLR_WHITE ); /* Label parts of table and graph. */ - ptl.y = rectClient.yTop - tmFontInfo.lMaxBaselineExt + /* Top line */ + ptl.y = rclClient.yTop - tmFontInfo.lMaxBaselineExt + /* Top line */ tmFontInfo.lMaxDescender; ptl.x = 0; - GpiCharStringAt( hPS, &ptl, 6L, (PCH)" DATE" ); - ptl.x = 11 * tmFontInfo.lAveCharWidth; + GpiCharStringAt( hPS, &ptl, 7L, (PCH)" DATE" ); + ptl.x = cxDateField + tmFontInfo.lAveCharWidth; GpiCharStringAt( hPS, &ptl, 3L, (PCH)"LOW" ); - ptl.x = rectClient.xRight - 5 * tmFontInfo.lAveCharWidth; + GpiQueryTextBox( hPS, 4L, "HIGH", TXTBOX_COUNT, ptlTextBox ); + ptl.x = rclClient.xRight - ptlTextBox[TXTBOX_CONCAT].x - tmFontInfo.lAveCharWidth; GpiCharStringAt( hPS, &ptl, 4L, (PCH)"HIGH" ); /* Underline labels from left to right across client area */ - ptl.y = rectClient.yTop - tmFontInfo.lMaxBaselineExt; + ptl.y = rclClient.yTop - tmFontInfo.lMaxBaselineExt; ptl.x = 0; GpiMove( hPS, &ptl ); - ptl.x = rectClient.xRight; + ptl.x = rclClient.xRight; GpiLine( hPS, &ptl ); /* Draw a vertical line separator between dates and cycles */ - ptl.y = rectClient.yTop; - ptl.x = 10 * tmFontInfo.lAveCharWidth; + ptl.y = rclClient.yTop; + ptl.x = cxDateField; GpiMove( hPS, &ptl ); - ptl.y = rectClient.yBottom; + ptl.y = rclClient.yBottom; GpiLine( hPS, &ptl ); /* Draw a dotted vertical center line to reference cycles */ GpiSetLineType( hPS, LINETYPE_DOT ); - ptl.x = (10 * tmFontInfo.lAveCharWidth + rectClient.xRight) / 2; + ptl.x = (cxDateField + rclClient.xRight) / 2; GpiMove( hPS, &ptl ); - ptl.y = rectClient.yTop; + ptl.y = rclClient.yTop; GpiLine( hPS, &ptl ); /* (Should not have to restore line type after EndPaint) */ GpiSetLineType( hPS, LINETYPE_DEFAULT ); /* Update only the range of lines which fall into update rectangle */ - start = (int)((rectClient.yTop - rcClip.yTop) / tmFontInfo.lMaxBaselineExt); + start = (int)((rclClient.yTop - rcClip.yTop) / tmFontInfo.lMaxBaselineExt); if (start<1) start = 1; - last = (int)((rectClient.yTop - rcClip.yBottom) / tmFontInfo.lMaxBaselineExt); + last = (int)((rclClient.yTop - rcClip.yBottom) / tmFontInfo.lMaxBaselineExt); if (last>(LinesPerPage-1)) last = LinesPerPage-1; @@ -131,12 +129,12 @@ HWND hWnd; each date affected. Start drawing one day before and after (outside clip rectangle) so that cycle lines will connect correctly with unaffected lines. */ - rcClip.yTop = rectClient.yTop - start*tmFontInfo.lMaxBaselineExt; + rcClip.yTop = rclClient.yTop - start*tmFontInfo.lMaxBaselineExt; start--; last++; - rcClip.yBottom = rectClient.yTop - last*tmFontInfo.lMaxBaselineExt + 1; + rcClip.yBottom = rclClient.yTop - last*tmFontInfo.lMaxBaselineExt + 1; hrgnClip = GpiCreateRegion( hPS, 1L, &rcClip ); - GpiSetClipRegion( hPS, hrgnClip ); + GpiSetClipRegion( hPS, hrgnClip, &hrgnClip ); /* List days and date */ for (y=start; y<=last; y++) { @@ -145,27 +143,29 @@ HWND hWnd; /* Get offset into days of the week initials array */ DayOfWeek = (int)((LONG)(Born+Day+y) % 7); /* Assemble each of the parts in a buffer */ - sprintf(szDay, "%c %02d-%02d-%02d", cDayOfWeek[DayOfWeek], + sprintf(szDay, " %02d-%02d-%02d", month, (int)day, year - (trunc4((double)year / 100)*100) ); /* If color available, draw weekends in red */ if (DayOfWeek > 4) GpiSetColor( hPS, CLR_RED ); ptl.x = 0; - ptl.y = rectClient.yTop - ((y+1)*tmFontInfo.lMaxBaselineExt - - tmFontInfo.lMaxDescender); - GpiCharStringAt( hPS, &ptl, 10L, (PCH)szDay ); + ptl.y = rclClient.yTop - ((y+1)*tmFontInfo.lMaxBaselineExt - + tmFontInfo.lMaxDescender); + GpiCharStringAt( hPS, &ptl, 1L, (PCH)&cDayOfWeek[DayOfWeek] ); + GpiQueryWidthTable( hPS, (LONG)'W', 1L, &ptl.x ); + GpiCharStringAt( hPS, &ptl, 9L, (PCH)szDay ); GpiSetColor( hPS, CLR_BLACK ); } /* Amplitude of sin wave is half client area minus space for dates */ - Amplitude = (int)((rectClient.xRight - 11 * tmFontInfo.lAveCharWidth) / 2); + Amplitude = (int)((rclClient.xRight - cxDateField - tmFontInfo.lAveCharWidth) >> 1); /* Move to right, make room for column of dates */ - offset = (int)(Amplitude + 11 * tmFontInfo.lAveCharWidth - 4); + offset = (int)(Amplitude + cxDateField + tmFontInfo.lAveCharWidth - (tmFontInfo.lAveCharWidth>>1)); for (i=0; i<3 && bBorn; i++ ) { GpiSetColor( hPS, Color[i] ); for (y=start; y<=last; y++) { ptl.x = (int)(sin( (y+Day-1)/Cycle[i]*2*3.14159 ) * Amplitude + offset); - ptl.y = rectClient.yTop - (y*tmFontInfo.lMaxBaselineExt + + ptl.y = rclClient.yTop - (y*tmFontInfo.lMaxBaselineExt + tmFontInfo.lMaxBaselineExt/2); if ((y+Day-1 > 0) && (y>start)) GpiLine( hPS, &ptl ); @@ -176,9 +176,9 @@ HWND hWnd; /* Draw highlight on selected day if visible. */ if ((SelectDay >= Day) && (SelectDay - Day < LinesPerPage - 1)) { - rc.xRight = rectClient.xRight; - rc.xLeft = rectClient.xLeft; - rc.yTop = rectClient.yTop - (int)(SelectDay - Day + 1) * tmFontInfo.lMaxBaselineExt; + rc.xRight = rclClient.xRight; + rc.xLeft = rclClient.xLeft; + rc.yTop = rclClient.yTop - (int)(SelectDay - Day + 1) * tmFontInfo.lMaxBaselineExt; rc.yBottom = rc.yTop - tmFontInfo.lMaxBaselineExt + 1; WinInvertRect( hPS, &rc ); } @@ -202,12 +202,6 @@ HWND hWnd; * Return Value: * double - Julian date converted * -* Globals (modified): -* none -* -* Globals (referenced): -* none -* * Description: * Convert Gregorian dates to Julian Days. Refer to Alamanac for * Computers (1978), p. B2, Naval Observatory Pub.