⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxbutton.cpp

📁 PW芯片方案Flash ROM烧写程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            x2      = m_nVWidth + FRAME_BORDER * 2;
            y2      = y1;
            cn      = xn++;
        }

        SetupForLine( pLI );

        DrawLine( x1, y1, x2, y2 );

        if( GetShowNumbers() ) {
            COLORREF oldBk  = m_pDC->SetBkColor(pLI->crColor);
            COLORREF oldTx  = m_pDC->SetTextColor( RGB(0,255,0) );

            DrawOffset( x1, y1, x2, y2, pLI->bVertical, cn, i, pLI->nOffset );

            m_pDC->SetBkColor(oldBk);
            m_pDC->SetTextColor(oldTx);
        }
    }

    ResetLine();
}

void CSXButton::DrawBoxes(void)
{
}

void CSXButton::DrawFrameBoxes(void)
{
}

void CSXButton::Cook( long& nValue, int nOffset )
{
    nValue  = nOffset + nValue * m_nScale + FRAME_BORDER;
}

void CSXButton::DrawBox( const CRect& rect, CBrush& br, COLORREF cr )
{
    CRect       orect(rect);

    Cook(orect.top,      m_nOffsetY);
    Cook(orect.bottom,   m_nOffsetY);
    Cook(orect.left,     m_nOffsetX);
    Cook(orect.right,    m_nOffsetX);

    m_pDC->FillRect( &orect, &br );
}

int CSXButton::AddLine( const int nType, const int nPenStyle, const int nWidth, 
                        const COLORREF crColor, BOOL bVertical, int nOffset )
{
    ASSERT( m_nLines < MAX_LINES-1 );

    LineInfo&   l   = m_sLines[m_nLines];
    
    l.nType         = nType;
    l.nPenStyle     = nPenStyle;
    l.nWidth        = nWidth;
    l.crColor       = crColor;
    l.bVertical     = bVertical;
    l.nOffset	    = nOffset;	
    l.nLeftIndex    = LNONE;
    l.nRightIndex   = LNONE;
    l.nTopIndex     = LNONE;
    l.nBottomIndex  = LNONE;

    return m_nLines++;
}

void CSXButton::DrawDimensions(void)
{
}

void CSXButton::DrawFrameDimensions(void)
{
}

void CSXButton::DrawDim( const CRect& rect, COLORREF cr, BOOL bVertical )
{
}

int CSXButton::GetHOffset( const int nPercent )

{
    return (m_nImageWidth * nPercent) / 100;;
}    

int CSXButton::GetVOffset( const int nPercent )
{
    return (m_nImageHeight * nPercent) / 100;;
}    

int CSXButton::AddOffsetLine( int nType, const int nOffset, const BOOL bVertical )
{
    COLORREF    crColor;

    switch( nType ) 
    {
        case _BORDER:
            crColor     = _BORDER_CLR;
            break;
        case _NORMAL:
            crColor     = _NORMAL_CLR;
            break;
        case _SELECT:
            crColor     = _SELECT_CLR;
            break;
    }

	return AddLine( nType, PS_SOLID, LINE_WIDTH, crColor, bVertical, nOffset );
}

void CSXButton::LimitLineRange( int nIndex, 
                int nLeftIndex, int nRightIndex, 
                int nTopIndex, int nBottomIndex )
{
    LineInfo&   l   = m_sLines[nIndex];
    
    l.nLeftIndex      = nLeftIndex;
    l.nRightIndex     = nRightIndex;
    l.nTopIndex       = nTopIndex;
    l.nBottomIndex    = nBottomIndex;
}

