2022-02-13 22:07:26 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2022-02-12 15:34:35 +01:00
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
namespace raylib {
|
|
|
|
#include <raylib.h>
|
|
|
|
}
|
2022-02-12 15:34:35 +01:00
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
#include "bounding_box.h"
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
struct Button {
|
|
|
|
raylib::Rectangle rect;
|
|
|
|
std::string text;
|
|
|
|
bool hover = false;
|
|
|
|
|
|
|
|
bool pressed() {
|
|
|
|
hover =
|
|
|
|
raylib::CheckCollisionPointRec(raylib::GetMousePosition(), rect);
|
|
|
|
return hover and
|
|
|
|
raylib::IsMouseButtonReleased(raylib::MOUSE_BUTTON_LEFT);
|
|
|
|
};
|
|
|
|
|
|
|
|
void draw() const {
|
|
|
|
raylib::DrawRectangleRec(rect, raylib::LIGHTGRAY);
|
|
|
|
raylib::DrawRectangleLines(rect.x, rect.y, rect.width, rect.height,
|
|
|
|
raylib::BLUE);
|
|
|
|
raylib::DrawText(text.c_str(),
|
|
|
|
(rect.x + rect.width / 2 -
|
|
|
|
raylib::MeasureText(text.c_str(), 10) / 2),
|
|
|
|
rect.y + 11, 10, raylib::DARKBLUE);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void draw(const BoundingBox& box) {}
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
if (argc < 2) {
|
|
|
|
std::cerr << "Usage: " << argv[0] << " path/to/image\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fs::path input(argv[1]);
|
|
|
|
if (!fs::exists(input)) {
|
|
|
|
std::cerr << "Input file " << input << " does not exist.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
raylib::Vector2 win_size = {800, 450};
|
|
|
|
const int padding = 5;
|
|
|
|
raylib::Vector2 in_offset = {padding, 40};
|
|
|
|
|
|
|
|
raylib::InitWindow(win_size.x, win_size.y, "netatmo - rect packing");
|
|
|
|
raylib::SetTargetFPS(60);
|
|
|
|
|
|
|
|
raylib::Image imOrigin = raylib::LoadImage(input.c_str());
|
|
|
|
raylib::ImageFormat(&imOrigin, raylib::PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
|
|
|
raylib::Texture2D texture = raylib::LoadTextureFromImage(imOrigin);
|
|
|
|
|
|
|
|
win_size.x = std::max(win_size.x, in_offset.x + texture.width + padding);
|
|
|
|
win_size.y = std::max(win_size.y, in_offset.y + texture.height + padding);
|
|
|
|
|
|
|
|
raylib::SetWindowSize(win_size.x, win_size.y);
|
|
|
|
|
|
|
|
Button b_add_box = {{padding, padding, 150, 30}, "Add box"};
|
|
|
|
std::vector<BoundingBox> bboxes;
|
|
|
|
|
|
|
|
while (!raylib::WindowShouldClose()) {
|
|
|
|
if (b_add_box.pressed()) {
|
|
|
|
bboxes.push_back(BoundingBox({0, 0, 20, 20}));
|
2022-02-12 15:34:35 +01:00
|
|
|
}
|
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
raylib::BeginDrawing();
|
|
|
|
raylib::ClearBackground(raylib::RAYWHITE);
|
2022-02-12 15:34:35 +01:00
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
b_add_box.draw();
|
2022-02-12 15:34:35 +01:00
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
raylib::DrawTexture(texture, in_offset.x, in_offset.y, raylib::WHITE);
|
|
|
|
raylib::DrawRectangleLines(in_offset.x, in_offset.y, texture.width,
|
|
|
|
texture.height, raylib::BLACK);
|
|
|
|
|
|
|
|
raylib::EndDrawing();
|
|
|
|
}
|
2022-02-12 15:34:35 +01:00
|
|
|
|
2022-02-13 22:07:26 +01:00
|
|
|
// Cleanup
|
|
|
|
raylib::UnloadTexture(texture);
|
|
|
|
raylib::UnloadImage(imOrigin);
|
|
|
|
raylib::CloseWindow();
|
2022-02-12 15:34:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|