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_object_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_scene_types.h"
40 #include "DNA_userdef_types.h"
41 #include "DNA_windowmanager_types.h"
43 #include "MEM_guardedalloc.h"
49 #include "BLI_blenlib.h"
50 #include "BLI_dynstr.h" /*for WM_operator_pystring */
52 #include "BLO_readfile.h"
54 #include "BKE_blender.h"
55 #include "BKE_context.h"
56 #include "BKE_depsgraph.h"
57 #include "BKE_idprop.h"
58 #include "BKE_library.h"
59 #include "BKE_global.h"
61 #include "BKE_report.h"
62 #include "BKE_scene.h"
63 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
64 #include "BKE_utildefines.h"
67 #include "BIF_glutil.h" /* for paint cursor */
69 #include "IMB_imbuf_types.h"
71 #include "ED_screen.h"
74 #include "RNA_access.h"
75 #include "RNA_define.h"
77 #include "UI_interface.h"
78 #include "UI_resources.h"
85 #include "wm_event_system.h"
86 #include "wm_event_types.h"
87 #include "wm_subwindow.h"
88 #include "wm_window.h"
92 static ListBase global_ops= {NULL, NULL};
94 /* ************ operator API, exported ********** */
97 wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
101 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
102 WM_operator_bl_idname(idname_bl, idname);
105 for(ot= global_ops.first; ot; ot= ot->next) {
106 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
112 printf("search for unknown operator %s, %s\n", idname_bl, idname);
117 wmOperatorType *WM_operatortype_exists(const char *idname)
121 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
122 WM_operator_bl_idname(idname_bl, idname);
125 for(ot= global_ops.first; ot; ot= ot->next) {
126 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
133 wmOperatorType *WM_operatortype_first(void)
135 return global_ops.first;
138 /* all ops in 1 list (for time being... needs evaluation later) */
139 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
143 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
144 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
148 static char dummy_name[] = "Dummy Name";
149 fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
150 ot->name= dummy_name;
153 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.
154 RNA_def_struct_identifier(ot->srna, ot->idname);
155 BLI_addtail(&global_ops, ot);
158 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
162 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
163 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
164 opfunc(ot, userdata);
165 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)");
166 RNA_def_struct_identifier(ot->srna, ot->idname);
167 BLI_addtail(&global_ops, ot);
170 /* ********************* macro operator ******************** */
176 static void wm_macro_start(wmOperator *op)
178 if (op->customdata == NULL) {
179 op->customdata = MEM_callocN(sizeof(MacroData), "MacroData");
183 static int wm_macro_end(wmOperator *op, int retval)
185 if (retval & OPERATOR_CANCELLED) {
186 MacroData *md = op->customdata;
188 if (md->retval & OPERATOR_FINISHED) {
189 retval |= OPERATOR_FINISHED;
190 retval &= ~OPERATOR_CANCELLED;
194 /* if modal is ending, free custom data */
195 if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED)) {
196 if (op->customdata) {
197 MEM_freeN(op->customdata);
198 op->customdata = NULL;
205 /* macro exec only runs exec calls */
206 static int wm_macro_exec(bContext *C, wmOperator *op)
209 int retval= OPERATOR_FINISHED;
213 for(opm= op->macro.first; opm; opm= opm->next) {
215 if(opm->type->exec) {
216 retval= opm->type->exec(C, opm);
218 if (retval & OPERATOR_FINISHED) {
219 MacroData *md = op->customdata;
220 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
222 break; /* operator didn't finish, end macro */
227 return wm_macro_end(op, retval);
230 int wm_macro_invoke_internal(bContext *C, wmOperator *op, wmEvent *event, wmOperator *opm)
232 int retval= OPERATOR_FINISHED;
234 /* start from operator received as argument */
235 for( ; opm; opm= opm->next) {
236 if(opm->type->invoke)
237 retval= opm->type->invoke(C, opm, event);
238 else if(opm->type->exec)
239 retval= opm->type->exec(C, opm);
241 if (retval & OPERATOR_FINISHED) {
242 MacroData *md = op->customdata;
243 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
245 break; /* operator didn't finish, end macro */
249 return wm_macro_end(op, retval);
252 static int wm_macro_invoke(bContext *C, wmOperator *op, wmEvent *event)
255 return wm_macro_invoke_internal(C, op, event, op->macro.first);
258 static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
260 wmOperator *opm = op->opm;
261 int retval= OPERATOR_FINISHED;
264 printf("macro error, calling NULL modal()\n");
266 retval = opm->type->modal(C, opm, event);
268 /* if this one is done but it's not the last operator in the macro */
269 if ((retval & OPERATOR_FINISHED) && opm->next) {
270 MacroData *md = op->customdata;
272 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
274 retval = wm_macro_invoke_internal(C, op, event, opm->next);
276 /* if new operator is modal and also added its own handler */
277 if (retval & OPERATOR_RUNNING_MODAL && op->opm != opm) {
278 wmWindow *win = CTX_wm_window(C);
279 wmEventHandler *handler = NULL;
281 for (handler = win->modalhandlers.first; handler; handler = handler->next) {
282 /* first handler in list is the new one */
283 if (handler->op == op)
288 BLI_remlink(&win->modalhandlers, handler);
289 wm_event_free_handler(handler);
292 /* if operator is blocking, grab cursor
293 * This may end up grabbing twice, but we don't care.
295 if(op->opm->type->flag & OPTYPE_BLOCKING) {
296 int bounds[4] = {-1,-1,-1,-1};
297 int wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->opm->flag & OP_GRAB_POINTER) || (op->opm->type->flag & OPTYPE_GRAB_POINTER));
300 ARegion *ar= CTX_wm_region(C);
302 bounds[0]= ar->winrct.xmin;
303 bounds[1]= ar->winrct.ymax;
304 bounds[2]= ar->winrct.xmax;
305 bounds[3]= ar->winrct.ymin;
309 WM_cursor_grab(CTX_wm_window(C), wrap, FALSE, bounds);
315 return wm_macro_end(op, retval);
318 static int wm_macro_cancel(bContext *C, wmOperator *op)
320 /* call cancel on the current modal operator, if any */
321 if (op->opm && op->opm->type->cancel) {
322 op->opm->type->cancel(C, op->opm);
325 return wm_macro_end(op, OPERATOR_CANCELLED);
328 /* Names have to be static for now */
329 wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
333 if(WM_operatortype_exists(idname)) {
334 printf("Macro error: operator %s exists\n", idname);
338 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
339 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
343 ot->flag= OPTYPE_MACRO|flag;
345 ot->exec= wm_macro_exec;
346 ot->invoke= wm_macro_invoke;
347 ot->modal= wm_macro_modal;
348 ot->cancel= wm_macro_cancel;
351 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.
352 RNA_def_struct_identifier(ot->srna, ot->idname);
354 BLI_addtail(&global_ops, ot);
359 void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
363 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
364 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
366 ot->flag= OPTYPE_MACRO;
367 ot->exec= wm_macro_exec;
368 ot->invoke= wm_macro_invoke;
369 ot->modal= wm_macro_modal;
370 ot->cancel= wm_macro_cancel;
373 opfunc(ot, userdata);
375 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)");
376 RNA_def_struct_identifier(ot->srna, ot->idname);
378 BLI_addtail(&global_ops, ot);
381 wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
383 wmOperatorTypeMacro *otmacro= MEM_callocN(sizeof(wmOperatorTypeMacro), "wmOperatorTypeMacro");
385 BLI_strncpy(otmacro->idname, idname, OP_MAX_TYPENAME);
387 /* do this on first use, since operatordefinitions might have been not done yet */
388 WM_operator_properties_alloc(&(otmacro->ptr), &(otmacro->properties), idname);
390 BLI_addtail(&ot->macro, otmacro);
395 static void wm_operatortype_free_macro(wmOperatorType *ot)
397 wmOperatorTypeMacro *otmacro;
399 for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
401 WM_operator_properties_free(otmacro->ptr);
402 MEM_freeN(otmacro->ptr);
405 BLI_freelistN(&ot->macro);
409 int WM_operatortype_remove(const char *idname)
411 wmOperatorType *ot = WM_operatortype_find(idname, 0);
416 BLI_remlink(&global_ops, ot);
417 RNA_struct_free(&BLENDER_RNA, ot->srna);
420 wm_operatortype_free_macro(ot);
427 /* SOME_OT_op -> some.op */
428 void WM_operator_py_idname(char *to, const char *from)
430 char *sep= strstr(from, "_OT_");
432 int i, ofs= (sep-from);
435 to[i]= tolower(from[i]);
438 BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
441 /* should not happen but support just incase */
442 BLI_strncpy(to, from, OP_MAX_TYPENAME);
446 /* some.op -> SOME_OT_op */
447 void WM_operator_bl_idname(char *to, const char *from)
450 char *sep= strchr(from, '.');
453 int i, ofs= (sep-from);
456 to[i]= toupper(from[i]);
458 BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
459 BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
462 /* should not happen but support just incase */
463 BLI_strncpy(to, from, OP_MAX_TYPENAME);
470 /* print a string representation of the operator, with the args that it runs
471 * so python can run it again,
473 * When calling from an existing wmOperator do.
474 * WM_operator_pystring(op->type, op->ptr);
476 char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args)
478 const char *arg_name= NULL;
479 char idname_py[OP_MAX_TYPENAME];
481 PropertyRNA *prop, *iterprop;
483 /* for building the string */
484 DynStr *dynstr= BLI_dynstr_new();
486 int first_iter=1, ok= 1;
489 /* only to get the orginal props for comparisons */
490 PointerRNA opptr_default;
491 PropertyRNA *prop_default;
493 if(all_args==0 || opptr==NULL) {
494 WM_operator_properties_create_ptr(&opptr_default, ot);
497 opptr = &opptr_default;
501 WM_operator_py_idname(idname_py, ot->idname);
502 BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
504 iterprop= RNA_struct_iterator_property(opptr->type);
506 RNA_PROP_BEGIN(opptr, propptr, iterprop) {
508 arg_name= RNA_property_identifier(prop);
510 if (strcmp(arg_name, "rna_type")==0) continue;
512 buf= RNA_property_as_string(C, opptr, prop);
517 /* not verbose, so only add in attributes that use non-default values
518 * slow but good for tooltips */
519 prop_default= RNA_struct_find_property(&opptr_default, arg_name);
522 buf_default= RNA_property_as_string(C, &opptr_default, prop_default);
524 if(strcmp(buf, buf_default)==0)
525 ok= 0; /* values match, dont bother printing */
527 MEM_freeN(buf_default);
532 BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
541 if(all_args==0 || opptr==&opptr_default )
542 WM_operator_properties_free(&opptr_default);
544 BLI_dynstr_append(dynstr, ")");
546 cstring = BLI_dynstr_get_cstring(dynstr);
547 BLI_dynstr_free(dynstr);
551 void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
553 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
556 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
558 wmOperatorType *ot= WM_operatortype_find(opstring, 0);
561 WM_operator_properties_create_ptr(ptr, ot);
563 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
566 /* similar to the function above except its uses ID properties
567 * used for keymaps and macros */
568 void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
570 if(*properties==NULL) {
571 IDPropertyTemplate val = {0};
572 *properties= IDP_New(IDP_GROUP, val, "wmOpItemProp");
576 *ptr= MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
577 WM_operator_properties_create(*ptr, opstring);
580 (*ptr)->data= *properties;
585 void WM_operator_properties_free(PointerRNA *ptr)
587 IDProperty *properties= ptr->data;
590 IDP_FreeProperty(properties);
591 MEM_freeN(properties);
595 /* ************ default op callbacks, exported *********** */
597 /* invoke callback, uses enum property named "type" */
598 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
604 prop= RNA_struct_find_property(op->ptr, "type");
607 RNA_STRUCT_BEGIN(op->ptr, findprop) {
608 if(RNA_property_type(findprop) == PROP_ENUM) {
617 printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname);
619 else if (RNA_property_type(prop) != PROP_ENUM) {
620 printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname);
622 else if (RNA_property_is_set(op->ptr, RNA_property_identifier(prop))) {
623 return op->type->exec(C, op);
626 pup= uiPupMenuBegin(C, op->type->name, 0);
627 layout= uiPupMenuLayout(pup);
628 uiItemsFullEnumO(layout, op->type->idname, (char*)RNA_property_identifier(prop), op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
629 uiPupMenuEnd(C, pup);
632 return OPERATOR_CANCELLED;
635 /* Can't be used as an invoke directly, needs message arg (can be NULL) */
636 int WM_operator_confirm_message(bContext *C, wmOperator *op, char *message)
640 IDProperty *properties= op->ptr->data;
642 if(properties && properties->len)
643 properties= IDP_CopyProperty(op->ptr->data);
647 pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
648 layout= uiPupMenuLayout(pup);
649 uiItemFullO(layout, message, 0, op->type->idname, properties, WM_OP_EXEC_REGION_WIN, 0);
650 uiPupMenuEnd(C, pup);
652 return OPERATOR_CANCELLED;
656 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
658 return WM_operator_confirm_message(C, op, NULL);
661 /* op->invoke, opens fileselect if path property not set, otherwise executes */
662 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
664 if (RNA_property_is_set(op->ptr, "path")) {
665 return WM_operator_call(C, op);
668 WM_event_add_fileselect(C, op);
669 return OPERATOR_RUNNING_MODAL;
673 /* default properties for fileselect */
674 void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type)
678 RNA_def_string_file_path(ot->srna, "path", "", FILE_MAX, "File Path", "Path to file.");
679 RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file.");
680 RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file.");
682 prop= RNA_def_boolean(ot->srna, "filter_blender", (filter & BLENDERFILE), "Filter .blend files", "");
683 RNA_def_property_flag(prop, PROP_HIDDEN);
684 prop= RNA_def_boolean(ot->srna, "filter_image", (filter & IMAGEFILE), "Filter image files", "");
685 RNA_def_property_flag(prop, PROP_HIDDEN);
686 prop= RNA_def_boolean(ot->srna, "filter_movie", (filter & MOVIEFILE), "Filter movie files", "");
687 RNA_def_property_flag(prop, PROP_HIDDEN);
688 prop= RNA_def_boolean(ot->srna, "filter_python", (filter & PYSCRIPTFILE), "Filter python files", "");
689 RNA_def_property_flag(prop, PROP_HIDDEN);
690 prop= RNA_def_boolean(ot->srna, "filter_font", (filter & FTFONTFILE), "Filter font files", "");
691 RNA_def_property_flag(prop, PROP_HIDDEN);
692 prop= RNA_def_boolean(ot->srna, "filter_sound", (filter & SOUNDFILE), "Filter sound files", "");
693 RNA_def_property_flag(prop, PROP_HIDDEN);
694 prop= RNA_def_boolean(ot->srna, "filter_text", (filter & TEXTFILE), "Filter text files", "");
695 RNA_def_property_flag(prop, PROP_HIDDEN);
696 prop= RNA_def_boolean(ot->srna, "filter_btx", (filter & BTXFILE), "Filter btx files", "");
697 RNA_def_property_flag(prop, PROP_HIDDEN);
698 prop= RNA_def_boolean(ot->srna, "filter_folder", (filter & FOLDERFILE), "Filter folders", "");
699 RNA_def_property_flag(prop, PROP_HIDDEN);
701 prop= RNA_def_int(ot->srna, "filemode", type, FILE_LOADLIB, FILE_SPECIAL,
702 "File Browser Mode", "The setting for the file browser mode to load a .blend file, a library or a special file.",
703 FILE_LOADLIB, FILE_SPECIAL);
704 RNA_def_property_flag(prop, PROP_HIDDEN);
707 void WM_operator_properties_select_all(wmOperatorType *ot) {
708 static EnumPropertyItem select_all_actions[] = {
709 {SEL_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle selection for all elements"},
710 {SEL_SELECT, "SELECT", 0, "Select", "Select all elements"},
711 {SEL_DESELECT, "DESELECT", 0, "Deselect", "Deselect all elements"},
712 {SEL_INVERT, "INVERT", 0, "Invert", "Invert selection of all elements"},
713 {0, NULL, 0, NULL, NULL}
716 RNA_def_enum(ot->srna, "action", select_all_actions, SEL_TOGGLE, "Action", "Selection action to execute");
719 void WM_operator_properties_gesture_border(wmOperatorType *ot, int extend)
721 RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
722 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
723 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
724 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
725 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
728 RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first.");
733 int WM_operator_winactive(bContext *C)
735 if(CTX_wm_window(C)==NULL) return 0;
740 static void redo_cb(bContext *C, void *arg_op, int event)
742 wmOperator *lastop= arg_op;
745 ED_undo_pop_op(C, lastop);
746 WM_operator_repeat(C, lastop);
750 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
752 wmWindowManager *wm= CTX_wm_manager(C);
753 wmOperator *op= arg_op;
757 uiStyle *style= U.uistyles.first;
758 int columns= 2, width= 300;
761 block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
762 uiBlockClearFlag(block, UI_BLOCK_LOOP);
763 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
764 uiBlockSetHandleFunc(block, redo_cb, arg_op);
766 if(!op->properties) {
767 IDPropertyTemplate val = {0};
768 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
771 // XXX - hack, only for editing docs
772 if(strcmp(op->type->idname, "WM_OT_doc_edit")==0) {
777 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
778 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style);
779 uiItemL(layout, op->type->name, 0);
783 op->type->ui((bContext*)C, op);
787 uiDefAutoButsRNA(C, layout, &ptr, columns);
789 uiPopupBoundsBlock(block, 4.0f, 0, 0);
790 uiEndBlock(C, block);
796 static uiBlock *wm_operator_create_ui(bContext *C, ARegion *ar, void *userData)
798 struct { wmOperator *op; int width; int height; } * data = userData;
799 wmWindowManager *wm= CTX_wm_manager(C);
800 wmOperator *op= data->op;
804 uiStyle *style= U.uistyles.first;
806 block= uiBeginBlock(C, ar, "opui_popup", UI_EMBOSS);
807 uiBlockClearFlag(block, UI_BLOCK_LOOP);
808 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
810 if(!op->properties) {
811 IDPropertyTemplate val = {0};
812 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
815 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
816 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, style);
820 op->type->ui((bContext*)C, op);
824 uiPopupBoundsBlock(block, 4.0f, 0, 0);
825 uiEndBlock(C, block);
830 int WM_operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
832 int retval= OPERATOR_CANCELLED;
835 retval= op->type->exec(C, op);
837 if(retval != OPERATOR_CANCELLED)
838 uiPupBlock(C, wm_block_create_redo, op);
843 void WM_operator_ui_popup(bContext *C, wmOperator *op, int width, int height)
845 struct { wmOperator *op; int width; int height; } data;
848 data.height = height;
849 uiPupBlock(C, wm_operator_create_ui, &data);
852 int WM_operator_redo_popup(bContext *C, wmOperator *op)
854 uiPupBlock(C, wm_block_create_redo, op);
856 return OPERATOR_CANCELLED;
859 /* ***************** Debug menu ************************* */
861 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
863 wmOperator *op= arg_op;
866 uiStyle *style= U.uistyles.first;
868 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
869 uiBlockClearFlag(block, UI_BLOCK_LOOP);
870 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
872 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
873 uiItemL(layout, op->type->name, 0);
881 uiDefAutoButsRNA(C, layout, op->ptr, 2);
883 uiPopupBoundsBlock(block, 4.0f, 0, 0);
884 uiEndBlock(C, block);
889 static int wm_debug_menu_exec(bContext *C, wmOperator *op)
891 G.rt= RNA_int_get(op->ptr, "debugval");
892 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
893 WM_event_add_notifier(C, NC_WINDOW, NULL);
895 return OPERATOR_FINISHED;
898 static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
901 RNA_int_set(op->ptr, "debugval", G.rt);
903 /* pass on operator, so return modal */
904 uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
906 return OPERATOR_RUNNING_MODAL;
909 static void WM_OT_debug_menu(wmOperatorType *ot)
911 ot->name= "Debug Menu";
912 ot->idname= "WM_OT_debug_menu";
913 ot->description= "Open a popup to set the debug level.";
915 ot->invoke= wm_debug_menu_invoke;
916 ot->exec= wm_debug_menu_exec;
917 ot->poll= WM_operator_winactive;
919 RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
923 /* ***************** Splash Screen ************************* */
925 static void wm_block_splash_close(bContext *C, void *arg_block, void *arg_unused)
927 uiPupBlockClose(C, arg_block);
930 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *arg_unused)
934 uiLayout *layout, *split, *col;
935 uiStyle *style= U.uistyles.first;
936 struct RecentFile *recent;
940 int ver_width, rev_width;
941 char *version_str = NULL;
942 char *revision_str = NULL;
943 char version_buf[128];
944 char revision_buf[128];
945 extern char * build_rev;
948 version_str = &version_buf[0];
949 revision_str = &revision_buf[0];
951 sprintf(version_str, "%d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
952 sprintf(revision_str, "r%s", build_rev);
954 /* here on my system I get ugly double quotes around the revision number.
955 * if so, clip it off: */
956 cp = strchr(revision_str, '"');
958 memmove(cp, cp+1, strlen(cp+1));
959 cp = strchr(revision_str, '"');
964 BLF_size(style->widgetlabel.points, U.dpi);
965 ver_width = BLF_width(version_str)+5;
966 rev_width = BLF_width(revision_str)+5;
967 #endif //NAN_BUILDINFO
969 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
970 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
972 but= uiDefBut(block, BUT_IMAGE, 0, "", 0, 10, 501, 282, NULL, 0.0, 0.0, 0, 0, "");
973 uiButSetFunc(but, wm_block_splash_close, block, NULL);
976 uiDefBut(block, LABEL, 0, version_str, 500-ver_width, 282-24, ver_width, 20, NULL, 0, 0, 0, 0, NULL);
977 uiDefBut(block, LABEL, 0, revision_str, 500-rev_width, 282-36, rev_width, 20, NULL, 0, 0, 0, 0, NULL);
978 #endif //NAN_BUILDINFO
981 uiBlockSetEmboss(block, UI_EMBOSSP);
983 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 10, 10, 480, 110, style);
985 uiLayoutSetOperatorContext(layout, WM_OP_EXEC_REGION_WIN);
987 split = uiLayoutSplit(layout, 0, 0);
988 col = uiLayoutColumn(split, 0);
989 uiItemL(col, "Links", 0);
990 uiItemO(col, NULL, ICON_URL, "HELP_OT_release_logs");
991 uiItemO(col, NULL, ICON_URL, "HELP_OT_manual");
992 uiItemO(col, NULL, ICON_URL, "HELP_OT_blender_website");
993 uiItemO(col, NULL, ICON_URL, "HELP_OT_user_community");
994 uiItemO(col, NULL, ICON_URL, "HELP_OT_python_api");
997 col = uiLayoutColumn(split, 0);
998 uiItemL(col, "Recent", 0);
999 for(recent = G.recent_files.first, i=0; (i<6) && (recent); recent = recent->next, i++) {
1000 char *display_name= BLI_last_slash(recent->filename);
1001 if(display_name) display_name++; /* skip the slash */
1002 else display_name= recent->filename;
1003 uiItemStringO(col, display_name, ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename);
1006 uiItemL(col, "", 0);
1008 uiCenteredBoundsBlock(block, 0.0f);
1009 uiEndBlock(C, block);
1014 static int wm_splash_invoke(bContext *C, wmOperator *op, wmEvent *event)
1016 uiPupBlock(C, wm_block_create_splash, NULL);
1018 return OPERATOR_FINISHED;
1021 static void WM_OT_splash(wmOperatorType *ot)
1023 ot->name= "Splash Screen";
1024 ot->idname= "WM_OT_splash";
1025 ot->description= "Opens a blocking popup region with release info";
1027 ot->invoke= wm_splash_invoke;
1028 ot->poll= WM_operator_winactive;
1032 /* ***************** Search menu ************************* */
1033 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1035 wmOperatorType *ot= arg2;
1038 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1041 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1043 wmOperatorType *ot = WM_operatortype_first();
1045 for(; ot; ot= ot->next) {
1047 if(BLI_strcasestr(ot->name, str)) {
1048 if(WM_operator_poll((bContext*)C, ot)) {
1050 int len= strlen(ot->name);
1052 /* display name for menu, can hold hotkey */
1053 BLI_strncpy(name, ot->name, 256);
1055 /* check for hotkey */
1057 if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1061 if(0==uiSearchItemAdd(items, name, ot, 0))
1068 static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
1070 static char search[256]= "";
1072 wmWindow *win= CTX_wm_window(C);
1076 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
1077 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
1079 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, 0, 0, "");
1080 uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1082 /* fake button, it holds space for search items */
1083 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
1085 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
1086 uiEndBlock(C, block);
1088 event= *(win->eventstate); /* XXX huh huh? make api call */
1089 event.type= EVT_BUT_OPEN;
1090 event.val= KM_PRESS;
1091 event.customdata= but;
1092 event.customdatafree= FALSE;
1093 wm_event_add(win, &event);
1098 static int wm_search_menu_exec(bContext *C, wmOperator *op)
1101 return OPERATOR_FINISHED;
1104 static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1107 uiPupBlock(C, wm_block_search_menu, op);
1109 return OPERATOR_CANCELLED;
1113 static int wm_search_menu_poll(bContext *C)
1115 if(CTX_wm_window(C)==NULL) return 0;
1116 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_CONSOLE) return 0; // XXX - so we can use the shortcut in the console
1117 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_TEXT) return 0; // XXX - so we can use the spacebar in the text editor
1118 if(CTX_data_edit_object(C) && CTX_data_edit_object(C)->type==OB_CURVE) return 0; // XXX - so we can use the spacebar for entering text
1122 static void WM_OT_search_menu(wmOperatorType *ot)
1124 ot->name= "Search Menu";
1125 ot->idname= "WM_OT_search_menu";
1127 ot->invoke= wm_search_menu_invoke;
1128 ot->exec= wm_search_menu_exec;
1129 ot->poll= wm_search_menu_poll;
1132 static int wm_call_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1134 char idname[BKE_ST_MAXNAME];
1135 RNA_string_get(op->ptr, "name", idname);
1137 uiPupMenuInvoke(C, idname);
1139 return OPERATOR_CANCELLED;
1142 static void WM_OT_call_menu(wmOperatorType *ot)
1144 ot->name= "Call Menu";
1145 ot->idname= "WM_OT_call_menu";
1147 ot->invoke= wm_call_menu_invoke;
1149 RNA_def_string(ot->srna, "name", "", BKE_ST_MAXNAME, "Name", "Name of the menu");
1152 /* ************ window / screen operator definitions ************** */
1154 static void WM_OT_window_duplicate(wmOperatorType *ot)
1156 ot->name= "Duplicate Window";
1157 ot->idname= "WM_OT_window_duplicate";
1158 ot->description="Duplicate the current Blender window.";
1160 ot->exec= wm_window_duplicate_op;
1161 ot->poll= WM_operator_winactive;
1164 static void WM_OT_save_homefile(wmOperatorType *ot)
1166 ot->name= "Save User Settings";
1167 ot->idname= "WM_OT_save_homefile";
1168 ot->description="Make the current file the default .blend file.";
1170 ot->invoke= WM_operator_confirm;
1171 ot->exec= WM_write_homefile;
1172 ot->poll= WM_operator_winactive;
1175 static void WM_OT_read_homefile(wmOperatorType *ot)
1177 ot->name= "Reload Start-Up File";
1178 ot->idname= "WM_OT_read_homefile";
1179 ot->description="Open the default file (doesn't save the current file).";
1181 ot->invoke= WM_operator_confirm;
1182 ot->exec= WM_read_homefile;
1183 ot->poll= WM_operator_winactive;
1185 RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
1188 /* *************** open file **************** */
1190 static void open_set_load_ui(wmOperator *op)
1192 if(!RNA_property_is_set(op->ptr, "load_ui"))
1193 RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI));
1196 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1198 RNA_string_set(op->ptr, "path", G.sce);
1199 open_set_load_ui(op);
1201 WM_event_add_fileselect(C, op);
1203 return OPERATOR_RUNNING_MODAL;
1206 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
1208 char path[FILE_MAX];
1210 RNA_string_get(op->ptr, "path", path);
1211 open_set_load_ui(op);
1213 if(RNA_boolean_get(op->ptr, "load_ui"))
1214 G.fileflags &= ~G_FILE_NO_UI;
1216 G.fileflags |= G_FILE_NO_UI;
1218 // XXX wm in context is not set correctly after WM_read_file -> crash
1219 // do it before for now, but is this correct with multiple windows?
1220 WM_event_add_notifier(C, NC_WINDOW, NULL);
1222 WM_read_file(C, path, op->reports);
1224 return OPERATOR_FINISHED;
1227 static void WM_OT_open_mainfile(wmOperatorType *ot)
1229 ot->name= "Open Blender File";
1230 ot->idname= "WM_OT_open_mainfile";
1231 ot->description="Open a Blender file.";
1233 ot->invoke= wm_open_mainfile_invoke;
1234 ot->exec= wm_open_mainfile_exec;
1235 ot->poll= WM_operator_winactive;
1237 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1239 RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file.");
1242 /* **************** link/append *************** */
1244 static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
1246 if(RNA_property_is_set(op->ptr, "path")) {
1247 return WM_operator_call(C, op);
1250 /* XXX TODO solve where to get last linked library from */
1251 RNA_string_set(op->ptr, "path", G.lib);
1252 WM_event_add_fileselect(C, op);
1253 return OPERATOR_RUNNING_MODAL;
1257 static short wm_link_append_flag(wmOperator *op)
1261 if(RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
1262 if(RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
1263 if(RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
1264 if(RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
1265 if(RNA_boolean_get(op->ptr, "instance_groups")) flag |= FILE_GROUP_INSTANCE;
1269 static void wm_link_make_library_local(Main *main, const char *libname)
1273 /* and now find the latest append lib file */
1274 for(lib= main->library.first; lib; lib=lib->id.next)
1275 if(BLI_streq(libname, lib->filename))
1284 static int wm_link_append_exec(bContext *C, wmOperator *op)
1286 Main *bmain= CTX_data_main(C);
1287 Scene *scene= CTX_data_scene(C);
1291 char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[GROUP_MAX];
1292 int idcode, totfiles=0;
1296 RNA_string_get(op->ptr, "filename", name);
1297 RNA_string_get(op->ptr, "directory", dir);
1299 /* test if we have a valid data */
1300 if(BLO_is_a_library(dir, libname, group) == 0) {
1301 BKE_report(op->reports, RPT_ERROR, "Not a library");
1302 return OPERATOR_CANCELLED;
1304 else if(group[0] == 0) {
1305 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1306 return OPERATOR_CANCELLED;
1308 else if(BLI_streq(bmain->name, libname)) {
1309 BKE_report(op->reports, RPT_ERROR, "Cannot use current file as library");
1310 return OPERATOR_CANCELLED;
1313 /* check if something is indicated for append/link */
1314 prop = RNA_struct_find_property(op->ptr, "files");
1316 totfiles= RNA_property_collection_length(op->ptr, prop);
1318 if(name[0] == '\0') {
1319 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1320 return OPERATOR_CANCELLED;
1324 else if(name[0] == '\0') {
1325 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1326 return OPERATOR_CANCELLED;
1329 /* now we have or selected, or an indicated file */
1330 if(RNA_boolean_get(op->ptr, "autoselect"))
1331 scene_deselect_all(scene);
1333 bh = BLO_blendhandle_from_file(libname);
1334 idcode = BLO_idcode_from_name(group);
1336 flag = wm_link_append_flag(op);
1338 /* tag everything, all untagged data can be made local
1339 * its also generally useful to know what is new
1341 * take extra care flag_all_listbases_ids(LIB_LINK_TAG, 0) is called after! */
1342 flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
1344 /* here appending/linking starts */
1345 mainl = BLO_library_append_begin(C, &bh, libname);
1347 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1350 RNA_BEGIN(op->ptr, itemptr, "files") {
1351 RNA_string_get(&itemptr, "name", name);
1352 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1356 BLO_library_append_end(C, mainl, &bh, idcode, flag);
1358 /* mark all library linked objects to be updated */
1359 recalc_all_library_objects(bmain);
1361 /* append, rather than linking */
1362 if((flag & FILE_LINK)==0)
1363 wm_link_make_library_local(bmain, libname);
1365 /* important we unset, otherwise these object wont
1366 * link into other scenes from this blend file */
1367 flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
1369 /* recreate dependency graph to include new objects */
1370 DAG_scene_sort(scene);
1371 DAG_ids_flush_update(0);
1373 BLO_blendhandle_close(bh);
1375 /* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
1376 BLI_strncpy(G.lib, dir, FILE_MAX);
1378 WM_event_add_notifier(C, NC_WINDOW, NULL);
1380 return OPERATOR_FINISHED;
1383 static void WM_OT_link_append(wmOperatorType *ot)
1385 ot->name= "Link/Append from Library";
1386 ot->idname= "WM_OT_link_append";
1387 ot->description= "Link or Append from a Library .blend file";
1389 ot->invoke= wm_link_append_invoke;
1390 ot->exec= wm_link_append_exec;
1391 ot->poll= WM_operator_winactive;
1393 ot->flag |= OPTYPE_UNDO;
1395 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_LOADLIB);
1397 RNA_def_boolean(ot->srna, "link", 1, "Link", "Link the objects or datablocks rather than appending.");
1398 RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects.");
1399 RNA_def_boolean(ot->srna, "active_layer", 1, "Active Layer", "Put the linked objects on the active layer.");
1400 RNA_def_boolean(ot->srna, "instance_groups", 1, "Instance Groups", "Create instances for each group as a DupliGroup.");
1401 RNA_def_boolean(ot->srna, "relative_paths", 1, "Relative Paths", "Store the library path as a relative path to current .blend file.");
1403 RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
1406 /* *************** recover last session **************** */
1408 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
1410 char filename[FILE_MAX];
1412 G.fileflags |= G_FILE_RECOVER;
1414 // XXX wm in context is not set correctly after WM_read_file -> crash
1415 // do it before for now, but is this correct with multiple windows?
1416 WM_event_add_notifier(C, NC_WINDOW, NULL);
1419 BLI_make_file_string("/", filename, btempdir, "quit.blend");
1420 WM_read_file(C, filename, op->reports);
1422 G.fileflags &= ~G_FILE_RECOVER;
1424 return OPERATOR_FINISHED;
1427 static void WM_OT_recover_last_session(wmOperatorType *ot)
1429 ot->name= "Recover Last Session";
1430 ot->idname= "WM_OT_recover_last_session";
1431 ot->description="Open the last closed file (\"quit.blend\").";
1433 ot->exec= wm_recover_last_session_exec;
1434 ot->poll= WM_operator_winactive;
1437 /* *************** recover auto save **************** */
1439 static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
1441 char path[FILE_MAX];
1443 RNA_string_get(op->ptr, "path", path);
1445 G.fileflags |= G_FILE_RECOVER;
1447 // XXX wm in context is not set correctly after WM_read_file -> crash
1448 // do it before for now, but is this correct with multiple windows?
1449 WM_event_add_notifier(C, NC_WINDOW, NULL);
1452 WM_read_file(C, path, op->reports);
1454 G.fileflags &= ~G_FILE_RECOVER;
1456 return OPERATOR_FINISHED;
1459 static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, wmEvent *event)
1461 char filename[FILE_MAX];
1463 wm_autosave_location(filename);
1464 RNA_string_set(op->ptr, "path", filename);
1465 WM_event_add_fileselect(C, op);
1467 return OPERATOR_RUNNING_MODAL;
1470 static void WM_OT_recover_auto_save(wmOperatorType *ot)
1472 ot->name= "Recover Auto Save";
1473 ot->idname= "WM_OT_recover_auto_save";
1474 ot->description="Open an automatically saved file to recover it.";
1476 ot->exec= wm_recover_auto_save_exec;
1477 ot->invoke= wm_recover_auto_save_invoke;
1478 ot->poll= WM_operator_winactive;
1480 WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER);
1483 /* *************** save file as **************** */
1485 static void untitled(char *name)
1487 if(G.save_over == 0 && strlen(name) < FILE_MAX-16) {
1488 char *c= BLI_last_slash(name);
1491 strcpy(&c[1], "untitled.blend");
1493 strcpy(name, "untitled.blend");
1497 static void save_set_compress(wmOperator *op)
1499 if(!RNA_property_is_set(op->ptr, "compress")) {
1500 if(G.save_over) /* keep flag for existing file */
1501 RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
1502 else /* use userdef for new file */
1503 RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
1507 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1509 char name[FILE_MAX];
1511 save_set_compress(op);
1513 BLI_strncpy(name, G.sce, FILE_MAX);
1515 RNA_string_set(op->ptr, "path", name);
1517 WM_event_add_fileselect(C, op);
1519 return OPERATOR_RUNNING_MODAL;
1522 /* function used for WM_OT_save_mainfile too */
1523 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
1525 char path[FILE_MAX];
1528 save_set_compress(op);
1530 if(RNA_property_is_set(op->ptr, "path"))
1531 RNA_string_get(op->ptr, "path", path);
1533 BLI_strncpy(path, G.sce, FILE_MAX);
1537 fileflags= G.fileflags;
1539 /* set compression flag */
1540 if(RNA_boolean_get(op->ptr, "compress")) fileflags |= G_FILE_COMPRESS;
1541 else fileflags &= ~G_FILE_COMPRESS;
1542 if(RNA_boolean_get(op->ptr, "relative_remap")) fileflags |= G_FILE_RELATIVE_REMAP;
1543 else fileflags &= ~G_FILE_RELATIVE_REMAP;
1545 WM_write_file(C, path, fileflags, op->reports);
1547 WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
1552 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
1554 ot->name= "Save As Blender File";
1555 ot->idname= "WM_OT_save_as_mainfile";
1556 ot->description="Save the current file in the desired location.";
1558 ot->invoke= wm_save_as_mainfile_invoke;
1559 ot->exec= wm_save_as_mainfile_exec;
1560 ot->poll= WM_operator_winactive;
1562 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1563 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1564 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory.");
1567 /* *************** save file directly ******** */
1569 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1571 char name[FILE_MAX];
1573 /* cancel if no active window */
1574 if (CTX_wm_window(C) == NULL)
1575 return OPERATOR_CANCELLED;
1577 save_set_compress(op);
1579 BLI_strncpy(name, G.sce, FILE_MAX);
1581 RNA_string_set(op->ptr, "path", name);
1584 uiPupMenuSaveOver(C, op, name);
1586 WM_event_add_fileselect(C, op);
1588 return OPERATOR_RUNNING_MODAL;
1591 static void WM_OT_save_mainfile(wmOperatorType *ot)
1593 ot->name= "Save Blender File";
1594 ot->idname= "WM_OT_save_mainfile";
1595 ot->description="Save the current Blender file.";
1597 ot->invoke= wm_save_mainfile_invoke;
1598 ot->exec= wm_save_as_mainfile_exec;
1601 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1602 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1603 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory.");
1607 /* XXX: move these collada operators to a more appropriate place */
1610 #include "../../collada/collada.h"
1612 static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *event)
1614 //char name[FILE_MAX];
1615 //BLI_strncpy(name, G.sce, FILE_MAX);
1618 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1620 WM_event_add_fileselect(C, op);
1622 return OPERATOR_RUNNING_MODAL;
1625 /* function used for WM_OT_save_mainfile too */
1626 static int wm_collada_export_exec(bContext *C, wmOperator *op)
1628 char filename[FILE_MAX];
1630 if(RNA_property_is_set(op->ptr, "path"))
1631 RNA_string_get(op->ptr, "path", filename);
1633 BLI_strncpy(filename, G.sce, FILE_MAX);
1637 //WM_write_file(C, filename, op->reports);
1638 collada_export(CTX_data_scene(C), filename);
1640 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1642 return OPERATOR_FINISHED;
1645 static void WM_OT_collada_export(wmOperatorType *ot)
1647 ot->name= "Export COLLADA";
1648 ot->idname= "WM_OT_collada_export";
1650 ot->invoke= wm_collada_export_invoke;
1651 ot->exec= wm_collada_export_exec;
1652 ot->poll= WM_operator_winactive;
1656 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1659 static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
1661 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1663 WM_event_add_fileselect(C, op);
1665 return OPERATOR_RUNNING_MODAL;
1668 /* function used for WM_OT_save_mainfile too */
1669 static int wm_collada_import_exec(bContext *C, wmOperator *op)
1671 char filename[FILE_MAX];
1673 if(RNA_property_is_set(op->ptr, "path"))
1674 RNA_string_get(op->ptr, "path", filename);
1676 BLI_strncpy(filename, G.sce, FILE_MAX);
1680 //WM_write_file(C, filename, op->reports);
1681 collada_import(C, filename);
1683 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1685 return OPERATOR_FINISHED;
1688 static void WM_OT_collada_import(wmOperatorType *ot)
1690 ot->name= "Import COLLADA";
1691 ot->idname= "WM_OT_collada_import";
1693 ot->invoke= wm_collada_import_invoke;
1694 ot->exec= wm_collada_import_exec;
1695 ot->poll= WM_operator_winactive;
1699 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1706 /* *********************** */
1708 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
1710 ot->name= "Toggle Fullscreen";
1711 ot->idname= "WM_OT_window_fullscreen_toggle";
1712 ot->description="Toggle the current window fullscreen.";
1714 ot->exec= wm_window_fullscreen_toggle_op;
1715 ot->poll= WM_operator_winactive;
1718 static int wm_exit_blender_op(bContext *C, wmOperator *op)
1720 WM_operator_free(op);
1724 return OPERATOR_FINISHED;
1727 static void WM_OT_exit_blender(wmOperatorType *ot)
1729 ot->name= "Exit Blender";
1730 ot->idname= "WM_OT_exit_blender";
1731 ot->description= "Quit Blender.";
1733 ot->invoke= WM_operator_confirm;
1734 ot->exec= wm_exit_blender_op;
1735 ot->poll= WM_operator_winactive;
1738 /* ************ default paint cursors, draw always around cursor *********** */
1740 - returns handler to free
1741 - poll(bContext): returns 1 if draw should happen
1742 - draw(bContext): drawing callback for paint cursor
1745 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
1746 wmPaintCursorDraw draw, void *customdata)
1748 wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
1750 BLI_addtail(&wm->paintcursors, pc);
1752 pc->customdata = customdata;
1759 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
1763 for(pc= wm->paintcursors.first; pc; pc= pc->next) {
1764 if(pc == (wmPaintCursor *)handle) {
1765 BLI_remlink(&wm->paintcursors, pc);
1772 /* ************ window gesture operator-callback definitions ************** */
1774 * These are default callbacks for use in operators requiring gesture input
1777 /* **************** Border gesture *************** */
1779 /* Border gesture has two types:
1780 1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border
1781 2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
1783 It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
1786 static int border_apply(bContext *C, wmOperator *op, int gesture_mode)
1788 wmGesture *gesture= op->customdata;
1789 rcti *rect= gesture->customdata;
1791 if(rect->xmin > rect->xmax)
1792 SWAP(int, rect->xmin, rect->xmax);
1793 if(rect->ymin > rect->ymax)
1794 SWAP(int, rect->ymin, rect->ymax);
1796 if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
1799 /* operator arguments and storage. */
1800 RNA_int_set(op->ptr, "xmin", rect->xmin);
1801 RNA_int_set(op->ptr, "ymin", rect->ymin);
1802 RNA_int_set(op->ptr, "xmax", rect->xmax);
1803 RNA_int_set(op->ptr, "ymax", rect->ymax);
1805 /* XXX weak; border should be configured for this without reading event types */
1806 if( RNA_struct_find_property(op->ptr, "gesture_mode") )
1807 RNA_int_set(op->ptr, "gesture_mode", gesture_mode);
1809 op->type->exec(C, op);
1814 static void wm_gesture_end(bContext *C, wmOperator *op)
1816 wmGesture *gesture= op->customdata;
1818 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
1819 op->customdata= NULL;
1821 ED_area_tag_redraw(CTX_wm_area(C));
1823 if( RNA_struct_find_property(op->ptr, "cursor") )
1824 WM_cursor_restore(CTX_wm_window(C));
1827 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
1829 if(ISTWEAK(event->type))
1830 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
1832 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
1834 /* add modal handler */
1835 WM_event_add_modal_handler(C, op);
1837 wm_gesture_tag_redraw(C);
1839 return OPERATOR_RUNNING_MODAL;
1842 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
1844 wmGesture *gesture= op->customdata;
1845 rcti *rect= gesture->customdata;
1848 if(event->type== MOUSEMOVE) {
1849 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1851 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1852 rect->xmin= rect->xmax= event->x - sx;
1853 rect->ymin= rect->ymax= event->y - sy;
1856 rect->xmax= event->x - sx;
1857 rect->ymax= event->y - sy;
1860 wm_gesture_tag_redraw(C);
1862 else if (event->type==EVT_MODAL_MAP) {
1863 switch (event->val) {
1864 case GESTURE_MODAL_BORDER_BEGIN:
1865 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1867 wm_gesture_tag_redraw(C);
1870 case GESTURE_MODAL_SELECT:
1871 case GESTURE_MODAL_DESELECT:
1872 if(border_apply(C, op, event->val)) {
1873 wm_gesture_end(C, op);
1874 return OPERATOR_FINISHED;
1876 wm_gesture_end(C, op);
1877 return OPERATOR_CANCELLED;
1880 case GESTURE_MODAL_CANCEL:
1881 wm_gesture_end(C, op);
1882 return OPERATOR_CANCELLED;
1886 // // Allow view navigation???
1888 // return OPERATOR_PASS_THROUGH;
1891 return OPERATOR_RUNNING_MODAL;
1894 /* **************** circle gesture *************** */
1895 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
1897 #ifdef GESTURE_MEMORY
1898 int circle_select_size= 25; // XXX - need some operator memory thing\!
1901 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
1903 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
1905 /* add modal handler */
1906 WM_event_add_modal_handler(C, op);
1908 wm_gesture_tag_redraw(C);
1910 return OPERATOR_RUNNING_MODAL;
1913 static void gesture_circle_apply(bContext *C, wmOperator *op)
1915 wmGesture *gesture= op->customdata;
1916 rcti *rect= gesture->customdata;
1918 if(RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_NOP)
1921 /* operator arguments and storage. */
1922 RNA_int_set(op->ptr, "x", rect->xmin);
1923 RNA_int_set(op->ptr, "y", rect->ymin);
1924 RNA_int_set(op->ptr, "radius", rect->xmax);
1927 op->type->exec(C, op);
1929 #ifdef GESTURE_MEMORY
1930 circle_select_size= rect->xmax;
1934 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
1936 wmGesture *gesture= op->customdata;
1937 rcti *rect= gesture->customdata;
1940 if(event->type== MOUSEMOVE) {
1941 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1943 rect->xmin= event->x - sx;
1944 rect->ymin= event->y - sy;
1946 wm_gesture_tag_redraw(C);
1949 gesture_circle_apply(C, op);
1951 else if (event->type==EVT_MODAL_MAP) {
1952 switch (event->val) {
1953 case GESTURE_MODAL_CIRCLE_ADD:
1954 rect->xmax += 2 + rect->xmax/10;
1955 wm_gesture_tag_redraw(C);
1957 case GESTURE_MODAL_CIRCLE_SUB:
1958 rect->xmax -= 2 + rect->xmax/10;
1959 if(rect->xmax < 1) rect->xmax= 1;
1960 wm_gesture_tag_redraw(C);
1962 case GESTURE_MODAL_SELECT:
1963 case GESTURE_MODAL_DESELECT:
1964 case GESTURE_MODAL_NOP:
1965 if(RNA_struct_find_property(op->ptr, "gesture_mode"))
1966 RNA_int_set(op->ptr, "gesture_mode", event->val);
1968 if(event->val != GESTURE_MODAL_NOP) {
1969 /* apply first click */
1970 gesture_circle_apply(C, op);
1975 case GESTURE_MODAL_CANCEL:
1976 case GESTURE_MODAL_CONFIRM:
1977 wm_gesture_end(C, op);
1978 return OPERATOR_FINISHED; /* use finish or we dont get an undo */
1981 // // Allow view navigation???
1983 // return OPERATOR_PASS_THROUGH;
1986 return OPERATOR_RUNNING_MODAL;
1990 /* template to copy from */
1991 void WM_OT_circle_gesture(wmOperatorType *ot)
1993 ot->name= "Circle Gesture";
1994 ot->idname= "WM_OT_circle_gesture";
1995 ot->description="Enter rotate mode with a circular gesture.";
1997 ot->invoke= WM_gesture_circle_invoke;
1998 ot->modal= WM_gesture_circle_modal;
2000 ot->poll= WM_operator_winactive;
2002 RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
2003 RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
2004 RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
2009 /* **************** Tweak gesture *************** */
2011 static void tweak_gesture_modal(bContext *C, wmEvent *event)
2013 wmWindow *window= CTX_wm_window(C);
2014 wmGesture *gesture= window->tweak;
2015 rcti *rect= gesture->customdata;
2018 switch(event->type) {
2021 wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
2023 rect->xmax= event->x - sx;
2024 rect->ymax= event->y - sy;
2026 if((val= wm_gesture_evaluate(C, gesture))) {
2029 event= *(window->eventstate);
2030 if(gesture->event_type==LEFTMOUSE)
2031 event.type= EVT_TWEAK_L;
2032 else if(gesture->event_type==RIGHTMOUSE)
2033 event.type= EVT_TWEAK_R;
2035 event.type= EVT_TWEAK_M;
2038 wm_event_add(window, &event);
2040 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
2041 window->tweak= NULL;
2049 if(gesture->event_type==event->type) {
2050 WM_gesture_end(C, gesture);
2051 window->tweak= NULL;
2053 /* when tweak fails we should give the other keymap entries a chance */
2054 event->val= KM_RELEASE;
2058 if(!ISTIMER(event->type)) {
2059 WM_gesture_end(C, gesture);
2060 window->tweak= NULL;
2066 /* standard tweak, called after window handlers passed on event */
2067 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
2069 wmWindow *win= CTX_wm_window(C);
2071 if(win->tweak==NULL) {
2072 if(CTX_wm_region(C)) {
2073 if(event->val==KM_PRESS) { // pressed
2074 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
2075 win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
2080 if(action & WM_HANDLER_BREAK) {
2081 WM_gesture_end(C, win->tweak);
2085 tweak_gesture_modal(C, event);
2089 /* *********************** lasso gesture ****************** */
2091 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
2093 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
2095 /* add modal handler */
2096 WM_event_add_modal_handler(C, op);
2098 wm_gesture_tag_redraw(C);
2100 if( RNA_struct_find_property(op->ptr, "cursor") )
2101 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2103 return OPERATOR_RUNNING_MODAL;
2106 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
2108 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
2110 /* add modal handler */
2111 WM_event_add_modal_handler(C, op);
2113 wm_gesture_tag_redraw(C);
2115 if( RNA_struct_find_property(op->ptr, "cursor") )
2116 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2118 return OPERATOR_RUNNING_MODAL;
2122 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
2124 wmGesture *gesture= op->customdata;
2128 short *lasso= gesture->customdata;
2130 /* operator storage as path. */
2132 for(i=0; i<gesture->points; i++, lasso+=2) {
2135 RNA_collection_add(op->ptr, "path", &itemptr);
2136 RNA_float_set_array(&itemptr, "loc", loc);
2139 wm_gesture_end(C, op);
2142 op->type->exec(C, op);
2146 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
2148 wmGesture *gesture= op->customdata;
2151 switch(event->type) {
2154 wm_gesture_tag_redraw(C);
2156 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2158 if(gesture->points == gesture->size) {
2159 short *old_lasso = gesture->customdata;
2160 gesture->customdata= MEM_callocN(2*sizeof(short)*(gesture->size + WM_LASSO_MIN_POINTS), "lasso points");
2161 memcpy(gesture->customdata, old_lasso, 2*sizeof(short)*gesture->size);
2162 gesture->size = gesture->size + WM_LASSO_MIN_POINTS;
2163 MEM_freeN(old_lasso);
2164 printf("realloc\n");
2168 short *lasso= gesture->customdata;
2169 lasso += 2 * gesture->points;
2170 lasso[0] = event->x - sx;
2171 lasso[1] = event->y - sy;
2179 if(event->val==KM_RELEASE) { /* key release */
2180 gesture_lasso_apply(C, op, event->type);
2181 return OPERATOR_FINISHED;
2185 wm_gesture_end(C, op);
2186 return OPERATOR_CANCELLED;
2188 return OPERATOR_RUNNING_MODAL;
2191 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
2193 return WM_gesture_lasso_modal(C, op, event);
2197 /* template to copy from */
2199 static int gesture_lasso_exec(bContext *C, wmOperator *op)
2201 RNA_BEGIN(op->ptr, itemptr, "path") {
2204 RNA_float_get_array(&itemptr, "loc", loc);
2205 printf("Location: %f %f\n", loc[0], loc[1]);
2209 return OPERATOR_FINISHED;
2212 void WM_OT_lasso_gesture(wmOperatorType *ot)
2216 ot->name= "Lasso Gesture";
2217 ot->idname= "WM_OT_lasso_gesture";
2218 ot->description="Select objects within the lasso as you move the pointer.";
2220 ot->invoke= WM_gesture_lasso_invoke;
2221 ot->modal= WM_gesture_lasso_modal;
2222 ot->exec= gesture_lasso_exec;
2224 ot->poll= WM_operator_winactive;
2226 prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
2227 RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
2231 /* *********************** radial control ****************** */
2233 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
2235 typedef struct wmRadialControl {
2237 float initial_value, value, max_value;
2238 int initial_mouse[2];
2243 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
2245 wmRadialControl *rc = (wmRadialControl*)customdata;
2246 ARegion *ar = CTX_wm_region(C);
2247 float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
2249 /* Keep cursor in the original place */
2250 x = rc->initial_mouse[0] - ar->winrct.xmin;
2251 y = rc->initial_mouse[1] - ar->winrct.ymin;
2255 glTranslatef((float)x, (float)y, 0.0f);
2257 if(rc->mode == WM_RADIALCONTROL_SIZE) {
2259 r2= rc->initial_value;
2261 } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
2262 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
2263 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2264 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2265 } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2266 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2267 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2271 glColor4ub(255, 255, 255, 128);
2272 glEnable( GL_LINE_SMOOTH );
2275 if(rc->mode == WM_RADIALCONTROL_ANGLE)
2276 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2279 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
2281 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2282 glRotatef(angle, 0, 0, 1);
2283 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2286 glBindTexture(GL_TEXTURE_2D, rc->tex);
2288 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2289 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2291 glEnable(GL_TEXTURE_2D);
2293 glColor4f(0,0,0, str);
2295 glVertex2f(-r3, -r3);
2297 glVertex2f(r3, -r3);
2301 glVertex2f(-r3, r3);
2303 glDisable(GL_TEXTURE_2D);
2306 glColor4ub(255, 255, 255, 128);
2307 glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
2308 glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
2309 glDisable(GL_BLEND);
2310 glDisable( GL_LINE_SMOOTH );
2315 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
2317 wmRadialControl *rc = (wmRadialControl*)op->customdata;
2318 int mode, initial_mouse[2], delta[2];
2320 double new_value = RNA_float_get(op->ptr, "new_value");
2321 int ret = OPERATOR_RUNNING_MODAL;
2323 mode = RNA_int_get(op->ptr, "mode");
2324 RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
2326 switch(event->type) {
2328 delta[0]= initial_mouse[0] - event->x;
2329 delta[1]= initial_mouse[1] - event->y;
2330 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
2332 if(mode == WM_RADIALCONTROL_SIZE)
2334 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2335 new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
2336 } else if(mode == WM_RADIALCONTROL_ANGLE)
2337 new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
2340 if(mode == WM_RADIALCONTROL_STRENGTH)
2341 new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f;
2343 new_value = ((int)new_value + 5) / 10*10;
2349 ret = OPERATOR_CANCELLED;
2353 op->type->exec(C, op);
2354 ret = OPERATOR_FINISHED;
2359 if(new_value > rc->max_value)
2360 new_value = rc->max_value;
2361 else if(new_value < 0)
2364 /* Update paint data */
2365 rc->value = new_value;
2367 RNA_float_set(op->ptr, "new_value", new_value);
2369 if(ret != OPERATOR_RUNNING_MODAL) {
2370 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
2374 ED_region_tag_redraw(CTX_wm_region(C));
2379 /* Expects the operator customdata to be an ImBuf (or NULL) */
2380 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
2382 wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
2383 int mode = RNA_int_get(op->ptr, "mode");
2384 float initial_value = RNA_float_get(op->ptr, "initial_value");
2385 int mouse[2] = {event->x, event->y};
2387 if(mode == WM_RADIALCONTROL_SIZE) {
2388 rc->max_value = 200;
2389 mouse[0]-= initial_value;
2391 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2393 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
2395 else if(mode == WM_RADIALCONTROL_ANGLE) {
2396 rc->max_value = 360;
2397 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
2398 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
2399 initial_value *= 180.0f/M_PI;
2402 if(op->customdata) {
2403 ImBuf *im = (ImBuf*)op->customdata;
2404 /* Build GL texture */
2405 glGenTextures(1, &rc->tex);
2406 glBindTexture(GL_TEXTURE_2D, rc->tex);
2407 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
2408 MEM_freeN(im->rect_float);
2412 RNA_int_set_array(op->ptr, "initial_mouse", mouse);
2413 RNA_float_set(op->ptr, "new_value", initial_value);
2415 op->customdata = rc;
2417 rc->initial_value = initial_value;
2418 rc->initial_mouse[0] = mouse[0];
2419 rc->initial_mouse[1] = mouse[1];
2420 rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
2421 wm_radial_control_paint, op->customdata);
2423 /* add modal handler */
2424 WM_event_add_modal_handler(C, op);
2426 WM_radial_control_modal(C, op, event);
2428 return OPERATOR_RUNNING_MODAL;
2431 /* Gets a descriptive string of the operation */
2432 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
2434 int mode = RNA_int_get(op->ptr, "mode");
2435 float v = RNA_float_get(op->ptr, "new_value");
2437 if(mode == WM_RADIALCONTROL_SIZE)
2438 sprintf(str, "Size: %d", (int)v);
2439 else if(mode == WM_RADIALCONTROL_STRENGTH)
2440 sprintf(str, "Strength: %d", (int)v);
2441 else if(mode == WM_RADIALCONTROL_ANGLE)
2442 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
2445 /** Important: this doesn't define an actual operator, it
2446 just sets up the common parts of the radial control op. **/
2447 void WM_OT_radial_control_partial(wmOperatorType *ot)
2449 static EnumPropertyItem radial_mode_items[] = {
2450 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
2451 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
2452 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
2453 {0, NULL, 0, NULL, NULL}};
2455 /* Should be set in custom invoke() */
2456 RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
2458 /* Set internally, should be used in custom exec() to get final value */
2459 RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
2461 /* Should be set before calling operator */
2462 RNA_def_enum(ot->srna, "mode", radial_mode_items, 0, "Mode", "");
2465 RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
2468 /* ************************** timer for testing ***************** */
2470 /* uses no type defines, fully local testing function anyway... ;) */
2472 static int redraw_timer_exec(bContext *C, wmOperator *op)
2474 ARegion *ar= CTX_wm_region(C);
2475 double stime= PIL_check_seconds_timer();
2476 int type = RNA_int_get(op->ptr, "type");
2477 int iter = RNA_int_get(op->ptr, "iterations");
2484 for(a=0; a<iter; a++) {
2486 ED_region_do_draw(C, ar);
2489 wmWindow *win= CTX_wm_window(C);
2491 ED_region_tag_redraw(ar);
2494 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2497 wmWindow *win= CTX_wm_window(C);
2500 ScrArea *sa_back= CTX_wm_area(C);
2501 ARegion *ar_back= CTX_wm_region(C);
2503 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
2505 CTX_wm_area_set(C, sa);
2507 for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next) {
2508 if(ar_iter->swinid) {
2509 CTX_wm_region_set(C, ar_iter);
2510 ED_region_do_draw(C, ar_iter);
2515 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2517 CTX_wm_area_set(C, sa_back);
2518 CTX_wm_region_set(C, ar_back);
2521 wmWindow *win= CTX_wm_window(C);
2524 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
2525 ED_area_tag_redraw(sa);
2528 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2531 Scene *scene= CTX_data_scene(C);
2533 if(a & 1) scene->r.cfra--;
2534 else scene->r.cfra++;
2535 scene_update_for_newframe(scene, scene->lay);
2543 time= ((PIL_check_seconds_timer()-stime)*1000);
2545 if(type==0) infostr= "Draw Region";
2546 if(type==1) infostr= "Draw Region and Swap";
2547 if(type==2) infostr= "Draw Window";
2548 if(type==3) infostr= "Draw Window and Swap";
2549 if(type==4) infostr= "Animation Steps";
2550 if(type==5) infostr= "Undo/Redo";
2554 BKE_reportf(op->reports, RPT_INFO, "%d x %s: %.2f ms, average: %.4f", iter, infostr, time, time/iter);
2556 return OPERATOR_FINISHED;
2559 static void WM_OT_redraw_timer(wmOperatorType *ot)
2561 static EnumPropertyItem prop_type_items[] = {
2562 {0, "DRAW", 0, "Draw Region", ""},
2563 {1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
2564 {2, "DRAW_WIN", 0, "Draw Window", ""},
2565 {3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
2566 {4, "ANIM_STEP", 0, "Anim Step", ""},
2567 {5, "UNDO", 0, "Undo/Redo", ""},
2568 {0, NULL, 0, NULL, NULL}};
2570 ot->name= "Redraw Timer";
2571 ot->idname= "WM_OT_redraw_timer";
2572 ot->description="Simple redraw timer to test the speed of updating the interface.";
2574 ot->invoke= WM_menu_invoke;
2575 ot->exec= redraw_timer_exec;
2576 ot->poll= WM_operator_winactive;
2578 RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
2579 RNA_def_int(ot->srna, "iterations", 10, 1,INT_MAX, "Iterations", "Number of times to redraw", 1,1000);
2583 /* ************************** memory statistics for testing ***************** */
2585 static int memory_statistics_exec(bContext *C, wmOperator *op)
2587 MEM_printmemlist_stats();
2588 return OPERATOR_FINISHED;
2591 static void WM_OT_memory_statistics(wmOperatorType *ot)
2593 ot->name= "Memory Statistics";
2594 ot->idname= "WM_OT_memory_statistics";
2595 ot->description= "Print memory statistics to the console.";
2597 ot->exec= memory_statistics_exec;
2600 /* ******************************************************* */
2602 /* called on initialize WM_exit() */
2603 void wm_operatortype_free(void)
2607 for(ot= global_ops.first; ot; ot= ot->next) {
2609 wm_operatortype_free_macro(ot);
2611 if(ot->ext.srna) /* python operator, allocs own string */
2612 MEM_freeN(ot->idname);
2615 BLI_freelistN(&global_ops);
2618 /* called on initialize WM_init() */
2619 void wm_operatortype_init(void)
2621 WM_operatortype_append(WM_OT_window_duplicate);
2622 WM_operatortype_append(WM_OT_read_homefile);
2623 WM_operatortype_append(WM_OT_save_homefile);
2624 WM_operatortype_append(WM_OT_window_fullscreen_toggle);
2625 WM_operatortype_append(WM_OT_exit_blender);
2626 WM_operatortype_append(WM_OT_open_mainfile);
2627 WM_operatortype_append(WM_OT_link_append);
2628 WM_operatortype_append(WM_OT_recover_last_session);
2629 WM_operatortype_append(WM_OT_recover_auto_save);
2630 WM_operatortype_append(WM_OT_save_as_mainfile);
2631 WM_operatortype_append(WM_OT_save_mainfile);
2632 WM_operatortype_append(WM_OT_redraw_timer);
2633 WM_operatortype_append(WM_OT_memory_statistics);
2634 WM_operatortype_append(WM_OT_debug_menu);
2635 WM_operatortype_append(WM_OT_splash);
2636 WM_operatortype_append(WM_OT_search_menu);
2637 WM_operatortype_append(WM_OT_call_menu);
2640 /* XXX: move these */
2641 WM_operatortype_append(WM_OT_collada_export);
2642 WM_operatortype_append(WM_OT_collada_import);
2647 /* called in transform_ops.c, on each regeneration of keymaps */
2648 static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
2650 static EnumPropertyItem modal_items[] = {
2651 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2652 {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
2653 {GESTURE_MODAL_CIRCLE_ADD, "ADD", 0, "Add", ""},
2654 {GESTURE_MODAL_CIRCLE_SUB, "SUBTRACT", 0, "Subtract", ""},
2656 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2657 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2658 {GESTURE_MODAL_NOP,"NOP", 0, "No Operation", ""},
2661 {0, NULL, 0, NULL, NULL}};
2663 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Gesture Circle");
2665 /* this function is called for each spacetype, only needs to add map once */
2668 keymap= WM_modalkeymap_add(keyconf, "View3D Gesture Circle", modal_items);
2670 /* items for modal map */
2671 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2672 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2674 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CONFIRM);
2675 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, 0, 0, GESTURE_MODAL_CONFIRM);
2677 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_SELECT);
2679 #if 0 // Durien guys like this :S
2680 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2681 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_NOP);
2683 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_DESELECT); // defailt 2.4x
2684 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP); // defailt 2.4x
2687 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP);
2689 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2690 WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2691 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2692 WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2694 /* assign map to operators */
2695 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
2696 WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
2700 /* called in transform_ops.c, on each regeneration of keymaps */
2701 static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
2703 static EnumPropertyItem modal_items[] = {
2704 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2705 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2706 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2707 {GESTURE_MODAL_BORDER_BEGIN, "BEGIN", 0, "Begin", ""},
2708 {0, NULL, 0, NULL, NULL}};
2710 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Gesture Border");
2712 /* this function is called for each spacetype, only needs to add map once */
2715 keymap= WM_modalkeymap_add(keyconf, "Gesture Border", modal_items);
2717 /* items for modal map */
2718 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2719 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2721 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2722 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_SELECT);
2724 #if 0 // Durian guys like this
2725 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_BORDER_BEGIN);
2726 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2728 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2729 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_DESELECT);
2732 /* assign map to operators */
2733 WM_modalkeymap_assign(keymap, "ACTION_OT_select_border");
2734 WM_modalkeymap_assign(keymap, "ANIM_OT_channels_select_border");
2735 WM_modalkeymap_assign(keymap, "ANIM_OT_previewrange_set");
2736 WM_modalkeymap_assign(keymap, "CONSOLE_OT_select_border");
2737 WM_modalkeymap_assign(keymap, "FILE_OT_select_border");
2738 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_border");
2739 WM_modalkeymap_assign(keymap, "MARKER_OT_select_border");
2740 WM_modalkeymap_assign(keymap, "NLA_OT_select_border");
2741 WM_modalkeymap_assign(keymap, "NODE_OT_select_border");
2742 // WM_modalkeymap_assign(keymap, "SCREEN_OT_border_select"); // template
2743 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
2744 WM_modalkeymap_assign(keymap, "UV_OT_select_border");
2745 WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
2746 WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
2747 WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");
2748 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_border");
2749 WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border"); // XXX TODO: zoom border should perhaps map rightmouse to zoom out instead of in+cancel
2752 /* default keymap for windows and screens, only call once per WM */
2753 void wm_window_keymap(wmKeyConfig *keyconf)
2755 wmKeyMap *keymap= WM_keymap_find(keyconf, "Window", 0, 0);
2758 /* note, this doesn't replace existing keymap items */
2759 WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2761 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0);
2762 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2763 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_OSKEY, 0);
2764 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_OSKEY, 0);
2765 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2766 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_OSKEY, 0);
2768 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_CTRL, 0);
2769 WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
2770 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2771 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0);
2772 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
2773 WM_keymap_add_item(keymap, "WM_OT_link_append", OKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2774 kmi= WM_keymap_add_item(keymap, "WM_OT_link_append", F1KEY, KM_PRESS, KM_SHIFT, 0);
2775 RNA_boolean_set(kmi->ptr, "link", FALSE);
2777 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0);
2778 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
2779 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2780 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
2782 WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
2783 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
2786 WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2787 WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2788 WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
2790 /* Space switching */
2793 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
2794 RNA_string_set(kmi->ptr, "path", "area.type");
2795 RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR");
2797 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0);
2798 RNA_string_set(kmi->ptr, "path", "area.type");
2799 RNA_string_set(kmi->ptr, "value", "NODE_EDITOR");
2801 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F4KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was data browser */
2802 RNA_string_set(kmi->ptr, "path", "area.type");
2803 RNA_string_set(kmi->ptr, "value", "CONSOLE");
2805 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F5KEY, KM_PRESS, KM_SHIFT, 0);
2806 RNA_string_set(kmi->ptr, "path", "area.type");
2807 RNA_string_set(kmi->ptr, "value", "VIEW_3D");
2809 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F6KEY, KM_PRESS, KM_SHIFT, 0);
2810 RNA_string_set(kmi->ptr, "path", "area.type");
2811 RNA_string_set(kmi->ptr, "value", "GRAPH_EDITOR");
2813 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F7KEY, KM_PRESS, KM_SHIFT, 0);
2814 RNA_string_set(kmi->ptr, "path", "area.type");
2815 RNA_string_set(kmi->ptr, "value", "PROPERTIES");
2817 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F8KEY, KM_PRESS, KM_SHIFT, 0);
2818 RNA_string_set(kmi->ptr, "path", "area.type");
2819 RNA_string_set(kmi->ptr, "value", "SEQUENCE_EDITOR");
2821 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F9KEY, KM_PRESS, KM_SHIFT, 0);
2822 RNA_string_set(kmi->ptr, "path", "area.type");
2823 RNA_string_set(kmi->ptr, "value", "OUTLINER");
2825 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F10KEY, KM_PRESS, KM_SHIFT, 0);
2826 RNA_string_set(kmi->ptr, "path", "area.type");
2827 RNA_string_set(kmi->ptr, "value", "IMAGE_EDITOR");
2829 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F11KEY, KM_PRESS, KM_SHIFT, 0);
2830 RNA_string_set(kmi->ptr, "path", "area.type");
2831 RNA_string_set(kmi->ptr, "value", "TEXT_EDITOR");
2833 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0);
2834 RNA_string_set(kmi->ptr, "path", "area.type");
2835 RNA_string_set(kmi->ptr, "value", "DOPESHEET_EDITOR");
2837 gesture_circle_modal_keymap(keyconf);
2838 gesture_border_modal_keymap(keyconf);
2841 /* Generic itemf's for operators that take library args */
2842 static EnumPropertyItem *rna_id_itemf(bContext *C, PointerRNA *ptr, int *free, ID *id)
2844 EnumPropertyItem *item= NULL, item_tmp;
2848 memset(&item_tmp, 0, sizeof(item_tmp));
2850 for( ; id; id= id->next) {
2851 item_tmp.identifier= item_tmp.name= id->name+2;
2852 item_tmp.value= i++;
2853 RNA_enum_item_add(&item, &totitem, &item_tmp);
2856 RNA_enum_item_end(&item, &totitem);
2863 EnumPropertyItem *RNA_group_itemf(bContext *C, PointerRNA *ptr, int *free)
2865 return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->group.first);
2867 EnumPropertyItem *RNA_scene_itemf(bContext *C, PointerRNA *ptr, int *free)
2869 return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->scene.first);