Tomato: enable color management by default for Windows
[blender.git] / source / blender / windowmanager / intern / wm_playanim.c
index e33ed41cdda65f26f5ebde486bdf10951ccd3a44..83dd8c528a3fb84cc5ec05d8c4b41d2d395c40f7 100644 (file)
@@ -1,7 +1,4 @@
-#if 0
-/**
- * $Id: playanim.c 17755 2008-12-09 04:57:42Z bdiego $
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Campbell Barton
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/windowmanager/intern/wm_playanim.c
+ *  \ingroup wm
+ *
+ * \note This file uses ghost directly and none of the WM definitions.
+ *       this could be made into its own module, alongside creator/
+ */
+
 #include <sys/types.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifndef WIN32
-#include <unistd.h>
-#include <sys/times.h>
-#include <sys/wait.h>
+#  include <unistd.h>
+#  include <sys/times.h>
+#  include <sys/wait.h>
 #else
-#include <io.h>
+#  include <io.h>
 #endif
 #include "MEM_guardedalloc.h"
 
 #include <math.h>
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
-#include "BDR_editcurve.h"
-
 #include "BKE_blender.h"
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
-#include "BIF_screen.h"
-#include "BIF_mywindow.h"
-
-#include "BMF_Api.h"
 
 #ifdef WITH_QUICKTIME
-#ifdef _WIN32
-#include <QTML.h>
-#include <Movies.h>
-#elif defined(__APPLE__)
-#include <QuickTime/Movies.h>
-#endif /* __APPLE__ */
+#  ifdef _WIN32
+#    include <QTML.h>
+#    include <Movies.h>
+#  elif defined(__APPLE__)
+#    include <QuickTime/Movies.h>
+#  endif /* __APPLE__ */
 #endif /* WITH_QUICKTIME */
 
-#include "playanim_ext.h"
-#include "mydevice.h"
-#include "blendef.h"
-#include "winlay.h"
+#include "DNA_scene_types.h"
+#include "BLI_utildefines.h"
+#include "wm_event_types.h"
+#include "GHOST_C-api.h"
+
+#define WINCLOSE -1
+#define REDRAW -3
+#define RESHAPE -2
+#define WINQUIT -4
+
+static int qtest(void)
+{
+       return 0;
+}
 
 /* ***************** gl_util.c ****************** */
 
-static Window *g_window = NULL;
+static GHOST_SystemHandle g_system = NULL;
+static void *g_window = NULL;
+
 static int qualN = 0;
 
 #define LSHIFT  (1 << 0)
@@ -93,7 +99,7 @@ static int qualN = 0;
 #define SHIFT   (LSHIFT | RSHIFT)
 #define LALT    (1 << 2)
 #define RALT    (1 << 3)
-#define ALT     (LALT | RALT)
+#define ALT (LALT | RALT)
 #define LCTRL   (1 << 4)
 #define RCTRL   (1 << 5)
 #define LMOUSE  (1 << 16)
@@ -103,11 +109,23 @@ static int qualN = 0;
 
 unsigned short screen_qread(short *val, char *ascii);
 
