📄 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 + -