📄 didcfgview.cpp
字号:
return DI_OK;
}
//-----------------------------------------------------------------------------
// Name: GetCurrentView()
// Desc: returns the current view identifier
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::GetCurrentView( LPINT lpnView )
{
// make sure this object has been properly initialized
if( FALSE == m_bIsInit )
return DIERR_NOTINITIALIZED;
// sanity check
if( NULL == lpnView )
return DIERR_INVALIDPARAM;
// copy the view
*lpnView = m_nView;
return DI_OK;
}
//-----------------------------------------------------------------------------
// Name: GetInfo()
// Desc: retrieves information from DIDCfgView
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::GetInfo( DIDCfgViewInfo* pCfgViewInfo )
{
// sanity checks
if( NULL == pCfgViewInfo )
return DIERR_INVALIDPARAM;
ZeroMemory( pCfgViewInfo, sizeof( DIDCfgViewInfo ) );
// always return whether the Config Viewer is initialized or not
pCfgViewInfo->bIsInit = m_bIsInit;
// make sure this object has been properly initialized
if( FALSE == m_bIsInit )
return DIERR_NOTINITIALIZED;
// set the information to be returned
pCfgViewInfo->iCurrentViewID = m_nView;
pCfgViewInfo->iNumTotalViews =( INT )m_lpViewManager->GetNumViews();
pCfgViewInfo->dwNumUniqueCallouts = m_lpCalloutManager->GetNumUniqueCallouts();
pCfgViewInfo->bCanBeCollapsed = m_bCanBeCollapsed;
pCfgViewInfo->bIsCollapsed = m_bIsCollapsed;
return DI_OK;
}
//-----------------------------------------------------------------------------
// Name: SetColors()
// Desc: sets the foreground( text ) color, background and highlight color,
// the highlighted callout color
//-----------------------------------------------------------------------------
VOID DIDCfgView::SetColors( COLORREF crFore, COLORREF crBack,
COLORREF crHighlight, COLORREF crHighlightLine )
{
m_crFore = crFore;
m_crBack = crBack;
m_crHighlight = crHighlight;
m_crHighlightLine = crHighlightLine;
}
//-----------------------------------------------------------------------------
// Name: GetColor()
// Desc: returns the colors currently being using in rendering
//-----------------------------------------------------------------------------
VOID DIDCfgView::GetColors( COLORREF* pCrFore, COLORREF* pCrBack,
COLORREF* pCrHighlight, COLORREF* pCrHighlightLine )
{
if( pCrFore ) *pCrFore = m_crFore;
if( pCrBack ) *pCrBack = m_crBack;
if( pCrHighlight ) *pCrHighlight = m_crHighlight;
if( pCrHighlightLine ) *pCrHighlightLine = m_crHighlightLine;
}
//-----------------------------------------------------------------------------
// Name: SetFont()
// Desc: sets the font used to draw the text
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::SetFont( const TCHAR* pctszFontName, DWORD dwAttribs )
{
HDC hDCMem;
HFONT hFont;
HRESULT hr = DI_OK;
if( NULL == pctszFontName )
{
if( m_hFont )
DeleteObject( m_hFont );
}
else
{
// create a memory device context
hDCMem = CreateCompatibleDC( NULL );
// create font
hFont = DidcvCreateFont( hDCMem, pctszFontName, DIDCV_DEFAULT_FONT_SIZE,
0, dwAttribs, FALSE );
if( NULL == hFont )
hr = DIERR_INVALIDPARAM;
else
{
if( m_hFont )
DeleteObject( m_hFont );
m_hFont = hFont;
}
// clean up
DeleteDC( hDCMem );
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: GetFont()
// Desc: sets the font used to draw the text
//-----------------------------------------------------------------------------
HFONT DIDCfgView::GetFont()
{
return m_hFont;
}
//-----------------------------------------------------------------------------
// Name: SetViewOrigin
// Desc: tells DIDCfgView where to start drawing and performing hit tests
// on the surface being rendered on
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::SetViewOrigin( const POINT* pPtOrg, POINT* pPtOldOrg )
{
if( NULL == pPtOrg )
return DIERR_INVALIDPARAM;
// return the current origin
if( pPtOldOrg )
{
pPtOldOrg->x = m_ptOrigin.x;
pPtOldOrg->y = m_ptOrigin.y;
}
// set the current origin to new origin
m_ptOrigin.x = pPtOrg->x;
m_ptOrigin.y = pPtOrg->y;
return DI_OK;
}
//-----------------------------------------------------------------------------
// Name: CalcCenterOrgForCurrentView()
// Desc: calculate the coordinate where to set the origin, in order for the
// current view to be centered on the drawing surface, lpImgSize should
// contain the dimensions of the drawing surface. if the view is
// larger than the drawing area, then( 0, 0 ) will be returned
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::CalcCenterOrgForCurrentView( const SIZE* pSurfaceSize,
POINT* pCenterOrg, BOOL bSetOrigin )
{
if( FALSE == m_bIsInit )
return DIERR_NOTINITIALIZED;
// sanity check
if( NULL == pSurfaceSize || NULL == pCenterOrg )
return DIERR_INVALIDPARAM;
INT x = 0, y = 0;
DidcvView* pView;
SIZE imgSize;
// get the current view
pView = m_lpViewManager->GetImage( m_nView );
// get the size and find the coordinate at which to center the image
// note that x == 0 and y == 0 if surface width and height
// is not as big as the image width and height, respectively
if( pView && pView->GetViewSize( &imgSize ) )
{
if( imgSize.cx < pSurfaceSize->cx )
x =( pSurfaceSize->cx - imgSize.cx ) / 2;
if( imgSize.cy < pSurfaceSize->cy )
y =( pSurfaceSize->cy - imgSize.cy ) / 2;
}
// set the values to be returns
pCenterOrg->x = x;
pCenterOrg->y = y;
// if bSetOrigin is TRUE, then set the view origin for this object
if( bSetOrigin )
SetViewOrigin( pCenterOrg, NULL );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: SetDefaultText()
// Desc: sets the default text for callouts that doesn't have action mapped
//-----------------------------------------------------------------------------
VOID DIDCfgView::SetDefaultText( const TCHAR* pctszDefaultText, DWORD length )
{
// copy up to MAX_PATH characters
size_t numToCopy =( length < MAX_PATH ? length : MAX_PATH );
_tcsncpy( m_tszDefaultText, pctszDefaultText, numToCopy );
// if we copied MAX_PATH, make sure it is NULL terminated
if( numToCopy == MAX_PATH )
m_tszDefaultText [MAX_PATH - 1] = 0;
}
//-----------------------------------------------------------------------------
// Name: RenderView()
// Desc: draws the configuration view to HBITMAP, a DDB or a DIB
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::RenderView( HBITMAP hBitmap, BOOL bIsDib )
{
HDC hDCMem;
HGDIOBJ hOldBitmap;
DIBSECTION dibs;
HRESULT hr;
// make sure this object has been properly initialized
if( FALSE == m_bIsInit )
return DIERR_NOTINITIALIZED;
// sanity check
if( NULL == hBitmap )
return DIERR_INVALIDPARAM;
// create a memory DC compatible with the current display
hDCMem = CreateCompatibleDC( NULL );
// select the surface to drawn on into the HDC
hOldBitmap = SelectObject( hDCMem, hBitmap );
// render, passing in as much data as we can safely acquire
if( bIsDib && GetObject( hBitmap, sizeof( DIBSECTION ), &dibs ) )
hr = RenderView( hDCMem, dibs.dsBm.bmBits, dibs.dsBm.bmWidth, dibs.dsBm.bmHeight );
else
hr = RenderView( hDCMem );
// clean up
SelectObject( hDCMem, hOldBitmap );
DeleteDC( hDCMem );
return hr;
}
//-----------------------------------------------------------------------------
// Name: RenderView()
// Desc: draws the configuration view to an HDC
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::RenderView( HDC hdc )
{
return RenderView( hdc, NULL, 0, 0 );
}
//-----------------------------------------------------------------------------
// Name: RenderView()
// Desc: draws the configuration view to an HDC
//-----------------------------------------------------------------------------
HRESULT DIDCfgView::RenderView( HDC hdc, VOID* pBits, INT width, INT height )
{
DidcvView* pView;
const DidcvCalloutSet* pSet;
int iDCStackNum;
// make sure this object has been properly initialized
if( FALSE == m_bIsInit )
return DIERR_NOTINITIALIZED;
if( NULL == hdc )
return DIERR_INVALIDPARAM;
pView = m_lpViewManager->GetImage( m_nView );
// no valid view set
if( NULL == pView )
return DIERR_NOTINITIALIZED;
// set rendering options for HDC
HBRUSH hBkBrush = CreateSolidBrush( m_crHighlight );
HPEN hLinePen = CreatePen( PS_SOLID, 0, m_crFore );
HPEN hHighlightPen = CreatePen( PS_SOLID, 0, m_crHighlight );
HPEN hHighlightLinePen = CreatePen( PS_SOLID, 0, m_crHighlightLine );
// save the state of the DC on the context stack
iDCStackNum = SaveDC( hdc );
// select the new highlight background color brush
SelectObject( hdc, hBkBrush );
// select the callout line color
SelectObject( hdc, hLinePen );
// set text color
SetTextColor( hdc, m_crFore );
// set background color
SetBkColor( hdc, m_crBack );
// shift the origin
SetViewportOrgEx( hdc, m_ptOrigin.x, m_ptOrigin.y, NULL );
// the bk mode for drawing text
SetBkMode( hdc, TRANSPARENT );
// draw the current view
pView->Render( hdc, pBits, width, height, &m_ptOrigin );
// get the set of callouts associated with the current view
pSet = m_lpCalloutManager->GetCalloutSetByView( m_nView );
if( pSet )
{
// Get the list of callout in the set.
// A callout is the line drawn from each axis/button to a label
const GwArray <DidcvCallout *> & arr = pSet->GetInternalArrayRef();
const DidcvCalloutData* pData;
UINT i;
BOOL bCalloutEmpty;
DWORD dwNumPts = 0;
const POINT* lpPts;
TCHAR szBuffer[MAX_PATH];
TCHAR szCopy[MAX_PATH];
DidcvActionMap* lpActionMap;
DWORD dwTextFlags, dwTextAlign;
if( m_hFont )
{
// set the font
SelectObject( hdc, m_hFont );
}
// for each callout (the line drawn from each axis/button to a label)
for( i = 0; i < arr.Size(); i++ )
{
// the data associated
pData = arr[i]->GetDataRef();
const RECT* rect = &( arr[i]->GetCalloutRect() );
// get the action map, if one exists
lpActionMap = pData->lpActionMap;
if( lpActionMap && lpActionMap->dia.lptszActionName )
bCalloutEmpty = FALSE;
else
bCalloutEmpty = TRUE;
// draw the callout for the control
if( !bCalloutEmpty || pData->lpState->bDrawEmptyCallout )
{
// draw the highlight first
if( pData->lpState->bDrawHighlight )
{
// draw the highlight
SelectObject( hdc, hHighlightPen );
Rectangle( hdc, rect->left, rect->top, rect->right, rect->bottom );
// set pen to highlight line
SelectObject( hdc, hHighlightLinePen );
// set back ground color to highlight color
SetBkColor( hdc, m_crHighlight );
// set the text color to highlightline color
// SetTextColor( hdc, m_crHighlightLine );
}
// draw the overlay image
if( pData->lpState->bDrawOverlay )
{
arr[i]->DrawOverlay( hdc, pBits, width, height, &m_ptOrigin );
}
// draw the callout line and text
if( pData->lpState->bDrawCallout )
{
// draw the callout line
lpPts = arr[i]->GetCalloutLine( &dwNumPts );
DidcvPolyLineArrow( hdc, lpPts,( INT ) dwNumPts, FALSE );
// set the draw text options
dwTextFlags = DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS
| DT_EDITCONTROL | DT_MODIFYSTRING;
if( !bCalloutEmpty )
{
// copy the text
_tcscpy( szBuffer, lpActionMap->dia.lptszActionName );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -