Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MFC and Tab controls

This topic is 5647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I want to build a dialog with a tab control in it. I''we derived my own classes from CPropertySheet and CPropertyPage and got it to work. The problem is that now when I''m going to update and/or store data in the pages things grow more and more complex. Therefore I want to use a simple CTabCtrl since I think it would fit better with what I want to do. Can I add pages as resources into my tab control in a similar way as with the property control or do I have to build all the pages on top of the tabcontrol and activate/show the different things that shall be on that page? The last thing feels like a big no-no... Any sugestions? Thanks // Javelin -- Why do something today when you can do it tomorrow... --

Share this post


Link to post
Share on other sites
Advertisement
I build my own tab pages in resource editor and activate ie. show/hide them in code. I tried using the property sheet but that''s only for dialog boxes, my tabs are embeded inside my control panel in an editor. You need to shrink the dlg boxes that make up your pages when you add more tabs otherwise the dlg boxes get pushed down and some text/controls might not be visible. I resize them in resource editor, though I think you can do it in code as well, but then you need to resize controls in code as well. In MFC, you need to pass in parent dlg box pointer that houses the tabs and pages to each child page, I think to get the ownership working.

Share this post


Link to post
Share on other sites
Hmmm... so you are using a new dialog for each page in your tab control? Did I got that correct?

My tabctrl is in a dialog, but I think it''s best if I build it by my own anyway and not using a property sheet.

Do you have to build your own handler that changes the pages? (I guess I have).

Thanks

// Javelin
-- Why do something today when you can do it tomorrow... --

Share this post


Link to post
Share on other sites
Yes, I build new dlg resource for each tab. I have written my own handler that switches between the pages. Here''s the code:

CtrlPanel

  
#if !defined(AFX_CTRLPANEL_H__8305B660_0141_11D6_9E6F_AFE5C813E54C__INCLUDED_)
#define AFX_CTRLPANEL_H__8305B660_0141_11D6_9E6F_AFE5C813E54C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// CtrlPanel.h : header file

//


// Forward declarations

class CellPage;
class CameraPage;
class TexturePage;
class TextureAdjPage;
class LightsPage;

/////////////////////////////////////////////////////////////////////////////

// CtrlPanel window


class CtrlPanel : public CTabCtrl
{
public:
// Enums


// Zero based indices of tabs in control panel, tabs go in order

// as named i.e. 0 index is first tab

// NOTE: Initialized in constructor in cpp file

const int CELL_TAB;
const int TEXTURE_TAB;
const int CAMERA_TAB;
const int TEXTUREADJ_TAB;
const int LIGHTS_TAB;

// Shrinks page so it fits inside ctrl panel box

const int SHRINK_VALUE;

// Operations

CtrlPanel();
virtual ~CtrlPanel();

BOOL Create(CDialogBar& DlgBar);

// Attributes


// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CtrlPanel)

//}}AFX_VIRTUAL


protected:
// Operations

BOOL CreateTabs();
BOOL CreatePages();

// Data

public:
CellPage *m_pCellPage;
CameraPage *m_pCameraPage;
TexturePage *m_pTexturePage;
TextureAdjPage *m_pTextureAdjPage;
LightsPage *m_pLightsPage;

protected:
CFont m_TabFont;

// Generated message map functions

//{{AFX_MSG(CtrlPanel)

afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG


DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_CTRLPANEL_H__8305B660_0141_11D6_9E6F_AFE5C813E54C__INCLUDED_)





  
// CtrlPanel.cpp : implementation file

//


#include "stdafx.h"
#include "MfcEditor.h"
#include "CtrlPanel.h"
#include "CellPage.h"
#include "CameraPage.h"
#include "TexturePage.h"
#include "TextureAdjPage.h"
#include "LightsPage.h"
#include "GlobalTypes.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////

// CtrlPanel


CtrlPanel::CtrlPanel():
CELL_TAB(0),
TEXTURE_TAB(1),
CAMERA_TAB(2),
TEXTUREADJ_TAB(3),
LIGHTS_TAB(4),

SHRINK_VALUE(5)// Pixels

{
m_pCellPage = NULL;
m_pCameraPage = NULL;
m_pTexturePage = NULL;
m_pTextureAdjPage = NULL;
}

CtrlPanel::~CtrlPanel()
{
if(m_pCellPage)
{
delete m_pCellPage;
m_pCellPage = NULL;
}

if(m_pCameraPage)
{
delete m_pCameraPage;
m_pCameraPage = NULL;
}

if(m_pTexturePage)
{
delete m_pTexturePage;
m_pTexturePage = NULL;
}

if(m_pTextureAdjPage)
{
delete m_pTextureAdjPage;
m_pTextureAdjPage = NULL;
}

if(m_pLightsPage)
{
delete m_pLightsPage;
m_pLightsPage = NULL;
}
}


BEGIN_MESSAGE_MAP(CtrlPanel, CTabCtrl)
//{{AFX_MSG_MAP(CtrlPanel)

ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
ON_NOTIFY_REFLECT(TCN_SELCHANGING, OnSelchanging)
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CtrlPanel message handlers


BOOL CtrlPanel::Create(CDialogBar& DlgBar)
{
// Create the control panel(derived from CTabCtrl), a child of dialog bar.

// Make it the size of the group box resource that''s placed on top

// of ctrl panel dialog bar(and is part of) in resource editor

CRect Rc;

CStatic* pAlignWnd = (CStatic*)DlgBar.GetDlgItem(IDC_CTRLPANEL_ALIGN_RECT);
if(!pAlignWnd)
return FALSE;

pAlignWnd->GetWindowRect(&Rc);
DlgBar.ScreenToClient(&Rc);

if(!CTabCtrl::Create(TCS_TABS|TCS_MULTILINE|WS_CHILD|WS_VISIBLE, Rc, &DlgBar, IDC_CTRLPANEL))
return FALSE;

// Enumerate the fonts first to see what''s available on the machine

LOGFONT LogFont;
CFontMaker FontMaker;

FontMaker.EnumFont(LogFont, "Arial", 14, TRUE, TRUE);

// IMPORTANT!!! Can''t create local font variable because the font

// object must persist until control is destroyed (see article ID:Q85518 in

// msdn docs)

if(!m_TabFont.CreateFontIndirect(&LogFont))
return FALSE;

SetFont(&m_TabFont, FALSE);

// Populate the control panel with pages

if(!CreateTabs())
return FALSE;

// Make the cell page the first visible page upon application start

SetCurSel(CELL_TAB);
m_pCellPage->ShowWindow(SW_SHOW);
m_pCameraPage->ShowWindow(SW_HIDE);

// Everything went ok

return TRUE;
}

BOOL CtrlPanel::CreateTabs()
{
int iRv;
TCITEM Tab;
Tab.mask = TCIF_TEXT;

Tab.pszText = "Cell";
iRv = InsertItem(CELL_TAB, &Tab);
if(-1 == iRv)
return FALSE;

Tab.pszText = "Textures";
iRv = InsertItem(TEXTURE_TAB, &Tab);
if(-1 == iRv)
return FALSE;

Tab.pszText = "Camera";
iRv = InsertItem(CAMERA_TAB, &Tab);
if(-1 == iRv)
return FALSE;

Tab.pszText = "Texture adjust";
iRv = InsertItem(TEXTUREADJ_TAB, &Tab);
if(-1 == iRv)
return FALSE;

Tab.pszText = "Lights";
iRv = InsertItem(LIGHTS_TAB, &Tab);
if(-1 == iRv)
return FALSE;

// Create page for each tab

if(!CreatePages())
return FALSE;

// Everything went ok

return TRUE;
}

/*
Purpose: Creates a page for each tab. The pages are dialog boxes.
Called from CreateTabs()

Entry:

Exit:
*/
BOOL CtrlPanel::CreatePages()
{
m_pCellPage = new CellPage(this);
if(!m_pCellPage)
{
ASSERT(0);
return FALSE;
}

m_pCameraPage = new CameraPage(this);
if(!m_pCameraPage)
{
ASSERT(0);
return FALSE;
}

m_pTexturePage = new TexturePage(this);
if(!m_pTexturePage)
{
ASSERT(0);
return FALSE;
}

m_pTextureAdjPage = new TextureAdjPage(this);
if(!m_pTextureAdjPage)
{
ASSERT(0);
return FALSE;
}

m_pLightsPage = new LightsPage(this);
if(!m_pLightsPage)
{
ASSERT(0);
return FALSE;
}

return TRUE;
}

/*
Purpose: Handle tab changes i.e. hide current page and display new page

Entry: These are reflected messages of tab control

Exit:
*/

void CtrlPanel::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here

int i = GetCurSel();

if(i != -1)
{
if(CELL_TAB == i)
m_pCellPage->ShowWindow(SW_SHOW);

if(CAMERA_TAB == i)
m_pCameraPage->ShowWindow(SW_SHOW);

if(TEXTURE_TAB == i)
m_pTexturePage->ShowWindow(SW_SHOW);

if(TEXTUREADJ_TAB == i)
m_pTextureAdjPage->ShowWindow(SW_SHOW);

if(LIGHTS_TAB == i)
m_pLightsPage->ShowWindow(SW_SHOW);
}
*pResult = 0;
}

void CtrlPanel::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here

int i = GetCurSel();

if(i != -1)
{
if(CELL_TAB == i)
m_pCellPage->ShowWindow(SW_HIDE);

if(CAMERA_TAB == i)
m_pCameraPage->ShowWindow(SW_HIDE);

if(TEXTURE_TAB == i)
m_pTexturePage->ShowWindow(SW_HIDE);

if(TEXTUREADJ_TAB == i)
m_pTextureAdjPage->ShowWindow(SW_HIDE);

if(LIGHTS_TAB == i)
m_pLightsPage->ShowWindow(SW_HIDE);
}
*pResult = 0;
}


One page in ctrlpanel:

  
#if !defined(AFX_LIGHTSPAGE_H__F358CD80_63FC_11D6_9E6F_B25C054B7542__INCLUDED_)
#define AFX_LIGHTSPAGE_H__F358CD80_63FC_11D6_9E6F_B25C054B7542__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// LightsPage.h : header file

//

#include "GlobalTypes.h"

// Forward declarations

class CtrlPanel;

/////////////////////////////////////////////////////////////////////////////

// LightsPage dialog


class LightsPage : public CDialog
{
// Construction

public:
LightsPage(CtrlPanel *pParent); // standard constructor


// Attributes

A_ENG_BYTE_COLOR GetColor();
void SetColor(A_ENG_BYTE_COLOR &Clr);
A_ENG_BYTE_COLOR& GetAmbientColor(){return m_AmbientColor;}

CRenderer::LIGHT GetCurLightType(); // Cur = current or selected

void SetCurLightType(int Type);

char GetSpotlightConeHalfAngle(){return m_CurrentSpotlightConeHalfangle;}
void ShowNewSpotlightConeHalfangle(float fAngle);

protected:
// Dialog Data

//{{AFX_DATA(LightsPage)

enum { IDD = IDD_CTRLPANEL_LIGHTSPAGE };
CEdit m_cSpotlightConeHalfangleEdit;
CSpinButtonCtrl m_cSpotlightConeHalfangleSpinner;
CStatic m_cSpotClr;
CStatic m_cPointClr;
CStatic m_cDirectClr;
CStatic m_cAmbientClr;
CButton m_cSpotBtn;
CButton m_cPointBtn;
CButton m_cDirectBtn;
CButton m_cAmbientBtn;
//}}AFX_DATA



// Overrides

void OnOK();
void OnCancel();

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(LightsPage)

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL


// Implementation

protected:
template<class T, class C> void z_DrawColor(T &Ctrl, C &Clr);
void z_SetColor();

// Data

CtrlPanel *m_pCtrlPanel; // Don''t free it


A_ENG_BYTE_COLOR m_PointColor, m_SpotColor, m_DirectColor, m_AmbientColor;

char m_SpotlightConeHalfangleMin, m_SpotlightConeHalfangleMax, m_CurrentSpotlightConeHalfangle;

// Generated message map functions

//{{AFX_MSG(LightsPage)

virtual BOOL OnInitDialog();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnPointcolor();
afx_msg void OnSpotcolor();
afx_msg void OnDirectcolor();
afx_msg void OnAmbientcolor();
afx_msg void OnDeltaposConeHalfangleSpinner(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_LIGHTSPAGE_H__F358CD80_63FC_11D6_9E6F_B25C054B7542__INCLUDED_)




  
// LightsPage.cpp : implementation file

//


#include "stdafx.h"
#include "MfcEditor.h"
#include "CtrlPanel.h"
#include "LightsPage.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////

// LightsPage dialog



LightsPage::LightsPage(CtrlPanel *pParent)
: CDialog(LightsPage::IDD, (CWnd*)pParent)
{
//{{AFX_DATA_INIT(LightsPage)

//}}AFX_DATA_INIT

m_pCtrlPanel = pParent;

// All lights except ambient have white default color

m_PointColor.ubRed = m_PointColor.ubGreen = m_PointColor.ubBlue = 255;
m_SpotColor = m_PointColor;
m_DirectColor = m_PointColor;

m_AmbientColor.ubRed = m_AmbientColor.ubGreen = m_AmbientColor.ubBlue = 0;

m_SpotlightConeHalfangleMin = 1;
m_SpotlightConeHalfangleMax = 89;
m_CurrentSpotlightConeHalfangle = 45;

// Create modeless page dialog box

VERIFY(CDialog::Create(IDD, (CWnd*)pParent));
}


void LightsPage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LightsPage)

DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT, m_cSpotlightConeHalfangleEdit);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_SPINNER, m_cSpotlightConeHalfangleSpinner);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_SPOTCOLOR, m_cSpotClr);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_POINTCOLOR, m_cPointClr);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_DIRECTCOLOR, m_cDirectClr);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_AMBIENTCOLOR, m_cAmbientClr);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_SPOTLIGHTBTN, m_cSpotBtn);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_POINTLIGHTBTN, m_cPointBtn);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_DIRECTLIGHTBTN, m_cDirectBtn);
DDX_Control(pDX, IDC_CTRLPANEL_LIGHTSPAGE_AMBIENTLIGHTBTN, m_cAmbientBtn);
//}}AFX_DATA_MAP

}


BEGIN_MESSAGE_MAP(LightsPage, CDialog)
//{{AFX_MSG_MAP(LightsPage)

ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_CTRLPANEL_LIGHTSPAGE_POINTCOLOR, OnPointcolor)
ON_BN_CLICKED(IDC_CTRLPANEL_LIGHTSPAGE_SPOTCOLOR, OnSpotcolor)
ON_BN_CLICKED(IDC_CTRLPANEL_LIGHTSPAGE_DIRECTCOLOR, OnDirectcolor)
ON_BN_CLICKED(IDC_CTRLPANEL_LIGHTSPAGE_AMBIENTCOLOR, OnAmbientcolor)
ON_NOTIFY(UDN_DELTAPOS, IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_SPINNER, OnDeltaposConeHalfangleSpinner)
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// LightsPage message handlers


BOOL LightsPage::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here


// Make point light the default selected light

SetCurLightType(CRenderer::POINT);

// Disable direct color since it isn''t implemented yet

m_cDirectBtn.EnableWindow(FALSE);
m_cDirectClr.EnableWindow(FALSE);

// Init spotlight''s cone halfangle and set its range

SetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT, m_CurrentSpotlightConeHalfangle, FALSE);
m_cSpotlightConeHalfangleSpinner.SetRange(m_SpotlightConeHalfangleMin, m_SpotlightConeHalfangleMax);

// Resize the dialog box so the top doesn''t interfere with tab on

// the page

CRect Rc, NewRc;

VERIFY(m_pCtrlPanel->GetItemRect(m_pCtrlPanel->LIGHTS_TAB, &Rc));
GetClientRect(&NewRc);

int iRowCount = m_pCtrlPanel->GetRowCount();

NewRc.top += (Rc.Height() * iRowCount) + m_pCtrlPanel->SHRINK_VALUE;
NewRc.bottom -= m_pCtrlPanel->SHRINK_VALUE;
NewRc.left += m_pCtrlPanel->SHRINK_VALUE;
NewRc.right -= m_pCtrlPanel->SHRINK_VALUE;

MoveWindow(&NewRc, FALSE);
return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