//  this determines if the new cell we want to move the line to 
//  is valid in the clipped world of the newer blitmap editor JimB 1/4/00
BOOL CSXButton::AdjustForClipping( int& nNewCell, int nOldCell )
{
    LineInfo&      l            = m_sLines[m_nCaptureLine];
    int            nBoundLess, nBoundMore;
    BOOL           bReturn;

    // determine if it's inbounds
    if( l.bVertical ) 
    {
        if( l.nLeftIndex == LNONE )
            nBoundLess  = 0;
        else if( l.nLeftIndex == LEDGE )
            nBoundLess  = 0;
        else
            nBoundLess  = m_sLines[l.nLeftIndex].nOffset;

        if( l.nRightIndex == LNONE )
            nBoundMore  = m_nWidth;
        else if( l.nRightIndex == LEDGE )
            nBoundMore  = m_nWidth;
        else
            nBoundMore  = m_sLines[l.nRightIndex].nOffset;

        // adjust the bounds of the greater if it's not specified.
        if( nBoundMore == PLACEHOLDER )
            nBoundMore  = m_nWidth;
    } else
    {
        if( l.nTopIndex == LNONE )
            nBoundLess  = 0;
        else if( l.nTopIndex == LEDGE )
            nBoundLess  = 0;
        else
            nBoundLess  = m_sLines[l.nTopIndex].nOffset;

        if( l.nBottomIndex == LNONE )
            nBoundMore  = m_nHeight;
        else if( l.nBottomIndex == LEDGE )
            nBoundMore  = m_nHeight;
        else
            nBoundMore  = m_sLines[l.nBottomIndex].nOffset;

        // adjust the bounds of the greater if it's not specified.
        if( nBoundMore == PLACEHOLDER )
            nBoundMore  = m_nHeight;
    }

    // adjust the bounds of the lesser if it's not specified.
    if( nBoundLess == PLACEHOLDER )
        nBoundLess  = 0;

    if( nNewCell < nBoundLess ) 
        nNewCell    = nBoundLess;
        
    if( nNewCell > nBoundMore )
        nNewCell    = nBoundMore;

    // return if the new cell continues to be different than old cell
    bReturn = (nNewCell != nOldCell);

//static int nCount = 0; CString s; s.Format( "%3d new %3d range %3d/%3d %s\n", ++nCount, nNewCell, nBoundLess, nBoundMore, (bReturn ? "TRUE" : "FALSE")); ODBG(s);

    return bReturn;
}

void CSXButton::ClearLines(void)
{
    m_nLines        = 0;
}

void CSXButton::SetupForLine( LineInfo *plineInfo )
{
    if( m_bCurLineInfoOk == FALSE ) 
    {
        ResetPen();

        SetPen( plineInfo->nPenStyle, plineInfo->nWidth, plineInfo->crColor );

    }
}

void CSXButton::ResetLine(void)
{
    ResetPen();

    m_bCurLineInfoOk    = FALSE;
}

BOOL CSXButton::FindLine( CPoint& point )
{
    // find the correct line for the point given. 
    LineInfo       *pLI     = &m_sLines[0];
    BOOL            bFound  = FALSE;
    int             i, nIndex;

    if( m_nLines == 0 ) return FALSE;

	// first look for contact in the rectangles for the match
    for( i = 0; !bFound && i < m_nLines; i++, pLI++ ) 
    {
		CRect	rect	= m_rectHandles[i];

        rect.InflateRect( SELECT_SLOP, SELECT_SLOP  );

/*
        CString strMsg;
        strMsg.Format("Compare pt %d,%d to recth %d,%d,%d,%d\n",
                    point.x, point.y, rect.left,rect.top,rect.right,rect.bottom );
        OutputDebugString( strMsg );
*/

        bFound  = rect.PtInRect( point );

		if( bFound )
			nIndex	= i;
    }

	pLI     = &m_sLines[0];

	// look at the lines themselves
    for( i = 0; !bFound && i < m_nLines; i++, pLI++ ) 
    {
        CRect   rect 	= GetLineRect( pLI );

        rect.InflateRect( SELECT_SLOP, SELECT_SLOP  );

/*
        CString strMsg;
        strMsg.Format("Compare pt %d,%d to line %d,%d,%d,%d\n",
                    point.x, point.y, rect.left,rect.top,rect.right,rect.bottom );
        OutputDebugString( strMsg );
*/
        bFound  = rect.PtInRect( point );

		if( bFound )
			nIndex	= i;
    }

    if( bFound ) 
    {
        m_nCaptureLine  = nIndex;

		// setup up the offset for the 
/*
		pLI     		= &m_sLines[m_nCaptureLine];
		CRect rect		= GetLineRect( pLI );

		if( pLI->bVertical ) {
			m_ptOffsetX	= 
		}
*/
/*
        CString strMsg;
        strMsg.Format("Found at index %d\n", m_nCaptureLine );
        OutputDebugString( strMsg );
*/
    }

    return bFound;
}

