Refactor editor includes and update source files for improved organization
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "ImGuiColorTextEdit/TextEditor.h"
|
#include "ImGuiColorTextEdit/TextEditor.h"
|
||||||
#include "app/core/common.h"
|
#include "app/core/common.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gui/style.h"
|
#include "app/gui/style.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "app/editor/music/music_editor.h"
|
#include "app/editor/music/music_editor.h"
|
||||||
#include "app/editor/overworld/overworld_editor.h"
|
#include "app/editor/overworld/overworld_editor.h"
|
||||||
#include "app/editor/sprite/sprite_editor.h"
|
#include "app/editor/sprite/sprite_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/editor/utils/gfx_context.h"
|
#include "app/editor/utils/gfx_context.h"
|
||||||
#include "app/emu/emulator.h"
|
#include "app/emu/emulator.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "dungeon_editor.h"
|
#include "dungeon_editor.h"
|
||||||
|
|
||||||
|
#include "absl/container/flat_hash_map.h"
|
||||||
#include "app/core/platform/renderer.h"
|
#include "app/core/platform/renderer.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
#define YAZE_APP_EDITOR_DUNGEONEDITOR_H
|
#define YAZE_APP_EDITOR_DUNGEONEDITOR_H
|
||||||
|
|
||||||
#include "app/core/common.h"
|
#include "app/core/common.h"
|
||||||
|
#include "absl/container/flat_hash_map.h"
|
||||||
#include "app/editor/graphics/gfx_group_editor.h"
|
#include "app/editor/graphics/gfx_group_editor.h"
|
||||||
#include "app/editor/graphics/palette_editor.h"
|
#include "app/editor/graphics/palette_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|||||||
52
src/app/editor/editor.cc
Normal file
52
src/app/editor/editor.cc
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include "editor.h"
|
||||||
|
|
||||||
|
#include "app/core/constants.h"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace app {
|
||||||
|
namespace editor {
|
||||||
|
|
||||||
|
absl::Status DrawEditor(EditorLayoutParams *params) {
|
||||||
|
if (params->editor == nullptr) {
|
||||||
|
return absl::InternalError("Editor is not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the editors based on h_split and v_split in a recursive manner
|
||||||
|
if (params->v_split) {
|
||||||
|
ImGui::BeginTable("##VerticalSplitTable", 2);
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
if (params->left)
|
||||||
|
RETURN_IF_ERROR(DrawEditor(params->left));
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
if (params->right)
|
||||||
|
RETURN_IF_ERROR(DrawEditor(params->right));
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
|
} else if (params->h_split) {
|
||||||
|
ImGui::BeginTable("##HorizontalSplitTable", 1);
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
if (params->top)
|
||||||
|
RETURN_IF_ERROR(DrawEditor(params->top));
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
if (params->bottom)
|
||||||
|
RETURN_IF_ERROR(DrawEditor(params->bottom));
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
|
} else {
|
||||||
|
// No split, just draw the single editor
|
||||||
|
ImGui::Text("%s Editor",
|
||||||
|
kEditorNames[static_cast<int>(params->editor->type())]);
|
||||||
|
RETURN_IF_ERROR(params->editor->Update());
|
||||||
|
}
|
||||||
|
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace editor
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
set(
|
set(
|
||||||
YAZE_APP_EDITOR_SRC
|
YAZE_APP_EDITOR_SRC
|
||||||
|
app/editor/editor.cc
|
||||||
app/editor/editor_manager.cc
|
app/editor/editor_manager.cc
|
||||||
app/editor/dungeon/dungeon_editor.cc
|
app/editor/dungeon/dungeon_editor.cc
|
||||||
app/editor/overworld/overworld_editor.cc
|
app/editor/overworld/overworld_editor.cc
|
||||||
|
|||||||
@@ -58,8 +58,32 @@ class Editor {
|
|||||||
EditorType type_;
|
EditorType type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dynamic Editor Layout Parameters
|
||||||
|
*/
|
||||||
|
typedef struct EditorLayoutParams {
|
||||||
|
bool v_split;
|
||||||
|
bool h_split;
|
||||||
|
int v_split_pos;
|
||||||
|
int h_split_pos;
|
||||||
|
Editor *editor = nullptr;
|
||||||
|
EditorLayoutParams *left = nullptr;
|
||||||
|
EditorLayoutParams *right = nullptr;
|
||||||
|
EditorLayoutParams *top = nullptr;
|
||||||
|
EditorLayoutParams *bottom = nullptr;
|
||||||
|
|
||||||
|
EditorLayoutParams() {
|
||||||
|
v_split = false;
|
||||||
|
h_split = false;
|
||||||
|
v_split_pos = 0;
|
||||||
|
h_split_pos = 0;
|
||||||
|
}
|
||||||
|
} EditorLayoutParams;
|
||||||
|
|
||||||
|
absl::Status DrawEditor(EditorLayoutParams *params);
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif // YAZE_APP_CORE_EDITOR_H
|
#endif // YAZE_APP_CORE_EDITOR_H
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "app/emu/emulator.h"
|
#include "app/emu/emulator.h"
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "imgui/imgui.h"
|
|
||||||
#include "yaze.h"
|
#include "yaze.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -57,6 +56,7 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
active_editors_.push_back(&palette_editor_);
|
active_editors_.push_back(&palette_editor_);
|
||||||
active_editors_.push_back(&sprite_editor_);
|
active_editors_.push_back(&sprite_editor_);
|
||||||
active_editors_.push_back(&message_editor_);
|
active_editors_.push_back(&message_editor_);
|
||||||
|
active_editors_.push_back(&screen_editor_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupScreen(std::string filename = "");
|
void SetupScreen(std::string filename = "");
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "gfx_group_editor.h"
|
#include "gfx_group_editor.h"
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
|
|||||||
@@ -1,20 +1,10 @@
|
|||||||
#ifndef YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
#ifndef YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
||||||
#define YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
#define YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
|
||||||
#include "app/editor/utils/editor.h"
|
|
||||||
#include "app/gfx/bitmap.h"
|
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/gui/icons.h"
|
|
||||||
#include "app/gui/style.h"
|
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "app/zelda3/overworld/overworld.h"
|
|
||||||
#include "imgui/imgui.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
@@ -55,4 +45,4 @@ class GfxGroupEditor : public SharedRom {
|
|||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
#endif // YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
#endif // YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/graphics/palette_editor.h"
|
#include "app/editor/graphics/palette_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "app/gui/modules/asset_browser.h"
|
#include "app/gui/modules/asset_browser.h"
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
#ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H
|
#ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H
|
||||||
#define YAZE_APP_EDITOR_PALETTE_EDITOR_H
|
#define YAZE_APP_EDITOR_PALETTE_EDITOR_H
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/graphics/gfx_group_editor.h"
|
#include "app/editor/graphics/gfx_group_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gfx/snes_color.h"
|
||||||
#include "app/gui/icons.h"
|
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
@@ -120,4 +123,4 @@ class PaletteEditor : public SharedRom, public Editor {
|
|||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/tilesheet.h"
|
#include "app/gfx/tilesheet.h"
|
||||||
@@ -33,7 +33,7 @@ namespace editor {
|
|||||||
* The class inherits from the SharedRom class.
|
* The class inherits from the SharedRom class.
|
||||||
*/
|
*/
|
||||||
class ScreenEditor : public SharedRom, public Editor {
|
class ScreenEditor : public SharedRom, public Editor {
|
||||||
public:
|
public:
|
||||||
ScreenEditor() {
|
ScreenEditor() {
|
||||||
screen_canvas_.SetCanvasSize(ImVec2(512, 512));
|
screen_canvas_.SetCanvasSize(ImVec2(512, 512));
|
||||||
type_ = EditorType::kScreen;
|
type_ = EditorType::kScreen;
|
||||||
@@ -50,7 +50,7 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
|
|
||||||
absl::Status SaveDungeonMaps();
|
absl::Status SaveDungeonMaps();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawTitleScreenEditor();
|
void DrawTitleScreenEditor();
|
||||||
void DrawNamingScreenEditor();
|
void DrawNamingScreenEditor();
|
||||||
void DrawOverworldMapEditor();
|
void DrawOverworldMapEditor();
|
||||||
@@ -60,7 +60,7 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
void DrawInventoryToolset();
|
void DrawInventoryToolset();
|
||||||
|
|
||||||
absl::Status LoadDungeonMaps();
|
absl::Status LoadDungeonMaps();
|
||||||
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t>& gfx_data,
|
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t> &gfx_data,
|
||||||
bool bin_mode = false);
|
bool bin_mode = false);
|
||||||
absl::Status SaveDungeonMapTile16();
|
absl::Status SaveDungeonMapTile16();
|
||||||
void DrawDungeonMapsTabs();
|
void DrawDungeonMapsTabs();
|
||||||
@@ -68,6 +68,10 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
|
|
||||||
void LoadBinaryGfx();
|
void LoadBinaryGfx();
|
||||||
|
|
||||||
|
enum class EditingMode { DRAW, EDIT };
|
||||||
|
|
||||||
|
EditingMode current_mode_ = EditingMode::DRAW;
|
||||||
|
|
||||||
bool dungeon_maps_loaded_ = false;
|
bool dungeon_maps_loaded_ = false;
|
||||||
bool binary_gfx_loaded_ = false;
|
bool binary_gfx_loaded_ = false;
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
uint8_t boss_room = 0;
|
uint8_t boss_room = 0;
|
||||||
|
|
||||||
int selected_tile16_ = 0;
|
int selected_tile16_ = 0;
|
||||||
|
int selected_tile8_ = 0;
|
||||||
int selected_dungeon = 0;
|
int selected_dungeon = 0;
|
||||||
int floor_number = 1;
|
int floor_number = 1;
|
||||||
|
|
||||||
@@ -98,13 +103,15 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
gui::Canvas current_tile_canvas_{"##CurrentTileCanvas"};
|
gui::Canvas current_tile_canvas_{"##CurrentTileCanvas"};
|
||||||
gui::Canvas screen_canvas_;
|
gui::Canvas screen_canvas_;
|
||||||
gui::Canvas tilesheet_canvas_;
|
gui::Canvas tilesheet_canvas_;
|
||||||
gui::Canvas tilemap_canvas_;
|
gui::Canvas tilemap_canvas_{"##TilemapCanvas",
|
||||||
|
ImVec2(128 + 2, (192) + 4),
|
||||||
|
gui::CanvasGridSize::k8x8, 2.f};
|
||||||
|
|
||||||
zelda3::screen::Inventory inventory_;
|
zelda3::screen::Inventory inventory_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "app/core/platform/renderer.h"
|
#include "app/core/platform/renderer.h"
|
||||||
#include "app/editor/graphics/palette_editor.h"
|
#include "app/editor/graphics/palette_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/message/message_data.h"
|
#include "app/editor/message/message_data.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "app/editor/code/assembly_editor.h"
|
#include "app/editor/code/assembly_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/gui/icons.h"
|
#include "app/gui/icons.h"
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "app/editor/graphics/palette_editor.h"
|
#include "app/editor/graphics/palette_editor.h"
|
||||||
#include "app/editor/graphics/tile16_editor.h"
|
#include "app/editor/graphics/tile16_editor.h"
|
||||||
#include "app/editor/overworld/entity.h"
|
#include "app/editor/overworld/entity.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/editor/utils/gfx_context.h"
|
#include "app/editor/utils/gfx_context.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/sprite/zsprite.h"
|
#include "app/editor/sprite/zsprite.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "app/editor/graphics/palette_editor.h"
|
#include "app/editor/graphics/palette_editor.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "app/core/platform/renderer.h"
|
#include "app/core/platform/renderer.h"
|
||||||
#include "app/editor/graphics/graphics_editor.h"
|
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gui/color.h"
|
#include "app/gui/color.h"
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
@@ -19,7 +18,6 @@ namespace gui {
|
|||||||
using core::Renderer;
|
using core::Renderer;
|
||||||
|
|
||||||
using ImGui::BeginMenu;
|
using ImGui::BeginMenu;
|
||||||
using ImGui::BeginPopup;
|
|
||||||
using ImGui::EndMenu;
|
using ImGui::EndMenu;
|
||||||
using ImGui::GetContentRegionAvail;
|
using ImGui::GetContentRegionAvail;
|
||||||
using ImGui::GetCursorScreenPos;
|
using ImGui::GetCursorScreenPos;
|
||||||
@@ -33,7 +31,6 @@ using ImGui::IsMouseDragging;
|
|||||||
using ImGui::MenuItem;
|
using ImGui::MenuItem;
|
||||||
using ImGui::OpenPopupOnItemClick;
|
using ImGui::OpenPopupOnItemClick;
|
||||||
using ImGui::Selectable;
|
using ImGui::Selectable;
|
||||||
using ImGui::Separator;
|
|
||||||
using ImGui::Text;
|
using ImGui::Text;
|
||||||
|
|
||||||
constexpr uint32_t kBlackColor = IM_COL32(0, 0, 0, 255);
|
constexpr uint32_t kBlackColor = IM_COL32(0, 0, 0, 255);
|
||||||
@@ -860,4 +857,4 @@ void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap,
|
|||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef YAZE_GUI_CANVAS_H
|
#ifndef YAZE_GUI_CANVAS_H
|
||||||
#define YAZE_GUI_CANVAS_H
|
#define YAZE_GUI_CANVAS_H
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
@@ -33,37 +32,46 @@ enum class CanvasGridSize { k8x8, k16x16, k32x32, k64x64 };
|
|||||||
* handling, tile painting, custom grid, and more.
|
* handling, tile painting, custom grid, and more.
|
||||||
*/
|
*/
|
||||||
class Canvas : public SharedRom {
|
class Canvas : public SharedRom {
|
||||||
public:
|
public:
|
||||||
Canvas() = default;
|
Canvas() = default;
|
||||||
explicit Canvas(const std::string& id) : canvas_id_(id) {
|
explicit Canvas(const std::string &id) : canvas_id_(id) {
|
||||||
context_id_ = id + "Context";
|
context_id_ = id + "Context";
|
||||||
}
|
}
|
||||||
explicit Canvas(const std::string& id, ImVec2 canvas_size)
|
explicit Canvas(const std::string &id, ImVec2 canvas_size)
|
||||||
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
||||||
context_id_ = id + "Context";
|
context_id_ = id + "Context";
|
||||||
}
|
}
|
||||||
explicit Canvas(const std::string& id, ImVec2 canvas_size,
|
explicit Canvas(const std::string &id, ImVec2 canvas_size,
|
||||||
CanvasGridSize grid_size)
|
CanvasGridSize grid_size)
|
||||||
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
|
||||||
context_id_ = id + "Context";
|
context_id_ = id + "Context";
|
||||||
|
SetCanvasGridSize(grid_size);
|
||||||
|
}
|
||||||
|
explicit Canvas(const std::string &id, ImVec2 canvas_size, CanvasGridSize grid_size, float global_scale)
|
||||||
|
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size), global_scale_(global_scale) {
|
||||||
|
context_id_ = id + "Context";
|
||||||
|
SetCanvasGridSize(grid_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCanvasGridSize(CanvasGridSize grid_size) {
|
||||||
switch (grid_size) {
|
switch (grid_size) {
|
||||||
case CanvasGridSize::k8x8:
|
case CanvasGridSize::k8x8:
|
||||||
custom_step_ = 8.0f;
|
custom_step_ = 8.0f;
|
||||||
break;
|
break;
|
||||||
case CanvasGridSize::k16x16:
|
case CanvasGridSize::k16x16:
|
||||||
custom_step_ = 16.0f;
|
custom_step_ = 16.0f;
|
||||||
break;
|
break;
|
||||||
case CanvasGridSize::k32x32:
|
case CanvasGridSize::k32x32:
|
||||||
custom_step_ = 32.0f;
|
custom_step_ = 32.0f;
|
||||||
break;
|
break;
|
||||||
case CanvasGridSize::k64x64:
|
case CanvasGridSize::k64x64:
|
||||||
custom_step_ = 64.0f;
|
custom_step_ = 64.0f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateColorPainter(gfx::Bitmap& bitmap, const ImVec4& color,
|
void UpdateColorPainter(gfx::Bitmap &bitmap, const ImVec4 &color,
|
||||||
const std::function<void()>& event, int tile_size,
|
const std::function<void()> &event, int tile_size,
|
||||||
float scale = 1.0f);
|
float scale = 1.0f);
|
||||||
|
|
||||||
void UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale = 1.0f,
|
void UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale = 1.0f,
|
||||||
@@ -75,16 +83,16 @@ class Canvas : public SharedRom {
|
|||||||
|
|
||||||
// Context Menu refers to what happens when the right mouse button is pressed
|
// Context Menu refers to what happens when the right mouse button is pressed
|
||||||
// This routine also handles the scrolling for the canvas.
|
// This routine also handles the scrolling for the canvas.
|
||||||
void DrawContextMenu(gfx::Bitmap* bitmap = nullptr);
|
void DrawContextMenu(gfx::Bitmap *bitmap = nullptr);
|
||||||
|
|
||||||
// Tile painter shows a preview of the currently selected tile
|
// Tile painter shows a preview of the currently selected tile
|
||||||
// and allows the user to left click to paint the tile or right
|
// and allows the user to left click to paint the tile or right
|
||||||
// click to select a new tile to paint with.
|
// click to select a new tile to paint with.
|
||||||
bool DrawTilePainter(const Bitmap& bitmap, int size, float scale = 1.0f);
|
bool DrawTilePainter(const Bitmap &bitmap, int size, float scale = 1.0f);
|
||||||
bool DrawSolidTilePainter(const ImVec4& color, int size);
|
bool DrawSolidTilePainter(const ImVec4 &color, int size);
|
||||||
|
|
||||||
// Draws a tile on the canvas at the specified position
|
// Draws a tile on the canvas at the specified position
|
||||||
void DrawTileOnBitmap(int tile_size, gfx::Bitmap* bitmap, ImVec4 color);
|
void DrawTileOnBitmap(int tile_size, gfx::Bitmap *bitmap, ImVec4 color);
|
||||||
|
|
||||||
// Dictates which tile is currently selected based on what the user clicks
|
// Dictates which tile is currently selected based on what the user clicks
|
||||||
// in the canvas window. Represented and split apart into a grid of tiles.
|
// in the canvas window. Represented and split apart into a grid of tiles.
|
||||||
@@ -95,15 +103,15 @@ class Canvas : public SharedRom {
|
|||||||
float scale = 1.0f);
|
float scale = 1.0f);
|
||||||
|
|
||||||
// Draws the contents of the Bitmap image to the Canvas
|
// Draws the contents of the Bitmap image to the Canvas
|
||||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
|
void DrawBitmap(const Bitmap &bitmap, int border_offset = 0,
|
||||||
bool ready = true);
|
bool ready = true);
|
||||||
void DrawBitmap(const Bitmap& bitmap, int border_offset, float scale);
|
void DrawBitmap(const Bitmap &bitmap, int border_offset, float scale);
|
||||||
void DrawBitmap(const Bitmap& bitmap, int x_offset = 0, int y_offset = 0,
|
void DrawBitmap(const Bitmap &bitmap, int x_offset = 0, int y_offset = 0,
|
||||||
float scale = 1.0f, int alpha = 255);
|
float scale = 1.0f, int alpha = 255);
|
||||||
void DrawBitmapTable(const BitmapTable& gfx_bin);
|
void DrawBitmapTable(const BitmapTable &gfx_bin);
|
||||||
|
|
||||||
void DrawBitmapGroup(std::vector<int>& group,
|
void DrawBitmapGroup(std::vector<int> &group,
|
||||||
std::vector<gfx::Bitmap>& tile16_individual_,
|
std::vector<gfx::Bitmap> &tile16_individual_,
|
||||||
int tile_size, float scale = 1.0f);
|
int tile_size, float scale = 1.0f);
|
||||||
|
|
||||||
void DrawOutline(int x, int y, int w, int h);
|
void DrawOutline(int x, int y, int w, int h);
|
||||||
@@ -115,7 +123,7 @@ class Canvas : public SharedRom {
|
|||||||
void DrawText(std::string text, int x, int y);
|
void DrawText(std::string text, int x, int y);
|
||||||
void DrawGridLines(float grid_step);
|
void DrawGridLines(float grid_step);
|
||||||
void DrawGrid(float grid_step = 64.0f, int tile_id_offset = 8);
|
void DrawGrid(float grid_step = 64.0f, int tile_id_offset = 8);
|
||||||
void DrawOverlay(); // last
|
void DrawOverlay(); // last
|
||||||
|
|
||||||
void DrawInfoGrid(float grid_step = 64.0f, int tile_id_offset = 8,
|
void DrawInfoGrid(float grid_step = 64.0f, int tile_id_offset = 8,
|
||||||
int label_id = 0);
|
int label_id = 0);
|
||||||
@@ -125,11 +133,11 @@ class Canvas : public SharedRom {
|
|||||||
int GetTileIdFromMousePos() {
|
int GetTileIdFromMousePos() {
|
||||||
int x = mouse_pos_in_canvas_.x;
|
int x = mouse_pos_in_canvas_.x;
|
||||||
int y = mouse_pos_in_canvas_.y;
|
int y = mouse_pos_in_canvas_.y;
|
||||||
int num_columns = canvas_sz_.x / custom_step_;
|
int num_columns = (canvas_sz_.x / global_scale_) / custom_step_;
|
||||||
int num_rows = canvas_sz_.y / custom_step_;
|
int num_rows = (canvas_sz_.y / global_scale_) / custom_step_;
|
||||||
int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns;
|
int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns;
|
||||||
if (tile_id >= num_columns * num_rows) {
|
if (tile_id >= num_columns * num_rows) {
|
||||||
tile_id = -1; // Invalid tile ID
|
tile_id = -1; // Invalid tile ID
|
||||||
}
|
}
|
||||||
return tile_id;
|
return tile_id;
|
||||||
}
|
}
|
||||||
@@ -189,7 +197,7 @@ class Canvas : public SharedRom {
|
|||||||
|
|
||||||
auto hover_mouse_pos() const { return mouse_pos_in_canvas_; }
|
auto hover_mouse_pos() const { return mouse_pos_in_canvas_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool draggable_ = false;
|
bool draggable_ = false;
|
||||||
bool is_hovered_ = false;
|
bool is_hovered_ = false;
|
||||||
bool enable_grid_ = true;
|
bool enable_grid_ = true;
|
||||||
@@ -213,7 +221,7 @@ class Canvas : public SharedRom {
|
|||||||
std::string canvas_id_ = "Canvas";
|
std::string canvas_id_ = "Canvas";
|
||||||
std::string context_id_ = "CanvasContext";
|
std::string context_id_ = "CanvasContext";
|
||||||
|
|
||||||
ImDrawList* draw_list_;
|
ImDrawList *draw_list_;
|
||||||
ImVector<ImVec2> points_;
|
ImVector<ImVec2> points_;
|
||||||
ImVector<ImVector<std::string>> labels_;
|
ImVector<ImVector<std::string>> labels_;
|
||||||
ImVec2 scrolling_;
|
ImVec2 scrolling_;
|
||||||
@@ -229,14 +237,14 @@ class Canvas : public SharedRom {
|
|||||||
|
|
||||||
void GraphicsBinCanvasPipeline(int width, int height, int tile_size,
|
void GraphicsBinCanvasPipeline(int width, int height, int tile_size,
|
||||||
int num_sheets_to_load, int canvas_id,
|
int num_sheets_to_load, int canvas_id,
|
||||||
bool is_loaded, BitmapTable& graphics_bin);
|
bool is_loaded, BitmapTable &graphics_bin);
|
||||||
|
|
||||||
void BitmapCanvasPipeline(gui::Canvas& canvas, const gfx::Bitmap& bitmap,
|
void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap,
|
||||||
int width, int height, int tile_size, bool is_loaded,
|
int width, int height, int tile_size, bool is_loaded,
|
||||||
bool scrollbar, int canvas_id);
|
bool scrollbar, int canvas_id);
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user