/*
Purpose: Traps Escape and Return keys so they don''t shutdown the lights dialog box

Entry:

Exit:
*/
void LightsPage::OnCancel(){}

void LightsPage::OnOK()
{
// On stroke of enter key will update all edit controls that user changed through typing
CDocument *pDoc = ((MainFrame*)AfxGetMainWnd())->GetActiveDocument();
ASSERT(pDoc);

App *pApp = (App*)AfxGetApp();
ASSERT(pApp);

if(m_cSpotlightConeHalfangleEdit.GetModify())
{
pDoc->SetModifiedFlag();
m_cSpotlightConeHalfangleEdit.SetModify();

UINT Angle = GetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT);

if(Angle >= m_SpotlightConeHalfangleMin && Angle <= m_SpotlightConeHalfangleMax)
{
m_CurrentSpotlightConeHalfangle = Angle;

// Update cone half-angle of all selected spotlights
// pApp->m_CellSelector.ScaleSpotlightCone((float)Angle);

((MainFrame*)GetParentFrame())->RepaintView(EditorView::ALL);
}
else
{
// Can''t have a negative or <= 0 angle since edit ctrl property limits this
if(Angle > m_SpotlightConeHalfangleMax)
{
SetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT,
m_SpotlightConeHalfangleMax, FALSE);

m_CurrentSpotlightConeHalfangle = m_SpotlightConeHalfangleMax;

// Update cone half-angle of all selected spotlights
// pApp->m_CellSelector.ScaleSpotlightCone((float)m_CurrentSpotlightConeHalfangle);

((MainFrame*)GetParentFrame())->RepaintView(EditorView::ALL);
}
else
{
if(Angle <= m_SpotlightConeHalfangleMin)
{
SetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT,
m_SpotlightConeHalfangleMin, FALSE);

m_CurrentSpotlightConeHalfangle = m_SpotlightConeHalfangleMin;

// Update cone half-angle of all selected spotlights
// pApp->m_CellSelector.ScaleSpotlightCone((float)m_CurrentSpotlightConeHalfangle);

((MainFrame*)GetParentFrame())->RepaintView(EditorView::ALL);
}
}
}
}
}

/*
Purpose: Update the current spotlight''s cone half-angle as well as change the angle of
existing selected spotlights in real-time

Entry:

Exit:
*/
void LightsPage::OnDeltaposConeHalfangleSpinner(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
CDocument *pDoc = ((MainFrame*)AfxGetMainWnd())->GetActiveDocument();
ASSERT(pDoc);

App *pApp = (App*)AfxGetApp();
ASSERT(pApp);

UINT Angle = GetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT);

if(pNMUpDown->iDelta < 0)
{
if(Angle <= m_SpotlightConeHalfangleMin)
Angle = m_SpotlightConeHalfangleMin;
else
Angle -= 1;
}
else
{
if(Angle >= m_SpotlightConeHalfangleMax)
Angle = m_SpotlightConeHalfangleMax;
else
Angle += 1;
}

ASSERT(Angle >= m_SpotlightConeHalfangleMin);
ASSERT(Angle <= m_SpotlightConeHalfangleMax);

m_CurrentSpotlightConeHalfangle = Angle;
// pApp->m_CellSelector.ScaleSpotlightCone((float)Angle);

pDoc->SetModifiedFlag();
((MainFrame*)GetParentFrame())->RepaintView(EditorView::ALL);

*pResult = 0;
}

/*
Purpose: Determines which light type is currently selected and returns the type

Entry:

Exit: Type of light, one of point, spot or direct type
*/
CRenderer::LIGHT LightsPage::GetCurLightType()
{
CRenderer::LIGHT Type;

if(m_cPointBtn.GetCheck() == 1)
Type = CRenderer::POINT;
else
if(m_cSpotBtn.GetCheck() == 1)
Type = CRenderer::SPOT;
else
if(m_cDirectBtn.GetCheck() == 1)
Type = CRenderer::DIRECT;
else
if(m_cAmbientBtn.GetCheck() == 1)
Type = CRenderer::AMBIENT;

return Type;
}

void LightsPage::SetCurLightType(int Type)
{
if(CRenderer::POINT == Type)
{
m_cPointBtn.SetCheck(1);
m_cSpotBtn.SetCheck(0);
m_cDirectBtn.SetCheck(0);
m_cAmbientBtn.SetCheck(0);
}
else
{
if(CRenderer::SPOT == Type)
{
m_cPointBtn.SetCheck(0);
m_cSpotBtn.SetCheck(1);
m_cDirectBtn.SetCheck(0);
m_cAmbientBtn.SetCheck(0);
}
else
{
if(CRenderer::DIRECT == Type)
{
m_cPointBtn.SetCheck(0);
m_cSpotBtn.SetCheck(0);
m_cDirectBtn.SetCheck(1);
m_cAmbientBtn.SetCheck(0);
}
else
{
if(CRenderer::AMBIENT == Type)
{
m_cPointBtn.SetCheck(0);
m_cSpotBtn.SetCheck(0);
m_cDirectBtn.SetCheck(0);
m_cAmbientBtn.SetCheck(1);
}
}
}
}
}

/*
Purpose: Returns the color of the selected light

Entry:

Exit:
*/
A_ENG_BYTE_COLOR LightsPage::GetColor()
{
A_ENG_BYTE_COLOR Color;

if(m_cPointBtn.GetCheck() == 1)
Color = m_PointColor;
else
if(m_cSpotBtn.GetCheck() == 1)
Color = m_SpotColor;
else
if(m_cDirectBtn.GetCheck() == 1)
Color = m_DirectColor;
else
if(m_cAmbientBtn.GetCheck() == 1)
Color = m_AmbientColor;

return Color;
}

void LightsPage::SetColor(A_ENG_BYTE_COLOR &Clr)
{
if(m_cPointBtn.GetCheck() == 1)
{
m_PointColor = Clr;
z_DrawColor(m_cPointClr, Clr);
}
else
{
if(m_cSpotBtn.GetCheck() == 1)
{
m_SpotColor = Clr;
z_DrawColor(m_cSpotClr, Clr);
}
else
{
if(m_cDirectBtn.GetCheck() == 1)
{
m_DirectColor = Clr;
z_DrawColor(m_cDirectClr, Clr);
}
else
{
if(m_cAmbientBtn.GetCheck() == 1)
{
m_AmbientColor = Clr;
z_DrawColor(m_cAmbientClr, Clr);
}
}
}
}
}

/*
Purpose: Redraws backround of a color stripe static control

Entry:

Exit: Must use ::CreateSolidBrush() win32 function, MFC brush object won''t work
*/
HBRUSH LightsPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
HBRUSH hNewBrush = NULL;

// TODO: Change any attributes of the DC here
if(pWnd->m_hWnd == m_cPointClr.m_hWnd)
hNewBrush = ::CreateSolidBrush(RGB(m_PointColor.ubRed, m_PointColor.ubGreen, m_PointColor.ubBlue));
else
if(pWnd->m_hWnd == m_cSpotClr.m_hWnd)
hNewBrush = ::CreateSolidBrush(RGB(m_SpotColor.ubRed, m_SpotColor.ubGreen, m_SpotColor.ubBlue));
else
if(pWnd->m_hWnd == m_cDirectClr.m_hWnd)
hNewBrush = ::CreateSolidBrush(RGB(m_DirectColor.ubRed, m_DirectColor.ubGreen, m_DirectColor.ubBlue));
else
if(pWnd->m_hWnd == m_cAmbientClr.m_hWnd)
hNewBrush = ::CreateSolidBrush(RGB(m_AmbientColor.ubRed, m_AmbientColor.ubGreen, m_AmbientColor.ubBlue));

// TODO: Return a different brush if the default is not desired
hbr = hNewBrush;
return hbr;
}

/*
Purpose: Opens up color picker dialog box for the currently selected light type
User is able to change color of light
Entry:

Exit:
*/
void LightsPage::OnPointcolor()
{
// Init color dlg box with light''s existing color
CColorDialog ClrDlg(
RGB(m_PointColor.ubRed, m_PointColor.ubGreen, m_PointColor.ubBlue),
CC_FULLOPEN);

// Make dlg box visible on the screen
if(IDOK == ClrDlg.DoModal())
{
COLORREF Color = ClrDlg.GetColor();

m_PointColor.ubRed = GetRValue(Color);
m_PointColor.ubGreen = GetGValue(Color);
m_PointColor.ubBlue = GetBValue(Color);

z_DrawColor(m_cPointClr, m_PointColor);
z_SetColor();
}
}

