Blender  V2.59
WM_api.h
Go to the documentation of this file.
00001 /*
00002  * $Id: WM_api.h 39293 2011-08-11 06:06:17Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2007 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * 
00024  * Contributor(s): Blender Foundation
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 #ifndef WM_API_H
00029 #define WM_API_H
00030 
00042 /* dna-savable wmStructs here */
00043 #include "DNA_windowmanager_types.h"
00044 #include "WM_keymap.h"
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 struct bContext;
00051 struct IDProperty;
00052 struct wmEvent;
00053 struct wmEventHandler;
00054 struct wmGesture;
00055 struct wmJob;
00056 struct wmNotifier;
00057 struct wmOperatorType;
00058 struct wmOperator;
00059 struct rcti;
00060 struct PointerRNA;
00061 struct EnumPropertyItem;
00062 struct MenuType;
00063 struct wmDropBox;
00064 struct wmDrag;
00065 struct ImBuf;
00066 
00067 typedef struct wmJob wmJob;
00068 
00069 /* general API */
00070 void            WM_setprefsize          (int stax, int stay, int sizx, int sizy);
00071 void            WM_setinitialstate_fullscreen(void);
00072 void            WM_setinitialstate_normal(void);
00073 
00074 void            WM_init                         (struct bContext *C, int argc, const char **argv);
00075 void            WM_exit                         (struct bContext *C);
00076 void            WM_main                         (struct bContext *C);
00077 
00078 int             WM_init_game            (struct bContext *C);
00079 void            WM_init_splash          (struct bContext *C);
00080 
00081 
00082 void            WM_check                        (struct bContext *C);
00083 
00084 struct wmWindow *WM_window_open (struct bContext *C, struct rcti *rect);
00085 
00086                         /* defines for 'type' WM_window_open_temp */
00087 #define WM_WINDOW_RENDER                0
00088 #define WM_WINDOW_USERPREFS             1
00089 #define WM_WINDOW_FILESEL               2
00090 
00091 void            WM_window_open_temp     (struct bContext *C, struct rcti *position, int type);
00092 
00093 
00094 
00095                         /* files */
00096 int                     WM_read_homefile_exec(struct bContext *C, struct wmOperator *op);
00097 int                     WM_read_homefile        (struct bContext *C, struct ReportList *reports, short from_memory);
00098 int                     WM_write_homefile       (struct bContext *C, struct wmOperator *op);
00099 void            WM_read_file            (struct bContext *C, const char *filepath, struct ReportList *reports);
00100 int                     WM_write_file           (struct bContext *C, const char *target, int fileflags, struct ReportList *reports, int copy);
00101 void            WM_read_autosavefile(struct bContext *C);
00102 void            WM_autosave_init        (struct wmWindowManager *wm);
00103 
00104                         /* mouse cursors */
00105 void            WM_cursor_set           (struct wmWindow *win, int curs);
00106 void            WM_cursor_modal         (struct wmWindow *win, int curs);
00107 void            WM_cursor_restore       (struct wmWindow *win);
00108 void            WM_cursor_wait          (int val);
00109 void            WM_cursor_grab(struct wmWindow *win, int wrap, int hide, int *bounds);
00110 void            WM_cursor_ungrab(struct wmWindow *win);
00111 void            WM_timecursor           (struct wmWindow *win, int nr);
00112 
00113 void            *WM_paint_cursor_activate(struct wmWindowManager *wm, int (*poll)(struct bContext *C), void (*draw)(struct bContext *C, int, int, void *customdata), void *customdata);
00114 void            WM_paint_cursor_end(struct wmWindowManager *wm, void *handle);
00115 
00116 void            WM_cursor_warp          (struct wmWindow *win, int x, int y);
00117 
00118                         /* event map */
00119 int                     WM_userdef_event_map(int kmitype);
00120 
00121                         /* handlers */
00122 
00123 struct wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
00124                                                 /* boundbox, optional subwindow boundbox for offset */
00125 struct wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, wmKeyMap *keymap, rcti *bb, rcti *swinbb);
00126                                                 /* priority not implemented, it adds in begin */
00127 struct wmEventHandler *WM_event_add_keymap_handler_priority(ListBase *handlers, wmKeyMap *keymap, int priority);
00128 
00129 void            WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
00130 
00131 struct wmEventHandler *WM_event_add_ui_handler(const struct bContext *C, ListBase *handlers,
00132                         int (*func)(struct bContext *C, struct wmEvent *event, void *userdata),
00133                         void (*remove)(struct bContext *C, void *userdata), void *userdata);
00134 void            WM_event_remove_ui_handler(ListBase *handlers,
00135                         int (*func)(struct bContext *C, struct wmEvent *event, void *userdata),
00136                         void (*remove)(struct bContext *C, void *userdata), void *userdata, int postpone);
00137 void            WM_event_remove_area_handler(struct ListBase *handlers, void *area);
00138 
00139 struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op);
00140 void            WM_event_remove_handlers(struct bContext *C, ListBase *handlers);
00141 
00142 struct wmEventHandler *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes);
00143 
00144                         /* mouse */
00145 void            WM_event_add_mousemove(struct bContext *C);
00146 int                     WM_modal_tweak_exit(struct wmEvent *evt, int tweak_event);
00147 
00148                         /* notifiers */
00149 void            WM_event_add_notifier(const struct bContext *C, unsigned int type, void *reference);
00150 void            WM_main_add_notifier(unsigned int type, void *reference);
00151 
00152 void            wm_event_add            (struct wmWindow *win, struct wmEvent *event_to_add); /* XXX only for warning */
00153 
00154                         /* at maximum, every timestep seconds it triggers event_type events */
00155 struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep);
00156 void            WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer);
00157 void            WM_event_timer_sleep(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer, int dosleep);
00158 
00159                 /* operator api, default callbacks */
00160                         /* invoke callback, uses enum property named "type" */
00161 int                     WM_menu_invoke                  (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00162 int                     WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00163                         /* invoke callback, confirm menu + exec */
00164 int                     WM_operator_confirm             (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00165                 /* invoke callback, file selector "filepath" unset + exec */
00166 int                     WM_operator_filesel             (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00167                         /* poll callback, context checks */
00168 int                     WM_operator_winactive   (struct bContext *C);
00169                         /* invoke callback, exec + redo popup */
00170 int                     WM_operator_props_popup (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00171 int             WM_operator_props_dialog_popup (struct bContext *C, struct wmOperator *op, int width, int height);
00172 int                     WM_operator_redo_popup  (struct bContext *C, struct wmOperator *op);
00173 int                     WM_operator_ui_popup    (struct bContext *C, struct wmOperator *op, int width, int height);
00174 
00175 int                     WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message);
00176 
00177                 /* operator api */
00178 void            WM_operator_free                (struct wmOperator *op);
00179 void            WM_operator_stack_clear(struct wmWindowManager *wm);
00180 
00181 struct wmOperatorType *WM_operatortype_find(const char *idnamem, int quiet);
00182 struct GHashIterator *WM_operatortype_iter(void);
00183 void            WM_operatortype_append  (void (*opfunc)(struct wmOperatorType*));
00184 void            WM_operatortype_append_ptr      (void (*opfunc)(struct wmOperatorType*, void *), void *userdata);
00185 void            WM_operatortype_append_macro_ptr        (void (*opfunc)(struct wmOperatorType*, void *), void *userdata);
00186 int                     WM_operatortype_remove(const char *idname);
00187 
00188 struct wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *name, int flag);
00189 struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot, const char *idname);
00190 
00191 
00192 int                     WM_operator_poll                (struct bContext *C, struct wmOperatorType *ot);
00193 int                     WM_operator_poll_context(struct bContext *C, struct wmOperatorType *ot, int context);
00194 int                     WM_operator_call                (struct bContext *C, struct wmOperator *op);
00195 int                     WM_operator_repeat              (struct bContext *C, struct wmOperator *op);
00196 int                     WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op);
00197 int                     WM_operator_name_call   (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties);
00198 int                     WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, int context, struct PointerRNA *properties, struct ReportList *reports);
00199 
00200 void            WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */
00201 void            WM_operator_properties_sanitize(struct PointerRNA *ptr, const short no_context); /* make props context sensitive or not */
00202 void            WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
00203 void            WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot);
00204 void            WM_operator_properties_free(struct PointerRNA *ptr);
00205 void            WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type, short action, short flag);
00206 void            WM_operator_properties_gesture_border(struct wmOperatorType *ot, int extend);
00207 void            WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor);
00208 void            WM_operator_properties_select_all(struct wmOperatorType *ot);
00209 
00210 wmOperator *WM_operator_last_redo(const struct bContext *C);
00211 
00212 /* MOVE THIS SOMEWHERE ELSE */
00213 #define SEL_TOGGLE              0
00214 #define SEL_SELECT              1
00215 #define SEL_DESELECT    2
00216 #define SEL_INVERT              3
00217 
00218 
00219 /* flags for WM_operator_properties_filesel */
00220 #define WM_FILESEL_RELPATH              (1 << 0)
00221 
00222 #define WM_FILESEL_DIRECTORY    (1 << 1)
00223 #define WM_FILESEL_FILENAME             (1 << 2)
00224 #define WM_FILESEL_FILEPATH             (1 << 3)
00225 
00226 
00227                 /* operator as a python command (resultuing string must be free'd) */
00228 char            *WM_operator_pystring(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args);
00229 void            WM_operator_bl_idname(char *to, const char *from);
00230 void            WM_operator_py_idname(char *to, const char *from);
00231 
00232 /* *************** menu types ******************** */
00233 void                            WM_menutype_init(void);
00234 struct MenuType         *WM_menutype_find(const char *idname, int quiet);
00235 int                                     WM_menutype_add(struct MenuType* mt);
00236 int                                     WM_menutype_contains(struct MenuType* mt);
00237 void                            WM_menutype_freelink(struct MenuType* mt);
00238 void                            WM_menutype_free(void);
00239 
00240                         /* default operator callbacks for border/circle/lasso */
00241 int                     WM_border_select_invoke (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00242 int                     WM_border_select_modal  (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00243 int                     WM_border_select_cancel(struct bContext *C, struct wmOperator *op);
00244 int                     WM_gesture_circle_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00245 int                     WM_gesture_circle_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00246 int                     WM_gesture_circle_cancel(struct bContext *C, struct wmOperator *op);
00247 int                     WM_gesture_lines_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00248 int                     WM_gesture_lines_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00249 int                     WM_gesture_lines_cancel(struct bContext *C, struct wmOperator *op);
00250 int                     WM_gesture_lasso_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00251 int                     WM_gesture_lasso_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00252 int                     WM_gesture_lasso_cancel(struct bContext *C, struct wmOperator *op);
00253 int                     WM_gesture_straightline_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00254 int                     WM_gesture_straightline_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
00255 int                     WM_gesture_straightline_cancel(struct bContext *C, struct wmOperator *op);
00256 
00257                         /* default operator for arearegions, generates event */
00258 void            WM_OT_tweak_gesture(struct wmOperatorType *ot);
00259 
00260                         /* Gesture manager API */
00261 struct wmGesture *WM_gesture_new(struct bContext *C, struct wmEvent *event, int type);
00262 void            WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
00263 void            WM_gestures_remove(struct bContext *C);
00264 
00265                         /* fileselecting support */
00266 void            WM_event_add_fileselect(struct bContext *C, struct wmOperator *op);
00267 void            WM_event_fileselect_event(struct bContext *C, void *ophandle, int eventval);
00268 
00269                         /* drag and drop */
00270 struct wmDrag           *WM_event_start_drag(struct bContext *C, int icon, int type, void *poin, double value);
00271 void                            WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, int sy);
00272 
00273 struct wmDropBox        *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(struct bContext *, struct wmDrag *, struct wmEvent *event),
00274                                                   void (*copy)(struct wmDrag *, struct wmDropBox *));
00275 ListBase        *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
00276 
00277                         /* Set a subwindow active in pixelspace view, with optional scissor subset */
00278 void            wmSubWindowSet                  (struct wmWindow *win, int swinid);
00279 void            wmSubWindowScissorSet   (struct wmWindow *win, int swinid, struct rcti *srct);
00280 
00281                         /* OpenGL utilities with safety check + working in modelview matrix mode */
00282 void            wmFrustum                       (float x1, float x2, float y1, float y2, float n, float f);
00283 void            wmOrtho                         (float x1, float x2, float y1, float y2, float n, float f);
00284 void            wmOrtho2                        (float x1, float x2, float y1, float y2);
00285 
00286                         /* utilities */
00287 void            WM_set_framebuffer_index_color(int index);
00288 int                     WM_framebuffer_to_index(unsigned int col);
00289 
00290                         /* threaded Jobs Manager */
00291 #define WM_JOB_PRIORITY         1
00292 #define WM_JOB_EXCL_RENDER      2
00293 #define WM_JOB_PROGRESS         4
00294 #define WM_JOB_SUSPEND          8
00295 
00296 struct wmJob *WM_jobs_get(struct wmWindowManager *wm, struct wmWindow *win, void *owner, const char *name, int flag);
00297 
00298 int                     WM_jobs_test(struct wmWindowManager *wm, void *owner);
00299 float           WM_jobs_progress(struct wmWindowManager *wm, void *owner);
00300 char            *WM_jobs_name(struct wmWindowManager *wm, void *owner);
00301 
00302 void            WM_jobs_customdata(struct wmJob *, void *customdata, void (*free)(void *));
00303 void            WM_jobs_timer(struct wmJob *, double timestep, unsigned int note, unsigned int endnote);
00304 void            WM_jobs_callbacks(struct wmJob *, 
00305                                                           void (*startjob)(void *, short *, short *, float *),
00306                                                           void (*initjob)(void *),
00307                                                           void (*update)(void *),
00308                                                           void (*endjob)(void *));
00309 
00310 void            WM_jobs_start(struct wmWindowManager *wm, struct wmJob *);
00311 void            WM_jobs_stop(struct wmWindowManager *wm, void *owner, void *startjob);
00312 void            WM_jobs_kill(struct wmWindowManager *wm, void *owner, void (*)(void *, short int *, short int *, float *));
00313 void            WM_jobs_stop_all(struct wmWindowManager *wm);
00314 
00315                         /* clipboard */
00316 char            *WM_clipboard_text_get(int selection);
00317 void            WM_clipboard_text_set(char *buf, int selection);
00318 
00319                         /* progress */
00320 void            WM_progress_set(struct wmWindow *win, float progress);
00321 void            WM_progress_clear(struct wmWindow *win);
00322 
00323 #ifdef WIN32
00324                         /* Windows System Console */
00325 void            WM_console_toggle(struct bContext *C, short show);
00326 #endif
00327 
00328 /* debugging only, convenience function to write on crash */
00329 int write_crash_blend(void);
00330 
00331 #ifdef __cplusplus
00332 }
00333 #endif
00334 
00335 #endif /* WM_API_H */
00336