| 1828235c |
Poul Sander |
2025-08-10 10:46 |
1 |
/* |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
2 |
=========================================================================== |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
3 |
* Sago Multi Scrambler Puzzle |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
4 |
Copyright (C) 2022-2024 Poul Sander |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
5 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
6 |
This program is free software: you can redistribute it and/or modify |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
7 |
it under the terms of the GNU General Public License as published by |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
8 |
the Free Software Foundation, either version 2 of the License, or |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
9 |
(at your option) any later version. |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
10 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
11 |
This program is distributed in the hope that it will be useful, |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
14 |
GNU General Public License for more details. |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
15 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
16 |
You should have received a copy of the GNU General Public License |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
17 |
along with this program. If not, see http://www.gnu.org/licenses/ |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
18 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
19 |
Source information and contacts persons can be found at |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
20 |
https://github.com/sago007/saland |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
21 |
=========================================================================== |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
22 |
*/ |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
23 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
24 |
#include "SagoTextureSelector.hpp" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
25 |
#include <iostream> |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
26 |
#include "imgui.h" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
27 |
#include "backends/imgui_impl_sdl2.h" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
28 |
#include "backends/imgui_impl_sdlrenderer2.h" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
29 |
#include <SDL_image.h> |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
30 |
#include "../../sago/SagoMisc.hpp" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
31 |
#include "../global.hpp" |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
32 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
33 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
34 |
class ChangeSDLColor |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
35 |
{ |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
36 |
public: |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
37 |
ChangeSDLColor(SDL_Renderer* renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a) : renderer(renderer) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
38 |
SDL_GetRenderDrawColor(renderer, &oldr, &oldg, &oldb, &olda); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
39 |
SDL_SetRenderDrawColor(renderer, r, g, b, a); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
40 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
41 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
42 |
ChangeSDLColor(SDL_Renderer* renderer) : renderer(renderer) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
43 |
SDL_GetRenderDrawColor(renderer, &oldr, &oldg, &oldb, &olda); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
44 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
45 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
46 |
void setRed() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
47 |
SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
48 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
49 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
50 |
void setYellow() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
51 |
SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
52 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
53 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
54 |
void reset() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
55 |
SDL_SetRenderDrawColor(renderer, oldr, oldg, oldb, olda); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
56 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
57 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
58 |
~ChangeSDLColor() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
59 |
SDL_SetRenderDrawColor(renderer, oldr, oldg, oldb, olda); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
60 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
61 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
62 |
private: |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
63 |
SDL_Renderer* renderer; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
64 |
Uint8 oldr, oldg, oldb, olda; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
65 |
}; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
66 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
67 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
68 |
static void addLinesToCanvas(SDL_Renderer* renderer, SDL_Texture* texture, int xstep = 32, int ystep = 32, int xoffset = 0, int yoffset = 0) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
69 |
int width, height; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
70 |
SDL_QueryTexture(texture, nullptr, nullptr, &width, &height); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
71 |
Uint8 r, g, b, a; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
72 |
SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
73 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
74 |
if (xstep > 0) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
75 |
for (int i = 0; i < width+1; i += xstep) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
76 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(i+xoffset, yoffset), ImVec2(i+xoffset, height+yoffset), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
77 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
78 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
79 |
if (ystep > 0) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
80 |
for (int i = 0; i < height+1; i += ystep) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
81 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(xoffset, i+yoffset), ImVec2(width+xoffset, i+yoffset), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
82 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
83 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
84 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
85 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
86 |
static void addRectableToCanvas(SDL_Renderer* renderer, int topx = 0, int topy = 0, int height = 100, int width = 100, int xoffset = 0, int yoffset = 0) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
87 |
Uint8 r, g, b, a; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
88 |
SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
89 |
topx += xoffset; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
90 |
topy += yoffset; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
91 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(topx, topy), ImVec2(topx+width, topy), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
92 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(topx+width, topy), ImVec2(topx+width, topy+height), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
93 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(topx+width, topy+height), ImVec2(topx, topy+height), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
94 |
ImGui::GetWindowDrawList()->AddLine(ImVec2(topx, topy+height), ImVec2(topx, topy), IM_COL32(r, g, b, a)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
95 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
96 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
97 |
static void addFolderToList(const std::string& folder, std::vector<std::string>& list, const std::string& filter = "") { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
98 |
std::vector<std::string> textures = sago::GetFileList(folder.c_str()); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
99 |
for (const auto& texture : textures) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
100 |
std::cout << "Texture: " << texture << "\n"; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
101 |
if (texture.find(".png") == std::string::npos) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
102 |
continue; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
103 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
104 |
if (filter.empty() || texture.find(filter) != std::string::npos) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
105 |
list.push_back(texture); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
106 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
107 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
108 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
109 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
110 |
static std::vector<std::string> populateTree(const std::string& filter = "") { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
111 |
std::vector<std::string> textures; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
112 |
addFolderToList("textures", textures, filter); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
113 |
return textures; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
114 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
115 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
116 |
std::string remove_file_extension(const std::string& filename) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
117 |
size_t lastindex = filename.find_last_of("."); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
118 |
return filename.substr(0, lastindex); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
119 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
120 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
121 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
122 |
static void ImGuiWritePartOfImage(SDL_Texture* texture, int topx, int topy, int w, int h) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
123 |
int tex_w, tex_h; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
124 |
SDL_QueryTexture(texture, nullptr, nullptr, &tex_w, &tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
125 |
float sprite_w = w; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
126 |
float sprite_h = h; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
127 |
float topxf = topx; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
128 |
float topyf = topy; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
129 |
ImVec2 uv0 = ImVec2(topxf / tex_w, topyf / tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
130 |
ImVec2 uv1 = ImVec2((topxf + sprite_w) / tex_w, (topyf + sprite_h) / tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
131 |
ImGui::Image((ImTextureID)(intptr_t)texture, ImVec2((float)w, (float)h), uv0, uv1); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
132 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
133 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
134 |
void SagoTextureSelector::runSpriteSelectorFrame(SDL_Renderer* target) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
135 |
ImGui::Begin("SpriteList", nullptr, ImGuiWindowFlags_NoCollapse); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
136 |
static char filter[256] = ""; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
137 |
ImGui::InputText("Filter", filter, IM_ARRAYSIZE(filter)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
138 |
ImGui::Separator(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
139 |
for (const auto& sprite : sprites) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
140 |
std::string sprite_name = sprite.first; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
141 |
if (filter[0] == '\0' || sprite_name.find(filter) != std::string::npos) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
142 |
if (ImGui::Selectable(sprite_name.c_str(), selected_sprite == sprite_name)) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
143 |
selected_sprite = sprite_name; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
144 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
145 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
146 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
147 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
148 |
ImGui::End(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
149 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
150 |
ImGui::Begin("SpriteViewer"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
151 |
if (selected_sprite.length()) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
152 |
const SagoSprite& current_sprite = sprites[selected_sprite]; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
153 |
SDL_Texture* current_texture = globalData.dataHolder->getTexturePtr(current_sprite.texture); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
154 |
ImGui::Text("Size: %d x %d", current_sprite.width, current_sprite.height); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
155 |
ImGui::BeginChild("Test"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
156 |
int offset = current_sprite.width * (SDL_GetTicks()/current_sprite.frame_time % current_sprite.number_of_frames); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
157 |
ImGuiWritePartOfImage(current_texture, current_sprite.topx+offset, current_sprite.topy, current_sprite.width, current_sprite.height); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
158 |
ImGui::EndChild(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
159 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
160 |
ImGui::End(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
161 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
162 |
ImGui::Begin("SpriteTexture"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
163 |
if (selected_sprite.length() && sprites[selected_sprite].texture.length()) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
164 |
int tex_w, tex_h; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
165 |
const SagoSprite& current_sprite = sprites[selected_sprite]; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
166 |
SDL_Texture* current_texture = globalData.dataHolder->getTexturePtr(current_sprite.texture); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
167 |
SDL_QueryTexture(current_texture, nullptr, nullptr, &tex_w, &tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
168 |
ImGui::Text("Size: %d x %d", tex_w, tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
169 |
ImGui::BeginChild("Test"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
170 |
ImVec2 p = ImGui::GetCursorScreenPos(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
171 |
ImGui::Image((ImTextureID)(intptr_t)current_texture, ImVec2((float)tex_w, (float)tex_h)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
172 |
ChangeSDLColor color(target); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
173 |
color.setYellow(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
174 |
for (int i = 1; i < current_sprite.number_of_frames; i++) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
175 |
addRectableToCanvas(target, current_sprite.topx+i*current_sprite.width, current_sprite.topy, current_sprite.height, current_sprite.width, p.x, p.y); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
176 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
177 |
color.setRed(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
178 |
addRectableToCanvas(target, current_sprite.topx, current_sprite.topy, current_sprite.height, current_sprite.width, p.x, p.y); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
179 |
ImGui::EndChild(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
180 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
181 |
ImGui::End(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
182 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
183 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
184 |
void SagoTextureSelector::runTextureSelectorFrame(SDL_Renderer* target) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
185 |
ImGui::Begin("TextureList", nullptr, ImGuiWindowFlags_NoCollapse); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
186 |
static char filter[256] = ""; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
187 |
ImGui::InputText("Filter", filter, IM_ARRAYSIZE(filter)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
188 |
ImGui::Separator(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
189 |
for (const auto& texture : textures) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
190 |
if (filter[0] == '\0' || texture.find(filter) != std::string::npos) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
191 |
if (ImGui::Selectable(texture.c_str(), selected_texture == texture)) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
192 |
selected_texture = texture; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
193 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
194 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
195 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
196 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
197 |
ImGui::End(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
198 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
199 |
ImGui::Begin("TextureViewer"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
200 |
if (selected_texture.length()) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
201 |
int tex_w, tex_h; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
202 |
SDL_Texture* current_texture = globalData.dataHolder->getTexturePtr(remove_file_extension(selected_texture)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
203 |
SDL_QueryTexture(current_texture, nullptr, nullptr, &tex_w, &tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
204 |
ImGui::Text("Size: %d x %d", tex_w, tex_h); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
205 |
ImGui::BeginChild("Test"); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
206 |
ImVec2 p = ImGui::GetCursorScreenPos(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
207 |
ImGui::Image((ImTextureID)(intptr_t)current_texture, ImVec2((float)tex_w, (float)tex_h)); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
208 |
ChangeSDLColor color(target); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
209 |
color.setRed(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
210 |
addLinesToCanvas(target, current_texture, 32, 32, p.x, p.y); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
211 |
ImGui::EndChild(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
212 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
213 |
ImGui::End(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
214 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
215 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
216 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
217 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
218 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
219 |
SagoTextureSelector::SagoTextureSelector() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
220 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
221 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
222 |
SagoTextureSelector::~SagoTextureSelector() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
223 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
224 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
225 |
bool SagoTextureSelector::IsActive() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
226 |
return isActive; |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
227 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
228 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
229 |
void SagoTextureSelector::ProcessInput(const SDL_Event& event, bool &processed) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
230 |
ImGui_ImplSDL2_ProcessEvent(&event); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
231 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
232 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
233 |
void SagoTextureSelector::Draw(SDL_Renderer* target) { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
234 |
runTextureSelectorFrame(target); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
235 |
runSpriteSelectorFrame(target); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
236 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
237 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
238 |
void SagoTextureSelector::Update() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
239 |
} |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
240 |
|
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
241 |
void SagoTextureSelector::Init() { |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
242 |
textures = populateTree(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
243 |
sprites = LoadSprites(); |
| 1828235c |
Poul Sander |
2025-08-10 10:46 |
244 |
} |