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

📄 fodropcolorpalettecontrol.cpp

📁 visual c++ 实例编程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}
	}
}

void CFODropColorPaletteControl::DrawLine(CDC *pDC, CPoint& start, CPoint& end, COLORREF color)
{
	CPen pen(PS_SOLID,1,color);
	CPen* oldPen = pDC->SelectObject(&pen);
	
	DrawLine(pDC, start, end);
	
	pDC->SelectObject(oldPen);
}

void CFODropColorPaletteControl::DrawLine(CDC *pDC, int xStart, int yStart, int xEnd, int yEnd)
{
	pDC->MoveTo(xStart, yStart);
	pDC->LineTo(xEnd, yEnd);
}

void CFODropColorPaletteControl::DrawLine(CDC *pDC, int xStart, int yStart, int xEnd, int yEnd, COLORREF color)
{
	CPen pen(PS_SOLID,1,color);
	CPen* oldPen = pDC->SelectObject(&pen);
	
	DrawLine(pDC, xStart, yStart, xEnd, yEnd);
	
	pDC->SelectObject(oldPen);
}

void CFODropColorPaletteControl::OnDraw(CDC *pDC)
{
	CFont *pfdc;
	pfdc = pDC->SelectObject(&fText);

	CRect rectClient;
	rectClient = m_rcPosition;

	CRect rcPos = CRect(rectClient.left + nMainBorderSize,rectClient.top + 4,rectClient.right - nMainBorderSize,rectClient.bottom);
	rcPos.bottom = rcPos.top + 6;
	
	pDC->FillSolidRect(rectClient, gfxData.m_crBtnFace);

	if(m_bPopup)
	{
		pDC->FillSolidRect(rcPos,gfxData.m_crAcCaption);
	}

	DrawOtherBorder(pDC,rectClient,nBorderType);
	
	CFOColorCellObj* pSelCell = NULL;
	
	for (int i = 0; i < FO_TOTAL_DROP_COLOR_CELLS; i ++)
	{
		
		m_crCells[i].OnDraw(pDC);
		
		if (m_crCells[i].GetCellColor() == m_crCurColor)
		{
			pSelCell = &m_crCells[i];
		}
	}
	
	if (pSelCell != NULL)
	{
		pSelCell->OnDrawSelect (pDC);
		if(bHasCustomBar)
		{
			CRect rcX = rcSep;
			rcX.bottom -= 2;
			pDC->Draw3dRect(rcX,gfxData.m_crBtnShadow,RGB(255,255,255));
			OnCustomDraw(pDC,FALSE);
			if(m_bCustomSelect)
			{
				OnCustomDrawSelect(pDC);
			}
		}
	}
	else
	{
		if(bHasCustomBar)
		{
			CRect rcX = rcSep;
			rcX.bottom -= 2;
			pDC->Draw3dRect(rcX,gfxData.m_crBtnShadow,RGB(255,255,255));
			OnCustomDraw(pDC,TRUE);
			if(m_bCustomSelect)
			{
				OnCustomDrawSelect(pDC);
			}
		}
	}
	pDC->SelectObject(pfdc);
}

void CFODropColorPaletteControl::ComputeColors()
{
	int nTotal;
	nTotal = 0;
	for (int nCols=0; nCols < 6; nCols++)
	{
		for (int nRow=0; nRow < 8; nRow++)
		{
			m_crCells[nTotal].SetCellColor(ColorMap[nRow][nCols]);
			nTotal ++;
		}
	}
}

void CFODropColorPaletteControl::AdjustCells(CRect rcPos)
{
	CRect rcTotal = rcPos;
	rcCells = rcTotal;
	
	// Determine the total width & height budgets.
	double MaxPixWide = double(rcTotal.Width());
	double maxPixHigh = double(rcTotal.Height());
	
	double dX;
	dX = 0;
	
	int *widthArray = new int[m_nCols+1];
	{
		double dlta = (double)(1/(double)m_nCols);
		for ( int i = 0 ; i < m_nCols+1 ; i++ ) 
		{
			int x = rcTotal.left + int(double((MaxPixWide)*dlta*i));
			widthArray[i] = x;
		}
	}
	int *heightArray = new int[m_nRows+1];
	{
		double dlta = double(1/(double)m_nRows);
		for ( int i = 0 ; i < m_nRows+1 ; i++ ) 
		{
			heightArray[i] = rcTotal.top + int(double((maxPixHigh)*dlta*i));
		}
	}
	
	CRect rcTemp;
	CRect rcOther;
	int nDay, nWeek;
	for (int x = 0 ; x < FO_TOTAL_DROP_COLOR_CELLS ; x++ )
	{
		nDay = x % m_nCols;
		nWeek = x / m_nCols ;
		rcTemp =  CRect(widthArray[nDay],heightArray[nWeek],widthArray[nDay+1],heightArray[nWeek+1]);
		m_crCells[x].SetRect(&rcTemp);
		m_crCells[x].SetFirstType(FALSE);
	}
	delete []heightArray;
	delete []widthArray;
}

void CFODropColorPaletteControl::CaptureMouse(BOOL bCapture)
{
	if(bCapture)
	{
		m_pParent->SetCapture();
	}
	else
	{
		ReleaseCapture();
	}
}

void CFODropColorPaletteControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	nChar; 
	nRepCnt; 
	nFlags; 
	
}

void CFODropColorPaletteControl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	nFlags;
	if(m_bCustomSelect)
	{
		m_bCustomSelect = FALSE;
		InvalRect(rcCustom);
	}
	for ( int i = 0 ; i < FO_TOTAL_DROP_COLOR_CELLS ; i++ ) 
	{
		if ( m_crCells[i].HitTest(point) )
		{
			OnSelectOK((WPARAM)(m_crCells[i].GetCellColor()),0);
			return;
		}
	}
	if(rcCustom.PtInRect(point))
	{
		if(bHasCustomBar)
		{
			m_pParent->PostMessage( WM_FO_SELECTCOLORCUSTOM, (WPARAM)(m_crCurColor), 0 );
			if(m_bPopup)
			{
				m_pParent->ShowWindow(SW_HIDE);
			}
		}
	}
}

void CFODropColorPaletteControl::OnSelectOK(WPARAM wParam, LPARAM lParam)
{
	m_pParent->PostMessage( WM_FO_SELECTCOLOROK, wParam, lParam );
	if(bHasCustomBar)
	{
		UpdateCustom();
	}
	if(m_bPopup)
	{
		m_pParent->ShowWindow(SW_HIDE);
	}
}

void CFODropColorPaletteControl::OnSelectCancel(WPARAM wParam, LPARAM lParam)
{
	m_pParent->PostMessage( WM_FO_SELECTCOLORCANCEL, wParam, lParam );
	if(bHasCustomBar)
	{
		UpdateCustom();
	}
	if(m_bPopup)
	{
		m_pParent->ShowWindow(SW_HIDE);
	}
}

void CFODropColorPaletteControl::OnMouseMove(UINT nFlags, CPoint point) 
{
	nFlags;
	CFOColorCellObj* pSel = HitTest(point);
	if(pSel != NULL)
	{
	}
	else if(rcCustom.PtInRect(point))
	{
		if(bHasCustomBar)
		{
			m_bCustomSelect = TRUE;
			InvalRect(rcCustom);
		}
	}
}

void CFODropColorPaletteControl::OnCancelMode()
{
	
}
void CFODropColorPaletteControl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	nFlags; 
	point; 
}

void CFODropColorPaletteControl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	nFlags; 
	point; 
	
}

void CFODropColorPaletteControl::OnRButtonDown(UINT nFlags, CPoint point) 
{
	nFlags; 
	point; 
}

void CFODropColorPaletteControl::OnCustomDraw(CDC *pDC,BOOL bHasColor)
{
	ASSERT_VALID (pDC);
	pDC->FillSolidRect(rcCustom,gfxData.m_crBtnFace);
	rcCustom = rcCustomSave;
	if(bHasColor)
	{
		CRect rcItem;
		rcItem = rcCustom;
		rcItem.left = rcItem.right -21;
		rcCustom.right = rcItem.left-2;
		
		CRect rcTemp;
		rcTemp = rcCustom;
		rcTemp.DeflateRect(2,2,2,2);
		CPen pen (PS_SOLID, 1, gfxData.m_crBtnShadow);
		CPen* pOldPen = pDC->SelectObject(&pen);
		
		CString strText;
		strText = strCustom;
		if (strText.GetLength())
		{
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(0);
			pDC->DrawText(strText, rcTemp, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
		}
		
		pDC->SelectObject (pOldPen);
		pDC->Draw3dRect(rcItem,gfxData.m_crBtnShadow,RGB(255,255,255));
		rcItem.DeflateRect(4,4,4,4);
		pDC->FillSolidRect(rcItem,m_crCurColor);
		pDC->Draw3dRect(rcItem,gfxData.m_crBtnShadow,gfxData.m_crBtnShadow);
	}
	else
	{
		CRect rcPos;
		rcPos = rcCustom;
		rcPos.DeflateRect(2,2,2,2);
		CPen pen (PS_SOLID, 1, gfxData.m_crBtnShadow);
		CPen* pOldPen = pDC->SelectObject(&pen);
		
		CString strText;
		strText = strCustom;
		if (strText.GetLength())
		{
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(0);
			pDC->DrawText(strText, rcPos, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
		}
		
		pDC->SelectObject (pOldPen);
	}
}

void CFODropColorPaletteControl::OnCustomDrawSelect(CDC *pDC)
{
	ASSERT_VALID (pDC);
	
	CBrush* pBrWhite = CBrush::FromHandle ((HBRUSH) ::GetStockObject (WHITE_BRUSH));
	ASSERT_VALID (pBrWhite);
	
	CBrush* pBrBlack = CBrush::FromHandle ((HBRUSH) ::GetStockObject (BLACK_BRUSH));
	ASSERT_VALID (pBrBlack);
	
	CRgn rgnOne, rgnTwo, rgnThree;
	
	CRect rcPos;
	rcPos = rcCustom;
	rcPos.DeflateRect(1,1,1,1);
	
	rgnTwo.CreateRectRgnIndirect(&rcPos);
	pDC->FrameRgn(&rgnTwo, pBrWhite, 2, 2);
	
	rcPos.InflateRect(2,2,2,2);
	
	rgnThree.CreateRectRgnIndirect(&rcPos);
	pDC->FrameRgn(&rgnThree, pBrBlack, 1, 1);
	
}


void CFODropColorPaletteControl::SetCustomBar(const BOOL bCustom)
{
	bHasCustomBar = bCustom;
}

void CFODropColorPaletteControl::SetMainBorderSize(const int nBorder)
{
	nMainBorderSize = nBorder;
}

void CFODropColorPaletteControl::UpdateCustom()
{
	InvalRect(rcCustomSave);
}

void CFODropColorPaletteControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	nFlags;
	nRepCnt;
	// Determine if the CONTROL key is pressed...
	int ks = GetKeyState( VK_CONTROL );
	ks >>= ((sizeof(int)*8)-1);

	int nCurSel  = 0;
	for (int i = 0; i < FO_TOTAL_DROP_COLOR_CELLS; i ++)
	{
		if (m_crCells[i].GetCellColor() == m_crCurColor)
		{
			nCurSel = i;
			break;
		}
	}

	int m_nCurCol = nCurSel % m_nCols;
	int m_nCurRow = nCurSel / m_nCols ;

	int nNewCol = m_nCurCol;
	int nNewRow = m_nCurRow;

	switch(nChar) 
	{
	case VK_LEFT:
		{
			if(m_nCurCol > 0) 
			{
				nNewCol--;
			}
			else if(m_nCurRow == 0)
			{
				if(m_nCurCol == 0 && m_nCurRow == 0)
				{
					nNewCol = m_nCurCol;
					nNewRow = m_nCurRow;
				}
				else
				{
					nNewCol = m_nCols-1, nNewRow = m_nRows - 1;
				}
			}
			else
			{
				nNewCol = m_nCols - 1, nNewRow--;
			}
			nCurSel = nNewRow * 8 + nNewCol;
			SetRGB(m_crCells[nCurSel].GetCellColor());
		}
		break;
		
	case VK_RIGHT:
		{
			if(m_nCurCol < (m_nCols-1)) 
			{
				// If we're not in the last column, we just move right one cell
				nNewCol++;
			}
			else if(m_nCurCol == (m_nCols-1) && m_nCurRow == (m_nRows-1))
			{
				// No "other" cell so move to the very first cell in the grid
				nNewCol = nNewRow = 0;
			}
			else
			{
				// Move to first cell in the row directly above us.
				nNewCol = 0, nNewRow++;
			}
			nCurSel = nNewRow * 8 + nNewCol;
			SetRGB(m_crCells[nCurSel].GetCellColor());
		}
		break;
		
	case VK_DOWN:
		{
			if(m_nCurRow < (m_nRows-1)) 
			{
				nNewRow++;
			}
			else
			{
				nNewRow = 0;
			}
			nCurSel = nNewRow * 8 + nNewCol;
			SetRGB(m_crCells[nCurSel].GetCellColor());
		}
		break;
		
	case VK_UP:
		{
			if(m_nCurRow > 0) 
			{
				nNewRow--;
			}
			else
			{
				nNewRow = m_nRows-1;
			}
			nCurSel = nNewRow * 8 + nNewCol;
			SetRGB(m_crCells[nCurSel].GetCellColor());
		}
		break;

	case VK_RETURN:
		{
			if(m_bPopup)
			{
				OnSelectOK((WPARAM)m_crCurColor,0L);
			}
		}
		break;

	case VK_CANCEL:
	case VK_ESCAPE:
		{
			if(m_bPopup)
			{
				OnSelectCancel((WPARAM)m_crCurColor,0L);
			}
		}
		break;

	case VK_TAB:
		{
			if(GetKeyState(VK_SHIFT)&0x8000)
			{
				// For shift tab, we move to the previous item in the Z order
				// of the parent window.
				CWnd* pParent = m_pParent;
				if( pParent != NULL )
				{
					CWnd* pPrevFocus = pParent->GetParent()->GetNextDlgTabItem(m_pParent, TRUE);
					if(pPrevFocus != NULL)
						pPrevFocus->SetFocus();
				}
			}
			else
			{
				if(bHasCustomBar)
				{
					m_pParent->PostMessage( WM_FO_SELECTCOLORCUSTOM, (WPARAM)(m_crCurColor), 0 );
					if(m_bPopup)
					{
						m_pParent->ShowWindow(SW_HIDE);
					}
				}
			}
		}
		return;
	}
}

void CFODropColorPaletteControl::SetCellBorderSize(const int nBorder)
{
	nCellBorderSize = nBorder;
	for (int i = 0; i < FO_TOTAL_DROP_COLOR_CELLS; i ++)
	{
		m_crCells[i].SetCellBorderSize(nBorder);
	}
}

⌨️ 快捷键说明

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