Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_wm_api.c
| Show All 25 Lines | |||||
| /** \file blender/makesrna/intern/rna_wm_api.c | /** \file blender/makesrna/intern/rna_wm_api.c | ||||
| * \ingroup RNA | * \ingroup RNA | ||||
| */ | */ | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <ctype.h> | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| ▲ Show 20 Lines • Show All 428 Lines • ▼ Show 20 Lines | static PointerRNA rna_WindoManager_operator_properties_last(const char *idname) | ||||
| if (ot != NULL) { | if (ot != NULL) { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| WM_operator_last_properties_ensure(ot, &ptr); | WM_operator_last_properties_ensure(ot, &ptr); | ||||
| return ptr; | return ptr; | ||||
| } | } | ||||
| return PointerRNA_NULL; | return PointerRNA_NULL; | ||||
| } | } | ||||
| static wmEvent *rna_Window_event_add_simulate( | |||||
| wmWindow *win, ReportList *reports, | |||||
| int type, int value, const char *unicode, | |||||
| int x, int y, | |||||
| bool shift, bool ctrl, bool alt, bool oskey) | |||||
| { | |||||
| if ((G.f & G_EVENT_SIMULATE) == 0) { | |||||
| BKE_report(reports, RPT_ERROR, "Not running with '--enable-event-simulate' enabled"); | |||||
| return NULL; | |||||
| } | |||||
| if (!ELEM(value, KM_PRESS, KM_RELEASE, KM_NOTHING)) { | |||||
| BKE_report(reports, RPT_ERROR, "value: only PRESS/RELEASE/NOTHING are supported"); | |||||
| return NULL; | |||||
| } | |||||
| if (ISKEYBOARD(type) || ISMOUSE_BUTTON(type)) { | |||||
| if (!ELEM(value, KM_PRESS, KM_RELEASE)) { | |||||
| BKE_report(reports, RPT_ERROR, "value: must be PRESS/RELEASE for keyboard/buttons"); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| if (ELEM(type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { | |||||
| if (value != KM_NOTHING) { | |||||
| BKE_report(reports, RPT_ERROR, "value: must be NOTHING for motion"); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| if (unicode != NULL) { | |||||
| if (value != KM_PRESS) { | |||||
| BKE_report(reports, RPT_ERROR, "value: must be PRESS when unicode is set"); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| /* TODO: validate NDOF. */ | |||||
| char ascii = 0; | |||||
| if (unicode != NULL) { | |||||
| int len = BLI_str_utf8_size(unicode); | |||||
| if (len == -1 || unicode[len] != '\0') { | |||||
| BKE_report(reports, RPT_ERROR, "Only a single character supported"); | |||||
| return NULL; | |||||
| } | |||||
| if (len == 1 && isascii(unicode[0])) { | |||||
| ascii = unicode[0]; | |||||
| } | |||||
| } | |||||
| wmEvent e = {NULL}; | |||||
| e.type = type; | |||||
| e.val = value; | |||||
| e.x = x; | |||||
| e.y = y; | |||||
| /* Note: KM_MOD_FIRST, KM_MOD_SECOND aren't used anywhere, set as bools */ | |||||
| e.shift = shift; | |||||
| e.ctrl = ctrl; | |||||
| e.alt = alt; | |||||
| e.oskey = oskey; | |||||
| const wmEvent *evt = win->eventstate; | |||||
brecht: I suggest to initialize `wmEvent e = win->eventstate;` and then fill in the other fields. | |||||
campbellbartonAuthorUnsubmitted Not Done Inline ActionsMissed this comment, done rB0822af4c4813f503dcd5de20facc588f67b1f9a6 campbellbarton: Missed this comment, done rB0822af4c4813f503dcd5de20facc588f67b1f9a6 | |||||
| e.prevx = evt->x; | |||||
| e.prevy = evt->y; | |||||
| e.prevval = evt->val; | |||||
| e.prevtype = evt->type; | |||||
| if (unicode != NULL) { | |||||
| e.ascii = ascii; | |||||
| STRNCPY(e.utf8_buf, unicode); | |||||
| } | |||||
| return WM_event_add_simulate(win, &e); | |||||
| } | |||||
| #else | #else | ||||
| #define WM_GEN_INVOKE_EVENT (1 << 0) | #define WM_GEN_INVOKE_EVENT (1 << 0) | ||||
| #define WM_GEN_INVOKE_SIZE (1 << 1) | #define WM_GEN_INVOKE_SIZE (1 << 1) | ||||
| #define WM_GEN_INVOKE_RETURN (1 << 2) | #define WM_GEN_INVOKE_RETURN (1 << 2) | ||||
| static void rna_generic_op_invoke(FunctionRNA *func, int flag) | static void rna_generic_op_invoke(FunctionRNA *func, int flag) | ||||
| { | { | ||||
| Show All 40 Lines | void RNA_api_window(StructRNA *srna) | ||||
| func = RNA_def_function(srna, "cursor_modal_set", "WM_cursor_modal_set"); | func = RNA_def_function(srna, "cursor_modal_set", "WM_cursor_modal_set"); | ||||
| parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE); | parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE); | ||||
| RNA_def_property_enum_items(parm, rna_enum_window_cursor_items); | RNA_def_property_enum_items(parm, rna_enum_window_cursor_items); | ||||
| RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | ||||
| RNA_def_function_ui_description(func, "Set the cursor, so the previous cursor can be restored"); | RNA_def_function_ui_description(func, "Set the cursor, so the previous cursor can be restored"); | ||||
| RNA_def_function(srna, "cursor_modal_restore", "WM_cursor_modal_restore"); | RNA_def_function(srna, "cursor_modal_restore", "WM_cursor_modal_restore"); | ||||
| RNA_def_function_ui_description(func, "Restore the previous cursor after calling ``cursor_modal_set``"); | RNA_def_function_ui_description(func, "Restore the previous cursor after calling ``cursor_modal_set``"); | ||||
| /* Arguments match 'rna_KeyMap_item_new'. */ | |||||
| func = RNA_def_function(srna, "event_simulate", "rna_Window_event_add_simulate"); | |||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS); | |||||
| parm = RNA_def_enum(func, "type", rna_enum_event_type_items, 0, "Type", ""); | |||||
| RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | |||||
| parm = RNA_def_enum(func, "value", rna_enum_event_value_items, 0, "Value", ""); | |||||
| RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | |||||
| parm = RNA_def_string(func, "unicode", NULL, 0, "", ""); | |||||
| RNA_def_parameter_clear_flags(parm, PROP_NEVER_NULL, 0); | |||||
| RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX); | |||||
| RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX); | |||||
| RNA_def_boolean(func, "shift", 0, "Shift", ""); | |||||
| RNA_def_boolean(func, "ctrl", 0, "Ctrl", ""); | |||||
| RNA_def_boolean(func, "alt", 0, "Alt", ""); | |||||
| RNA_def_boolean(func, "oskey", 0, "OS Key", ""); | |||||
| parm = RNA_def_pointer(func, "event", "Event", "Item", "Added key map item"); | |||||
| RNA_def_function_return(func, parm); | |||||
| } | } | ||||
| void RNA_api_wm(StructRNA *srna) | void RNA_api_wm(StructRNA *srna) | ||||
| { | { | ||||
| FunctionRNA *func; | FunctionRNA *func; | ||||
| PropertyRNA *parm; | PropertyRNA *parm; | ||||
| func = RNA_def_function(srna, "fileselect_add", "WM_event_add_fileselect"); | func = RNA_def_function(srna, "fileselect_add", "WM_event_add_fileselect"); | ||||
| ▲ Show 20 Lines • Show All 478 Lines • Show Last 20 Lines | |||||
I suggest to initialize wmEvent e = win->eventstate; and then fill in the other fields.
That's what the WM code does as well so it's maybe a bit more future proof in case extra fields get added.