Exemplo n.º 1
0
BOOL GUIAPI UnionRect(RECT* pdrc, const RECT* psrc1, const RECT* psrc2)
{
    RECT src1, src2;
    memcpy(&src1, psrc1, sizeof(RECT));
    memcpy(&src2, psrc2, sizeof(RECT));

    NormalizeRect(&src1);
    NormalizeRect(&src2);

    if (src1.left == src2.left 
        && src1.right == src2.right) {
        if (src1.top <= src2.top && src2.top <= src1.bottom) {
            pdrc->left = src1.left;
            pdrc->right = src1.right;
            pdrc->top = src1.top;
            pdrc->bottom = MAX(src1.bottom, src2.bottom);

            return TRUE;
        }
        else if (src1.top >= src2.top && src2.bottom >= src1.top) {
            pdrc->left = src1.left;
            pdrc->right = src1.right;
            pdrc->top = src2.top;
            pdrc->bottom = MAX(src1.bottom, src2.bottom);

            return TRUE;
       }

       return FALSE;
    }

    if (src1.top == src2.top 
        && src1.bottom == src2.bottom) {
        if (src1.left <= src2.left && src2.left <= src1.right) {
            pdrc->top = src1.top;
            pdrc->bottom = src1.bottom;
            pdrc->left = src1.left;
            pdrc->right = MAX(src1.right, src2.right);

            return TRUE;
        }
        else if (src1.left >= src2.left && src2.right >= src1.left) {
            pdrc->top = src1.top;
            pdrc->bottom = src1.bottom;
            pdrc->left = src2.left;
            pdrc->right = MAX(src1.right, src2.right);

            return TRUE;
       }

       return FALSE;
    }

    return FALSE;
}
Exemplo n.º 2
0
void GUIAPI GetBoundRect (PRECT pdrc,  const RECT* psrc1, const RECT* psrc2)
{
    RECT src1, src2;
    memcpy(&src1, psrc1, sizeof(RECT));
    memcpy(&src2, psrc2, sizeof(RECT));

    NormalizeRect(&src1);
    NormalizeRect(&src2);

    pdrc->left = (src1.left < src2.left) ? src1.left : src2.left;
    pdrc->top  = (src1.top < src2.top) ? src1.top : src2.top;
    pdrc->right = (src1.right > src2.right) ? src1.right : src2.right;
    pdrc->bottom = (src1.bottom > src2.bottom) 
                   ? src1.bottom : src2.bottom;
}
Exemplo n.º 3
0
LRESULT OnLButtonUp(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
    RECT crt,irt;
    int SwapResult;

    if (DragMode==DM_DRAW) {
        if (AppendObject(NowTool,sx,sy,oldx,oldy)==TRUE) {
            NowSel=arNum-1;
        } else {
            NowTool=DT_SELECT;
            NowSel=-1;
        }
        InvalidateRect(hWnd,NULL,TRUE);
    }
    if (DragMode==DM_MOVE || DragMode==DM_SIZE) {
        SwapResult=NormalizeRect(&dObj.rt);
        GetClientRect(hWnd,&crt);
        InflateRect(&crt,-10,-10);
        IntersectRect(&irt,&crt,&dObj.rt);
        if (!IsRectEmpty(&irt)) {
            arObj[NowSel]->rt=dObj.rt;
            arObj[NowSel]->Flag ^= SwapResult;
        }
        InvalidateRect(hWnd,NULL,TRUE);
    }
    DragMode=DM_NONE;
    ReleaseCapture();
    return 0;
}
Exemplo n.º 4
0
STDMETHODIMP CDrawMenu::MoveHandleTo(long nHandle, POINT point)
{
	DefaultMoveHandleTo(&m_rcPosition, -nHandle, point);
	NormalizeRect(&m_rcPosition);

	return S_OK;
}
Exemplo n.º 5
0
int GUIAPI TabbedTextOutLen (HDC hdc, int x, int y, const char* spText, int len) 
{
    PCLIPRECT pClipRect;
    PDC pdc;
    SIZE size;
    RECT rcOutput;

    if (len == 0) return 0;
    if (len < 0) len = strlen (spText);

    pdc = dc_HDC2PDC(hdc);

    coor_LP2SP (pdc, &pdc->CurTextPos.x, &pdc->CurTextPos.y);
    gdi_get_TabbedTextOut_extent (pdc, pdc->pLogFont, pdc->tabstop, spText, len, 
                &size, &pdc->CurTextPos);
    coor_SP2LP (pdc, &pdc->CurTextPos.x, &pdc->CurTextPos.y);

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return size.cx;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x, &y);
    
    rcOutput.left = x;
    rcOutput.top  = y;
    rcOutput.right = x + size.cx + 1;
    rcOutput.bottom = y + size.cy + 1;
    NormalizeRect(&rcOutput);

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC(pdc->gc);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            gdi_tabbedtextout (pdc, x, y, spText, len);
        }
            
        pClipRect = pClipRect->next;
    }

    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
    pthread_mutex_unlock(&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);

    return size.cx;
}
Exemplo n.º 6
0
BOOL GUIAPI AddClipRect (PCLIPRGN pRgn, const RECT* pRect)
{
     PCLIPRECT pClipRect;
     RECT rcTemp;

     rcTemp = *pRect;

     if (IsRectEmpty (&rcTemp))
         return FALSE;

     NormalizeRect (&rcTemp);

     pClipRect = ClipRectAlloc (pRgn->heap);
     pClipRect->rc = rcTemp;
     pClipRect->next = NULL;

     if (pRgn->head) {
         pRgn->tail->next = pClipRect;
         pRgn->tail = pClipRect;
     }
     else {
         pRgn->head = pRgn->tail = pClipRect;
     }

     return TRUE;
}
Exemplo n.º 7
0
BOOL GUIAPI SetClipRgn (PCLIPRGN pRgn, const RECT* pRect)
{
    PCLIPRECT pClipRect;
    RECT rcTemp;

    rcTemp = *pRect;

    if (IsRectEmpty (&rcTemp))
        return FALSE;

    NormalizeRect (&rcTemp);

    // empty rgn first
    EmptyClipRgn (pRgn);

    // get a new clip rect from free list
    pClipRect = ClipRectAlloc (pRgn->heap);

    // set clip rect
    pClipRect->rc = rcTemp;
    pClipRect->next = NULL;

    pRgn->head = pRgn->tail = pClipRect;
    pRgn->rcBound = rcTemp;

    return TRUE;
} 
Exemplo n.º 8
0
STDMETHODIMP CDrawTxt::MoveHandleTo(long nHandle, POINT point)
{
	DefaultMoveHandleTo(&m_rcPosition, -nHandle, point);
	NormalizeRect(&m_rcPosition);
	if (m_bAutoSize)
		ReCalcFontSize(m_dFontHeight, m_dFontWidth);

	return S_OK;
}
Exemplo n.º 9
0
STDMETHODIMP CDrawMenu::MoveTo(RECTF rect, BOOL bUniformScale)
{
	NormalizeRect(&rect);
	m_rcPosition.left = rect.left;
	m_rcPosition.top = rect.top;
	m_rcPosition.right = rect.right;
	m_rcPosition.bottom = rect.bottom;

	return S_OK;
}
Exemplo n.º 10
0
void GUIAPI BitBlt(HDC hsdc, int sx, int sy, int sw, int sh,
                   HDC hddc, int dx, int dy, DWORD dwRop)
{
    PCLIPRECT pClipRect;
    PDC psdc, pddc;
    RECT rcOutput;

    psdc = dc_HDC2PDC(hsdc);
    pddc = dc_HDC2PDC(hddc);

    if (dc_IsGeneralHDC(hddc)) {
        if (!dc_GenerateECRgn (pddc, FALSE)) {
            return;
        }
    }

    if (sw <= 0 || sh <= 0) {
        sw = RECTW (psdc->DevRC);
        sh = RECTH (psdc->DevRC);
    }

    // Transfer logical to device to screen here.
    sw += sx; sh += sy;
    coor_LP2SP(psdc, &sx, &sy);
    coor_LP2SP(psdc, &sw, &sh);
    (sw > sx) ? (sw -= sx) : (sw = sx - sw);
    (sh > sy) ? (sh -= sy) : (sh = sy - sh);
    coor_LP2SP(pddc, &dx, &dy);
    rcOutput.left = dx;
    rcOutput.top  = dy;
    rcOutput.right = dx + sw;
    rcOutput.bottom = dy + sh;
    NormalizeRect(&rcOutput);
    
    ShowCursorForGDI(FALSE, &g_rcScr);

    // set graphics context.
    GAL_SetGC (pddc->gc);

    pClipRect = pddc->ecrgn.head;

    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pddc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            GAL_CrossBlit (psdc->gc, sx, sy, sw, sh, pddc->gc, dx, dy);
        }

        pClipRect = pClipRect->next;
    }

    ShowCursorForGDI(TRUE, &g_rcScr);
}
Exemplo n.º 11
0
size_t CGRect::Read( LPCTSTR pszVal )
{
	ADDTOCALLSTACK("CGRect::Read");
	// parse reading the rectangle
	TCHAR *pszTemp = Str_GetTemp();
	strcpy( pszTemp, pszVal );
	TCHAR * ppVal[5];
	size_t i = Str_ParseCmds( pszTemp, ppVal, COUNTOF( ppVal ), " ,\t");
	switch (i)
	{
		case 5:
			m_map = ATOI(ppVal[4]);
			if (( m_map < 0 ) || ( m_map >= 256 ) || !g_MapList.m_maps[m_map] )
			{
				g_Log.EventError("Unsupported map #%d specified. Auto-fixing that to 0.\n", m_map);
				m_map = 0;
			}
			m_bottom = ATOI(ppVal[3]);
			m_right = ATOI(ppVal[2]);
			m_top =	ATOI(ppVal[1]);
			m_left = ATOI(ppVal[0]);
			break;
		case 4:
			m_map = 0;
			m_bottom = ATOI(ppVal[3]);
			m_right = ATOI(ppVal[2]);
			m_top =	ATOI(ppVal[1]);
			m_left = ATOI(ppVal[0]);
			break;
		case 3:
			m_map = 0;
			m_bottom = 0;
			m_right = ATOI(ppVal[2]);
			m_top =	ATOI(ppVal[1]);
			m_left = ATOI(ppVal[0]);
			break;
		case 2:
			m_map = 0;
			m_bottom = 0;
			m_right = 0;
			m_top =	ATOI(ppVal[1]);
			m_left = ATOI(ppVal[0]);
			break;
		case 1:
			m_map = 0;
			m_bottom = 0;
			m_right = 0;
			m_top = 0;
			m_left = ATOI(ppVal[0]);
			break;
	}
	NormalizeRect();
	return( i );
}
Exemplo n.º 12
0
CV_INLINE IplROI RectToROI( RECT r )
{
   IplROI roi;
   r = NormalizeRect( r );
   roi.xOffset = r.left;
   roi.yOffset = r.top;
   roi.width = r.right - r.left;
   roi.height = r.bottom - r.top;
   roi.coi = 0;

   return roi;
}
Exemplo n.º 13
0
void CHMMDemoView::CheckUpdate()
{
    m_sel = NormalizeRect( m_tmp_sel );
    if( !Camera().IsRunning() )
    {
        CImage& img = Camera().GetFrame();
        CRect ir( 0, 0, img.Width(), img.Height() );

        InvalidateRect(&ir, FALSE);
        UpdateWindow();
    }
}
Exemplo n.º 14
0
void GUIAPI Rectangle(HDC hdc, int x0, int y0, int x1, int y1)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    RECT rcOutput;

    pdc = dc_HDC2PDC(hdc);

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x0, &y0); 
    coor_LP2SP(pdc, &x1, &y1); 
    
    rcOutput.left = x0;
    rcOutput.top = y0;
    rcOutput.right = x1;
    rcOutput.bottom = y1;
    NormalizeRect (&rcOutput);
    rcOutput.right ++;
    rcOutput.bottom ++;

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->pencolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            GAL_Rectangle (pdc->gc, x0, y0, x1, y1, pdc->pencolor);
        }
            
        pClipRect = pClipRect->next;
    }
    
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
    pthread_mutex_unlock(&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}
Exemplo n.º 15
0
void CHMMDemoView::SetSelection( RECT* sel )
{
    if( sel )
    {
        m_tmp_sel = NormalizeRect( *sel );
    }
    else
    {
        CImage& img = Camera().GetFrame();
        m_tmp_sel = CRect( 0, 0, img.Width(), img.Height() );
    }
    CheckUpdate();
}
Exemplo n.º 16
0
HRESULT CDrawTxt::ICxDrawObject_MoveTo(RECTF rect, BOOL bUniformScale)
{
	BOOL bNeedCalcFontSize = !(m_rcPosition.right - m_rcPosition.left == rect.right - rect.left &&
		m_rcPosition.bottom - m_rcPosition.top == rect.bottom - rect.top);
		
	m_rcPosition = rect;
	NormalizeRect(&m_rcPosition);
	
	if (bNeedCalcFontSize && m_bAutoSize)
		ReCalcFontSize(m_dFontHeight, m_dFontWidth);
		
	return 0;
}
Exemplo n.º 17
0
/****************************** Bitmap Support *******************************/
void GUIAPI FillBox (HDC hdc, int x, int y, int w, int h)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    RECT rcOutput;

    pdc = dc_HDC2PDC(hdc);

    if (dc_IsGeneralHDC(hdc)) {
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            return;
        }
    }

    // Transfer logical to device to screen here.
    w += x; h += y;
    coor_LP2SP(pdc, &x, &y);
    coor_LP2SP(pdc, &w, &h);
    rcOutput.left = x;
    rcOutput.top  = y;
    rcOutput.right = w;
    rcOutput.bottom = h;
    NormalizeRect (&rcOutput);
    w = RECTW (rcOutput); h = RECTH (rcOutput);

    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);
    
    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->brushcolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);
        
            GAL_FillBox (pdc->gc, x, y, w, h, pdc->brushcolor);
        }

        pClipRect = pClipRect->next;
    }

    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
}
Exemplo n.º 18
0
//------------------------------------------------------    
int CRectTracker::HitTest( const LPPOINT point ) const
{
	ATLASSERT(point);

    // check handles
    RECT R = GetHandleRect(handleBegin);

    if (PtInRect(&R, *point))
        return hitBegin;

    R = GetHandleRect(handleEnd);
    if (PtInRect(&R, *point))
        return hitEnd;

    SetRect(&R, CurPos.Begin.x, CurPos.Begin.y, CurPos.End.x, CurPos.End.y );
    NormalizeRect(&R);
    RECT VicX = R;
    RECT VicY = R;

    InflateRect(&VicX, VicinitySize, 0 );
    InflateRect(&VicY, 0, VicinitySize );

    if (!PtInRect(&VicX, *point) && !PtInRect(&VicY, *point))
        return hitNothing;

    // check distance from the point to the line by x and by y
    int dx = CurPos.End.x - CurPos.Begin.x;
    int dy = CurPos.End.y - CurPos.Begin.y;
	double r = sqrt((double)(dx*dx + dy*dy));

    // compute coordinates relative to the origin of the line
    int x1 = point->x - CurPos.Begin.x;
    int y1 = point->y - CurPos.Begin.y;

    // compute coordinates relative to the line
    double x2 = (x1*dx + y1*dy)/r;
    double y2 = (-x1*dy + y1*dx)/r;

    if ((x2>=0) && (x2<=r) && (y2<=VicinitySize) && (y2 >= -VicinitySize))
        return hitMiddle;

    return hitNothing;
};
Exemplo n.º 19
0
BOOL GUIAPI IntersectClipRect (PCLIPRGN pRgn, const RECT* pRect)
{
    PCLIPRECT pCRect;
    RECT rcTemp;
 
    rcTemp = *pRect;
    if (IsRectEmpty (&rcTemp))
         return FALSE;

    NormalizeRect (&rcTemp);

    // intersect
    pCRect = pRgn->head;
    while (pCRect) {
        if (!IntersectRect (&pCRect->rc, &pCRect->rc, &rcTemp))
            SetRectEmpty(&pCRect->rc);

        pCRect = pCRect->next;
    }

    EvaluateBoundRect (pRgn);

    return TRUE;
}
Exemplo n.º 20
0
CV_INLINE CvRect RectToCvRect( RECT sr )
{
   sr = NormalizeRect( sr );
   return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
}
Exemplo n.º 21
0
//------------------------------------------------------    
void CRectTracker::SetValidRect( RECT const& Rect )
{
    ValidRect = Rect; 
    NormalizeRect(&ValidRect); 
}; 
Exemplo n.º 22
0
//------------------------------------------------------    
BOOL CRectTracker::TrackHandle( HWND hWnd, const LPPOINT point, int HitTest )
{
	ATLASSERT(point);

    if ((HitTest != hitBegin) && (HitTest != hitEnd) && (HitTest != hitMiddle))
        return FALSE;

    if (!IsValidPos())
        return FALSE;

    // set mouse cursor parameters
    RECT CursorRect;

    if (IsRectEmpty(&ValidRect))
    {
        GetClientRect(hWnd, &CursorRect);
    }
    else
    {
        // valid rectangle is not empty
        if (HitTest == hitMiddle)
        {
            RECT BeginRect = ValidRect;
			OffsetRect(&BeginRect, point->x, point->y);
			OffsetRect(&BeginRect,  -CurPos.Begin.x, -CurPos.Begin.y);
            NormalizeRect(&BeginRect);

            RECT EndRect = ValidRect;
			OffsetRect(&EndRect, point->x, point->y);
			OffsetRect(&EndRect,  -CurPos.End.x, -CurPos.End.y);
            NormalizeRect(&EndRect);

            CursorRect = ValidRect;
            IntersectRect(&CursorRect, &CursorRect, &BeginRect);
            IntersectRect(&CursorRect, &CursorRect, &EndRect);
        }
        else
            CursorRect = ValidRect;
    };

    if (IsRectEmpty(&CursorRect))
        return FALSE;

    ClientToScreen(hWnd, (LPPOINT)&CursorRect );
    ClientToScreen(hWnd, ((LPPOINT)&CursorRect)+1 );
    ClipCursor(&CursorRect);
    SetCapture(hWnd);

	// get DC for drawing
	HDC dc = GetDC(hWnd);

    // set dc parameters
    HPEN LinePen = CreatePen( PS_SOLID, LineWidth, CLR_WHITE );
    HPEN hOldPen = (HPEN)SelectObject(dc, LinePen);
    SetROP2(dc, R2_XORPEN );

    KLinePos OriginalPos = CurPos;
    BOOL bCanceled = FALSE;

    // draw the rectangle for the first time
	DrawRect(dc, &CurPos.Begin, &CurPos.End);

	// get messages until capture lost or cancelled/accepted
    BOOL bExit = FALSE;
    KLinePos NewPos;

	while (!bExit)
	{
		MSG msg;
		BOOL b = ::GetMessage(&msg, NULL, 0, 0);
		ATLASSERT(b);

		if (GetCapture() != hWnd)
			break; // exit loop

		switch (msg.message)
		{
		    // handle movement/accept messages
		    case WM_LBUTTONUP:
		    case WM_MOUSEMOVE:
                {
			        NewPos = CurPos;
                    POINT MousePoint = { (int)(short)LOWORD(msg.lParam), (int)(short)HIWORD(msg.lParam) };

                    switch (HitTest)
                    {
                        case hitBegin:
                            NewPos.Begin = MousePoint;
                            break;

                        case hitEnd:
                            NewPos.End = MousePoint;
                            break;

                        case hitMiddle:
                             NewPos.Begin.x = OriginalPos.Begin.x + (MousePoint.x-point->x);
                             NewPos.Begin.y = OriginalPos.Begin.y + (MousePoint.y-point->y);

                             NewPos.End.x = OriginalPos.End.x + (MousePoint.x-point->x);
                             NewPos.End.y = OriginalPos.End.y + (MousePoint.y-point->y);
                             break;
                    };

                    // redraw the line
                    if ((NewPos.Begin.x != CurPos.Begin.x) || (NewPos.Begin.y != CurPos.Begin.y) ||
						(NewPos.End.x != CurPos.End.x) || (NewPos.End.y != CurPos.End.y))
                    {
                        // draw new rectangle
						DrawRect(dc, &NewPos.Begin, &NewPos.End);

                        // erase old rectangle
						DrawRect(dc, &CurPos.Begin, &CurPos.End);
                    };

                    if (IsValidPos(NewPos))
                        CurPos = NewPos;

                    if (msg.message == WM_LBUTTONUP)
                        bExit = TRUE;
                };
    	        break;

		    // handle cancel messages
		    case WM_KEYDOWN:
			    if (msg.wParam == VK_ESCAPE)
                {
                    bCanceled = TRUE;
                    bExit = TRUE;
                };
			    break;

		    case WM_RBUTTONDOWN:
                bCanceled = TRUE;
                bExit = TRUE;
                break;

		    // just dispatch rest of the messages
		    default:
			    DispatchMessage(&msg);
			    break;
	    }
    };

    ClipCursor(NULL);
    ReleaseCapture();

    if (bCanceled)
        CurPos = OriginalPos;

    SelectObject(dc, hOldPen);
	DeleteObject(LinePen);
	ReleaseDC(hWnd, dc);
    return !bCanceled;
};
Exemplo n.º 23
0
void GUIAPI LineTo (HDC hdc, int x, int y)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    RECT rcOutput;
    int startx, starty;

    pdc = dc_HDC2PDC(hdc);

    startx = pdc->CurPenPos.x;
    starty = pdc->CurPenPos.y;

    // Move the current pen pos.
    pdc->CurPenPos.x = x;
    pdc->CurPenPos.y = y;

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x, &y);
    coor_LP2SP(pdc, &startx, &starty);
    rcOutput.left = startx;
    rcOutput.top  = starty;
    rcOutput.right = x;
    rcOutput.bottom = y;
    NormalizeRect (&rcOutput);
    InflateRect (&rcOutput, 1, 1);

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->pencolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            if(starty == y) {
                if (startx > x)
                    GAL_DrawHLine (pdc->gc, x, y, startx - x, pdc->pencolor);
                else
                    GAL_DrawHLine (pdc->gc, startx, y, x - startx, pdc->pencolor);
            }
            else
                GAL_Line (pdc->gc, startx, starty, x, y, pdc->pencolor);
        }
            
        pClipRect = pClipRect->next;
    }

    if (!dc_IsMemHDC (hdc)) ShowCursorForGDI (TRUE, &rcOutput);
    pthread_mutex_unlock (&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}
