Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_edit.c
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2008 Blender Foundation. All rights reserved. */ | * Copyright 2008 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edscr | * \ingroup edscr | ||||
| */ | */ | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "DNA_video_edit_types.h" | |||||
| #include "DNA_workspace_types.h" | #include "DNA_workspace_types.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLT_translation.h" | |||||
| #include "BLF_api.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_sound.h" | #include "BKE_sound.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_clip.h" | #include "ED_clip.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_screen_types.h" | #include "ED_screen_types.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | |||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "screen_intern.h" /* own module include */ | #include "screen_intern.h" /* own module include */ | ||||
| ▲ Show 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | if ((dir != SCREEN_DIR_NONE) && (neighbor->global == NULL)) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Join from neighbor into this area to close it. */ | /* Join from neighbor into this area to close it. */ | ||||
| return screen_area_join_ex(C, screen, sa2, area, true); | return screen_area_join_ex(C, screen, sa2, area, true); | ||||
| } | } | ||||
| void screen_area_spacelink_add(Scene *scene, ScrArea *area, eSpace_Type space_type) | void screen_area_spacelink_add(wmWindow *win, ScrArea *area, eSpace_Type space_type) | ||||
| { | { | ||||
| SpaceType *stype = BKE_spacetype_from_id(space_type); | SpaceType *stype = BKE_spacetype_from_id(space_type); | ||||
| SpaceLink *slink = stype->create(area, scene); | SpaceLink *slink = stype->create(win, area); | ||||
| area->regionbase = slink->regionbase; | area->regionbase = slink->regionbase; | ||||
| BLI_addhead(&area->spacedata, slink); | BLI_addhead(&area->spacedata, slink); | ||||
| BLI_listbase_clear(&slink->regionbase); | BLI_listbase_clear(&slink->regionbase); | ||||
| } | } | ||||
| /* ****************** EXPORTED API TO OTHER MODULES *************************** */ | /* ****************** EXPORTED API TO OTHER MODULES *************************** */ | ||||
| ▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (ScrArea *, area_iter, &win->global_areas.areabase) { | ||||
| } | } | ||||
| } | } | ||||
| if (area) { | if (area) { | ||||
| screen_area_set_geometry_rect(area, rect); | screen_area_set_geometry_rect(area, rect); | ||||
| } | } | ||||
| else { | else { | ||||
| area = screen_area_create_with_geometry(&win->global_areas, rect, space_type); | area = screen_area_create_with_geometry(&win->global_areas, rect, space_type); | ||||
| screen_area_spacelink_add(WM_window_get_active_scene(win), area, space_type); | screen_area_spacelink_add(win, area, space_type); | ||||
| /* Data specific to global areas. */ | /* Data specific to global areas. */ | ||||
| area->global = MEM_callocN(sizeof(*area->global), __func__); | area->global = MEM_callocN(sizeof(*area->global), __func__); | ||||
| area->global->size_max = height_max; | area->global->size_max = height_max; | ||||
| area->global->size_min = height_min; | area->global->size_min = height_min; | ||||
| area->global->align = align; | area->global->align = align; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| } | } | ||||
| } | } | ||||
| if (refresh_toolsystem) { | if (refresh_toolsystem) { | ||||
| WM_toolsystem_refresh_screen_window(win); | WM_toolsystem_refresh_screen_window(win); | ||||
| } | } | ||||
| } | } | ||||
| void ED_screen_video_edit_change(bContext *C, wmWindow *win, VideoEdit *video_edit) | |||||
| { | |||||
| win->video_edit = video_edit; | |||||
| if (CTX_wm_window(C) == win) { | |||||
| CTX_data_video_edit_set(C, video_edit); | |||||
| } | |||||
| } | |||||
| ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *area, int type) | ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *area, int type) | ||||
| { | { | ||||
| bScreen *newscreen = NULL; | bScreen *newscreen = NULL; | ||||
| ScrArea *newsa = NULL; | ScrArea *newsa = NULL; | ||||
| SpaceLink *newsl; | SpaceLink *newsl; | ||||
| if (!area || area->full == NULL) { | if (!area || area->full == NULL) { | ||||
| newscreen = ED_screen_state_maximized_create(C); | newscreen = ED_screen_state_maximized_create(C); | ||||
| ▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | if (animtimer && (U.uiflag & USER_SHOW_FPS)) { | ||||
| fpsi->lredrawtime = animtimer->ltime; | fpsi->lredrawtime = animtimer->ltime; | ||||
| } | } | ||||
| else { | else { | ||||
| /* playback stopped or shouldn't be running */ | /* playback stopped or shouldn't be running */ | ||||
| MEM_SAFE_FREE(scene->fps_info); | MEM_SAFE_FREE(scene->fps_info); | ||||
| } | } | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name FPS Drawing | |||||
| * \{ */ | |||||
| static void draw_fps_ex(ScreenFrameRateInfo *fpsi, double fps_setting, int xoffset, int *yoffset) | |||||
| { | |||||
| #define VIEW3D_OVERLAY_LINEHEIGHT (0.9f * U.widget_unit) | |||||
| char printable[16]; | |||||
| if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) { | |||||
| return; | |||||
| } | |||||
| printable[0] = '\0'; | |||||
| /* Doing an average for a more robust calculation. */ | |||||
| fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / | |||||
| (fpsi->lredrawtime - fpsi->redrawtime)); | |||||
| float fps = 0.0f; | |||||
| int tot = 0; | |||||
| for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) { | |||||
| if (fpsi->redrawtimes_fps[i]) { | |||||
| fps += fpsi->redrawtimes_fps[i]; | |||||
| tot++; | |||||
| } | |||||
| } | |||||
| if (tot) { | |||||
| fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; | |||||
| fps = fps / tot; | |||||
| } | |||||
| const int font_id = BLF_default(); | |||||
| /* Is this more than half a frame behind? */ | |||||
| if (fps + 0.5f < (float)(fps_setting)) { | |||||
| UI_FontThemeColor(font_id, TH_REDALERT); | |||||
| BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps_setting); | |||||
| } | |||||
| else { | |||||
| UI_FontThemeColor(font_id, TH_TEXT_HI); | |||||
| BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps_setting + 0.5f)); | |||||
| } | |||||
| float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | |||||
| BLF_enable(font_id, BLF_SHADOW); | |||||
| BLF_shadow(font_id, 5, shadow_color); | |||||
| BLF_shadow_offset(font_id, 1, -1); | |||||
| *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | |||||
| BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); | |||||
| BLF_disable(font_id, BLF_SHADOW); | |||||
| #undef VIEW3D_OVERLAY_LINEHEIGHT | |||||
| } | |||||
| void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) | |||||
| { | |||||
| ScreenFrameRateInfo *fpsi = (ScreenFrameRateInfo *)scene->fps_info; | |||||
| draw_fps_ex(fpsi, FPS, xoffset, yoffset); | |||||
| } | |||||
| void ED_video_edit_draw_fps(const VideoEdit *video_edit, int xoffset, int *yoffset) | |||||
| { | |||||
| ScreenFrameRateInfo *fpsi = (ScreenFrameRateInfo *)video_edit->fps_info; | |||||
| double fps = (((double)video_edit->r.frs_sec) / (double)video_edit->r.frs_sec_base); | |||||
| draw_fps_ex(fpsi, fps, xoffset, yoffset); | |||||
| } | |||||
| /** \} */ | |||||
| void ED_screen_animation_timer(bContext *C, int redraws, int sync, int enable) | void ED_screen_animation_timer(bContext *C, int redraws, int sync, int enable) | ||||
| { | { | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| bScreen *stopscreen = ED_screen_animation_playing(wm); | bScreen *stopscreen = ED_screen_animation_playing(wm); | ||||
| ▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines | |||||