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
// and remap the string pointers
DWORD dwBytes=0;
DWORD dwLen1=0;
DWORD dwLen2=0;
std::size_t totalBytes = 0;
std::size_t textBytes = 0;
std::size_t imageBytes = 0;
if(ItemInfo.pwszText)
{
dwLen1=(int)wcslen(ItemInfo.pwszText)*sizeof(WCHAR);
dwBytes+=dwLen1+sizeof(WCHAR);
textBytes = wcslen(ItemInfo.pwszText) * sizeof(WCHAR);
totalBytes += textBytes + sizeof(WCHAR);
}
if(ItemInfo.pwszImage)
{
dwLen2=(int)(wcslen(ItemInfo.pwszImage))*sizeof(WCHAR);
dwBytes+=dwLen2+sizeof(WCHAR);
imageBytes = wcslen(ItemInfo.pwszImage) * sizeof(WCHAR);
totalBytes += imageBytes + sizeof(WCHAR);
}
dwBytes+=sizeof( LIST_ITEM_INFO );
LIST_ITEM_INFO *pItemInfo = (LIST_ITEM_INFO *)new BYTE[dwBytes];
ZeroMemory(pItemInfo,dwBytes);
totalBytes += sizeof(LIST_ITEM_INFO);
LIST_ITEM_INFO *pItemInfo = reinterpret_cast<LIST_ITEM_INFO *>(new unsigned char[totalBytes]);
ZeroMemory(pItemInfo, totalBytes);
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];
if(dwLen2!=0)
if(imageBytes != 0)
{
BYTE *pwszImage = ((BYTE *)&pItemInfo[1])+dwLen1+sizeof(WCHAR);
XMemCpy( pwszImage, ItemInfo.pwszImage, dwLen2 );
pItemInfo->pwszImage=(LPCWSTR)pwszImage;
unsigned char *imageText = reinterpret_cast<unsigned char *>(&pItemInfo[1]) + textBytes + sizeof(WCHAR);
XMemCpy( imageText, ItemInfo.pwszImage, imageBytes );
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];
}
@ -162,9 +162,9 @@ int CXuiCtrl4JList::GetIndexByUserData(int iData)
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)
@ -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;
HXUIOBJ hVisual,hBorder;
GetItemControl(dw,&Control);
GetItemControl(index,&Control);
Control.GetVisual(&hVisual);
XuiElementGetChildById(hVisual,L"Border",&hBorder);
return XuiElementSetShow(hBorder,bShow);
return XuiElementSetShow(hBorder,show);
}
void CXuiCtrl4JList::SetSelectionChangedHandle(HXUIOBJ hObj)
@ -383,7 +383,7 @@ HRESULT CXuiCtrl4JList::OnDestroy()
{
XuiDestroyBrush( m_vListData[i]->hXuiBrush );
}
delete [] (BYTE *)m_vListData[i];
delete [] reinterpret_cast<unsigned char *>(m_vListData[i]);
}
}
return S_OK;
@ -402,4 +402,4 @@ HRESULT CXuiCtrl4JList::OnNotifySelChanged( HXUIOBJ hObjSource, XUINotifySelChan
bHandled = xuiMsg.bHandled;
}
return S_OK;
}
}

View file

@ -40,10 +40,10 @@ public:
void UpdateGraphic(int iItem,HXUIBRUSH hXuiBrush );
void UpdateGraphic(FILETIME *pfTime,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& 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);
protected:

View file

@ -55,19 +55,19 @@ HRESULT CXuiCtrlCraftIngredientSlot::OnGetSourceText(XUIMessageGetSourceText *pG
return S_OK;
}
void CXuiCtrlCraftIngredientSlot::SetRedBox(BOOL bVal)
void CXuiCtrlCraftIngredientSlot::SetRedBox(bool show)
{
HRESULT hr=S_OK;
HXUIOBJ hObj,hObjChild;
hr=GetVisual(&hObj);
XuiElementGetChildById(hObj,L"BoxRed",&hObjChild);
XuiElementSetShow(hObjChild,bVal);
XuiElementSetShow(hObjChild,show);
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_iID=iId;
@ -92,7 +92,7 @@ void CXuiCtrlCraftIngredientSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCo
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);
else
@ -120,4 +120,4 @@ void CXuiCtrlCraftIngredientSlot::SetDescription(LPCWSTR Desc)
XuiControlSetText(hObjChild,Desc);
XuiElementSetShow(hObjChild,Desc==NULL?FALSE:TRUE);
m_Desc=Desc;
}
}

View file

@ -14,9 +14,9 @@ public:
CXuiCtrlCraftIngredientSlot();
virtual ~CXuiCtrlCraftIngredientSlot() { };
void SetRedBox(BOOL bVal);
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 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, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, bool bShow=true);
void SetDescription(LPCWSTR Desc);
protected:
@ -42,4 +42,4 @@ private:
bool m_isFoil;
LPCWSTR m_Desc;
bool m_isDirty;
};
};

