diff --git a/MUSHclient.cpp b/MUSHclient.cpp index 69e41891..82c23d66 100644 --- a/MUSHclient.cpp +++ b/MUSHclient.cpp @@ -64,6 +64,8 @@ bool bWinNT; bool bWin95; bool bWin98; bool bWine; +OSVERSIONINFO os_version; + // memory state tracking #ifdef _DEBUG @@ -641,15 +643,14 @@ BOOL CMUSHclientApp::InitInstance() // see which OS we are using - OSVERSIONINFO ver; - memset(&ver, 0, sizeof(ver)); - ver.dwOSVersionInfoSize = sizeof(ver); - VERIFY(::GetVersionEx(&ver)); - bWinNT = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT); - bWin95 = (ver.dwPlatformId == - VER_PLATFORM_WIN32_WINDOWS) && (ver.dwMinorVersion == 0); - bWin98 = (ver.dwPlatformId == - VER_PLATFORM_WIN32_WINDOWS) && (ver.dwMinorVersion > 0); + memset(&os_version, 0, sizeof(os_version)); + os_version.dwOSVersionInfoSize = sizeof(os_version); + VERIFY(::GetVersionEx(&os_version)); + bWinNT = (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT); + bWin95 = (os_version.dwPlatformId == + VER_PLATFORM_WIN32_WINDOWS) && (os_version.dwMinorVersion == 0); + bWin98 = (os_version.dwPlatformId == + VER_PLATFORM_WIN32_WINDOWS) && (os_version.dwMinorVersion > 0); // MXP initialisation diff --git a/miniwindow.cpp b/miniwindow.cpp index 94225d30..e3daa81a 100644 --- a/miniwindow.cpp +++ b/miniwindow.cpp @@ -2525,160 +2525,6 @@ long CMiniWindow::ImageFromWindow(LPCTSTR ImageId, CMiniWindow * pSrcWindow) } // end of CMiniWindow::ImageFromWindow -static void HorizontalLinearGradient (const COLORREF StartColour, - const COLORREF EndColour, - unsigned char * pBuffer, - const long iWidth, - const long iHeight) - { - - if (iWidth < 1) - return; // avoid divide by zero - - double rdiff = GetRValue (EndColour) - GetRValue (StartColour), - gdiff = GetGValue (EndColour) - GetGValue (StartColour), - bdiff = GetBValue (EndColour) - GetBValue (StartColour); - - double rval = GetRValue (StartColour), - gval = GetGValue (StartColour), - bval = GetBValue (StartColour); - - double rinc = rdiff / (double) (iWidth - 1), - ginc = gdiff / (double) (iWidth - 1), - binc = bdiff / (double) (iWidth - 1); - - long row, col; - uint8 r = 0, g = 0, b = 0; - - int increment = BytesPerLine (iWidth, 24); - - // main loop is columns - for (col = 0; col < iWidth; col++) - { - r = (uint8) rval; - g = (uint8) gval; - b = (uint8) bval; - unsigned char * p = pBuffer + col * 3; - for (row = 0; row < iHeight; row++) - { - p [0] = b; - p [1] = g; - p [2] = r; - p += increment; - } // end of each row - rval += rinc; - gval += ginc; - bval += binc; - } // end of each column - - - } // end of HorizontalLinearGradient - -static void HorizontalLinearGradientHSL (const CColor StartColour, - const CColor EndColour, - unsigned char * pBuffer, - const long iWidth, - const long iHeight) - { - - if (iWidth < 1) - return; // avoid divide by zero - - double starthue = StartColour.GetHue (); - double endhue = EndColour.GetHue (); - double startlum = StartColour.GetLuminance (); - double endlum = EndColour.GetLuminance (); - double startsat = StartColour.GetSaturation (); - double endsat = EndColour.GetSaturation (); - - - double hinc = (endhue - starthue) / (double) (iWidth - 1), - linc = (endlum - startlum) / (double) (iWidth - 1), - sinc = (endsat - startsat) / (double) (iWidth - 1); - - long row, col; - uint8 r = 0, g = 0, b = 0; - - int increment = BytesPerLine (iWidth, 24); - - // main loop is columns - for (col = 0; col < iWidth; col++) - { - double h = starthue; - double l = startlum; - double s = startsat; - - CColor c; - c.SetHLS (h, l, s); - r = c.GetRed (); - g = c.GetGreen (); - b = c.GetBlue (); - - unsigned char * p = pBuffer + col * 3; - for (row = 0; row < iHeight; row++) - { - p [0] = b; - p [1] = g; - p [2] = r; - p += increment; - } // end of each row - starthue += hinc; - startlum += linc; - startsat += sinc; - } // end of each column - - - } // end of HorizontalLinearGradient - -static void VerticalLinearGradient (const COLORREF StartColour, - const COLORREF EndColour, - unsigned char * pBuffer, - const long iWidth, - const long iHeight) - { - - if (iHeight < 1) - return; // avoid divide by zero - - double rdiff = GetRValue (EndColour) - GetRValue (StartColour), - gdiff = GetGValue (EndColour) - GetGValue (StartColour), - bdiff = GetBValue (EndColour) - GetBValue (StartColour); - - double rval = GetRValue (EndColour), - gval = GetGValue (EndColour), - bval = GetBValue (EndColour); - - double rinc = - rdiff / (double) (iHeight - 1), - ginc = - gdiff / (double) (iHeight - 1), - binc = - bdiff / (double) (iHeight - 1); - - long row, col; - uint8 r = 0, g = 0, b = 0; - - int increment = BytesPerLine (iWidth, 24); - - // main loop is rows - for (row = 0; row < iHeight; row++) - { - r = (uint8) rval; - g = (uint8) gval; - b = (uint8) bval; - unsigned char * p = pBuffer + increment * row; - for (col = 0; col < iWidth; col++) - { - p [0] = b; - p [1] = g; - p [2] = r; - p += 3; - } // end of each column - rval += rinc; - gval += ginc; - bval += binc; - } // end of each row - - } // end of VerticalLinearGradient - - static void MakeTexture (const COLORREF Multiplier, unsigned char * pBuffer, const long iWidth, @@ -2712,155 +2558,161 @@ static void MakeTexture (const COLORREF Multiplier, } // end of MakeTexture -// this is a load of old cobblers - -#if 0 - -static void HorizontalLogGradient (const COLORREF StartColour, const double rdiff, const double gdiff, const double bdiff, - unsigned char * pBuffer, - const long iWidth, - const long iHeight, - const bool rightToLeft) +long CMiniWindow::Gradient(long Left, long Top, long Right, long Bottom, + long StartColour, long EndColour, + short Mode) { - double rval = GetRValue (StartColour), - gval = GetGValue (StartColour), - bval = GetBValue (StartColour); + // calculate size of desired rectangle + long iWidth = FixRight (Right) - Left; + long iHeight = FixBottom (Bottom) - Top; + if (iWidth <= 0 || iHeight <= 0) // sanity check + return eOK; - double rfactor = pow (abs (rdiff), (double) 1.0 / (double) iWidth); - double gfactor = pow (abs (gdiff), (double) 1.0 / (double) iWidth); - double bfactor = pow (abs (bdiff), (double) 1.0 / (double) iWidth); + // Texture Fill requires slower method + if (Mode == 3) + { - long row, col; - uint8 r = 0, g = 0, b = 0; + // upper layer (from image id) + CDC gDC; + gDC.CreateCompatibleDC(&dc); + CBitmap gbmp; - double rinc = rfactor, - ginc = gfactor, - binc = bfactor; + BITMAPINFO bmi; + ZeroMemory (&bmi, sizeof bmi); - int increment = BytesPerLine (iWidth, 24); + bmi.bmiHeader.biSize = sizeof bmi; + bmi.bmiHeader.biWidth = iWidth; + bmi.bmiHeader.biHeight = iHeight; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 24; + bmi.bmiHeader.biCompression = BI_RGB; + bmi.bmiHeader.biSizeImage = iHeight * BytesPerLine (iWidth, 24); - // main loop is columns - for (col = 0; col < iWidth; col++) - { + unsigned char * pA = NULL; + HBITMAP hbmG = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pA, NULL, 0); - r = (uint8) rval; - g = (uint8) gval; - b = (uint8) bval; - unsigned char * p = pBuffer + col * 3; - for (row = 0; row < iHeight; row++) - { - p [0] = b; - p [1] = g; - p [2] = r; - p += increment; - } // end of each row + HBITMAP hOldAbmp = (HBITMAP) SelectObject(gDC.m_hDC, hbmG); - rinc *= rfactor; - ginc *= gfactor; - binc *= bfactor; + MakeTexture (StartColour, pA, iWidth, iHeight); - if (rightToLeft) - { - rval = GetRValue (StartColour) - rinc; - gval = GetGValue (StartColour) - ginc; - bval = GetBValue (StartColour) - binc; - } - else - { - rval = GetRValue (StartColour) + rinc; - gval = GetGValue (StartColour) + ginc; - bval = GetBValue (StartColour) + binc; - } - } // end of each column + // copy result back + dc.BitBlt (Left, Top, iWidth, iHeight, &gDC, 0, 0, SRCCOPY); - } // end of HorizontalLogGradient -#endif // 0 + SelectObject(gDC.m_hDC, hOldAbmp); -long CMiniWindow::Gradient(long Left, long Top, long Right, long Bottom, - long StartColour, long EndColour, - short Mode) - { - // calculate size of desired rectangle - long iWidth = FixRight (Right) - Left; - long iHeight = FixBottom (Bottom) - Top; + DeleteObject (hbmG); - if (iWidth <= 0 || iHeight <= 0) // sanity check return eOK; - // upper layer (from image id) - CDC gDC; - gDC.CreateCompatibleDC(&dc); - CBitmap gbmp; + } // end of texture fill - BITMAPINFO bmi; - ZeroMemory (&bmi, sizeof bmi); + + // for Windows 2000 onwards, use faster GDI fill mode as suggested by Twisol + // See: http://msdn.microsoft.com/en-us/library/aa925212.aspx - bmi.bmiHeader.biSize = sizeof bmi; - bmi.bmiHeader.biWidth = iWidth; - bmi.bmiHeader.biHeight = iHeight; - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = 24; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biSizeImage = iHeight * BytesPerLine (iWidth, 24); - - unsigned char * pA = NULL; - - HBITMAP hbmG = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pA, NULL, 0); + if (os_version.dwPlatformId > VER_PLATFORM_WIN32_NT || // some future version? + (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT && // NT upwards + os_version.dwMajorVersion >= 5)) // Windows 2000 upwards + { - HBITMAP hOldAbmp = (HBITMAP) SelectObject(gDC.m_hDC, hbmG); + TRIVERTEX vert[2] ; + GRADIENT_RECT gRect; + DWORD dwMode; + + // first vertex + vert [0] .x = Left; + vert [0] .y = Top; + vert [0] .Red = GetRValue (StartColour) << 8; // higher resolution colours + vert [0] .Green = GetGValue (StartColour) << 8; + vert [0] .Blue = GetBValue (StartColour) << 8; + vert [0] .Alpha = 0; + + // second vertex + vert [1] .x = Right; + vert [1] .y = Bottom; + vert [1] .Red = GetRValue (EndColour) << 8; + vert [1] .Green = GetGValue (EndColour) << 8; + vert [1] .Blue = GetBValue (EndColour) << 8; + vert [1] .Alpha = 0; + + // rectange goes from first vertex to second one + gRect.UpperLeft = 0; + gRect.LowerRight = 1; - switch (Mode) - { - case 1 : // horizontal (left to right) - HorizontalLinearGradient (StartColour, EndColour, pA, iWidth, iHeight); - break; // end of horizontal + switch (Mode) + { + case 1 : dwMode = GRADIENT_FILL_RECT_H; break; // horizontal + case 2 : dwMode = GRADIENT_FILL_RECT_V; break; // vertical + default: return eUnknownOption; + } // end of switch + // do the fill + GradientFill (dc.m_hDC, vert, 2, &gRect, 1, dwMode); + + return eOK; - case 2 : // vertical (top to bottom) - VerticalLinearGradient (StartColour, EndColour, pA, iWidth, iHeight); - break; // end of vertical + } // end of Windows 2000 or higher - case 3 : // texture - MakeTexture (StartColour, pA, iWidth, iHeight); - break; // end of texture + // slower method (also suggested by Twisol rather than doing individual bytes): + double rdiff = GetRValue (EndColour) - GetRValue (StartColour), + gdiff = GetGValue (EndColour) - GetGValue (StartColour), + bdiff = GetBValue (EndColour) - GetBValue (StartColour); - // forget it! + double rval = GetRValue (StartColour), + gval = GetGValue (StartColour), + bval = GetBValue (StartColour); -#if 0 - case 4 : // horizontal (left to right) - HorizontalLinearGradientHSL (CColor (StartColour), CColor (EndColour), pA, iWidth, iHeight); - break; // end of horizontal + double rinc = rdiff / (double) (iWidth - 1), + ginc = gdiff / (double) (iWidth - 1), + binc = bdiff / (double) (iWidth - 1); - case 5 : // horizontal (left to right) - HorizontalLogGradient (StartColour, rdiff, gdiff, bdiff, pA, iWidth, iHeight, false); - break; // end of horizontal + COLORREF oldColour = dc.GetBkColor (); + dc.SetBkMode (TRANSPARENT); - case 6 : // horizontal (right to left) - HorizontalLogGradient (EndColour, rdiff, gdiff, bdiff, pA, iWidth, iHeight, true); - break; // end of horizontal -#endif // 0 + switch (Mode) + { + case 1 : // horizontal (left to right) - default: return eUnknownOption; + { + for (long x = Left; x < Right; x++) + { + dc.FillSolidRect( x, Top, 1, Bottom - Top, RGB (rval, gval, bval) ); + rval += rinc; + gval += ginc; + bval += binc; + } + } - } // end of switch + break; // end of horizontal + case 2 : // vertical (top to bottom) - // copy result back + { + for (long y = Top; y < Bottom; y++) + { + dc.FillSolidRect( Left, y, Right - Left, 1, RGB (rval, gval, bval) ); + rval += rinc; + gval += ginc; + bval += binc; + } + } + + break; // end of vertical - dc.BitBlt (Left, Top, iWidth, iHeight, &gDC, 0, 0, SRCCOPY); + default: return eUnknownOption; - SelectObject(gDC.m_hDC, hOldAbmp); + } // end of switch - DeleteObject (hbmG); - return eOK; + dc.SetBkColor (oldColour); // FillSolidRect changes the background colour + return eOK; // end of horizontal or vertical } // end of CMiniWindow::Gradient diff --git a/scripting/methods/methods_info.cpp b/scripting/methods/methods_info.cpp index 4203c6d3..076b9337 100644 --- a/scripting/methods/methods_info.cpp +++ b/scripting/methods/methods_info.cpp @@ -373,16 +373,6 @@ static void GetWindowHeight (CWnd * pWnd, VARIANT & vaResult, const bool client vaResult.lVal = rect.bottom; } // end of GetWindowHeight -OSVERSIONINFO ver; - -static void GetOSVersion (void) - { - // see which OS we are using - memset(&ver, 0, sizeof(ver)); - ver.dwOSVersionInfoSize = sizeof(ver); - ::GetVersionEx (&ver); - } // GetOSVersion - // helper function CMUSHView * CMUSHclientDoc::GetFirstOutputWindow () { @@ -524,13 +514,7 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType) case 74: SetUpVariantString (vaResult, ExtractDirectory (App.m_strMUSHclientFileName) + "sounds\\"); break; case 75: SetUpVariantString (vaResult, m_IAC_subnegotiation_data.c_str ()); break; case 76: SetUpVariantString (vaResult, m_strSpecialFontName); break; - - case 77: - { - GetOSVersion (); - SetUpVariantString (vaResult, ver.szCSDVersion); - break; - } + case 77: SetUpVariantString (vaResult, os_version.szCSDVersion); break; case 78: SetUpVariantString (vaResult, m_strForegroundImageName); break; case 79: SetUpVariantString (vaResult, m_strBackgroundImageName); break; @@ -874,33 +858,10 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType) break; } - case 265: - { - GetOSVersion (); - SetUpVariantLong (vaResult, ver.dwMajorVersion); - break; - } - - case 266: - { - GetOSVersion (); - SetUpVariantLong (vaResult, ver.dwMinorVersion); - break; - } - - case 267: - { - GetOSVersion (); - SetUpVariantLong (vaResult, ver.dwBuildNumber); - break; - } - - case 268: - { - GetOSVersion (); - SetUpVariantLong (vaResult, ver.dwPlatformId); - break; - } + case 265: SetUpVariantLong (vaResult, os_version.dwMajorVersion); break; + case 266: SetUpVariantLong (vaResult, os_version.dwMinorVersion); break; + case 267: SetUpVariantLong (vaResult, os_version.dwBuildNumber); break; + case 268: SetUpVariantLong (vaResult, os_version.dwPlatformId); break; case 269: SetUpVariantLong (vaResult, m_iForegroundMode); break; case 270: SetUpVariantLong (vaResult, m_iBackgroundMode); break; diff --git a/stdafx.h b/stdafx.h index 3e211caa..fa347540 100644 --- a/stdafx.h +++ b/stdafx.h @@ -321,6 +321,7 @@ extern bool bWinNT; extern bool bWin95; extern bool bWin98; extern bool bWine; +extern OSVERSIONINFO os_version; BOOL Set_Up_Set_Strings (const int set_type, CString & suggested_name, diff --git a/world_debug.cpp b/world_debug.cpp index e0496068..e3688112 100644 --- a/world_debug.cpp +++ b/world_debug.cpp @@ -975,34 +975,28 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) Note (CTime::GetCurrentTime().Format (TranslateTime ("Time now: %A, %B %d, %Y, %#I:%M %p"))); - OSVERSIONINFO ver; - // see which OS we are using - memset(&ver, 0, sizeof(ver)); - ver.dwOSVersionInfoSize = sizeof(ver); - ::GetVersionEx (&ver); - // work out operating system CString sVersion = TFormat ("Unknown (Platform %ld, Major %ld, Minor %ld)", - ver.dwPlatformId, ver.dwMajorVersion, ver.dwMinorVersion); + os_version.dwPlatformId, os_version.dwMajorVersion, os_version.dwMinorVersion); - if (ver.dwPlatformId == 1) // Windows 95-style versions + if (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) // Windows 95-style versions { - switch (ver.dwMinorVersion) + switch (os_version.dwMinorVersion) { case 0: sVersion = "Windows 95"; break; case 10: sVersion = "Windows 98"; break; case 90: sVersion = "Windows ME"; break; } // end of switch on dwMinorVersion } // end of dwPlatformId == 1 - else if (ver.dwPlatformId == 2) // Windows NT versions + else if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT) // Windows NT versions { - switch (ver.dwMajorVersion) + switch (os_version.dwMajorVersion) { case 3: sVersion = "Windows NT 3.51"; break; case 4: sVersion = "Windows NT"; break; case 5: - switch (ver.dwMinorVersion) + switch (os_version.dwMinorVersion) { case 0: sVersion = "Windows 2000"; break; case 1: sVersion = "Windows XP"; break; @@ -1011,7 +1005,7 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) break; // end case 5 of dwMinorVersion case 6: - switch (ver.dwMinorVersion) + switch (os_version.dwMinorVersion) { case 0: sVersion = "Windows Vista"; break; case 1: sVersion = "Windows 7"; break;