Exemplo n.º 24
0
void NormalizeRect(RECT& rRect)
{
	NormalizeRect(&rRect);
}
Exemplo n.º 25
0
void GUIAPI StretchBlt (HDC hsdc, int sx, int sy, int sw, int sh,
                       HDC hddc, int dx, int dy, int dw, int dh, DWORD dwRop)
{
    PCLIPRECT pClipRect;
    PDC psdc, pddc;
    void* srcBitmap = NULL; 
    void* scaledBitmap = NULL;
    RECT rcOutput;

    psdc = dc_HDC2PDC(hsdc);
    pddc = dc_HDC2PDC(hddc);

    if (dc_IsGeneralHDC(hddc)) {
        if (!dc_GenerateECRgn (pddc, FALSE)) {
            return;
        }
    }

    // Transfer logical to device to screen here.
    sw += sx; sh += sy;
    coor_LP2SP(psdc, &sx, &sy);
    coor_LP2SP(psdc, &sw, &sh);
    (sw > sx) ? (sw -= sx) : (sw = sx - sw);
    (sh > sy) ? (sh -= sy) : (sh = sy - sh);

    dw += dx; dh += dy;
    coor_LP2SP(pddc, &dx, &dy);
    coor_LP2SP(pddc, &dw, &dh);
    rcOutput.left = dx;
    rcOutput.top = dy;
    rcOutput.right = dw;
    rcOutput.bottom = dh;
    NormalizeRect (&rcOutput);
    dw -= dx; dh -= dy;

    if (!dc_IsMemHDC(hddc)) ShowCursorForGDI(FALSE, &g_rcScr);
    GAL_SetGC (psdc->gc);

    if ((srcBitmap = malloc (GAL_BoxSize (psdc->gc, sw, sh))) == NULL || 
        (scaledBitmap = malloc (GAL_BoxSize (pddc->gc, dw, dh))) == NULL)
        goto free_ret;

    GAL_GetBox (psdc->gc, sx, sy, sw, sh, srcBitmap);
    GAL_ScaleBox (psdc->gc, sw, sh, srcBitmap, dw, dh, scaledBitmap);

    GAL_SetGC (pddc->gc);

    pClipRect = pddc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pddc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            GAL_PutBox (pddc->gc, dx, dy, dw, dh, scaledBitmap);
        }

        pClipRect = pClipRect->next;
    }

free_ret:
    if (!dc_IsMemHDC(hddc)) ShowCursorForGDI (TRUE, &g_rcScr);

    free (srcBitmap);
    free (scaledBitmap);
}
Exemplo n.º 26
0
int DrawTextEx (HDC hdc, const char* pText, int nCount, 
                RECT* pRect, int indent, UINT nFormat)
{
    PDC pdc;
    int n, nLines = 0, width = 0;
    BOOL bOutput = TRUE;
    int x, y;
    RECT rcDraw, rcOutput;
    int nTabWidth, tabs; 
    SIZE size;
    int line_height;

    pdc = dc_HDC2PDC(hdc);

    if (nCount == -1)
        nCount = strlen (pText);

    line_height = pdc->pLogFont->size + pdc->alExtra + pdc->blExtra;

    if (nFormat & DT_TABSTOP)
        nTabWidth = HIWORD (nFormat) * 
                    (*pdc->pLogFont->sbc_devfont->font_ops->get_ave_width)
                    (pdc->pLogFont, pdc->pLogFont->sbc_devfont);

    else
        nTabWidth = pdc->tabstop * 
                    (*pdc->pLogFont->sbc_devfont->font_ops->get_ave_width)
                    (pdc->pLogFont, pdc->pLogFont->sbc_devfont);

    // Transfer logical to device to screen here.
    rcDraw = *pRect;
    coor_LP2SP(pdc, &rcDraw.left, &rcDraw.top);
    coor_LP2SP(pdc, &rcDraw.right, &rcDraw.bottom);
    NormalizeRect (&rcDraw);

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE))
            bOutput = FALSE;
    }

    pthread_mutex_lock (&__mg_gdilock);

    // set graphics context.
    GAL_SetGC (pdc->gc);

    // Draw text here.
    if (nFormat & DT_CALCRECT)
        bOutput = FALSE;

    y = rcDraw.top;
    if (nFormat & DT_SINGLELINE) {
        if (nFormat & DT_BOTTOM)
            y = rcDraw.bottom - pdc->pLogFont->size;
        else if (nFormat & DT_VCENTER)
            y = rcDraw.top + ((RECTH (rcDraw) - pdc->pLogFont->size) >> 1);
    }

    while (nCount != 0) {
        int nOutput;
        int maxwidth;

        if (nLines == 0) {
            maxwidth = rcDraw.right - rcDraw.left - indent;
            if (maxwidth <= 0) {
                // new line
                y += pdc->pLogFont->size;
                nLines ++;
                continue;
            }
        }
        else
            maxwidth = rcDraw.right - rcDraw.left;
        
        gdi_start_new_line (pdc->pLogFont);
        tabs = txtGetOneLine (pdc, pText, nCount, nTabWidth, maxwidth, nFormat, &n);

        gdi_get_TextOut_extent (pdc, pdc->pLogFont, pText, n, &size);
        width = size.cx + tabs * nTabWidth;
        n += tabs;

        if ( (pText[n-1] == '\n' || pText[n-1] == '\r') 
             && !(nFormat & DT_SINGLELINE) ) {
            int tmpx = 0, tmpy = 0;

            nOutput = n - 1;
            width -= gdi_width_one_char (pdc->pLogFont, pdc->pLogFont->sbc_devfont, 
                            pText + n - 1, 1, &tmpx, &tmpy);
        }
        else
            nOutput = n;
            
        if (nFormat & DT_RIGHT)
            x = rcDraw.right - width;
        else if (nFormat & DT_CENTER)
            x = rcDraw.left + ((RECTW (rcDraw) - width) >> 1);
        else
            x = rcDraw.left;
        x += (nLines ? 0 : indent);

        rcOutput.left   = x;
        rcOutput.top    = y;
        rcOutput.right  = rcOutput.left + width;
        rcOutput.bottom = rcOutput.top + line_height;
        NormalizeRect(&rcOutput);

        if (nFormat & DT_CALCRECT) {
            if (nLines == 0)
                *pRect = rcOutput;
            else
                GetBoundRect (pRect, pRect, &rcOutput);
        }

        // draw one line
        if (bOutput && width > 0) {
            if (!dc_IsMemHDC(hdc)) ShowCursorForGDI(FALSE, &rcOutput);

            if (nFormat & DT_NOCLIP)
                txtDrawOneLine (pdc, pText, nOutput, x, y, 
                        &rcOutput, nFormat, nTabWidth);
            else {
                RECT rcClip;
                IntersectRect (&rcClip, &rcOutput, &rcDraw);
                txtDrawOneLine (pdc, pText, nOutput, x, y, 
                        &rcClip, nFormat, nTabWidth);
            }
        
            if (!dc_IsMemHDC(hdc)) ShowCursorForGDI (TRUE, &rcOutput);
        }

        pText += n;

        // new line
        y += line_height;
        nLines ++;

        // left characters
        nCount = nCount - n;
    }
