housekeeping style format etc

This commit is contained in:
scawful
2022-06-09 18:28:50 -04:00
parent 6f95d72d81
commit 3a4b532979
5 changed files with 346 additions and 312 deletions

View File

@@ -41,8 +41,8 @@ char* ALTTPCompression::DecompressGfx(const char* c_data,
unsigned int max_length,
unsigned int* uncompressed_data_size,
unsigned int* compressed_length) {
char* toret =
std_nintendo_.Decompress(c_data, start, max_length, uncompressed_data_size,
char* toret = std_nintendo_.Decompress(c_data, start, max_length,
uncompressed_data_size,
compressed_length, D_NINTENDO_C_MODE2);
return toret;
}
@@ -50,8 +50,8 @@ char* ALTTPCompression::DecompressGfx(const char* c_data,
char* ALTTPCompression::DecompressOverworld(
const char* c_data, const unsigned int start, unsigned int max_length,
unsigned int* uncompressed_data_size, unsigned int* compressed_length) {
char* toret =
std_nintendo_.Decompress(c_data, start, max_length, uncompressed_data_size,
char* toret = std_nintendo_.Decompress(c_data, start, max_length,
uncompressed_data_size,
compressed_length, D_NINTENDO_C_MODE1);
return toret;
}
@@ -79,10 +79,12 @@ char* ALTTPCompression::CompressOverworld(const char* u_data,
* Then you have a new header byte and so on, until you hit a header with the
* value FF
*/
char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int start,
char* StdNintendoCompression::Decompress(const char* c_data,
const unsigned int start,
unsigned int max_length,
unsigned int* uncompressed_data_size,
unsigned int* compressed_length, char mode) {
unsigned int* compressed_length,
char mode) {
char* u_data;
unsigned char header;
unsigned int c_data_pos;
@@ -91,16 +93,16 @@ char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int
unsigned int max_offset;
max_offset = 0;
if (max_length != 0)
max_offset = start + max_length;
if (max_length != 0) max_offset = start + max_length;
header = c_data[start];
u_data = (char *) malloc(INITIAL_ALLOC_SIZE); // No way to know the final size, we will probably realloc if needed
u_data =
(char*)malloc(INITIAL_ALLOC_SIZE); // No way to know the final size, we
// will probably realloc if needed
allocated_memory = INITIAL_ALLOC_SIZE;
u_data_pos = 0;
c_data_pos = start;
while (header != 0xFF)
{
while (header != 0xFF) {
unsigned int length;
char command;
@@ -108,45 +110,46 @@ char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int
length = (header & 0x1F); // The rest is the length
// Extended header, to allow for bigger length value than 32
if (command == 7)
{
if (command == 7) {
// The command are the next 3 bits
command = (header >> 2) & 7;
// 2 bits in the original header are the hight bit for the new length
// the next byte is added to this length
length = ((int)((header & 3) << 8)) + (unsigned char) c_data[c_data_pos + 1];
length =
((int)((header & 3) << 8)) + (unsigned char)c_data[c_data_pos + 1];
c_data_pos++;
}
// length value starts at 0, 0 is 1
length++;
printf("%d[%d]", command, length);
printf("header %02X - Command : %d , length : %d\n", header, command, length);
if (c_data_pos >= max_offset && max_offset != 0)
{
decompression_error_ = "Compression string exceed the max_length specified";
printf("header %02X - Command : %d , length : %d\n", header, command,
length);
if (c_data_pos >= max_offset && max_offset != 0) {
decompression_error_ =
"Compression string exceed the max_length specified";
goto error;
}
if (u_data_pos + length + 1 > allocated_memory) // Adjust allocated memory
{
printf("Memory get reallocated by %d was %d\n", INITIAL_ALLOC_SIZE, allocated_memory);
printf("Memory get reallocated by %d was %d\n", INITIAL_ALLOC_SIZE,
allocated_memory);
u_data = (char*)realloc(u_data, allocated_memory + INITIAL_ALLOC_SIZE);
if (u_data == NULL)
{
if (u_data == NULL) {
decompression_error_ = "Can't realloc memory";
return NULL;
}
allocated_memory += INITIAL_ALLOC_SIZE;
}
switch (command)
{
switch (command) {
case D_CMD_COPY: { // No compression, data are copied as
if (max_offset != 0 && c_data_pos + 1 + length > max_offset)
{
//decompression_error_ = vasprintf("A copy command exceed the available data %d > %d (max_length specified)\n", c_data_pos + 1 + length, max_offset);
if (max_offset != 0 && c_data_pos + 1 + length > max_offset) {
// decompression_error_ = vasprintf("A copy command exceed the
// available data %d > %d (max_length specified)\n", c_data_pos + 1 +
// length, max_offset);
goto error;
}
memcpy(u_data + u_data_pos, c_data + c_data_pos + 1, length);
@@ -158,14 +161,13 @@ char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int
c_data_pos += 2;
break;
}
case D_CMD_WORD_REPEAT: { // Next byte is A, the one after is B, copy the sequence AB length times
case D_CMD_WORD_REPEAT: { // Next byte is A, the one after is B, copy the
// sequence AB length times
char a = c_data[c_data_pos + 1];
char b = c_data[c_data_pos + 2];
for (int i = 0; i < length; i = i + 2)
{
for (int i = 0; i < length; i = i + 2) {
u_data[u_data_pos + i] = a;
if ((i + 1) < length)
u_data[u_data_pos + i + 1] = b;
if ((i + 1) < length) u_data[u_data_pos + i + 1] = b;
}
c_data_pos += 3;
break;
@@ -177,24 +179,30 @@ char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int
c_data_pos += 2;
break;
}
case D_CMD_COPY_EXISTING: { // Next 2 bytes form an offset to pick data from the output
//printf("%02X,%02X\n", (unsigned char) c_data[c_data_pos + 1], (unsigned char) c_data[c_data_pos + 2]);
case D_CMD_COPY_EXISTING: { // Next 2 bytes form an offset to pick data
// from the output
// printf("%02X,%02X\n", (unsigned char) c_data[c_data_pos + 1],
// (unsigned char) c_data[c_data_pos + 2]);
unsigned short offset;
if (mode == D_NINTENDO_C_MODE2)
offset = (unsigned char)(c_data[c_data_pos + 1]) | ((unsigned char) (c_data[c_data_pos + 2]) << 8);
offset = (unsigned char)(c_data[c_data_pos + 1]) |
((unsigned char)(c_data[c_data_pos + 2]) << 8);
if (mode == D_NINTENDO_C_MODE1)
offset = (unsigned char)(c_data[c_data_pos + 2]) | ((unsigned char) (c_data[c_data_pos + 1]) << 8);
if (offset > u_data_pos)
{
printf("Offset for command copy existing is larger than the current position (Offset : 0x%04X | Pos : 0x%06X\n", offset, u_data_pos);
offset = (unsigned char)(c_data[c_data_pos + 2]) |
((unsigned char)(c_data[c_data_pos + 1]) << 8);
if (offset > u_data_pos) {
printf(
"Offset for command copy existing is larger than the current "
"position (Offset : 0x%04X | Pos : 0x%06X\n",
offset, u_data_pos);
goto error;
}
if (u_data_pos + length >= allocated_memory)
{
printf("Memory get reallocated by a copy, %d was %d\n", INITIAL_ALLOC_SIZE, allocated_memory);
u_data = (char*) realloc(u_data, allocated_memory + INITIAL_ALLOC_SIZE);
if (u_data == NULL)
{
if (u_data_pos + length >= allocated_memory) {
printf("Memory get reallocated by a copy, %d was %d\n",
INITIAL_ALLOC_SIZE, allocated_memory);
u_data =
(char*)realloc(u_data, allocated_memory + INITIAL_ALLOC_SIZE);
if (u_data == NULL) {
decompression_error_ = "Can't realloc memory";
return NULL;
}
@@ -205,7 +213,8 @@ char* StdNintendoCompression::Decompress(const char* c_data, const unsigned int
break;
}
default: {
decompression_error_ = "Invalid command in the header for decompression";
decompression_error_ =
"Invalid command in the header for decompression";
goto error;
}
}
@@ -223,7 +232,6 @@ error:
return NULL;
}
void StdNintendoCompression::PrintComponent(CompressionComponent* piece) {
printf("Command : %d\n", piece->command);
printf("length : %d\n", piece->length);
@@ -240,7 +248,8 @@ void StdNintendoCompression::PrintComponent(CompressionComponent * piece) {
printf("Argument :%s\n", toret);
}
StdNintendoCompression::CompressionComponent* StdNintendoCompression::CreateComponent(const char command,
StdNintendoCompression::CompressionComponent*
StdNintendoCompression::CreateComponent(const char command,
const unsigned int length,
const char* args,
const unsigned int argument_length) {
@@ -272,7 +281,8 @@ void StdNintendoCompression::DestroyChain(CompressionComponent* piece) {
}
// Merge consecutive copy if possible
StdNintendoCompression::CompressionComponent* StdNintendoCompression::merge_copy(CompressionComponent* start) {
StdNintendoCompression::CompressionComponent*
StdNintendoCompression::merge_copy(CompressionComponent* start) {
CompressionComponent* piece = start;
while (piece != NULL) {
@@ -298,8 +308,8 @@ StdNintendoCompression::CompressionComponent* StdNintendoCompression::merge_copy
return start;
}
unsigned int StdNintendoCompression::create_compression_string(CompressionComponent* start, char* output,
char mode) {
unsigned int StdNintendoCompression::create_compression_string(
CompressionComponent* start, char* output, char mode) {
unsigned int pos = 0;
CompressionComponent* piece = start;
@@ -320,28 +330,25 @@ unsigned int StdNintendoCompression::create_compression_string(CompressionCompon
CompressionComponent* new_piece = NULL;
if (piece->command == D_CMD_BYTE_REPEAT ||
piece->command == D_CMD_WORD_REPEAT) {
new_piece =
CreateComponent(piece->command, length_left,
new_piece = CreateComponent(piece->command, length_left,
piece->argument, piece->argument_length);
}
if (piece->command == D_CMD_BYTE_INC) {
new_piece =
CreateComponent(piece->command, length_left,
new_piece = CreateComponent(piece->command, length_left,
piece->argument, piece->argument_length);
new_piece->argument[0] = (char)(piece->argument[0] + D_max_length);
}
if (piece->command == D_CMD_COPY) {
piece->argument_length = D_max_length;
new_piece = CreateComponent(piece->command, length_left, NULL,
length_left);
new_piece =
CreateComponent(piece->command, length_left, NULL, length_left);
memcpy(new_piece->argument, piece->argument + D_max_length,
length_left);
}
if (piece->command == D_CMD_COPY_EXISTING) {
piece->argument_length = D_max_length;
unsigned int offset = piece->argument[0] + (piece->argument[1] << 8);
new_piece =
CreateComponent(piece->command, length_left,
new_piece = CreateComponent(piece->command, length_left,
piece->argument, piece->argument_length);
if (mode == D_NINTENDO_C_MODE2) {
new_piece->argument[0] = (offset + D_max_length) & 0xFF;
@@ -382,7 +389,11 @@ unsigned int StdNintendoCompression::create_compression_string(CompressionCompon
// TODO TEST compressed data border for each cmd
char* StdNintendoCompression::Compress(const char* u_data, const unsigned int start, const unsigned int length, unsigned int* compressed_size, char mode) {
char* StdNintendoCompression::Compress(const char* u_data,
const unsigned int start,
const unsigned int length,
unsigned int* compressed_size,
char mode) {
// we will realloc later
char* compressed_data = (char*)malloc(
length +
@@ -518,8 +529,8 @@ char* StdNintendoCompression::Compress(const char* u_data, const unsigned int st
memcpy(buffer, u_data + u_data_pos - bytes_since_last_compression,
bytes_since_last_compression);
CompressionComponent* new_comp_piece =
CreateComponent(D_CMD_COPY, bytes_since_last_compression,
buffer, bytes_since_last_compression);
CreateComponent(D_CMD_COPY, bytes_since_last_compression, buffer,
bytes_since_last_compression);
compressed_chain->next = new_comp_piece;
compressed_chain = new_comp_piece;
bytes_since_last_compression = 0;
@@ -539,8 +550,8 @@ char* StdNintendoCompression::Compress(const char* u_data, const unsigned int st
memcpy(copy_buff, u_data + u_data_pos - bytes_since_last_compression,
bytes_since_last_compression);
CompressionComponent* copy_chuck =
CreateComponent(D_CMD_COPY, bytes_since_last_compression,
copy_buff, bytes_since_last_compression);
CreateComponent(D_CMD_COPY, bytes_since_last_compression, copy_buff,
bytes_since_last_compression);
compressed_chain->next = copy_chuck;
compressed_chain = copy_chuck;
}

View File

@@ -1,8 +1,8 @@
#ifndef YAZE_APPLICATION_UTILS_COMPRESSION_H
#define YAZE_APPLICATION_UTILS_COMPRESSION_H
#include <cstdlib>
#include <cstddef>
#include <cstdlib>
#include <string>
#include <vector>
@@ -42,8 +42,9 @@ class StdNintendoCompression {
*/
char* Compress(const char* u_data, const unsigned int start,
const unsigned int length,
unsigned int* compressed_size, char mode);
const unsigned int length, unsigned int* compressed_size,
char mode);
private:
std::string compression_error_;
std::string decompression_error_;
@@ -67,9 +68,8 @@ class StdNintendoCompression {
void DestroyComponent(CompressionComponent* piece);
void DestroyChain(CompressionComponent* piece);
CompressionComponent* merge_copy(CompressionComponent* start);
unsigned int create_compression_string(CompressionComponent* start, char* output,
char mode);
unsigned int create_compression_string(CompressionComponent* start,
char* output, char mode);
};
class ALTTPCompression {
@@ -125,7 +125,6 @@ class ALTTPCompression {
std::string decompression_error_;
};
} // namespace Utils
} // namespace Application
} // namespace yaze

View File

@@ -5,7 +5,6 @@ namespace Application {
namespace Utils {
void ROM::LoadFromFile(const std::string& path) {
std::cout << "filename: " << path << std::endl;
std::ifstream stream(path, std::ios::in | std::ios::binary);
@@ -14,7 +13,8 @@ void ROM::LoadFromFile(const std::string & path) {
return;
}
std::vector<char> contents((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
std::vector<char> contents((std::istreambuf_iterator<char>(stream)),
std::istreambuf_iterator<char>());
for (auto i : contents) {
int value = i;
@@ -25,10 +25,14 @@ void ROM::LoadFromFile(const std::string & path) {
unsigned int uncompressed_data_size = 0;
unsigned int compressed_length = 0;
auto gfx_decompressed_data = alttp_compressor_.DecompressGfx(contents.data(), 0, contents.size(), &uncompressed_data_size, &compressed_length);
auto overworld_decompressed = alttp_compressor_.DecompressOverworld(contents.data(), 0, contents.size(), &uncompressed_data_size, &compressed_length);
auto gfx_decompressed_data = alttp_compressor_.DecompressGfx(
contents.data(), 0, contents.size(), &uncompressed_data_size,
&compressed_length);
auto overworld_decompressed = alttp_compressor_.DecompressOverworld(
contents.data(), 0, contents.size(), &uncompressed_data_size,
&compressed_length);
}
}
}
}
} // namespace Utils
} // namespace Application
} // namespace yaze

View File

@@ -1,13 +1,14 @@
#ifndef YAZE_APPLICATION_UTILS_ROM_H
#define YAZE_APPLICATION_UTILS_ROM_H
#include <bits/postypes.h>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <bits/postypes.h>
#include <memory>
#include <iostream>
#include <fstream>
#include <cstddef>
#include "Compression.h"
#include "Core/Constants.h"
@@ -27,8 +28,8 @@ class ROM {
ALTTPCompression alttp_compressor_;
};
}
}
}
} // namespace Utils
} // namespace Application
} // namespace yaze
#endif

View File

@@ -53,13 +53,13 @@ void Editor::DrawYazeMenu() {
// close
ImGuiFileDialog::Instance()->Close();
}
}
void Editor::DrawFileMenu() const {
if (ImGui::MenuItem("Open", "Ctrl+O")) {
// TODO: Add the ability to open ALTTP ROM
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM", ".sfc,.smc", ".");
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM",
".sfc,.smc", ".");
}
if (ImGui::BeginMenu("Open Recent")) {
ImGui::MenuItem("alttp.sfc");
@@ -80,8 +80,7 @@ void Editor::DrawFileMenu() const {
static bool enabled = true;
ImGui::MenuItem("Enabled", "", &enabled);
ImGui::BeginChild("child", ImVec2(0, 60), true);
for (int i = 0; i < 10; i++)
ImGui::Text("Scrolling Text %d", i);
for (int i = 0; i < 10; i++) ImGui::Text("Scrolling Text %d", i);
ImGui::EndChild();
static float f = 0.5f;
static int n = 0;
@@ -92,7 +91,6 @@ void Editor::DrawFileMenu() const {
}
}
void Editor::DrawEditMenu() const {
if (ImGui::MenuItem("Undo", "Ctrl+O")) {
// TODO: Implement this
@@ -116,25 +114,26 @@ void Editor::DrawEditMenu() const {
}
}
// i would not recommend doing dungeon because each objects is drawn separately but you could start with OW
// first step would be to decompress all graphics data from the game (in alttp that's easy they're all located in the same location all the same sheet size 128x32)
// have a code that convert PC address to SNES and vice-versa
// first step would be to decompress all graphics data from the game
// (in alttp that's easy they're all located in the same location all the same
// sheet size 128x32) have a code that convert PC address to SNES and vice-versa
// 1) find the gfx pointers (you could use ZS constant file)
// 2) decompress all the gfx with your lz2 decompressor
// 3) convert the 3bpp snes data into PC 4bpp (probably the hardest part)
// 4) get the tiles32 data
// 5) get the tiles16 data
// 6) get the map32 data (they must be decompressed as well with a lz2 variant not the same as gfx compression but pretty similar)
// 7) get the gfx data of the map yeah i forgot that one and load 4bpp in a pseudo vram and use that to render tiles on screen
// 6) get the map32 data (they must be decompressed as well with a lz2 variant
// not the same as gfx compression but pretty similar)
// 7) get the gfx data of the map
// yeah i forgot that one and load 4bpp in a pseudo vram and use that to
// render tiles on screen
// 8) try to render the tiles on the bitmap in black & white to start
// 9) get the palettes data and try to find how they're loaded in the game that's a big puzzle to solve
// then 9 you'll have an overworld map viewer, in less than few hours if are able to understand the data quickly
void Editor::DrawOverworldEditor()
{
if (ImGui::BeginTabItem("Overworld"))
{
// 9) get the palettes data and try to find how they're loaded in
// the game that's a big puzzle to solve then 9 you'll have an overworld map
// viewer, in less than few hours if are able to understand the data quickly
void Editor::DrawOverworldEditor() {
if (ImGui::BeginTabItem("Overworld")) {
static ImVector<ImVec2> points;
static ImVec2 scrolling(0.0f, 0.0f);
static bool opt_enable_grid = true;
@@ -143,13 +142,18 @@ void Editor::DrawOverworldEditor()
ImGui::Checkbox("Enable grid", &opt_enable_grid);
ImGui::Checkbox("Enable context menu", &opt_enable_context_menu);
ImGui::Text("Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click for context menu.");
ImGui::Text(
"Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click "
"for context menu.");
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
ImVec2 canvas_p0 =
ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
ImVec2 canvas_sz =
ImGui::GetContentRegionAvail(); // Resize canvas to what's available
if (canvas_sz.x < 50.0f) canvas_sz.x = 50.0f;
if (canvas_sz.y < 50.0f) canvas_sz.y = 50.0f;
ImVec2 canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
ImVec2 canvas_p1 =
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
// Draw border and background color
const ImGuiIO& io = ImGui::GetIO();
@@ -158,31 +162,35 @@ void Editor::DrawOverworldEditor()
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
// This will catch our interactions
ImGui::InvisibleButton("canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
ImGui::InvisibleButton(
"canvas", canvas_sz,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
const bool is_active = ImGui::IsItemActive(); // Held
const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
const ImVec2 origin(canvas_p0.x + scrolling.x,
canvas_p0.y + scrolling.y); // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
io.MousePos.y - origin.y);
// Add first and second point
if (is_hovered && !adding_line && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
{
if (is_hovered && !adding_line &&
ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
points.push_back(mouse_pos_in_canvas);
points.push_back(mouse_pos_in_canvas);
adding_line = true;
}
if (adding_line)
{
if (adding_line) {
points.back() = mouse_pos_in_canvas;
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left))
adding_line = false;
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) adding_line = false;
}
// Pan (we use a zero mouse threshold when there's no context menu)
// You may decide to make that threshold dynamic based on whether the mouse is hovering something etc.
const float mouse_threshold_for_pan = opt_enable_context_menu ? -1.0f : 0.0f;
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan))
{
// You may decide to make that threshold dynamic based on whether the mouse
// is hovering something etc.
const float mouse_threshold_for_pan =
opt_enable_context_menu ? -1.0f : 0.0f;
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right,
mouse_threshold_for_pan)) {
scrolling.x += io.MouseDelta.x;
scrolling.y += io.MouseDelta.y;
}
@@ -191,35 +199,46 @@ void Editor::DrawOverworldEditor()
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
if (opt_enable_context_menu && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
if (ImGui::BeginPopup("context"))
{
if (adding_line)
points.resize(points.size() - 2);
if (ImGui::BeginPopup("context")) {
if (adding_line) points.resize(points.size() - 2);
adding_line = false;
if (ImGui::MenuItem("Remove one", NULL, false, points.Size > 0)) { points.resize(points.size() - 2); }
if (ImGui::MenuItem("Remove all", NULL, false, points.Size > 0)) { points.clear(); }
if (ImGui::MenuItem("Remove one", NULL, false, points.Size > 0)) {
points.resize(points.size() - 2);
}
if (ImGui::MenuItem("Remove all", NULL, false, points.Size > 0)) {
points.clear();
}
ImGui::EndPopup();
}
// Draw grid + all lines in the canvas
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
if (opt_enable_grid)
{
if (opt_enable_grid) {
const float GRID_STEP = 64.0f;
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x; x += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y), ImVec2(canvas_p0.x + x, canvas_p1.y), IM_COL32(200, 200, 200, 40));
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y; y += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y), ImVec2(canvas_p1.x, canvas_p0.y + y), IM_COL32(200, 200, 200, 40));
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x;
x += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y),
ImVec2(canvas_p0.x + x, canvas_p1.y),
IM_COL32(200, 200, 200, 40));
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y;
y += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y),
ImVec2(canvas_p1.x, canvas_p0.y + y),
IM_COL32(200, 200, 200, 40));
}
for (int n = 0; n < points.Size; n += 2)
draw_list->AddLine(ImVec2(origin.x + points[n].x, origin.y + points[n].y), ImVec2(origin.x + points[n + 1].x, origin.y + points[n + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
draw_list->AddLine(
ImVec2(origin.x + points[n].x, origin.y + points[n].y),
ImVec2(origin.x + points[n + 1].x, origin.y + points[n + 1].y),
IM_COL32(255, 255, 0, 255), 2.0f);
draw_list->PopClipRect();
ImGui::EndTabItem();
}
}
} // namespace View
} // namespace Application
} // namespace yaze