5 #include "system/stacktrace.h"
6 #include "system/log.h"
7 #include "game/camera.h"
9 #include "rect_layer.h"
10 #include "proto_rect.h"
12 #define PROTO_AREA_THRESHOLD 10.0
14 int proto_rect_render(const ProtoRect *proto_rect,
17 trace_assert(proto_rect);
18 trace_assert(proto_rect->color_current);
21 if (proto_rect->active) {
27 *proto_rect->color_current) < 0) {
35 int proto_rect_event(ProtoRect *proto_rect,
36 const SDL_Event *event,
39 trace_assert(proto_rect);
40 trace_assert(proto_rect->color_current);
41 trace_assert(proto_rect->layer_current);
45 if (proto_rect->active) {
47 switch (event->type) {
48 case SDL_MOUSEBUTTONUP: {
49 switch (event->button.button) {
50 case SDL_BUTTON_LEFT: {
51 const Rect real_rect =
55 const float area = real_rect.w * real_rect.h;
57 if (area >= PROTO_AREA_THRESHOLD) {
58 rect_layer_add_rect(proto_rect->layer_current, real_rect, *proto_rect->color_current);
60 log_info("The area is too small %f. Such small box won't be created.\n", area);
62 proto_rect->active = false;
67 case SDL_MOUSEMOTION: {
68 proto_rect->end = camera_map_screen(
76 switch (event->type) {
77 case SDL_MOUSEBUTTONDOWN: {
78 switch (event->button.button) {
79 case SDL_BUTTON_LEFT: {
80 proto_rect->active = true;
81 proto_rect->begin = camera_map_screen(
85 proto_rect->end = proto_rect->begin;
95 int proto_rect_mouse_button(ProtoRect *proto_rect,
96 const SDL_MouseButtonEvent *event,
99 trace_assert(proto_rect);
100 trace_assert(proto_rect->color_current);
101 trace_assert(proto_rect->layer_current);
103 trace_assert(camera);
105 if (proto_rect->active) {
107 switch (event->type) {
108 case SDL_MOUSEBUTTONUP: {
109 switch (event->button) {
110 case SDL_BUTTON_LEFT: {
111 const Rect real_rect =
115 const float area = real_rect.w * real_rect.h;
117 if (area >= PROTO_AREA_THRESHOLD) {
118 rect_layer_add_rect(proto_rect->layer_current, real_rect, *proto_rect->color_current);
120 log_info("The area is too small %f. Such small box won't be created.\n", area);
122 proto_rect->active = false;
125 case SDL_BUTTON_RIGHT: {
126 proto_rect->active = false;
133 switch (event->type) {
134 case SDL_MOUSEBUTTONDOWN: {
135 switch (event->button) {
136 case SDL_BUTTON_LEFT: {
137 proto_rect->active = true;
138 proto_rect->begin = camera_map_screen(
142 proto_rect->end = proto_rect->begin;
153 int proto_rect_mouse_motion(ProtoRect *proto_rect,
154 const SDL_MouseMotionEvent *event,
155 const Camera *camera)
157 trace_assert(proto_rect);
160 if (proto_rect->active) {
161 proto_rect->end = camera_map_screen(