]> git.lizzy.rs Git - nothing.git/commitdiff
(#786) Don't allow creating small boxes
authorrexim <reximkut@gmail.com>
Sat, 13 Apr 2019 16:33:27 +0000 (23:33 +0700)
committerrexim <reximkut@gmail.com>
Sat, 13 Apr 2019 16:33:27 +0000 (23:33 +0700)
src/game/level/level_editor/proto_rect.c

index 12c04c6d16e0db3720990a20ec028be7dbd7d940..ffabfab19e8822d8d677577027eb964c33180396 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "./proto_rect.h"
 
+#define PROTO_AREA_THRESHOLD 10.0
+
 int proto_rect_render(const ProtoRect *proto_rect,
                       Camera *camera)
 {
@@ -53,12 +55,17 @@ int proto_rect_event(ProtoRect *proto_rect,
         case SDL_MOUSEBUTTONUP: {
             switch (event->button.button) {
             case SDL_BUTTON_LEFT: {
-                boxes_add_box(
-                    boxes,
+                const Rect real_rect =
                     rect_from_points(
                         proto_rect->begin,
-                        proto_rect->end),
-                    proto_rect->color);
+                        proto_rect->end);
+                const float area = real_rect.w * real_rect.h;
+
+                if (area >= PROTO_AREA_THRESHOLD) {
+                    boxes_add_box(boxes, real_rect, proto_rect->color);
+                } else {
+                    log_info("The area is too small %f. Such small box won't be created.\n", area);
+                }
                 proto_rect->active = false;
             } break;
             }