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:"(undocumented operator)"); // 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, ot->description ? ot->description:"(undocumented operator)");
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;
525 int wm_search_menu_poll(bContext *C)
527 if(CTX_wm_window(C)==NULL) return 0;
528 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_CONSOLE) return 0; // XXX - so we can use the shortcut in the console
532 static void WM_OT_search_menu(wmOperatorType *ot)
534 ot->name= "Search Menu";
535 ot->idname= "WM_OT_search_menu";
537 ot->invoke= wm_search_menu_invoke;
538 ot->exec= wm_search_menu_exec;
539 ot->poll= wm_search_menu_poll;
543 /* ************ window / screen operator definitions ************** */
545 static void WM_OT_window_duplicate(wmOperatorType *ot)
547 ot->name= "Duplicate Window";
548 ot->idname= "WM_OT_window_duplicate";
550 ot->invoke= WM_operator_confirm;
551 ot->exec= wm_window_duplicate_op;
552 ot->poll= WM_operator_winactive;
555 static void WM_OT_save_homefile(wmOperatorType *ot)
557 ot->name= "Save User Settings";
558 ot->idname= "WM_OT_save_homefile";
560 ot->invoke= WM_operator_confirm;
561 ot->exec= WM_write_homefile;
562 ot->poll= WM_operator_winactive;
565 static void WM_OT_read_homefile(wmOperatorType *ot)
567 ot->name= "Reload Start-Up File";
568 ot->idname= "WM_OT_read_homefile";
570 ot->invoke= WM_operator_confirm;
571 ot->exec= WM_read_homefile;
572 ot->poll= WM_operator_winactive;
574 RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
578 /* ********* recent file *********** */
580 static int recentfile_exec(bContext *C, wmOperator *op)
582 int event= RNA_enum_get(op->ptr, "file");
584 // XXX wm in context is not set correctly after WM_read_file -> crash
585 // do it before for now, but is this correct with multiple windows?
588 if (G.sce[0] && (event==1)) {
589 WM_event_add_notifier(C, NC_WINDOW, NULL);
590 WM_read_file(C, G.sce, op->reports);
593 struct RecentFile *recent = BLI_findlink(&(G.recent_files), event-2);
595 WM_event_add_notifier(C, NC_WINDOW, NULL);
596 WM_read_file(C, recent->filename, op->reports);
603 static int wm_recentfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
608 pup= uiPupMenuBegin(C, "Open Recent", 0);
609 layout= uiPupMenuLayout(pup);
610 uiItemsEnumO(layout, op->type->idname, "file");
611 uiPupMenuEnd(C, pup);
613 return OPERATOR_CANCELLED;
616 static EnumPropertyItem *open_recentfile_itemf(bContext *C, PointerRNA *ptr, int *free)
618 EnumPropertyItem tmp = {0, "", 0, "", ""};
619 EnumPropertyItem *item= NULL;
620 struct RecentFile *recent;
621 int totitem= 0, i, ofs= 0;
625 tmp.identifier= G.sce;
627 RNA_enum_item_add(&item, &totitem, &tmp);
631 /* dynamically construct enum */
632 for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
633 if(strcmp(recent->filename, G.sce)) {
635 tmp.identifier= recent->filename;
636 tmp.name= recent->filename;
637 RNA_enum_item_add(&item, &totitem, &tmp);
641 RNA_enum_item_end(&item, &totitem);
647 static void WM_OT_open_recentfile(wmOperatorType *ot)
650 static EnumPropertyItem file_items[]= {
651 {0, NULL, 0, NULL, NULL}};
653 ot->name= "Open Recent File";
654 ot->idname= "WM_OT_open_recentfile";
656 ot->invoke= wm_recentfile_invoke;
657 ot->exec= recentfile_exec;
658 ot->poll= WM_operator_winactive;
660 prop= RNA_def_enum(ot->srna, "file", file_items, 1, "File", "");
661 RNA_def_enum_funcs(prop, open_recentfile_itemf);
664 /* ********* main file *********** */
666 static void untitled(char *name)
668 if (G.save_over == 0 && strlen(name) < FILE_MAX-16) {
669 char *c= BLI_last_slash(name);
672 strcpy(&c[1], "untitled.blend");
674 strcpy(name, "untitled.blend");
679 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
682 RNA_string_set(op->ptr, "filename", G.sce);
683 RNA_boolean_set(op->ptr, "filter_blender", 1);
684 RNA_boolean_set(op->ptr, "filter_folder", 1);
685 WM_event_add_fileselect(C, op);
687 return OPERATOR_RUNNING_MODAL;
690 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
692 char filename[FILE_MAX];
693 RNA_string_get(op->ptr, "filename", filename);
695 // XXX wm in context is not set correctly after WM_read_file -> crash
696 // do it before for now, but is this correct with multiple windows?
697 WM_event_add_notifier(C, NC_WINDOW, NULL);
699 WM_read_file(C, filename, op->reports);
704 static void WM_OT_open_mainfile(wmOperatorType *ot)
707 ot->name= "Open Blender File";
708 ot->idname= "WM_OT_open_mainfile";
710 ot->invoke= wm_open_mainfile_invoke;
711 ot->exec= wm_open_mainfile_exec;
712 ot->poll= WM_operator_winactive;
714 RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path of blendfile to open.");
716 prop= RNA_def_boolean(ot->srna, "filter_blender", 0, "Filter Blendfiles", "");
717 RNA_def_property_boolean_sdna(prop, NULL, "filter", BLENDERFILE);
718 prop= RNA_def_boolean(ot->srna, "filter_folder", 0, "Filter Blendfiles", "");
719 RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE);
723 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
725 char scestr[FILE_MAX], filename[FILE_MAX];
728 /* back up some values */
729 BLI_strncpy(scestr, G.sce, sizeof(scestr));
730 save_over = G.save_over;
732 // XXX wm in context is not set correctly after WM_read_file -> crash
733 // do it before for now, but is this correct with multiple windows?
734 WM_event_add_notifier(C, NC_WINDOW, NULL);
737 BLI_make_file_string("/", filename, btempdir, "quit.blend");
738 WM_read_file(C, filename, op->reports);
741 G.save_over = save_over;
742 BLI_strncpy(G.sce, scestr, sizeof(G.sce));
747 static void WM_OT_recover_last_session(wmOperatorType *ot)
749 ot->name= "Recover Last Session";
750 ot->idname= "WM_OT_recover_last_session";
752 ot->exec= wm_recover_last_session_exec;
753 ot->poll= WM_operator_winactive;
756 static void save_set_compress(wmOperator *op)
758 if(!RNA_property_is_set(op->ptr, "compress")) {
759 if(G.save_over) /* keep flag for existing file */
760 RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
761 else /* use userdef for new file */
762 RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
766 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
770 save_set_compress(op);
772 BLI_strncpy(name, G.sce, FILE_MAX);
774 RNA_string_set(op->ptr, "filename", name);
776 WM_event_add_fileselect(C, op);
778 return OPERATOR_RUNNING_MODAL;
781 /* function used for WM_OT_save_mainfile too */
782 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
784 char filename[FILE_MAX];
787 save_set_compress(op);
788 compress= RNA_boolean_get(op->ptr, "compress");
790 if(RNA_property_is_set(op->ptr, "filename"))
791 RNA_string_get(op->ptr, "filename", filename);
793 BLI_strncpy(filename, G.sce, FILE_MAX);
797 WM_write_file(C, filename, compress, op->reports);
799 WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
804 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
806 ot->name= "Save As Blender File";
807 ot->idname= "WM_OT_save_as_mainfile";
809 ot->invoke= wm_save_as_mainfile_invoke;
810 ot->exec= wm_save_as_mainfile_exec;
811 ot->poll= WM_operator_winactive;
813 RNA_def_string_file_path(ot->srna, "filename", "", 0, "Filename", "");
814 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
817 /* *************** Save file directly ******** */
819 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
823 save_set_compress(op);
825 BLI_strncpy(name, G.sce, FILE_MAX);
827 RNA_string_set(op->ptr, "filename", name);
828 uiPupMenuSaveOver(C, op, name);
830 return OPERATOR_RUNNING_MODAL;
833 static void WM_OT_save_mainfile(wmOperatorType *ot)
835 ot->name= "Save Blender File";
836 ot->idname= "WM_OT_save_mainfile";
838 ot->invoke= wm_save_mainfile_invoke;
839 ot->exec= wm_save_as_mainfile_exec;
840 ot->poll= WM_operator_winactive;
842 RNA_def_string_file_path(ot->srna, "filename", "", 0, "Filename", "");
843 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
847 /* *********************** */
849 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
851 ot->name= "Toggle Fullscreen";
852 ot->idname= "WM_OT_window_fullscreen_toggle";
854 ot->invoke= WM_operator_confirm;
855 ot->exec= wm_window_fullscreen_toggle_op;
856 ot->poll= WM_operator_winactive;
859 static int wm_exit_blender_op(bContext *C, wmOperator *op)
861 WM_operator_free(op);
865 return OPERATOR_FINISHED;
868 static void WM_OT_exit_blender(wmOperatorType *ot)
870 ot->name= "Exit Blender";
871 ot->idname= "WM_OT_exit_blender";
873 ot->invoke= WM_operator_confirm;
874 ot->exec= wm_exit_blender_op;
875 ot->poll= WM_operator_winactive;
878 /* ************ default paint cursors, draw always around cursor *********** */
880 - returns handler to free
881 - poll(bContext): returns 1 if draw should happen
882 - draw(bContext): drawing callback for paint cursor
885 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
886 void (*draw)(bContext *C, int, int, void *customdata), void *customdata)
888 wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
890 BLI_addtail(&wm->paintcursors, pc);
892 pc->customdata = customdata;
899 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
903 for(pc= wm->paintcursors.first; pc; pc= pc->next) {
904 if(pc == (wmPaintCursor *)handle) {
905 BLI_remlink(&wm->paintcursors, pc);
912 /* ************ window gesture operator-callback definitions ************** */
914 * These are default callbacks for use in operators requiring gesture input
917 /* **************** Border gesture *************** */
919 /* Border gesture has two types:
920 1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border
921 2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
923 It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
926 static int border_apply(bContext *C, wmOperator *op, int event_type, int event_orig)
928 wmGesture *gesture= op->customdata;
929 rcti *rect= gesture->customdata;
931 if(rect->xmin > rect->xmax)
932 SWAP(int, rect->xmin, rect->xmax);
933 if(rect->ymin > rect->ymax)
934 SWAP(int, rect->ymin, rect->ymax);
936 if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
939 /* operator arguments and storage. */
940 RNA_int_set(op->ptr, "xmin", rect->xmin);
941 RNA_int_set(op->ptr, "ymin", rect->ymin);
942 RNA_int_set(op->ptr, "xmax", rect->xmax);
943 RNA_int_set(op->ptr, "ymax", rect->ymax);
945 /* XXX weak; border should be configured for this without reading event types */
946 if( RNA_struct_find_property(op->ptr, "event_type") ) {
947 if(ELEM4(event_orig, EVT_TWEAK_L, EVT_TWEAK_R, EVT_TWEAK_A, EVT_TWEAK_S))
948 event_type= LEFTMOUSE;
950 RNA_int_set(op->ptr, "event_type", event_type);
952 op->type->exec(C, op);
957 static void wm_gesture_end(bContext *C, wmOperator *op)
959 wmGesture *gesture= op->customdata;
961 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
962 op->customdata= NULL;
964 ED_area_tag_redraw(CTX_wm_area(C));
966 if( RNA_struct_find_property(op->ptr, "cursor") )
967 WM_cursor_restore(CTX_wm_window(C));
970 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
972 if(WM_key_event_is_tweak(event->type))
973 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
975 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
977 /* add modal handler */
978 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
980 wm_gesture_tag_redraw(C);
982 return OPERATOR_RUNNING_MODAL;
985 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
987 wmGesture *gesture= op->customdata;
988 rcti *rect= gesture->customdata;
991 switch(event->type) {
994 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
996 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
997 rect->xmin= rect->xmax= event->x - sx;
998 rect->ymin= rect->ymax= event->y - sy;
1001 rect->xmax= event->x - sx;
1002 rect->ymax= event->y - sy;
1005 wm_gesture_tag_redraw(C);
1012 if(event->val==KM_PRESS) {
1013 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1015 wm_gesture_tag_redraw(C);
1019 if(border_apply(C, op, event->type, gesture->event_type)) {
1020 wm_gesture_end(C, op);
1021 return OPERATOR_FINISHED;
1023 wm_gesture_end(C, op);
1024 return OPERATOR_CANCELLED;
1028 wm_gesture_end(C, op);
1029 return OPERATOR_CANCELLED;
1031 return OPERATOR_RUNNING_MODAL;
1034 /* **************** circle gesture *************** */
1035 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
1037 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
1039 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
1041 /* add modal handler */
1042 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1044 wm_gesture_tag_redraw(C);
1046 return OPERATOR_RUNNING_MODAL;
1049 static void gesture_circle_apply(bContext *C, wmOperator *op)
1051 wmGesture *gesture= op->customdata;
1052 rcti *rect= gesture->customdata;
1054 /* operator arguments and storage. */
1055 RNA_int_set(op->ptr, "x", rect->xmin);
1056 RNA_int_set(op->ptr, "y", rect->ymin);
1057 RNA_int_set(op->ptr, "radius", rect->xmax);
1060 op->type->exec(C, op);
1063 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
1065 wmGesture *gesture= op->customdata;
1066 rcti *rect= gesture->customdata;
1069 switch(event->type) {
1072 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1074 rect->xmin= event->x - sx;
1075 rect->ymin= event->y - sy;
1077 wm_gesture_tag_redraw(C);
1080 gesture_circle_apply(C, op);
1084 rect->xmax += 2 + rect->xmax/10;
1085 wm_gesture_tag_redraw(C);
1087 case WHEELDOWNMOUSE:
1088 rect->xmax -= 2 + rect->xmax/10;
1089 if(rect->xmax < 1) rect->xmax= 1;
1090 wm_gesture_tag_redraw(C);
1095 if(event->val==0) { /* key release */
1096 wm_gesture_end(C, op);
1097 return OPERATOR_FINISHED;
1100 if( RNA_struct_find_property(op->ptr, "event_type") )
1101 RNA_int_set(op->ptr, "event_type", event->type);
1103 /* apply first click */
1104 gesture_circle_apply(C, op);
1109 wm_gesture_end(C, op);
1110 return OPERATOR_CANCELLED;
1112 return OPERATOR_RUNNING_MODAL;
1116 /* template to copy from */
1117 void WM_OT_circle_gesture(wmOperatorType *ot)
1119 ot->name= "Circle Gesture";
1120 ot->idname= "WM_OT_circle_gesture";
1122 ot->invoke= WM_gesture_circle_invoke;
1123 ot->modal= WM_gesture_circle_modal;
1125 ot->poll= WM_operator_winactive;
1127 RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
1128 RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
1129 RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
1134 /* **************** Tweak gesture *************** */
1136 static void tweak_gesture_modal(bContext *C, wmEvent *event)
1138 wmWindow *window= CTX_wm_window(C);
1139 wmGesture *gesture= window->tweak;
1140 rcti *rect= gesture->customdata;
1143 switch(event->type) {
1146 wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
1148 rect->xmax= event->x - sx;
1149 rect->ymax= event->y - sy;
1151 if((val= wm_gesture_evaluate(C, gesture))) {
1154 event= *(window->eventstate);
1155 if(gesture->event_type==LEFTMOUSE)
1156 event.type= EVT_TWEAK_L;
1157 else if(gesture->event_type==RIGHTMOUSE)
1158 event.type= EVT_TWEAK_R;
1160 event.type= EVT_TWEAK_M;
1163 wm_event_add(window, &event);
1165 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
1166 window->tweak= NULL;
1174 if(gesture->event_type==event->type) {
1175 WM_gesture_end(C, gesture);
1176 window->tweak= NULL;
1178 /* when tweak fails we should give the other keymap entries a chance */
1179 event->val= KM_RELEASE;
1183 WM_gesture_end(C, gesture);
1184 window->tweak= NULL;
1188 /* standard tweak, called after window handlers passed on event */
1189 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
1191 wmWindow *win= CTX_wm_window(C);
1193 if(win->tweak==NULL) {
1194 if(CTX_wm_region(C)) {
1195 if(event->val) { // pressed
1196 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
1197 win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
1202 if(action==WM_HANDLER_BREAK) {
1203 WM_gesture_end(C, win->tweak);
1207 tweak_gesture_modal(C, event);
1211 /* *********************** lasso gesture ****************** */
1213 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
1215 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
1217 /* add modal handler */
1218 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1220 wm_gesture_tag_redraw(C);
1222 if( RNA_struct_find_property(op->ptr, "cursor") )
1223 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1225 return OPERATOR_RUNNING_MODAL;
1228 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
1230 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
1232 /* add modal handler */
1233 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1235 wm_gesture_tag_redraw(C);
1237 if( RNA_struct_find_property(op->ptr, "cursor") )
1238 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
1240 return OPERATOR_RUNNING_MODAL;
1244 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
1246 wmGesture *gesture= op->customdata;
1250 short *lasso= gesture->customdata;
1252 /* operator storage as path. */
1254 for(i=0; i<gesture->points; i++, lasso+=2) {
1257 RNA_collection_add(op->ptr, "path", &itemptr);
1258 RNA_float_set_array(&itemptr, "loc", loc);
1261 wm_gesture_end(C, op);
1264 op->type->exec(C, op);
1268 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
1270 wmGesture *gesture= op->customdata;
1273 switch(event->type) {
1276 wm_gesture_tag_redraw(C);
1278 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1279 if(gesture->points < WM_LASSO_MAX_POINTS) {
1280 short *lasso= gesture->customdata;
1281 lasso += 2 * gesture->points;
1282 lasso[0] = event->x - sx;
1283 lasso[1] = event->y - sy;
1287 gesture_lasso_apply(C, op, event->type);
1288 return OPERATOR_FINISHED;
1295 if(event->val==0) { /* key release */
1296 gesture_lasso_apply(C, op, event->type);
1297 return OPERATOR_FINISHED;
1301 wm_gesture_end(C, op);
1302 return OPERATOR_CANCELLED;
1304 return OPERATOR_RUNNING_MODAL;
1307 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
1309 return WM_gesture_lasso_modal(C, op, event);
1313 /* template to copy from */
1315 static int gesture_lasso_exec(bContext *C, wmOperator *op)
1317 RNA_BEGIN(op->ptr, itemptr, "path") {
1320 RNA_float_get_array(&itemptr, "loc", loc);
1321 printf("Location: %f %f\n", loc[0], loc[1]);
1325 return OPERATOR_FINISHED;
1328 void WM_OT_lasso_gesture(wmOperatorType *ot)
1332 ot->name= "Lasso Gesture";
1333 ot->idname= "WM_OT_lasso_gesture";
1335 ot->invoke= WM_gesture_lasso_invoke;
1336 ot->modal= WM_gesture_lasso_modal;
1337 ot->exec= gesture_lasso_exec;
1339 ot->poll= WM_operator_winactive;
1341 prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
1342 RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
1346 /* *********************** radial control ****************** */
1348 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
1350 typedef struct wmRadialControl {
1352 float initial_value, value, max_value;
1353 int initial_mouse[2];
1358 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
1360 wmRadialControl *rc = (wmRadialControl*)customdata;
1361 ARegion *ar = CTX_wm_region(C);
1362 float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
1364 /* Keep cursor in the original place */
1365 x = rc->initial_mouse[0] - ar->winrct.xmin;
1366 y = rc->initial_mouse[1] - ar->winrct.ymin;
1370 glTranslatef((float)x, (float)y, 0.0f);
1372 if(rc->mode == WM_RADIALCONTROL_SIZE) {
1374 r2= rc->initial_value;
1376 } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
1377 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
1378 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1379 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1380 } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1381 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1382 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
1386 glColor4ub(255, 255, 255, 128);
1387 glEnable( GL_LINE_SMOOTH );
1390 if(rc->mode == WM_RADIALCONTROL_ANGLE)
1391 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1394 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
1396 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
1397 glRotatef(angle, 0, 0, 1);
1398 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
1401 glBindTexture(GL_TEXTURE_2D, rc->tex);
1403 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1404 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1406 glEnable(GL_TEXTURE_2D);
1408 glColor4f(0,0,0, str);
1410 glVertex2f(-r3, -r3);
1412 glVertex2f(r3, -r3);
1416 glVertex2f(-r3, r3);
1418 glDisable(GL_TEXTURE_2D);
1421 glColor4ub(255, 255, 255, 128);
1422 glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
1423 glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
1424 glDisable(GL_BLEND);
1425 glDisable( GL_LINE_SMOOTH );
1430 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
1432 wmRadialControl *rc = (wmRadialControl*)op->customdata;
1433 int mode, initial_mouse[2], delta[2];
1435 double new_value = RNA_float_get(op->ptr, "new_value");
1436 int ret = OPERATOR_RUNNING_MODAL;
1438 mode = RNA_int_get(op->ptr, "mode");
1439 RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
1441 switch(event->type) {
1443 delta[0]= initial_mouse[0] - event->x;
1444 delta[1]= initial_mouse[1] - event->y;
1445 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
1447 if(mode == WM_RADIALCONTROL_SIZE)
1449 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1450 new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
1451 } else if(mode == WM_RADIALCONTROL_ANGLE)
1452 new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
1455 if(mode == WM_RADIALCONTROL_STRENGTH)
1456 new_value = ((int)(new_value * 100) / 10*10) / 100.0f;
1458 new_value = ((int)new_value + 5) / 10*10;
1464 ret = OPERATOR_CANCELLED;
1468 op->type->exec(C, op);
1469 ret = OPERATOR_FINISHED;
1474 if(new_value > rc->max_value)
1475 new_value = rc->max_value;
1476 else if(new_value < 0)
1479 /* Update paint data */
1480 rc->value = new_value;
1482 RNA_float_set(op->ptr, "new_value", new_value);
1484 if(ret != OPERATOR_RUNNING_MODAL) {
1485 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
1489 ED_region_tag_redraw(CTX_wm_region(C));
1494 /* Expects the operator customdata to be an ImBuf (or NULL) */
1495 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
1497 wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
1498 int mode = RNA_int_get(op->ptr, "mode");
1499 float initial_value = RNA_float_get(op->ptr, "initial_value");
1500 int mouse[2] = {event->x, event->y};
1502 if(mode == WM_RADIALCONTROL_SIZE) {
1503 rc->max_value = 200;
1504 mouse[0]-= initial_value;
1506 else if(mode == WM_RADIALCONTROL_STRENGTH) {
1508 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
1510 else if(mode == WM_RADIALCONTROL_ANGLE) {
1511 rc->max_value = 360;
1512 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
1513 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
1514 initial_value *= 180.0f/M_PI;
1517 if(op->customdata) {
1518 ImBuf *im = (ImBuf*)op->customdata;
1519 /* Build GL texture */
1520 glGenTextures(1, &rc->tex);
1521 glBindTexture(GL_TEXTURE_2D, rc->tex);
1522 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
1523 MEM_freeN(im->rect_float);
1527 RNA_int_set_array(op->ptr, "initial_mouse", mouse);
1528 RNA_float_set(op->ptr, "new_value", initial_value);
1530 op->customdata = rc;
1532 rc->initial_value = initial_value;
1533 rc->initial_mouse[0] = mouse[0];
1534 rc->initial_mouse[1] = mouse[1];
1535 rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
1536 wm_radial_control_paint, op->customdata);
1538 /* add modal handler */
1539 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
1541 WM_radial_control_modal(C, op, event);
1543 return OPERATOR_RUNNING_MODAL;
1546 /* Gets a descriptive string of the operation */
1547 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
1549 int mode = RNA_int_get(op->ptr, "mode");
1550 float v = RNA_float_get(op->ptr, "new_value");
1552 if(mode == WM_RADIALCONTROL_SIZE)
1553 sprintf(str, "Size: %d", (int)v);
1554 else if(mode == WM_RADIALCONTROL_STRENGTH)
1555 sprintf(str, "Strength: %d", (int)v);
1556 else if(mode == WM_RADIALCONTROL_ANGLE)
1557 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
1560 /** Important: this doesn't define an actual operator, it
1561 just sets up the common parts of the radial control op. **/
1562 void WM_OT_radial_control_partial(wmOperatorType *ot)
1564 static EnumPropertyItem prop_mode_items[] = {
1565 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
1566 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
1567 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
1568 {0, NULL, 0, NULL, NULL}};
1570 /* Should be set in custom invoke() */
1571 RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
1573 /* Set internally, should be used in custom exec() to get final value */
1574 RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
1576 /* Should be set before calling operator */
1577 RNA_def_enum(ot->srna, "mode", prop_mode_items, 0, "Mode", "");
1580 RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
1583 /* ************************** timer for testing ***************** */
1585 /* uses no type defines, fully local testing function anyway... ;) */
1587 static int ten_timer_exec(bContext *C, wmOperator *op)
1589 ARegion *ar= CTX_wm_region(C);
1590 double stime= PIL_check_seconds_timer();
1591 int type = RNA_int_get(op->ptr, "type");
1597 for(a=0; a<10; a++) {
1599 ED_region_do_draw(C, ar);
1602 wmWindow *win= CTX_wm_window(C);
1604 ED_region_tag_redraw(ar);
1607 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
1610 wmWindow *win= CTX_wm_window(C);
1613 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
1614 ED_area_tag_redraw(sa);
1617 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
1620 Scene *scene= CTX_data_scene(C);
1622 if(a & 1) scene->r.cfra--;
1623 else scene->r.cfra++;
1624 scene_update_for_newframe(scene, scene->lay);
1632 time= (int) ((PIL_check_seconds_timer()-stime)*1000);
1634 if(type==0) sprintf(tmpstr, "10 x Draw Region: %d ms", time);
1635 if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time);
1636 if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time);
1637 if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time);
1638 if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time);
1642 uiPupMenuNotice(C, tmpstr);
1644 return OPERATOR_FINISHED;
1647 static void WM_OT_ten_timer(wmOperatorType *ot)
1649 static EnumPropertyItem prop_type_items[] = {
1650 {0, "DRAW", 0, "Draw Region", ""},
1651 {1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
1652 {2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
1653 {3, "ANIMSTEP", 0, "Anim Step", ""},
1654 {4, "UNDO", 0, "Undo/Redo", ""},
1655 {0, NULL, 0, NULL, NULL}};
1657 ot->name= "Ten Timer";
1658 ot->idname= "WM_OT_ten_timer";
1660 ot->invoke= WM_menu_invoke;
1661 ot->exec= ten_timer_exec;
1662 ot->poll= WM_operator_winactive;
1664 RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
1670 /* ******************************************************* */
1672 /* called on initialize WM_exit() */
1673 void wm_operatortype_free(void)
1675 BLI_freelistN(&global_ops);
1678 /* called on initialize WM_init() */
1679 void wm_operatortype_init(void)
1681 WM_operatortype_append(WM_OT_window_duplicate);
1682 WM_operatortype_append(WM_OT_read_homefile);
1683 WM_operatortype_append(WM_OT_save_homefile);
1684 WM_operatortype_append(WM_OT_window_fullscreen_toggle);
1685 WM_operatortype_append(WM_OT_exit_blender);
1686 WM_operatortype_append(WM_OT_open_recentfile);
1687 WM_operatortype_append(WM_OT_open_mainfile);
1688 WM_operatortype_append(WM_OT_recover_last_session);
1689 WM_operatortype_append(WM_OT_jobs_timer);
1690 WM_operatortype_append(WM_OT_save_as_mainfile);
1691 WM_operatortype_append(WM_OT_save_mainfile);
1692 WM_operatortype_append(WM_OT_ten_timer);
1693 WM_operatortype_append(WM_OT_debug_menu);
1694 WM_operatortype_append(WM_OT_search_menu);
1697 /* default keymap for windows and screens, only call once per WM */
1698 void wm_window_keymap(wmWindowManager *wm)
1700 ListBase *keymap= WM_keymap_listbase(wm, "Window", 0, 0);
1702 /* items to make WM work */
1703 WM_keymap_verify_item(keymap, "WM_OT_jobs_timer", TIMERJOBS, KM_ANY, KM_ANY, 0);
1705 /* note, this doesn't replace existing keymap items */
1706 WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
1707 WM_keymap_verify_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0);
1708 WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
1709 WM_keymap_verify_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_CTRL, 0);
1710 WM_keymap_verify_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
1711 WM_keymap_verify_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
1712 WM_keymap_verify_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
1713 WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_SHIFT, 0);
1714 WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
1717 WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1718 WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
1719 WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, KM_CTRL, 0);