techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/editor.h
blob: f18cae0b0f8cafdf242c56ff3918a34b38e273d2 (plain)
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
#ifndef EDITOR_H
#define EDITOR_H

#include "common.h"
#include "ent.h"

typedef enum {
	ED_ACTION_TRANSFORM,
	ED_ACTION_CREATE,
	ED_ACTION_DELETE,
	ED_ACTION_RENAME,
} 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;
} 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_CMD,
} EditorPanelType;

typedef struct {
	Vec3 sel_point;
	Quaternion sel_rot;
	int sel_cnt;

	f32 grid_sz;

	EditorPanelContainer focus;
	bool focus_captured;
	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);

/* draw */
void	editor_draw_ui(void);
void	editor_draw_3d(void);

/* utils */
f32	editor_label_w(cstr);
void	editor_rename_selected(cstr);



#endif