Exemplo n.º 27
0
BOOL GUIAPI SubtractClipRect (PCLIPRGN pRgn, const RECT* pRect)
{
    PCLIPRECT pCRect, pSaved, pTemp;
    RECT rc[4], rcTemp, rcInflated;
    int nCount;
    PRECT src, erc;
    int i;

    if (IsRectEmpty (pRect))
        return FALSE;

    rcInflated = *pRect;
    erc = &rcInflated;

    NormalizeRect (erc);

    if (!DoesIntersect(&pRgn->rcBound, erc)) {
        return FALSE;
    }

    pCRect = pRgn->head;
    while (pCRect) {

        src = &pCRect->rc;
        if (!IntersectRect(&rcTemp, src, erc)) {
            pCRect = pCRect->next;
            continue;
        }

        pSaved = pCRect->next;

        nCount = 0;
        if(erc->top > src->top)
        {
            rc[nCount].left  = src->left;
            rc[nCount].top   = src->top;
            rc[nCount].right = src->right;
            rc[nCount].bottom = erc->top;
            nCount++;

            src->top = erc->top;
        }

        if(erc->bottom < src->bottom)
        {
            rc[nCount].top  = erc->bottom;
            rc[nCount].left   = src->left;
            rc[nCount].right = src->right;
            rc[nCount].bottom = src->bottom;
            nCount++;
 
            src->bottom = erc->bottom;
        }

        if(erc->left > src->left)
        {
            rc[nCount].left  = src->left;
            rc[nCount].top   = src->top;
            rc[nCount].right = erc->left;
            rc[nCount].bottom = src->bottom;
            nCount++;
        }

        if(erc->right < src->right)
        {
            rc[nCount].left  = erc->right;
            rc[nCount].top   = src->top;
            rc[nCount].right = src->right;
            rc[nCount].bottom = src->bottom;
            nCount++;
        }

        if (nCount == 0)
            SetRectEmpty (&pCRect->rc);
        else if(nCount > 0)
            pCRect->rc = rc[0];

        for(i = 1; i<nCount; i++)
        {
            pTemp = ClipRectAlloc (pRgn->heap); 
            pTemp->rc = rc[i];
            pCRect->next = pTemp;
            pCRect = pTemp;
        }

        pCRect->next = pSaved;

        pCRect = pSaved;
    }

    EvaluateBoundRect (pRgn);

    return TRUE;
}
Exemplo n.º 28
0
void GUIAPI DrawIcon(HDC hdc, int x, int y, int w, int h, HICON hicon)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    PICON picon = (PICON)hicon;
    int i;
    int imagesize;
    BYTE* iconimage;
    BYTE* andbits = NULL;
    BYTE* xorbits = NULL;
    RECT rcOutput;

    pdc = dc_HDC2PDC(hdc);

    if (dc_IsGeneralHDC(hdc)) {
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            return;
        }
    }

    if(w <= 0) w = picon->width;
    if(h <= 0) h = picon->height;

    // Transfer logical to device to screen here.
    w += x;
    h += y;
    coor_LP2SP(pdc, &x, &y);
    coor_LP2SP(pdc, &w, &h);
    rcOutput.left = x;
    rcOutput.top  = y;
    rcOutput.right = w;
    rcOutput.bottom = h;
    NormalizeRect (&rcOutput);
    w = RECTW (rcOutput);
    h = RECTH (rcOutput);

    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    GAL_SetGC (pdc->gc);

    imagesize = w * h * GAL_BytesPerPixel (pdc->gc);
    if ((iconimage = malloc (imagesize)) == NULL)
        goto free_ret;

    if (w != picon->width || h != picon->height) {
        andbits = malloc (imagesize);
        xorbits = malloc (imagesize);
        if (andbits == NULL || xorbits == NULL)
            goto free_ret;

        GAL_ScaleBox (pdc->gc, picon->width, picon->height, picon->AndBits, w, h, andbits);
        GAL_ScaleBox (pdc->gc, picon->width, picon->height, picon->XorBits, w, h, xorbits);
    }
    else {
        andbits = picon->AndBits;
        xorbits = picon->XorBits;
    }

    GAL_GetBox (pdc->gc, x, y, w, h, iconimage);

    for(i = 0; i < imagesize; i++) {
        iconimage[i] &= andbits [i];
        iconimage[i] ^= xorbits [i];
    }

    pClipRect = pdc->ecrgn.head;
    while (pClipRect) {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                            pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            GAL_PutBox(pdc->gc, x, y, w, h, iconimage);
        }

        pClipRect = pClipRect->next;
    }