View file

@ -32,7 +32,7 @@ HRESULT CXuiCtrlEnchantmentButton::OnInit(XUIMessageInit* pInitData, BOOL& rfHan
assert( parent != NULL );
VOID *pObj;
void *pObj;
XuiObjectFromHandle( parent, &pObj );
m_containerScene = (CXuiSceneEnchant *)pObj;
@ -87,4 +87,4 @@ HRESULT CXuiCtrlEnchantmentButton::OnGetSourceDataText(XUIMessageGetSourceText *
bHandled = TRUE;
return S_OK;
}
}

View file

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

View file

@ -42,7 +42,7 @@ HRESULT CXuiCtrlEnchantmentButtonText::OnInit(XUIMessageInit* pInitData, BOOL& r
assert( parent != NULL );
VOID *pObj;
void *pObj;
XuiObjectFromHandle( parent, &pObj );
m_parentControl = (CXuiCtrlEnchantmentButton *)pObj;
@ -182,4 +182,4 @@ std::wstring CXuiCtrlEnchantmentButtonText::EnchantmentNames::getRandomName()
word += words[random.nextInt(words.size())];
}
return word;
}
}

View file

@ -15,7 +15,7 @@
//-----------------------------------------------------------------------------
CXuiCtrlMinecraftPlayer::CXuiCtrlMinecraftPlayer() :
m_bDirty(FALSE),
m_bDirty(false),
m_fScale(1.0f),
m_fAlpha(1.0f)
{
@ -45,7 +45,7 @@ HRESULT CXuiCtrlMinecraftPlayer::OnInit(XUIMessageInit* pInitData, BOOL& rfHandl
assert( parent != NULL );
VOID *pObj;
void *pObj;
XuiObjectFromHandle( parent, &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;
}
VOID CXuiCtrlMinecraftSlot::SetPassThroughDataAssociation(unsigned int iID, unsigned int iData)
void CXuiCtrlMinecraftSlot::SetPassThroughDataAssociation(unsigned int iID, unsigned int iData)
{
m_item = nullptr;
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_iID=iId;
@ -343,7 +343,7 @@ void CXuiCtrlMinecraftSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, i
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_isFoil = item->isFoil();

View file

@ -16,14 +16,14 @@ class CXuiCtrlMinecraftSlot : public CXuiControlImpl
public:
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();
virtual ~CXuiCtrlMinecraftSlot();
void renderGuiItem(Font *font, Textures *textures,ItemInstance *item, int x, int y);
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, std::shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow=TRUE);
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);
protected:

View file

@ -5,7 +5,7 @@
HRESULT CXuiCtrlSliderWrapper::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
{
VOID *pObj;
void *pObj;
HXUIOBJ hObjChild;
XuiElementGetChildById(m_hObj,L"FocusSink",&hObjChild);
@ -17,8 +17,8 @@ HRESULT CXuiCtrlSliderWrapper::OnInit( XUIMessageInit* pInitData, BOOL& bHandled
m_pSlider = (CXuiSlider *)pObj;
m_sliderActive = false;
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_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
XuiSetTimer( m_hObj,NO_SOUND_TIMER,50);
bHandled = TRUE;
return S_OK;
@ -66,7 +66,7 @@ HRESULT CXuiCtrlSliderWrapper::OnNotifyValueChanged (HXUIOBJ hObjSource, XUINoti
if(m_bPlaySound)
{
m_bPlaySound=false;
m_bPlaySound = false;
CXuiSceneBase::PlayUISFX(eSFX_Scroll);
XuiSetTimer( m_hObj,NO_SOUND_TIMER,150);
}
@ -108,7 +108,7 @@ HRESULT CXuiCtrlSliderWrapper::SetValue( int nValue )
return S_OK;
}
HRESULT CXuiCtrlSliderWrapper::SetValueDisplay( BOOL bShow )
HRESULT CXuiCtrlSliderWrapper::SetValueDisplay(bool show)
{
CXuiCtrlSliderWrapper *pThis;
HXUIOBJ hVisual,hText;
@ -121,7 +121,7 @@ HRESULT CXuiCtrlSliderWrapper::SetValueDisplay( BOOL bShow )
if(hText!=NULL)
{
XuiElementSetShow(hText,bShow);
XuiElementSetShow(hText,show);
}
return S_OK;
@ -171,4 +171,4 @@ HRESULT CXuiCtrlSliderWrapper::SetRange( int nRangeMin, int nRangeMax)
return hr;
pThis->m_pSlider->SetRange(nRangeMin, nRangeMax);
return S_OK;
}
}

View file

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