BOOL CSXButton::MoveLine( CPoint& point )
{
    LineInfo       *pLI         = &m_sLines[m_nCaptureLine];
    BOOL            bChanged    = FALSE;
    int             nNewCell;

    // see if we are on a new cell for user.
    if( pLI->bVertical ) 
    {
        nNewCell     = (point.x + (m_nScale>>1) - m_nOffsetX) / m_nScale;

        // we have to be even boundary for bitmap blit widths
        if( nNewCell & 0x01 ) 
            nNewCell    -= 1;

        // update info for where capture is on screen
        m_nCapX     = nNewCell;
        m_nCapY     = -1;
    } else
    {
        nNewCell     = (point.y + (m_nScale>>1) - m_nOffsetY) / m_nScale;

        // we have to be even boundary for bitmap blit heights as well..
        if( nNewCell & 0x01 ) 
            nNewCell    -= 1;

        // update info for where capture is on screen
        m_nCapX     = -1;
        m_nCapY     = nNewCell;
    }

    bChanged    = (nNewCell != pLI->nOffset);

    // if we want to move it, check to see if should clip to a boundary.
    if( bChanged )
        bChanged = AdjustForClipping( nNewCell, pLI->nOffset );

    if( bChanged  ) 
    {
        pLI->nOffset = nNewCell;

        // with the pen crosshatching need to invalidate all.
        Redraw();

        m_bIsChanged    = TRUE;
    }

    return bChanged;
}


BOOL CSXButton::FindMagnet( CPoint& point )
{
    return FALSE;
}

BOOL CSXButton::MoveMagnet( CPoint& point )
{
    return FALSE;
}

void CSXButton::MoveMagnetDone(void)
{
}

void CSXButton::InvalidateLineRect( LineInfo *plineInfo )
{
    CRect       rect    = GetLineRect( plineInfo );

    if( plineInfo->bVertical )
        rect.InflateRect( OFFSET*2, 0 );
    else
        rect.InflateRect( 0, OFFSET*2 );

    InvalidateRect( rect, TRUE );    
}

CRect CSXButton::GetLineRect( LineInfo *plineInfo )
{
    int             x1, y1, x2, y2;

    // determine the coordinates of the line in screen units.
    if( plineInfo->bVertical ) 
    {
        x1      = m_nOffsetX + plineInfo->nOffset * m_nScale - plineInfo->nWidth + FRAME_BORDER;
        y1      = FRAME_BORDER;
        x2      = x1 + plineInfo->nWidth * 2;
        y2      = m_nVHeight + FRAME_BORDER * 2;
    } else
    {
        x1      = FRAME_BORDER;
        y1      = m_nOffsetY + plineInfo->nOffset * m_nScale - plineInfo->nWidth + FRAME_BORDER;
        x2      = m_nVWidth + FRAME_BORDER * 2;
        y2      = y1 + plineInfo->nWidth * 2;
    }

    return CRect( x1, y1, x2, y2 );
}

void CSXButton::SetGraphicScale( const int nScale )					
{ 
}


void CSXButton::SetLines(void)
{

}    

void CSXButton::GetLines(void)
{
}    

void CSXButton::LowHighTest( int& nLow, int& nHigh )
{
    if( nLow > nHigh ) 
    {
        int     nSwap   = nLow;
        nLow    = nHigh;
        nHigh   = nSwap;
    }
}    

