Monday, October 4, 2010

Inside The Blender C API - Part2

In the "main" function of "creator.c" the function call "WM_keymap_init(C)" ('C' blender-context) setups basic mouse and keyboard handling. Calls to CTX_wm_manager(C) which returns a pointer to the wmWindowManager struct contained by C. WM_keymap_init, a new wmKeyConfig struct is created by WM_keyconfig_new, passed to: wm_window_keymap, ED_spacetypes_keymap, and WM_keyconfig_userdef. Finally the wmKeyConfig is assigned to the wmWindowManager struct as `defaultconf`.

Blender Context.



C contains: thread index, window manager struct, data-context-struct, and eval struct. The window manager struct contains: a manager, window, screen, area, region, menu, and store. The data-context-struct contains the scene and python context.

blenkernel note:

Many functions defined in blender/source/blender/blendkernel are prefixed with BKE, but not all. CTX_create and CTX_wm_manager are two examples of blendkernel functions that do not start with BKE.


The wmWindowManager struct and wmKeyConfig are defined in blender/source/blender/makesdna/DNA_windowmanager_types.h. Other important window manager related structs also define here are: wmWindow and wmOperator. The wmWindow struct contains a pointer to a wmEvent struct named `eventstate`, and a list named `queue` that contains all events. Two other event lists inside wmWindow are: `handlers` and `modalhandlers`.

WM_types.h and wm_event_types.h

Both of these headers are in: blender/source/blender/windowmanager/. wmEvent and other window event related things are defined here, the structs are in WM_types.h and the enums are in wm_event_types.h. Below is the definition of wmEvent:

/* each event should have full modifier state */
/* event comes from eventmanager and from keymap */
typedef struct wmEvent {
struct wmEvent *next, *prev;
short type; /* event code itself (short, is also in keymap) */
short val; /* press, release, scrollvalue */
short x, y; /* mouse pointer position, screen coord */
short mval[2]; /* region mouse position, name convention pre 2.5 :) */
short unicode; /* future, ghost? */
char ascii; /* from ghost */
char pad;
/* previous state */
short prevtype;
short prevval;
short prevx, prevy;
double prevclicktime;
short prevclickx, prevclicky;
/* modifier states */
short shift, ctrl, alt, oskey; /* oskey is apple or windowskey, value denotes order of pressed */
short keymodifier; /* rawkey modifier */
short pad1;
/* keymap item, set by handler (weak?) */
const char *keymap_idname;
/* custom data */
short custom; /* custom data type, stylus, 6dof, see wm_event_types.h */
short customdatafree;
int pad2;
void *customdata; /* ascii, unicode, mouse coords, angles, vectors, dragdrop info */
} wmEvent;