📄 diagrameditor.cpp
字号:
the resize area around the virtual page
border. Selection markers are displayed
to allow resizing of the virtual page
with the mouse.
"marker" can be one of the following:
"DEHT_NONE" No hit-point
"DEHT_BODY" Inside object body
"DEHT_TOPLEFT" Top-left corner
"DEHT_TOPMIDDLE" Middle top-side
"DEHT_TOPRIGHT" Top-right corner
"DEHT_BOTTOMLEFT" Bottom-left corner
"DEHT_BOTTOMMIDDLE" Middle bottom-side
"DEHT_BOTTOMRIGHT" Bottom-right corner
"DEHT_LEFTMIDDLE" Middle left-side
"DEHT_RIGHTMIDDLE" Middle right-side
============================================================*/
{
CRect rect( 0, 0, round( static_cast< double >( GetVirtualSize().cx ) * GetZoom() ),
round( static_cast< double >( GetVirtualSize().cy ) * GetZoom() ) );
CRect rectMarker;
int horz = m_markerSize.cx / 2;
int vert = m_markerSize.cy / 2;
switch( marker )
{
case DEHT_TOPLEFT:
rectMarker.SetRect( rect.left - horz,
rect.top - vert,
rect.left + horz,
rect.top + vert );
break;
case DEHT_TOPMIDDLE:
rectMarker.SetRect( rect.left + ( rect.Width() / 2 ) - horz,
rect.top - vert,
rect.left + ( rect.Width() / 2 ) + horz,
rect.top + vert );
break;
case DEHT_TOPRIGHT:
rectMarker.SetRect( rect.right - horz,
rect.top - vert,
rect.right + horz,
rect.top + vert );
break;
case DEHT_BOTTOMLEFT:
rectMarker.SetRect( rect.left - horz,
rect.bottom - vert,
rect.left + horz,
rect.bottom + vert );
break;
case DEHT_BOTTOMMIDDLE:
rectMarker.SetRect( rect.left + ( rect.Width() / 2 ) - horz,
rect.bottom - vert,
rect.left + ( rect.Width() / 2 ) + horz,
rect.bottom + vert );
break;
case DEHT_BOTTOMRIGHT:
rectMarker.SetRect( rect.right - horz,
rect.bottom - vert,
rect.right + horz,
rect.bottom + vert );
break;
case DEHT_LEFTMIDDLE:
rectMarker.SetRect( rect.left - horz,
rect.top + ( rect.Height() / 2 ) - vert,
rect.left + horz,
rect.top + ( rect.Height() / 2 ) + vert );
break;
case DEHT_RIGHTMIDDLE:
rectMarker.SetRect( rect.right - horz,
rect.top + ( rect.Height() / 2 ) - vert,
rect.right + horz,
rect.top + ( rect.Height() / 2 ) + vert );
break;
}
return rectMarker;
}
/////////////////////////////////////////////////////////////////////////////
// CDiagramEditor property accessors
void CDiagramEditor::SetVirtualSize( const CSize& size )
/* ============================================================
Function : CDiagramEditor::SetVirtualSize
Description : Sets the size of the virtual paper.
Access : Public
Return : void
Parameters : const CSize& size - New virtual size.
Usage : The virtual page of the editor is the
'paper' where the user can draw. This
function marks the data as changed.
============================================================*/
{
ASSERT( m_objs );
SetInternalVirtualSize( size );
m_objs->SetModified( TRUE );
}
void CDiagramEditor::SetInternalVirtualSize( const CSize& size )
/* ============================================================
Function : CDiagramEditor::SetInternalVirtualSize
Description : Changes the virtual page size without
setting the data as modified.
Access : Private
Return : void
Parameters : const CSize& size - New virtual size.
Usage : Internal function.
============================================================*/
{
if( m_objs && size != GetVirtualSize() )
{
m_objs->SetVirtualSize( size );
SetupScrollbars();
if( m_hWnd )
RedrawWindow();
}
}
CSize CDiagramEditor::GetVirtualSize() const
/* ============================================================
Function : CDiagramEditor::GetVirtualSize
Description : Returns the virtual size of the editor.
Access : Public
Return : CSize - The current virtual size.
Parameters : none
Usage : The virtual page of the editor is the
'paper' where the user can draw.
============================================================*/
{
CRect rect( 0, 0, 0, 0 );
if( m_hWnd )
GetClientRect( &rect );
CSize size( CSize( 0, 0 ) );
if( m_objs )
size = m_objs->GetVirtualSize();
if( size.cx == 0 )
size.cx = rect.right;
if( size.cy == 0 )
size.cy = rect.bottom;
return size;
}
void CDiagramEditor::SetBackgroundColor( COLORREF col )
/* ============================================================
Function : CDiagramEditor::SetBackgroundColor
Description : Sets the background color.
Access : Public
Return : void
Parameters : COLORREF col - New background color
to set.
Usage : The background is the virtual area of the
editor (might both be smaller or bigger
than the client rect).
============================================================*/
{
m_bkgndCol = col;
if( m_hWnd )
RedrawWindow();
}
void CDiagramEditor::SetNonClientColor( COLORREF col )
/* ============================================================
Function : CDiagramEditor::SetNonClientColor
Description : Sets the non-client area color.
Access : Public
Return : void
Parameters : COLORREF col - New non-client area
color.
Usage : The non-client color is the color of the
area outside the virtual page.
============================================================*/
{
m_nonClientBkgndCol = col;
if( m_hWnd )
RedrawWindow();
}
void CDiagramEditor::ShowGrid( BOOL grid )
/* ============================================================
Function : CDiagramEditor::ShowGrid
Description : Sets grid visibility.
Access : Public
Return : void
Parameters : BOOL grid - "TRUE" to show the grid, "FALSE"
to hide.
Usage : If the grid is visible, it will be drawn
using the grid pen style and color. The
grid lines will not be scaled with the
zoom (the space between them will of
course be, however)
============================================================*/
{
m_grid = grid;
if( m_hWnd )
RedrawWindow();
}
BOOL CDiagramEditor::IsGridVisible() const
/* ============================================================
Function : CDiagramEditor::IsGridVisible
Description : Returns the visibility state of the grid.
Access : Public
Return : BOOL - "TRUE" if grid is visible.
Parameters : none
Usage : If the grid is visible, it will be drawn
using the grid pen style and color. The
grid lines will not be scaled with the
zoom (the space between them will of
course be, however)
============================================================*/
{
return m_grid;
}
void CDiagramEditor::SetGridColor( COLORREF col )
/* ============================================================
Function : CDiagramEditor::SetGridColor
Description : Sets a new grid pen color.
Access : Public
Return : void
Parameters : COLORREF col - New grid pen color.
Usage : If the grid is visible, it will be drawn
using the grid pen style and color. The
grid lines will not be scaled with the
zoom (the space between them will of
course be, however)
============================================================*/
{
m_gridCol = col;
if( m_hWnd )
RedrawWindow();
}
COLORREF CDiagramEditor::GetGridColor() const
/* ============================================================
Function : CDiagramEditor::GetGridColor
Description : Returns the current grid pen color.
Access : Public
Return : COLORREF - The current grid color.
Parameters : none
Usage : If the grid is visible, it will be drawn
using the grid pen style and color. The
grid lines will not be scaled with the
zoom (the space between them will of
course be, however)
============================================================*/
{
return m_gridCol;
}
void CDiagramEditor::SetGridSize( CSize size )
/* ============================================================
Function : CDiagramEditor::SetGridSize
Description : Sets a new grid size.
Access : Public
Return : void
Parameters : CSize size - The new grid size.
Usage : If snap to grid is on, added, moved and
resized objects snap to the closest grid
position. If the background is resized, it
will also snap to the grid.
============================================================*/
{
m_gridSize = size;
if( m_hWnd )
RedrawWindow();
}
CSize CDiagramEditor::GetGridSize() const
/* ============================================================
Function : CDiagramEditor::GetGridSize
Description : Gets the current grid size.
Access : Public
Return : CSize - The current grid size.
Parameters : none
Usage : If snap to grid is on, added, moved and
resized objects snap to the closest grid
position. If the background is resized, it
will also snap to the grid.
============================================================*/
{
return m_gridSize;
}
void CDiagramEditor::SetGridPenStyle( int style )
/* ============================================================
Function : CDiagramEditor::SetGridPenStyle
Description : Sets the new grid pen style.
Access : Public
Return : void
Parameters : int style - The new pen style, one of
the style constants for
"CreatePen".
Usage : The grid (if visible) is drawn with a pen
created with the grid pen style. The grid
lines will not be scaled with the zoom
(the space between them will of course be,
however)
============================================================*/
{
m_gridStyle = style;
if( m_hWnd )
RedrawWindow();
}
int CDiagramEditor::GetGridPenStyle() const
/* ============================================================
Function : CDiagramEditor::GetGridPenStyle
Description : Returns the pen style for the grid.
Access : Public
Return : int - The pen style, one of the style
constants for "CreatePen".
Parameters : none
Usage : The grid (if visible) is drawn with a pen
created with the grid pen style. The grid
lines will not be scaled with the zoom
(the space between them will of course be,
however)
============================================================*/
{
return m_gridStyle;
}
void CDiagramEditor::SetSnapToGrid( BOOL snap )
/* ============================================================
Function : CDiagramEditor::SetSnapToGrid
Description : Enable/disable snap to grid.
Access : Public
Return : void
Parameters : BOOL snap - "TRUE" if objects should
snap to grid.
Usage : If snap to grid is on, added, moved and
resized objects snap to the closest grid
position. If the background is resized, it
will also snap to the grid.
============================================================*/
{
m_snap = snap;
}
BOOL CDiagramEditor::GetSnapToGrid() const
/* ============================================================
Function : CDiagramEditor::GetSnapToGrid
Description : Gets the state of the snap-to-grid state.
Access : Public
Return : BOOL - "TRUE" if snap is on.
Parameters : none
Usage : If snap to grid is on, added, moved and
resized objects snap to the closest grid
position. If the background is resized, it
will also snap to the grid.
============================================================*/
{
return m_snap;
}
void CDiagramEditor::SetResize( BOOL bgresize )
/* ============================================================
Function : CDiagramEditor::SetResize
Description : Enables/disables background resizing.
Access : Public
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -