void DisplayStreamInfos(HWND hW) { HWND hWS=GetDlgItem(hW,IDC_SAREA); HDC hdc;RECT r;HBRUSH hBO;int ch,dy,i,j,id; //----------------------------------------------------// GetClientRect(hWS,&r); // get size of stream display hdc=GetDC(hWS); // device context r.right--; // leave the right border intact ScrollDC(hdc,-1,0,&r,&r,NULL,NULL); // scroll one pixel to the left //----------------------------------------------------// hBO = (HBRUSH) SelectObject(hdc,hBStream[0]); // clean the right border PatBlt(hdc,r.right-1,0,1,r.bottom,PATCOPY); //----------------------------------------------------// dy=r.bottom/MAXCHAN; // size of one channel area for(ch=0;ch<MAXCHAN;ch++) // loop the channels { if(s_chan[ch].iIrqDone) { s_chan[ch].iIrqDone=0; PatBlt(hdc,r.right-1,ch*r.bottom/MAXCHAN, 1,dy,BLACKNESS); continue; } if(s_chan[ch].bOn) // channel is on? { j=s_chan[ch].sval;if(j<0) j=-j; // -> get one channel data (-32k ... 32k) j=(dy*j)/32768; if(j==0) j=1; // -> adjust to display coords i=(dy/2)+(ch*r.bottom/MAXCHAN)-j/2; // -> position where to paint it if (s_chan[ch].iMute) id=1; // -> get color id else if(s_chan[ch].bNoise) id=2; else if(s_chan[ch].bFMod==2) id=3; else if(s_chan[ch].bFMod==1) id=4; else id=5; SelectObject(hdc,hBStream[id]); // -> select the brush PatBlt(hdc,r.right-1,i,1,j,PATCOPY); // -> paint the value line } if(ch) SetPixel(hdc,r.right-1, // -> not first line? ch*r.bottom/MAXCHAN,RGB(0,0,0)); // --> draw the line (one dot scrolled to the left) } //----------------------------------------------------// SelectObject(hdc,hBO); // repair brush ReleaseDC(hWS,hdc); // release context }
/* PA: new routine to scroll part of the content of a window. It is assumed that scrolling happens in one direction only (dx<>0 && dy==0 || dx==0 && dy<>0). The result rect (oleft,otop,oright,obottom) is the bounding box of the update area that remains to be updated. If all are zero, then nothing needs to be updated. */ void WinScrollRectangle (int left, int top, int right, int bottom, int dx, int dy, OSPictContext context, int * oleft, int * otop, int * oright, int * obottom ) { RECT scrollRect; HRGN hrgnUpdate, hrgnRect; scrollRect.left = left; scrollRect.top = top; scrollRect.right = right; scrollRect.bottom = bottom; if (dx<0) { hrgnRect = CreateRectRgn (right+dx-1,top-1,right+1,bottom+1); } else if (dx>0) { hrgnRect = CreateRectRgn (left-1,top-1,left+dx+1,bottom+1); } else if (dy<0) { hrgnRect = CreateRectRgn (left-1,bottom+dy-1,right+1,bottom+1); } else if (dy>0) { hrgnRect = CreateRectRgn (left-1,top-1,right+1,top+dy+1); } else { hrgnRect = CreateRectRgn (0,0,0,0); } hrgnUpdate = CreateRectRgn (0,0,1,1); if (!ScrollDC (context->hDC, dx,dy, &scrollRect, &scrollRect, hrgnUpdate, NULL)) { rMessageBox (NULL,MB_APPLMODAL,"WinScrollRectangle","ScrollDC failed"); } else { if (CombineRgn (hrgnUpdate, hrgnUpdate, hrgnRect, RGN_DIFF) == NULLREGION) { *oleft = 0; *otop = 0; *oright = 0; *obottom = 0; } else { RECT box; GetRgnBox (hrgnUpdate,&box); *oleft = box.left; *otop = box.top; *oright = box.right; *obottom = box.bottom; } } DeleteObject (hrgnUpdate); DeleteObject (hrgnRect); } /* WinScrollRectangle */
void Test_ScrollDC() { HWND hWnd, hWnd2; HDC hDC; HRGN hrgn; RECT rcClip; int iResult; /* Create a window */ hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 100, 100, NULL, NULL, 0, 0); UpdateWindow(hWnd); hDC = GetDC(hWnd); /* Test that no update region is there */ hrgn = CreateRectRgn(0,0,0,0); iResult = GetUpdateRgn(hWnd, hrgn, FALSE); ok (iResult == NULLREGION, "Expected NULLREGION, got %d\n", iResult); /* Test normal scrolling */ ok(ScrollDC(hDC, 0, 0, NULL, NULL, hrgn, NULL) == TRUE, "ScrollDC failed\n"); /* Scroll with invalid update region */ DeleteObject(hrgn); ok(ScrollDC(hDC, 50, 0, NULL, NULL, (HRGN)0x12345678, NULL) == FALSE, "ScrollDC successed\n"); ok(ScrollDC(hDC, 50, 0, NULL, NULL, hrgn, NULL) == FALSE, "ScrollDC successed\n"); hrgn = CreateRectRgn(0,0,0,0); iResult = GetUpdateRgn(hWnd, hrgn, FALSE); ok(iResult == NULLREGION, "Expected NULLREGION, got %d\n", iResult); /* Scroll with invalid update rect pointer */ ok(ScrollDC(hDC, 50, 0, NULL, NULL, NULL, (PRECT)1) == FALSE, "ScrollDC failed\n"); iResult = GetUpdateRgn(hWnd, hrgn, FALSE); ok(iResult == NULLREGION, "Expected NULLREGION, got %d\n", iResult); /* Scroll with a clip rect */ rcClip.left = 50; rcClip.top = 0; rcClip.right = 100; rcClip.bottom = 100; ok(ScrollDC(hDC, 50, 0, NULL, &rcClip, hrgn, NULL) == TRUE, "ScrollDC failed\n"); iResult = GetUpdateRgn(hWnd, hrgn, FALSE); ok(iResult == NULLREGION, "Expected NULLREGION, got %d\n", iResult); /* Scroll with a clip rect */ rcClip.left = 50; rcClip.top = 0; rcClip.right = 100; rcClip.bottom = 100; ok(ScrollDC(hDC, 50, 50, NULL, &rcClip, hrgn, NULL) == TRUE, "ScrollDC failed\n"); iResult = GetUpdateRgn(hWnd, hrgn, FALSE); ok(iResult == NULLREGION, "Expected NULLREGION, got %d\n", iResult); /* Overlap with another window */ hWnd2 = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 30, 160, 100, 100, NULL, NULL, 0, 0); UpdateWindow(hWnd2); /* Cleanup */ ReleaseDC(hWnd, hDC); DestroyWindow(hWnd); DestroyWindow(hWnd2); }
LOCAL void fb_copyarea(WINDISPLAY *mod, struct TVRequest *req) { WINWINDOW *win = req->tvr_Op.CopyArea.Window; struct THook *exposehook = (struct THook *) TGetTag(req->tvr_Op.CopyArea.Tags, TVisual_ExposeHook, TNULL); TINT *sr = req->tvr_Op.CopyArea.Rect; TINT dx = req->tvr_Op.CopyArea.DestX - sr[0]; TINT dy = req->tvr_Op.CopyArea.DestY - sr[1]; RECT r; r.left = sr[4]; r.top = sr[5]; r.right = sr[4] + sr[2]; r.bottom = sr[5] + sr[3]; if (exposehook) { RGNDATAHEADER *rdh = (RGNDATAHEADER *) win->fbv_RegionData; RECT *rd = (RECT *) (rdh + 1); HRGN updateregion = CreateRectRgn(0, 0, 0, 0); ScrollDC(win->fbv_HDC, dx, dy, &r, &r, updateregion, NULL); if (GetRegionData(updateregion, 1024, (LPRGNDATA) rdh)) { TUINT i; for (i = 0; i < rdh->nCount; ++i) TCallHookPkt(exposehook, win, (TTAG) (rd + i)); } else { TDBPRINTF(TDB_WARN,("Regiondata buffer too small\n")); InvalidateRgn(win->fbv_HWnd, updateregion, FALSE); } DeleteObject(updateregion); } else ScrollDC(win->fbv_HDC, dx, dy, &r, &r, NULL, NULL); win->fbv_Dirty = TTRUE; }
/************************************************************************* * ScrollDC (USER.221) */ BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect, const RECT16 *cliprc, HRGN16 hrgnUpdate, LPRECT16 rcUpdate ) { RECT rect32, clipRect32, rcUpdate32; BOOL16 ret; if (rect) CONV_RECT16TO32( rect, &rect32 ); if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 ); ret = ScrollDC( hdc, dx, dy, rect ? &rect32 : NULL, cliprc ? &clipRect32 : NULL, hrgnUpdate, &rcUpdate32 ); if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate ); return ret; }
void WinCopyRectangle (int left, int top, int right, int bottom, int dx, int dy, OSPictContext context) { RECT scrollRect; scrollRect.left = left; scrollRect.top = top; scrollRect.right = right; scrollRect.bottom = bottom; if (!ScrollDC (context->hDC, dx,dy, &scrollRect, &scrollRect, NULL, NULL)) { rMessageBox (NULL,MB_APPLMODAL,"WinCopyRectangle","ScrollDC failed"); } } /* WinCopyRectangle */
CLIPPER WBrwScrl( PARAMS ) // ( hWnd, nRows, hFont, nLineStyle, hDC ) #endif { HWND hWnd = ( HWND ) _parnl( 1 ); int wRows = _parni( 2 ); HFONT hFont = ( HFONT ) _parnl( 3 ); HFONT hOldFont; HDC hDC = ( HDC ) _parnl( 5 ); // = GetDC( hWnd ); RECT rct; WORD nStyle = _parni( 4 ); if( hFont ) hOldFont = SelectObject( hDC, hFont ); GetClientRect( hWnd, &rct ); if ( bDrawHeaders ) rct.top += wHeaderHeight+1 ; // Defino Bottom de Area del Scroll rct.bottom = ( WBrwRowsC( hWnd, hDC, hFont ) * (wLineHeight+1) ) + ( bDrawHeaders ? wHeaderHeight+1 : 0 ) ; // Si es un estilo sin separadores horizontales, pintar uno mas arriba // CeSoTech para que que bien completa el area !!! // El Area Scroll deber entonces no tomar el separator (forma parte de ant) if ( !(nStyle == 0 || nStyle == 5 || nStyle == 6 || nStyle == 9 || nStyle == 10 || nStyle == 3 ) ) rct.bottom++; // Debe tomarse dado que no pinta celda 1 una mas arriba // ScrollWindowEx( hWnd, 0, -( (wLineHeight+1) * wRows ), 0, &rct, 0, 0, 0 ); ScrollDC( hDC, 0, -( (wLineHeight+1) * wRows ), 0, &rct, 0, 0 ); if( hFont ) SelectObject( hDC, hOldFont ); // ReleaseDC( hWnd, hDC ); }
/** * @brief Scroll vertically a section of the screen. * @note Optional. * @note If x,y + cx,cy is off the screen, the result is undefined. * @note If lines is >= cy, it is equivelent to a area fill with bgcolor. * * @param[in] x, y The start of the area to be scrolled * @param[in] cx, cy The size of the area to be scrolled * @param[in] lines The number of lines to scroll (Can be positive or negative) * @param[in] bgcolor The color to fill the newly exposed area. * * @notapi */ void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { RECT rect, frect, srect; HBRUSH hbr; #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP // Clip pre orientation change if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; } if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; } if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return; if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x; if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y; #endif if (lines > cy) lines = cy; else if (-lines > cy) lines = -cy; bgcolor = COLOR2BGR(bgcolor); hbr = CreateSolidBrush(bgcolor); #if GDISP_NEED_CONTROL switch(GDISP.Orientation) { case GDISP_ROTATE_0: rect.top = y; rect.bottom = rect.top+cy; rect.left = x; rect.right = rect.left+cx; lines = -lines; goto vertical_scroll; case GDISP_ROTATE_90: rect.top = x; rect.bottom = rect.top+cx; rect.right = GDISP.Height - y; rect.left = rect.right-cy; goto horizontal_scroll; case GDISP_ROTATE_180: rect.bottom = GDISP.Height - y; rect.top = rect.bottom-cy; rect.right = GDISP.Width - x; rect.left = rect.right-cx; vertical_scroll: srect.left = frect.left = rect.left; srect.right = frect.right = rect.right; if (lines > 0) { srect.top = frect.top = rect.top; frect.bottom = rect.top+lines; srect.bottom = rect.bottom-lines; } else { srect.bottom = frect.bottom = rect.bottom; frect.top = rect.bottom+lines; srect.top = rect.top-lines; } if (cy >= lines && cy >= -lines) ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0); break; case GDISP_ROTATE_270: rect.bottom = GDISP.Width - x; rect.top = rect.bottom-cx; rect.left = y; rect.right = rect.left+cy; lines = -lines; horizontal_scroll: srect.top = frect.top = rect.top; srect.bottom = frect.bottom = rect.bottom; if (lines > 0) { srect.left = frect.left = rect.left; frect.right = rect.left+lines; srect.right = rect.right-lines; } else { srect.right = frect.right = rect.right; frect.left = rect.right+lines; srect.left = rect.left-lines; } if (cy >= lines && cy >= -lines) ScrollDC(dcBuffer, lines, 0, &srect, 0, 0, 0); break; } #else rect.top = y; rect.bottom = rect.top+cy; rect.left = x; rect.right = rect.left+cx; lines = -lines; srect.left = frect.left = rect.left; srect.right = frect.right = rect.right; if (lines > 0) { srect.top = frect.top = rect.top; frect.bottom = rect.top+lines; srect.bottom = rect.bottom-lines; } else { srect.bottom = frect.bottom = rect.bottom; frect.top = rect.bottom+lines; srect.top = rect.top-lines; } if (cy >= lines && cy >= -lines) ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0); #endif if (hbr) FillRect(dcBuffer, &frect, hbr); InvalidateRect(winRootWindow, &rect, FALSE); UpdateWindow(winRootWindow); }
static VOID MonSelMoveDragRect(IN OUT PMONITORSELWND infoPtr, IN PPOINT ppt) { RECT rcPrev, rcUpdate, *prc; HRGN hRgnPrev; HDC hDC; if (infoPtr->CanDisplay) { hDC = GetDC(infoPtr->hSelf); if (hDC != NULL) { if (infoPtr->ptDrag.x != ppt->x || infoPtr->ptDrag.y != ppt->y) { infoPtr->ptDrag = *ppt; rcPrev = infoPtr->rcDragging; /* Calculate updated dragging rectangle */ prc = &infoPtr->Monitors[infoPtr->DraggingMonitor].rc; infoPtr->rcDragging.left = ppt->x - infoPtr->DraggingMargin.cx; infoPtr->rcDragging.top = ppt->y - infoPtr->DraggingMargin.cy; infoPtr->rcDragging.right = infoPtr->rcDragging.left + (prc->right - prc->left); infoPtr->rcDragging.bottom = infoPtr->rcDragging.top + (prc->bottom - prc->top); hRgnPrev = CreateRectRgn(rcPrev.left, rcPrev.top, rcPrev.right, rcPrev.bottom); if (hRgnPrev != NULL) { if (!ScrollDC(hDC, infoPtr->rcDragging.left - rcPrev.left, infoPtr->rcDragging.top - rcPrev.top, &rcPrev, NULL, hRgnPrev, &rcUpdate) || !InvalidateRgn(infoPtr->hSelf, hRgnPrev, TRUE)) { DeleteObject(hRgnPrev); goto InvRects; } DeleteObject(hRgnPrev); } else { InvRects: InvalidateRect(infoPtr->hSelf, &rcPrev, TRUE); InvalidateRect(infoPtr->hSelf, &infoPtr->rcDragging, TRUE); } } ReleaseDC(infoPtr->hSelf, hDC); } } }
LOCAL void display_cast( HWND hWnd, LPTSTR lpString, BOOL bScroll ) // Display a scrolling list of the Cast, beginning with a new player each time. /************************************************************************/ { TEXTMETRIC SysCharSize; HDC hDC; RECT Area; LPTSTR lpNext, lpCastName; HRGN hUpdate; int SaveLevel, WndHeight, CastHeight, OldBkMode; DWORD OldTextColor; HBRUSH hBrush; HGDIOBJ hFont, hOldFont; RECT Update, rDummy; WORD wChar; BOOL fDBCS, fCenter; static short CastOfs = -1; #define SCROLLCOUNT 1 if ( !hWnd ) return; if ( !(hDC = GetDC( hWnd )) ) return; GetTextMetrics( hDC, &SysCharSize ); OldBkMode = SetBkMode( hDC,TRANSPARENT ); OldTextColor = SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) ); hBrush = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) ); if ( !(hFont = (HFONT)SendMessage( hWnd, WM_GETFONT, 0, 0L )) ) hFont = GetStockObject( GetSystemMetrics( SM_DBCSENABLED ) ? SYSTEM_FONT:ANSI_VAR_FONT ); hOldFont = SelectObject(hDC, hFont); GetClientRect( hWnd, &Area ); CastHeight = 0; lpNext = lpString; while ( lpNext ) { CastHeight += SysCharSize.tmHeight; lpNext = lStrChr( MyCharNextN( lpNext, 1 ), _T('\n') ); } if (bScroll) { Area.top += SCROLLCOUNT; ScrollDC( hDC, 0, -SCROLLCOUNT, &Area, NULL, NULL, &Update ); Area.top -= SCROLLCOUNT; SaveLevel = SaveDC( hDC ); } else { Update = Area; } hUpdate = CreateRectRgn(Update.left,Update.top,Update.right,Update.bottom); SelectClipRgn( hDC, hUpdate ); WndHeight = (1 + Area.bottom / SysCharSize.tmHeight) * SysCharSize.tmHeight; if ((WndHeight - (CastOfs -= SCROLLCOUNT)) >= CastHeight) CastOfs = WndHeight; Area.top = CastOfs; lpNext = lpString; while ( lpNext ) { Area.bottom = Area.top + SysCharSize.tmHeight; lpCastName = lpNext; if( lpNext = lStrChr( lpNext, _T('\n') )) { if( IsDBCSLeadByte(( BYTE )*lpNext )) { fDBCS = TRUE; wChar = *(( LPWORD )lpNext ); } else { fDBCS = FALSE; wChar = *lpNext; } *lpNext = _T('\0'); } if( IntersectRect( &rDummy, &Area, &Update )) { FillRect( hDC, &Area, hBrush ); if( IsDBCSLeadByte(( BYTE )*lpCastName )) fCenter = ( *(( LPWORD )lpCastName ) == _T(' ') ); else fCenter = ( *lpCastName == _T(' ') ); DrawText( hDC, lpCastName, -1, &Area, ( fCenter ? DT_CENTER : 0 ) | DT_NOPREFIX | DT_SINGLELINE ); } if( lpNext ) { if( fDBCS ) *(( LPWORD )lpNext ) = wChar; else *lpNext = LOBYTE( wChar ); lpNext = MyCharNext( lpNext ); } if ((Area.top = Area.bottom) > WndHeight ) Area.top -= CastHeight; } if (bScroll) RestoreDC( hDC, SaveLevel ); DeleteObject( hUpdate ); DeleteObject( hBrush ); SetTextColor( hDC, OldTextColor ); SetBkMode( hDC, OldBkMode ); if ( hOldFont ) SelectObject( hDC, hOldFont ); ReleaseDC( hWnd, hDC ); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent,length; static char *str; static int mouseX,mouseY,menu,width,polX,polY; static bool polFl = true, fl = false, text=false,zoom=false; static float k=1; PAINTSTRUCT ps; static HDC hdc; HBITMAP hbmp1,hbmp2; HGDIOBJ hobj; HFONT hFont; static RECT r; static COLORREF clr; static HPEN hpen; switch (message) { case WM_CREATE: hdc = GetDC(hWnd); scrhor =3* GetDeviceCaps(hdc, HORZRES); scrvert =3* GetDeviceCaps(hdc, VERTRES); hdc1 = CreateCompatibleDC(hdc); hdc2 = CreateCompatibleDC(hdc); hbmp1 = CreateCompatibleBitmap(hdc, scrhor, scrvert); hbmp2 = CreateCompatibleBitmap(hdc, scrhor, scrvert); SelectObject(hdc1, hbmp1); SelectObject(hdc2, hbmp2); r.left = 0; r.top = 0; r.right = scrhor; r.bottom = scrvert; FillRect(hdc1, &r, (HBRUSH)CreateSolidBrush(RGB(255, 255, 255))); FillRect(hdc2, &r, (HBRUSH)CreateSolidBrush(RGB(255, 255, 255))); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IM_EXIT: DestroyWindow(hWnd); break; case IM_PENCIL: menu = IM_PENCIL; break; case IM_LINE: menu = IM_LINE; break; case IM_TEXT: menu = IM_TEXT; break; case IM_RECTANGLE: menu = IM_RECTANGLE; break; case IM_COLOR: GetPenColor(hWnd, &clr); hpen = CreatePen(PS_SOLID, 1, clr); SelectObject(hdc, hpen); SelectObject(hdc1, hpen); SelectObject(hdc2, hpen); break; case IM_POLYLINE: menu = 8; break; case IM_POLYGON: menu = 9; break; case IM_SAVE: SaveEnhMetaFile(hWnd); break; case IM_OPEN: OpenEnhMetaFile(hWnd); break; case IM_PRINT: Print(hWnd); break; case IM_ELLIPSE: menu = IM_ELLIPSE; break; case IM_WIDTH_1: width = 1; break; case IM_WIDTH_2: width = 2; break; case IM_WIDTH_3: width = 3; break; case IM_WIDTH_4: width = 4; break; case IM_WIDTH_5: width = 5; break; case IM_WIDTH_6: width = 6; break; case IM_WIDTH_7: width = 7; break; case IM_WIDTH_8: width = 8; break; case IM_WIDTH_9: width = 9; break; case IM_WIDTH_10: width = 10; break; default: return DefWindowProc(hWnd, message, wParam, lParam); } if (width > 0) { hpen = CreatePen(PS_SOLID, width, clr); SelectObject(hdc, hpen); SelectObject(hdc1, hpen); SelectObject(hdc2, hpen); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if (zoom) { StretchBlt(hdc2, scrhor/3, scrvert/3, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, scrhor*k, scrvert*k, SRCCOPY); StretchBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3,scrvert/3, scrhor*k, scrvert*k, SRCCOPY); } else { BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_CHAR: if (menu == IM_TEXT && text) { length = strlen(str); if (wParam == 8) { str[length - 1] = '\0'; BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); TextOutA(hdc1, mouseX+scrhor/3, mouseY+scrvert/3, str, strlen(str)); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); InvalidateRect(hWnd, NULL, false); } else { if (wParam == 13) { text = false; } else { str = (char*)realloc(str, length + 2); length = length + 2; str[length - 2] = wParam; str[length - 1] = '\0'; TextOutA(hdc1, mouseX+scrhor/3, mouseY+scrvert/3, str, strlen(str)); InvalidateRect(hWnd, NULL, false); } } } break; case WM_KEYUP: if (wParam == VK_SHIFT) { zoom = false; k = 1; BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); } break; case WM_MOUSEWHEEL: if (HIWORD(wParam) > WHEEL_DELTA) { if (LOWORD(wParam)==MK_SHIFT) { k = k/1.1; zoom = true; } else { if (LOWORD(wParam)==MK_CONTROL) { ScrollDC(hdc1, 5, 0, &r, NULL, NULL, NULL); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } else { ScrollDC(hdc1, 0, 5, &r, NULL, NULL, NULL); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } } } else { if (LOWORD(wParam)==MK_SHIFT) { k = k*1.1; zoom = true; } else { if (LOWORD(wParam)==MK_CONTROL) { ScrollDC(hdc1, -5, 0, &r, NULL, NULL, NULL); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } else { ScrollDC(hdc1, 0, -5, &r, NULL, NULL, NULL); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } } } InvalidateRect(hWnd, NULL, false); break; case WM_LBUTTONDOWN: if (menu) { mouseX = LOWORD(lParam); mouseY = HIWORD(lParam); if (menu == IM_POLYGON && polFl) { polX = mouseX; polY = mouseY; polFl = false; } MoveToEx(hdc1, mouseX+scrhor/3, mouseY+scrvert/3, NULL); MoveToEx(hdc2, mouseX+scrhor/3, mouseY+scrvert/3, NULL); fl = !fl; if (menu == IM_POLYLINE || menu==IM_POLYGON) { fl = false; BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); } if (menu == IM_TEXT) { BitBlt(hdc2, 0, 0, scrhor, scrvert, hdc1, 0, 0, SRCCOPY); text = true; str = (char*)malloc(1); str[0] = '\0'; } } break; case WM_MOUSEMOVE: if (fl) { hdc = GetDC(hWnd); SelectObject(hdc1, hpen); if (menu == IM_PENCIL) { mouseX = LOWORD(lParam); mouseY = HIWORD(lParam); LineTo(hdc1, mouseX+scrhor/3, mouseY+scrvert/3); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc1, scrhor/3, scrvert/3, SRCCOPY); } if (menu == IM_LINE) { BitBlt(hdc2, 0, 0, scrhor, scrvert, hdc1, 0, 0, SRCCOPY); MoveToEx(hdc2, mouseX+scrhor/3, mouseY+scrvert/3, NULL); LineTo(hdc2, LOWORD(lParam)+scrhor/3,HIWORD(lParam)+scrvert/3); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); } if (menu == IM_RECTANGLE) { BitBlt(hdc2, 0, 0, scrhor, scrvert, hdc1, 0, 0, SRCCOPY); MoveToEx(hdc2, mouseX+scrhor/3, mouseY+scrhor/3, NULL); hobj=SelectObject(hdc2, GetStockObject(NULL_BRUSH)); Rectangle(hdc2, mouseX+scrhor/3, mouseY+scrvert/3, LOWORD(lParam)+scrhor/3, HIWORD(lParam)+scrvert/3); SelectObject(hdc2, hobj); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); } if (menu == IM_ELLIPSE) { BitBlt(hdc2, 0, 0, scrhor, scrvert, hdc1, 0, 0, SRCCOPY); MoveToEx(hdc2, mouseX, mouseY, NULL); hobj=SelectObject(hdc2, GetStockObject(NULL_BRUSH)); Ellipse(hdc2, mouseX+scrhor/3, mouseY+scrvert/3, LOWORD(lParam)+scrhor/3, HIWORD(lParam)+scrvert/3); SelectObject(hdc2, hobj); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); } if (menu == IM_POLYLINE || menu ==IM_POLYGON) { BitBlt(hdc2, 0, 0, scrhor, scrvert, hdc1, 0, 0, SRCCOPY); MoveToEx(hdc2, mouseX+scrhor/3, mouseY+scrvert/3, NULL); LineTo(hdc2, LOWORD(lParam)+scrhor/3, HIWORD(lParam)+scrvert/3); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); } } break; case WM_LBUTTONUP: if (menu == IM_LINE || menu == IM_RECTANGLE || menu == IM_ELLIPSE) { BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); } if (menu == IM_POLYLINE || menu ==IM_POLYGON) { fl = false; } fl = !fl; break; case WM_RBUTTONDOWN: if (menu == IM_POLYLINE || menu==IM_POLYGON) { fl = false; BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); } if (menu == IM_POLYGON) { LineTo(hdc2, polX+scrhor/3, polY+scrvert/3); BitBlt(hdc, 0, 0, scrhor, scrvert, hdc2, scrhor/3, scrvert/3, SRCCOPY); BitBlt(hdc1, 0, 0, scrhor, scrvert, hdc2, 0, 0, SRCCOPY); polFl = true; } break; case WM_DESTROY: ReleaseDC(hWnd, hdc); ReleaseDC(hWnd, hdc1); ReleaseDC(hWnd, hdc2); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/******************************************************************** * SendToScreen: Displays the current text line in the Dialog Window. *********************************************************************/ void SendToScreen ( void ) { extern SCREEN WinDialog; /* D.S. Holding info about screen */ RECT DRect; /* Client Area of Dialog Window */ RECT Rect; /* Adjusted Area for scrolling */ HDC hDC = GetDC ( WinDialog.hWnd); /* Handle to the device context */ extern int OldLine; /* Previous Line Printed */ int min, max, pos; /* Scroll Bar Values */ int Scroll = 0; /* Scrolling Needed? */ GetClientRect ( WinDialog.hWnd, &Rect ); GetClientRect ( WinDialog.hWnd, &DRect ); HideCaret ( WinDialog.hWnd ); /*------------------------------------------------------+ | Move to the bottom of the screen if not already there | +------------------------------------------------------*/ GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max ); pos = GetScrollPos (WinDialog.hWnd, SB_VERT ); if ( pos != max ) { InvalidateRect ( WinDialog.hWnd, NULL, TRUE ); SetScrollPos (WinDialog.hWnd, SB_VERT, max, FALSE ); SendMessage ( WinDialog.hWnd, WM_PAINT, 0, 0); } /*--------------------------------------------------------+ | Determine if the screen is full and scrolling is needed | +--------------------------------------------------------*/ if ( max > WinDialog.NoLines ) Scroll = 1; /*-------------------------------------------------------------+ | Scroll Window if newline and text will not fit on the screen | +-------------------------------------------------------------*/ if (Scroll && WinDialog.LastLine != OldLine) { OldLine = WinDialog.LastLine; ScrollDC ( hDC, 0, -WinDialog.LineSize, &DRect, &DRect, NULL, &Rect ); } /*----------------------------------------+ | Calculate when text is to be displayed | +----------------------------------------*/ if ( !Scroll) Rect.top = (WinDialog.LastLine) * WinDialog.LineSize; else Rect.top = (WinDialog.NoLines) * WinDialog.LineSize; /*----------------------------+ | Clear Line to be displayed | +----------------------------*/ { HANDLE OldObject; OldObject = SelectObject (hDC, GetStockObject ( WHITE_PEN ) ); Rectangle (hDC, Rect.left, Rect.top, Rect.right, Rect.bottom); SelectObject (hDC, OldObject); } /*--------------------------+ | Display Text Adjusting | | for the Horizontal scroll | +--------------------------*/ pos = GetScrollPos (WinDialog.hWnd, SB_HORZ ); if (Terminal[WinDialog.LastLine] == NULL) { /* Do Nothing */ } else if ( pos < strlen (Terminal[WinDialog.LastLine]) ) { DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX ); DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX); } else Rect.right = 2; /*-----------+ | Show Caret | +-----------*/ SetCaretPos (Rect.right, Rect.top); ShowCaret ( WinDialog.hWnd ); /*--------------------------------+ | Automatic Horizontal Scrolling | +--------------------------------*/ if (Terminal[WinDialog.LastLine] != NULL) { DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX ); } if ( Rect.right > DRect.right && HorizScroll ) { GetScrollRange ( WinDialog.hWnd, SB_HORZ, &min, &max ); pos ++; if ( max < pos) max = pos; SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, max, FALSE ); SetScrollPos ( WinDialog.hWnd, SB_HORZ, pos, TRUE ); InvalidateRect (WinDialog.hWnd, NULL, TRUE); } OldLine = WinDialog.LastLine; ReleaseDC ( WinDialog.hWnd, hDC); }
LRESULT CALLBACK FrameProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_HSCROLL:{ int xDelta; int xNewPos; int yDelta = 0; switch (LOWORD(wParam)) { /* User clicked the shaft left of the scroll box. */ case SB_PAGEUP: xNewPos = xCurrentScroll - xPageScroll; break; /* User clicked the shaft right of the scroll box. */ case SB_PAGEDOWN: xNewPos = xCurrentScroll + xPageScroll; break; /* User clicked the left arrow. */ case SB_LINEUP: xNewPos = xCurrentScroll - xIncrementScroll; break; /* User clicked the right arrow. */ case SB_LINEDOWN: xNewPos = xCurrentScroll + xIncrementScroll; break; /* User dragged or is dragging the scroll box. */ case SB_THUMBPOSITION: case SB_THUMBTRACK: xNewPos = HIWORD(wParam); break; default: xNewPos = xCurrentScroll; } /* New position must be between 0 and the screen width. */ xNewPos = max(0, xNewPos); xNewPos = min(xMaxScroll, xNewPos); /* If the current position does not change, do not scroll.*/ if (xNewPos == xCurrentScroll) break; /* Determine the amount scrolled (in pixels). */ xDelta = (xNewPos - xCurrentScroll)*xPixelsPerIncrement; //(-) is hit left, scroll right /* Reset the current scroll position. */ xCurrentScroll = xNewPos; ScrollDC(hdcMemoryTheMap,-xDelta,-yDelta,NULL,NULL,NULL,NULL); MapPositionX=xCurrentScroll; if (xDelta>0) //hit right, scroll left RenderScreen(hwnd,max(0,(TheMapWidth-xDelta)),0,TheMapWidth,TheMapHeight); else //hit left, scroll right RenderScreen(hwnd,0,0,min(TheMapWidth,-xDelta),TheMapHeight); ScrollWindowEx(hwnd, -xDelta, -yDelta, &TheWindowRect, &TheWindowRect, (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); // InvalidateRect(hwnd,&TheWindowRect,false); UpdateWindow(hwnd); ResetScrollBarX(hwnd); } break; case WM_VSCROLL:{ int xDelta=0; int yNewPos; int yDelta; switch (LOWORD(wParam)) { /* User clicked the shaft above scroll box. */ case SB_PAGEUP: yNewPos = yCurrentScroll - yPageScroll; break; /* User clicked the shaft below the scroll box. */ case SB_PAGEDOWN: yNewPos = yCurrentScroll + yPageScroll; break; /* User clicked the up arrow. */ case SB_LINEUP: yNewPos = yCurrentScroll - yIncrementScroll; break; /* User clicked the down arrow. */ case SB_LINEDOWN: yNewPos = yCurrentScroll + yIncrementScroll; break; /* User dragged or is dragging the scroll box. */ case SB_THUMBPOSITION: case SB_THUMBTRACK: yNewPos = HIWORD(wParam); break; default: yNewPos = yCurrentScroll; } /* New position must be between 0 and the screen height. */ yNewPos = max(0, yNewPos); yNewPos = min(yMaxScroll, yNewPos); /* If the current position does not change, do not scroll.*/ if (yNewPos == yCurrentScroll) break; /* Determine the amount scrolled (in pixels). */ yDelta = (yNewPos - yCurrentScroll)*yPixelsPerIncrement; //(-) is hit up, scroll down /* Reset the current scroll position. */ yCurrentScroll = yNewPos; ScrollDC(hdcMemoryTheMap,-xDelta,-yDelta,NULL,NULL,NULL,NULL); MapPositionY=yCurrentScroll; if (yDelta>0) //hit down, scroll up RenderScreen(hwnd,0,max(0,(TheMapHeight-yDelta)),TheMapWidth,TheMapHeight); else //hit up, scroll down RenderScreen(hwnd,0,0,TheMapWidth,min(TheMapHeight,-yDelta)); ScrollWindowEx(hwnd, -xDelta, -yDelta, &TheWindowRect, &TheWindowRect, (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); UpdateWindow(hwnd); ResetScrollBarY(hwnd); } break; case WM_COMMAND: MainWindowCommand(hwnd,LOWORD(wParam)); break; case WM_ERASEBKGND: if (MapLoaded) return 1; //don't erase background if we have the map loaded return DefWindowProc(hwnd, Message, wParam, lParam); case WM_PAINT: PAINTSTRUCT ps; HDC hdcWindow; hdcWindow = BeginPaint(hwnd, &ps); if (!TheMapBitmap) { CreateMainBitmapX(hwnd); RenderFullScreen(hwnd); } DisplayFullScreen2(hdcWindow); EndPaint(hwnd, &ps); break; case WM_SIZE: //Adjust our bitmap to fit window if ((wParam==SIZE_MAXIMIZED)||(wParam==SIZE_RESTORED)) AdjustScreenSize(hwnd,LOWORD(lParam),HIWORD(lParam)); break; case WM_CREATE: CreateMainMenu(hwnd); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: FreeAllData(); if (hdcMemoryTheMap) DeleteDC(hdcMemoryTheMap); if (TheMapBitmap) DeleteObject(TheMapBitmap); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, Message, wParam, lParam); } return 0; }
LLDSPEC void gdisp_lld_vertical_scroll(GDisplay *g) { winPriv * priv; RECT rect; coord_t lines; priv = g->priv; #if GDISP_NEED_CONTROL switch(g->g.Orientation) { case GDISP_ROTATE_0: default: rect.top = g->p.y; rect.bottom = rect.top+g->p.cy; rect.left = g->p.x; rect.right = rect.left+g->p.cx; lines = -g->p.y1; goto vertical_scroll; case GDISP_ROTATE_90: rect.bottom = g->g.Width - g->p.x; rect.top = rect.bottom-g->p.cx; rect.left = g->p.y; rect.right = rect.left+g->p.cy; lines = -g->p.y1; goto horizontal_scroll; case GDISP_ROTATE_180: rect.bottom = g->g.Height - g->p.y; rect.top = rect.bottom-g->p.cy; rect.right = g->g.Width - g->p.x; rect.left = rect.right-g->p.cx; lines = g->p.y1; vertical_scroll: if (lines > 0) { rect.bottom -= lines; } else { rect.top -= lines; } if (g->p.cy >= lines && g->p.cy >= -lines) { WaitForSingleObject(drawMutex, INFINITE); ScrollDC(priv->dcBuffer, 0, lines, &rect, 0, 0, 0); #if GDISP_WIN32_USE_INDIRECT_UPDATE ReleaseMutex(drawMutex); InvalidateRect(priv->hwnd, &rect, FALSE); #else { HDC dc; dc = GetDC(priv->hwnd); ScrollDC(dc, 0, lines, &rect, 0, 0, 0); ReleaseDC(priv->hwnd, dc); ReleaseMutex(drawMutex); } #endif } break; case GDISP_ROTATE_270: rect.top = g->p.x; rect.bottom = rect.top+g->p.cx; rect.right = g->g.Height - g->p.y; rect.left = rect.right-g->p.cy; lines = g->p.y1; horizontal_scroll: if (lines > 0) { rect.right -= lines; } else { rect.left -= lines; } if (g->p.cy >= lines && g->p.cy >= -lines) { WaitForSingleObject(drawMutex, INFINITE); ScrollDC(priv->dcBuffer, lines, 0, &rect, 0, 0, 0); #if GDISP_WIN32_USE_INDIRECT_UPDATE ReleaseMutex(drawMutex); InvalidateRect(priv->hwnd, &rect, FALSE); #else { HDC dc; dc = GetDC(priv->hwnd); ScrollDC(dc, lines, 0, &rect, 0, 0, 0); ReleaseDC(priv->hwnd, dc); ReleaseMutex(drawMutex); } #endif } break; } #else rect.top = g->p.y; rect.bottom = rect.top+g->p.cy; rect.left = g->p.x; rect.right = rect.left+g->p.cx; lines = -g->p.y1; if (lines > 0) { rect.bottom -= lines; } else { rect.top -= lines; } if (g->p.cy >= lines && g->p.cy >= -lines) { WaitForSingleObject(drawMutex, INFINITE); ScrollDC(priv->dcBuffer, 0, lines, &rect, 0, 0, 0); #if GDISP_WIN32_USE_INDIRECT_UPDATE ReleaseMutex(drawMutex); InvalidateRect(priv->hwnd, &rect, FALSE); #else { HDC dc; dc = GetDC(priv->hwnd); ScrollDC(dc, 0, lines, &rect, 0, 0, 0); ReleaseDC(priv->hwnd, dc); ReleaseMutex(drawMutex); } #endif } #endif }