BOOL CSXButton::LoadBlitMap(void)
{

    return TRUE;
}

void CSXButton::StoreBlitMap( BOOL bForce )
{
}    


void CSXButton::PaintBkgnd(void)
{
	CRect 		rect    = m_rcItem;
	CBrush		brush;
	int			fx, fy, lx, ly;
	int			x, y, ax, ay;
	int			dx, dy;

    rect.DeflateRect( FRAME_BORDER, FRAME_BORDER );

	brush.CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
	m_pDC->FillRect(&rect, &brush);

	if( m_nScale >= 3 ) {

		dx	= m_nScale * 2;
		dy	= m_nScale * 2;
//		fx	= m_nOffsetX % m_nScale;    // align the X offset so it starts at even boundary for scale size
		fx	= 0;
		fy	= 0;
		lx	= rect.right;
		ly	= rect.bottom;

//        CString strMsg; strMsg.Format("Offset %d scale %d mod %d\n", m_nOffsetX, m_nScale, fx);
//        OutputDebugString( strMsg );

		// overlay grid points..
		for( y = fy; y < ly; y += dy ) {

			ay	= y + FRAME_BORDER;

			for( x = fx; x < lx; x += dx ) {

				ax	= x + FRAME_BORDER;

				m_pDC->SetPixel( ax, ay, RGB(0,0,0) );
			}	
		}
	}
}

BOOL CSXButton::OnEraseBkgnd(CDC* pDC) 
{
    // prevent flashing.
	return 0L;
}

void CSXButton::AddMagnet( BOOL bNE, BOOL bNW, BOOL bSE, BOOL bSW, BOOL bCE )
{
}

void CSXButton::DrawMagnets(void)
{
}

void CSXButton::ValidateAllMagnets(void)
{
}

void CSXButton::ValidateMagnet( int nIndex )
{
}

void CSXButton::DrawLocation(void)
{
    CString     strLoc;

    if( m_nCapX >= 0 && m_nCapY >= 0 ) 
        strLoc.Format( "X/Y %d,%d", m_nCapX, m_nCapY );
    else if( m_nCapY >= 0 ) 
        strLoc.Format( "Y %d", m_nCapY );
    else if( m_nCapX >= 0 ) 
        strLoc.Format( "X %d", m_nCapX);

    if( strLoc.GetLength() ) {
        COLORREF    cr(RGB(0,0,0));
        CBrush      br(cr);
        CBrush      brf(RGB(255,255,255));
        CRect       rect;
        COLORREF    oldText, oldBack;

        GetClientRect( &rect );

        rect.left   = rect.right - 100;
        rect.top    = rect.bottom - 40;

        m_pDC->FrameRect( &rect, &brf );
        rect.DeflateRect( 2,2 );
	    m_pDC->FillRect( &rect, &br );

	    oldText = m_pDC->SetTextColor( RGB(255,255,255) );
	    oldBack = m_pDC->SetBkColor(   cr );

        rect.DeflateRect( 5,5 );
	    m_pDC->DrawText(strLoc, &rect, DT_CENTER | DT_SINGLELINE | DT_NOPREFIX);

	    m_pDC->SetTextColor( oldText );
	    m_pDC->SetBkColor( oldBack );
    }
}

CString	CSXButton::GetInfo(void)
{
	CString	strRet;
	char	*pColor;
	BITMAP	bm;

    GetObject(m_hBitmap,sizeof(BITMAP),&bm);

    switch (bm.bmBitsPixel) {
    case 1:
		pColor	= "Mono";
        break;
    case 4:
		pColor	= "16";
        break;
    case 8:
		pColor	= "256";
        break;
    case 16:
		pColor	= "65K";
        break;
    case 24:
		pColor	= "16 million";
        break;
    default:
		pColor	= "???";
        break;
    }

	strRet.Format("Size: %dx%d Clrs: %s", bm.bmWidth, bm.bmHeight, pColor);

	return strRet;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -