show packed bboxes
This commit is contained in:
parent
81463d9eb0
commit
8698cf8160
3 changed files with 28 additions and 17 deletions
|
@ -98,6 +98,7 @@ int main(int argc, const char* argv[]) {
|
|||
i += 4;
|
||||
}
|
||||
const std::vector<Color> bbox_colors = {RED, GREEN, BLUE};
|
||||
std::vector<freling::BoundingBox> packed_bboxes;
|
||||
|
||||
Vector2 win_size = {800, 450};
|
||||
const int padding = 5;
|
||||
|
@ -120,16 +121,13 @@ int main(int argc, const char* argv[]) {
|
|||
SetWindowSize(win_size.x, win_size.y);
|
||||
|
||||
const Vector2 b_size = {150, 30};
|
||||
Button b_add_box = {{padding, padding, b_size.x, b_size.y}, "Add box"};
|
||||
Button b_pack = {{padding * 2 + b_size.x, padding, b_size.x, b_size.y},
|
||||
"Pack rects"};
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
//
|
||||
// Buttons
|
||||
// Widgets: buttons, ...
|
||||
//
|
||||
if (GuiButton((Rectangle){padding, padding, b_size.x, b_size.y},
|
||||
"Add Box")) {
|
||||
|
@ -139,7 +137,8 @@ int main(int argc, const char* argv[]) {
|
|||
if (GuiButton((Rectangle){padding * 2 + b_size.x, padding, b_size.x,
|
||||
b_size.y},
|
||||
"Pack Rects")) {
|
||||
std::optional<Frame> f_packed = pack(*in_frame, bboxes);
|
||||
std::optional<Frame> f_packed =
|
||||
pack(*in_frame, bboxes, packed_bboxes);
|
||||
|
||||
if (packed) {
|
||||
UnloadTexture(pack_texture);
|
||||
|
@ -179,10 +178,18 @@ int main(int argc, const char* argv[]) {
|
|||
// Packed image
|
||||
//
|
||||
if (packed) {
|
||||
const int offset_x = in_offset.x + in_texture.width + padding;
|
||||
DrawTexture(pack_texture, offset_x, in_offset.y, WHITE);
|
||||
DrawRectangleLines(offset_x, in_offset.y, pack_texture.width,
|
||||
Vector2 pack_offset = {in_offset.x + in_texture.width + padding,
|
||||
in_offset.y};
|
||||
DrawTexture(pack_texture, pack_offset.x, pack_offset.y, WHITE);
|
||||
DrawRectangleLines(pack_offset.x, pack_offset.y, pack_texture.width,
|
||||
pack_texture.height, BLACK);
|
||||
|
||||
int c = 0;
|
||||
for (const auto& b : packed_bboxes) {
|
||||
const auto& color = bbox_colors[c % bboxes.size()];
|
||||
draw(b, pack_offset, color);
|
||||
++c;
|
||||
};
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue