resize bboxes
This commit is contained in:
parent
e86be28cc0
commit
1d851158fc
|
@ -7,10 +7,12 @@ The subject is available here: [Test Algo](./test_algo.pdf)
|
|||
- [X] dumb packing
|
||||
- [ ] skyline
|
||||
- [X] add raygui
|
||||
- [X] resize box
|
||||
- [ ] add box in gui by pressing down
|
||||
- [ ] delete box in gui by clicking
|
||||
- [ ] wrap stb_rect_pack?
|
||||
- [X] change bbox api to origin + size
|
||||
- [ ] dummy A2
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
|
@ -19,6 +20,8 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
constexpr int resize_handle = 20;
|
||||
|
||||
Rectangle rect_from_bbox(const freling::BoundingBox& box,
|
||||
const Vector2& offset) {
|
||||
const Rectangle rect = {offset.x + box.x, offset.y + box.y,
|
||||
|
@ -33,6 +36,11 @@ void draw(const freling::BoundingBox& box,
|
|||
const Rectangle rect = rect_from_bbox(box, offset);
|
||||
DrawRectangleRec(rect, ColorAlpha(color, 0.3));
|
||||
DrawRectangleLinesEx(rect, 3, color);
|
||||
DrawTriangle(
|
||||
(Vector2){rect.x + rect.width - resize_handle, rect.y + rect.height},
|
||||
(Vector2){rect.x + rect.width, rect.y + rect.height},
|
||||
(Vector2){rect.x + rect.width, rect.y + rect.height - resize_handle},
|
||||
color);
|
||||
}
|
||||
|
||||
Image image_from_frame(const Frame& frame) {
|
||||
|
@ -112,6 +120,7 @@ int main(int argc, const char* argv[]) {
|
|||
Vector2 mouse_pos = {0};
|
||||
Vector2 mouse_delta = {0};
|
||||
int b_moving_idx = -1;
|
||||
int b_resize_idx = -1;
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
//
|
||||
|
@ -124,17 +133,33 @@ int main(int argc, const char* argv[]) {
|
|||
const Rectangle rect = rect_from_bbox(box, in_offset);
|
||||
if (CheckCollisionPointRec(mouse_pos, rect) and
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
b_moving_idx = b;
|
||||
const Rectangle handle_area = {
|
||||
rect.x + rect.width - resize_handle,
|
||||
rect.y + rect.height - resize_handle, resize_handle,
|
||||
resize_handle};
|
||||
if (CheckCollisionPointRec(mouse_pos, handle_area)) {
|
||||
b_resize_idx = b;
|
||||
} else {
|
||||
b_moving_idx = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
b_moving_idx = -1;
|
||||
b_resize_idx = -1;
|
||||
}
|
||||
if (b_moving_idx != -1) {
|
||||
auto& box = bboxes[b_moving_idx];
|
||||
box.x += mouse_delta.x;
|
||||
box.y += mouse_delta.y;
|
||||
}
|
||||
if (b_resize_idx != -1) {
|
||||
auto& box = bboxes[b_resize_idx];
|
||||
box.width = std::max(static_cast<int>(box.width + mouse_delta.x),
|
||||
resize_handle);
|
||||
box.height = std::max(static_cast<int>(box.height + mouse_delta.y),
|
||||
resize_handle);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw
|
||||
|
|
Loading…
Reference in a new issue