implement naive packer
This commit is contained in:
parent
8698cf8160
commit
e31683d2fe
8 changed files with 114 additions and 78 deletions
|
@ -19,31 +19,12 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
struct Button {
|
||||
Rectangle rect;
|
||||
std::string text;
|
||||
bool hover = false;
|
||||
|
||||
bool pressed() {
|
||||
hover = CheckCollisionPointRec(GetMousePosition(), rect);
|
||||
return hover and IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
};
|
||||
|
||||
void draw() const {
|
||||
DrawRectangleRec(rect, LIGHTGRAY);
|
||||
DrawRectangleLines(rect.x, rect.y, rect.width, rect.height, BLUE);
|
||||
DrawText(text.c_str(),
|
||||
(rect.x + rect.width / 2 - MeasureText(text.c_str(), 10) / 2),
|
||||
rect.y + 11, 10, DARKBLUE);
|
||||
};
|
||||
};
|
||||
|
||||
void draw(const freling::BoundingBox& box,
|
||||
const Vector2& offset,
|
||||
const Color& color) {
|
||||
const Rectangle rect = {offset.x + box.left, offset.y + box.top,
|
||||
static_cast<float>(box.right - box.left),
|
||||
static_cast<float>(box.bottom - box.top)};
|
||||
const Rectangle rect = {offset.x + box.x, offset.y + box.y,
|
||||
static_cast<float>(box.width),
|
||||
static_cast<float>(box.height)};
|
||||
DrawRectangleRec(rect, ColorAlpha(color, 0.3));
|
||||
DrawRectangleLinesEx(rect, 3, color);
|
||||
}
|
||||
|
@ -69,8 +50,8 @@ int main(int argc, const char* argv[]) {
|
|||
if (argc < 2 or (argc - 2) % 4 != 0) {
|
||||
std::cerr
|
||||
<< "Usage: " << argv[0] << " path/to/image"
|
||||
<< " [x1 y1 x2 y2 ...]\n"
|
||||
<< "x/y points must be grouped by 4 to define bounding boxes\n";
|
||||
<< " [x y width height ...]\n"
|
||||
<< "x/y/w/h points must be grouped by 4 to define bounding boxes\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -90,11 +71,11 @@ int main(int argc, const char* argv[]) {
|
|||
bboxes.reserve((argc - 2) / 4);
|
||||
int i = 2;
|
||||
while (i < argc) {
|
||||
const uint32_t x1 = atoi(argv[i]);
|
||||
const uint32_t y1 = atoi(argv[i + 1]);
|
||||
const uint32_t x2 = atoi(argv[i + 2]);
|
||||
const uint32_t y2 = atoi(argv[i + 3]);
|
||||
bboxes.push_back(freling::BoundingBox({x1, y1, x2, y2}));
|
||||
const int32_t x = atoi(argv[i]);
|
||||
const int32_t y = atoi(argv[i + 1]);
|
||||
const uint32_t w = atoi(argv[i + 2]);
|
||||
const uint32_t h = atoi(argv[i + 3]);
|
||||
bboxes.push_back(freling::BoundingBox({x, y, w, h}));
|
||||
i += 4;
|
||||
}
|
||||
const std::vector<Color> bbox_colors = {RED, GREEN, BLUE};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue