]> git.lizzy.rs Git - nothing.git/blob - src/game/level/level_editor/rect_layer.h
Introduce tool bar for subtract and snapping tools
[nothing.git] / src / game / level / level_editor / rect_layer.h
1 #ifndef RECT_LAYER_H_
2 #define RECT_LAYER_H_
3
4 #include "layer.h"
5 #include "game/level/action.h"
6 #include "ui/cursor.h"
7 #include "dynarray.h"
8 #include "color_picker.h"
9 #include "ui/edit_field.h"
10
11 typedef struct RectLayer RectLayer;
12
13 typedef enum {
14     RECT_LAYER_IDLE = 0,
15     RECT_LAYER_CREATE,
16     RECT_LAYER_RESIZE,
17     RECT_LAYER_MOVE,
18     RECT_LAYER_ID_RENAME,
19     RECT_LAYER_RECOLOR,
20     RECT_LAYER_SUBTRACT
21 } RectLayerState;
22
23 struct RectLayer {
24     RectLayerState state;
25     int resize_mask;
26     Dynarray ids;
27     Dynarray rects;
28     Dynarray colors;
29     Dynarray actions;
30     ColorPicker color_picker;
31     Vec2f create_begin;
32     Vec2f create_end;
33     int selection;
34     Vec2f move_anchor;          // The mouse offset from the left-top
35                                 // corner of the rect during moving it
36     Edit_field id_edit_field;
37     Color inter_color;
38     Rect inter_rect;
39     int id_name_counter;
40     const char *id_name_prefix;
41     Cursor *cursor;
42
43     int snapping_enabled;
44     int subtract_enabled;
45 };
46
47 LayerPtr rect_layer_as_layer(RectLayer *layer);
48 // NOTE: create_rect_layer and create_rect_layer_from_line_stream does
49 // not own id_name_prefix
50
51 RectLayer *create_rect_layer(Memory *memory,
52                              const char *id_name_prefix,
53                              Cursor *cursor);
54 void rect_layer_load(RectLayer *rect_layer, Memory *memory, String *input);
55
56 static inline
57 void destroy_rect_layer(RectLayer layer)
58 {
59     free(layer.ids.data);
60     free(layer.rects.data);
61     free(layer.colors.data);
62     free(layer.actions.data);
63 }
64
65
66 int rect_layer_render(const RectLayer *layer, const Camera *camera, int active);
67 int rect_layer_event(RectLayer *layer,
68                      const SDL_Event *event,
69                      const Camera *camera,
70                      UndoHistory *undo_history);
71
72 int rect_layer_dump_stream(const RectLayer *layer, FILE *filedump);
73
74 size_t rect_layer_count(const RectLayer *layer);
75 const Rect *rect_layer_rects(const RectLayer *layer);
76 const Color *rect_layer_colors(const RectLayer *layer);
77 const char *rect_layer_ids(const RectLayer *layer);
78 const Action *rect_layer_actions(const RectLayer *layer);
79
80 #endif  // RECT_LAYER_H_