Skip to content

Commit

Permalink
Move image logic to chirp
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed May 11, 2024
1 parent 495d943 commit 9933ad3
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 51 deletions.
12 changes: 0 additions & 12 deletions src/asset/image.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/asset/image.hpp

This file was deleted.

13 changes: 10 additions & 3 deletions src/asset/tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ asset::tileset::tileset(const std::vector<unsigned char> &data)
size = texture.get_height();
}

auto asset::tileset::at(int i) const -> asset::image
auto asset::tileset::at(int i) const -> chirp::image
{
auto size_f = static_cast<float>(size);
Rectangle rect{
static_cast<float>(size * i), 0.F,
size_f, size_f,
};

return asset::image(ImageFromImage(image, rect));
int size;
const auto r_image = ImageFromImage(*image.data(), rect);

auto *data = ExportImageToMemory(r_image, ".png", &size);
const std::vector<unsigned char> buffer(data, data + size);

RL_FREE(data);
return chirp::image(buffer);
}

void asset::tileset::draw(float x, float y, int i, float rotation, float scale) const
Expand All @@ -25,7 +32,7 @@ void asset::tileset::draw(float x, float y, int i, float rotation, float scale)

void asset::tileset::flip_horizontal()
{
ImageFlipHorizontal(&image);
image.flip_horizontal();
texture = ce::texture(image);
}

Expand Down
4 changes: 2 additions & 2 deletions src/asset/tileset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace asset
public:
explicit tileset(const std::vector<unsigned char> &data);

auto at(int index) const -> asset::image;
auto at(int index) const -> chirp::image;

void draw(float x, float y, int index, float rotation, float scale) const;

Expand All @@ -23,7 +23,7 @@ namespace asset
/** Total size for each tile */
int size = 0;

asset::image image;
chirp::image image;
ce::texture texture;
};
}
4 changes: 2 additions & 2 deletions src/engine/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ auto ce::assets::font(const std::string &path, const int font_size) const -> chi
return chirp::font(open("fonts", path), font_size);
}

auto ce::assets::image(const std::string &path) const -> asset::image
auto ce::assets::image(const std::string &path) const -> chirp::image
{
return asset::image(open("images", path));
return chirp::image(open("images", path));
}

auto ce::assets::tileset(const std::string &path) const -> asset::tileset
Expand Down
10 changes: 5 additions & 5 deletions src/engine/assets.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "asset/image.hpp"
#include "asset/level.hpp"
#include "asset/sound.hpp"
#include "asset/tileset.hpp"

#include "chirp/assets.hpp"
#include "chirp/font.hpp"
#include "chirp/music.hpp"
#include <chirp/assets.hpp>
#include <chirp/font.hpp>
#include <chirp/image.hpp>
#include <chirp/music.hpp>

namespace ce
{
Expand All @@ -25,7 +25,7 @@ namespace ce

auto font(const std::string &path, int font_size) const -> chirp::font;

auto image(const std::string &path) const -> asset::image;
auto image(const std::string &path) const -> chirp::image;

auto tileset(const std::string &path) const -> asset::tileset;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ce::sprite::sprite(const ce::texture &texture)
{
}

ce::sprite::sprite(const asset::image &image)
ce::sprite::sprite(const chirp::image &image)
: ce::sprite(ce::texture(image))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ce
/**
* New sprite from image
*/
explicit sprite(const asset::image &image);
explicit sprite(const chirp::image &image);

void draw();

Expand Down
4 changes: 2 additions & 2 deletions src/engine/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "texture.hpp"

ce::texture::texture(const asset::image &image)
: r_texture(LoadTextureFromImage(image))
ce::texture::texture(const chirp::image &image)
: r_texture(LoadTextureFromImage(*image.data()))
{
}

Expand Down
5 changes: 2 additions & 3 deletions src/engine/texture.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once

#include "raylib.h"
#include "asset/image.hpp"

#include <cmath>
#include <chirp/image.hpp>

namespace ce
{
class texture
{
public:
explicit texture(const asset::image &image);
explicit texture(const chirp::image &image);

/**
* Draw entire texture at position
Expand Down
4 changes: 2 additions & 2 deletions src/engine/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void ce::window::close()
CloseWindow();
}

void ce::window::set_icon(const asset::image &image)
void ce::window::set_icon(const chirp::image &image)
{
SetWindowIcon(image);
SetWindowIcon(*image.data());
}

auto ce::window::size() -> chirp::vector2i
Expand Down
4 changes: 2 additions & 2 deletions src/engine/window.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "raylib.h"
#include "asset/image.hpp"

#include <chirp/image.hpp>
#include <chirp/vector2.hpp>

#include <iostream>
Expand All @@ -24,7 +24,7 @@ namespace ce
void end() const;

static void close();
static void set_icon(const asset::image &image);
static void set_icon(const chirp::image &image);

static auto size() -> chirp::vector2i;

Expand Down

0 comments on commit 9933ad3

Please sign in to comment.