-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlocksWnd.cpp
More file actions
95 lines (82 loc) · 2.81 KB
/
BlocksWnd.cpp
File metadata and controls
95 lines (82 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
#include "imgui.h"
#include "FileDialogNative.h"
#include "AssetsErrHandler.h"
#include "ImEditor.h"
#include "Utils.h"
#include "BlocksWnd.h"
void CBlocksWnd::RenderBegin()
{
ImGui::Begin( m_sWindowName.c_str(), &m_bOpen );
}
void CBlocksWnd::RenderEnd()
{
ImGui::End();
}
void CBlocksWnd::Render()
{
if ( ImGui::Button( "Load Bin" ) ) {
if ( auto osFilePath = FileDialog::OpenFile( FileDialog::Filter::DAT ) ) {
g_ErrHandler.HandleResult( m_Blocks.LoadBin( *osFilePath ) );
m_Blocks.DestroyTexture();
}
} ImGui::SameLine();
if ( ImGui::Button( "Load Image" ) ) {
if ( auto osFilePath = FileDialog::OpenFile( FileDialog::Filter::BMP ) ) {
g_ErrHandler.HandleResult( m_Blocks.LoadImg( *osFilePath ) );
m_Blocks.DestroyTexture();
}
} ImGui::SameLine();
if ( ImGui::Button( "Export Image" ) ) {
g_ErrHandler.HandleResult( m_Blocks.ExportImg( Util::FileSystem::FormatExportPathFromFileName( GetAssetName() ) ) );
} ImGui::SameLine();
if ( ImGui::Button( "Export Bin" ) ) {
g_ErrHandler.HandleResult( m_Blocks.ExportBin( Util::FileSystem::FormatExportPathFromFileName( GetAssetName() ) ) );
}
if ( m_Blocks.GetTexture() == nullptr ) {
for ( size_t i = 0; i < Assets::Blocks::k_uNumBlocks; i++ ) {
m_Blocks.CreateSubTexture( m_pd3dDevice, i );
}
m_Blocks.CreateTexture( m_pd3dDevice );
}
else {
ImEditor::SetPointFiltering( m_pd3dDevice );
ImGui::Checkbox( "Draw Atlas", &m_bDrawAtlas );
if ( m_bDrawAtlas ) {
ImEditor::RenderTexture( m_Blocks.GetTexture() );
}
else {
if ( ImGui::BeginPopup( "Texture Options" ) ) {
if ( ImGui::MenuItem( "Export SubTexture" ) ) {
g_ErrHandler.HandleResult( m_Blocks.ExportSubImg( Util::FileSystem::FormatExportPathFromFileName( GetAssetName() ), m_uSubTexClicked ) );
}
if ( ImGui::MenuItem( "Load SubTexture" ) ) {
if ( auto osFilePath = FileDialog::OpenFile( FileDialog::Filter::BMP ) ) {
g_ErrHandler.HandleResult( m_Blocks.LoadSubImg( m_pd3dDevice, *osFilePath, m_uSubTexClicked ) );
}
}
ImGui::EndPopup();
}
for ( size_t uIndex = 0; uIndex < Assets::Blocks::k_uNumBlocks; uIndex++ ) {
if ( ImEditor::ImageButton( m_Blocks.GetTexture( uIndex ) ) ) {
ImGui::OpenPopup( "Texture Options" );
m_uSubTexClicked = uIndex;
}
if ( (uIndex + 1) % 8 == 0 ) ImGui::NewLine();
else ImGui::SameLine();
}
}
ImEditor::ResetRenderState();
}
}
void CBlocksWnd::OnPaletteChange()
{
m_Blocks.DestroyTextures();
}