www.pudn.com > JingXiang-Design-Jeff.rar > BrightAdjust.cpp
// BrightAdjust.cpp : implementation file
//
#include "stdafx.h"
#include "Design.h"
#include "BrightAdjust.h"
#include "MainFrm.h"
#include "DesignDoc.h"
#include "DesignView.h"
#include "BMPFILE.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// BrightAdjust dialog
BrightAdjust::BrightAdjust(CWnd* pParent /*=NULL*/)
: CDialog(BrightAdjust::IDD, pParent)
{
this->m_IsPreview=FALSE;
//{{AFX_DATA_INIT(BrightAdjust)
m_Adjust_Num = 0;
m_IsPreview = TRUE;
//}}AFX_DATA_INIT
}
void BrightAdjust::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(BrightAdjust)
DDX_Text(pDX, IDC_EDIT1, m_Adjust_Num);
DDV_MinMaxInt(pDX, m_Adjust_Num, -255, 255);
DDX_Check(pDX, IDC_PREVIEW, m_IsPreview);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(BrightAdjust, CDialog)
//{{AFX_MSG_MAP(BrightAdjust)
ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
ON_WM_VSCROLL()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(ID_RETURN, OnReturn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// BrightAdjust message handlers
void BrightAdjust::OnPreview()
{
UpdateData(TRUE);
return;
}
BOOL BrightAdjust::OnInitDialog()
{
m_Adjust_Num=0;
CDesignDoc *pDesignDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
// Backup The BMPData
::memcpy(pDesignDoc->BitMap.pBMPDataForGray,pDesignDoc->BitMap.pBMPData,pDesignDoc->BitMap.BmpInfoHeader.biSizeImage);
pSlider_=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
pSlider_->SetRange(0,510);
pSlider_->SetPos(510-(this->m_Adjust_Num+255));
m_Adjust_Num=0;
pSpin_=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1);
pSpin_->SetRange(-255,255);
pSpin_->SetPos(this->m_Adjust_Num);
CDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void BrightAdjust::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(pScrollBar->GetDlgCtrlID()==IDC_SPIN1)
{
this->m_Adjust_Num=nPos;
UpdateData(FALSE);
pSlider_->SetPos(510-(m_Adjust_Num+255));
}
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDER1)
{
CSliderCtrl *pSlider=(CSliderCtrl*)pScrollBar;
m_Adjust_Num=255-pSlider->GetPos();
UpdateData(FALSE);
pSpin_->SetPos(m_Adjust_Num);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
if(!this->m_IsPreview) return;
CDesignDoc *pDoc;
CDesignView *pView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pView=(CDesignView *) pMFrame->GetActiveView();
::memcpy(pDoc->BitMap.pBMPData,pDoc->BitMap.pBMPDataForGray,pDoc->BitMap.BmpInfoHeader.biSizeImage);
if(pDoc->BitMap.RectSelected)
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num,&pDoc->BitMap.ReallyRectOfBMP);
}
else
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num);
}
pDoc->BitMap.CopyImageDataAsNonCompressionDataToMemForShow();
pView->Invalidate(FALSE);
if(pView->IsHistogramShowed)
{
pView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
return;
}
void BrightAdjust::OnChangeEdit1()
{
UpdateData(TRUE);
pSlider_->SetPos(510-(this->m_Adjust_Num+255));
pSpin_->SetPos(this->m_Adjust_Num);
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!this->m_IsPreview) return;
CDesignDoc *pDoc;
CDesignView *pView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pView=(CDesignView *) pMFrame->GetActiveView();
::memcpy(pDoc->BitMap.pBMPData,pDoc->BitMap.pBMPDataForGray,pDoc->BitMap.BmpInfoHeader.biSizeImage);
if(pDoc->BitMap.RectSelected)
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num,&pDoc->BitMap.ReallyRectOfBMP);
}
else
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num);
}
pDoc->BitMap.CopyImageDataAsNonCompressionDataToMemForShow();
pView->Invalidate();
if(pView->IsHistogramShowed)
{
pView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
return;
}
void BrightAdjust::OnOK()
{
if(this->m_IsPreview) CDialog::OnOK();
CDesignDoc *pDoc;
CDesignView *pView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pView=(CDesignView *) pMFrame->GetActiveView();
::memcpy(pDoc->BitMap.pBMPData,pDoc->BitMap.pBMPDataForGray,pDoc->BitMap.BmpInfoHeader.biSizeImage);
if(pDoc->BitMap.RectSelected)
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num,&pDoc->BitMap.ReallyRectOfBMP);
}
else
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num);
}
pDoc->BitMap.CopyImageDataAsNonCompressionDataToMemForShow();
pView->Invalidate();
if(pView->IsHistogramShowed)
{
pView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
CDialog::OnOK();
}
void BrightAdjust::OnCancel()
{
//if(!this->m_IsPreview){CDialog::OnCancel(); return;}
CDesignDoc *pDoc;
CDesignView *pView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pView=(CDesignView *) pMFrame->GetActiveView();
::memcpy(pDoc->BitMap.pBMPData,pDoc->BitMap.pBMPDataForGray,pDoc->BitMap.BmpInfoHeader.biSizeImage);
pDoc->BitMap.CopyImageDataAsNonCompressionDataToMemForShow();
pView->Invalidate();
if(pView->IsHistogramShowed)
{
pView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
CDialog::OnCancel();
}
void BrightAdjust::OnReturn()
{
CDesignDoc *pDoc;
CDesignView *pView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pView=(CDesignView *) pMFrame->GetActiveView();
this->m_Adjust_Num=0;
UpdateData(FALSE);
::memcpy(pDoc->BitMap.pBMPData,pDoc->BitMap.pBMPDataForGray,pDoc->BitMap.BmpInfoHeader.biSizeImage);
if(pDoc->BitMap.RectSelected)
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num,&pDoc->BitMap.ReallyRectOfBMP);
}
else
{
pDoc->BitMap.BrightAdjusting(m_Adjust_Num);
}
pDoc->BitMap.CopyImageDataAsNonCompressionDataToMemForShow();
pView->Invalidate();
if(pView->IsHistogramShowed)
{
pView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
pSlider_->SetPos(m_Adjust_Num+255);
pSpin_->SetPos(m_Adjust_Num);
return;
}