Skip to content

Commit

Permalink
Sprays - Initial commit
Browse files Browse the repository at this point in the history
* Integrate stb_image.h library
* fixes NeotokyoRebuild#602
  • Loading branch information
nullsystem committed Sep 28, 2024
1 parent bc8e217 commit 16870dd
Show file tree
Hide file tree
Showing 8 changed files with 8,084 additions and 2 deletions.
9 changes: 9 additions & 0 deletions mp/src/game/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target_include_directories(client
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons
${CMAKE_SOURCE_DIR}/public
${CMAKE_SOURCE_DIR}/thirdparty/sixensesdk/include
${CMAKE_SOURCE_DIR}/vendor
game_controls
hl2
hl2/elements
Expand Down Expand Up @@ -1486,6 +1487,14 @@ target_sources_grouped(
neo/neo_fixup_glshaders.h
)

target_sources_grouped(
TARGET client
NAME "Source Files\\NEO_Vendor"
FILES
neo/vendor_impl.cpp
${CMAKE_SOURCE_DIR}/vendor/stb_image.h
)

target_sources_grouped(
TARGET client
NAME "Source Files\\NEO\\Game_Controls"
Expand Down
14 changes: 12 additions & 2 deletions mp/src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,18 @@ void CNeoRoot::ReadNewsFile(CUtlBuffer &buf)

void CNeoRoot::OnFileSelected(const char *szFullpath)
{
((m_ns.crosshair.eFileIOMode == vgui::FOD_OPEN) ?
&ImportCrosshair : &ExportCrosshair)(&m_ns.crosshair.info, szFullpath);
switch (m_eFileIOMode)
{
case FILEIODLGMODE_CROSSHAIR:
((m_ns.crosshair.eFileIOMode == vgui::FOD_OPEN) ?
&ImportCrosshair : &ExportCrosshair)(&m_ns.crosshair.info, szFullpath);
break;
case FILEIODLGMODE_SPRAY:
NeoUI::ConvertToVTF(szFullpath);
break;
default:
break;
}
}

// NEO NOTE (nullsystem): NeoRootCaptureESC is so that ESC keybinds can be recognized by non-root states, but root
Expand Down
8 changes: 8 additions & 0 deletions mp/src/game/client/neo/ui/neo_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class CNeoRoot : public vgui::EditablePanel, public CGameEventListener
void ReadNewsFile(CUtlBuffer &buf);
bool m_bShowBrowserLabel = false;

enum FileIODialogMode
{
FILEIODLGMODE_CROSSHAIR = 0,
FILEIODLGMODE_SPRAY,

FILEIODLGMODE__TOTAL,
};
FileIODialogMode m_eFileIOMode;
vgui::FileOpenDialog *m_pFileIODialog = nullptr;
MESSAGE_FUNC_CHARPTR(OnFileSelected, "FileSelected", fullpath);
};
Expand Down
18 changes: 18 additions & 0 deletions mp/src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,23 @@ void NeoSettings_General(NeoSettings *ns)
NeoUI::RingBoxBool(L"Show position", &pGeneral->bShowPos);
NeoUI::RingBox(L"Show FPS", SHOWFPS_LABELS, ARRAYSIZE(SHOWFPS_LABELS), &pGeneral->iShowFps);
NeoUI::RingBox(L"Download filter", DLFILTER_LABELS, ARRAYSIZE(DLFILTER_LABELS), &pGeneral->iDlFilter);

NeoUI::Pad();
if (NeoUI::Button(L"", L"Import spray").bPressed)
{
if (g_pNeoRoot->m_pFileIODialog)
{
g_pNeoRoot->m_pFileIODialog->MarkForDeletion();
}
g_pNeoRoot->m_pFileIODialog = new vgui::FileOpenDialog(g_pNeoRoot, "Import spray", vgui::FOD_OPEN);
g_pNeoRoot->m_eFileIOMode = CNeoRoot::FILEIODLGMODE_SPRAY;
g_pNeoRoot->m_pFileIODialog->AddFilter("*.jpg;*.jpeg;*.png;*.vtf", "Images (JPEG, PNG, VTF)", true);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.jpg;*.jpeg", "JPEG Image", false);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.png", "PNG Image", false);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.vtf", "VTF Image", false);
g_pNeoRoot->m_pFileIODialog->DoModal();
}
NeoUI::Pad();
}

void NeoSettings_Keys(NeoSettings *ns)
Expand Down Expand Up @@ -786,6 +803,7 @@ void NeoSettings_Crosshair(NeoSettings *ns)
g_pNeoRoot->m_pFileIODialog->MarkForDeletion();
}
pCrosshair->eFileIOMode = bPresImport ? vgui::FOD_OPEN : vgui::FOD_SAVE;
g_pNeoRoot->m_eFileIOMode = CNeoRoot::FILEIODLGMODE_CROSSHAIR;
g_pNeoRoot->m_pFileIODialog = new vgui::FileOpenDialog(g_pNeoRoot,
bPresImport ? "Import crosshair" : "Export crosshair",
pCrosshair->eFileIOMode);
Expand Down
44 changes: 44 additions & 0 deletions mp/src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vgui/IInput.h>
#include <vgui_controls/Controls.h>

#include "stb_image.h"

using namespace vgui;

static const wchar_t *ENABLED_LABELS[] = {
Expand Down Expand Up @@ -1020,4 +1022,46 @@ void OpenURL(const char *szBaseUrl, const char *szPath)
system(syscmd);
}

void ConvertToVTF(const char *szFullpath)
{
if (!szFullpath)
{
return;
}

// TODO: See: CViewRender::WriteSaveGameScreenshotOfSize
int x, y, n;
unsigned char *data = stbi_load(szFullpath, &x, &y, &n, 0);

#if 0
// Create and initialize a VTF texture
IVTFTexture *pVTFTexture = CreateVTFTexture();
const int nFlags = TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_SRGB;
if ( pVTFTexture->Init( nSrcWidth, nSrcHeight, 1, IMAGE_FORMAT_RGB888, nFlags, 1, 1 ) )
{
// Copy the image data over to the VTF
unsigned char *pDestBits = pVTFTexture->ImageData();
int nDstSize = nSrcWidth * nSrcHeight * 3;
V_memcpy( pDestBits, pSrcImage, nDstSize );

// Allocate output buffer
int iMaxVTFSize = 1024 + ( nSrcWidth * nSrcHeight * 3 );
void *pVTF = malloc( iMaxVTFSize );
buffer.SetExternalBuffer( pVTF, iMaxVTFSize, 0 );

// Serialize to the buffer
bWriteResult = pVTFTexture->Serialize( buffer );

// Free the VTF texture
DestroyVTFTexture( pVTFTexture );
}
else
{
bWriteResult = false;
}
#endif

stbi_image_free(data);
}

} // namespace NeoUI
2 changes: 2 additions & 0 deletions mp/src/game/client/neo/ui/neo_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ void SliderU8(const wchar_t *wszLeftLabel, uint8 *ucValue, const uint8 iMin, con
void TextEdit(const wchar_t *wszLeftLabel, wchar_t *wszText, const int iMaxSize);
bool Bind(const ButtonCode_t eCode);
void OpenURL(const char *szBaseUrl, const char *szPath);

void ConvertToVTF(const char *szFullpath);
}
3 changes: 3 additions & 0 deletions mp/src/game/client/neo/vendor_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

Loading

0 comments on commit 16870dd

Please sign in to comment.