/** * \brief get the color from the screen. * * Special check for image or nodes where we MAY have HDR pixels which don't display. */ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int mx, int my, float r_col[3]) { /* we could use some clever */ wmWindow *win = CTX_wm_window(C); ScrArea *sa; for (sa = win->screen->areabase.first; sa; sa = sa->next) { if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { if (sa->spacetype == SPACE_IMAGE) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { SpaceImage *sima = sa->spacedata.first; int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) { return; } } } else if (sa->spacetype == SPACE_NODE) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { SpaceNode *snode = sa->spacedata.first; int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) { return; } } } else if (sa->spacetype == SPACE_CLIP) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { SpaceClip *sc = sa->spacedata.first; int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) { return; } } } } } /* fallback to simple opengl picker */ glReadBuffer(GL_FRONT); glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, r_col); glReadBuffer(GL_BACK); }
static wmKeyMapItem *wm_keymap_item_find_props( const bContext *C, const char *opname, int opcontext, IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r) { wmWindow *win = CTX_wm_window(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); wmKeyMapItem *found = NULL; /* look into multiple handler lists to find the item */ if (win) found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); if (sa && found == NULL) found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); if (found == NULL) { if (ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) { if (sa) { if (!(ar && ar->regiontype == RGN_TYPE_WINDOW)) ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); } } else if (ELEM(opcontext, WM_OP_EXEC_REGION_CHANNELS, WM_OP_INVOKE_REGION_CHANNELS)) { if (!(ar && ar->regiontype == RGN_TYPE_CHANNELS)) ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS); if (ar) found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); } else if (ELEM(opcontext, WM_OP_EXEC_REGION_PREVIEW, WM_OP_INVOKE_REGION_PREVIEW)) { if (!(ar && ar->regiontype == RGN_TYPE_PREVIEW)) ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); if (ar) found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); } else { if (ar) found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r); } } return found; }
/** * \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 */ wmWindow *win = CTX_wm_window(C); ScrArea *sa; ScrArea *area_prev = CTX_wm_area(C); ARegion *ar_prev = CTX_wm_region(C); ddr->name[0] = '\0'; for (sa = win->screen->areabase.first; sa; sa = sa->next) { if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { if (sa->spacetype == SPACE_VIEW3D) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { 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); } } if (id) { BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", ddr->idcode_name, id->name + 2); *r_id = id; } break; } } } } } CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, ar_prev); }
/* takes an area instead of a region, use for listeners */ void text_scroll_to_cursor__area(SpaceText *st, ScrArea *sa, const bool center) { ARegion *ar; if (ELEM(NULL, st, st->text, st->text->curl)) return; ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) { text_scroll_to_cursor(st, ar, center); } }
ARegion *BKE_area_find_region_active_win(ScrArea *sa) { if (sa) { ARegion *ar = BLI_findlink(&sa->regionbase, sa->region_active_win); if (ar && (ar->regiontype == RGN_TYPE_WINDOW)) { return ar; } /* fallback to any */ return BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); } return NULL; }
static ARegion *text_has_properties_region(ScrArea *sa) { ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); if (ar) return ar; /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ if (ar == NULL) return NULL; arnew = MEM_callocN(sizeof(ARegion), "properties region"); BLI_insertlinkafter(&sa->regionbase, ar, arnew); arnew->regiontype = RGN_TYPE_UI; arnew->alignment = RGN_ALIGN_LEFT; arnew->flag = RGN_FLAG_HIDDEN; return arnew; }
/* screen can be NULL */ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **thumb_pt) { /* will be scaled down, but gives some nice oversampling */ ImBuf *ibuf; BlendThumbnail *thumb; char err_out[256] = "unknown"; /* screen if no camera found */ ScrArea *sa = NULL; ARegion *ar = NULL; View3D *v3d = NULL; /* In case we are given a valid thumbnail data, just generate image from it. */ if (*thumb_pt) { thumb = *thumb_pt; return BKE_main_thumbnail_to_imbuf(NULL, thumb); } /* scene can be NULL if running a script at startup and calling the save operator */ if (G.background || scene == NULL) return NULL; if ((scene->camera == NULL) && (screen != NULL)) { sa = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0); ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) { v3d = sa->spacedata.first; } } if (scene->camera == NULL && v3d == NULL) { return NULL; } /* gets scaled to BLEN_THUMB_SIZE */ if (scene->camera) { ibuf = ED_view3d_draw_offscreen_imbuf_simple( scene, scene->camera, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, 0, false, NULL, NULL, NULL, err_out); } else { ibuf = ED_view3d_draw_offscreen_imbuf( scene, v3d, ar, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, false, R_ALPHAPREMUL, 0, false, NULL, NULL, NULL, err_out); } if (ibuf) { float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); /* dirty oversampling */ IMB_scaleImBuf(ibuf, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE); /* add pretty overlay */ IMB_thumb_overlay_blend(ibuf->rect, ibuf->x, ibuf->y, aspect); thumb = BKE_main_thumbnail_from_imbuf(NULL, ibuf); } else { /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ fprintf(stderr, "blend_file_thumb failed to create thumbnail: %s\n", err_out); thumb = NULL; } /* must be freed by caller */ *thumb_pt = thumb; return ibuf; }
bool WM_init_game(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win; ScrArea *sa; ARegion *ar = NULL; Scene *scene = CTX_data_scene(C); if (!scene) { /* XXX, this should not be needed. */ Main *bmain = CTX_data_main(C); scene = bmain->scene.first; } win = wm->windows.first; /* first to get a valid window */ if (win) CTX_wm_window_set(C, win); sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0); ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); /* if we have a valid 3D view */ if (sa && ar) { ARegion *arhide; CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); /* disable quad view */ if (ar->alignment == RGN_ALIGN_QSPLIT) WM_operator_name_call(C, "SCREEN_OT_region_quadview", WM_OP_EXEC_DEFAULT, NULL); /* toolbox, properties panel and header are hidden */ for (arhide = sa->regionbase.first; arhide; arhide = arhide->next) { if (arhide->regiontype != RGN_TYPE_WINDOW) { if (!(arhide->flag & RGN_FLAG_HIDDEN)) { ED_region_toggle_hidden(C, arhide); } } } /* full screen the area */ if (!sa->full) { ED_screen_state_toggle(C, win, sa, SCREENMAXIMIZED); } /* Fullscreen */ if ((scene->gm.playerflag & GAME_PLAYER_FULLSCREEN)) { WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL); wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax); ar->winx = ar->winrct.xmax + 1; ar->winy = ar->winrct.ymax + 1; } else { GHOST_RectangleHandle rect = GHOST_GetClientBounds(win->ghostwin); ar->winrct.ymax = GHOST_GetHeightRectangle(rect); ar->winrct.xmax = GHOST_GetWidthRectangle(rect); ar->winx = ar->winrct.xmax + 1; ar->winy = ar->winrct.ymax + 1; GHOST_DisposeRectangle(rect); } WM_operator_name_call(C, "VIEW3D_OT_game_start", WM_OP_EXEC_DEFAULT, NULL); BKE_sound_exit(); return true; } else { ReportTimerInfo *rti; BKE_report(&wm->reports, RPT_ERROR, "No valid 3D View found, game auto start is not possible"); /* After adding the report to the global list, reset the report timer. */ WM_event_remove_timer(wm, NULL, wm->reports.reporttimer); /* Records time since last report was added */ wm->reports.reporttimer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER, 0.02); rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo"); wm->reports.reporttimer->customdata = rti; return false; } }
static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *event) { SpaceText *st = CTX_wm_space_text(C); ScrArea *sa = CTX_wm_area(C); ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); int draw = 0, tools = 0, swallow = 0, scroll = 1; Text *text = CTX_data_edit_text(C); int retval = OPERATOR_RUNNING_MODAL; (void)text; if (st->doplugins && texttool_text_is_active(st->text)) { if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST; if (texttool_docs_get()) tools |= TOOL_DOCUMENT; } switch (event->type) { case LEFTMOUSE: if (event->val == KM_PRESS) { if (text_do_suggest_select(st, ar)) swallow = 1; else { if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; retval = OPERATOR_FINISHED; } draw = 1; } break; case MIDDLEMOUSE: if (event->val == KM_PRESS) { if (text_do_suggest_select(st, ar)) { confirm_suggestion(st->text); text_update_line_edited(st->text->curl); swallow = 1; } else { if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; retval = OPERATOR_FINISHED; } draw = 1; } break; case ESCKEY: if (event->val == KM_PRESS) { draw = swallow = 1; if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(); else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; else draw = swallow = 0; retval = OPERATOR_CANCELLED; } break; case RETKEY: case PADENTER: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { confirm_suggestion(st->text); text_update_line_edited(st->text->curl); swallow = 1; draw = 1; } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1; retval = OPERATOR_FINISHED; } break; case LEFTARROWKEY: case BACKSPACEKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { if (event->ctrl) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } else { /* Work out which char we are about to delete/pass */ if (st->text->curl && st->text->curc > 0) { char ch = st->text->curl->line[st->text->curc - 1]; if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) { get_suggest_prefix(st->text, -1); text_pop_suggest_list(); } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; } break; case RIGHTARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { if (event->ctrl) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } else { /* Work out which char we are about to pass */ if (st->text->curl && st->text->curc < st->text->curl->len) { char ch = st->text->curl->line[st->text->curc + 1]; if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) { get_suggest_prefix(st->text, 1); text_pop_suggest_list(); } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } else { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; } } } if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0; } break; case PAGEDOWNKEY: scroll = SUGG_LIST_SIZE - 1; /* fall-through */ case WHEELDOWNMOUSE: case DOWNARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_DOCUMENT) { doc_scroll++; swallow = 1; draw = 1; } else if (tools & TOOL_SUGG_LIST) { SuggItem *sel = texttool_suggest_selected(); if (!sel) { texttool_suggest_select(texttool_suggest_first()); } else { while (sel && scroll--) { if (sel != texttool_suggest_last() && sel->next) { texttool_suggest_select(sel->next); sel = sel->next; } else { texttool_suggest_select(texttool_suggest_first()); sel = texttool_suggest_first(); } } } text_pop_suggest_list(); swallow = 1; draw = 1; } } break; case PAGEUPKEY: scroll = SUGG_LIST_SIZE - 1; /* fall-through */ case WHEELUPMOUSE: case UPARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_DOCUMENT) { if (doc_scroll > 0) doc_scroll--; swallow = 1; draw = 1; } else if (tools & TOOL_SUGG_LIST) { SuggItem *sel = texttool_suggest_selected(); while (sel && scroll--) { if (sel != texttool_suggest_first() && sel->prev) { texttool_suggest_select(sel->prev); sel = sel->prev; } else { texttool_suggest_select(texttool_suggest_last()); sel = texttool_suggest_last(); } } text_pop_suggest_list(); swallow = 1; draw = 1; } } break; case RIGHTSHIFTKEY: case LEFTSHIFTKEY: break; #if 0 default: if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw = 1; if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1; #endif } if (draw) { ED_area_tag_redraw(sa); } // if (swallow) { // retval = OPERATOR_RUNNING_MODAL; // } if (texttool_suggest_first()) { if (retval != OPERATOR_RUNNING_MODAL) { text_autocomplete_free(C, op); } return retval; } else { text_autocomplete_free(C, op); return OPERATOR_FINISHED; } }
/* only meant for timer usage */ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { ScrArea *sa = CTX_wm_area(C); SpaceFile *sfile = CTX_wm_space_file(C); ARegion *ar, *oldar = CTX_wm_region(C); int offset; int numfiles, numfiles_layout; int edit_idx = 0; int i; /* escape if not our timer */ if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata) return OPERATOR_PASS_THROUGH; numfiles = filelist_numfiles(sfile->files); /* check if we are editing a name */ for (i = 0; i < numfiles; ++i) { if (filelist_is_selected(sfile->files, i, CHECK_ALL) ) { edit_idx = i; break; } } /* if we are not editing, we are done */ if (0 == edit_idx) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); sfile->smoothscroll_timer = NULL; return OPERATOR_PASS_THROUGH; } /* we need the correct area for scrolling */ ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (!ar || ar->regiontype != RGN_TYPE_WINDOW) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); sfile->smoothscroll_timer = NULL; return OPERATOR_PASS_THROUGH; } offset = ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax); if (offset < 0) offset = 0; /* scroll offset is the first file in the row/column we are editing in */ if (sfile->scroll_offset == 0) { if (sfile->layout->flag & FILE_LAYOUT_HOR) { sfile->scroll_offset = (edit_idx / sfile->layout->rows) * sfile->layout->rows; if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->rows; } else { sfile->scroll_offset = (edit_idx / sfile->layout->columns) * sfile->layout->columns; if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->columns; } } numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, ar); /* check if we have reached our final scroll position */ if ( (sfile->scroll_offset >= offset) && (sfile->scroll_offset < offset + numfiles_layout) ) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); sfile->smoothscroll_timer = NULL; return OPERATOR_FINISHED; } /* temporarily set context to the main window region, * so the scroll operators work */ CTX_wm_region_set(C, ar); /* scroll one step in the desired direction */ if (sfile->scroll_offset < offset) { if (sfile->layout->flag & FILE_LAYOUT_HOR) { WM_operator_name_call(C, "VIEW2D_OT_scroll_left", 0, NULL); } else { WM_operator_name_call(C, "VIEW2D_OT_scroll_up", 0, NULL); } } else { if (sfile->layout->flag & FILE_LAYOUT_HOR) { WM_operator_name_call(C, "VIEW2D_OT_scroll_right", 0, NULL); } else { WM_operator_name_call(C, "VIEW2D_OT_scroll_down", 0, NULL); } } ED_region_tag_redraw(ar); /* and restore context */ CTX_wm_region_set(C, oldar); return OPERATOR_FINISHED; }
/* screen can be NULL */ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, int **thumb_pt) { /* will be scaled down, but gives some nice oversampling */ ImBuf *ibuf; int *thumb; char err_out[256] = "unknown"; /* screen if no camera found */ ScrArea *sa = NULL; ARegion *ar = NULL; View3D *v3d = NULL; *thumb_pt = NULL; /* scene can be NULL if running a script at startup and calling the save operator */ if (G.background || scene == NULL) return NULL; if ((scene->camera == NULL) && (screen != NULL)) { sa = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0); ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) { v3d = sa->spacedata.first; } } if (scene->camera == NULL && v3d == NULL) { return NULL; } /* gets scaled to BLEN_THUMB_SIZE */ if (scene->camera) { ibuf = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, OB_SOLID, FALSE, FALSE, R_ADDSKY, err_out); } else { ibuf = ED_view3d_draw_offscreen_imbuf(scene, v3d, ar, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, FALSE, R_ADDSKY, err_out); } if (ibuf) { float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); /* dirty oversampling */ IMB_scaleImBuf(ibuf, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE); /* add pretty overlay */ IMB_overlayblend_thumb(ibuf->rect, ibuf->x, ibuf->y, aspect); /* first write into thumb buffer */ thumb = MEM_mallocN(((2 + (BLEN_THUMB_SIZE * BLEN_THUMB_SIZE))) * sizeof(int), "write_file thumb"); thumb[0] = BLEN_THUMB_SIZE; thumb[1] = BLEN_THUMB_SIZE; memcpy(thumb + 2, ibuf->rect, BLEN_THUMB_SIZE * BLEN_THUMB_SIZE * sizeof(int)); } else { /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ fprintf(stderr, "blend_file_thumb failed to create thumbnail: %s\n", err_out); thumb = NULL; } /* must be freed by caller */ *thumb_pt = thumb; return ibuf; }