Remove WinAPI helper types from XUI controls

This commit is contained in:
notmatthewbeshay 2026-03-14 07:17:22 +11:00
parent 7b39869e38
commit 4cc0bd5e25
12 changed files with 61 additions and 62 deletions

View file

@ -16,41 +16,41 @@ void CXuiCtrl4JList::AddData( const LIST_ITEM_INFO& ItemInfo , int iSortListFrom
{ {
// need to allocate memory for the structure and its strings // need to allocate memory for the structure and its strings
// and remap the string pointers // and remap the string pointers
DWORD dwBytes=0; std::size_t totalBytes = 0;
DWORD dwLen1=0; std::size_t textBytes = 0;
DWORD dwLen2=0; std::size_t imageBytes = 0;
if(ItemInfo.pwszText) if(ItemInfo.pwszText)
{ {
dwLen1=(int)wcslen(ItemInfo.pwszText)*sizeof(WCHAR); textBytes = wcslen(ItemInfo.pwszText) * sizeof(WCHAR);
dwBytes+=dwLen1+sizeof(WCHAR); totalBytes += textBytes + sizeof(WCHAR);
} }
if(ItemInfo.pwszImage) if(ItemInfo.pwszImage)
{ {
dwLen2=(int)(wcslen(ItemInfo.pwszImage))*sizeof(WCHAR); imageBytes = wcslen(ItemInfo.pwszImage) * sizeof(WCHAR);
dwBytes+=dwLen2+sizeof(WCHAR); totalBytes += imageBytes + sizeof(WCHAR);
} }
dwBytes+=sizeof( LIST_ITEM_INFO ); totalBytes += sizeof(LIST_ITEM_INFO);
LIST_ITEM_INFO *pItemInfo = (LIST_ITEM_INFO *)new BYTE[dwBytes]; LIST_ITEM_INFO *pItemInfo = reinterpret_cast<LIST_ITEM_INFO *>(new unsigned char[totalBytes]);
ZeroMemory(pItemInfo,dwBytes); ZeroMemory(pItemInfo, totalBytes);
XMemCpy( pItemInfo, &ItemInfo, sizeof( LIST_ITEM_INFO ) ); XMemCpy( pItemInfo, &ItemInfo, sizeof( LIST_ITEM_INFO ) );
if(dwLen1!=0) if(textBytes != 0)
{ {
XMemCpy( &pItemInfo[1], ItemInfo.pwszText, dwLen1 ); XMemCpy( &pItemInfo[1], ItemInfo.pwszText, textBytes );
pItemInfo->pwszText=(LPCWSTR)&pItemInfo[1]; pItemInfo->pwszText=(LPCWSTR)&pItemInfo[1];
if(dwLen2!=0) if(imageBytes != 0)
{ {
BYTE *pwszImage = ((BYTE *)&pItemInfo[1])+dwLen1+sizeof(WCHAR); unsigned char *imageText = reinterpret_cast<unsigned char *>(&pItemInfo[1]) + textBytes + sizeof(WCHAR);
XMemCpy( pwszImage, ItemInfo.pwszImage, dwLen2 ); XMemCpy( imageText, ItemInfo.pwszImage, imageBytes );
pItemInfo->pwszImage=(LPCWSTR)pwszImage; pItemInfo->pwszImage = reinterpret_cast<LPCWSTR>(imageText);
} }
} }
else if(dwLen2!=0) else if(imageBytes != 0)
{ {
XMemCpy( &pItemInfo[1], ItemInfo.pwszImage, dwLen2 ); XMemCpy( &pItemInfo[1], ItemInfo.pwszImage, imageBytes );
pItemInfo->pwszImage=(LPCWSTR)&pItemInfo[1]; pItemInfo->pwszImage=(LPCWSTR)&pItemInfo[1];
} }
@ -162,9 +162,9 @@ int CXuiCtrl4JList::GetIndexByUserData(int iData)
return 0; return 0;
} }
CXuiCtrl4JList::LIST_ITEM_INFO& CXuiCtrl4JList::GetData(DWORD dw) CXuiCtrl4JList::LIST_ITEM_INFO& CXuiCtrl4JList::GetData(int index)
{ {
return *m_vListData[dw]; return *m_vListData[index];
} }
CXuiCtrl4JList::LIST_ITEM_INFO& CXuiCtrl4JList::GetDataiData(int iData) CXuiCtrl4JList::LIST_ITEM_INFO& CXuiCtrl4JList::GetDataiData(int iData)
@ -356,14 +356,14 @@ HRESULT CXuiCtrl4JList::OnGetItemEnable(XUIMessageGetItemEnable *pGetItemEnableD
} }
HRESULT CXuiCtrl4JList::SetBorder(DWORD dw,BOOL bShow) HRESULT CXuiCtrl4JList::SetBorder(int index, bool show)
{ {
CXuiControl Control; CXuiControl Control;
HXUIOBJ hVisual,hBorder; HXUIOBJ hVisual,hBorder;
GetItemControl(dw,&Control); GetItemControl(index,&Control);
Control.GetVisual(&hVisual); Control.GetVisual(&hVisual);
XuiElementGetChildById(hVisual,L"Border",&hBorder); XuiElementGetChildById(hVisual,L"Border",&hBorder);
return XuiElementSetShow(hBorder,bShow); return XuiElementSetShow(hBorder,show);
} }
void CXuiCtrl4JList::SetSelectionChangedHandle(HXUIOBJ hObj) void CXuiCtrl4JList::SetSelectionChangedHandle(HXUIOBJ hObj)
@ -383,7 +383,7 @@ HRESULT CXuiCtrl4JList::OnDestroy()
{ {
XuiDestroyBrush( m_vListData[i]->hXuiBrush ); XuiDestroyBrush( m_vListData[i]->hXuiBrush );
} }
delete [] (BYTE *)m_vListData[i]; delete [] reinterpret_cast<unsigned char *>(m_vListData[i]);
} }
} }
return S_OK; return S_OK;

View file

@ -40,10 +40,10 @@ public:
void UpdateGraphic(int iItem,HXUIBRUSH hXuiBrush ); void UpdateGraphic(int iItem,HXUIBRUSH hXuiBrush );
void UpdateGraphic(FILETIME *pfTime,HXUIBRUSH hXuiBrush ); void UpdateGraphic(FILETIME *pfTime,HXUIBRUSH hXuiBrush );
void UpdateGraphicFromiData(int iData,HXUIBRUSH hXuiBrush ); void UpdateGraphicFromiData(int iData,HXUIBRUSH hXuiBrush );
LIST_ITEM_INFO& GetData(DWORD dw); LIST_ITEM_INFO& GetData(int index);
LIST_ITEM_INFO& GetData(FILETIME *pFileTime); LIST_ITEM_INFO& GetData(FILETIME *pFileTime);
LIST_ITEM_INFO& GetDataiData(int iData); LIST_ITEM_INFO& GetDataiData(int iData);
HRESULT SetBorder(DWORD dw,BOOL bShow); // for a highlight around the current selected item in the controls layout HRESULT SetBorder(int index, bool show); // for a highlight around the current selected item in the controls layout
void SetSelectionChangedHandle(HXUIOBJ hObj); void SetSelectionChangedHandle(HXUIOBJ hObj);
protected: protected:

View file

@ -55,19 +55,19 @@ HRESULT CXuiCtrlCraftIngredientSlot::OnGetSourceText(XUIMessageGetSourceText *pG
return S_OK; return S_OK;
} }
void CXuiCtrlCraftIngredientSlot::SetRedBox(BOOL bVal) void CXuiCtrlCraftIngredientSlot::SetRedBox(bool show)
{ {
HRESULT hr=S_OK; HRESULT hr=S_OK;
HXUIOBJ hObj,hObjChild; HXUIOBJ hObj,hObjChild;
hr=GetVisual(&hObj); hr=GetVisual(&hObj);
XuiElementGetChildById(hObj,L"BoxRed",&hObjChild); XuiElementGetChildById(hObj,L"BoxRed",&hObjChild);
XuiElementSetShow(hObjChild,bVal); XuiElementSetShow(hObjChild,show);
XuiElementGetChildById(hObj,L"Exclaim",&hObjChild); XuiElementGetChildById(hObj,L"Exclaim",&hObjChild);
XuiElementSetShow(hObjChild,bVal); XuiElementSetShow(hObjChild,show);
} }
void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,bool isFoil, BOOL bShow) void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,bool isFoil, bool bShow)
{ {
m_item = nullptr; m_item = nullptr;
m_iID=iId; m_iID=iId;
@ -92,7 +92,7 @@ void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCo
XuiElementSetShow(m_hObj,bShow); XuiElementSetShow(m_hObj,bShow);
} }
void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow) void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, bool bShow)
{ {
if(item == NULL) SetIcon(iPad, 0,0,0,0,0,false,false,bShow); if(item == NULL) SetIcon(iPad, 0,0,0,0,0,false,false,bShow);
else else

View file

@ -14,9 +14,9 @@ public:
CXuiCtrlCraftIngredientSlot(); CXuiCtrlCraftIngredientSlot();
virtual ~CXuiCtrlCraftIngredientSlot() { }; virtual ~CXuiCtrlCraftIngredientSlot() { };
void SetRedBox(BOOL bVal); void SetRedBox(bool show);
void SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha, bool bDecorations, bool isFoil = false, BOOL bShow=TRUE); void SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha, bool bDecorations, bool isFoil = false, bool bShow=true);
void SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow=TRUE); void SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, bool bShow=true);
void SetDescription(LPCWSTR Desc); void SetDescription(LPCWSTR Desc);
protected: protected:

View file

@ -32,7 +32,7 @@ HRESULT CXuiCtrlEnchantmentButton::OnInit(XUIMessageInit* pInitData, BOOL& rfHan
assert( parent != NULL ); assert( parent != NULL );
VOID *pObj; void *pObj;
XuiObjectFromHandle( parent, &pObj ); XuiObjectFromHandle( parent, &pObj );
m_containerScene = (CXuiSceneEnchant *)pObj; m_containerScene = (CXuiSceneEnchant *)pObj;

View file

@ -23,7 +23,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CXuiCtrlEnchantmentBook::CXuiCtrlEnchantmentBook() : CXuiCtrlEnchantmentBook::CXuiCtrlEnchantmentBook() :
m_bDirty(FALSE), m_bDirty(false),
m_fScale(1.0f), m_fScale(1.0f),
m_fAlpha(1.0f) m_fAlpha(1.0f)
{ {
@ -64,7 +64,7 @@ HRESULT CXuiCtrlEnchantmentBook::OnInit(XUIMessageInit* pInitData, BOOL& rfHandl
assert( parent != NULL ); assert( parent != NULL );
VOID *pObj; void *pObj;
XuiObjectFromHandle( parent, &pObj ); XuiObjectFromHandle( parent, &pObj );
m_containerScene = (CXuiSceneEnchant *)pObj; m_containerScene = (CXuiSceneEnchant *)pObj;

View file

@ -42,7 +42,7 @@ HRESULT CXuiCtrlEnchantmentButtonText::OnInit(XUIMessageInit* pInitData, BOOL& r
assert( parent != NULL ); assert( parent != NULL );
VOID *pObj; void *pObj;
XuiObjectFromHandle( parent, &pObj ); XuiObjectFromHandle( parent, &pObj );
m_parentControl = (CXuiCtrlEnchantmentButton *)pObj; m_parentControl = (CXuiCtrlEnchantmentButton *)pObj;

View file

@ -15,7 +15,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CXuiCtrlMinecraftPlayer::CXuiCtrlMinecraftPlayer() : CXuiCtrlMinecraftPlayer::CXuiCtrlMinecraftPlayer() :
m_bDirty(FALSE), m_bDirty(false),
m_fScale(1.0f), m_fScale(1.0f),
m_fAlpha(1.0f) m_fAlpha(1.0f)
{ {
@ -45,7 +45,7 @@ HRESULT CXuiCtrlMinecraftPlayer::OnInit(XUIMessageInit* pInitData, BOOL& rfHandl
assert( parent != NULL ); assert( parent != NULL );
VOID *pObj; void *pObj;
XuiObjectFromHandle( parent, &pObj ); XuiObjectFromHandle( parent, &pObj );
m_containerScene = (CXuiSceneInventory *)pObj; m_containerScene = (CXuiSceneInventory *)pObj;
@ -187,4 +187,3 @@ HRESULT CXuiCtrlMinecraftPlayer::OnRender(XUIMessageRender *pRenderData, BOOL &b
} }

View file

@ -73,7 +73,7 @@ CXuiCtrlMinecraftSlot::~CXuiCtrlMinecraftSlot()
delete m_pItemRenderer; delete m_pItemRenderer;
} }
VOID CXuiCtrlMinecraftSlot::SetPassThroughDataAssociation(unsigned int iID, unsigned int iData) void CXuiCtrlMinecraftSlot::SetPassThroughDataAssociation(unsigned int iID, unsigned int iData)
{ {
m_item = nullptr; m_item = nullptr;
m_iPassThroughIdAssociation = iID; m_iPassThroughIdAssociation = iID;
@ -309,7 +309,7 @@ HRESULT CXuiCtrlMinecraftSlot::OnRender(XUIMessageRender *pRenderData, BOOL &bHa
} }
void CXuiCtrlMinecraftSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,BOOL bShow, bool isFoil) void CXuiCtrlMinecraftSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,bool bShow, bool isFoil)
{ {
m_item = nullptr; m_item = nullptr;
m_iID=iId; m_iID=iId;
@ -343,7 +343,7 @@ void CXuiCtrlMinecraftSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, i
XuiElementSetShow(m_hObj,bShow); XuiElementSetShow(m_hObj,bShow);
} }
void CXuiCtrlMinecraftSlot::SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow) void CXuiCtrlMinecraftSlot::SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, bool bShow)
{ {
m_item = item; m_item = item;
m_isFoil = item->isFoil(); m_isFoil = item->isFoil();

View file

@ -16,14 +16,14 @@ class CXuiCtrlMinecraftSlot : public CXuiControlImpl
public: public:
XUI_IMPLEMENT_CLASS(CXuiCtrlMinecraftSlot, L"CXuiCtrlMinecraftSlot", XUI_CLASS_LABEL) XUI_IMPLEMENT_CLASS(CXuiCtrlMinecraftSlot, L"CXuiCtrlMinecraftSlot", XUI_CLASS_LABEL)
VOID SetPassThroughDataAssociation(unsigned int iID, unsigned int iData); void SetPassThroughDataAssociation(unsigned int iID, unsigned int iData);
CXuiCtrlMinecraftSlot(); CXuiCtrlMinecraftSlot();
virtual ~CXuiCtrlMinecraftSlot(); virtual ~CXuiCtrlMinecraftSlot();
void renderGuiItem(Font *font, Textures *textures,ItemInstance *item, int x, int y); void renderGuiItem(Font *font, Textures *textures,ItemInstance *item, int x, int y);
void RenderItem(); void RenderItem();
void SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,BOOL bShow, bool isFoil); void SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,bool bShow, bool isFoil);
void SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow=TRUE); void SetIcon(int iPad, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, bool bShow=true);
protected: protected:

View file

@ -5,7 +5,7 @@
HRESULT CXuiCtrlSliderWrapper::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) HRESULT CXuiCtrlSliderWrapper::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
{ {
VOID *pObj; void *pObj;
HXUIOBJ hObjChild; HXUIOBJ hObjChild;
XuiElementGetChildById(m_hObj,L"FocusSink",&hObjChild); XuiElementGetChildById(m_hObj,L"FocusSink",&hObjChild);
@ -17,8 +17,8 @@ HRESULT CXuiCtrlSliderWrapper::OnInit( XUIMessageInit* pInitData, BOOL& bHandled
m_pSlider = (CXuiSlider *)pObj; m_pSlider = (CXuiSlider *)pObj;
m_sliderActive = false; m_sliderActive = false;
m_bDisplayVal=true; m_bDisplayVal = true;
m_bPlaySound=false; // make this false to avoid a sound being played in the first setting of the slider value in a scene m_bPlaySound = false; // make this false to avoid a sound being played in the first setting of the slider value in a scene
XuiSetTimer( m_hObj,NO_SOUND_TIMER,50); XuiSetTimer( m_hObj,NO_SOUND_TIMER,50);
bHandled = TRUE; bHandled = TRUE;
return S_OK; return S_OK;
@ -66,7 +66,7 @@ HRESULT CXuiCtrlSliderWrapper::OnNotifyValueChanged (HXUIOBJ hObjSource, XUINoti
if(m_bPlaySound) if(m_bPlaySound)
{ {
m_bPlaySound=false; m_bPlaySound = false;
CXuiSceneBase::PlayUISFX(eSFX_Scroll); CXuiSceneBase::PlayUISFX(eSFX_Scroll);
XuiSetTimer( m_hObj,NO_SOUND_TIMER,150); XuiSetTimer( m_hObj,NO_SOUND_TIMER,150);
} }
@ -108,7 +108,7 @@ HRESULT CXuiCtrlSliderWrapper::SetValue( int nValue )
return S_OK; return S_OK;
} }
HRESULT CXuiCtrlSliderWrapper::SetValueDisplay( BOOL bShow ) HRESULT CXuiCtrlSliderWrapper::SetValueDisplay(bool show)
{ {
CXuiCtrlSliderWrapper *pThis; CXuiCtrlSliderWrapper *pThis;
HXUIOBJ hVisual,hText; HXUIOBJ hVisual,hText;
@ -121,7 +121,7 @@ HRESULT CXuiCtrlSliderWrapper::SetValueDisplay( BOOL bShow )
if(hText!=NULL) if(hText!=NULL)
{ {
XuiElementSetShow(hText,bShow); XuiElementSetShow(hText,show);
} }
return S_OK; return S_OK;

View file

@ -33,6 +33,6 @@ public:
HRESULT SetRange( int nRangeMin, int nRangeMax); HRESULT SetRange( int nRangeMin, int nRangeMax);
LPCWSTR GetText( ); LPCWSTR GetText( );
HRESULT SetText(LPCWSTR text, int iDataAssoc=0 ); HRESULT SetText(LPCWSTR text, int iDataAssoc=0 );
HRESULT SetValueDisplay( BOOL bShow ); HRESULT SetValueDisplay( bool show );
}; };