Removes GdiUtil and cleanups GuidUtil from Code/Editor
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -15,45 +15,6 @@
|
||||
#include "Util/GuidUtil.h"
|
||||
#include <map>
|
||||
|
||||
//! Derive from this class to decrease the amount of work for creating a new class description
|
||||
//! Provides standard reference counter implementation for IUnknown
|
||||
class CRefCountClassDesc
|
||||
: public IClassDesc
|
||||
{
|
||||
public:
|
||||
virtual ~CRefCountClassDesc() { }
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface([[maybe_unused]] const IID& riid, [[maybe_unused]] void** ppvObj)
|
||||
{
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE AddRef()
|
||||
{
|
||||
++m_nRefCount;
|
||||
return m_nRefCount;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release()
|
||||
{
|
||||
int refs = m_nRefCount;
|
||||
|
||||
if (--m_nRefCount <= 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
return refs;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_nRefCount;
|
||||
};
|
||||
|
||||
|
||||
// Use this for debugging unregistration problems.
|
||||
//#define DEBUG_CLASS_NAME_REGISTRATION
|
||||
|
||||
|
||||
//! Class factory is a common repository of all registered plugin classes,
|
||||
//! Classes here can found by their class ID or all classes of given system class retrieved
|
||||
class CRYEDIT_API CClassFactory
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "GdiUtil.h"
|
||||
|
||||
// Qt
|
||||
#include <QPainter>
|
||||
#include <QMessageBox>
|
||||
|
||||
QColor ScaleColor(const QColor& c, float aScale)
|
||||
{
|
||||
QColor aColor = c;
|
||||
if (!aColor.isValid())
|
||||
{
|
||||
// help out scaling, by starting at very low black
|
||||
aColor = QColor(1, 1, 1);
|
||||
}
|
||||
|
||||
const float r = static_cast<float>(aColor.red()) * aScale;
|
||||
const float g = static_cast<float>(aColor.green()) * aScale;
|
||||
const float b = static_cast<float>(aColor.blue()) * aScale;
|
||||
|
||||
return QColor(AZStd::clamp(static_cast<int>(r), 0, 255), AZStd::clamp(static_cast<int>(g), 0, 255), AZStd::clamp(static_cast<int>(b), 0, 255));
|
||||
}
|
||||
|
||||
CAlphaBitmap::CAlphaBitmap()
|
||||
{
|
||||
m_width = m_height = 0;
|
||||
}
|
||||
|
||||
CAlphaBitmap::~CAlphaBitmap()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
bool CAlphaBitmap::Create(void* pData, UINT aWidth, UINT aHeight, bool bVerticalFlip, bool bPremultiplyAlpha)
|
||||
{
|
||||
if (!aWidth || !aHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bmp = QImage(aWidth, aHeight, QImage::Format_RGBA8888);
|
||||
if (m_bmp.isNull())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<UINT> vBuffer;
|
||||
|
||||
if (pData)
|
||||
{
|
||||
// copy over the raw 32bpp data
|
||||
bVerticalFlip = !bVerticalFlip; // in Qt, the flip is not required. Still, keep the API behaving the same
|
||||
if (bVerticalFlip)
|
||||
{
|
||||
UINT nBufLen = aWidth * aHeight;
|
||||
vBuffer.resize(nBufLen);
|
||||
|
||||
if (IsBadReadPtr(pData, nBufLen * 4))
|
||||
{
|
||||
//TODO: remove after testing alot the browser, it doesnt happen anymore
|
||||
QMessageBox::critical(QApplication::activeWindow(), QString(), QObject::tr("Bad image data ptr!"));
|
||||
Free();
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(!vBuffer.empty());
|
||||
|
||||
if (vBuffer.empty())
|
||||
{
|
||||
Free();
|
||||
return false;
|
||||
}
|
||||
|
||||
UINT scanlineSize = aWidth * 4;
|
||||
|
||||
for (UINT i = 0, iCount = aHeight; i < iCount; ++i)
|
||||
{
|
||||
// top scanline position
|
||||
UINT* pTopScanPos = (UINT*)&vBuffer[0] + i * aWidth;
|
||||
// bottom scanline position
|
||||
UINT* pBottomScanPos = (UINT*)pData + (aHeight - i - 1) * aWidth;
|
||||
|
||||
// save a scanline from top
|
||||
memcpy(pTopScanPos, pBottomScanPos, scanlineSize);
|
||||
}
|
||||
|
||||
pData = &vBuffer[0];
|
||||
}
|
||||
|
||||
// premultiply alpha, AlphaBlend GDI expects it
|
||||
if (bPremultiplyAlpha)
|
||||
{
|
||||
for (UINT y = 0; y < aHeight; ++y)
|
||||
{
|
||||
BYTE* pPixel = (BYTE*) pData + aWidth * 4 * y;
|
||||
|
||||
for (UINT x = 0; x < aWidth; ++x)
|
||||
{
|
||||
pPixel[0] = ((int)pPixel[0] * pPixel[3] + 127) >> 8;
|
||||
pPixel[1] = ((int)pPixel[1] * pPixel[3] + 127) >> 8;
|
||||
pPixel[2] = ((int)pPixel[2] * pPixel[3] + 127) >> 8;
|
||||
pPixel += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(m_bmp.bits(), pData, aWidth * aHeight * 4);
|
||||
|
||||
if (m_bmp.isNull())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bmp.fill(Qt::transparent);
|
||||
}
|
||||
|
||||
// we dont need this screen DC anymore
|
||||
m_width = aWidth;
|
||||
m_height = aHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QImage& CAlphaBitmap::GetBitmap()
|
||||
{
|
||||
return m_bmp;
|
||||
}
|
||||
|
||||
void CAlphaBitmap::Free()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UINT CAlphaBitmap::GetWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
UINT CAlphaBitmap::GetHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void CheckerboardFillRect(QPainter* pGraphics, const QRect& rRect, int checkDiameter, const QColor& aColor1, const QColor& aColor2)
|
||||
{
|
||||
pGraphics->save();
|
||||
pGraphics->setClipRect(rRect);
|
||||
// Create a checkerboard background for easier readability
|
||||
pGraphics->fillRect(rRect, aColor1);
|
||||
QBrush lightBrush(aColor2);
|
||||
|
||||
// QRect bottom/right methods are short one unit for legacy reasons. Compute bottomr/right of the rectange ourselves to get the full size.
|
||||
const int rectRight = rRect.x() + rRect.width();
|
||||
const int rectBottom = rRect.y() + rRect.height();
|
||||
|
||||
for (int i = rRect.left(); i < rectRight; i += checkDiameter)
|
||||
{
|
||||
for (int j = rRect.top(); j < rectBottom; j += checkDiameter)
|
||||
{
|
||||
if ((i / checkDiameter) % 2 ^ (j / checkDiameter) % 2)
|
||||
{
|
||||
pGraphics->fillRect(QRect(i, j, checkDiameter, checkDiameter), lightBrush);
|
||||
}
|
||||
}
|
||||
}
|
||||
pGraphics->restore();
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Description : Utilitarian classes for double buffer GDI rendering and 32bit bitmaps
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_UTIL_GDIUTIL_H
|
||||
#define CRYINCLUDE_EDITOR_UTIL_GDIUTIL_H
|
||||
#pragma once
|
||||
|
||||
QColor ScaleColor(const QColor& coor, float aScale);
|
||||
|
||||
//! This class loads alpha-channel bitmaps and holds a DC for use with AlphaBlend function
|
||||
class CRYEDIT_API CAlphaBitmap
|
||||
{
|
||||
public:
|
||||
|
||||
CAlphaBitmap();
|
||||
~CAlphaBitmap();
|
||||
|
||||
//! creates the bitmap from raw 32bpp data
|
||||
//! \param pData the 32bpp raw image data, RGBA, can be nullptr and it would create just an empty bitmap
|
||||
//! \param aWidth the bitmap width
|
||||
//! \param aHeight the bitmap height
|
||||
bool Create(void* pData, UINT aWidth, UINT aHeight, bool bVerticalFlip = false, bool bPremultiplyAlpha = false);
|
||||
//! \return the actual bitmap
|
||||
QImage& GetBitmap();
|
||||
//! free the bitmap and DC
|
||||
void Free();
|
||||
//! \return bitmap width
|
||||
UINT GetWidth();
|
||||
//! \return bitmap height
|
||||
UINT GetHeight();
|
||||
|
||||
protected:
|
||||
|
||||
QImage m_bmp;
|
||||
UINT m_width, m_height;
|
||||
};
|
||||
|
||||
//! Fill a rectangle with a checkerboard pattern.
|
||||
//! \param pGraphics The Graphics object used for drawing
|
||||
//! \param rRect The rectangle to be filled
|
||||
//! \param checkDiameter the diameter of the check squares
|
||||
//! \param aColor1 the color that starts in the top left corner check square
|
||||
//! \param aColor2 the second color used for check squares
|
||||
void CheckerboardFillRect(QPainter* pGraphics, const QRect& rRect, int checkDiameter, const QColor& aColor1, const QColor& aColor2);
|
||||
#endif // CRYINCLUDE_EDITOR_UTIL_GDIUTIL_H
|
||||
@@ -6,12 +6,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "GuidUtil.h"
|
||||
|
||||
const char* GuidUtil::ToString(REFGUID guid)
|
||||
{
|
||||
static char guidString[64];
|
||||
sprintf_s(guidString, "{%.8" GUID_FORMAT_DATA1 "-%.4X-%.4X-%.2X%.2X-%.2X%.2X%.2X%.2X%.2X%.2X}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1],
|
||||
guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
return guidString;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
const GUID GuidUtil::NullGuid = {
|
||||
0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
GUID GuidUtil::FromString(const char* guidString)
|
||||
{
|
||||
GUID guid;
|
||||
unsigned int d[8];
|
||||
memset(&d, 0, sizeof(guid));
|
||||
guid.Data1 = 0;
|
||||
guid.Data2 = 0;
|
||||
guid.Data3 = 0;
|
||||
azsscanf(guidString, "{%8" GUID_FORMAT_DATA1 "-%4hX-%4hX-%2X%2X-%2X%2X%2X%2X%2X%2X}",
|
||||
&guid.Data1, &guid.Data2, &guid.Data3, &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7]);
|
||||
guid.Data4[0] = static_cast<unsigned char>(d[0]);
|
||||
guid.Data4[1] = static_cast<unsigned char>(d[1]);
|
||||
guid.Data4[2] = static_cast<unsigned char>(d[2]);
|
||||
guid.Data4[3] = static_cast<unsigned char>(d[3]);
|
||||
guid.Data4[4] = static_cast<unsigned char>(d[4]);
|
||||
guid.Data4[5] = static_cast<unsigned char>(d[5]);
|
||||
guid.Data4[6] = static_cast<unsigned char>(d[6]);
|
||||
guid.Data4[7] = static_cast<unsigned char>(d[7]);
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,6 @@ struct GuidUtil
|
||||
static const char* ToString(REFGUID guid);
|
||||
//! Convert from guid string in valid format to GUID class.
|
||||
static GUID FromString(const char* guidString);
|
||||
static bool IsEmpty(REFGUID guid);
|
||||
|
||||
static const GUID NullGuid;
|
||||
};
|
||||
|
||||
/** Used to compare GUID keys.
|
||||
@@ -38,42 +35,4 @@ struct guid_less_predicate
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
inline bool GuidUtil::IsEmpty(REFGUID guid)
|
||||
{
|
||||
return guid == NullGuid;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
inline const char* GuidUtil::ToString(REFGUID guid)
|
||||
{
|
||||
static char guidString[64];
|
||||
sprintf_s(guidString, "{%.8" GUID_FORMAT_DATA1 "-%.4X-%.4X-%.2X%.2X-%.2X%.2X%.2X%.2X%.2X%.2X}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1],
|
||||
guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
return guidString;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
inline GUID GuidUtil::FromString(const char* guidString)
|
||||
{
|
||||
GUID guid;
|
||||
unsigned int d[8];
|
||||
memset(&d, 0, sizeof(guid));
|
||||
guid.Data1 = 0;
|
||||
guid.Data2 = 0;
|
||||
guid.Data3 = 0;
|
||||
azsscanf(guidString, "{%8" GUID_FORMAT_DATA1 "-%4hX-%4hX-%2X%2X-%2X%2X%2X%2X%2X%2X}",
|
||||
&guid.Data1, &guid.Data2, &guid.Data3, &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7]);
|
||||
guid.Data4[0] = static_cast<unsigned char>(d[0]);
|
||||
guid.Data4[1] = static_cast<unsigned char>(d[1]);
|
||||
guid.Data4[2] = static_cast<unsigned char>(d[2]);
|
||||
guid.Data4[3] = static_cast<unsigned char>(d[3]);
|
||||
guid.Data4[4] = static_cast<unsigned char>(d[4]);
|
||||
guid.Data4[5] = static_cast<unsigned char>(d[5]);
|
||||
guid.Data4[6] = static_cast<unsigned char>(d[6]);
|
||||
guid.Data4[7] = static_cast<unsigned char>(d[7]);
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_UTIL_GUIDUTIL_H
|
||||
|
||||
@@ -636,8 +636,6 @@ set(FILES
|
||||
Util/FileEnum.h
|
||||
Util/FileUtil.cpp
|
||||
Util/FileUtil.h
|
||||
Util/GdiUtil.cpp
|
||||
Util/GdiUtil.h
|
||||
Util/GeometryUtil.cpp
|
||||
Util/GuidUtil.cpp
|
||||
Util/GuidUtil.h
|
||||
|
||||
Reference in New Issue
Block a user