EditColorsDlg.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:10k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // EditColorsDlg.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #include "MyColorPaletteWnd.h"
- #include "EditColorDlg.h"
- #include "EditColorsDlg.h"
- #include "EditNameDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEditColorsDlg dialog
- CEditColorsDlg::CEditColorsDlg(C3dColorList* pColorList, CWnd* pParent /*=NULL*/)
- : CDialog(CEditColorsDlg::IDD, pParent)
- {
- m_hPalette = NULL;
- m_pList = pColorList;
- m_pListSelColor = NULL;
- //{{AFX_DATA_INIT(CEditColorsDlg)
- m_fRed = 0.0f;
- m_fGrn = 0.0f;
- m_fBlu = 0.0f;
- m_szColorName = _T("");
- m_fAlpha = 0.0f;
- //}}AFX_DATA_INIT
- }
- void CEditColorsDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEditColorsDlg)
- DDX_Control(pDX, IDC_COLOR_LIST, m_ListBox);
- DDX_Text(pDX, IDC_RED, m_fRed);
- DDV_MinMaxFloat(pDX, m_fRed, 0.f, 1.f);
- DDX_Text(pDX, IDC_GRN, m_fGrn);
- DDV_MinMaxFloat(pDX, m_fGrn, 0.f, 1.f);
- DDX_Text(pDX, IDC_BLU, m_fBlu);
- DDV_MinMaxFloat(pDX, m_fBlu, 0.f, 1.f);
- DDX_Text(pDX, IDC_COLOR_NAME, m_szColorName);
- DDX_Text(pDX, IDC_ALPHA, m_fAlpha);
- DDV_MinMaxFloat(pDX, m_fAlpha, 0.f, 1.f);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CEditColorsDlg, CDialog)
- //{{AFX_MSG_MAP(CEditColorsDlg)
- ON_WM_SHOWWINDOW()
- ON_LBN_SELCHANGE(IDC_COLOR_LIST, OnSelchangeColorList)
- ON_BN_CLICKED(IDNEW, OnNew)
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColor)
- ON_WM_DRAWITEM()
- ON_EN_KILLFOCUS(IDC_RED, OnKillfocusRed)
- ON_EN_KILLFOCUS(IDC_GRN, OnKillfocusGrn)
- ON_EN_KILLFOCUS(IDC_BLU, OnKillfocusBlu)
- ON_EN_KILLFOCUS(IDC_ALPHA, OnKillfocusAlpha)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEditColorsDlg function implimentation
- void CEditColorsDlg::LoadDialogData(C3dColor* pColor)
- {
- if(pColor)
- {
- // Set our local values to the colors' values
- m_szColorName = pColor->m_szName;
- m_fRed = pColor->m_fColor[0];
- m_fGrn = pColor->m_fColor[1];
- m_fBlu = pColor->m_fColor[2];
- m_fAlpha = pColor->m_fColor[3];
- }
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Paint our button window
- PaintButtonWnd();
- }
- void CEditColorsDlg::SaveDialogData(C3dColor* pColor)
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Set our colors values to the local values
- pColor->m_szName = m_szColorName;
- pColor->m_fColor[0] = m_fRed;
- pColor->m_fColor[1] = m_fGrn;
- pColor->m_fColor[2] = m_fBlu;
- }
- void CEditColorsDlg::PaintButtonWnd()
- {
- CRect rect; // window rect
- CDC* pDC; // pointer to a device context
- // Get the size of the gradient window
- m_wndButtonColor.GetWindowRect(&rect);
- // Get a pointer to the windows device context
- pDC = m_wndButtonColor.GetDC();
- if(pDC)
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(m_fRed*255,
- m_fGrn*255,
- m_fBlu*255));
- ReleaseDC(pDC);
- }
- void CEditColorsDlg::ResetDlg(C3dColorList* pColorList)
- {
- if(pColorList)
- {
- // If this is the same C3dColorList pointer
- // that we last updated the dialog box with
- // then the data is current. Do not clear.
- if(pColorList == m_pList)
- return;
- else
- {
- m_pList = pColorList;
- // reset our variables, since we may have
- m_fRed = 0.0f;
- m_fGrn = 0.0f;
- m_fBlu = 0.0f;
- m_fAlpha = 0.0f;
- m_szColorName = _T("");
- m_pListSelColor = NULL;
- // Reload the Color list box
- C3dColor* pColor = m_pList->LoadListBox(&m_ListBox);
- // initializ the Dialog window
- LoadDialogData(NULL);
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEditColorsDlg message handlers
- BOOL CEditColorsDlg::OnInitDialog()
- {
- // let the base class do the default work
- CDialog::OnInitDialog();
- // Create the button color window
- CRect rect;
- GetDlgItem(IDC_BUTTON_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_BUTTON_COLOR_WND, // UINT nID
- 0); // pContext
- // Load the Color list box
- if(m_pList)
- C3dColor* pColor = m_pList->LoadListBox(&m_ListBox);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CEditColorsDlg::OnSelchangeColorList()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ListBox.GetCurSel();
- // Save the last selected color and reload the list
- // box. (The user may have changed the name of the
- // color..)
- if(m_pListSelColor)
- {
- SaveDialogData(m_pListSelColor);
- // Reload the Color list box
- if(m_pList)
- pColor = m_pList->LoadListBox(&m_ListBox);
- }
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- m_pListSelColor = (C3dColor*)m_ListBox.GetItemData(index);
- if(m_pListSelColor)
- // Display the colors values
- LoadDialogData(m_pListSelColor);
- }
- void CEditColorsDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- // Let the base class draw the control item first
- CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
- if(nIDCtl == IDC_BUTTON_COLOR_WND && m_pListSelColor)
- PaintButtonWnd();
- }
- void CEditColorsDlg::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CDialog::OnShowWindow(bShow, nStatus);
- // if(bShow) // Reload list box
- // LoadListBox();
- }
- void CEditColorsDlg::OnOK()
- {
- if(m_pListSelColor)
- // Save the dialog data to the color
- SaveDialogData(m_pListSelColor);
- CDialog::OnOK();
- }
- void CEditColorsDlg::OnNew()
- {
- // Get the name of the new color
- CEditNameDlg newNameDlg(this);
- if(newNameDlg.DoModal() == IDOK)
- {
- if(m_pList)
- {
- C3dColor* pColor = NULL;
- pColor = C3dColor::Create();
- pColor->m_szName = newNameDlg.m_szName;
- if(!m_pList->Find(pColor))
- {
- // pColor is not in the list, so add to to list,
- // reload the list box, select the color, reload
- // the dialog data, and pop up the color dialog
- // window
- m_pList->Append(pColor);
- // Reload the Color list box
- m_pList->LoadListBox(&m_ListBox);
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- m_pListSelColor = pColor;
- // Display the colors values
- LoadDialogData(m_pListSelColor);
- // Pop up the color dialog window
- OnButtonColor();
- }
- else
- C3dColor::Delete(pColor);
- }
- }
- }
- void CEditColorsDlg::OnButtonColor()
- {
- if(m_pListSelColor)
- {
- // Create the dialog
- CEditColorDlg colorDlg(m_pList, m_pListSelColor, this);
- // Invoke the modal dialog box and return the
- // dialog-box result when done.
- if(colorDlg.DoModal() == IDOK)
- {
- // Save any changes the user may have made
- m_pListSelColor->m_fColor[0] = colorDlg.m_Color.m_fColor[0];
- m_pListSelColor->m_fColor[1] = colorDlg.m_Color.m_fColor[1];
- m_pListSelColor->m_fColor[2] = colorDlg.m_Color.m_fColor[2];
- LoadDialogData(m_pListSelColor);
- }
- }
- else
- AfxMessageBox("A Color has not been selected. Create a new color or select one from the list.", MB_OK);
- }
- void CEditColorsDlg::OnKillfocusRed()
- {
- if(m_pListSelColor)
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- m_pListSelColor->m_fColor[0] = m_fRed;
- m_pListSelColor->m_fColor[1] = m_fGrn;
- m_pListSelColor->m_fColor[2] = m_fBlu;
- m_pListSelColor->m_fColor[3] = m_fAlpha;
- PaintButtonWnd();
- }
- }
- void CEditColorsDlg::OnKillfocusGrn()
- {
- if(m_pListSelColor)
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- m_pListSelColor->m_fColor[0] = m_fRed;
- m_pListSelColor->m_fColor[1] = m_fGrn;
- m_pListSelColor->m_fColor[2] = m_fBlu;
- m_pListSelColor->m_fColor[3] = m_fAlpha;
- PaintButtonWnd();
- }
- }
- void CEditColorsDlg::OnKillfocusBlu()
- {
- if(m_pListSelColor)
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- m_pListSelColor->m_fColor[0] = m_fRed;
- m_pListSelColor->m_fColor[1] = m_fGrn;
- m_pListSelColor->m_fColor[2] = m_fBlu;
- m_pListSelColor->m_fColor[3] = m_fAlpha;
- PaintButtonWnd();
- }
- }
- void CEditColorsDlg::OnKillfocusAlpha()
- {
- if(m_pListSelColor)
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- m_pListSelColor->m_fColor[0] = m_fRed;
- m_pListSelColor->m_fColor[1] = m_fGrn;
- m_pListSelColor->m_fColor[2] = m_fBlu;
- m_pListSelColor->m_fColor[3] = m_fAlpha;
- PaintButtonWnd();
- }
- }