Refactor ImTextureID casting for SDL_Texture rendering

This commit is contained in:
scawful
2024-10-09 01:59:15 -04:00
parent 0b1387bb49
commit e8e6ab00bf
7 changed files with 45 additions and 44 deletions

View File

@@ -498,7 +498,7 @@ void DungeonEditor::DrawRoomGraphics() {
top_left_y = room_gfx_canvas_.zero_point().y + height * current_block;
}
room_gfx_canvas_.draw_list()->AddImage(
(void*)graphics_bin_[block].texture(),
(ImTextureID)(intptr_t)graphics_bin_[block].texture(),
ImVec2(room_gfx_canvas_.zero_point().x + 2, top_left_y),
ImVec2(room_gfx_canvas_.zero_point().x + 0x100,
room_gfx_canvas_.zero_point().y + offset));

View File

@@ -11,10 +11,10 @@
#include "app/gfx/scad_format.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/modules/asset_browser.h"
#include "app/gui/canvas.h"
#include "app/gui/color.h"
#include "app/gui/input.h"
#include "app/gui/modules/asset_browser.h"
#include "app/gui/style.h"
#include "app/rom.h"
#include "imgui/imgui.h"
@@ -215,7 +215,7 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
if (value.is_active()) {
auto texture = value.texture();
graphics_bin_canvas_.draw_list()->AddImage(
(void*)texture,
(ImTextureID)(intptr_t)texture,
ImVec2(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2),
ImVec2(graphics_bin_canvas_.zero_point().x +
@@ -712,7 +712,8 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
if (Button("Paste From Clipboard")) {
const char* text = ImGui::GetClipboardText();
if (text) {
const auto clipboard_data = std::vector<uint8_t>(text, text + strlen(text));
const auto clipboard_data =
std::vector<uint8_t>(text, text + strlen(text));
ImGui::MemFree((void*)text);
status_ = temp_rom_.LoadFromBytes(clipboard_data);
is_open_ = true;

View File

@@ -109,7 +109,7 @@ void OverworldEditor::DrawToolset() {
status_ = Redo();
}
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
NEXT_COLUMN()
if (Button(ICON_MD_ZOOM_OUT)) {
@@ -127,7 +127,7 @@ void OverworldEditor::DrawToolset() {
}
HOVER_HINT("Fullscreen Canvas")
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
NEXT_COLUMN()
if (Selectable(ICON_MD_PAN_TOOL_ALT, current_mode == EditingMode::PAN)) {
@@ -186,7 +186,7 @@ void OverworldEditor::DrawToolset() {
}
HOVER_HINT("Gfx Group Editor")
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TableNextColumn();
if (Button(ICON_MD_CONTENT_COPY)) {
@@ -201,10 +201,10 @@ void OverworldEditor::DrawToolset() {
}
HOVER_HINT("Copy Map to Clipboard");
TableNextColumn(); // Palette
TableNextColumn(); // Palette
status_ = DisplayPalette(palette_, overworld_.is_loaded());
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TableNextColumn();
Checkbox("Properties", &show_properties);
@@ -514,12 +514,10 @@ void OverworldEditor::CheckForOverworldEdits() {
int end_x = std::floor(end.x / kTile16Size) * kTile16Size;
int end_y = std::floor(end.y / kTile16Size) * kTile16Size;
if (start_x > end_x)
std::swap(start_x, end_x);
if (start_y > end_y)
std::swap(start_y, end_y);
if (start_x > end_x) std::swap(start_x, end_x);
if (start_y > end_y) std::swap(start_y, end_y);
constexpr int local_map_size = 512; // Size of each local map
constexpr int local_map_size = 512; // Size of each local map
// Number of tiles per local map (since each tile is 16x16)
constexpr int tiles_per_local_map = local_map_size / kTile16Size;
@@ -670,8 +668,7 @@ void OverworldEditor::DrawOverworldCanvas() {
if (current_mode == EditingMode::DRAW_TILE) {
CheckForOverworldEdits();
}
if (IsItemHovered())
status_ = CheckForCurrentMap();
if (IsItemHovered()) status_ = CheckForCurrentMap();
}
ow_map_canvas_.DrawGrid();
@@ -734,7 +731,7 @@ void OverworldEditor::DrawTile8Selector() {
}
auto texture = value.texture();
graphics_bin_canvas_.draw_list()->AddImage(
(void *)texture,
(ImTextureID)(intptr_t)texture,
ImVec2(graphics_bin_canvas_.zero_point().x + 2, top_left_y),
ImVec2(graphics_bin_canvas_.zero_point().x + 0x100,
graphics_bin_canvas_.zero_point().y + offset));
@@ -1149,8 +1146,7 @@ void OverworldEditor::RefreshOverworldMap() {
// We need to update the map and its siblings if it's a large map
for (int i = 1; i < 4; i++) {
int sibling_index = overworld_.overworld_map(source_map_id)->parent() + i;
if (i >= 2)
sibling_index += 6;
if (i >= 2) sibling_index += 6;
futures.push_back(
std::async(std::launch::async, refresh_map_async, sibling_index));
indices[i] = sibling_index;
@@ -1179,8 +1175,7 @@ absl::Status OverworldEditor::RefreshMapPalette() {
// We need to update the map and its siblings if it's a large map
for (int i = 1; i < 4; i++) {
int sibling_index = overworld_.overworld_map(current_map_)->parent() + i;
if (i >= 2)
sibling_index += 6;
if (i >= 2) sibling_index += 6;
RETURN_IF_ERROR(
overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
RETURN_IF_ERROR(
@@ -1423,7 +1418,7 @@ void OverworldEditor::DrawUsageGrid() {
int totalSquares = 128;
int squaresWide = 8;
int squaresTall = (totalSquares + squaresWide - 1) /
squaresWide; // Ceiling of totalSquares/squaresWide
squaresWide; // Ceiling of totalSquares/squaresWide
// Loop through each row
for (int row = 0; row < squaresTall; ++row) {
@@ -1438,8 +1433,9 @@ void OverworldEditor::DrawUsageGrid() {
// Set highlight color if needed
if (highlight) {
PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.5f, 0.0f,
1.0f)); // Or any highlight color
PushStyleColor(ImGuiCol_Button,
ImVec4(1.0f, 0.5f, 0.0f,
1.0f)); // Or any highlight color
}
// Create a button or selectable for each square
@@ -1524,6 +1520,6 @@ void OverworldEditor::InitializeZeml() {
});
}
} // namespace editor
} // namespace app
} // namespace yaze
} // namespace editor
} // namespace app
} // namespace yaze

View File

@@ -118,7 +118,8 @@ void Emulator::RenderSnesPpu() {
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar);
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - size.x) * 0.5f);
ImGui::SetCursorPosY((ImGui::GetWindowSize().y - size.y) * 0.5f);
ImGui::Image((void*)ppu_texture_, size, ImVec2(0, 0), ImVec2(1, 1));
ImGui::Image((ImTextureID)(intptr_t)ppu_texture_, size, ImVec2(0, 0),
ImVec2(1, 1));
ImGui::EndChild();
} else {

View File

@@ -236,7 +236,7 @@ bool Canvas::DrawTilePainter(const Bitmap &bitmap, int size, float scale) {
if (bitmap.is_active()) {
draw_list_->AddImage(
(void *)bitmap.texture(),
(ImTextureID)(intptr_t)bitmap.texture(),
ImVec2(origin.x + painter_pos.x, origin.y + painter_pos.y),
ImVec2(origin.x + painter_pos.x + (size)*scale,
origin.y + painter_pos.y + size * scale));
@@ -464,7 +464,7 @@ void Canvas::DrawSelectRect(int current_map, int tile_size, float scale) {
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, bool ready) {
if (ready) {
draw_list_->AddImage(
(void *)bitmap.texture(),
(ImTextureID)(intptr_t)bitmap.texture(),
ImVec2(canvas_p0_.x + border_offset, canvas_p0_.y + border_offset),
ImVec2(canvas_p0_.x + (bitmap.width() * 2),
canvas_p0_.y + (bitmap.height() * 2)));
@@ -475,7 +475,7 @@ void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, float scale) {
if (!bitmap.is_active()) {
return;
}
draw_list_->AddImage((void *)bitmap.texture(),
draw_list_->AddImage((ImTextureID)(intptr_t)bitmap.texture(),
ImVec2(canvas_p0_.x, canvas_p0_.y),
ImVec2(canvas_p0_.x + (bitmap.width() * scale),
canvas_p0_.y + (bitmap.height() * scale)));
@@ -488,7 +488,7 @@ void Canvas::DrawBitmap(const Bitmap &bitmap, int x_offset, int y_offset,
return;
}
draw_list_->AddImage(
(void *)bitmap.texture(),
(ImTextureID)(intptr_t)bitmap.texture(),
ImVec2(canvas_p0_.x + x_offset + scrolling_.x,
canvas_p0_.y + y_offset + scrolling_.y),
ImVec2(
@@ -505,7 +505,7 @@ void Canvas::DrawBitmapTable(const BitmapTable &gfx_bin) {
if (key >= 1) {
top_left_y = canvas_p0_.y + 0x40 * key;
}
draw_list_->AddImage((void *)value.texture(),
draw_list_->AddImage((ImTextureID)(intptr_t)value.texture(),
ImVec2(canvas_p0_.x + 2, top_left_y),
ImVec2(canvas_p0_.x + 0x100, canvas_p0_.y + offset));
}
@@ -805,7 +805,8 @@ void GraphicsBinCanvasPipeline(int width, int height, int tile_size,
int num_sheets_to_load, int canvas_id,
bool is_loaded, gfx::BitmapTable &graphics_bin) {
gui::Canvas canvas;
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)canvas_id);
if (ImGuiID child_id =
ImGui::GetID((ImTextureID)(intptr_t)(intptr_t)canvas_id);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
canvas.DrawBackground(ImVec2(width + 1, num_sheets_to_load * height + 1));
@@ -818,7 +819,7 @@ void GraphicsBinCanvasPipeline(int width, int height, int tile_size,
top_left_y = canvas.zero_point().y + height * key;
}
canvas.draw_list()->AddImage(
(void *)value.texture(),
(ImTextureID)(intptr_t)value.texture(),
ImVec2(canvas.zero_point().x + 2, top_left_y),
ImVec2(canvas.zero_point().x + 0x100,
canvas.zero_point().y + offset));
@@ -845,7 +846,8 @@ void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap,
};
if (scrollbar) {
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)canvas_id);
if (ImGuiID child_id =
ImGui::GetID((ImTextureID)(intptr_t)(intptr_t)canvas_id);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
draw_canvas(canvas, bitmap, width, height, tile_size, is_loaded);

View File

@@ -229,9 +229,10 @@ void GfxSheetAssetBrowser::Draw(
if (display_label) {
ImU32 label_col = GetColorU32(
item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled);
draw_list->AddImage((void*)bmp_manager[item_data->ID].texture(),
box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
GetColorU32(ImVec4(1, 1, 1, 1)));
draw_list->AddImage(
(ImTextureID)(intptr_t)bmp_manager[item_data->ID].texture(),
box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
GetColorU32(ImVec4(1, 1, 1, 1)));
draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()),
label_col,
absl::StrFormat("%X", item_data->ID).c_str());

View File

@@ -1,17 +1,17 @@
#ifndef YAZE_APP_CORE_STYLE_H
#define YAZE_APP_CORE_STYLE_H
#include "ImGuiColorTextEdit/TextEditor.h"
#include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
#include <functional>
#include <vector>
#include "ImGuiColorTextEdit/TextEditor.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "app/core/constants.h"
#include "app/gfx/bitmap.h"
#include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
namespace yaze {
namespace app {
@@ -72,7 +72,7 @@ class BitmapViewer {
const gfx::Bitmap& current_bitmap = bitmaps[current_bitmap_index_];
// Assuming Bitmap has a function to get its texture ID, and width and
// height.
ImTextureID tex_id = current_bitmap.texture();
ImTextureID tex_id = (ImTextureID)(intptr_t)current_bitmap.texture();
ImVec2 size(current_bitmap.width() * scale,
current_bitmap.height() * scale);
// ImGui::Image(tex_id, size);