00001
00002
00003
00004
00005
00006
00007
00008 #include "StdAfx.h"
00009 #include "DecoratorUtil.h"
00010 #define _USE_MATH_DEFINES
00011 #include <math.h>
00012
00013 #include "DecoratorDefs.h"
00014 #include "GmeApi.h"
00015 #include "BitmapUtil.h"
00016
00017
00018 static long stereotypeCharacterType = 0;
00019
00020 namespace {
00021 bool isRunningUnderWine() {
00022
00023 static bool haveRunWineDetection = false;
00024 static bool isWine = false;
00025 if (!haveRunWineDetection) {
00026 haveRunWineDetection = true;
00027 HMODULE ntdll = LoadLibrary(_T("ntdll.dll"));
00028 if (ntdll != 0) {
00029 isWine = GetProcAddress(ntdll, "wine_get_version") != 0;
00030 FreeLibrary(ntdll);
00031 }
00032 }
00033 return isWine;
00034 }
00035
00036 }
00037
00038 namespace DecoratorSDK
00039 {
00040 Facilities facilities;
00041
00042 Facilities& getFacilities()
00043 {
00044 return facilities;
00045 }
00046
00047 bool Convert( const CString& strValue, long& lValue, bool bIsHexa )
00048 {
00049 return _stscanf( strValue, ( bIsHexa ) ? _T("%x") : _T("%ld"), &lValue ) == 1;
00050 }
00051
00052 bool Convert( const CString& strValue, COLORREF& crValue )
00053 {
00054 long lValue;
00055 if ( ! Convert( strValue, lValue, true ) ) {
00056 crValue = 0x0;
00057 return false;
00058 }
00059 unsigned int uiR = ( lValue & 0xFF0000 ) >> 16;
00060 unsigned int uiG = ( lValue & 0xFF00 ) >> 8;
00061 unsigned int uiB = ( lValue & 0xFF );
00062 crValue = RGB( uiR, uiG, uiB );
00063 return true;
00064 }
00065
00066 bool Convert( const CString& strValueIn, ELocation& eValue )
00067 {
00068 int iValue = 0;
00069 if ( _stscanf( strValueIn, _T("%d"), &iValue ) == 1 ) {
00070 eValue = (ELocation) iValue;
00071 return true;
00072 }
00073 CString strValue = strValueIn;
00074 strValue.TrimLeft( _T("\t ") );
00075 strValue.TrimRight( _T("\t ") );
00076 if ( strValue == _T("N")) {
00077 eValue = L_NORTH;
00078 return true;
00079 }
00080 if ( strValue == _T("NE")) {
00081 eValue = L_NORTHEAST;
00082 return true;
00083 }
00084 if ( strValue == _T("E")) {
00085 eValue = L_EAST;
00086 return true;
00087 }
00088 if ( strValue == _T("SE")) {
00089 eValue = L_SOUTHEAST;
00090 return true;
00091 }
00092 if ( strValue == _T("S")) {
00093 eValue = L_SOUTH;
00094 return true;
00095 }
00096 if ( strValue == _T("SW")) {
00097 eValue = L_SOUTHWEST;
00098 return true;
00099 }
00100 if ( strValue == _T("W")) {
00101 eValue = L_WEST;
00102 return true;
00103 }
00104 if ( strValue == _T("NW")) {
00105 eValue = L_NORTHWEST;
00106 return true;
00107 }
00108 if ( strValue ==_T("C")) {
00109 eValue = L_CENTER;
00110 return true;
00111 }
00112 return false;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 Facilities::Facilities()
00122 : m_spProject( NULL )
00123 {
00124 m_nullDC.CreateCompatibleDC(NULL);
00125 m_gdip = NULL;
00126 m_eEdgeAntiAlias = Gdiplus::SmoothingModeHighQuality;
00127 m_eFontAntiAlias = Gdiplus::TextRenderingHintAntiAlias;
00128
00129 CComPtr<IMgaRegistrar> registrar;
00130 COMTHROW(registrar.CoCreateInstance(OLESTR("Mga.MgaRegistrar")));
00131 ASSERT(registrar != NULL);
00132 edgesmoothmode_enum edgeSmoothMode;
00133 COMTHROW(registrar->get_EdgeSmoothMode(REGACCESS_USER, &edgeSmoothMode));
00134 m_eEdgeAntiAlias = (Gdiplus::SmoothingMode)edgeSmoothMode;
00135 fontsmoothmode_enum fontSmoothMode;
00136 COMTHROW(registrar->get_FontSmoothMode(REGACCESS_USER, &fontSmoothMode));
00137 m_eFontAntiAlias = (Gdiplus::TextRenderingHint)fontSmoothMode;
00138
00139 createFont( FONT_LABEL, _T("Arial"), FW_NORMAL, false, 16 );
00140 createFont( FONT_PORT, _T("Arial"), FW_BOLD, false, 12 );
00141 createFont( FONT_TYPE, _T("Arial"), FW_NORMAL, false, 12 );
00142 createFont( FONT_PORT_OUTSIDE, _T("Arial"), FW_BOLD, false, 11 );
00143 createFont( FONT_PORTNAME, _T("Arial"), FW_NORMAL, false, 15 );
00144 createFont( FONT_CONNLABEL, _T("Arial"), FW_LIGHT, false, 12 );
00145 createFont( FONT_ABSTRACT, _T("Arial"), FW_NORMAL, true, 15 );
00146
00147 TileVector* pTileVector = new TileVector();
00148
00149 RefPoint rpTL2( RefCoord( CRP_BEGIN, 0 ), RefCoord( CRP_BEGIN, 0 ) );
00150 RefPoint rpBR2( RefCoord( CRP_END, 0 ), RefCoord( CRP_END, 0 ) );
00151 pTileVector->push_back( BackgroundTile( rpTL2, rpBR2, rpTL2, rpBR2, FT_STRETCH, FT_STRETCH ) );
00152
00153
00154 addTileVector( TILE_ATOMDEFAULT, pTileVector );
00155
00156 pTileVector = new TileVector();
00157
00158 RefPoint rpTL( RefCoord( CRP_BEGIN, 0 ), RefCoord( CRP_BEGIN, 0 ) );
00159 RefPoint rpBR( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_BEGIN, 5 ) );
00160 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_NONE ) );
00161 rpTL = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_BEGIN, 0 ) );
00162 rpBR = RefPoint( RefCoord( CRP_END, 0 ), RefCoord( CRP_BEGIN, 5 ) );
00163 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_NONE ) );
00164 rpTL = RefPoint( RefCoord( CRP_BEGIN, 0 ), RefCoord( CRP_END, 5 ) );
00165 rpBR = RefPoint( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_END, 0 ) );
00166 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_NONE ) );
00167 rpTL = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_END, 5 ) );
00168 rpBR = RefPoint( RefCoord( CRP_END, 0 ), RefCoord( CRP_END, 0 ) );
00169 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_NONE ) );
00170
00171 rpTL = RefPoint( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_BEGIN, 0 ) );
00172 rpBR = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_BEGIN, 5 ) );
00173 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_STRETCH, FT_NONE ) );
00174 rpTL = RefPoint( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_END, 5 ) );
00175 rpBR = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_END, 0 ) );
00176 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_STRETCH, FT_NONE ) );
00177 rpTL = RefPoint( RefCoord( CRP_BEGIN, 0 ), RefCoord( CRP_BEGIN, 5 ) );
00178 rpBR = RefPoint( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_END, 5 ) );
00179 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_STRETCH ) );
00180 rpTL = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_BEGIN, 5 ) );
00181 rpBR = RefPoint( RefCoord( CRP_END, 0 ), RefCoord( CRP_END, 5 ) );
00182 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_NONE, FT_STRETCH ) );
00183
00184 rpTL = RefPoint( RefCoord( CRP_BEGIN, 5 ), RefCoord( CRP_BEGIN, 5 ) );
00185 rpBR = RefPoint( RefCoord( CRP_END, 5 ), RefCoord( CRP_END, 5 ) );
00186 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_STRETCH, FT_STRETCH ) );
00187
00188 addTileVector( TILE_MODELDEFAULT, pTileVector );
00189
00190 pTileVector = new TileVector();
00191
00192 rpTL = RefPoint( RefCoord( CRP_BEGIN, 0 ), RefCoord( CRP_BEGIN, 0 ) );
00193 rpBR = RefPoint( RefCoord( CRP_END, 0 ), RefCoord( CRP_END, 0 ) );
00194 pTileVector->push_back( BackgroundTile( rpTL, rpBR, rpTL, rpBR, FT_STRETCH, FT_STRETCH ) );
00195
00196 addTileVector( TILE_PORTDEFAULT, pTileVector );
00197 }
00198
00199 Facilities::~Facilities()
00200 {
00201 for ( std::map<CString,BitmapBase*>::iterator it = m_mapBitmaps.begin() ; it != m_mapBitmaps.end() ; ++it )
00202 delete it->second;
00203 for ( std::map<CString,TileVector*>::iterator it2 = m_mapTileVectors.begin() ; it2 != m_mapTileVectors.end() ; ++it2 )
00204 delete it2->second;
00205 for ( std::map<int,GdipFont*>::iterator it3 = m_mapFonts.begin() ; it3 != m_mapFonts.end() ; ++it3 ) {
00206 delete it3->second->gdipFont;
00207 delete it3->second;
00208 }
00209 for ( std::map<CString,Gdiplus::Pen*>::iterator it4 = m_mapPens.begin() ; it4 != m_mapPens.end() ; ++it4 )
00210 delete it4->second;
00211 for ( std::map<CString,Gdiplus::SolidBrush*>::iterator it5 = m_mapBrushes.begin() ; it5 != m_mapBrushes.end() ; ++it5 )
00212 delete it5->second;
00213
00214 delete m_gdip;
00215 }
00216
00217 bool Facilities::loadPathes( IMgaProject* pProject, bool bRefresh )
00218 {
00219 if (m_gdip == NULL) {
00220 m_gdip = new Gdiplus::Graphics(m_nullDC.m_hDC);
00221 if (m_gdip == NULL)
00222 throw hresult_exception(E_NOT_VALID_STATE);
00223 m_gdip->SetPageUnit(Gdiplus::UnitPixel);
00224 m_gdip->SetSmoothingMode(m_eEdgeAntiAlias);
00225 m_gdip->SetTextRenderingHint(m_eFontAntiAlias);
00226 }
00227
00228 if (!m_spProject || !m_spProject.IsEqualObject(pProject))
00229 m_spProject = pProject;
00230 else if (m_pathUtil.arePathsValid())
00231 return true;
00232
00233 return m_pathUtil.loadPaths(pProject, bRefresh);
00234 }
00235
00236 bool Facilities::arePathesValid() const
00237 {
00238 return m_pathUtil.arePathsValid();
00239 }
00240
00241 std::vector<CString> Facilities::getPathes() const
00242 {
00243 return m_pathUtil.getPaths();
00244 }
00245
00246 Gdiplus::Graphics* Facilities::getGraphics(void) const
00247 {
00248 return m_gdip;
00249 }
00250
00251 CDC* Facilities::getCDC(void)
00252 {
00253 return &m_nullDC;
00254 }
00255
00256 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, const CString& strName, CString& strValue ) const
00257 {
00258 return getPreference(spFCO, NULL, strName, strValue);
00259 }
00260
00261 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, const CString& strName, long& lValue, bool bInHexa ) const
00262 {
00263 return getPreference(spFCO, NULL, strName, lValue, bInHexa);
00264 }
00265
00266 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, const CString& strName, COLORREF& crValue ) const
00267 {
00268 return getPreference(spFCO, NULL, strName, crValue);
00269 }
00270
00271 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, const CString& strName, ELocation& eValue ) const
00272 {
00273 return getPreference(spFCO, NULL, strName, eValue);
00274 }
00275
00276 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, const CString& strName, bool& bValue ) const
00277 {
00278 return getPreference(spFCO, NULL, strName, bValue);
00279 }
00280
00281 bool Facilities::getPreference( CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, CString& strValue ) const
00282 {
00283 return getPreference(NULL, spMetaFCO, strName, strValue);
00284 }
00285
00286 bool Facilities::getPreference( CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, long& lValue, bool bInHexa ) const
00287 {
00288 return getPreference(NULL, spMetaFCO, strName, lValue, bInHexa);
00289 }
00290
00291 bool Facilities::getPreference( CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, COLORREF& crValue ) const
00292 {
00293 return getPreference(NULL, spMetaFCO, strName, crValue);
00294 }
00295
00296 bool Facilities::getPreference( CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, ELocation& eValue ) const
00297 {
00298 return getPreference(NULL, spMetaFCO, strName, eValue);
00299 }
00300
00301 bool Facilities::getPreference( CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, bool& bValue ) const
00302 {
00303 return getPreference(NULL, spMetaFCO, strName, bValue);
00304 }
00305
00306 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, CString& strValue ) const
00307 {
00308 CComBSTR bstrPath;
00309 CopyTo( strName, bstrPath );
00310 CComBSTR bstrValue;
00311
00312 try {
00313 if (spFCO)
00314 COMTHROW( spFCO->get_RegistryValue( bstrPath, &bstrValue ) );
00315 else if (spMetaFCO)
00316 COMTHROW( spMetaFCO->get_RegistryValue( bstrPath, &bstrValue ) );
00317 else
00318 ;
00319 }
00320 catch (hresult_exception &) {
00321 bstrValue.Empty();
00322 }
00323
00324 CString strValueT = bstrValue;
00325 if ( ! strValueT.IsEmpty() )
00326 strValue = strValueT;
00327 return ! strValueT.IsEmpty();
00328 }
00329
00330 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, long& lValue, bool bInHexa ) const
00331 {
00332 CString strValue;
00333 if ( ! getPreference( spFCO, spMetaFCO, strName, strValue ) )
00334 return false;
00335 long lValueT;
00336 if ( ! Convert( strValue, lValueT, bInHexa ) )
00337 return false;
00338 lValue = lValueT;
00339 return true;
00340 }
00341
00342 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, COLORREF& crValue ) const
00343 {
00344 CString strValue;
00345 if ( ! getPreference( spFCO, spMetaFCO, strName, strValue ) )
00346 return false;
00347 COLORREF crValueT;
00348 if ( ! Convert( strValue, crValueT ) )
00349 return false;
00350 crValue = crValueT;
00351 return true;
00352 }
00353
00354 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, ELocation& eValue ) const
00355 {
00356 CString strValue;
00357 if ( ! getPreference( spFCO, spMetaFCO, strName, strValue ) )
00358 return false;
00359 ELocation eValueT;
00360 if ( ! Convert( strValue, eValueT ) )
00361 return false;
00362 eValue = eValueT;
00363 return true;
00364 }
00365
00366 bool Facilities::getPreference( CComPtr<IMgaFCO> spFCO, CComPtr<IMgaMetaFCO> spMetaFCO, const CString& strName, bool& bValue ) const
00367 {
00368 CString strValue;
00369 if ( ! getPreference( spFCO, spMetaFCO, strName, strValue ) )
00370 return false;
00371 strValue.MakeLower();
00372 bValue = strValue == _T("t") || strValue == _T("true") || strValue == _T("1");
00373 return true;
00374 }
00375
00376 EPrefStatus Facilities::getPreferenceStatus( CComPtr<IMgaFCO> spFCO, const CString& strName ) const
00377 {
00378 CString strValue;
00379 if ( ! getPreference( spFCO, strName, strValue ) )
00380 return PS_UNDEFINED;
00381
00382 CComPtr<IMgaRegNode> spNode;
00383 CComBSTR bstrName;
00384 CopyTo( strName, bstrName );
00385 COMTHROW( spFCO->get_RegistryNode( bstrName, &spNode ) );
00386
00387 long lStatus;
00388 COMTHROW( spNode->get_Status( &lStatus ) );
00389 switch ( lStatus ) {
00390 case 0 : return PS_HERE;
00391 case -1 : return PS_META;
00392 default : return PS_INHERITED;
00393 }
00394 }
00395
00396 bool Facilities::getAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, CString& strValue ) const
00397 {
00398 if (!spFCO) {
00399 return false;
00400 }
00401 CComBSTR attrname;
00402 CopyTo( strName, attrname );
00403 CComBSTR bstrValue;
00404
00405 try {
00406 COMTHROW(spFCO->get_StrAttrByName(attrname, &bstrValue));
00407 }
00408 catch (hresult_exception &) {
00409 bstrValue.Empty();
00410 }
00411
00412 CString strValueT = bstrValue;
00413 if ( ! strValueT.IsEmpty() )
00414 strValue = strValueT;
00415 return ! strValueT.IsEmpty();
00416 }
00417
00418 bool Facilities::getAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, bool& bValue ) const
00419 {
00420 if (!spFCO) {
00421 return false;
00422 }
00423 CComBSTR attrname;
00424 CopyTo( strName, attrname );
00425 VARIANT_BOOL vval;
00426
00427 try {
00428 COMTHROW(spFCO->get_BoolAttrByName(attrname, &vval));
00429 }
00430 catch (hresult_exception &) {
00431 return false;
00432 }
00433
00434 bValue = (vval == VARIANT_TRUE);
00435 return true;
00436 }
00437
00438 bool Facilities::getAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, long& lValue ) const
00439 {
00440 if (!spFCO) {
00441 return false;
00442 }
00443 CComBSTR attrname;
00444 CopyTo( strName, attrname );
00445
00446 try {
00447 COMTHROW(spFCO->get_IntAttrByName(attrname, &lValue));
00448 }
00449 catch (hresult_exception &) {
00450 return false;
00451 }
00452
00453 return true;
00454 }
00455
00456 bool Facilities::getAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, double& fValue ) const
00457 {
00458 if (!spFCO) {
00459 return false;
00460 }
00461 CComBSTR attrname;
00462 CopyTo( strName, attrname );
00463
00464 try {
00465 COMTHROW(spFCO->get_FloatAttrByName(attrname, &fValue));
00466 }
00467 catch (hresult_exception &) {
00468 return false;
00469 }
00470
00471 return true;
00472 }
00473
00474 bool Facilities::setAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, const CString& strValue ) const
00475 {
00476 if (!spFCO) {
00477 return false;
00478 }
00479 CComBSTR attrname;
00480 CopyTo( strName, attrname );
00481 CComBSTR bstrValue;
00482 CopyTo( strValue, bstrValue );
00483
00484 try {
00485 COMTHROW(spFCO->put_StrAttrByName(attrname, bstrValue));
00486 }
00487 catch (hresult_exception &) {
00488 return false;
00489 }
00490
00491 return true;
00492 }
00493
00494 bool Facilities::setAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, bool bValue ) const
00495 {
00496 if (!spFCO) {
00497 return false;
00498 }
00499 CComBSTR attrname;
00500 CopyTo( strName, attrname );
00501 VARIANT_BOOL vval = bValue ? VARIANT_TRUE : VARIANT_FALSE;
00502
00503 try {
00504 COMTHROW(spFCO->put_BoolAttrByName(attrname, vval));
00505 }
00506 catch (hresult_exception &) {
00507 return false;
00508 }
00509
00510 return true;
00511 }
00512
00513 bool Facilities::setAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, long lValue ) const
00514 {
00515 if (!spFCO) {
00516 return false;
00517 }
00518 CComBSTR attrname;
00519 CopyTo( strName, attrname );
00520
00521 try {
00522 COMTHROW(spFCO->put_IntAttrByName(attrname, lValue));
00523 }
00524 catch (hresult_exception &) {
00525 return false;
00526 }
00527
00528 return true;
00529 }
00530
00531 bool Facilities::setAttribute( CComPtr<IMgaFCO> spFCO, const CString& strName, double fValue ) const
00532 {
00533 if (!spFCO) {
00534 return false;
00535 }
00536 CComBSTR attrname;
00537 CopyTo( strName, attrname );
00538
00539 try {
00540 COMTHROW(spFCO->put_FloatAttrByName(attrname, fValue));
00541 }
00542 catch (hresult_exception &) {
00543 return false;
00544 }
00545
00546 return true;
00547 }
00548
00549 bool Facilities::getMetaFCO(const CComPtr<IMgaMetaPart> &metaPart, CComPtr<IMgaMetaFCO> &metaFco) const
00550 {
00551 if (!metaPart) {
00552 return false;
00553 }
00554
00555 metaFco = NULL;
00556 CComPtr<IMgaMetaRole> metaRole;
00557 try {
00558 COMTHROW(metaPart->get_Role(&metaRole));
00559 VERIFY(metaRole);
00560 COMTHROW(metaRole->get_Kind(&metaFco));
00561 }
00562 catch (hresult_exception &) {
00563 metaFco = NULL;
00564 }
00565 return (metaFco != NULL);
00566 }
00567
00568 BitmapBase* Facilities::getBitmap( const CString& strName, bool bHasTC, COLORREF crTC, bool bHasBC, COLORREF crBC,
00569 bool masked, UINT nResID )
00570 {
00571 CString strID( strName );
00572 if ( masked ) {
00573 if (nResID != 0) {
00574 TCHAR chBuffer[ 10 ];
00575 _ultot( nResID, chBuffer, 10 );
00576 strID += chBuffer;
00577 }
00578 strID += _T("<Masked>");
00579 }
00580 if ( bHasTC ) {
00581 TCHAR chBuffer[ 10 ];
00582 _ultot( crTC, chBuffer, 16 );
00583 strID += _T("<TC:") + CString( chBuffer ) + _T(">");
00584 }
00585 if ( bHasBC ) {
00586 TCHAR chBuffer[ 10 ];
00587 _ultot( crBC, chBuffer, 16 );
00588 strID += _T("<BC:") + CString( chBuffer ) + _T(">");
00589 }
00590
00591 std::map<CString,BitmapBase*>::iterator it = m_mapBitmaps.find( strID );
00592 if ( it != m_mapBitmaps.end() )
00593 return it->second;
00594
00595 if (masked) {
00596 BitmapMasked* pBMP = NULL;
00597 if ( nResID != NULL )
00598 pBMP = new BitmapMasked( nResID, crTC, crBC );
00599 else
00600 pBMP = new BitmapMasked( strName, crTC, crBC );
00601 m_mapBitmaps.insert( std::map<CString,BitmapBase*>::value_type( strID, pBMP ) );
00602 if ( pBMP->isInitialized() ) {
00603 return pBMP;
00604 }
00605 return NULL;
00606 }
00607
00608 CString strExt, strEx2;
00609 if ( strName.GetLength() >= 4 ) {
00610 strExt = strName.Right( 4 ).MakeLower();
00611
00612 if( strName.GetLength() >= 5)
00613 strEx2 = strName.Right(5).MakeLower();
00614
00615 if ( strExt != _T(".bmp") && strExt != _T(".gif") && strExt != _T(".png")
00616 && strExt != _T(".jpg") && strExt != _T(".jpe") && strEx2 != _T(".jpeg")
00617 && strExt != _T(".res") && strExt != _T(".wmf") && strExt != _T(".emf"))
00618 strExt = _T("");
00619 }
00620
00621 if( strExt.IsEmpty())
00622 {
00623 bool success = false;
00624 static TCHAR * exts[] = { _T(".bmp"), _T(".gif"), _T(".png"), _T(".jpg"), _T(".jpe"), _T(".jpeg"), _T(".wmf"), _T(".emf") };
00625 for( int i = 0; !success && i < 6; ++i)
00626 {
00627 CString strName2 = strName + exts[i];
00628 BitmapGen* pBMP = NULL;
00629 if ( bHasTC )
00630 pBMP = ( bHasBC ) ? new BitmapGen( strName2, crTC, crBC ) : new BitmapGen( strName2, crTC, true );
00631 else
00632 pBMP = ( bHasBC ) ? new BitmapGen( strName2, crBC, false ) : new BitmapGen( strName2);
00633 if ( pBMP->isInitialized() ) {
00634 m_mapBitmaps.insert( std::map<CString,BitmapBase*>::value_type( strID, pBMP ) );
00635 success = true;
00636 return pBMP;
00637 }
00638 delete pBMP;
00639 }
00640 }
00641 else if( strExt != _T(".res"))
00642 {
00643 BitmapGen* pBMP = NULL;
00644 if ( bHasTC )
00645 pBMP = ( bHasBC ) ? new BitmapGen( strName, crTC, crBC ) : new BitmapGen( strName, crTC, true );
00646 else
00647 pBMP = ( bHasBC ) ? new BitmapGen( strName, crBC, false ) : new BitmapGen( strName);
00648 if ( pBMP->isInitialized() ) {
00649 m_mapBitmaps.insert( std::map<CString,BitmapBase*>::value_type( strID, pBMP ) );
00650 return pBMP;
00651 }
00652 delete pBMP;
00653 }
00654
00655 if ( strExt == _T(".res") || strExt.IsEmpty() ) {
00656 int iID = _ttoi( strName.Left( strName.GetLength() - ( ( strExt.IsEmpty() ) ? 0 : 4 ) ) );
00657 if( iID == 0)
00658 return NULL;
00659 BitmapRES* pBMP = NULL;
00660 if ( bHasTC )
00661 pBMP = ( bHasBC ) ? new BitmapRES( iID, crTC, crBC ) : new BitmapRES( iID, crTC, true );
00662 else
00663 pBMP = ( bHasBC ) ? new BitmapRES( iID, crBC, false ) : new BitmapRES( iID );
00664 if ( pBMP->isInitialized() ) {
00665 m_mapBitmaps.insert( std::map<CString,BitmapBase*>::value_type( strID, pBMP ) );
00666 return pBMP;
00667 }
00668 delete pBMP;
00669 }
00670 m_mapBitmaps.insert( std::map<CString,BitmapBase*>::value_type( strID, static_cast<BitmapBase*>(NULL) ) );
00671 return NULL;
00672 }
00673
00674 BitmapBase* Facilities::getBitmap( const CString& strName )
00675 {
00676 return getBitmap( strName, false, 0x0, false, 0x0 );
00677 }
00678
00679 BitmapBase* Facilities::getBitmapT( const CString& strName, COLORREF crTransparent )
00680 {
00681 return getBitmap( strName, true, crTransparent, false, 0x0 );
00682 }
00683
00684 BitmapBase* Facilities::getBitmapB( const CString& strName, COLORREF crBackground )
00685 {
00686 return getBitmap( strName, false, 0x0, true, crBackground );
00687 }
00688
00689 BitmapBase* Facilities::getBitmapTB( const CString& strName, COLORREF crTransparent, COLORREF crBackground )
00690 {
00691 return getBitmap( strName, true, crTransparent, true, crBackground );
00692 }
00693
00694 BitmapBase* Facilities::getMaskedBitmap( const CString& strName, COLORREF crTransparent, COLORREF crBackground )
00695 {
00696 return getBitmap( strName, true, crTransparent, true, crBackground, true );
00697 }
00698
00699 BitmapBase* Facilities::getMaskedBitmap( UINT nResID, COLORREF crTransparent, COLORREF crBackground )
00700 {
00701 return getBitmap( _T(""), true, crTransparent, true, crBackground, true, nResID );
00702 }
00703
00704 void Facilities::addTileVector( const CString& strName, TileVector* vecTiles )
00705 {
00706 TileVector* vecStored = getTileVector( strName );
00707 if ( vecStored )
00708 delete vecStored;
00709 m_mapTileVectors[ strName ] = vecTiles;
00710 }
00711
00712 TileVector* Facilities::getTileVector( const CString& strName ) const
00713 {
00714 std::map<CString,TileVector*>::const_iterator it = m_mapTileVectors.find( strName );
00715 return ( it == m_mapTileVectors.end() ) ? NULL : it->second;
00716 }
00717
00718 void Facilities::createFont( int iFontKey, const CString& strKind, int iBoldness, bool bItalics, int iSize )
00719 {
00720 GdipFont* pgFont = GetFont( iFontKey );
00721 if ( pgFont ) {
00722 delete pgFont->gdipFont;
00723 delete pgFont;
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 m_mapFonts[ iFontKey ] = new GdipFont( strKind, iSize, iBoldness == FW_BOLD, bItalics );
00738
00739 CFont* pFont = new CFont();
00740 pFont->CreateFont( iSize, 0, 0, 0, iBoldness, bItalics, 0, 0, ANSI_CHARSET, OUT_DEVICE_PRECIS,
00741 CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_SWISS, strKind );
00742 LOGFONT logFont;
00743 pFont->GetLogFont(&logFont);
00744 m_mapFonts[ iFontKey ]->gdipFont = new Gdiplus::Font( getCDC()->m_hDC, &logFont );
00745
00746 pFont->DeleteObject();
00747 delete pFont;
00748 }
00749
00750 GdipFont* Facilities::GetFont( int iFontKey ) const
00751 {
00752 std::map<int,GdipFont*>::const_iterator it = m_mapFonts.find( iFontKey );
00753 return ( it == m_mapFonts.end() ) ? NULL : it->second;
00754 }
00755
00756 Gdiplus::Pen* Facilities::GetPen( COLORREF crColor, int iWidth )
00757 {
00758 CString chBuffer;
00759 chBuffer.Format(_T("%x-%ld"), crColor, iWidth);
00760 std::map<CString,Gdiplus::Pen*>::iterator it = m_mapPens.find(chBuffer);
00761 if (it != m_mapPens.end())
00762 return it->second;
00763 Gdiplus::Pen* pPen = new Gdiplus::Pen(Gdiplus::Color(GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)), static_cast<float> (iWidth));
00764 m_mapPens.insert( std::map<CString,Gdiplus::Pen*>::value_type(chBuffer, pPen));
00765 return pPen;
00766 }
00767
00768 Gdiplus::SolidBrush* Facilities::GetBrush( COLORREF crColor )
00769 {
00770 CString chBuffer;
00771 chBuffer.Format(_T("%x"), crColor);
00772 std::map<CString,Gdiplus::SolidBrush*>::iterator it = m_mapBrushes.find(chBuffer);
00773 if (it != m_mapBrushes.end())
00774 return it->second;
00775 Gdiplus::SolidBrush* pBrush = new Gdiplus::SolidBrush(Gdiplus::Color(GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)));
00776 m_mapBrushes.insert(std::map<CString,Gdiplus::SolidBrush*>::value_type(chBuffer, pBrush));
00777 return pBrush;
00778 }
00779
00780 CSize Facilities::MeasureText( Gdiplus::Graphics* gdip, GdipFont* pFont, const CString& strText) const
00781 {
00782 return MeasureText(gdip, pFont->gdipFont, strText);
00783 }
00784
00785 CSize Facilities::MeasureText( Gdiplus::Graphics* gdip, Gdiplus::Font* pFont, const CString& strText) const
00786 {
00787 Gdiplus::Graphics* gdip2 = gdip;
00788 if (gdip == NULL)
00789 gdip2 = m_gdip;
00790
00791 Gdiplus::PointF origin(0, 0);
00792 Gdiplus::RectF rectF;
00793 CStringW strText2(strText);
00794 gdip2->MeasureString(strText2, strText2.GetLength(), pFont, origin, &rectF);
00795 Gdiplus::SizeF sizeF;
00796 rectF.GetSize(&sizeF);
00797 CSize size(static_cast<long> (sizeF.Width), static_cast<long> (sizeF.Height));
00798
00799 return size;
00800 }
00801
00802 void Facilities::DrawString( Gdiplus::Graphics* gdip, const CString& strText, const CRect& crBounds, GdipFont* pFont,
00803 COLORREF crColor, int iAlign, int iLength, const CString& strPre, const CString& strPost, bool bPeriods ) const
00804 {
00805 DrawString(gdip, strText, crBounds, pFont->gdipFont, crColor, iAlign, iLength, strPre, strPost, bPeriods);
00806 }
00807
00808 void Facilities::DrawString( Gdiplus::Graphics* gdip, const CString& strText, const CRect& crBounds, Gdiplus::Font* pFont,
00809 COLORREF crColor, int iAlign, int iLength, const CString& strPre, const CString& strPost, bool bPeriods ) const
00810 {
00811 CString strText2( strPre + strText + strPost );
00812 if ( iLength != -1 && strText2.GetLength() > iLength )
00813 strText2 = strPre + strText.Left( iLength ) + ( ( bPeriods ) ? _T("...") : _T("") ) + strPost;
00814
00815 Gdiplus::StringFormat format;
00816 Gdiplus::StringAlignment horizontalAlignment;
00817 if ((iAlign & TA_CENTER) == TA_CENTER) {
00818 horizontalAlignment = Gdiplus::StringAlignmentCenter;
00819 } else if ((iAlign & TA_RIGHT) == TA_RIGHT) {
00820 horizontalAlignment = Gdiplus::StringAlignmentFar;
00821 } else {
00822 horizontalAlignment = Gdiplus::StringAlignmentNear;
00823 }
00824 format.SetAlignment(horizontalAlignment);
00825 Gdiplus::StringAlignment verticalAlignment;
00826 if ((iAlign & TA_BASELINE) == TA_BASELINE) {
00827 verticalAlignment = Gdiplus::StringAlignmentCenter;
00828 } else if ((iAlign & TA_BOTTOM) == TA_BOTTOM) {
00829 verticalAlignment = Gdiplus::StringAlignmentFar;
00830 } else {
00831 verticalAlignment = Gdiplus::StringAlignmentNear;
00832 }
00833 format.SetLineAlignment(verticalAlignment);
00834 format.SetFormatFlags(format.GetFormatFlags() | Gdiplus::StringFormatFlagsNoWrap);
00835 format.SetTrimming(Gdiplus::StringTrimmingEllipsisPath);
00836
00837
00838 COLORREF textColor = crColor;
00839
00840
00841 Gdiplus::SolidBrush textBrush(Gdiplus::Color(GetRValue(textColor),
00842 GetGValue(textColor),
00843 GetBValue(textColor)));
00844
00845 CStringW wcTxt(strText2);
00846 if (isRunningUnderWine()) {
00847
00848
00849 CSize size = this->MeasureText(gdip, pFont, strText2);
00850 Gdiplus::PointF pointF(static_cast<float> (crBounds.left),
00851 static_cast<float> (crBounds.top));
00852 if ((iAlign & TA_CENTER) == TA_CENTER) {
00853 pointF.X += (crBounds.Width() - size.cx) / 2;
00854 } else if ((iAlign & TA_RIGHT) == TA_RIGHT) {
00855 pointF.X += crBounds.Width() - size.cx;
00856 }
00857
00858 format.SetAlignment(Gdiplus::StringAlignmentNear);
00859 format.SetLineAlignment(Gdiplus::StringAlignmentNear);
00860 gdip->DrawString(wcTxt, strText2.GetLength(), pFont, pointF, &format, &textBrush);
00861 } else {
00862 Gdiplus::RectF rectF(static_cast<float> (crBounds.left),
00863 static_cast<float> (crBounds.top),
00864 static_cast<float> (crBounds.Width()),
00865 static_cast<float> (crBounds.Height()));
00866 gdip->DrawString(wcTxt, strText2.GetLength(), pFont, rectF, &format, &textBrush);
00867 }
00868
00869 }
00870
00871 void Facilities::DrawRect( Gdiplus::Graphics* gdip, const CRect& cRect, COLORREF crColor, int iWidth,
00872 bool bRoundRect, int iCornerRadius ) const
00873 {
00874 Facilities* pThis = (Facilities*) this;
00875 Gdiplus::Pen* pPen = pThis->GetPen( crColor, iWidth );
00876 CRect cRect2 = cRect;
00877 cRect2.DeflateRect( iWidth / 2, iWidth / 2 );
00878
00879 if (bRoundRect && iCornerRadius > 0) {
00880 long diameter = 2 * iCornerRadius;
00881 Gdiplus::GraphicsPath buttonPath;
00882 buttonPath.AddArc(cRect2.left, cRect2.top, diameter, diameter, 180.0, 90.0);
00883 buttonPath.AddLine(cRect2.left + iCornerRadius, cRect2.top, cRect2.right - iCornerRadius, cRect2.top);
00884 buttonPath.AddArc(cRect2.right - diameter, cRect2.top, diameter, diameter, 270.0, 90.0);
00885 buttonPath.AddLine(cRect2.right, cRect2.top + iCornerRadius, cRect2.right, cRect2.bottom - iCornerRadius);
00886 buttonPath.AddArc(cRect2.right - diameter, cRect2.bottom - diameter, diameter, diameter, 0.0, 90.0);
00887 buttonPath.AddLine(cRect2.right - iCornerRadius, cRect2.bottom, cRect2.left + iCornerRadius, cRect2.bottom);
00888 buttonPath.AddArc(cRect2.left, cRect2.bottom - diameter, diameter, diameter, 90.0, 90.0);
00889 buttonPath.AddLine(cRect2.left, cRect2.bottom - iCornerRadius, cRect2.left, cRect2.top + iCornerRadius);
00890 gdip->DrawPath(pPen, &buttonPath);
00891 } else {
00892 gdip->DrawRectangle(pPen, cRect2.left, cRect2.top, cRect2.Width(), cRect2.Height());
00893 }
00894 }
00895
00896 void Facilities::DrawBox( Gdiplus::Graphics* gdip, const CRect& cRect, COLORREF crColor, int iDepth,
00897 bool bRoundRect, int iCornerRadius ) const
00898 {
00899 COLORREF beginColor = ShiftColor(crColor, -40);
00900 COLORREF endColor = ShiftColor(crColor, 60);
00901
00902 Gdiplus::Color darkerColor = Gdiplus::Color(GetRValue(beginColor),
00903 GetGValue(beginColor),
00904 GetBValue(beginColor));
00905 Gdiplus::Color lighterColor = Gdiplus::Color(GetRValue(endColor),
00906 GetGValue(endColor),
00907 GetBValue(endColor));
00908
00909 if (isRunningUnderWine()) {
00910
00911 Gdiplus::SolidBrush brush(lighterColor);
00912 gdip->FillRectangle(&brush, cRect.left, cRect.top, cRect.right - cRect.left, cRect.bottom - cRect.top);
00913 } else if (bRoundRect && iCornerRadius > 0) {
00914 long diameter = 2 * iCornerRadius;
00915 Gdiplus::GraphicsPath buttonPath;
00916 CRect tmpRect = cRect;
00917 CRect cRect = tmpRect;
00918 cRect.right -= 1;
00919 cRect.top -= 1;
00920 buttonPath.AddArc(cRect.left, cRect.top, diameter, diameter, 180.0, 90.0);
00921 buttonPath.AddLine(cRect.left + iCornerRadius, cRect.top, cRect.right - iCornerRadius, cRect.top);
00922 buttonPath.AddArc(cRect.right - diameter, cRect.top, diameter, diameter, 270.0, 90.0);
00923 buttonPath.AddLine(cRect.right, cRect.top + iCornerRadius, cRect.right, cRect.bottom - iCornerRadius);
00924 buttonPath.AddArc(cRect.right - diameter, cRect.bottom - diameter, diameter, diameter, 0.0, 90.0);
00925 buttonPath.AddLine(cRect.right - iCornerRadius, cRect.bottom, cRect.left + iCornerRadius, cRect.bottom);
00926 buttonPath.AddArc(cRect.left, cRect.bottom - diameter, diameter, diameter, 90.0, 90.0);
00927 buttonPath.AddLine(cRect.left, cRect.bottom - iCornerRadius, cRect.left, cRect.top + iCornerRadius);
00928
00929 Gdiplus::PathGradientBrush roundPathGradientBrush(&buttonPath);
00930 Gdiplus::Color presetColors[] = {
00931 darkerColor,
00932 lighterColor,
00933 lighterColor };
00934 float bandRatio = static_cast<float> (static_cast<float> (iDepth) / min(cRect.Width(), cRect.Height()));
00935 if (bandRatio > 1.0)
00936 bandRatio = 1.0;
00937 float interpolationPositions[] = {
00938 0.0f,
00939 bandRatio,
00940 1.0f };
00941 roundPathGradientBrush.SetInterpolationColors(presetColors, interpolationPositions, 3);
00942
00943 gdip->FillPath(&roundPathGradientBrush, &buttonPath);
00944 } else {
00945 int width = cRect.Width();
00946 int height = cRect.Height();
00947 if (width > height) {
00948
00949
00950
00951
00952
00953
00954 int h2 = height / 2;
00955 CPoint leftFocus;
00956 leftFocus.x = cRect.left + h2;
00957 leftFocus.y = cRect.top + h2;
00958 CPoint rightFocus;
00959 rightFocus.x = cRect.right - h2;
00960 rightFocus.y = leftFocus.y;
00961
00962 Gdiplus::GraphicsPath doubleTrapezPath;
00963 doubleTrapezPath.AddLine(cRect.left, cRect.top, cRect.right, cRect.top);
00964 doubleTrapezPath.AddLine(cRect.right, cRect.top, cRect.right, cRect.top + 1);
00965 doubleTrapezPath.AddLine(cRect.right, cRect.top + 1, rightFocus.x + 1, rightFocus.y);
00966 doubleTrapezPath.AddLine(rightFocus.x + 1, rightFocus.y, cRect.right, cRect.bottom - 1);
00967 doubleTrapezPath.AddLine(cRect.right, cRect.bottom - 1, cRect.right, cRect.bottom);
00968 doubleTrapezPath.AddLine(cRect.right, cRect.bottom, cRect.left, cRect.bottom);
00969 doubleTrapezPath.AddLine(cRect.left, cRect.bottom, cRect.left, cRect.bottom - 1);
00970 doubleTrapezPath.AddLine(cRect.left, cRect.bottom - 1, leftFocus.x - 1, leftFocus.y);
00971 doubleTrapezPath.AddLine(leftFocus.x - 1, leftFocus.y, cRect.left, cRect.top + 1);
00972 doubleTrapezPath.AddLine(cRect.left, cRect.top + 1, cRect.left, cRect.top);
00973
00974 float bandRatio = static_cast<float> (static_cast<float> (iDepth) / cRect.Height());
00975 if (bandRatio > 1.0)
00976 bandRatio = 1.0;
00977 Gdiplus::LinearGradientBrush trapezGradientBrush(Gdiplus::Point(cRect.left, cRect.top),
00978 Gdiplus::Point(cRect.left, cRect.bottom),
00979 darkerColor,
00980 lighterColor);
00981 float blendFactors[] = {
00982 0.0f,
00983 1.0f,
00984 1.0f,
00985 0.0f };
00986 float blendPositions[] = {
00987 0.0f,
00988 bandRatio,
00989 1.0f - bandRatio,
00990 1.0f };
00991 trapezGradientBrush.SetBlend(blendFactors, blendPositions, 4);
00992 gdip->FillPath(&trapezGradientBrush, &doubleTrapezPath);
00993
00994 float bandRatio2 = static_cast<float> (static_cast<float> (iDepth) / h2);
00995 if (bandRatio2 > 1.0)
00996 bandRatio2 = 1.0;
00997 Gdiplus::GraphicsPath leftTrianglePath;
00998 leftTrianglePath.AddLine(cRect.left, cRect.top, leftFocus.x, leftFocus.y);
00999 leftTrianglePath.AddLine(leftFocus.x, leftFocus.y, cRect.left, cRect.bottom);
01000 leftTrianglePath.AddLine(cRect.left, cRect.bottom, cRect.left, cRect.top);
01001 Gdiplus::LinearGradientBrush leftTriangleGradientBrush(Gdiplus::Point(cRect.left, leftFocus.y),
01002 Gdiplus::Point(leftFocus.x, leftFocus.y),
01003 darkerColor,
01004 lighterColor);
01005 float leftBlendFactors[] = {
01006 0.0f,
01007 1.0f,
01008 1.0f };
01009 float leftBlendPositions[] = {
01010 0.0f,
01011 bandRatio2,
01012 1.0f };
01013 leftTriangleGradientBrush.SetBlend(leftBlendFactors, leftBlendPositions, 3);
01014 gdip->FillPath(&leftTriangleGradientBrush, &leftTrianglePath);
01015
01016 Gdiplus::GraphicsPath rightTrianglePath;
01017 rightTrianglePath.AddLine(cRect.right, cRect.top, cRect.right, cRect.bottom);
01018 rightTrianglePath.AddLine(cRect.right, cRect.bottom, rightFocus.x, rightFocus.y);
01019 rightTrianglePath.AddLine(rightFocus.x, rightFocus.y, cRect.right, cRect.top);
01020 Gdiplus::LinearGradientBrush rightTriangleGradientBrush(Gdiplus::Point(rightFocus.x, rightFocus.y),
01021 Gdiplus::Point(cRect.right, rightFocus.y),
01022 lighterColor,
01023 darkerColor);
01024 float rightBlendFactors[] = {
01025 0.0f,
01026 0.0f,
01027 1.0f };
01028 float rightBlendPositions[] = {
01029 0.0f,
01030 1.0f - bandRatio2,
01031 1.0f };
01032 rightTriangleGradientBrush.SetBlend(rightBlendFactors, rightBlendPositions, 3);
01033 gdip->FillPath(&rightTriangleGradientBrush, &rightTrianglePath);
01034 } else {
01035
01036
01037
01038
01039
01040
01041
01042
01043 int w2 = width / 2;
01044 CPoint topFocus;
01045 topFocus.x = cRect.left + w2;
01046 topFocus.y = cRect.top + w2;
01047 CPoint bottomFocus;
01048 bottomFocus.x = topFocus.x;
01049 bottomFocus.y = cRect.bottom - w2;
01050
01051 Gdiplus::GraphicsPath doubleTrapezPath;
01052 doubleTrapezPath.AddLine(cRect.left, cRect.top, cRect.left + 1, cRect.top);
01053 doubleTrapezPath.AddLine(cRect.left + 1, cRect.top, topFocus.x, topFocus.y - 1);
01054 doubleTrapezPath.AddLine(topFocus.x, topFocus.y - 1, cRect.right - 1, cRect.top);
01055 doubleTrapezPath.AddLine(cRect.right - 1, cRect.top, cRect.right, cRect.top);
01056 doubleTrapezPath.AddLine(cRect.right, cRect.top, cRect.right, cRect.bottom);
01057 doubleTrapezPath.AddLine(cRect.right, cRect.bottom, cRect.right - 1, cRect.bottom);
01058 doubleTrapezPath.AddLine(cRect.right - 1, cRect.bottom, bottomFocus.x, bottomFocus.y + 1);
01059 doubleTrapezPath.AddLine(bottomFocus.x, bottomFocus.y + 1, cRect.left + 1, cRect.bottom);
01060 doubleTrapezPath.AddLine(cRect.left + 1, cRect.bottom, cRect.left, cRect.bottom);
01061 doubleTrapezPath.AddLine(cRect.left, cRect.bottom, cRect.left, cRect.top);
01062
01063 float bandRatio = static_cast<float> (static_cast<float> (iDepth) / cRect.Width());
01064 if (bandRatio > 1.0)
01065 bandRatio = 1.0;
01066 Gdiplus::LinearGradientBrush trapezGradientBrush(Gdiplus::Point(cRect.left, cRect.top),
01067 Gdiplus::Point(cRect.right, cRect.top),
01068 darkerColor,
01069 lighterColor);
01070 float blendFactors[] = {
01071 0.0f,
01072 1.0f,
01073 1.0f,
01074 0.0f };
01075 float blendPositions[] = {
01076 0.0f,
01077 bandRatio,
01078 1.0f - bandRatio,
01079 1.0f };
01080 trapezGradientBrush.SetBlend(blendFactors, blendPositions, 4);
01081 gdip->FillPath(&trapezGradientBrush, &doubleTrapezPath);
01082
01083 float bandRatio2 = static_cast<float> (static_cast<float> (iDepth) / w2);
01084 if (bandRatio2 > 1.0)
01085 bandRatio2 = 1.0;
01086 Gdiplus::GraphicsPath topTrianglePath;
01087 topTrianglePath.AddLine(cRect.left, cRect.top, cRect.right, cRect.top);
01088 topTrianglePath.AddLine(cRect.right, cRect.top, topFocus.x, topFocus.y);
01089 topTrianglePath.AddLine(topFocus.x, topFocus.y, cRect.left, cRect.top);
01090 Gdiplus::LinearGradientBrush topTriangleGradientBrush(Gdiplus::Point(topFocus.x, cRect.top),
01091 Gdiplus::Point(topFocus.x, topFocus.y),
01092 darkerColor,
01093 lighterColor);
01094 float topBlendFactors[] = {
01095 0.0f,
01096 1.0f,
01097 1.0f };
01098 float topBlendPositions[] = {
01099 0.0f,
01100 bandRatio2,
01101 1.0f };
01102 topTriangleGradientBrush.SetBlend(topBlendFactors, topBlendPositions, 3);
01103 gdip->FillPath(&topTriangleGradientBrush, &topTrianglePath);
01104
01105 Gdiplus::GraphicsPath bottomTrianglePath;
01106 bottomTrianglePath.AddLine(cRect.left, cRect.bottom, bottomFocus.x, bottomFocus.y);
01107 bottomTrianglePath.AddLine(bottomFocus.x, bottomFocus.y, cRect.right, cRect.bottom);
01108 bottomTrianglePath.AddLine(cRect.right, cRect.bottom, cRect.left, cRect.bottom);
01109 Gdiplus::LinearGradientBrush bottomTriangleGradientBrush(Gdiplus::Point(bottomFocus.x, bottomFocus.y),
01110 Gdiplus::Point(bottomFocus.x, cRect.bottom),
01111 lighterColor,
01112 darkerColor);
01113 float bottomBlendFactors[] = {
01114 0.0f,
01115 0.0f,
01116 1.0f };
01117 float bottomBlendPositions[] = {
01118 0.0f,
01119 1.0f - bandRatio2,
01120 1.0f };
01121 bottomTriangleGradientBrush.SetBlend(bottomBlendFactors, bottomBlendPositions, 3);
01122 gdip->FillPath(&bottomTriangleGradientBrush, &bottomTrianglePath);
01123 }
01124 }
01125 }
01126
01127 COLORREF Facilities::ShiftColor( COLORREF crColor, int iShift ) const
01128 {
01129 int iR = GetRValue( crColor );
01130 int iG = GetGValue( crColor );
01131 int iB = GetBValue( crColor );
01132 iR = min( max( iR + iShift, 0 ), 255 );
01133 iG = min( max( iG + iShift, 0 ), 255 );
01134 iB = min( max( iB + iShift, 0 ), 255 );
01135 return RGB( iR, iG, iB );
01136 }
01137
01138 double Facilities::Deg2Rad( long deg ) const
01139 {
01140 return (deg * 2 * M_PI / 360.0);
01141 }
01142
01143 std::vector<CString> Facilities::wrapString( const CString& strIn, int iWrap, int iMax ) const
01144 {
01145 std::vector<CString> vecOut;
01146 CString str = strIn;
01147 str.TrimLeft();
01148 str.TrimRight();
01149 iWrap = min( iMax, iWrap );
01150 if ( iWrap == 0 || iWrap == -1 )
01151 vecOut.push_back( str );
01152 else {
01153 while ( ! str.IsEmpty() ) {
01154 CString str2 = str;
01155 if ( str.GetLength() > iWrap ) {
01156 str2 = str.Left( iWrap );
01157 int iPos = str2.ReverseFind( ' ' );
01158 if ( iPos == -1 || iPos < str2.GetLength() - 5 ) {
01159 str2 = str.Right( str.GetLength() - iWrap );
01160 iPos = str2.Find( ' ' );
01161 if ( iPos == -1 && str2.GetLength() > 5 || iPos >= 5 ) {
01162 str2 = str.Left( iWrap );
01163 str = str.Right( str.GetLength() - iWrap );
01164 }
01165 else {
01166 if ( iPos == -1 )
01167 iPos = str2.GetLength();
01168 str2 = str.Left( iWrap + iPos );
01169 str = str.Right( str.GetLength() - iWrap - iPos - 1 );
01170 }
01171 }
01172 else {
01173 str2 = str.Left( iPos );
01174 str = str.Right( str.GetLength() - iPos - 1 );
01175 }
01176 }
01177 else
01178 str = "";
01179 str2.TrimRight();
01180 str.TrimLeft();
01181 vecOut.push_back( str2 );
01182 }
01183 }
01184 return vecOut;
01185 }
01186
01187 CString Facilities::getStereotyped( const CString& strIn ) const
01188 {
01189 CString str;
01190 if (stereotypeCharacterType)
01191 str = str + STEREOTYPE_LEFTB + strIn + STEREOTYPE_RIGHTB;
01192 else
01193 str = str + STEREOTYPE_LEFTA + strIn + STEREOTYPE_RIGHTA;
01194 return str;
01195 }
01196
01197 };