1 /*	Public domain	*/
2 
3 #ifndef _AGAR_VG_TOOL_H_
4 #define _AGAR_VG_TOOL_H_
5 
6 #include <agar/gui/iconmgr.h>
7 
8 #include <agar/vg/begin.h>
9 
10 struct vg_tool_keybinding;
11 struct vg_tool_mousebinding;
12 struct vg_tool_command;
13 struct vg_view;
14 
15 /* VG tool class description */
16 typedef struct vg_tool_ops {
17 	const char *name;		/* Tool name */
18 	const char *desc;		/* Optional description */
19 	AG_StaticIcon *icon;		/* Optional GUI icon */
20 	size_t len;			/* Size of instance structure */
21 	Uint flags;
22 #define VG_MOUSEMOTION_NOSNAP	0x01	/* Ignore snapping in mousemotion */
23 #define VG_BUTTONUP_NOSNAP	0x02	/* Ignore snapping in buttonup */
24 #define VG_BUTTONDOWN_NOSNAP	0x04	/* Ignore snapping in buttondown */
25 #define VG_BUTTON_NOSNAP	(VG_BUTTONUP_NOSNAP|VG_BUTTONDOWN_NOSNAP)
26 #define VG_NOSNAP		(VG_BUTTON_NOSNAP|VG_MOUSEMOTION_NOSNAP)
27 #define VG_NOEDITCLEAR		0x08	/* Don't clear edit areas on select */
28 
29 	void (*init)(void *);
30 	void (*destroy)(void *);
31 	void *(*edit)(void *, struct vg_view *);
32 	void (*predraw)(void *, struct vg_view *);
33 	void (*postdraw)(void *, struct vg_view *);
34 	void (*selected)(void *, struct vg_view *);
35 	void (*deselected)(void *, struct vg_view *);
36 
37 	int (*mousemotion)(void *, VG_Vector vPos, VG_Vector vRel, int buttons);
38 	int (*mousebuttondown)(void *, VG_Vector vPos, int button);
39 	int (*mousebuttonup)(void *, VG_Vector vPos, int button);
40 	int (*keydown)(void *, int ksym, int kmod, Uint32 unicode);
41 	int (*keyup)(void *, int ksym, int kmod, Uint32 unicode);
42 } VG_ToolOps;
43 
44 /* VG tool instance */
45 typedef struct vg_tool {
46 	const VG_ToolOps *ops;
47 	int selected;				/* Tool is in use */
48 	struct vg_view *vgv;			/* Associated view */
49 	void *p;				/* User-supplied pointer */
50 	AG_Window *editWin;			/* Edition window (if any) */
51 	AG_Widget *editArea;			/* Edition area (if any) */
52 	VG_Vector vCursor;			/* Last cursor position */
53 	AG_SLIST_HEAD_(vg_tool_keybinding) kbindings;
54 	AG_TAILQ_HEAD_(vg_tool_command) cmds;
55 	AG_TAILQ_ENTRY(vg_tool) tools;
56 } VG_Tool;
57 
58 /* General command handler */
59 typedef struct vg_tool_command {
60 	char *name;				/* Command string */
61 	char *descr;				/* Description string */
62 	AG_Event *fn;				/* Callback routine (bound to VG_View) */
63 	AG_KeyMod kMod;				/* Bound key modifier */
64 	AG_KeySym kSym;				/* Bound keysym */
65 	VG_Tool *tool;				/* Back pointer to tool */
66 	AG_TAILQ_ENTRY(vg_tool_command) cmds;
67 } VG_ToolCommand;
68 
69 #define VGTOOL(t) ((VG_Tool *)(t))
70 #define VG_CURTOOL(vv) \
71     (vv)->curtool != NULL ? (vv)->curtool : \
72     (vv)->deftool != NULL ? (vv)->deftool : NULL
73 
74 __BEGIN_DECLS
75 void       VG_ToolInit(VG_Tool *);
76 void       VG_ToolDestroy(VG_Tool *);
77 AG_Window *VG_ToolWindow(void *, const char *);
78 
79 VG_ToolCommand *VG_ToolCommandNew(void *, const char *, AG_EventFn);
80 void            VG_ToolCommandKey(VG_ToolCommand *, AG_KeyMod, AG_KeySym);
81 void            VG_ToolCommandDescr(VG_ToolCommand *, const char *, ...);
82 int             VG_ToolCommandExec(void *, const char *, const char *, ...);
83 __END_DECLS
84 
85 #include <agar/vg/close.h>
86 #endif /* _AGAR_VG_TOOL_H_ */
87