+void playanim_window_get_size(int *width_r, int *height_r)
+{
+       GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_window);
+       *width_r = GHOST_GetWidthRectangle(bounds);
+       *height_r = GHOST_GetHeightRectangle(bounds);
+       GHOST_DisposeRectangle(bounds);
+}
+
 /* implementation */
 static int qreadN(short *val)
 {
+#if 0 // XXX25
        char ascii;
        int event = screen_qread(val, &ascii);
+#else
+       int event = 123456789;
+#endif
 
        switch (event) {
                case LEFTMOUSE:
@@ -151,13 +169,8 @@ static int qreadN(short *val)
        return(event);
 }
 
-/* ***************** gl_util.c ****************** */
-
-
-
-
-typedef struct pict {
-       struct pict *next, *prev;
+typedef struct PlayAnimPict {
+       struct PlayAnimPict *next, *prev;
        char *mem;
        int size;
        char *name;
@@ -165,9 +178,9 @@ typedef struct pict {
        struct anim *anim;
        int frame;
        int IB_flags;
-}Pict;
+} PlayAnimPict;
 
-static struct ListBase _picsbase = {0, 0};
+static struct ListBase _picsbase = {NULL, NULL};
 static struct ListBase *picsbase = &_picsbase;
 static int fromdisk = FALSE;
 static int fstep = 1;
@@ -186,10 +199,10 @@ static int pupdate_time(void)
        return (ptottime < 0);
 }
 
-static void toscreen(Pict *picture, struct ImBuf *ibuf)
+static void toscreen(PlayAnimPict *picture, struct ImBuf *ibuf)
 {
 
-       if (ibuf == 0) {
+       if (ibuf == NULL) {
                printf("no ibuf !\n");
                return;
        }
@@ -207,76 +220,83 @@ static void toscreen(Pict *picture, struct ImBuf *ibuf)
        pupdate_time();
 
        if (picture && (qualN & (SHIFT | LMOUSE))) {
-               char str[512];
+               char str[32 + FILE_MAX];
                cpack(-1);
-               glRasterPos2f(0.02f,  0.03f);
-               sprintf(str, "%s | %.2f frames/s\n", picture->name, fstep / swaptime);
+               glRasterPos2f(0.02f, 0.03f);
+               BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s\n", picture->name, fstep / swaptime);
+#if 0 // XXX25
                BMF_DrawString(G.fonts, str);
+#endif
        }
 
-       window_swap_buffers(g_window);
+       GHOST_SwapWindowBuffers(g_window);
 }
 
 static void build_pict_list(char *first, int totframes, int fstep)
 {
-       int size, pic, file;
-       char *mem, name[512];
-       short val;
-       struct pict *picture = 0;
-       struct ImBuf *ibuf = 0;
-       int count = 0;
-       char str[512];
+       char *mem, filepath[FILE_MAX];
+//     short val;
+       PlayAnimPict *picture = NULL;
+       struct ImBuf *ibuf = NULL;
+       char str[32 + FILE_MAX];
        struct anim *anim;
 
        if (IMB_isanim(first)) {
-               anim = IMB_open_anim(first, IB_rect);
+               anim = IMB_open_anim(first, IB_rect, 0);
                if (anim) {
-                       ibuf = IMB_anim_absolute(anim, 0);
+                       int pic;
+                       ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
                        if (ibuf) {
                                toscreen(NULL, ibuf);
                                IMB_freeImBuf(ibuf);
                        }
 
-                       for (pic = 0; pic < IMB_anim_get_duration(anim); pic++) {
-                               picture = (Pict *)MEM_callocN(sizeof(Pict), "Pict");
+                       for (pic = 0; pic < IMB_anim_get_duration(anim, IMB_TC_NONE); pic++) {
+                               picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "Pict");
                                picture->anim = anim;
                                picture->frame = pic;
                                picture->IB_flags = IB_rect;
-                               sprintf(str, "%s : %d", first, pic + 1);
+                               BLI_snprintf(str, sizeof(str), "%s : %d", first, pic + 1);
                                picture->name = strdup(str);
                                BLI_addtail(picsbase, picture);
                        }
                }
-               else printf("couldn't open anim %s\n", first);
+               else {
+                       printf("couldn't open anim %s\n", first);
+               }
        }
        else {
+               int count = 0;
 
-               strcpy(name, first);
+               BLI_strncpy(filepath, first, sizeof(filepath));
 
                pupdate_time();
                ptottime = 1.0;
 
-/*
-     O_DIRECT
-            If set, all reads and writes on the resulting file descriptor will
-            be performed directly to or from the user program buffer, provided
-            appropriate size and alignment restrictions are met.  Refer to the
-            F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry for
-            information about how to determine the alignment constraints.
-            O_DIRECT is a Silicon Graphics extension and is only supported on
-            local EFS and XFS file systems.
- */
-
-               while (IMB_ispic(name) && totframes) {
-                       file = open(name, O_BINARY | O_RDONLY, 0);
+               /* O_DIRECT
+                *
+                * If set, all reads and writes on the resulting file descriptor will
+                * be performed directly to or from the user program buffer, provided
+                * appropriate size and alignment restrictions are met.  Refer to the
+                * F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry for
+                * information about how to determine the alignment constraints.
+                * O_DIRECT is a Silicon Graphics extension and is only supported on
+                * local EFS and XFS file systems.
+                */
+
+               while (IMB_ispic(filepath) && totframes) {
+                       size_t size;
+                       int file;
+
+                       file = open(filepath, O_BINARY | O_RDONLY, 0);
                        if (file < 0) return;
-                       picture = (struct pict *)MEM_callocN(sizeof(struct pict), "picture");
-                       if (picture == 0) {
+                       picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture");
+                       if (picture == NULL) {
                                printf("Not enough memory for pict struct \n");
                                close(file);
                                return;
                        }
-                       size = BLI_filesize(file);
+                       size = BLI_file_descriptor_size(file);
 
                        if (size < 1) {
                                close(file);
@@ -289,7 +309,7 @@ static void build_pict_list(char *first, int totframes, int fstep)
 
                        if (fromdisk == FALSE) {
                                mem = (char *)MEM_mallocN(size, "build pic list");
-                               if (mem == 0) {
+                               if (mem == NULL) {
                                        printf("Couldn't get memory\n");
                                        close(file);
                                        MEM_freeN(picture);
@@ -297,17 +317,19 @@ static void build_pict_list(char *first, int totframes, int fstep)
                                }
 
                                if (read(file, mem, size) != size) {
-                                       printf("Error while reading %s\n", name);
+                                       printf("Error while reading %s\n", filepath);
                                        close(file);
                                        MEM_freeN(picture);
                                        MEM_freeN(mem);
                                        return;
                                }
                        }
-                       else mem = 0;
+                       else {
+                               mem = NULL;
+                       }
 
                        picture->mem = mem;
-                       picture->name = strdup(name);
+                       picture->name = strdup(filepath);
                        close(file);
                        BLI_addtail(picsbase, picture);
                        count++;
@@ -315,8 +337,13 @@ static void build_pict_list(char *first, int totframes, int fstep)
                        pupdate_time();
 
                        if (ptottime > 1.0) {
-                               if (picture->mem) ibuf = IMB_ibImageFromMemory((int *) picture->mem, picture->size, picture->IB_flags);
-                               else ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
+                               if (picture->mem) {
+                                       ibuf = IMB_ibImageFromMemory((unsigned char *)picture->mem, picture->size,
+                                                                    picture->IB_flags, picture->name);
+                               }
+                               else {
+                                       ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
+                               }
                                if (ibuf) {
                                        toscreen(picture, ibuf);
                                        IMB_freeImBuf(ibuf);
@@ -325,8 +352,9 @@ static void build_pict_list(char *first, int totframes, int fstep)
                                ptottime = 0.0;
                        }
 
-                       BLI_newname(name, +fstep);
+                       BLI_newname(filepath, +fstep);
 
+#if 0 // XXX25
                        while (qtest()) {
                                switch (qreadN(&val)) {
                                        case ESCKEY:
@@ -334,24 +362,69 @@ static void build_pict_list(char *first, int totframes, int fstep)
                                                break;
                                }
                        }
+#endif
                        totframes--;
                }
        }
        return;
 }
 
-void playanim(int argc, char **argv)
+static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr)
+{
+       (void)evt;
+       (void)C_void_ptr;
+
+       return 1;
+}
+
+void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey, int start_maximized)
 {
-       struct ImBuf *ibuf = 0;
-       struct pict *picture = 0;
-       char name[512];
+       GHOST_TWindowState inital_state;
+       GHOST_TUns32 scr_w, scr_h;
+
+       GHOST_GetMainDisplayDimensions(g_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;
+#ifdef __APPLE__
+       inital_state += macPrefState;
+#endif
+
+       g_window = GHOST_CreateWindow(g_system,
+                                     title,
+                                     posx, posy, sizex, sizey,
+                                     inital_state,
+                                     GHOST_kDrawingContextTypeOpenGL,
+                                     FALSE /* no stereo */, FALSE);
+
+       //if (ghostwin) {
+       //if (win) {
+       // GHOST_SetWindowUserData(ghostwin, win);
+       //} else {
+       //      GHOST_DisposeWindow(g_system, ghostwin);
+       //}
+       //}
+}
+
+
+void playanim(int argc, const char **argv)
+{
+       struct ImBuf *ibuf = NULL;
+       PlayAnimPict *picture = NULL;
+       char filepath[FILE_MAX];
        short val = 0, go = TRUE, ibufx = 0, ibufy = 0;
-       int event, stopped = FALSE, maxwinx, maxwiny;
-       short /*  c233 = FALSE, */ /*  yuvx = FALSE, */ once = FALSE, sstep = FALSE, wait2 = FALSE, /*  resetmap = FALSE, */ pause = 0;
+       int event, stopped = FALSE;
+       GHOST_TUns32 maxwinx, maxwiny;
+       /* short c233 = FALSE, yuvx = FALSE; */ /* UNUSED */
+       short once = FALSE, sstep = FALSE, wait2 = FALSE, /*  resetmap = FALSE, */ pause = 0;
        short pingpong = FALSE, direction = 1, next = 1, turbo = FALSE, /*  doubleb = TRUE, */ noskip = FALSE;
-       int sizex, sizey, ofsx, ofsy, i;
+       int sizex, sizey, i;
        /* This was done to disambiguate the name for use under c++. */
-       struct anim *anim = 0;
+       struct anim *anim = NULL;
        int start_x = 0, start_y = 0;
        int sfra = -1;
        int efra = -1;
@@ -378,7 +451,7 @@ void playanim(int argc, char **argv)
                                        if (argc > 3) {
                                                double fps = atof(argv[2]);
                                                double fps_base = atof(argv[3]);
-                                               if (fps == 0) {
+                                               if (fps == 0.0) {
                                                        fps = 1;
                                                        printf("invalid fps,"
                                                               "forcing 1\n");
@@ -414,7 +487,9 @@ void playanim(int argc, char **argv)
                        argc--;
                        argv++;
                }
-               else break;
+               else {
+                       break;
+               }
        }
 
 #ifdef WITH_QUICKTIME
@@ -437,42 +512,55 @@ void playanim(int argc, char **argv)
        G.have_quicktime = TRUE;
 #endif /* WITH_QUICKTIME */
 
-       if (argc > 1) strcpy(name, argv[1]);
+       if (argc > 1) {
+               BLI_strncpy(filepath, argv[1], sizeof(filepath));
+       }
        else {
-               BLI_getwdN(name);
-               if (name[strlen(name) - 1] != '/') strcat(name, "/");
+               BLI_current_working_dir(filepath, sizeof(filepath));
+               BLI_add_slash(filepath);
        }
 
-       if (IMB_isanim(name)) {
-               anim = IMB_open_anim(name, IB_rect);
+       if (IMB_isanim(filepath)) {
+               anim = IMB_open_anim(filepath, IB_rect, 0);
                if (anim) {
-                       ibuf = IMB_anim_absolute(anim, 0);
+                       ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
                        IMB_close_anim(anim);
                        anim = NULL;
                }
        }
-       else if (!IMB_ispic(name)) {
+       else if (!IMB_ispic(filepath)) {
                exit(1);
        }
 
-       if (ibuf == 0) ibuf = IMB_loadiffname(name, IB_rect);
-       if (ibuf == 0) {
-               printf("couldn't open %s\n", name);
+       if (ibuf == NULL) {
+               ibuf = IMB_loadiffname(filepath, IB_rect);
+       }
+
+       if (ibuf == NULL) {
+               printf("couldn't open %s\n", filepath);
                exit(1);
        }
 
+#if 0 //XXX25
        #if !defined(WIN32) && !defined(__APPLE__)
        if (fork()) exit(0);
        #endif
-
-       winlay_get_screensize(&maxwinx, &maxwiny);
+#endif //XXX25
 
        /* XXX, fixme zr */
        {
-               extern void add_to_mainqueue(Window *win, void *user_data, short evt, short val, char ascii);
+//             extern void add_to_mainqueue(wmWindow *win, void *user_data, short evt, short val, char ascii);
+
+               void *some_handle = NULL; // XXX25, fixme
+               GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, some_handle);
+
+               g_system = GHOST_CreateSystem();
+               GHOST_AddEventConsumer(g_system, consumer);
+
+
 
-               g_window = window_open("Blender:Anim", start_x, start_y, ibuf->x, ibuf->y, 0);
-               window_set_handler(g_window, add_to_mainqueue, NULL);
+               playanim_window_open("Blender:Anim", start_x, start_y, ibuf->x, ibuf->y, 0);
+//XXX25                window_set_handler(g_window, add_to_mainqueue, NULL);
 
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
@@ -480,7 +568,11 @@ void playanim(int argc, char **argv)
                glMatrixMode(GL_MODELVIEW);
        }
 
+       GHOST_GetMainDisplayDimensions(g_system, &maxwinx, &maxwiny);
+
+#if 0 //XXX25
        G.fonts = BMF_GetFont(BMF_kHelvetica10);
+#endif
 
        ibufx = ibuf->x;
        ibufy = ibuf->y;
@@ -491,7 +583,7 @@ void playanim(int argc, char **argv)
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
-       window_swap_buffers(g_window);
+       GHOST_SwapWindowBuffers(g_window);
 
        if (sfra == -1 || efra == -1) {
                /* one of the frames was invalid, just use all images */
@@ -499,15 +591,15 @@ void playanim(int argc, char **argv)
                efra = MAXFRAME;
        }
 
-       build_pict_list(name, (efra - sfra) + 1, fstep);
+       build_pict_list(filepath, (efra - sfra) + 1, fstep);
 
        for (i = 2; i < argc; i++) {
-               strcpy(name, argv[i]);
-               build_pict_list(name, (efra - sfra) + 1, fstep);
+               BLI_strncpy(filepath, argv[i], sizeof(filepath));
+               build_pict_list(filepath, (efra - sfra) + 1, fstep);
        }
 
        IMB_freeImBuf(ibuf);
-       ibuf = 0;
+       ibuf = NULL;
 
        pupdate_time();
        ptottime = 0;
@@ -515,32 +607,49 @@ void playanim(int argc, char **argv)
        while (go) {
                if (pingpong) direction = -direction;
 
-               if (direction == 1) picture = picsbase->first;
-               else picture = picsbase->last;
+               if (direction == 1) {
+                       picture = picsbase->first;
+               }
+               else {
+                       picture = picsbase->last;
+               }
 
-               if (picture == 0) {
+               if (picture == NULL) {
                        printf("couldn't find pictures\n");
                        go = FALSE;
                }
                if (pingpong) {
-                       if (direction == 1) picture = picture->next;
-                       else picture = picture->prev;
+                       if (direction == 1) {
+                               picture = picture->next;
+                       }
+                       else {
+                               picture = picture->prev;
+                       }
                }
                if (ptottime > 0.0) ptottime = 0.0;
 
                while (picture) {
-                       if (ibuf != 0 && ibuf->type == 0) IMB_freeImBuf(ibuf);
+                       if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf);
 
-                       if (picture->ibuf) ibuf = picture->ibuf;
-                       else if (picture->anim) ibuf = IMB_anim_absolute(picture->anim, picture->frame);
-                       else if (picture->mem) ibuf = IMB_ibImageFromMemory((int *) picture->mem, picture->size, picture->IB_flags);
-                       else ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
+                       if (picture->ibuf) {
+                               ibuf = picture->ibuf;
+                       }
+                       else if (picture->anim) {
+                               ibuf = IMB_anim_absolute(picture->anim, picture->frame, IMB_TC_NONE, IMB_PROXY_NONE);
+                       }
+                       else if (picture->mem) {
+                               ibuf = IMB_ibImageFromMemory((unsigned char *) picture->mem, picture->size,
+                                                            picture->IB_flags, picture->name);
+                       }
+                       else {
+                               ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
+                       }
 
                        if (ibuf) {
-                               strcpy(ibuf->name, picture->name);
+                               BLI_strncpy(ibuf->name, picture->name, sizeof(ibuf->name));
 
 #ifdef _WIN32
-                               window_set_title(g_window, picture->name);
+                               GHOST_SetTitle(g_window, picture->name);
 #endif
 
                                while (pupdate_time()) PIL_sleep_ms(1);
@@ -553,8 +662,12 @@ void playanim(int argc, char **argv)
                        }
 
                        if (once) {
-                               if (picture->next == 0) wait2 = TRUE;
-                               else if (picture->prev == 0) wait2 = TRUE;
+                               if (picture->next == NULL) {
+                                       wait2 = TRUE;
+                               }
+                               else if (picture->prev == NULL) {
+                                       wait2 = TRUE;
+                               }
                        }
 
                        next = direction;
@@ -644,7 +757,7 @@ void playanim(int argc, char **argv)
                                        case LEFTMOUSE:
                                        case MOUSEX:
                                                if (qualN & LMOUSE) {
-                                                       window_get_size(g_window, &sizex, &sizey);
+                                                       playanim_window_get_size(&sizex, &sizey);
                                                        picture = picsbase->first;
                                                        i = 0;
                                                        while (picture) {
@@ -654,7 +767,7 @@ void playanim(int argc, char **argv)
                                                        i = (i * val) / sizex;
                                                        picture = picsbase->first;
                                                        for (; i > 0; i--) {
-                                                               if (picture->next == 0) break;
+                                                               if (picture->next == NULL) break;
                                                                picture = picture->next;
                                                        }
                                                        sstep = TRUE;
@@ -662,15 +775,15 @@ void playanim(int argc, char **argv)
                                                        next = 0;
                                                }
                                                break;
-                                               go = FALSE;
-                                               break;
                                        case EQUALKEY:
                                                if (val) {
                                                        if (qualN & SHIFT) {
                                                                pause++;
                                                                printf("pause:%d\n", pause);
                                                        }
-                                                       else swaptime /= 1.1;
+                                                       else {
+                                                               swaptime /= 1.1;
+                                                       }
                                                }
                                                break;
                                        case MINUSKEY:
@@ -679,14 +792,16 @@ void playanim(int argc, char **argv)
                                                                pause--;
                                                                printf("pause:%d\n", pause);
                                                        }
-                                                       else swaptime *= 1.1;
+                                                       else {
+                                                               swaptime *= 1.1;
+                                                       }
                                                }
                                                break;
                                        case PAD0:
                                                if (val) {
                                                        if (once) once = wait2 = FALSE;
                                                        else {
-                                                               picture = 0;
+                                                               picture = NULL;
                                                                once = TRUE;
                                                                wait2 = FALSE;
                                                        }
@@ -742,27 +857,31 @@ void playanim(int argc, char **argv)
                                                zoomx += 2.0;
                                                zoomy += 2.0;
                                        case PADMINUS:
+                                       {
+                                               /* int ofsx, ofsy; */ /* UNUSED */
+
                                                if (val == 0) break;
                                                if (zoomx > 1.0) zoomx -= 1.0;
                                                if (zoomy > 1.0) zoomy -= 1.0;
-                                               window_get_position(g_window, &ofsx, &ofsy);
-                                               window_get_size(g_window, &sizex, &sizey);
-                                               ofsx += sizex / 2;
-                                               ofsy += sizey / 2;
+                                               // playanim_window_get_position(&ofsx, &ofsy);
+                                               playanim_window_get_size(&sizex, &sizey);
+                                               /* ofsx += sizex / 2; */ /* UNUSED */
+                                               /* ofsy += sizey / 2; */ /* UNUSED */
                                                sizex = zoomx * ibufx;
                                                sizey = zoomy * ibufy;
-                                               ofsx -= sizex / 2;
-                                               ofsy -= sizey / 2;
-/*                  window_set_position(g_window,sizex,sizey); */
-                                               window_set_size(g_window, sizex, sizey);
+                                               /* ofsx -= sizex / 2; */ /* UNUSED */
+                                               /* ofsy -= sizey / 2; */ /* UNUSED */
+                                               // window_set_position(g_window,sizex,sizey);
+                                               GHOST_SetClientSize(g_window, sizex, sizey);
                                                break;
+                                       }
                                        case RESHAPE:
                                        case REDRAW:
-                                               window_get_size(g_window, &sizex, &sizey);
-                                               window_make_active(g_window);
+                                               playanim_window_get_size(&sizey, &sizey);
+                                               GHOST_ActivateWindowDrawingContext(g_window);
 
-                                               glViewport(0,  0, sizex, sizey);
-                                               glScissor(0,  0, sizex, sizey);
+                                               glViewport(0, 0, sizex, sizey);
+                                               glScissor(0, 0, sizex, sizey);
 
                                                zoomx = (float) sizex / ibufx;
                                                zoomy = (float) sizey / ibufy;
@@ -801,20 +920,32 @@ void playanim(int argc, char **argv)
                        if (picture && next) {
                                /* always at least set one step */
                                while (picture) {
-                                       if (next < 0) picture = picture->prev;
-                                       else picture = picture->next;
+                                       if (next < 0) {
+                                               picture = picture->prev;
+                                       }
+                                       else {
+                                               picture = picture->next;
+                                       }
 
-                                       if (once && picture != 0) {
-                                               if (picture->next == 0) wait2 = TRUE;
-                                               else if (picture->prev == 0) wait2 = TRUE;
+                                       if (once && picture != NULL) {
+                                               if (picture->next == NULL) {
+                                                       wait2 = TRUE;
+                                               }
+                                               else if (picture->prev == NULL) {
+                                                       wait2 = TRUE;
+                                               }
                                        }
 
                                        if (wait2 || ptottime < swaptime || turbo || noskip) break;
                                        ptottime -= swaptime;
                                }
-                               if (picture == 0 && sstep) {
-                                       if (next < 0) picture = picsbase->last;
-                                       else if (next > 0) picture = picsbase->first;
+                               if (picture == NULL && sstep) {
+                                       if (next < 0) {
+                                               picture = picsbase->last;
+                                       }
+                                       else if (next > 0) {
+                                               picture = picsbase->first;
+                                       }
                                }
                        }
                        if (go == FALSE) break;
@@ -848,7 +979,7 @@ void playanim(int argc, char **argv)
        if (ibuf) IMB_freeImBuf(ibuf);
        BLI_freelistN(picsbase);
        free_blender();
-       window_destroy(g_window);
+       GHOST_DisposeWindow(g_system, g_window);
 
        totblock = MEM_get_memory_blocks_in_use();
        if (totblock != 0) {
@@ -856,11 +987,3 @@ void playanim(int argc, char **argv)
                MEM_printmemlist();
        }
 }
-
-#endif
-
-void playanim(int argc, const char **argv)
-{
-       (void)argc;
-       (void)argv;
-}