free_ret:
    if (!dc_IsMemHDC(hdc)) ShowCursorForGDI (TRUE, &rcOutput);

    free (iconimage);
    if (w != picon->width || h != picon->height) {
        free (andbits);
        free (xorbits);
    }
}
Exemplo n.º 29
0
BOOL GUIAPI FillBoxWithBitmapPart (HDC hdc, int x, int y, int w, int h,
                int bw, int bh, const BITMAP* pBitmap, int xo, int yo)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    void* scaledBitmap = NULL;
    void* partBitmap = NULL;
    int sw = pBitmap->bmWidth, sh = pBitmap->bmHeight;
    RECT rcOutput;
    int bpp;

    if (pBitmap->bmWidth <= 0 || pBitmap->bmHeight <= 0 || pBitmap->bmBits == NULL)
        return FALSE;

    pdc = dc_HDC2PDC(hdc);
    bpp = GAL_BytesPerPixel (pdc->gc);

    if (dc_IsGeneralHDC(hdc)) {

        if (!dc_GenerateECRgn (pdc, FALSE)) {
            return TRUE;
        }
    }

    // Transfer logical to device to screen here.
    w += x; h += y;
    coor_LP2SP(pdc, &x, &y);
    coor_LP2SP(pdc, &w, &h);
    rcOutput.left = x;
    rcOutput.top = y;
    rcOutput.right = w;
    rcOutput.bottom = h;
    NormalizeRect (&rcOutput);
    w = RECTW (rcOutput); h = RECTH (rcOutput);

    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC(pdc->gc);

    if (bw <= 0 || bh <= 0) {
        scaledBitmap = pBitmap->bmBits;
        bw = sw;
        bh = sh;
    }
    else if (bw == sw && bh == sh)
        scaledBitmap = pBitmap->bmBits;
    else {
        if ((scaledBitmap = malloc (GAL_BoxSize(pdc->gc, w, h))) == NULL)
            goto free_ret;
        GAL_ScaleBox (pdc->gc, sw, sh, pBitmap->bmBits, bw, bh, scaledBitmap);
    }

    // extract part box
    if ((partBitmap = malloc (GAL_BoxSize(pdc->gc, w, h))) == NULL)
        goto free_ret;
    bmpGetBoxPart (bpp, w, h, partBitmap, bw, bh, scaledBitmap, xo, yo);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            if (pBitmap->bmType != BMP_TYPE_COLORKEY)
                GAL_PutBox (pdc->gc, x, y, w, h, partBitmap);
            else
                GAL_PutBoxMask (pdc->gc, x, y, w, h, partBitmap, pBitmap->bmColorKey);
        }

        pClipRect = pClipRect->next;
    }

free_ret:
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);

    if (bw != sw || bh != sh)
        free (scaledBitmap);
    free (partBitmap);

    return TRUE;
}