void LightsPage::OnSpotcolor()
{
// Init color dlg box with light''s existing color
CColorDialog ClrDlg(
RGB(m_SpotColor.ubRed, m_SpotColor.ubGreen, m_SpotColor.ubBlue),
CC_FULLOPEN);

// Make dlg box visible on the screen
if(IDOK == ClrDlg.DoModal())
{
COLORREF Color = ClrDlg.GetColor();

m_SpotColor.ubRed = GetRValue(Color);
m_SpotColor.ubGreen = GetGValue(Color);
m_SpotColor.ubBlue = GetBValue(Color);

z_DrawColor(m_cSpotClr, m_SpotColor);
z_SetColor();
}
}

void LightsPage::OnDirectcolor()
{
// Init color dlg box with light''s existing color
CColorDialog ClrDlg(
RGB(m_DirectColor.ubRed, m_DirectColor.ubGreen, m_DirectColor.ubBlue),
CC_FULLOPEN);

// Make dlg box visible on the screen
if(IDOK == ClrDlg.DoModal())
{
COLORREF Color = ClrDlg.GetColor();

m_DirectColor.ubRed = GetRValue(Color);
m_DirectColor.ubGreen = GetGValue(Color);
m_DirectColor.ubBlue = GetBValue(Color);

z_DrawColor(m_cDirectClr, m_DirectColor);
z_SetColor();
}
}

void LightsPage::OnAmbientcolor()
{
// Init color dlg box with light''s existing color
CColorDialog ClrDlg(
RGB(m_AmbientColor.ubRed, m_AmbientColor.ubGreen, m_AmbientColor.ubBlue),
CC_FULLOPEN);

// Make dlg box visible on the screen
if(IDOK == ClrDlg.DoModal())
{
COLORREF Color = ClrDlg.GetColor();

m_AmbientColor.ubRed = GetRValue(Color);
m_AmbientColor.ubGreen = GetGValue(Color);
m_AmbientColor.ubBlue = GetBValue(Color);

z_DrawColor(m_cAmbientClr, m_AmbientColor);
z_SetColor();
}
}

template<class T, class C>
void LightsPage::z_DrawColor(T &Ctrl, C &Clr)
{
CRect rc;
Ctrl.GetClientRect(rc);

CDC *pDC = Ctrl.GetDC();
ASSERT(pDC);

pDC->FillSolidRect(rc, RGB(Clr.ubRed, Clr.ubGreen, Clr.ubBlue));
ReleaseDC(pDC);
}

/*
Purpose: Sets color of selected cells based on currently selected light type and its color

Entry:

Exit:
*/
void LightsPage::z_SetColor()
{
App *pApp = (App*)AfxGetApp();
MainFrame *pFrame = (MainFrame*)AfxGetMainWnd();

if(!pApp || !pFrame)
{
ASSERT(pApp);
ASSERT(pFrame);
return;
}

// pApp->m_CellSelector.SetCellColor(GetColor(), GetCurLightType());

// Redraw all windows and mark document as modified
pFrame->RepaintView(EditorView::ALL);
pFrame->GetActiveDocument()->SetModifiedFlag();
}

/*
Purpose: Display new spotlight''s cone half-angle based on currently selected spotlight

Entry:

Exit:
*/

void LightsPage::ShowNewSpotlightConeHalfangle(float fAngle)
{
MainFrame *pFrame = (MainFrame*)AfxGetMainWnd();

if(!pFrame)
{
ASSERT(pFrame);
return;
}

m_CurrentSpotlightConeHalfangle = fAngle;
SetDlgItemInt(IDC_CTRLPANEL_LIGHTSPAGE_CONEHALFANGLE_EDIT, (UINT)fAngle, FALSE);
pFrame->GetActiveDocument()->SetModifiedFlag();
}


Inspect the constructors because they''re modified.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!