Пример #1
0
void CChooseClrAnimList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC *pDC;

	pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
	//dc.Attach(lpDrawItemStruct->hDC);

	CRect rcDraw = lpDrawItemStruct->rcItem;

	if (lpDrawItemStruct->itemID >= 0)
	{
		if (lpDrawItemStruct->itemAction & ODA_SELECT)
		{
			CBrush brRect;
			if (lpDrawItemStruct->itemState & ODS_SELECTED)
			{
				// Draw selection
				brRect.CreateSolidBrush( RGB(0, 0, 128));
			}
			else
			{
				brRect.CreateSolidBrush( RGB(255, 255, 255) );
			}

			pDC->FillRect( rcDraw, &brRect );
		}
		
		CString sTxt;
		GetText(lpDrawItemStruct->itemID, sTxt);

		CK_FAVOURITE *pFavourite = (CK_FAVOURITE *)GetItemData(lpDrawItemStruct->itemID);

		CSize szText = pDC->GetTextExtent( sTxt );

		pDC->TextOut(rcDraw.left + 2, rcDraw.top + (rcDraw.Height() / 2) - (szText.cy / 2), sTxt);

		// Draw the keyframes

		CRect rcFrame;
		rcFrame.left   = rcDraw.left + szText.cx + 10;
		rcFrame.top	   = rcDraw.top + 2;
		rcFrame.right  = rcDraw.right;
		rcFrame.bottom = rcDraw.bottom - 2;

		CBrush brBlack(RGB(0, 0, 0));
		pDC->FrameRect(&rcFrame, &brBlack);

		// Fill in the frame with the colour keys

		rcFrame.left ++;
		rcFrame.top ++;
		rcFrame.bottom --;
		rcFrame.right --;

		m_posColRatio = 1.0f / rcFrame.Width();

		for (int i = 0; i < rcFrame.Width(); i ++)
		{
			int r, g, b;

			PosToCol(pFavourite, i, &r, &g, &b);
				
			CBrush brCol(RGB(r, g, b));
			pDC->FillRect(CRect(i + rcFrame.left, rcFrame.top, rcFrame.left + i + 1, rcFrame.Height() + rcFrame.top), &brCol);
		}
	}
}
Пример #2
0
void KkrBoardView::drawCell(QPainter &p, int col, int row) const
{
    static const char * digits[] = {
        " ",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
        "40", "41", "42", "43", "44", "45"
    };
    const QRect cellRect{getCellRect(col, row)};
    switch(m_pBoardData->getCellType(col, row)) {
    case CellType::CellAnswer:
    {
        if(m_curCol == col && m_curRow == row) {
            QBrush brCyan(Qt::cyan);
            p.fillRect(cellRect, brCyan);
        }
        const int ans = m_pBoardData->getAnswer(col, row);
        if(ans != EMPTY_ANSWER) {
            p.setFont(m_fontAns);
            p.drawText(cellRect, Qt::AlignCenter | Qt::AlignHCenter, digits[ans]);
        }
    }
        break;
    case CellType::CellClue:
    {
        const bool onCursor = m_curCol==col && m_curRow==row;
        QBrush brWhite(Qt::white);
        QBrush brBlack(Qt::black);
        QBrush brCyan(Qt::cyan);

        if(onCursor && m_curClue==CursorClue::None)
            p.setBrush(brCyan);
        else
            p.setBrush(brBlack);
        std::array<QPoint, 3> points;

        // upper right triangle
        points[0] = cellRect.topLeft(); points[0] += QPoint(2,1);
        points[1] = cellRect.topRight(); points[1] += QPoint(-1,1);
        points[2] = cellRect.bottomRight(); points[2] += QPoint(-1,-2);
        p.drawPolygon(points.data(), static_cast<int>(points.size()));

        // bottom left triangle
        points[0] = cellRect.topLeft(); points[0] += QPoint(1,2);
        points[1] = cellRect.bottomLeft(); points[1] += QPoint(1,-1);
        points[2] = cellRect.bottomRight(); points[2] += QPoint(-2,-1);
        p.drawPolygon(points.data(), static_cast<int>(points.size()));

        if(m_pBoardData->getClueRight(col, row) != CLOSED_CLUE) {
            const QRect clueRect{getClueRectRight(cellRect)};
            if(onCursor && m_curClue==CursorClue::Right)
                p.fillRect(clueRect, brCyan);
            else
                p.fillRect(clueRect, brWhite);
            p.setFont(m_fontClue);
            p.drawText(clueRect, Qt::AlignCenter | Qt::AlignHCenter,
                        digits[m_pBoardData->getClueRight(col, row)]);
        }

        if(m_pBoardData->getClueDown(col, row) != CLOSED_CLUE) {
            const QRect clueRect{getClueRectDown(cellRect)};
            if(onCursor && m_curClue==CursorClue::Down)
                p.fillRect(clueRect, brCyan);
            else
                p.fillRect(clueRect, brWhite);
            p.setFont(m_fontClue);
            p.drawText(clueRect, Qt::AlignCenter | Qt::AlignHCenter,
                       digits[m_pBoardData->getClueDown(col, row)]);
        }
    }
        break;
    default:
        Q_ASSERT(false);
    }
}