~amavect/makeu

ref: d17551be6203b2f728bb42154fce2ca5083d83c6 makeu/elementile.h -rw-r--r-- 2.0 KiB
d17551beamavect fix usage message 1 year, 8 months ago
                                                                                
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
/* Amavect! */
//#pragma src "."
//#pragma lib "libelementile.a"

typedef struct Elementile Elementile;
typedef struct Guipart Guipart;

struct Elementile {
	void *aux; /* the entity */
	Point (*init)(Elementile*); /* electricity is the essence of consciousness */
	void (*resize)(Elementile*, Rectangle); /* the ground is where we live */
	int (*update)(Elementile*); /* the air we breathe brings us to a new state */
	int (*mouse)(Elementile*, Mouse); /* flow of input is the blood of computation */
	int (*keyboard)(Elementile*, Rune); /* strike the keyboard into flame */
	void (*free)(Elementile*); /* vapor escapes our grasp, leaving nothing in its wake */
};

/*
 * *aux is a pointer to the auxillary/internal state of the Elementile.
 * Spark is initialization. Init any internal state.
 *   Return the minimum size.
 * Earth is resize. Refresh any internal state to the current size given and redraw.
 * Air is update. Validate any state changes and redraw. 
 *   Return 1 if redraw needed, 0 if not.
 * Water is mouse. Use the Mouse to update any state and redraw. 
 *   Return 1 if redraw needed, 0 if not.
 * Fire is keyboard. Use the Rune to update any state and redraw. 
 *   Return 1 if redraw needed, 0 if not.
 * Vapor is free. Free any memory and state.
 */

typedef enum Divtype{
	Vdiv,
	Hdiv
} Divtype;

struct Guipart {
	Divtype vh; /* vertical or horizontal division */
	int w; /* division width = 2*w */
	double d; /* division ratio */
	Elementile *lt; /* left or top next element */
	Elementile *rb; /* right or bottom next element */
	/* internal */
	Point ltmin; /* minimum size of lt */
	Point rbmin; /* minimum size of rb */
	Rectangle ltrect; /* current size of lt */
	Rectangle rbrect; /* current size of rb */
	Elementile *sel; /* selected element, can be nil */
	int state; /* state machine */
};

extern Point guipartinit(Elementile*);
extern void guipartresize(Elementile*, Rectangle);
extern int guipartupdate(Elementile*);
extern int guipartmouse(Elementile*, Mouse);
extern int guipartkeyboard(Elementile*, Rune);
extern void guipartfree(Elementile*);