1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#ifndef EDITOR_H
#define EDITOR_H
#include "common.h"
#include "ent.h"
#include "cam.h"
typedef enum {
ED_ACTION_TRANSFORM,
ED_ACTION_CREATE,
ED_ACTION_DELETE,
ED_ACTION_RENAME,
ED_ACTION_MODEL,
ED_ACTION_PHYSICS,
} EditorActionTag;
typedef union {
struct {
Vec3 pos, scale;
Quaternion rot;
} transform;
/* stored meaning 'stored entity', shared by creation/deletion */
struct {
Entity ent;
u64 parent, prev, next;
} stored;
struct {
char *name;
} rename;
ModelCmp model;
PhysicsCmp physics;
} EditorActionData;
typedef struct {
EditorActionTag tag;
u32 item_cnt;
struct {
u64 pid;
EditorActionData before, after;
} *item;
} EditorAction;
typedef enum {
ED_PNL_NULL,
ED_PNL_LEFT,
ED_PNL_RIGHT,
ED_PNL_CENTER,
ED_PNL_CNT,
} EditorPanelContainer;
typedef enum {
ED_PNL_TYPE_SCENE,
ED_PNL_TYPE_PROPERTIES,
ED_PNL_TYPE_SPACE,
ED_PNL_TYPE_MODEL_PICKER,
ED_PNL_TYPE_PHYSICS_ELEMENTS,
ED_PNL_TYPE_PHYSICS_PROPERTIES,
ED_PNL_TYPE_CMD,
} EditorPanelType;
typedef enum {
ED_MODE_SCENE,
ED_MODE_ENTITY,
ED_MODE_PHYSICS,
} EditorModeTag;
typedef enum {
ED_INTERACT_NONE,
ED_INTERACT_SELECT,
ED_INTERACT_MOVE,
ED_INTERACT_ROTATE,
ED_INTERACT_SCALE,
ED_INTERACT_CAMERA,
} EditorInteraction;
typedef struct {
Vec3 sel_point;
Quaternion sel_rot;
int sel_cnt;
f32 grid_sz;
int rotation_snap;
u64 physics_pid;
int physics_body, physics_shape;
Vec2 physics_scroll;
CameraInfo scene_cam;
bool draw_physics;
EditorModeTag mode, prev_mode;
EditorInteraction interact;
EditorPanelContainer focus;
bool focus_captured;
int move_axis;
bool move_plane;
Vec3 move_snap_origin;
int rotate_axis;
bool rotate_group;
Vec3 rotate_pivot;
Quaternion move_rotation;
int scale_axis;
bool scale_group;
Vec3 scale_pivot;
f32 scale_factor;
struct {
EditorPanelType type;
Rect bounds;
Vec2 scroll;
bool enabled;
} panel[ED_PNL_CNT];
EditorAction *history;
// history_save_csr UINT32_MAX means no saved position and marks file
// as having unsaved changes.
u32 history_cnt, history_cap, history_csr, history_save_csr;
} EditorInfo;
extern EditorInfo ed;
void editor_init(void);
void editor_exit(void);
void editor_update(void);
/* tools */
void editor_select(void);
void editor_move(void);
void editor_rotate(void);
void editor_scale(void);
/* draw */
void editor_draw_ui(void);
void editor_draw_3d(void);
/* utils */
f32 editor_label_w(cstr);
void editor_rename_selected(cstr);
#endif
|