/* * Paint - When the mouse button is down, we want to paint on the * drawing area. */ void Paint( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, int mousebutton ) { WPI_POINT s_pt; WPI_POINT e_pt; WPI_PARAM2 lparam; WPI_LINEDDAPROC fp; s_pt.x = MAKELOGPTX(start_pt->x); s_pt.y = MAKELOGPTY(start_pt->y); e_pt.x = MAKELOGPTX(end_pt->x); e_pt.y = MAKELOGPTY(end_pt->y); CheckBounds( hwnd, &s_pt ); CheckBounds( hwnd, &e_pt ); s_pt.x = s_pt.x / pointSize.x; s_pt.y = s_pt.y / pointSize.y; e_pt.x = e_pt.x / pointSize.x; e_pt.y = e_pt.y / pointSize.y; currentMouseButton = mousebutton; SET_HWND_PARAM2( lparam, hwnd ); fp = _wpi_makelineddaprocinstance( drawPt, Instance ); _wpi_linedda( s_pt.x, s_pt.y, e_pt.x, e_pt.y, (WPI_LINEDDAPROC)fp, lparam); _wpi_freeprocinstance( fp ); DrawSinglePoint( hwnd, end_pt, mousebutton ); memcpy(start_pt, end_pt, sizeof(WPI_POINT)); } /* Paint */
/* * OutlineLine - outline the line before it is drawn */ void OutlineLine( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, WPI_POINT *prev_pt, BOOL firsttime ) { WPI_POINT startpt; WPI_POINT endpt; WPI_POINT prevpt; int prevROP2; HPEN holdpen; HPEN hwhitepen; WPI_PRES pres; CheckBounds( hwnd, start_pt ); CheckBounds( hwnd, end_pt ); startpt.x = MAKELOGPTX( start_pt->x ) + pointSize.x / 2; startpt.y = MAKELOGPTY( start_pt->y ) + pointSize.y / 2; endpt.x = MAKELOGPTX( end_pt->x ) + pointSize.x / 2; endpt.y = MAKELOGPTY( end_pt->y ) + pointSize.y / 2; pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); holdpen = _wpi_selectobject( pres, hwhitepen ); prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); if( !firsttime ) { CheckBounds( hwnd, prev_pt ); prevpt.x = MAKELOGPTX( prev_pt->x ) + pointSize.x / 2; prevpt.y = MAKELOGPTY( prev_pt->y ) + pointSize.y / 2; _wpi_movetoex( pres, &startpt, NULL ); _wpi_lineto( pres, &prevpt ); } _wpi_movetoex( pres, &startpt, NULL ); _wpi_lineto( pres, &endpt ); _wpi_setrop2( pres, prevROP2 ); _wpi_selectobject( pres, holdpen ); _wpi_deleteobject( hwhitepen ); _wpi_releasepres( hwnd, pres ); } /* OutlineLine */
/* * OutlineRegion - displays the potential region (rectangle or ellipse) * on the draw area. */ void OutlineRegion( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, WPI_POINT *prev_pt, BOOL firsttime ) { WPI_POINT topleft; WPI_POINT bottomright; WPI_POINT prevtl; // previous top left point WPI_POINT prevbr; // previous bottom right point int prevROP2; HBRUSH hbrush; HBRUSH holdbrush; HPEN hwhitepen; HPEN holdpen; int temp; WPI_PRES pres; CheckBounds( hwnd, start_pt ); CheckBounds( hwnd, end_pt ); CheckBounds( hwnd, prev_pt ); _wpi_setpoint(&topleft, MAKELOGPTX(start_pt->x), MAKELOGPTY(start_pt->y)); _wpi_setpoint(&bottomright, MAKELOGPTX(end_pt->x), MAKELOGPTY(end_pt->y)); if (topleft.x > bottomright.x) { temp = (short)bottomright.x; bottomright.x = topleft.x + pointSize.x; topleft.x = temp; } else { bottomright.x += pointSize.x; } if (topleft.y > bottomright.y) { temp = (int)bottomright.y; bottomright.y = topleft.y + pointSize.y; topleft.y = temp; } else { bottomright.y += pointSize.y; } prevtl.x = MAKELOGPTX( start_pt->x ); prevtl.y = MAKELOGPTY( start_pt->y ); prevbr.x = MAKELOGPTX( prev_pt->x ); prevbr.y = MAKELOGPTY( prev_pt->y ); if (prevtl.x > prevbr.x) { temp = (int)prevbr.x; prevbr.x = prevtl.x + pointSize.x; prevtl.x = temp; } else { prevbr.x += pointSize.x; } if (prevtl.y > prevbr.y) { temp = (int)prevbr.y; prevbr.y = prevtl.y + pointSize.y; prevtl.y = temp; } else { prevbr.y += pointSize.y; } ++prevtl.x; ++prevtl.y; ++topleft.x; ++topleft.y; pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); hbrush = _wpi_createsolidbrush( BLACK ); hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); holdbrush = _wpi_selectobject( pres, hbrush ); holdpen = _wpi_selectobject( pres, hwhitepen ); if (!firsttime) { if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) { _wpi_ellipse( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y ); } else { _wpi_rectangle( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y ); } } if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) { _wpi_ellipse( pres, topleft.x, topleft.y, bottomright.x, bottomright.y ); } else { _wpi_rectangle( pres, topleft.x, topleft.y, bottomright.x, bottomright.y ); } _wpi_selectobject( pres, holdpen ); _wpi_selectobject( pres, holdbrush ); _wpi_deleteobject( hwhitepen ); _wpi_deleteobject( hbrush ); _wpi_setrop2( pres, prevROP2 ); _wpi_releasepres( hwnd, pres ); } /* OutlineRegion */
/* * OutlineClip - displays the potential region to be clipped to the clip board */ void OutlineClip( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, WPI_POINT *prev_pt, BOOL firsttime ) { WPI_RECT newpos; WPI_RECT oldpos; short temp; WPI_PRES pres; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; CheckBounds( hwnd, start_pt ); CheckBounds( hwnd, end_pt ); CheckBounds( hwnd, prev_pt ); left = (IMGED_DIM)MAKELOGPTX(start_pt->x); top = (IMGED_DIM)MAKELOGPTY(start_pt->y); right = (IMGED_DIM)MAKELOGPTX(end_pt->x); bottom = (IMGED_DIM)MAKELOGPTY(end_pt->y); if (left > right) { temp = right; right = left + pointSize.x; left = temp; } else { right += pointSize.x; } if (top > bottom) { temp = bottom; bottom = top + pointSize.y; top = temp; } else { bottom += pointSize.y; } _wpi_setrectvalues( &newpos, left, top, right, bottom ); left = (IMGED_DIM)MAKELOGPTX( start_pt->x ); top = (IMGED_DIM)MAKELOGPTY( start_pt->y ); right = (IMGED_DIM)MAKELOGPTX( prev_pt->x ); bottom = (IMGED_DIM)MAKELOGPTY( prev_pt->y ); if (left > right) { temp = right; right = left + pointSize.x; left = temp; } else { right += pointSize.x; } if (top > bottom) { temp = bottom; bottom = top + pointSize.y; top = temp; } else { bottom += pointSize.y; } _wpi_setrectvalues( &oldpos, left, top, right, bottom ); pres = _wpi_getpres( hwnd ); OutlineRectangle( firsttime, pres, &oldpos, &newpos ); _wpi_releasepres( hwnd, pres ); } /* OutlineClip */