Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_playanim.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| WS_QUAL_LSHIFT = (1 << 0), | WS_QUAL_LSHIFT = (1 << 0), | ||||
| WS_QUAL_RSHIFT = (1 << 1), | WS_QUAL_RSHIFT = (1 << 1), | ||||
| WS_QUAL_SHIFT = (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT), | WS_QUAL_SHIFT = (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT), | ||||
| WS_QUAL_LALT = (1 << 2), | WS_QUAL_LALT = (1 << 2), | ||||
| WS_QUAL_RALT = (1 << 3), | WS_QUAL_RALT = (1 << 3), | ||||
| WS_QUAL_ALT = (WS_QUAL_LALT | WS_QUAL_RALT), | WS_QUAL_ALT = (WS_QUAL_LALT | WS_QUAL_RALT), | ||||
| WS_QUAL_LCTRL = (1 << 4), | WS_QUAL_LCTRL = (1 << 4), | ||||
| WS_QUAL_RCTRL = (1 << 5), | WS_QUAL_RCTRL = (1 << 5), | ||||
| WS_QUAL_CTRL = (WS_QUAL_LCTRL | WS_QUAL_RCTRL), | WS_QUAL_CMD = (1 << 6), | ||||
| WS_QUAL_CTRL = (WS_QUAL_LCTRL | WS_QUAL_RCTRL | WS_QUAL_CMD), | |||||
| WS_QUAL_LMOUSE = (1 << 16), | WS_QUAL_LMOUSE = (1 << 16), | ||||
| WS_QUAL_MMOUSE = (1 << 17), | WS_QUAL_MMOUSE = (1 << 17), | ||||
| WS_QUAL_RMOUSE = (1 << 18), | WS_QUAL_RMOUSE = (1 << 18), | ||||
| WS_QUAL_MOUSE = (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE), | WS_QUAL_MOUSE = (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE), | ||||
| } eWS_Qual; | } eWS_Qual; | ||||
| static struct WindowStateGlobal { | static struct WindowStateGlobal { | ||||
| GHOST_SystemHandle ghost_system; | GHOST_SystemHandle ghost_system; | ||||
| void *ghost_window; | void *ghost_window; | ||||
| GPUContext *gpu_context; | GPUContext *gpu_context; | ||||
| /* events */ | /* events */ | ||||
| eWS_Qual qual; | eWS_Qual qual; | ||||
| } g_WS = {NULL}; | } g_WS = {NULL}; | ||||
| static void playanim_window_get_size(int *r_width, int *r_height) | static void playanim_window_get_size(int *r_width, int *r_height) | ||||
| { | { | ||||
| GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window); | GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window); | ||||
| *r_width = GHOST_GetWidthRectangle(bounds); | const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | ||||
| *r_height = GHOST_GetHeightRectangle(bounds); | |||||
| *r_width = GHOST_GetWidthRectangle(bounds) * pixelsize; | |||||
| *r_height = GHOST_GetHeightRectangle(bounds) * pixelsize; | |||||
| GHOST_DisposeRectangle(bounds); | GHOST_DisposeRectangle(bounds); | ||||
| } | } | ||||
| static void playanim_gl_matrix(void) | static void playanim_gl_matrix(void) | ||||
| { | { | ||||
| /* unified matrix, note it affects offset for drawing */ | /* unified matrix, note it affects offset for drawing */ | ||||
| /* NOTE: cannot use GPU_matrix_ortho_2d_set here because shader ignores. */ | /* NOTE: cannot use GPU_matrix_ortho_2d_set here because shader ignores. */ | ||||
| GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f); | GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f); | ||||
| Show All 19 Lines | |||||
| SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_RCTRL); | SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_RCTRL); | ||||
| /* Alt */ | /* Alt */ | ||||
| GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftAlt, &val); | GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftAlt, &val); | ||||
| SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_LALT); | SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_LALT); | ||||
| GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightAlt, &val); | GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightAlt, &val); | ||||
| SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_RALT); | SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_RALT); | ||||
| /* Command (macOS). */ | |||||
| #ifdef __APPLE__ | |||||
| GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyOS, &val); | |||||
| SET_FLAG_FROM_TEST(g_WS.qual, val, WS_QUAL_CMD); | |||||
| #endif | |||||
| } | } | ||||
| typedef struct PlayAnimPict { | typedef struct PlayAnimPict { | ||||
| struct PlayAnimPict *next, *prev; | struct PlayAnimPict *next, *prev; | ||||
| uchar *mem; | uchar *mem; | ||||
| int size; | int size; | ||||
| const char *name; | const char *name; | ||||
| struct ImBuf *ibuf; | struct ImBuf *ibuf; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| float fsizex_inv, fsizey_inv; | float fsizex_inv, fsizey_inv; | ||||
| char str[32 + FILE_MAX]; | char str[32 + FILE_MAX]; | ||||
| BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime); | BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime); | ||||
| playanim_window_get_size(&sizex, &sizey); | playanim_window_get_size(&sizex, &sizey); | ||||
| fsizex_inv = 1.0f / sizex; | fsizex_inv = 1.0f / sizex; | ||||
| fsizey_inv = 1.0f / sizey; | fsizey_inv = 1.0f / sizey; | ||||
| const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | |||||
| BLF_color4f(fontid, 1.0, 1.0, 1.0, 1.0); | BLF_color4f(fontid, 1.0, 1.0, 1.0, 1.0); | ||||
| BLF_enable(fontid, BLF_ASPECT); | BLF_enable(fontid, BLF_ASPECT); | ||||
| BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f); | BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f); | ||||
| BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f); | BLF_position(fontid, 10.0f * pixelsize * fsizex_inv, 10.0f * pixelsize * fsizey_inv, 0.0f); | ||||
| BLF_draw(fontid, str, sizeof(str)); | BLF_draw(fontid, str, sizeof(str)); | ||||
| } | } | ||||
| if (ps->indicator) { | if (ps->indicator) { | ||||
| float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - | float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - | ||||
| ((PlayAnimPict *)picsbase.first)->frame); | ((PlayAnimPict *)picsbase.first)->frame); | ||||
| fac = 2.0f * fac - 1.0f; | fac = 2.0f * fac - 1.0f; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| case GHOST_kEventButtonDown: | case GHOST_kEventButtonDown: | ||||
| case GHOST_kEventButtonUp: { | case GHOST_kEventButtonUp: { | ||||
| GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); | GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); | ||||
| int cx, cy, sizex, sizey, inside_window; | int cx, cy, sizex, sizey, inside_window; | ||||
| GHOST_GetCursorPosition(g_WS.ghost_system, &cx, &cy); | GHOST_GetCursorPosition(g_WS.ghost_system, &cx, &cy); | ||||
| GHOST_ScreenToClient(g_WS.ghost_window, cx, cy, &cx, &cy); | GHOST_ScreenToClient(g_WS.ghost_window, cx, cy, &cx, &cy); | ||||
| const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | |||||
| cx *= pixelsize; | |||||
| cy *= pixelsize; | |||||
| playanim_window_get_size(&sizex, &sizey); | playanim_window_get_size(&sizex, &sizey); | ||||
| inside_window = (cx >= 0 && cx < sizex && cy >= 0 && cy <= sizey); | inside_window = (cx >= 0 && cx < sizex && cy >= 0 && cy <= sizey); | ||||
| if (bd->button == GHOST_kButtonMaskLeft) { | if (bd->button == GHOST_kButtonMaskLeft) { | ||||
| if (type == GHOST_kEventButtonDown) { | if (type == GHOST_kEventButtonDown) { | ||||
| if (inside_window) { | if (inside_window) { | ||||
| g_WS.qual |= WS_QUAL_LMOUSE; | g_WS.qual |= WS_QUAL_LMOUSE; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| if (x_test != cd->x || y_test != cd->y) { | if (x_test != cd->x || y_test != cd->y) { | ||||
| /* we're not the last event... skipping */ | /* we're not the last event... skipping */ | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy); | GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy); | ||||
| tag_change_frame(ps, cx); | const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | ||||
| tag_change_frame(ps, cx * pixelsize); | |||||
| } | |||||
| break; | |||||
| } | |||||
| case GHOST_kEventWheel: { | |||||
| GHOST_TEventWheelData *wheelData = GHOST_GetEventData(evt); | |||||
| if (wheelData->z > 0) { | |||||
| playanim_window_zoom(ps, 0.1f); | |||||
| } | |||||
| else { | |||||
| playanim_window_zoom(ps, -0.1f); | |||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case GHOST_kEventWindowActivate: | case GHOST_kEventWindowActivate: | ||||
| case GHOST_kEventWindowDeactivate: { | case GHOST_kEventWindowDeactivate: { | ||||
| g_WS.qual &= ~WS_QUAL_MOUSE; | g_WS.qual &= ~WS_QUAL_MOUSE; | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
| int sizex, sizey; | int sizex, sizey; | ||||
| /* int ofsx, ofsy; */ /* UNUSED */ | /* int ofsx, ofsy; */ /* UNUSED */ | ||||
| if (ps->zoom + zoom_offset > 0.0f) { | if (ps->zoom + zoom_offset > 0.0f) { | ||||
| ps->zoom += zoom_offset; | ps->zoom += zoom_offset; | ||||
| } | } | ||||
| // playanim_window_get_position(&ofsx, &ofsy); | // playanim_window_get_position(&ofsx, &ofsy); | ||||
| playanim_window_get_size(&sizex, &sizey); | // playanim_window_get_size(&sizex, &sizey); | ||||
| /* ofsx += sizex / 2; */ /* UNUSED */ | /* ofsx += sizex / 2; */ /* UNUSED */ | ||||
| /* ofsy += sizey / 2; */ /* UNUSED */ | /* ofsy += sizey / 2; */ /* UNUSED */ | ||||
| sizex = ps->zoom * ps->ibufx; | sizex = ps->zoom * ps->ibufx; | ||||
| sizey = ps->zoom * ps->ibufy; | sizey = ps->zoom * ps->ibufy; | ||||
| /* ofsx -= sizex / 2; */ /* UNUSED */ | /* ofsx -= sizex / 2; */ /* UNUSED */ | ||||
| /* ofsy -= sizey / 2; */ /* UNUSED */ | /* ofsy -= sizey / 2; */ /* UNUSED */ | ||||
| // window_set_position(g_WS.ghost_window, sizex, sizey); | // window_set_position(g_WS.ghost_window, sizex, sizey); | ||||
| GHOST_SetClientSize(g_WS.ghost_window, sizex, sizey); | |||||
| const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | |||||
| GHOST_SetClientSize(g_WS.ghost_window, sizex / pixelsize, sizey / pixelsize); | |||||
| } | } | ||||
| /** | /** | ||||
| * \return The a path used to restart the animation player or NULL to exit. | * \return The a path used to restart the animation player or NULL to exit. | ||||
| */ | */ | ||||
| static char *wm_main_playanim_intern(int argc, const char **argv) | static char *wm_main_playanim_intern(int argc, const char **argv) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| static char filepath[FILE_MAX]; /* abused to return dropped file path */ | static char filepath[FILE_MAX]; /* abused to return dropped file path */ | ||||
| uint32_t maxwinx, maxwiny; | |||||
| int i; | int i; | ||||
| /* This was done to disambiguate the name for use under c++. */ | /* This was done to disambiguate the name for use under c++. */ | ||||
| int start_x = 0, start_y = 0; | int start_x = 0, start_y = 0; | ||||
| int sfra = -1; | int sfra = -1; | ||||
| int efra = -1; | int efra = -1; | ||||
| int totblock; | int totblock; | ||||
| PlayState ps = {0}; | PlayState ps = {0}; | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | |||||
| GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, &ps); | GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, &ps); | ||||
| g_WS.ghost_system = GHOST_CreateSystem(); | g_WS.ghost_system = GHOST_CreateSystem(); | ||||
| GHOST_AddEventConsumer(g_WS.ghost_system, consumer); | GHOST_AddEventConsumer(g_WS.ghost_system, consumer); | ||||
| playanim_window_open("Blender Animation Player", start_x, start_y, ibuf->x, ibuf->y); | playanim_window_open("Blender Animation Player", start_x, start_y, ibuf->x, ibuf->y); | ||||
| } | } | ||||
| GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &maxwinx, &maxwiny); | |||||
| // GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); | // GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); | ||||
| /* initialize OpenGL immediate mode */ | /* initialize OpenGL immediate mode */ | ||||
| g_WS.gpu_context = GPU_context_create(g_WS.ghost_window); | g_WS.gpu_context = GPU_context_create(g_WS.ghost_window); | ||||
| GPU_init(); | GPU_init(); | ||||
| const float pixelsize = GHOST_GetNativePixelSize(g_WS.ghost_window); | |||||
| if (pixelsize > 1.0f) { | |||||
| /* Update window size, macOS retina opens window with 2x more pixels. */ | |||||
| GHOST_SetClientSize(g_WS.ghost_window, ibuf->x / pixelsize, ibuf->y / pixelsize); | |||||
| } | |||||
| /* initialize the font */ | /* initialize the font */ | ||||
| BLF_init(); | BLF_init(); | ||||
| ps.fontid = BLF_load_mono_default(false); | ps.fontid = BLF_load_mono_default(false); | ||||
| BLF_size(ps.fontid, 11, 72); | BLF_size(ps.fontid, 11, 72 * pixelsize); | ||||
| ps.ibufx = ibuf->x; | ps.ibufx = ibuf->x; | ||||
| ps.ibufy = ibuf->y; | ps.ibufy = ibuf->y; | ||||
| ps.win_x = ps.ibufx; | ps.win_x = ps.ibufx; | ||||
| ps.win_y = ps.ibufy; | ps.win_y = ps.ibufy; | ||||
| #if 0 /* UNUSED */ | |||||
| uint32_t maxwinx, maxwiny; | |||||
| GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &maxwinx, &maxwiny); | |||||
| if (maxwinx % ibuf->x) { | if (maxwinx % ibuf->x) { | ||||
| maxwinx = ibuf->x * (1 + (maxwinx / ibuf->x)); | maxwinx = ibuf->x * (1 + (maxwinx / ibuf->x)); | ||||
| } | } | ||||
| if (maxwiny % ibuf->y) { | if (maxwiny % ibuf->y) { | ||||
| maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y)); | maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y)); | ||||
| } | } | ||||
| #endif | |||||
| GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f); | GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f); | ||||
| int win_x, win_y; | int win_x, win_y; | ||||
| playanim_window_get_size(&win_x, &win_y); | playanim_window_get_size(&win_x, &win_y); | ||||
| GPU_viewport(0, 0, win_x, win_y); | GPU_viewport(0, 0, win_x, win_y); | ||||
| GPU_scissor(0, 0, win_x, win_y); | GPU_scissor(0, 0, win_x, win_y); | ||||
| playanim_gl_matrix(); | playanim_gl_matrix(); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||