/* XXX this one should correctly check for apple top header... * done for Cocoa : returns window contents (and not frame) max size*/ void wm_get_screensize(int *width_r, int *height_r) { unsigned int uiwidth; unsigned int uiheight; GHOST_GetMainDisplayDimensions(g_system, &uiwidth, &uiheight); *width_r = uiwidth; *height_r = uiheight; }
/* XXX this one should correctly check for apple top header... * done for Cocoa : returns window contents (and not frame) max size*/ void wm_get_screensize(int *r_width, int *r_height) { unsigned int uiwidth; unsigned int uiheight; GHOST_GetMainDisplayDimensions(g_system, &uiwidth, &uiheight); *r_width = uiwidth; *r_height = uiheight; }
static void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey) { GHOST_TUns32 scr_w, scr_h; GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &scr_w, &scr_h); posy = (scr_h - posy - sizey); g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system, title, posx, posy, sizex, sizey, /* could optionally start fullscreen */ GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, FALSE /* no stereo */, FALSE); }
LoggerWindow *loggerwindow_new(MultiTestApp *app) { GHOST_SystemHandle sys= multitestapp_get_system(app); GHOST_TUns32 screensize[2]; GHOST_WindowHandle win; GHOST_GetMainDisplayDimensions(sys, &screensize[0], &screensize[1]); win= GHOST_CreateWindow(sys, "MultiTest:Logger", 40, screensize[1]-432, 800, 300, GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, FALSE, FALSE); if (win) { LoggerWindow *lw= MEM_callocN(sizeof(*lw), "loggerwindow_new"); int bbox[2][2]; lw->app= app; lw->win= win; #ifdef USE_BMF lw->font= BMF_GetFont(BMF_kScreen12); lw->fonttexid= BMF_GetFontTexture(lw->font); BMF_GetBoundingBox(lw->font, &bbox[0][0], &bbox[0][1], &bbox[1][0], &bbox[1][1]); lw->fontheight= rect_height(bbox); #else lw->font= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); BLF_size(lw->font, 11, 72); lw->fontheight= BLF_height(lw->font, "A_"); #endif lw->nloglines= lw->logsize= 0; lw->loglines= MEM_mallocN(sizeof(*lw->loglines)*lw->nloglines, "loglines"); lw->scroll= scrollbar_new(2, 40); GHOST_SetWindowUserData(lw->win, windowdata_new(lw, loggerwindow_handle)); loggerwindow_do_reshape(lw); return lw; } else { return NULL; } }
static void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey, int start_maximized) { GHOST_TWindowState inital_state; GHOST_TUns32 scr_w, scr_h; GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &scr_w, &scr_h); posy = (scr_h - posy - sizey); if (start_maximized == G_WINDOWSTATE_FULLSCREEN) inital_state = start_maximized ? GHOST_kWindowStateFullScreen : GHOST_kWindowStateNormal; else inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal; g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system, title, posx, posy, sizex, sizey, inital_state, GHOST_kDrawingContextTypeOpenGL, FALSE /* no stereo */, FALSE); }
/* return path for restart */ static char *wm_main_playanim_intern(int argc, const char **argv) { struct ImBuf *ibuf = NULL; static char filepath[FILE_MAX]; /* abused to return dropped file path */ GHOST_TUns32 maxwinx, maxwiny; int i; /* This was done to disambiguate the name for use under c++. */ struct anim *anim = NULL; int start_x = 0, start_y = 0; int sfra = -1; int efra = -1; int totblock; PlayState ps = {0}; /* ps.doubleb = TRUE;*/ /* UNUSED */ ps.go = TRUE; ps.direction = TRUE; ps.next_frame = 1; ps.once = FALSE; ps.turbo = FALSE; ps.pingpong = FALSE; ps.noskip = FALSE; ps.sstep = FALSE; ps.wait2 = FALSE; ps.stopped = FALSE; ps.picture = NULL; ps.dropped_file[0] = 0; ps.zoom = 1.0f; /* resetmap = FALSE */ ps.fstep = 1; ps.fontid = -1; while (argc > 1) { if (argv[1][0] == '-') { switch (argv[1][1]) { case 'm': fromdisk = TRUE; break; case 'p': if (argc > 3) { start_x = atoi(argv[2]); start_y = atoi(argv[3]); argc -= 2; argv += 2; } else { printf("too few arguments for -p (need 2): skipping\n"); } break; case 'f': if (argc > 3) { double fps = atof(argv[2]); double fps_base = atof(argv[3]); if (fps == 0.0) { fps = 1; printf("invalid fps," "forcing 1\n"); } swaptime = fps_base / fps; argc -= 2; argv += 2; } else { printf("too few arguments for -f (need 2): skipping\n"); } break; case 's': sfra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); argc--; argv++; break; case 'e': efra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); argc--; argv++; break; case 'j': ps.fstep = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]))); swaptime *= ps.fstep; argc--; argv++; break; default: printf("unknown option '%c': skipping\n", argv[1][1]); break; } argc--; argv++; } else { break; } } if (argc > 1) { BLI_strncpy(filepath, argv[1], sizeof(filepath)); } else { BLI_current_working_dir(filepath, sizeof(filepath)); BLI_add_slash(filepath); } if (IMB_isanim(filepath)) { /* OCIO_TODO: support different input color spaces */ anim = IMB_open_anim(filepath, IB_rect, 0, NULL); if (anim) { ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE); IMB_close_anim(anim); anim = NULL; } } else if (!IMB_ispic(filepath)) { printf("%s: '%s' not an image file\n", __func__, filepath); exit(1); } if (ibuf == NULL) { /* OCIO_TODO: support different input color space */ ibuf = IMB_loadiffname(filepath, IB_rect, NULL); } if (ibuf == NULL) { printf("%s: '%s' couldn't open\n", __func__, filepath); exit(1); } #if 0 //XXX25 #if !defined(WIN32) && !defined(__APPLE__) if (fork()) exit(0); #endif #endif //XXX25 { GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, &ps); g_WS.ghost_system = GHOST_CreateSystem(); GHOST_AddEventConsumer(g_WS.ghost_system, consumer); playanim_window_open("Blender:Anim", start_x, start_y, ibuf->x, ibuf->y); /* unified matrix, note it affects offset for drawing */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); } GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &maxwinx, &maxwiny); //GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); /* initialize the font */ BLF_init(11, 72); ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(ps.fontid, 11, 72); ps.ibufx = ibuf->x; ps.ibufy = ibuf->y; ps.win_x = ps.ibufx; ps.win_y = ps.ibufy; if (maxwinx % ibuf->x) maxwinx = ibuf->x * (1 + (maxwinx / ibuf->x)); if (maxwiny % ibuf->y) maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y)); glClearColor(0.1, 0.1, 0.1, 0.0); glClear(GL_COLOR_BUFFER_BIT); GHOST_SwapWindowBuffers(g_WS.ghost_window); if (sfra == -1 || efra == -1) { /* one of the frames was invalid, just use all images */ sfra = 1; efra = MAXFRAME; } build_pict_list(&ps, filepath, (efra - sfra) + 1, ps.fstep, ps.fontid); for (i = 2; i < argc; i++) { BLI_strncpy(filepath, argv[i], sizeof(filepath)); build_pict_list(&ps, filepath, (efra - sfra) + 1, ps.fstep, ps.fontid); } IMB_freeImBuf(ibuf); ibuf = NULL; pupdate_time(); ptottime = 0; /* newly added in 2.6x, without this images never get freed */ #define USE_IMB_CACHE while (ps.go) { if (ps.pingpong) ps.direction = -ps.direction; if (ps.direction == 1) { ps.picture = picsbase.first; } else { ps.picture = picsbase.last; } if (ps.picture == NULL) { printf("couldn't find pictures\n"); ps.go = FALSE; } if (ps.pingpong) { if (ps.direction == 1) { ps.picture = ps.picture->next; } else { ps.picture = ps.picture->prev; } } if (ptottime > 0.0) ptottime = 0.0; while (ps.picture) { int hasevent; #ifndef USE_IMB_CACHE if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf); #endif if (ps.picture->ibuf) { ibuf = ps.picture->ibuf; } else if (ps.picture->anim) { ibuf = IMB_anim_absolute(ps.picture->anim, ps.picture->frame, IMB_TC_NONE, IMB_PROXY_NONE); } else if (ps.picture->mem) { /* use correct colorspace here */ ibuf = IMB_ibImageFromMemory((unsigned char *) ps.picture->mem, ps.picture->size, ps.picture->IB_flags, NULL, ps.picture->name); } else { /* use correct colorspace here */ ibuf = IMB_loadiffname(ps.picture->name, ps.picture->IB_flags, NULL); } if (ibuf) { #ifdef USE_IMB_CACHE ps.picture->ibuf = ibuf; #endif BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name)); /* why only windows? (from 2.4x) - campbell */ #ifdef _WIN32 GHOST_SetTitle(g_WS.ghost_window, ps.picture->name); #endif while (pupdate_time()) PIL_sleep_ms(1); ptottime -= swaptime; playanim_toscreen(&ps, ps.picture, ibuf, ps.fontid, ps.fstep); } /* else delete */ else { printf("error: can't play this image type\n"); exit(0); } if (ps.once) { if (ps.picture->next == NULL) { ps.wait2 = TRUE; } else if (ps.picture->prev == NULL) { ps.wait2 = TRUE; } } ps.next_frame = ps.direction; while ( (hasevent = GHOST_ProcessEvents(g_WS.ghost_system, 0)) || ps.wait2 != 0) { if (hasevent) { GHOST_DispatchEvents(g_WS.ghost_system); } /* Note, this still draws for mousemoves on pause */ if (ps.wait2) { if (hasevent) { if (ibuf) { while (pupdate_time()) PIL_sleep_ms(1); ptottime -= swaptime; playanim_toscreen(&ps, ps.picture, ibuf, ps.fontid, ps.fstep); } } } if (!ps.go) { break; } } ps.wait2 = ps.sstep; if (ps.wait2 == 0 && ps.stopped == 0) { ps.stopped = TRUE; } pupdate_time(); if (ps.picture && ps.next_frame) { /* always at least set one step */ while (ps.picture) { ps.picture = playanim_step(ps.picture, ps.next_frame); if (ps.once && ps.picture != NULL) { if (ps.picture->next == NULL) { ps.wait2 = TRUE; } else if (ps.picture->prev == NULL) { ps.wait2 = TRUE; } } if (ps.wait2 || ptottime < swaptime || ps.turbo || ps.noskip) break; ptottime -= swaptime; } if (ps.picture == NULL && ps.sstep) { ps.picture = playanim_step(ps.picture, ps.next_frame); } } if (ps.go == FALSE) { break; } } } ps.picture = picsbase.first; anim = NULL; while (ps.picture) { if (ps.picture && ps.picture->anim && (anim != ps.picture->anim)) { // to prevent divx crashes anim = ps.picture->anim; IMB_close_anim(anim); } if (ps.picture->ibuf) { IMB_freeImBuf(ps.picture->ibuf); } if (ps.picture->mem) { MEM_freeN(ps.picture->mem); } ps.picture = ps.picture->next; } /* cleanup */ #ifndef USE_IMB_CACHE if (ibuf) IMB_freeImBuf(ibuf); #endif BLI_freelistN(&picsbase); #if 0 // XXX25 free_blender(); #else /* we still miss freeing a lot!, * but many areas could skip initialization too for anim play */ BLF_exit(); #endif GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window); /* early exit, IMB and BKE should be exited only in end */ if (ps.dropped_file[0]) { BLI_strncpy(filepath, ps.dropped_file, sizeof(filepath)); return filepath; } IMB_exit(); BKE_images_exit(); totblock = MEM_get_memory_blocks_in_use(); if (totblock != 0) { /* prints many bAKey, bArgument's which are tricky to fix */ #if 0 printf("Error Totblock: %d\n", totblock); MEM_printmemlist(); #endif } return NULL; }