cleanup canvas

This commit is contained in:
scawful
2024-08-06 19:24:24 -04:00
parent 7e5b3858f4
commit af29ef3fb7

View File

@@ -1,7 +1,5 @@
#include "canvas.h" #include "canvas.h"
#include "imgui/imgui.h"
#include <cmath> #include <cmath>
#include <string> #include <string>
@@ -11,6 +9,7 @@
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/gui/style.h" #include "app/gui/style.h"
#include "app/rom.h" #include "app/rom.h"
#include "imgui/imgui.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -98,8 +97,8 @@ void Canvas::DrawBackground(ImVec2 canvas_size, bool can_drag) {
void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) { void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
const ImGuiIO &io = GetIO(); const ImGuiIO &io = GetIO();
auto scaled_sz = const ImVec2 scaled_sz(canvas_sz_.x * global_scale_,
ImVec2(canvas_sz_.x * global_scale_, canvas_sz_.y * global_scale_); canvas_sz_.y * global_scale_);
const ImVec2 origin(canvas_p0_.x + scrolling_.x, const ImVec2 origin(canvas_p0_.x + scrolling_.x,
canvas_p0_.y + scrolling_.y); // Lock scrolled origin canvas_p0_.y + scrolling_.y); // Lock scrolled origin
const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y); const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
@@ -126,31 +125,26 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
if (bitmap != nullptr) { if (bitmap != nullptr) {
if (BeginMenu("Bitmap Properties")) { if (BeginMenu("Bitmap Properties")) {
Text("Size: %.0f x %.0f", scaled_sz.x, scaled_sz.y); Text("Size: %.0f x %.0f", scaled_sz.x, scaled_sz.y);
Text("Pitch: %s", Text("Pitch: %d", bitmap->surface()->pitch);
absl::StrFormat("%d", bitmap->surface()->pitch).c_str());
Text("BitsPerPixel: %d", bitmap->surface()->format->BitsPerPixel); Text("BitsPerPixel: %d", bitmap->surface()->format->BitsPerPixel);
Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel); Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel);
EndMenu(); EndMenu();
} }
if (BeginMenu("Bitmap Format")) { if (BeginMenu("Bitmap Format")) {
if (MenuItem("Indexed")) { if (MenuItem("Indexed")) {
bitmap->Reformat(0); bitmap->Reformat(gfx::BitmapFormat::kIndexed);
bitmap->ApplyPalette(bitmap->palette());
rom()->UpdateBitmap(bitmap); rom()->UpdateBitmap(bitmap);
} }
if (MenuItem("2BPP")) { if (MenuItem("2BPP")) {
bitmap->Reformat(1); bitmap->Reformat(gfx::BitmapFormat::k2bpp);
bitmap->ApplyPalette(bitmap->palette());
rom()->UpdateBitmap(bitmap); rom()->UpdateBitmap(bitmap);
} }
if (MenuItem("4BPP")) { if (MenuItem("4BPP")) {
bitmap->Reformat(2); bitmap->Reformat(gfx::BitmapFormat::k4bpp);
bitmap->ApplyPalette(bitmap->palette());
rom()->UpdateBitmap(bitmap); rom()->UpdateBitmap(bitmap);
} }
if (MenuItem("8BPP")) { if (MenuItem("8BPP")) {
bitmap->Reformat(3); bitmap->Reformat(gfx::BitmapFormat::k8bpp);
bitmap->ApplyPalette(bitmap->palette());
rom()->UpdateBitmap(bitmap); rom()->UpdateBitmap(bitmap);
} }
EndMenu(); EndMenu();