Consolidated renderer and window into the controller, added hex text input, removed more junk
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <imgui/backends/imgui_impl_sdl.h>
|
||||||
|
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include <imgui/imgui_internal.h>
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
#include "Core/renderer.h"
|
#include <memory>
|
||||||
#include "Core/window.h"
|
|
||||||
#include "Editor/editor.h"
|
#include "Editor/editor.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -15,8 +17,9 @@ namespace Core {
|
|||||||
bool Controller::isActive() const { return active_; }
|
bool Controller::isActive() const { return active_; }
|
||||||
|
|
||||||
void Controller::onEntry() {
|
void Controller::onEntry() {
|
||||||
window_.Create();
|
CreateWindow();
|
||||||
renderer_.Create(window_.Get());
|
CreateRenderer();
|
||||||
|
CreateGuiContext();
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
|
io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
|
||||||
io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey(SDLK_RETURN);
|
io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey(SDLK_RETURN);
|
||||||
@@ -94,17 +97,88 @@ void Controller::onInput() {
|
|||||||
|
|
||||||
void Controller::onLoad() { editor_.UpdateScreen(); }
|
void Controller::onLoad() { editor_.UpdateScreen(); }
|
||||||
|
|
||||||
void Controller::doRender() { renderer_.Render(); }
|
void Controller::doRender() {
|
||||||
|
SDL_RenderClear(sdl_renderer_.get());
|
||||||
|
ImGui::Render();
|
||||||
|
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
SDL_RenderPresent(sdl_renderer_.get());
|
||||||
|
}
|
||||||
|
|
||||||
void Controller::onExit() {
|
void Controller::onExit() {
|
||||||
ImGui_ImplSDLRenderer_Shutdown();
|
ImGui_ImplSDLRenderer_Shutdown();
|
||||||
ImGui_ImplSDL2_Shutdown();
|
ImGui_ImplSDL2_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
window_.Destroy();
|
|
||||||
renderer_.Destroy();
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::CreateWindow() {
|
||||||
|
if (SDL_Init(SDL_INIT_EVERYTHING)) {
|
||||||
|
SDL_Log("SDL_Init: %s\n", SDL_GetError());
|
||||||
|
} else {
|
||||||
|
sdl_window_ = std::unique_ptr<SDL_Window, sdl_deleter>(
|
||||||
|
SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
||||||
|
1200, // width, in pixels
|
||||||
|
800, // height, in pixels
|
||||||
|
SDL_WINDOW_RESIZABLE),
|
||||||
|
sdl_deleter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::CreateRenderer() {
|
||||||
|
if (sdl_window_ == nullptr) {
|
||||||
|
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
|
||||||
|
SDL_Quit();
|
||||||
|
} else {
|
||||||
|
sdl_renderer_ = std::unique_ptr<SDL_Renderer, sdl_deleter>(
|
||||||
|
SDL_CreateRenderer(
|
||||||
|
sdl_window_.get(), -1,
|
||||||
|
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
|
||||||
|
sdl_deleter());
|
||||||
|
if (sdl_renderer_ == nullptr) {
|
||||||
|
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
|
||||||
|
SDL_Quit();
|
||||||
|
} else {
|
||||||
|
SDL_SetRenderDrawBlendMode(sdl_renderer_.get(), SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetRenderDrawColor(sdl_renderer_.get(), 0x00, 0x00, 0x00, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::CreateGuiContext() {
|
||||||
|
// Create the ImGui and ImPlot contexts
|
||||||
|
ImGui::CreateContext();
|
||||||
|
|
||||||
|
// Initialize ImGui for SDL
|
||||||
|
ImGui_ImplSDL2_InitForSDLRenderer(sdl_window_.get(), sdl_renderer_.get());
|
||||||
|
ImGui_ImplSDLRenderer_Init(sdl_renderer_.get());
|
||||||
|
|
||||||
|
// Load available fonts
|
||||||
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
|
io.Fonts->AddFontFromFileTTF("assets/Fonts/Karla-Regular.ttf", 14.0f);
|
||||||
|
|
||||||
|
// merge in icons from Google Material Design
|
||||||
|
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
||||||
|
ImFontConfig icons_config;
|
||||||
|
icons_config.MergeMode = true;
|
||||||
|
icons_config.GlyphOffset.y = 5.0f;
|
||||||
|
icons_config.GlyphMinAdvanceX = 13.0f;
|
||||||
|
icons_config.PixelSnapH = true;
|
||||||
|
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, 18.0f, &icons_config,
|
||||||
|
icons_ranges);
|
||||||
|
io.Fonts->AddFontFromFileTTF("assets/Fonts/Roboto-Medium.ttf", 14.0f);
|
||||||
|
io.Fonts->AddFontFromFileTTF("assets/Fonts/Cousine-Regular.ttf", 14.0f);
|
||||||
|
io.Fonts->AddFontFromFileTTF("assets/Fonts/DroidSans.ttf", 16.0f);
|
||||||
|
|
||||||
|
// Set the default style
|
||||||
|
Style::ColorsYaze();
|
||||||
|
|
||||||
|
// Build a new ImGui frame
|
||||||
|
ImGui_ImplSDLRenderer_NewFrame();
|
||||||
|
ImGui_ImplSDL2_NewFrame(sdl_window_.get());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
@@ -3,14 +3,16 @@
|
|||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <imgui/backends/imgui_impl_sdl.h>
|
||||||
|
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include <imgui/imgui_internal.h>
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
#include "Core/renderer.h"
|
|
||||||
#include "Core/window.h"
|
|
||||||
#include "Editor/editor.h"
|
#include "Editor/editor.h"
|
||||||
|
#include "Graphics/icons.h"
|
||||||
|
#include "Graphics/style.h"
|
||||||
|
|
||||||
int main(int argc, char** argv);
|
int main(int argc, char **argv);
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace Application {
|
namespace Application {
|
||||||
@@ -28,13 +30,22 @@ class Controller {
|
|||||||
void onExit();
|
void onExit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CreateWindow();
|
||||||
|
void CreateRenderer();
|
||||||
|
void CreateGuiContext();
|
||||||
inline void quit() { active_ = false; }
|
inline void quit() { active_ = false; }
|
||||||
friend int ::main(int argc, char** argv);
|
friend int ::main(int argc, char **argv);
|
||||||
|
|
||||||
|
struct sdl_deleter {
|
||||||
|
void operator()(SDL_Window *p) const { SDL_DestroyWindow(p); }
|
||||||
|
void operator()(SDL_Renderer *p) const { SDL_DestroyRenderer(p); }
|
||||||
|
void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); }
|
||||||
|
};
|
||||||
|
|
||||||
bool active_;
|
bool active_;
|
||||||
Window window_;
|
|
||||||
Renderer renderer_;
|
|
||||||
Editor::Editor editor_;
|
Editor::Editor editor_;
|
||||||
|
std::shared_ptr<SDL_Window> sdl_window_;
|
||||||
|
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
25
src/Application/Core/input.cc
Normal file
25
src/Application/Core/input.cc
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <imgui/imgui.h>
|
||||||
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace Gui {
|
||||||
|
|
||||||
|
const int kStepOneHex = 0x01;
|
||||||
|
const int kStepFastHex = 0x0F;
|
||||||
|
|
||||||
|
bool InputHex(const char* label, int* data) {
|
||||||
|
return ImGui::InputScalar(label, ImGuiDataType_U64, data, &kStepOneHex,
|
||||||
|
&kStepFastHex, "%06X",
|
||||||
|
ImGuiInputTextFlags_CharsHexadecimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputHexShort(const char* label, int* data) {
|
||||||
|
return ImGui::InputScalar(label, ImGuiDataType_U32, data, &kStepOneHex,
|
||||||
|
&kStepFastHex, "%06X",
|
||||||
|
ImGuiInputTextFlags_CharsHexadecimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Gui
|
||||||
|
} // namespace yaze
|
||||||
19
src/Application/Core/input.h
Normal file
19
src/Application/Core/input.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef YAZE_APPLICATION_CORE_INPUT_H
|
||||||
|
#define YAZE_APPLICATION_CORE_INPUT_H
|
||||||
|
|
||||||
|
#include <imgui/imgui.h>
|
||||||
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace Gui {
|
||||||
|
|
||||||
|
IMGUI_API bool InputHex(const char* label, int* data);
|
||||||
|
IMGUI_API bool InputHexShort(const char* label, int* data);
|
||||||
|
|
||||||
|
} // namespace Gui
|
||||||
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
#include "renderer.h"
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <imgui/backends/imgui_impl_sdl.h>
|
|
||||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
|
||||||
#include <imgui/imgui.h>
|
|
||||||
|
|
||||||
#include "Graphics/icons.h"
|
|
||||||
#include "Graphics/style.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
|
||||||
namespace Application {
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
void Renderer::Create(SDL_Window* window) {
|
|
||||||
if (window == nullptr) {
|
|
||||||
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
|
|
||||||
SDL_Quit();
|
|
||||||
} else {
|
|
||||||
renderer = SDL_CreateRenderer(
|
|
||||||
window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
||||||
if (renderer == nullptr) {
|
|
||||||
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
|
|
||||||
SDL_Quit();
|
|
||||||
} else {
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the ImGui and ImPlot contexts
|
|
||||||
ImGui::CreateContext();
|
|
||||||
|
|
||||||
// Initialize ImGui for SDL
|
|
||||||
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
|
|
||||||
ImGui_ImplSDLRenderer_Init(renderer);
|
|
||||||
|
|
||||||
// Load available fonts
|
|
||||||
const ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Karla-Regular.ttf", 14.0f);
|
|
||||||
|
|
||||||
// merge in icons from Google Material Design
|
|
||||||
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
|
||||||
ImFontConfig icons_config;
|
|
||||||
icons_config.MergeMode = true;
|
|
||||||
icons_config.GlyphOffset.y = 5.0f;
|
|
||||||
icons_config.GlyphMinAdvanceX = 13.0f;
|
|
||||||
icons_config.PixelSnapH = true;
|
|
||||||
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, 18.0f, &icons_config,
|
|
||||||
icons_ranges);
|
|
||||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Roboto-Medium.ttf", 14.0f);
|
|
||||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Cousine-Regular.ttf", 14.0f);
|
|
||||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/DroidSans.ttf", 16.0f);
|
|
||||||
|
|
||||||
// Set the default style
|
|
||||||
Style::ColorsYaze();
|
|
||||||
|
|
||||||
// Build a new ImGui frame
|
|
||||||
ImGui_ImplSDLRenderer_NewFrame();
|
|
||||||
ImGui_ImplSDL2_NewFrame(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Render() {
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
ImGui::Render();
|
|
||||||
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Destroy() {
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
renderer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace yaze
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef YAZE_APPLICATION_CORE_RENDERER_H
|
|
||||||
#define YAZE_APPLICATION_CORE_RENDERER_H
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <imgui/backends/imgui_impl_sdl.h>
|
|
||||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
|
||||||
#include <imgui/imgui.h>
|
|
||||||
|
|
||||||
#include "Graphics/icons.h"
|
|
||||||
#include "Graphics/style.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
|
||||||
namespace Application {
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
static SDL_Renderer* renderer = nullptr;
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
public:
|
|
||||||
void Create(SDL_Window* window);
|
|
||||||
void Render();
|
|
||||||
void Destroy();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Core
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace yaze
|
|
||||||
|
|
||||||
#endif // YAZE_APPLICATION_CORE_RENDERER_H
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#include "window.h"
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
namespace yaze {
|
|
||||||
namespace Application {
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
// TODO: pass in the size of the window as argument
|
|
||||||
void Window::Create() {
|
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING)) {
|
|
||||||
SDL_Log("SDL_Init: %s\n", SDL_GetError());
|
|
||||||
} else {
|
|
||||||
window = SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
|
||||||
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
|
||||||
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
|
||||||
1200, // width, in pixels
|
|
||||||
800, // height, in pixels
|
|
||||||
SDL_WINDOW_RESIZABLE // window flags
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Window* Window::Get() { return window; }
|
|
||||||
|
|
||||||
void Window::Destroy() {
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
window = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace yaze
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef YAZE_APPLICATION_CORE_WINDOW_H
|
|
||||||
#define YAZE_APPLICATION_CORE_WINDOW_H
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
namespace yaze {
|
|
||||||
namespace Application {
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
class Window {
|
|
||||||
public:
|
|
||||||
void Create();
|
|
||||||
void Destroy();
|
|
||||||
SDL_Window* Get();
|
|
||||||
|
|
||||||
private:
|
|
||||||
SDL_Window* window = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Core
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace yaze
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -38,8 +38,8 @@ std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
|
|||||||
std::cout << "Extracting tiles..." << std::endl;
|
std::cout << "Extracting tiles..." << std::endl;
|
||||||
uint filePos = 0;
|
uint filePos = 0;
|
||||||
uint size_out = 0;
|
uint size_out = 0;
|
||||||
uint size = preset.length;
|
uint size = preset.length_;
|
||||||
int tilePos = preset.pcTilesLocation;
|
int tilePos = preset.pc_tiles_location_;
|
||||||
std::vector<tile8> rawTiles;
|
std::vector<tile8> rawTiles;
|
||||||
filePos = GetRomPosition(preset, tilePos, preset.SNESTilesLocation);
|
filePos = GetRomPosition(preset, tilePos, preset.SNESTilesLocation);
|
||||||
std::cout << "ROM Position: " << filePos << " from "
|
std::cout << "ROM Position: " << filePos << " from "
|
||||||
@@ -51,7 +51,7 @@ std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
|
|||||||
data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
||||||
std::cout << "size: " << size << std::endl;
|
std::cout << "size: " << size << std::endl;
|
||||||
std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
||||||
if (data == NULL) {
|
if (data == nullptr) {
|
||||||
std::cout << alttp_decompression_error << std::endl;
|
std::cout << alttp_decompression_error << std::endl;
|
||||||
return rawTiles;
|
return rawTiles;
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,9 @@ std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
|
|||||||
// unpack the tiles based on their depth
|
// unpack the tiles based on their depth
|
||||||
unsigned tileCpt = 0;
|
unsigned tileCpt = 0;
|
||||||
std::cout << "Unpacking tiles..." << std::endl;
|
std::cout << "Unpacking tiles..." << std::endl;
|
||||||
for (unsigned int tilePos = 0; tilePos < size; tilePos += preset.bpp * 8) {
|
for (unsigned int tilePos = 0; tilePos < size;
|
||||||
tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bpp);
|
tilePos += preset.bits_per_pixel_ * 8) {
|
||||||
|
tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bits_per_pixel_);
|
||||||
newTile.id = tileCpt;
|
newTile.id = tileCpt;
|
||||||
rawTiles.push_back(newTile);
|
rawTiles.push_back(newTile);
|
||||||
tileCpt++;
|
tileCpt++;
|
||||||
@@ -72,10 +73,10 @@ std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Graphics::SNESPalette ROM::ExtractPalette(Graphics::TilePreset &preset) {
|
Graphics::SNESPalette ROM::ExtractPalette(Graphics::TilePreset &preset) {
|
||||||
unsigned int filePos = GetRomPosition(preset, preset.pcPaletteLocation,
|
unsigned int filePos = GetRomPosition(preset, preset.pc_palette_location_,
|
||||||
preset.SNESPaletteLocation);
|
preset.SNESPaletteLocation);
|
||||||
std::cout << "Palette pos : " << filePos << std::endl; // TODO: make this hex
|
std::cout << "Palette pos : " << filePos << std::endl; // TODO: make this hex
|
||||||
unsigned int palette_size = pow(2, preset.bpp); // - 1;
|
unsigned int palette_size = pow(2, preset.bits_per_pixel_); // - 1;
|
||||||
char *ab = (char *)malloc(sizeof(char) * (palette_size * 2));
|
char *ab = (char *)malloc(sizeof(char) * (palette_size * 2));
|
||||||
memcpy(ab, current_rom_ + filePos, palette_size * 2);
|
memcpy(ab, current_rom_ + filePos, palette_size * 2);
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ Graphics::SNESPalette ROM::ExtractPalette(Graphics::TilePreset &preset) {
|
|||||||
|
|
||||||
const char *data = ab;
|
const char *data = ab;
|
||||||
Graphics::SNESPalette pal(ab);
|
Graphics::SNESPalette pal(ab);
|
||||||
if (preset.paletteNoZeroColor) {
|
if (preset.no_zero_color_) {
|
||||||
Graphics::SNESColor col;
|
Graphics::SNESColor col;
|
||||||
|
|
||||||
col.setRgb(ImVec4(153, 153, 153, 255));
|
col.setRgb(ImVec4(153, 153, 153, 255));
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ Editor::Editor() {
|
|||||||
asm_editor_.SetLanguageDefinition(language_65816_);
|
asm_editor_.SetLanguageDefinition(language_65816_);
|
||||||
asm_editor_.SetPalette(TextEditor::GetDarkPalette());
|
asm_editor_.SetPalette(TextEditor::GetDarkPalette());
|
||||||
|
|
||||||
current_set_.bpp = 4;
|
current_set_.bits_per_pixel_ = 4;
|
||||||
current_set_.pcTilesLocation = 0x80000;
|
current_set_.pc_tiles_location_ = 0x80000;
|
||||||
current_set_.SNESTilesLocation = 0x0000;
|
current_set_.SNESTilesLocation = 0x0000;
|
||||||
current_set_.length = 28672;
|
current_set_.length_ = 28672;
|
||||||
current_set_.pcPaletteLocation = 906022;
|
current_set_.pc_palette_location_ = 906022;
|
||||||
current_set_.SNESPaletteLocation = 0;
|
current_set_.SNESPaletteLocation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,22 +263,20 @@ void Editor::DrawProjectEditor() {
|
|||||||
ImGui::Text("Version: %d", rom_.getVersion());
|
ImGui::Text("Version: %d", rom_.getVersion());
|
||||||
ImGui::Text("ROM Size: %ld", rom_.getSize());
|
ImGui::Text("ROM Size: %ld", rom_.getSize());
|
||||||
|
|
||||||
ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32,
|
ImGui::InputInt("Bits per Pixel", ¤t_set_.bits_per_pixel_);
|
||||||
(void *)¤t_set_.bpp);
|
|
||||||
|
|
||||||
ImGui::InputInt("PC Tile Location", ¤t_set_.pcTilesLocation);
|
yaze::Gui::InputHex("PC Tile Location", ¤t_set_.pc_tiles_location_);
|
||||||
// 1, 100, ImGuiInputTextFlags_CharsHexadecimal
|
|
||||||
|
|
||||||
ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U16,
|
yaze::Gui::InputHex("SNES Tile Location",
|
||||||
(void *)¤t_set_.SNESTilesLocation);
|
¤t_set_.SNESTilesLocation);
|
||||||
|
|
||||||
ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32,
|
ImGui::InputInt("Tile Preset Length", ¤t_set_.length_);
|
||||||
(void *)¤t_set_.length);
|
|
||||||
|
|
||||||
ImGui::InputInt("PC Palette Location", ¤t_set_.pcPaletteLocation);
|
ImGui::InputInt("PC Palette Location",
|
||||||
|
¤t_set_.pc_palette_location_);
|
||||||
|
|
||||||
ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U16,
|
yaze::Gui::InputHex("SNES Palette Location",
|
||||||
(void *)¤t_set_.SNESPaletteLocation);
|
¤t_set_.SNESPaletteLocation);
|
||||||
|
|
||||||
BASIC_BUTTON("ExtractTiles") {
|
BASIC_BUTTON("ExtractTiles") {
|
||||||
if (rom_.isLoaded()) {
|
if (rom_.isLoaded()) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||||
|
|
||||||
#include "Core/constants.h"
|
#include "Core/constants.h"
|
||||||
|
#include "Core/input.h"
|
||||||
#include "Data/rom.h"
|
#include "Data/rom.h"
|
||||||
#include "Editor/overworld_editor.h"
|
#include "Editor/overworld_editor.h"
|
||||||
#include "Graphics/icons.h"
|
#include "Graphics/icons.h"
|
||||||
|
|||||||
10
src/Application/Editor/tile_editor.cc
Normal file
10
src/Application/Editor/tile_editor.cc
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "tile_editor.h"
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace Application {
|
||||||
|
namespace Editor {
|
||||||
|
|
||||||
|
void TileEditor::UpdateScreen() {}
|
||||||
|
} // namespace Editor
|
||||||
|
} // namespace Application
|
||||||
|
} // namespace yaze
|
||||||
15
src/Application/Editor/tile_editor.h
Normal file
15
src/Application/Editor/tile_editor.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef YAZE_APPLICATION_EDITOR_TILEEDITOR_H
|
||||||
|
#define YAZE_APPLICATION_EDITOR_TILEEDITOR_H
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace Application {
|
||||||
|
namespace Editor {
|
||||||
|
class TileEditor {
|
||||||
|
public:
|
||||||
|
void UpdateScreen();
|
||||||
|
};
|
||||||
|
} // namespace Editor
|
||||||
|
} // namespace Application
|
||||||
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -73,6 +73,7 @@ char* SNESPalette::encode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Palette* SNESPalette::GetSDL_Palette() {
|
SDL_Palette* SNESPalette::GetSDL_Palette() {
|
||||||
|
std::cout << "Converting SNESPalette to SDL_Palette" << std::endl;
|
||||||
auto sdl_palette = std::make_shared<SDL_Palette>();
|
auto sdl_palette = std::make_shared<SDL_Palette>();
|
||||||
sdl_palette->ncolors = size_;
|
sdl_palette->ncolors = size_;
|
||||||
|
|
||||||
@@ -81,6 +82,9 @@ SDL_Palette* SNESPalette::GetSDL_Palette() {
|
|||||||
sdl_colors[i].r = (uint8_t)colors[i].rgb.x * 100;
|
sdl_colors[i].r = (uint8_t)colors[i].rgb.x * 100;
|
||||||
sdl_colors[i].g = (uint8_t)colors[i].rgb.y * 100;
|
sdl_colors[i].g = (uint8_t)colors[i].rgb.y * 100;
|
||||||
sdl_colors[i].b = (uint8_t)colors[i].rgb.z * 100;
|
sdl_colors[i].b = (uint8_t)colors[i].rgb.z * 100;
|
||||||
|
std::cout << "Color " << i << " added (R:" << sdl_colors[i].r
|
||||||
|
<< " G:" << sdl_colors[i].g << " B:" << sdl_colors[i].b << ")"
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
sdl_palette->colors = sdl_colors;
|
sdl_palette->colors = sdl_colors;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Core/renderer.h"
|
|
||||||
#include "Graphics/tile.h"
|
#include "Graphics/tile.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -23,59 +22,32 @@ void Scene::buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
|
|||||||
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
|
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
|
||||||
tile8 tile = arrangedTiles[j][i];
|
tile8 tile = arrangedTiles[j][i];
|
||||||
// SDL_PIXELFORMAT_RGB888 ?
|
// SDL_PIXELFORMAT_RGB888 ?
|
||||||
SDL_Surface* newImage = SDL_CreateRGBSurfaceWithFormat(
|
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormat(
|
||||||
0, 8, 8, SDL_BITSPERPIXEL(3), SDL_PIXELFORMAT_RGB444);
|
0, 8, 8, SDL_BITSPERPIXEL(3), SDL_PIXELFORMAT_RGB444);
|
||||||
SDL_PixelFormat* format = newImage->format;
|
if (surface == nullptr) {
|
||||||
|
SDL_Log("SDL_CreateRGBSurfaceWithFormat() failed: %s", SDL_GetError());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
SDL_PixelFormat* format = surface->format;
|
||||||
format->palette = mPalette.GetSDL_Palette();
|
format->palette = mPalette.GetSDL_Palette();
|
||||||
|
char* ptr = (char*)surface->pixels;
|
||||||
|
|
||||||
char* ptr = (char*)newImage->pixels;
|
for (int k = 0; k < 8; k++) {
|
||||||
|
for (int l = 0; l < 8; l++) {
|
||||||
for (int i = 0; i < 8; i++) {
|
ptr[k * 8 + l] = tile.data[k * 8 + l];
|
||||||
for (int j = 0; j < 8; j++) {
|
|
||||||
ptr[i * 8 + j] = (char)tile.data[i * 8 + j];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Texture* texture =
|
// SDL_Texture* texture =
|
||||||
SDL_CreateTextureFromSurface(Core::renderer, newImage);
|
// SDL_CreateTextureFromSurface(Core::renderer, surface);
|
||||||
imagesCache[tile.id] = texture;
|
// if (texture == nullptr) {
|
||||||
|
// std::cout << "Error: " << SDL_GetError() << std::endl;
|
||||||
|
// }
|
||||||
|
// imagesCache[tile.id] = texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::buildScene(const std::vector<tile8>& tiles,
|
|
||||||
const SNESPalette mPalette, const TilesPattern& tp) {
|
|
||||||
arrangedTiles = TilesPattern::transform(tp, tiles);
|
|
||||||
tilesPattern = tp;
|
|
||||||
allTiles = tiles;
|
|
||||||
for (unsigned int j = 0; j < arrangedTiles.size(); j++) {
|
|
||||||
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
|
|
||||||
tile8 tile = arrangedTiles[j][i];
|
|
||||||
// QImage newImage(8, 8, QImage::Format_Indexed8);
|
|
||||||
// newImage.setColorCount(mPalette.size);
|
|
||||||
// for (int i = 0; i < mPalette.size; i++) {
|
|
||||||
// newImage.setColor(i, mPalette.colors.at(i).rgb);
|
|
||||||
// }
|
|
||||||
// for (int i = 0; i < 8; i++) {
|
|
||||||
// for (int j = 0; j < 8; j++)
|
|
||||||
// newImage.setPixel(i, j, tile.data[i + j * 8]);
|
|
||||||
// }
|
|
||||||
// QPixmap m;
|
|
||||||
// m.convertFromImage(newImage);
|
|
||||||
// imagesCache[tile.id] = m;
|
|
||||||
// GraphicsTileItem *newTileItem = new GraphicsTileItem(m, tile);
|
|
||||||
// addItem(newTileItem);
|
|
||||||
// newTileItem->setTileZoom(tilesZoom);
|
|
||||||
// newTileItem->setPos(i * newTileItem->boundingRect().width() + i,
|
|
||||||
// j * newTileItem->boundingRect().width() + j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// unsigned max_w = items()[0]->boundingRect().width() *
|
|
||||||
// arrangedTiles[0].size() + arrangedTiles[0].size(); unsigned max_h =
|
|
||||||
// items()[0]->boundingRect().width() * arrangedTiles.size() +
|
|
||||||
// arrangedTiles.size(); setSceneRect(QRect(0, 0, max_w, max_h));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::updateScene() {
|
void Scene::updateScene() {
|
||||||
std::cout << "Update scene";
|
std::cout << "Update scene";
|
||||||
unsigned int itemCpt = 0;
|
unsigned int itemCpt = 0;
|
||||||
@@ -92,13 +64,6 @@ void Scene::updateScene() {
|
|||||||
itemCpt++;
|
itemCpt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// unsigned max_w =
|
|
||||||
// items()[0]->boundingRect().width() * arrangedTiles[0].size() +
|
|
||||||
// arrangedTiles[0].size();
|
|
||||||
// unsigned max_h = items()[0]->boundingRect().width() * arrangedTiles.size()
|
|
||||||
// +
|
|
||||||
// arrangedTiles.size();
|
|
||||||
// setSceneRect(QRect(0, 0, max_w, max_h));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setTilesZoom(unsigned int tileZoom) {
|
void Scene::setTilesZoom(unsigned int tileZoom) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Core/renderer.h"
|
|
||||||
#include "Graphics/tile.h"
|
#include "Graphics/tile.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -17,9 +16,6 @@ namespace Graphics {
|
|||||||
class Scene {
|
class Scene {
|
||||||
public:
|
public:
|
||||||
Scene() = default;
|
Scene() = default;
|
||||||
void buildScene(const std::vector<tile8>& tiles, const SNESPalette mPalette,
|
|
||||||
const TilesPattern& tp);
|
|
||||||
|
|
||||||
void buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
|
void buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
|
||||||
const TilesPattern& tp);
|
const TilesPattern& tp);
|
||||||
|
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ class TilePreset {
|
|||||||
TilePreset() = default;
|
TilePreset() = default;
|
||||||
TilesPattern tilesPattern;
|
TilesPattern tilesPattern;
|
||||||
bool no_zero_color_ = false;
|
bool no_zero_color_ = false;
|
||||||
int pc_tiles_location_ = -1;
|
int pc_tiles_location_ = 0;
|
||||||
int pc_palette_location_ = 0;
|
int pc_palette_location_ = 0;
|
||||||
uint32_t length_ = 0;
|
int bits_per_pixel_ = 0;
|
||||||
uint32_t bits_per_pixel_ = 0;
|
int length_ = 0;
|
||||||
uint16_t SNESTilesLocation = 0;
|
int SNESTilesLocation = 0;
|
||||||
uint16_t SNESPaletteLocation = 0;
|
int SNESPaletteLocation = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
|
|||||||
Reference in New Issue
Block a user