?? cedlg.cpp
字號:
// CEDlg.cpp : implementation file
//
#include "stdafx.h"
#include "source10.h"
#include "AIEDlg.h"
#include "CEDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CAIEDlg *m_pAIEDlg;
/////////////////////////////////////////////////////////////////////////////
// CCEDlg dialog
//POINT MousePos;
CCEDlg::CCEDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCEDlg::IDD, pParent)
{
int i;
COORDINATE p;
m_nID = CCEDlg::IDD;//IDD=IDD_AIE_CURVE
m_pParent = pParent;//pParent=NULL
//初始化矩形方框中索引點坐標的索引表,表明在LIST定義的兩點之間有256個
//查詢點,它的大小為變量,隨LIST中點的個數,點與點之間的距離有關
for(i=0;i<256;i++)
m_Index[i] = i;
p.x = 0;
p.y = 0;
//為表增加內容,表的元素反映的是點的坐標
m_PointList.AddTail( p );
i=0;
// m_PointList.AddTail(i);
p.x = 255;
p.y = 255;
m_PointList.AddTail( p );
//{{AFX_DATA_INIT(CCEDlg)
m_sMethod = _T("Gamma");
m_sChannel = _T("主通道");
//}}AFX_DATA_INIT
}
extern CSource10App theApp;
BOOL CCEDlg::Create(void)
{
//調用資源產生無模式的CE對話框
return CDialog::Create(m_nID,m_pParent);
}
void CCEDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCEDlg)
DDX_CBString(pDX, IDC_METHOD, m_sMethod);
DDX_CBString(pDX, IDC_CHANNEL, m_sChannel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCEDlg, CDialog)
//{{AFX_MSG_MAP(CCEDlg)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_CBN_SELCHANGE(IDC_METHOD, OnSelchangeMethod)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//響應消息調用畫線函數
void CCEDlg::OnPaint()
{
int i;
POSITION position;
COORDINATE p1,p2;
CRect rect; //Histogram zoom
//Get the coordination of histogram frame.
GetDlgItem(IDC_STATIC_FRAME)->GetClientRect(rect);
GetDlgItem(IDC_STATIC_FRAME)->ClientToScreen(rect);
ScreenToClient(rect);
//使用戶坐標縮小
rect.left++;
rect.top++;
rect.right--;
rect.bottom--;
rect.right--;
rect.bottom--;
////////
CPaintDC dc(this); // device context for painting
//產生點線筆,寬度為1
CPen newPen( PS_DOT, 1, RGB(240,240,240));//;RGB(255,0,0)
//產生硬筆
CPen MasterPen( PS_SOLID, 1, RGB(0,0,0));
CPen RedPen( PS_SOLID, 1, RGB(255,0,0));
CPen GreenPen( PS_SOLID, 1, RGB(0,255,0));
CPen BluePen( PS_SOLID, 1, RGB(0,0,255));
CPen* oldPen;
//選擇新筆代替當前的筆
oldPen=dc.SelectObject( &newPen );
//畫水平和垂直的點劃線
for(i=1;i<4;i++)
{
//horizontal
dc.MoveTo(rect.left, rect.top+(rect.bottom-rect.top)/4*i);
dc.LineTo(rect.right,rect.top+(rect.bottom-rect.top)/4*i);
//vertical
dc.MoveTo(rect.left+(rect.right-rect.left)/4*i,rect.top);
dc.LineTo(rect.left+(rect.right-rect.left)/4*i,rect.bottom);
}
UpdateData(TRUE);
if(m_sChannel=="主通道")
{
dc.SelectObject( &MasterPen);
}
if(m_sChannel=="紅通道")
{
dc.SelectObject( &RedPen );
}
if(m_sChannel=="綠通道")
{
dc.SelectObject( &GreenPen );
}
if(m_sChannel=="藍通道")
{
dc.SelectObject( &BluePen );
}
//根據LIST中位置點畫線
position = m_PointList.GetHeadPosition();
p1=m_PointList.GetNext(position);
dc.Rectangle( (p1.x*(rect.right-rect.left))/255+rect.left-3 ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255-3,
(p1.x*(rect.right-rect.left))/255+rect.left+3 ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255+3 );
dc.MoveTo( (p1.x*(rect.right-rect.left))/255+rect.left ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255);
while( position!=NULL )
{
p2=m_PointList.GetNext(position);
dc.LineTo((p2.x*(rect.right-rect.left))/255+rect.left ,rect.bottom-(p2.y*(rect.bottom-rect.top))/255);
p1=p2;
//在筆的起始點畫一個小矩形框 .
dc.Rectangle( (p1.x*(rect.right-rect.left))/255+rect.left-3 ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255-3,
(p1.x*(rect.right-rect.left))/255+rect.left+3 ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255+3 );
//移動筆到下一個點
dc.MoveTo( (p1.x*(rect.right-rect.left))/255+rect.left ,rect.bottom-(p1.y*(rect.bottom-rect.top))/255);
};
//恢復初始筆即點線筆
dc.SelectObject( oldPen );
}
//////////////////////////////////////////////////////////////////////////////////////////
//
void CALLBACK EXPORT MyOnTimer(struct HWND__ *,unsigned int,unsigned int,unsigned long);
//CE對話框前響應WM_INITDIALOG消息調用初始化函數
BOOL CCEDlg::OnInitDialog()
{
COORDINATE p;
int i;
CDialog::OnInitDialog();
if(m_sMethod=="Gamma")
{
((CAIEDlg*)m_pParent)->method=FALSE;
//由繼承知表中已存在兩個元素
//移走隊尾元素并返回其值
m_PointList.RemoveTail();
//表中增加元素,共27個元素即位置點
for(i=1;i<26;i++)
{
p.x=10*i;
p.y=(int)(255*pow(p.x/255.0,0.5));
m_PointList.AddTail(p);
}
p.x=255;
p.y=255;
m_PointList.AddTail(p);
//調用函數產生Gamma索引值數組
Updatem_IndexfromGamma( 0.5 );
}
// TODO: Add extra initialization here
m_bDragLines = FALSE;
m_bDragGamma = FALSE;
SetTimer( 1, 2000, MyOnTimer); return TRUE;
}
//選擇參數矯正的方法(GAMMA,LINE)缺省為GAMMA
void CCEDlg::OnSelchangeMethod()
{
COORDINATE p;
CRect rect;
int i;
UpdateData(TRUE);
if(m_sMethod=="Line")
{
((CAIEDlg*)m_pParent)->method=TRUE;
m_PointList.RemoveAll();
//增加新的元素
p.x=0;
p.y=0;
m_PointList.AddTail(p);
p.x=255;
p.y=255;
m_PointList.AddTail(p);
}
else
{
((CAIEDlg*)m_pParent)->method=FALSE;
m_PointList.RemoveAll();
p.x=0;
p.y=0;
m_PointList.AddTail(p);
//表中增加元素,共27個元素即位置點
for(i=1;i<26;i++)
{
p.x=10*i;
p.y=(int)(255*pow(p.x/255.0,0.5));
m_PointList.AddTail(p);
}
p.x=255;
p.y=255;
m_PointList.AddTail(p);
}
GetDlgItem(IDC_STATIC_FRAME)->GetClientRect(rect);
//將RECT中的用戶坐標轉換為系統坐標
GetDlgItem(IDC_STATIC_FRAME)->ClientToScreen(rect);
ScreenToClient(rect);
InvalidateRect( &rect, TRUE );
}
//////////////////////////////////////////////////////////////////////////////////////////////
//在當前窗口下鼠標左鍵按下時調用此函數
void CCEDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
POSITION position;
COORDINATE NewNod;
CRect rect;
double fGamma;
int i;
GetDlgItem(IDC_STATIC_FRAME)->GetClientRect(rect);
GetDlgItem(IDC_STATIC_FRAME)->ClientToScreen(rect);
ScreenToClient(rect);
if(point.x<=rect.right&&point.x>=rect.left&&point.y<=rect.bottom&&point.y>=rect.top)
{
UpdateData(TRUE);
//矯正方法為LINE,LINE線上點的個數隨鼠標按下點的增多而增加
//LIST表的大小是變化的,索引表也隨之而變
if(m_sMethod=="Line")
{
if( MouseInSlidePos(point) )
{
m_bDragLines = TRUE;
}
else
{
//插入新點并畫新線
position = m_PointList.GetHeadPosition();
while( position!=NULL )
{
//從頭點開始直到找到比按下點大的點,跳出循環
NewNod=m_PointList.GetNext(position);
if(NewNod.x>=(point.x-rect.left)*255/(rect.right-rect.left))
break;
}
//修正按下點的位置值
NewNod.x = (point.x-rect.left)*255/(rect.right-rect.left);
NewNod.y = (rect.bottom-point.y)*255/(rect.bottom-rect.top);
if(position==NULL)
{
//沒有比按下點大的點,取表尾點
position=m_PointList.GetTailPosition();
m_PointList.InsertBefore(position,NewNod);
}
else
{
m_PointList.GetPrev(position);
m_PointList.GetPrev(position);
m_PointList.InsertAfter(position,NewNod);
}
//修正索引位置的索引表
Updatem_IndexfromLines( );
InvalidateRect( &rect, TRUE );
}
}
//矯正GAMMA曲線的方法,GAMMA曲線中LIST中有27個位置點
//矯正的過程是隨著按下點的位置重新計算27個點位置,同時修正索引表
if(m_sMethod=="Gamma")
{
if( MouseInSlidePos(point) )
{
m_bDragGamma = TRUE;
}
else
{
NewNod.x = (point.x-rect.left)*255/(rect.right-rect.left);
NewNod.y = (rect.bottom-point.y)*255/(rect.bottom-rect.top);
if(NewNod.x==0||NewNod.y==0)
return;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -