Update GraphicsEditor, fix CommandHandler

This commit is contained in:
scawful
2023-11-26 23:12:04 -05:00
parent 620fc934ba
commit 0bf45c86a9
11 changed files with 224 additions and 47 deletions

View File

@@ -163,6 +163,28 @@ void Bitmap::ApplyPalette(const SNESPalette &palette) {
SDL_LockSurface(surface_.get());
}
void Bitmap::ApplyPaletteWithTransparent(const SNESPalette &palette,
int index) {
palette_ = palette;
auto start_index = index * 7;
std::vector<ImVec4> colors;
colors.push_back(ImVec4(0, 0, 0, 0));
for (int i = start_index; i < start_index + 7; ++i) {
colors.push_back(palette.GetColor(i).GetRGB());
}
SDL_UnlockSurface(surface_.get());
int i = 0;
for (auto &each : colors) {
surface_->format->palette->colors[i].r = each.x;
surface_->format->palette->colors[i].g = each.y;
surface_->format->palette->colors[i].b = each.z;
surface_->format->palette->colors[i].a = each.w;
i++;
}
SDL_LockSurface(surface_.get());
}
void Bitmap::ApplyPalette(const std::vector<SDL_Color> &palette) {
SDL_UnlockSurface(surface_.get());
for (int i = 0; i < palette.size(); ++i) {

View File

@@ -24,7 +24,6 @@ class Bitmap {
Bitmap(int width, int height, int depth, int data_size);
Bitmap(int width, int height, int depth, const Bytes &data)
: width_(width), height_(height), depth_(depth), data_(data) {
// CreateTextureFromData();
InitializeFromData(width, height, depth, data);
}
@@ -42,20 +41,21 @@ class Bitmap {
void Create(int width, int height, int depth, int data_size);
void Create(int width, int height, int depth, const Bytes &data);
void InitializeFromData(uint32_t width, uint32_t height,
uint32_t depth, const Bytes &data);
void InitializeFromData(uint32_t width, uint32_t height, uint32_t depth,
const Bytes &data);
void ReserveData(uint32_t width, uint32_t height, uint32_t depth,
uint32_t size);
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
void UpdateTexture(std::shared_ptr<SDL_Renderer> renderer);
void CreateTexture(SDL_Renderer* renderer);
void UpdateTexture(SDL_Renderer* renderer);
void CreateTexture(SDL_Renderer *renderer);
void UpdateTexture(SDL_Renderer *renderer);
void SaveSurfaceToFile(std::string_view filename);
void SetSurface(SDL_Surface *surface);
void ApplyPalette(const SNESPalette &palette);
void ApplyPaletteWithTransparent(const SNESPalette &palette, int index);
void ApplyPalette(const std::vector<SDL_Color> &palette);
void WriteToPixel(int position, uchar value) {
@@ -66,6 +66,15 @@ class Bitmap {
modified_ = true;
}
void WriteWordToPixel(int position, uint16_t value) {
if (pixel_data_ == nullptr) {
pixel_data_ = data_.data();
}
this->pixel_data_[position] = value & 0xFF;
this->pixel_data_[position + 1] = (value >> 8) & 0xFF;
modified_ = true;
}
void Cleanup() {
// Reset texture_
if (texture_) {
@@ -171,6 +180,8 @@ class BitmapManager {
return nullptr;
}
auto mutable_bitmap(int id) { return bitmap_cache_[id]; }
using value_type = std::pair<const int, std::shared_ptr<gfx::Bitmap>>;
using iterator =
std::unordered_map<int, std::shared_ptr<gfx::Bitmap>>::iterator;