bool ED_view3d_context_activate(bContext *C) { bScreen *sc = CTX_wm_screen(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar; /* sa can be NULL when called from python */ if (sa == NULL || sa->spacetype != SPACE_VIEW3D) { sa = BKE_screen_find_big_area(sc, SPACE_VIEW3D, 0); } if (sa == NULL) { return false; } ar = BKE_area_find_region_active_win(sa); if (ar == NULL) { return false; } /* bad context switch .. */ CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); return true; }
/* Graph Editor View Settings */ static void graph_panel_view(const bContext *C, Panel *pa) { bScreen *sc = CTX_wm_screen(C); SpaceIpo *sipo = CTX_wm_space_graph(C); Scene *scene = CTX_data_scene(C); PointerRNA spaceptr, sceneptr; uiLayout *col, *sub, *row; /* get RNA pointers for use when creating the UI elements */ RNA_id_pointer_create(&scene->id, &sceneptr); RNA_pointer_create(&sc->id, &RNA_SpaceGraphEditor, sipo, &spaceptr); /* 2D-Cursor */ col = uiLayoutColumn(pa->layout, FALSE); uiItemR(col, &spaceptr, "show_cursor", 0, NULL, ICON_NONE); sub = uiLayoutColumn(col, TRUE); uiLayoutSetActive(sub, RNA_boolean_get(&spaceptr, "show_cursor")); uiItemO(sub, IFACE_("Cursor from Selection"), ICON_NONE, "GRAPH_OT_frame_jump"); sub = uiLayoutColumn(col, TRUE); uiLayoutSetActive(sub, RNA_boolean_get(&spaceptr, "show_cursor")); row = uiLayoutSplit(sub, 0.7f, TRUE); uiItemR(row, &sceneptr, "frame_current", 0, IFACE_("Cursor X"), ICON_NONE); uiItemEnumO(row, "GRAPH_OT_snap", IFACE_("To Keys"), 0, "type", GRAPHKEYS_SNAP_CFRA); row = uiLayoutSplit(sub, 0.7f, TRUE); uiItemR(row, &spaceptr, "cursor_position_y", 0, IFACE_("Cursor Y"), ICON_NONE); uiItemEnumO(row, "GRAPH_OT_snap", IFACE_("To Keys"), 0, "type", GRAPHKEYS_SNAP_VALUE); }
/** * \brief get the ID from the screen. */ static void depthdropper_depth_sample_pt( bContext *C, DepthDropper *ddr, int mx, int my, float *r_depth) { /* we could use some clever */ bScreen *screen = CTX_wm_screen(C); ScrArea *sa = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my); Scene *scene = CTX_data_scene(C); ScrArea *area_prev = CTX_wm_area(C); ARegion *ar_prev = CTX_wm_region(C); ddr->name[0] = '\0'; if (sa) { if (sa->spacetype == SPACE_VIEW3D) { ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my); if (ar) { struct Depsgraph *depsgraph = CTX_data_depsgraph(C); View3D *v3d = sa->spacedata.first; RegionView3D *rv3d = ar->regiondata; /* weak, we could pass in some reference point */ const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; const int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; float co[3]; CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); /* grr, always draw else we leave stale text */ ED_region_tag_redraw(ar); view3d_operator_needs_opengl(C); if (ED_view3d_autodist(depsgraph, ar, v3d, mval, co, true, NULL)) { const float mval_center_fl[2] = {(float)ar->winx / 2, (float)ar->winy / 2}; float co_align[3]; /* quick way to get view-center aligned point */ ED_view3d_win_to_3d(v3d, ar, co, mval_center_fl, co_align); *r_depth = len_v3v3(view_co, co_align); bUnit_AsString2(ddr->name, sizeof(ddr->name), (double)*r_depth, 4, B_UNIT_LENGTH, &scene->unit, false); } else { BLI_strncpy(ddr->name, "Nothing under cursor", sizeof(ddr->name)); } } } } CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, ar_prev); }
/* would use BKE_screen_find_big_area(...) but this is too specific */ static ScrArea *biggest_non_image_area(bContext *C) { bScreen *sc = CTX_wm_screen(C); ScrArea *sa, *big = NULL; int size, maxsize = 0, bwmaxsize = 0; short foundwin = 0; for (sa = sc->areabase.first; sa; sa = sa->next) { if (sa->winx > 30 && sa->winy > 30) { size = sa->winx * sa->winy; if (sa->spacetype == SPACE_BUTS) { if (foundwin == 0 && size > bwmaxsize) { bwmaxsize = size; big = sa; } } else if (sa->spacetype != SPACE_IMAGE && size > maxsize) { maxsize = size; big = sa; foundwin = 1; } } } return big; }
static void uilist_draw_item(uiList *ui_list, bContext *C, uiLayout *layout, PointerRNA *dataptr, PointerRNA *itemptr, int icon, PointerRNA *active_dataptr, const char *active_propname, int index, int flt_flag) { extern FunctionRNA rna_UIList_draw_item_func; PointerRNA ul_ptr; ParameterList list; FunctionRNA *func; RNA_pointer_create(&CTX_wm_screen(C)->id, ui_list->type->ext.srna, ui_list, &ul_ptr); func = &rna_UIList_draw_item_func; /* RNA_struct_find_function(&ul_ptr, "draw_item"); */ RNA_parameter_list_create(&list, &ul_ptr, func); RNA_parameter_set_lookup(&list, "context", &C); RNA_parameter_set_lookup(&list, "layout", &layout); RNA_parameter_set_lookup(&list, "data", dataptr); RNA_parameter_set_lookup(&list, "item", itemptr); RNA_parameter_set_lookup(&list, "icon", &icon); RNA_parameter_set_lookup(&list, "active_data", active_dataptr); RNA_parameter_set_lookup(&list, "active_property", &active_propname); RNA_parameter_set_lookup(&list, "index", &index); RNA_parameter_set_lookup(&list, "flt_flag", &flt_flag); ui_list->type->ext.call((bContext *)C, &ul_ptr, func, &list); RNA_parameter_list_free(&list); }
bool ED_view3d_context_activate(bContext *C) { bScreen *sc = CTX_wm_screen(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar; /* sa can be NULL when called from python */ if (sa == NULL || sa->spacetype != SPACE_VIEW3D) for (sa = sc->areabase.first; sa; sa = sa->next) if (sa->spacetype == SPACE_VIEW3D) break; if (!sa) return false; for (ar = sa->regionbase.first; ar; ar = ar->next) if (ar->regiontype == RGN_TYPE_WINDOW) break; if (!ar) return false; /* bad context switch .. */ CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); return true; }
static int tree_element_active_world(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set) { TreeElement *tep; TreeStoreElem *tselem = NULL; Scene *sce = NULL; tep = te->parent; if (tep) { tselem = TREESTORE(tep); if (tselem->type == 0) sce = (Scene *)tselem->id; } if (set) { // make new scene active if (sce && scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } } if (tep == NULL || tselem->id == (ID *)scene) { if (set) { // XXX extern_set_butspace(F8KEY, 0); } else { return 1; } } return 0; }
static PointerRNA rna_Context_space_data_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; PointerRNA newptr; RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &newptr); return newptr; }
static PointerRNA rna_Context_region_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; PointerRNA newptr; RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C), &newptr); return newptr; }
static int read_undosave(bContext *C, UndoElem *uel) { char mainstr[sizeof(G.main->name)]; int success = 0, fileflags; /* This is needed so undoing/redoing doesn't crash with threaded previews going */ WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C)); BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */ fileflags = G.fileflags; G.fileflags |= G_FILE_NO_UI; if (UNDO_DISK) success = (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL); else success = BKE_read_file_from_memfile(C, &uel->memfile, NULL); /* restore */ BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */ G.fileflags = fileflags; if (success) { /* important not to update time here, else non keyed tranforms are lost */ DAG_on_visible_update(G.main, false); } return success; }
void gpencil_panel_standard_header(const bContext *C, Panel *pa) { PointerRNA ptr; RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &ptr); uiItemR(pa->layout, &ptr, "show_grease_pencil", 0, "", ICON_NONE); }
void outliner_do_object_operation(bContext *C, Scene *scene_act, SpaceOops *soops, ListBase *lb, void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *)) { TreeElement *te; TreeStoreElem *tselem; for (te = lb->first; te; te = te->next) { tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { if (tselem->type == 0 && te->idcode == ID_OB) { // when objects selected in other scenes... dunno if that should be allowed Scene *scene_owner = (Scene *)outliner_search_back(soops, te, ID_SCE); if (scene_owner && scene_act != scene_owner) { ED_screen_set_scene(C, CTX_wm_screen(C), scene_owner); } /* important to use 'scene_owner' not scene_act else deleting objects can crash. * only use 'scene_act' when 'scene_owner' is NULL, which can happen when the * outliner isn't showing scenes: Visible Layer draw mode for eg. */ operation_cb(C, scene_owner ? scene_owner : scene_act, te, NULL, tselem); } } if (TSELEM_OPEN(tselem, soops)) { outliner_do_object_operation(C, scene_act, soops, &te->subtree, operation_cb); } } }
/* note, init has to be called succesfully */ static void ed_marker_move_apply(bContext *C, wmOperator *op) { #ifdef DURIAN_CAMERA_SWITCH bScreen *sc = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); Object *camera = scene->camera; #endif MarkerMove *mm = op->customdata; TimeMarker *marker; int a, offs; offs = RNA_int_get(op->ptr, "frames"); for (a = 0, marker = mm->markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { marker->frame = mm->oldframe[a] + offs; a++; } } WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); #ifdef DURIAN_CAMERA_SWITCH /* so we get view3d redraws */ BKE_scene_camera_switch_update(scene); if (camera != scene->camera) { BKE_screen_view3d_scene_sync(sc); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); } #endif }
void ED_screen_do_listen(bContext *C, wmNotifier *note) { wmWindow *win = CTX_wm_window(C); bScreen *screen = CTX_wm_screen(C); /* generic notes */ switch (note->category) { case NC_WM: if (note->data == ND_FILEREAD) { screen->do_draw = true; } break; case NC_WINDOW: screen->do_draw = true; break; case NC_SCREEN: if (note->action == NA_EDITED) { screen->do_draw = screen->do_refresh = true; } break; case NC_SCENE: if (note->data == ND_MODE) { region_cursor_set(win, true); } break; } }
static int actkeys_viewall(bContext *C, const short onlySel) { bAnimContext ac; View2D *v2d; float extra; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; v2d= &ac.ar->v2d; /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, onlySel); extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin); v2d->cur.xmin -= extra; v2d->cur.xmax += extra; /* set vertical range */ v2d->cur.ymax= 0.0f; v2d->cur.ymin= (float)-(v2d->mask.ymax - v2d->mask.ymin); /* do View2D syncing */ UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); /* just redraw this view */ ED_area_tag_redraw(CTX_wm_area(C)); return OPERATOR_FINISHED; }
static int editsource_exec(bContext *C, wmOperator *op) { uiBut *but = UI_context_active_but_get(C); if (but) { GHashIterator ghi; struct uiEditSourceButStore *but_store = NULL; ARegion *ar = CTX_wm_region(C); int ret; /* needed else the active button does not get tested */ UI_screen_free_active_but(C, CTX_wm_screen(C)); // printf("%s: begin\n", __func__); /* take care not to return before calling ui_editsource_active_but_clear */ ui_editsource_active_but_set(but); /* redraw and get active button python info */ ED_region_do_layout(C, ar); ED_region_do_draw(C, ar); ar->do_draw = false; for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash); BLI_ghashIterator_done(&ghi) == false; BLI_ghashIterator_step(&ghi)) { uiBut *but_key = BLI_ghashIterator_getKey(&ghi); if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) { but_store = BLI_ghashIterator_getValue(&ghi); break; } } if (but_store) { if (but_store->py_dbg_ln != -1) { ret = editsource_text_edit(C, op, but_store->py_dbg_fn, but_store->py_dbg_ln); } else { BKE_report( op->reports, RPT_ERROR, "Active button is not from a script, cannot edit source"); ret = OPERATOR_CANCELLED; } } else { BKE_report(op->reports, RPT_ERROR, "Active button match cannot be found"); ret = OPERATOR_CANCELLED; } ui_editsource_active_but_clear(); // printf("%s: end\n", __func__); return ret; } else { BKE_report(op->reports, RPT_ERROR, "Active button not found"); return OPERATOR_CANCELLED; } }
static int tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set, bool recursive) { TreeStoreElem *tselem = TREESTORE(te); Scene *sce; Base *base; Object *ob = NULL; /* if id is not object, we search back */ if (te->idcode == ID_OB) { ob = (Object *)tselem->id; } else { ob = (Object *)outliner_search_back(soops, te, ID_OB); if (ob == OBACT) return 0; } if (ob == NULL) return 0; sce = (Scene *)outliner_search_back(soops, te, ID_SCE); if (sce && scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); scene = sce; } /* find associated base in current scene */ base = BKE_scene_base_find(scene, ob); if (base) { if (set == 2) { /* swap select */ if (base->flag & SELECT) ED_base_object_select(base, BA_DESELECT); else ED_base_object_select(base, BA_SELECT); } else { /* deleselect all */ BKE_scene_base_deselect_all(scene); ED_base_object_select(base, BA_SELECT); } if (recursive) { /* Recursive select/deselect for Object hierarchies */ do_outliner_object_select_recursive(scene, ob, (ob->flag & SELECT) != 0); } if (C) { ED_base_object_activate(C, base); /* adds notifier */ WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } } if (ob != scene->obedit) ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); return 1; }
/** * \brief get the ID from the screen. */ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id) { /* we could use some clever */ bScreen *screen = CTX_wm_screen(C); ScrArea *sa = BKE_screen_find_area_xy(screen, -1, mx, my); ScrArea *area_prev = CTX_wm_area(C); ARegion *ar_prev = CTX_wm_region(C); ddr->name[0] = '\0'; if (sa) { if (sa->spacetype == SPACE_VIEW3D) { ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my); if (ar) { const int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; Base *base; CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); /* grr, always draw else we leave stale text */ ED_region_tag_redraw(ar); base = ED_view3d_give_base_under_cursor(C, mval); if (base) { Object *ob = base->object; ID *id = NULL; if (ddr->idcode == ID_OB) { id = (ID *)ob; } else if (ob->data) { if (GS(((ID *)ob->data)->name) == ddr->idcode) { id = (ID *)ob->data; } else { BLI_snprintf( ddr->name, sizeof(ddr->name), "Incompatible, expected a %s", ddr->idcode_name); } } PointerRNA idptr; RNA_id_pointer_create(id, &idptr); if (id && RNA_property_pointer_poll(&ddr->ptr, ddr->prop, &idptr)) { BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", ddr->idcode_name, id->name + 2); *r_id = id; } } } } } CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, ar_prev); }
static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr) { bool is_save_internal; bScreen *sc = CTX_wm_screen(C); bkr->ob = CTX_data_active_object(C); bkr->main = CTX_data_main(C); bkr->scene = CTX_data_scene(C); bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL; bkr->pass_type = RNA_enum_get(op->ptr, "type"); bkr->pass_filter = RNA_enum_get(op->ptr, "pass_filter"); bkr->margin = RNA_int_get(op->ptr, "margin"); bkr->save_mode = RNA_enum_get(op->ptr, "save_mode"); is_save_internal = (bkr->save_mode == R_BAKE_SAVE_INTERNAL); bkr->is_clear = RNA_boolean_get(op->ptr, "use_clear"); bkr->is_split_materials = (!is_save_internal) && RNA_boolean_get(op->ptr, "use_split_materials"); bkr->is_automatic_name = RNA_boolean_get(op->ptr, "use_automatic_name"); bkr->is_selected_to_active = RNA_boolean_get(op->ptr, "use_selected_to_active"); bkr->is_cage = RNA_boolean_get(op->ptr, "use_cage"); bkr->cage_extrusion = RNA_float_get(op->ptr, "cage_extrusion"); bkr->normal_space = RNA_enum_get(op->ptr, "normal_space"); bkr->normal_swizzle[0] = RNA_enum_get(op->ptr, "normal_r"); bkr->normal_swizzle[1] = RNA_enum_get(op->ptr, "normal_g"); bkr->normal_swizzle[2] = RNA_enum_get(op->ptr, "normal_b"); bkr->width = RNA_int_get(op->ptr, "width"); bkr->height = RNA_int_get(op->ptr, "height"); bkr->identifier = ""; RNA_string_get(op->ptr, "uv_layer", bkr->uv_layer); RNA_string_get(op->ptr, "cage_object", bkr->custom_cage); if ((!is_save_internal) && bkr->is_automatic_name) { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "type"); RNA_property_enum_identifier(C, op->ptr, prop, bkr->pass_type, &bkr->identifier); } CTX_data_selected_objects(C, &bkr->selected_objects); bkr->reports = op->reports; bkr->result = OPERATOR_CANCELLED; bkr->render = RE_NewSceneRender(bkr->scene); /* XXX hack to force saving to always be internal. Whether (and how) to support * external saving will be addressed later */ bkr->save_mode = R_BAKE_SAVE_INTERNAL; }
static int actkeys_viewall(bContext *C, const bool only_sel) { bAnimContext ac; View2D *v2d; float extra, min, max; bool found; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; v2d = &ac.ar->v2d; /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ found = get_keyframe_extents(&ac, &min, &max, only_sel); if (only_sel && (found == false)) return OPERATOR_CANCELLED; v2d->cur.xmin = min; v2d->cur.xmax = max; extra = 0.1f * BLI_rctf_size_x(&v2d->cur); v2d->cur.xmin -= extra; v2d->cur.xmax += extra; /* set vertical range */ if (only_sel == false) { /* view all -> the summary channel is usually the shows everything, and resides right at the top... */ v2d->cur.ymax = 0.0f; v2d->cur.ymin = (float)-BLI_rcti_size_y(&v2d->mask); } else { /* locate first selected channel (or the active one), and frame those */ float ymin = v2d->cur.ymin; float ymax = v2d->cur.ymax; if (actkeys_channels_get_selected_extents(&ac, &ymin, &ymax)) { /* recenter the view so that this range is in the middle */ float ymid = (ymax - ymin) / 2.0f + ymin; float x_center; UI_view2d_center_get(v2d, &x_center, NULL); UI_view2d_center_set(v2d, x_center, ymid); } } /* do View2D syncing */ UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); /* just redraw this view */ ED_area_tag_redraw(CTX_wm_area(C)); return OPERATOR_FINISHED; }
void wm_gesture_tag_redraw(bContext *C) { wmWindow *win = CTX_wm_window(C); bScreen *screen = CTX_wm_screen(C); ARegion *ar = CTX_wm_region(C); if (screen) screen->do_draw_gesture = TRUE; wm_tag_redraw_overlay(win, ar); }
static ARegion *region_event_inside_for_screen(bContext *C, const int xy[2]) { bScreen *sc = CTX_wm_screen(C); if (sc) { for (ARegion *ar = sc->regionbase.first; ar; ar = ar->next) { if (BLI_rcti_isect_pt_v(&ar->winrct, xy)) { return ar; } } } return NULL; }
static PointerRNA rna_Context_region_data_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; /* only exists for one space still, no generic system yet */ if(CTX_wm_view3d(C)) { PointerRNA newptr; RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C), &newptr); return newptr; } return PointerRNA_NULL; }
static void change_frame_seq_preview_begin(bContext *C, const wmEvent *event) { ScrArea *sa = CTX_wm_area(C); bScreen *screen = CTX_wm_screen(C); if (sa && sa->spacetype == SPACE_SEQ) { SpaceSeq *sseq = sa->spacedata.first; if (ED_space_sequencer_check_show_strip(sseq)) { ED_sequencer_special_preview_set(C, event->mval); } } if (screen) screen->scrubbing = true; }
static void panel_draw_header(const bContext *C, Panel *pnl) { PointerRNA ptr; ParameterList list; FunctionRNA *func; RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr); func= RNA_struct_find_function(&ptr, "draw_header"); RNA_parameter_list_create(&list, &ptr, func); RNA_parameter_set_lookup(&list, "context", &C); pnl->type->ext.call((bContext *)C, &ptr, func, &list); RNA_parameter_list_free(&list); }
static void menu_draw(const bContext *C, Menu *hdr) { PointerRNA mtr; ParameterList list; FunctionRNA *func; RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->ext.srna, hdr, &mtr); func= RNA_struct_find_function(&mtr, "draw"); RNA_parameter_list_create(&list, &mtr, func); RNA_parameter_set_lookup(&list, "context", &C); hdr->type->ext.call((bContext *)C, &mtr, func, &list); RNA_parameter_list_free(&list); }
static int screencast_exec(bContext *C, wmOperator *op) { wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); bScreen *screen = CTX_wm_screen(C); wmJob *wm_job; ScreenshotJob *sj; /* if called again, stop the running job */ if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST)) WM_jobs_stop(wm, screen, screenshot_startjob); wm_job = WM_jobs_get(wm, win, screen, "Screencast", 0, WM_JOB_TYPE_SCREENCAST); sj = MEM_callocN(sizeof(ScreenshotJob), "screenshot job"); /* setup sj */ if (RNA_boolean_get(op->ptr, "full")) { sj->x = 0; sj->y = 0; sj->dumpsx = WM_window_pixels_x(win); sj->dumpsy = WM_window_pixels_y(win); } else { ScrArea *curarea = CTX_wm_area(C); sj->x = curarea->totrct.xmin; sj->y = curarea->totrct.ymin; sj->dumpsx = curarea->totrct.xmax - sj->x; sj->dumpsy = curarea->totrct.ymax - sj->y; } sj->bmain = CTX_data_main(C); sj->scene = CTX_data_scene(C); sj->wm = wm; BKE_reports_init(&sj->reports, RPT_PRINT); /* setup job */ WM_jobs_customdata_set(wm_job, sj, screenshot_freejob); WM_jobs_timer(wm_job, 0.1, 0, NC_SCREEN | ND_SCREENCAST); WM_jobs_callbacks(wm_job, screenshot_startjob, NULL, screenshot_updatejob, screenshot_endjob); WM_jobs_start(sj->wm, wm_job); screencast_cursor_toggle(sj->wm, 1); WM_event_add_notifier(C, NC_SCREEN | ND_SCREENCAST, screen); return OPERATOR_FINISHED; }
static int game_engine_poll(bContext *C) { /* we need a context and area to launch BGE it's a temporary solution to avoid crash at load time if we try to auto run the BGE. Ideally we want the context to be set as soon as we load the file. */ if(CTX_wm_window(C)==NULL) return 0; if(CTX_wm_screen(C)==NULL) return 0; if(CTX_wm_area(C)==NULL) return 0; if(CTX_data_mode_enum(C)!=CTX_MODE_OBJECT) return 0; return 1; }
/* on startup, it adds all data, for matching */ void wm_add_default(bContext *C) { wmWindowManager *wm= alloc_libblock(&CTX_data_main(C)->wm, ID_WM, "WinMan"); wmWindow *win; bScreen *screen= CTX_wm_screen(C); /* XXX from file read hrmf */ CTX_wm_manager_set(C, wm); win= wm_window_new(C); win->screen= screen; screen->winid= win->winid; BLI_strncpy(win->screenname, screen->id.name+2, sizeof(win->screenname)); wm->winactive= win; wm->file_saved= 1; wm_window_make_drawable(C, win); }
static void draw_gpencil_space_specials(const bContext *C, uiLayout *layout) { uiLayout *col, *row; SpaceClip *sc = CTX_wm_space_clip(C); col = uiLayoutColumn(layout, FALSE); if (sc) { bScreen *screen = CTX_wm_screen(C); PointerRNA sc_ptr; RNA_pointer_create(&screen->id, &RNA_SpaceClipEditor, sc, &sc_ptr); row = uiLayoutRow(col, TRUE); uiItemR(row, &sc_ptr, "grease_pencil_source", UI_ITEM_R_EXPAND, NULL, ICON_NONE); } }