Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
static int editsource_text_edit(bContext *C,
                                wmOperator *op,
                                const char filepath[FILE_MAX],
                                const int line)
{
  struct Main *bmain = CTX_data_main(C);
  Text *text;

  /* Developers may wish to copy-paste to an external editor. */
  printf("%s:%d\n", filepath, line);

  for (text = bmain->texts.first; text; text = text->id.next) {
    if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
      break;
    }
  }

  if (text == NULL) {
    text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
    id_us_ensure_real(&text->id);
  }

  if (text == NULL) {
    BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
    return OPERATOR_CANCELLED;
  }
  else {
    /* naughty!, find text area to set, not good behavior
     * but since this is a dev tool lets allow it - campbell */
    ScrArea *sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
    if (sa) {
      SpaceText *st = sa->spacedata.first;
      st->text = text;
    }
    else {
      BKE_reportf(op->reports, RPT_INFO, "See '%s' in the text editor", text->id.name + 2);
    }

    txt_move_toline(text, line - 1, false);
    WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
  }

  return OPERATOR_FINISHED;
}
Пример #4
0
static int editsource_text_edit(bContext *C, wmOperator *op,
                                char filepath[240], int line)
{
	struct Main *bmain= CTX_data_main(C);
	Text *text;

	for (text=bmain->text.first; text; text=text->id.next) {
		if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
			break;
		}
	}

	if (text == NULL) {
		text= add_text(filepath, bmain->name);
	}

	if (text == NULL) {
		BKE_reportf(op->reports, RPT_WARNING,
		            "file: '%s' can't be opened", filepath);
		return OPERATOR_CANCELLED;
	}
	else {
		/* naughty!, find text area to set, not good behavior
		 * but since this is a dev tool lets allow it - campbell */
		ScrArea *sa= BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
		if(sa) {
			SpaceText *st= sa->spacedata.first;
			st->text= text;
		}
		else {
			BKE_reportf(op->reports, RPT_INFO,
			            "See '%s' in the text editor", text->id.name + 2);
		}

		txt_move_toline(text, line - 1, FALSE);
		WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
	}

	return OPERATOR_FINISHED;
}
Пример #5
0
/* 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;
}
Пример #6
0
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;
	}
}
Пример #7
0
/* 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;
}
Пример #8
0
/* new window uses x,y to set position */
void render_view_open(bContext *C, int mx, int my)
{
	wmWindow *win = CTX_wm_window(C);
	Scene *scene = CTX_data_scene(C);
	ScrArea *sa = NULL;
	SpaceImage *sima;
	int area_was_image = 0;

	if (scene->r.displaymode == R_OUTPUT_NONE)
		return;
	
	if (scene->r.displaymode == R_OUTPUT_WINDOW) {
		rcti rect;
		int sizex, sizey;

		sizex = 10 + (scene->r.xsch * scene->r.size) / 100;
		sizey = 40 + (scene->r.ysch * scene->r.size) / 100;

		/* arbitrary... miniature image window views don't make much sense */
		if (sizex < 320) sizex = 320;
		if (sizey < 256) sizey = 256;

		/* some magic to calculate postition */
		/* pixelsize: mouse coords are in U.pixelsize units :/ */
		rect.xmin = (mx / U.pixelsize) + win->posx - sizex / 2;
		rect.ymin = (my / U.pixelsize) + win->posy - sizey / 2;
		rect.xmax = rect.xmin + sizex;
		rect.ymax = rect.ymin + sizey;

		/* changes context! */
		WM_window_open_temp(C, &rect, WM_WINDOW_RENDER);

		sa = CTX_wm_area(C);
	}
	else if (scene->r.displaymode == R_OUTPUT_SCREEN) {
		if (CTX_wm_area(C) && CTX_wm_area(C)->spacetype == SPACE_IMAGE)
			area_was_image = 1;

		/* this function returns with changed context */
		sa = ED_screen_full_newspace(C, CTX_wm_area(C), SPACE_IMAGE);
	}

	if (!sa) {
		sa = find_area_showing_r_result(C, &win);
		if (sa == NULL)
			sa = find_area_image_empty(C);
		
		/* if area found in other window, we make that one show in front */
		if (win && win != CTX_wm_window(C))
			wm_window_raise(win);

		if (sa == NULL) {
			/* find largest open non-image area */
			sa = biggest_non_image_area(C);
			if (sa) {
				ED_area_newspace(C, sa, SPACE_IMAGE);
				sima = sa->spacedata.first;

				/* makes ESC go back to prev space */
				sima->flag |= SI_PREVSPACE;
			}
			else {
				/* use any area of decent size */
				sa = BKE_screen_find_big_area(CTX_wm_screen(C), -1, 0);
				if (sa->spacetype != SPACE_IMAGE) {
					// XXX newspace(sa, SPACE_IMAGE);
					sima = sa->spacedata.first;

					/* makes ESC go back to prev space */
					sima->flag |= SI_PREVSPACE;
				}
			}
		}
	}
	sima = sa->spacedata.first;

	/* get the correct image, and scale it */
	sima->image = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");


	/* if we're rendering to full screen, set appropriate hints on image editor
	 * so it can restore properly on pressing esc */
	if (sa->full) {
		sima->flag |= SI_FULLWINDOW;

		/* Tell the image editor to revert to previous space in space list on close
		 * _only_ if it wasn't already an image editor when the render was invoked */
		if (area_was_image == 0)
			sima->flag |= SI_PREVSPACE;
		else {
			/* Leave it alone so the image editor will just go back from
			 * full screen to the original tiled setup */
		}
	}
}