4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2007 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
30 #define _USE_MATH_DEFINES
37 #include "DNA_screen_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_userdef_types.h"
40 #include "DNA_windowmanager_types.h"
42 #include "MEM_guardedalloc.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_dynstr.h" /*for WM_operator_pystring */
49 #include "BKE_blender.h"
50 #include "BKE_context.h"
51 #include "BKE_idprop.h"
52 #include "BKE_library.h"
53 #include "BKE_global.h"
55 #include "BKE_scene.h"
56 #include "BKE_utildefines.h"
59 #include "BIF_glutil.h" /* for paint cursor */
61 #include "IMB_imbuf_types.h"
63 #include "ED_screen.h"
66 #include "RNA_access.h"
67 #include "RNA_define.h"
69 #include "UI_interface.h"
70 #include "UI_resources.h"
77 #include "wm_event_system.h"
78 #include "wm_subwindow.h"
79 #include "wm_window.h"
83 static ListBase global_ops= {NULL, NULL};
85 /* ************ operator API, exported ********** */
88 wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
92 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
93 WM_operator_bl_idname(idname_bl, idname);
95 for(ot= global_ops.first; ot; ot= ot->next) {
96 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
101 printf("search for unknown operator %s, %s\n", idname_bl, idname);
106 wmOperatorType *WM_operatortype_exists(const char *idname)
110 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
111 WM_operator_bl_idname(idname_bl, idname);
113 for(ot= global_ops.first; ot; ot= ot->next) {
114 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
120 wmOperatorType *WM_operatortype_first(void)
122 return global_ops.first;
125 /* all ops in 1 list (for time being... needs evaluation later) */
126 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
130 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
131 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
135 static char dummy_name[] = "Dummy Name";
136 fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
137 ot->name= dummy_name;
140 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:""); // XXX All ops should have a description but for now allow them not to.
141 RNA_def_struct_identifier(ot->srna, ot->idname);
142 BLI_addtail(&global_ops, ot);
145 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
149 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
150 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
151 opfunc(ot, userdata);
152 RNA_def_struct_ui_text(ot->srna, ot->name, "DOC_BROKEN"); /* TODO - add a discription to wmOperatorType? */
153 RNA_def_struct_identifier(ot->srna, ot->idname);
154 BLI_addtail(&global_ops, ot);
157 int WM_operatortype_remove(const char *idname)
159 wmOperatorType *ot = WM_operatortype_find(idname, 0);
164 BLI_remlink(&global_ops, ot);
165 RNA_struct_free(&BLENDER_RNA, ot->srna);
171 /* SOME_OT_op -> some.op */
172 void WM_operator_py_idname(char *to, const char *from)
174 char *sep= strstr(from, "_OT_");
176 int i, ofs= (sep-from);
179 to[i]= tolower(from[i]);
182 BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
185 /* should not happen but support just incase */
186 BLI_strncpy(to, from, OP_MAX_TYPENAME);
190 /* some.op -> SOME_OT_op */
191 void WM_operator_bl_idname(char *to, const char *from)
193 char *sep= strstr(from, ".");
196 int i, ofs= (sep-from);
199 to[i]= toupper(from[i]);
201 BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
202 BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
205 /* should not happen but support just incase */
206 BLI_strncpy(to, from, OP_MAX_TYPENAME);
210 /* print a string representation of the operator, with the args that it runs
211 * so python can run it again */
212 char *WM_operator_pystring(wmOperator *op)
214 const char *arg_name= NULL;
215 char idname_py[OP_MAX_TYPENAME];
217 PropertyRNA *prop, *iterprop;
219 /* for building the string */
220 DynStr *dynstr= BLI_dynstr_new();
224 WM_operator_py_idname(idname_py, op->idname);
225 BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
227 iterprop= RNA_struct_iterator_property(op->ptr->type);
229 RNA_PROP_BEGIN(op->ptr, propptr, iterprop) {
231 arg_name= RNA_property_identifier(prop);
233 if (strcmp(arg_name, "rna_type")==0) continue;
235 buf= RNA_property_as_string(op->ptr, prop);
237 BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
244 BLI_dynstr_append(dynstr, ")");
246 cstring = BLI_dynstr_get_cstring(dynstr);
247 BLI_dynstr_free(dynstr);
251 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
253 wmOperatorType *ot= WM_operatortype_find(opstring, 0);
256 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
258 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
261 void WM_operator_properties_free(PointerRNA *ptr)
263 IDProperty *properties= ptr->data;
266 IDP_FreeProperty(properties);
267 MEM_freeN(properties);
271 /* ************ default op callbacks, exported *********** */
273 /* invoke callback, uses enum property named "type" */
274 /* only weak thing is the fixed property name... */
275 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
277 PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type");
282 printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname);
284 else if (RNA_property_type(prop) != PROP_ENUM) {
285 printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname);
288 pup= uiPupMenuBegin(C, op->type->name, 0);
289 layout= uiPupMenuLayout(pup);
290 uiItemsEnumO(layout, op->type->idname, "type");
291 uiPupMenuEnd(C, pup);
294 return OPERATOR_CANCELLED;
298 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
303 pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
304 layout= uiPupMenuLayout(pup);
305 uiItemO(layout, NULL, 0, op->type->idname);
306 uiPupMenuEnd(C, pup);
308 return OPERATOR_CANCELLED;
311 /* op->invoke, opens fileselect if filename property not set, otherwise executes */
312 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
314 if (RNA_property_is_set(op->ptr, "filename")) {
315 return WM_operator_call(C, op);
318 WM_event_add_fileselect(C, op);
319 return OPERATOR_RUNNING_MODAL;
324 int WM_operator_winactive(bContext *C)
326 if(CTX_wm_window(C)==NULL) return 0;
331 static void redo_cb(bContext *C, void *arg_op, void *arg2)
333 wmOperator *lastop= arg_op;
337 WM_operator_repeat(C, lastop);
341 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
343 wmWindowManager *wm= CTX_wm_manager(C);
344 wmOperator *op= arg_op;
348 uiStyle *style= U.uistyles.first;
350 block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
351 uiBlockClearFlag(block, UI_BLOCK_LOOP);
352 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
353 uiBlockSetFunc(block, redo_cb, arg_op, NULL);
355 if(!op->properties) {
356 IDPropertyTemplate val = {0};
357 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
360 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
361 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
362 uiDefAutoButsRNA(C, layout, &ptr, 2);
364 uiPopupBoundsBlock(block, 4.0f, 0, 0);
365 uiEndBlock(C, block);
370 int WM_operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
372 int retval= OPERATOR_CANCELLED;
375 retval= op->type->exec(C, op);
377 if(retval != OPERATOR_CANCELLED)
378 uiPupBlock(C, wm_block_create_redo, op);
383 int WM_operator_redo_popup(bContext *C, wmOperator *op)
385 uiPupBlock(C, wm_block_create_redo, op);
387 return OPERATOR_CANCELLED;
390 /* ***************** Debug menu ************************* */
392 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
394 wmOperator *op= arg_op;
397 uiStyle *style= U.uistyles.first;
399 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
400 uiBlockClearFlag(block, UI_BLOCK_LOOP);
401 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
403 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
404 uiDefAutoButsRNA(C, layout, op->ptr, 2);
406 uiPopupBoundsBlock(block, 4.0f, 0, 0);
407 uiEndBlock(C, block);
412 static int wm_debug_menu_exec(bContext *C, wmOperator *op)
414 G.rt= RNA_int_get(op->ptr, "debugval");
415 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
416 WM_event_add_notifier(C, NC_WINDOW, NULL);
418 return OPERATOR_FINISHED;
421 static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
424 RNA_int_set(op->ptr, "debugval", G.rt);
426 /* pass on operator, so return modal */
427 uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
429 return OPERATOR_RUNNING_MODAL;
432 static void WM_OT_debug_menu(wmOperatorType *ot)
434 ot->name= "Debug Menu";
435 ot->idname= "WM_OT_debug_menu";
437 ot->invoke= wm_debug_menu_invoke;
438 ot->exec= wm_debug_menu_exec;
439 ot->poll= WM_operator_winactive;
441 RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
444 /* ***************** Search menu ************************* */
445 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
447 wmOperatorType *ot= arg2;
450 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
453 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
455 wmOperatorType *ot = WM_operatortype_first();
457 for(; ot; ot= ot->next) {
459 if(BLI_strcasestr(ot->name, str)) {
460 if(ot->poll==NULL || ot->poll((bContext *)C)) {
462 int len= strlen(ot->name);
464 /* display name for menu, can hold hotkey */
465 BLI_strncpy(name, ot->name, 256);
467 /* check for hotkey */
469 if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
473 if(0==uiSearchItemAdd(items, name, ot, 0))
480 static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
482 static char search[256]= "";
484 wmWindow *win= CTX_wm_window(C);
488 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
489 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1);
491 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, "");
492 uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
494 /* fake button, it holds space for search items */
495 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
497 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
498 uiEndBlock(C, block);
500 event= *(win->eventstate); /* XXX huh huh? make api call */
501 event.type= EVT_BUT_OPEN;
503 event.customdata= but;
504 event.customdatafree= FALSE;
505 wm_event_add(win, &event);
510 static int wm_search_menu_exec(bContext *C, wmOperator *op)
513 return OPERATOR_FINISHED;
516 static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
519 uiPupBlock(C, wm_block_search_menu, op);
521 return OPERATOR_CANCELLED;
524 static void WM_OT_search_menu(wmOperatorType *ot)
526 ot->name= "Search Menu";
527 ot->idname= "WM_OT_search_menu";
529 ot->invoke= wm_search_menu_invoke;
530 ot->exec= wm_search_menu_exec;
531 ot->poll= WM_operator_winactive;
535 /* ************ window / screen operator definitions ************** */
537 static void WM_OT_window_duplicate(wmOperatorType *ot)
539 ot->name= "Duplicate Window";
540 ot->idname= "WM_OT_window_duplicate";
542 ot->invoke= WM_operator_confirm;
543 ot->exec= wm_window_duplicate_op;
544 ot->poll= WM_operator_winactive;
547 static void WM_OT_save_homefile(wmOperatorType *ot)
549 ot->name= "Save User Settings";
550 ot->idname= "WM_OT_save_homefile";
552 ot->invoke= WM_operator_confirm;
553 ot->exec= WM_write_homefile;
554 ot->poll= WM_operator_winactive;
557 static void WM_OT_read_homefile(wmOperatorType *ot)
559 ot->name= "Reload Start-Up File";
560 ot->idname= "WM_OT_read_homefile";
562 ot->invoke= WM_operator_confirm;
563 ot->exec= WM_read_homefile;
564 ot->poll= WM_operator_winactive;
566 RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
570 /* ********* recent file *********** */
572 static int recentfile_exec(bContext *C, wmOperator *op)
574 int event= RNA_enum_get(op->ptr, "file");
576 // XXX wm in context is not set correctly after WM_read_file -> crash
577 // do it before for now, but is this correct with multiple windows?
580 if (G.sce[0] && (event==1)) {
581 WM_event_add_notifier(C, NC_WINDOW, NULL);
582 WM_read_file(C, G.sce, op->reports);
585 struct RecentFile *recent = BLI_findlink(&(G.recent_files), event-2);
587 WM_event_add_notifier(C, NC_WINDOW, NULL);
588 WM_read_file(C, recent->filename, op->reports);
595 static int wm_recentfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
600 pup= uiPupMenuBegin(C, "Open Recent", 0);
601 layout= uiPupMenuLayout(pup);
602 uiItemsEnumO(layout, op->type->idname, "file");
603 uiPupMenuEnd(C, pup);
605 return OPERATOR_CANCELLED;
608 static EnumPropertyItem *open_recentfile_itemf(bContext *C, PointerRNA *ptr, int *free)
610 EnumPropertyItem tmp = {0, "", 0, "", ""};
611 EnumPropertyItem *item= NULL;
612 struct RecentFile *recent;
613 int totitem= 0, i, ofs= 0;
617 tmp.identifier= G.sce;
619 RNA_enum_item_add(&item, &totitem, &tmp);
623 /* dynamically construct enum */
624 for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
625 if(strcmp(recent->filename, G.sce)) {
627 tmp.identifier= recent->filename;
628 tmp.name= recent->filename;
629 RNA_enum_item_add(&item, &totitem, &tmp);
633 RNA_enum_item_end(&item, &totitem);
639 static void WM_OT_open_recentfile(wmOperatorType *ot)
642 static EnumPropertyItem file_items[]= {
643 {0, NULL, 0, NULL, NULL}};
645 ot->name= "Open Recent File";
646 ot->idname= "WM_OT_open_recentfile";
648 ot->invoke= wm_recentfile_invoke;
649 ot->exec= recentfile_exec;
650 ot->poll= WM_operator_winactive;
652 prop= RNA_def_enum(ot->srna, "file", file_items, 1, "File", "");
653 RNA_def_enum_funcs(prop, open_recentfile_itemf);
656 /* ********* main file *********** */
658 static void untitled(char *name)
660 if (G.save_over == 0 && strlen(name) < FILE_MAX-16) {
661 char *c= BLI_last_slash(name);
664 strcpy(&c[1], "untitled.blend");
666 strcpy(name, "untitled.blend");
671 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
674 RNA_string_set(op->ptr, "filename", G.sce);
675 WM_event_add_fileselect(C, op);
677 return OPERATOR_RUNNING_MODAL;
680 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
682 char filename[FILE_MAX];
683 RNA_string_get(op->ptr, "filename", filename);
685 // XXX wm in context is not set correctly after WM_read_file -> crash
686 // do it before for now, but is this correct with multiple windows?
687 WM_event_add_notifier(C, NC_WINDOW, NULL);
689 WM_read_file(C, filename, op->reports);
694 static void WM_OT_open_mainfile(wmOperatorType *ot)
696 ot->name= "Open Blender File";
697 ot->idname= "WM_OT_open_mainfile";
699 ot->invoke= wm_open_mainfile_invoke;
700 ot->exec= wm_open_mainfile_exec;
701 ot->poll= WM_operator_winactive;
703 RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
706 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
708 char scestr[FILE_MAX], filename[FILE_MAX];
711 /* back up some values */
712 BLI_strncpy(scestr, G.sce, sizeof(scestr));
713 save_over = G.save_over;
715 // XXX wm in context is not set correctly after WM_read_file -> crash
716 // do it before for now, but is this correct with multiple windows?
717 WM_event_add_notifier(C, NC_WINDOW, NULL);
720 BLI_make_file_string("/", filename, btempdir, "quit.blend");
721 WM_read_file(C, filename, op->reports);
724 G.save_over = save_over;
725 BLI_strncpy(G.sce, scestr, sizeof(G.sce));
730 static void WM_OT_recover_last_session(wmOperatorType *ot)
732 ot->name= "Recover Last Session";
733 ot->idname= "WM_OT_recover_last_session";
735 ot->exec= wm_recover_last_session_exec;
736 ot->poll= WM_operator_winactive;
739 static void save_set_compress(wmOperator *op)
741 if(!RNA_property_is_set(op->ptr, "compress")) {
742 if(G.save_over) /* keep flag for existing file */
743 RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
744 else /* use userdef for new file */
745 RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
749 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
753 save_set_compress(op);
755 BLI_strncpy(name, G.sce, FILE_MAX);
757 RNA_string_set(op->ptr, "filename", name);
759 WM_event_add_fileselect(C, op);
761 return OPERATOR_RUNNING_MODAL;
764 /* function used for WM_OT_save_mainfile too */
765 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
767 char filename[FILE_MAX];
770 save_set_compress(op);
771 compress= RNA_boolean_get(op->ptr, "compress");
773 if(RNA_property_is_set(op->ptr, "filename"))
774 RNA_string_get(op->ptr, "filename", filename);
776 BLI_strncpy(filename, G.sce, FILE_MAX);
780 WM_write_file(C, filename, compress, op->reports);
782 WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
787 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
789 ot->name= "Save As Blender File";
790 ot->idname= "WM_OT_save_as_mainfile";
792 ot->invoke= wm_save_as_mainfile_invoke;
793 ot->exec= wm_save_as_mainfile_exec;
794 ot->poll= WM_operator_winactive;
796 RNA_def_string_file_path(ot->srna, "filename", "", 0, "Filename", "");
797 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
800 /* *************** Save file directly ******** */
802 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
806 save_set_compress(op);
808 BLI_strncpy(name, G.sce, FILE_MAX);
810 RNA_string_set(op->ptr, "filename", name);
811 uiPupMenuSaveOver(C, op, name);
813 return OPERATOR_RUNNING_MODAL;
816 static void WM_OT_save_mainfile(wmOperatorType *ot)
818 ot->name= "Save Blender File";
819 ot->idname= "WM_OT_save_mainfile";
821 ot->invoke= wm_save_mainfile_invoke;
822 ot->exec= wm_save_as_mainfile_exec;
823 ot->poll= WM_operator_winactive;
825 RNA_def_string_file_path(ot->srna, "filename", "", 0, "Filename", "");
826 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
830 /* *********************** */
832 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
834 ot->name= "Toggle Fullscreen";
835 ot->idname= "WM_OT_window_fullscreen_toggle";
837 ot->invoke= WM_operator_confirm;
838 ot->exec= wm_window_fullscreen_toggle_op;
839 ot->poll= WM_operator_winactive;
842 static int wm_exit_blender_op(bContext *C, wmOperator *op)
844 WM_operator_free(op);
848 return OPERATOR_FINISHED;
851 static void WM_OT_exit_blender(wmOperatorType *ot)
853 ot->name= "Exit Blender";
854 ot->idname= "WM_OT_exit_blender";
856 ot->invoke= WM_operator_confirm;
857 ot->exec= wm_exit_blender_op;
858 ot->poll= WM_operator_winactive;
861 /* ************ default paint cursors, draw always around cursor *********** */
863 - returns handler to free
864 - poll(bContext): returns 1 if draw should happen
865 - draw(bContext): drawing callback for paint cursor
868 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
869 void (*draw)(bContext *C, int, int, void *customdata), void *customdata)
871 wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
873 BLI_addtail(&wm->paintcursors, pc);
875 pc->customdata = customdata;
882 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
886 for(pc= wm->paintcursors.first; pc; pc= pc->next) {
887 if(pc == (wmPaintCursor *)handle) {
888 BLI_remlink(&wm->paintcursors, pc);
895 /* ************ window gesture operator-callback definitions ************** */
897 * These are default callbacks for use in operators requiring gesture input
900 /* **************** Border gesture *************** */
902 /* Border gesture has two types:
903 1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border
904 2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
906 It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
909 static int border_apply(bContext *C, wmOperator *op, int event_type, int event_orig)
911 wmGesture *gesture= op->customdata;
912 rcti *rect= gesture->customdata;
914 if(rect->xmin > rect->xmax)
915 SWAP(int, rect->xmin, rect->xmax);
916 if(rect->ymin > rect->ymax)
917 SWAP(int, rect->ymin, rect->ymax);
919 if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
922 /* operator arguments and storage. */
923 RNA_int_set(op->ptr, "xmin", rect->xmin);
924 RNA_int_set(op->ptr, "ymin", rect->ymin);
925 RNA_int_set(op->ptr, "xmax", rect->xmax);
926 RNA_int_set(op->ptr, "ymax", rect->ymax);
928 /* XXX weak; border should be configured for this without reading event types */
929 if( RNA_struct_find_property(op->ptr, "event_type") ) {
930 if(ELEM4(event_orig, EVT_TWEAK_L, EVT_TWEAK_R, EVT_TWEAK_A, EVT_TWEAK_S))
931 event_type= LEFTMOUSE;
933 RNA_int_set(op->ptr, "event_type", event_type);
935 op->type->exec(C, op);
940 static void wm_gesture_end(bContext *C, wmOperator *op)
942 wmGesture *gesture= op->customdata;
944 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
945 op->customdata= NULL;
947 ED_area_tag_redraw(CTX_wm_area(C));
949 if( RNA_struct_find_property(op->ptr, "cursor") )
950 WM_cursor_restore(CTX_wm_window(C));
953 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
955 if(WM_key_event_is_tweak(event->type))
956 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
958 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
960 /* add modal handler */
961 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
963 wm_gesture_tag_redraw(C);
965 return OPERATOR_RUNNING_MODAL;
968 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
970 wmGesture *gesture= op->customdata;
971 rcti *rect= gesture->customdata;
974 switch(event->type) {
977 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
979 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
980 rect->xmin= rect->xmax= event->x - sx;
981 rect->ymin= rect->ymax= event->y - sy;
984 rect->xmax= event->x - sx;
985 rect->ymax= event->y - sy;
988 wm_gesture_tag_redraw(C);
995 if(event->val==KM_PRESS) {
996 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
998 wm_gesture_tag_redraw(C);
1002 if(border_apply(C, op, event->type, gesture->event_type)) {
1003 wm_gesture_end(C, op);
1004 return OPERATOR_FINISHED;
1006 wm_gesture_end(C, op);
1007 return OPERATOR_CANCELLED;
1011 wm_gesture_end(C, op);
1012 return OPERATOR_CANCELLED;
1014 return OPERATOR_RUNNING_MODAL;
1017 /* **************** circle gesture *************** */
1018 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
1020 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
1022 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
1024 /* add modal handler */
1025 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1027 wm_gesture_tag_redraw(C);
1029 return OPERATOR_RUNNING_MODAL;
1032 static void gesture_circle_apply(bContext *C, wmOperator *op)
1034 wmGesture *gesture= op->customdata;
1035 rcti *rect= gesture->customdata;
1037 /* operator arguments and storage. */
1038 RNA_int_set(op->ptr, "x", rect->xmin);
1039 RNA_int_set(op->ptr, "y", rect->ymin);
1040 RNA_int_set(op->ptr, "radius", rect->xmax);
1043 op->type->exec(C, op);
1046 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
1048 wmGesture *gesture= op->customdata;
1049 rcti *rect= gesture->customdata;
1052 switch(event->type) {
1055 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1057 rect->xmin= event->x - sx;
1058 rect->ymin= event->y - sy;
1060 wm_gesture_tag_redraw(C);
1063 gesture_circle_apply(C, op);
1067 rect->xmax += 2 + rect->xmax/10;
1068 wm_gesture_tag_redraw(C);
1070 case WHEELDOWNMOUSE:
1071 rect->xmax -= 2 + rect->xmax/10;
1072 if(rect->xmax < 1) rect->xmax= 1;
1073 wm_gesture_tag_redraw(C);
1078 if(event->val==0) { /* key release */
1079 wm_gesture_end(C, op);
1080 return OPERATOR_FINISHED;
1083 if( RNA_struct_find_property(op->ptr, "event_type") )
1084 RNA_int_set(op->ptr, "event_type", event->type);
1086 /* apply first click */
1087 gesture_circle_apply(C, op);
1092 wm_gesture_end(C, op);
1093 return OPERATOR_CANCELLED;
1095 return OPERATOR_RUNNING_MODAL;
1099 /* template to copy from */
1100 void WM_OT_circle_gesture(wmOperatorType *ot)
1102 ot->name= "Circle Gesture";
1103 ot->idname= "WM_OT_circle_gesture";
1105 ot->invoke= WM_gesture_circle_invoke;
1106 ot->modal= WM_gesture_circle_modal;
1108 ot->poll= WM_operator_winactive;
1110 RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
1111 RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
1112 RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
1117 /* **************** Tweak gesture *************** */
1119 static void tweak_gesture_modal(bContext *C, wmEvent *event)
1121 wmWindow *window= CTX_wm_window(C);
1122 wmGesture *gesture= window->tweak;
1123 rcti *rect= gesture->customdata;
1126 switch(event->type) {
1129 wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
1131 rect->xmax= event->x - sx;
1132 rect->ymax= event->y - sy;
1134 if((val= wm_gesture_evaluate(C, gesture))) {
1137 event= *(window->eventstate);
1138 if(gesture->event_type==LEFTMOUSE)
1139 event.type= EVT_TWEAK_L;
1140 else if(gesture->event_type==RIGHTMOUSE)
1141 event.type= EVT_TWEAK_R;
1143 event.type= EVT_TWEAK_M;
1146 wm_event_add(window, &event);
1148 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
1149 window->tweak= NULL;
1157 if(gesture->event_type==event->type) {
1158 WM_gesture_end(C, gesture);
1159 window->tweak= NULL;
1161 /* when tweak fails we should give the other keymap entries a chance */
1162 event->val= KM_RELEASE;
1166 WM_gesture_end(C, gesture);
1167 window->tweak= NULL;
1171 /* standard tweak, called after window handlers passed on event */
1172 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
1174 wmWindow *win= CTX_wm_window(C);
1176 if(win->tweak==NULL) {
1177 if(CTX_wm_region(C)) {
1178 if(event->val) { // pressed
1179 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
1180 win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
1185 if(action==WM_HANDLER_BREAK) {
1186 WM_gesture_end(C, win->tweak);
1190 tweak_gesture_modal(C, event);
1194 /* *********************** lasso gesture ****************** */
1196 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
1198 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
1200 /* add modal handler */
1201 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1203 wm_gesture_tag_redraw(C);
1205 if( RNA_struct_find_property(op->ptr, "cursor") )
1206 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1208 return OPERATOR_RUNNING_MODAL;
1211 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
1213 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
1215 /* add modal handler */
1216 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1218 wm_gesture_tag_redraw(C);
1220 if( RNA_struct_find_property(op->ptr, "cursor") )
1221 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1223 return OPERATOR_RUNNING_MODAL;
1227 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
1229 wmGesture *gesture= op->customdata;
1233 short *lasso= gesture->customdata;
1235 /* operator storage as path. */
1237 for(i=0; i<gesture->points; i++, lasso+=2) {
1240 RNA_collection_add(op->ptr, "path", &itemptr);
1241 RNA_float_set_array(&itemptr, "loc", loc);
1244 wm_gesture_end(C, op);
1247 op->type->exec(C, op);
1251 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
1253 wmGesture *gesture= op->customdata;
1256 switch(event->type) {
1259 wm_gesture_tag_redraw(C);
1261 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1262 if(gesture->points < WM_LASSO_MAX_POINTS) {
1263 short *lasso= gesture->customdata;
1264 lasso += 2 * gesture->points;
1265 lasso[0] = event->x - sx;
1266 lasso[1] = event->y - sy;
1270 gesture_lasso_apply(C, op, event->type);
1271 return OPERATOR_FINISHED;
1278 if(event->val==0) { /* key release */
1279 gesture_lasso_apply(C, op, event->type);
1280 return OPERATOR_FINISHED;
1284 wm_gesture_end(C, op);
1285 return OPERATOR_CANCELLED;
1287 return OPERATOR_RUNNING_MODAL;
1290 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
1292 return WM_gesture_lasso_modal(C, op, event);
1296 /* template to copy from */
1298 static int gesture_lasso_exec(bContext *C, wmOperator *op)
1300 RNA_BEGIN(op->ptr, itemptr, "path") {
1303 RNA_float_get_array(&itemptr, "loc", loc);
1304 printf("Location: %f %f\n", loc[0], loc[1]);
1308 return OPERATOR_FINISHED;
1311 void WM_OT_lasso_gesture(wmOperatorType *ot)
1315 ot->name= "Lasso Gesture";
1316 ot->idname= "WM_OT_lasso_gesture";
1318 ot->invoke= WM_gesture_lasso_invoke;
1319 ot->modal= WM_gesture_lasso_modal;
1320 ot->exec= gesture_lasso_exec;
1322 ot->poll= WM_operator_winactive;
1324 prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
1325 RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
1329 /* *********************** radial control ****************** */
1331 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
1333 typedef struct wmRadialControl {
1335 float initial_value, value, max_value;
1336 int initial_mouse[2];
1341 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
1343 wmRadialControl *rc = (wmRadialControl*)customdata;
1344 ARegion *ar = CTX_wm_region(C);
1345 float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
1347 /* Keep cursor in the original place */
1348 x = rc->initial_mouse[0] - ar->winrct.xmin;
1349 y = rc->initial_mouse[1] - ar->winrct.ymin;
1353 glTranslatef((float)x, (float)y, 0.0f);
1355 if(rc->mode == WM_RADIALCONTROL_SIZE) {
1357 r2= rc->initial_value;
1359 } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
1360 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
1361 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1362 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1363 } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1364 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1365 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1369 glColor4ub(255, 255, 255, 128);
1370 glEnable( GL_LINE_SMOOTH );
1373 if(rc->mode == WM_RADIALCONTROL_ANGLE)
1374 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1377 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
1379 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1380 glRotatef(angle, 0, 0, 1);
1381 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1384 glBindTexture(GL_TEXTURE_2D, rc->tex);
1386 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1387 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1389 glEnable(GL_TEXTURE_2D);
1391 glColor4f(0,0,0, str);
1393 glVertex2f(-r3, -r3);
1395 glVertex2f(r3, -r3);
1399 glVertex2f(-r3, r3);
1401 glDisable(GL_TEXTURE_2D);
1404 glColor4ub(255, 255, 255, 128);
1405 glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
1406 glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
1407 glDisable(GL_BLEND);
1408 glDisable( GL_LINE_SMOOTH );
1413 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
1415 wmRadialControl *rc = (wmRadialControl*)op->customdata;
1416 int mode, initial_mouse[2], delta[2];
1418 double new_value = RNA_float_get(op->ptr, "new_value");
1419 int ret = OPERATOR_RUNNING_MODAL;
1421 mode = RNA_int_get(op->ptr, "mode");
1422 RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
1424 switch(event->type) {
1426 delta[0]= initial_mouse[0] - event->x;
1427 delta[1]= initial_mouse[1] - event->y;
1428 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
1430 if(mode == WM_RADIALCONTROL_SIZE)
1432 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1433 new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
1434 } else if(mode == WM_RADIALCONTROL_ANGLE)
1435 new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
1438 if(mode == WM_RADIALCONTROL_STRENGTH)
1439 new_value = ((int)(new_value * 100) / 10*10) / 100.0f;
1441 new_value = ((int)new_value + 5) / 10*10;
1447 ret = OPERATOR_CANCELLED;
1451 op->type->exec(C, op);
1452 ret = OPERATOR_FINISHED;
1457 if(new_value > rc->max_value)
1458 new_value = rc->max_value;
1459 else if(new_value < 0)
1462 /* Update paint data */
1463 rc->value = new_value;
1465 RNA_float_set(op->ptr, "new_value", new_value);
1467 if(ret != OPERATOR_RUNNING_MODAL) {
1468 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
1472 ED_region_tag_redraw(CTX_wm_region(C));
1477 /* Expects the operator customdata to be an ImBuf (or NULL) */
1478 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
1480 wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
1481 int mode = RNA_int_get(op->ptr, "mode");
1482 float initial_value = RNA_float_get(op->ptr, "initial_value");
1483 int mouse[2] = {event->x, event->y};
1485 if(mode == WM_RADIALCONTROL_SIZE) {
1486 rc->max_value = 200;
1487 mouse[0]-= initial_value;
1489 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1491 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
1493 else if(mode == WM_RADIALCONTROL_ANGLE) {
1494 rc->max_value = 360;
1495 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
1496 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
1497 initial_value *= 180.0f/M_PI;
1500 if(op->customdata) {
1501 ImBuf *im = (ImBuf*)op->customdata;
1502 /* Build GL texture */
1503 glGenTextures(1, &rc->tex);
1504 glBindTexture(GL_TEXTURE_2D, rc->tex);
1505 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
1506 MEM_freeN(im->rect_float);
1510 RNA_int_set_array(op->ptr, "initial_mouse", mouse);
1511 RNA_float_set(op->ptr, "new_value", initial_value);
1513 op->customdata = rc;
1515 rc->initial_value = initial_value;
1516 rc->initial_mouse[0] = mouse[0];
1517 rc->initial_mouse[1] = mouse[1];
1518 rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
1519 wm_radial_control_paint, op->customdata);
1521 /* add modal handler */
1522 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1524 WM_radial_control_modal(C, op, event);
1526 return OPERATOR_RUNNING_MODAL;
1529 /* Gets a descriptive string of the operation */
1530 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
1532 int mode = RNA_int_get(op->ptr, "mode");
1533 float v = RNA_float_get(op->ptr, "new_value");
1535 if(mode == WM_RADIALCONTROL_SIZE)
1536 sprintf(str, "Size: %d", (int)v);
1537 else if(mode == WM_RADIALCONTROL_STRENGTH)
1538 sprintf(str, "Strength: %d", (int)v);
1539 else if(mode == WM_RADIALCONTROL_ANGLE)
1540 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
1543 /** Important: this doesn't define an actual operator, it
1544 just sets up the common parts of the radial control op. **/
1545 void WM_OT_radial_control_partial(wmOperatorType *ot)
1547 static EnumPropertyItem prop_mode_items[] = {
1548 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
1549 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
1550 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
1551 {0, NULL, 0, NULL, NULL}};
1553 /* Should be set in custom invoke() */
1554 RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
1556 /* Set internally, should be used in custom exec() to get final value */
1557 RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
1559 /* Should be set before calling operator */
1560 RNA_def_enum(ot->srna, "mode", prop_mode_items, 0, "Mode", "");
1563 RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
1566 /* ************************** timer for testing ***************** */
1568 /* uses no type defines, fully local testing function anyway... ;) */
1570 static int ten_timer_exec(bContext *C, wmOperator *op)
1572 ARegion *ar= CTX_wm_region(C);
1573 double stime= PIL_check_seconds_timer();
1574 int type = RNA_int_get(op->ptr, "type");
1580 for(a=0; a<10; a++) {
1582 ED_region_do_draw(C, ar);
1585 wmWindow *win= CTX_wm_window(C);
1587 ED_region_tag_redraw(ar);
1590 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
1593 wmWindow *win= CTX_wm_window(C);
1596 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
1597 ED_area_tag_redraw(sa);
1600 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
1603 Scene *scene= CTX_data_scene(C);
1605 if(a & 1) scene->r.cfra--;
1606 else scene->r.cfra++;
1607 scene_update_for_newframe(scene, scene->lay);
1615 time= (int) ((PIL_check_seconds_timer()-stime)*1000);
1617 if(type==0) sprintf(tmpstr, "10 x Draw Region: %d ms", time);
1618 if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time);
1619 if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time);
1620 if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time);
1621 if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time);
1625 uiPupMenuNotice(C, tmpstr);
1627 return OPERATOR_FINISHED;
1630 static void WM_OT_ten_timer(wmOperatorType *ot)
1632 static EnumPropertyItem prop_type_items[] = {
1633 {0, "DRAW", 0, "Draw Region", ""},
1634 {1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
1635 {2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
1636 {3, "ANIMSTEP", 0, "Anim Step", ""},
1637 {4, "UNDO", 0, "Undo/Redo", ""},
1638 {0, NULL, 0, NULL, NULL}};
1640 ot->name= "Ten Timer";
1641 ot->idname= "WM_OT_ten_timer";
1643 ot->invoke= WM_menu_invoke;
1644 ot->exec= ten_timer_exec;
1645 ot->poll= WM_operator_winactive;
1647 RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
1653 /* ******************************************************* */
1655 /* called on initialize WM_exit() */
1656 void wm_operatortype_free(void)
1658 BLI_freelistN(&global_ops);
1661 /* called on initialize WM_init() */
1662 void wm_operatortype_init(void)
1664 WM_operatortype_append(WM_OT_window_duplicate);
1665 WM_operatortype_append(WM_OT_read_homefile);
1666 WM_operatortype_append(WM_OT_save_homefile);
1667 WM_operatortype_append(WM_OT_window_fullscreen_toggle);
1668 WM_operatortype_append(WM_OT_exit_blender);
1669 WM_operatortype_append(WM_OT_open_recentfile);
1670 WM_operatortype_append(WM_OT_open_mainfile);
1671 WM_operatortype_append(WM_OT_recover_last_session);
1672 WM_operatortype_append(WM_OT_jobs_timer);
1673 WM_operatortype_append(WM_OT_save_as_mainfile);
1674 WM_operatortype_append(WM_OT_save_mainfile);
1675 WM_operatortype_append(WM_OT_ten_timer);
1676 WM_operatortype_append(WM_OT_debug_menu);
1677 WM_operatortype_append(WM_OT_search_menu);
1680 /* default keymap for windows and screens, only call once per WM */
1681 void wm_window_keymap(wmWindowManager *wm)
1683 ListBase *keymap= WM_keymap_listbase(wm, "Window", 0, 0);
1685 /* items to make WM work */
1686 WM_keymap_verify_item(keymap, "WM_OT_jobs_timer", TIMERJOBS, KM_ANY, KM_ANY, 0);
1688 /* note, this doesn't replace existing keymap items */
1689 WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
1690 WM_keymap_verify_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0);
1691 WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
1692 WM_keymap_verify_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_CTRL, 0);
1693 WM_keymap_verify_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
1694 WM_keymap_verify_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
1695 WM_keymap_verify_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
1696 WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_SHIFT, 0);
1697 WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
1700 WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1701 WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1702 WM_keymap_verify_item(keymap, "WM_OT_search_menu", FKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);