code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / windowmanager / intern / wm_playanim.c
index fd44f4a..cc364c2 100644 (file)
 
 #include "PIL_time.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_fileops.h"
 #include "BLI_listbase.h"
 #include "BLI_path_util.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
-#include "BLI_utildefines.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
@@ -91,7 +91,7 @@ typedef struct PlayState {
        short wait2;
        short stopped;
        short go;
-
+       
        int fstep;
 
        /* current picture */
@@ -103,6 +103,9 @@ typedef struct PlayState {
 
        /* saves passing args */
        struct ImBuf *curframe_ibuf;
+       
+       /* restarts player for file drop */
+       char dropped_file[FILE_MAX];
 } PlayState;
 
 /* for debugging */
@@ -252,8 +255,15 @@ static void playanim_toscreen(PlayAnimPict *picture, struct ImBuf *ibuf, int fon
 
        glRasterPos2f(0.0f, 0.0f);
 
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+       fdrawcheckerboard(0.0f, 0.0f, ibuf->x, ibuf->y);
+
        glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 
+       glDisable(GL_BLEND);
+
        pupdate_time();
 
        if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) {
@@ -580,7 +590,9 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
                                case GHOST_kKeyPeriod:
                                case GHOST_kKeyNumpadPeriod:
                                        if (val) {
-                                               if (ps->sstep) ps->wait2 = FALSE;
+                                               if (ps->sstep) {
+                                                       ps->wait2 = FALSE;
+                                               }
                                                else {
                                                        ps->sstep = TRUE;
                                                        ps->wait2 = !ps->wait2;
@@ -728,6 +740,23 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
                        ps->go = FALSE;
                        break;
                }
+               case GHOST_kEventDraggingDropDone:
+               {
+                       GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt);
+                       
+                       if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
+                               GHOST_TStringArray *stra = ddd->data;
+                               int a;
+                               
+                               for (a = 0; a < stra->count; a++) {
+                                       BLI_strncpy(ps->dropped_file, (char *)stra->strings[a], sizeof(ps->dropped_file));
+                                       ps->go = FALSE;
+                                       printf("drop file %s\n", stra->strings[a]);
+                                       break; /* only one drop element supported now */
+                               }
+                       }
+                       break;
+               }
                default:
                        /* quiet warnings */
                        break;
@@ -778,12 +807,12 @@ static void playanim_window_zoom(const PlayState *ps, const float zoom_offset)
        GHOST_SetClientSize(g_WS.ghost_window, sizex, sizey);
 }
 
-void WM_main_playanim(int argc, const char **argv)
+/* return path for restart */
+static char *wm_main_playanim_intern(int argc, const char **argv)
 {
        struct ImBuf *ibuf = NULL;
-       char filepath[FILE_MAX];
+       static char filepath[FILE_MAX]; /* abused to return dropped file path */
        GHOST_TUns32 maxwinx, maxwiny;
-       /* short c233 = FALSE, yuvx = FALSE; */ /* UNUSED */
        int i;
        /* This was done to disambiguate the name for use under c++. */
        struct anim *anim = NULL;
@@ -791,7 +820,7 @@ void WM_main_playanim(int argc, const char **argv)
        int sfra = -1;
        int efra = -1;
        int totblock;
-
+       
        PlayState ps = {0};
 
        /* ps.doubleb   = TRUE;*/ /* UNUSED */
@@ -806,6 +835,7 @@ void WM_main_playanim(int argc, const char **argv)
        ps.wait2     = FALSE;
        ps.stopped   = FALSE;
        ps.picture   = NULL;
+       ps.dropped_file[0] = 0;
        /* resetmap = FALSE */
 
        ps.fstep     = 1;
@@ -1135,12 +1165,20 @@ void WM_main_playanim(int argc, const char **argv)
 #else
        /* we still miss freeing a lot!,
         * but many areas could skip initialization too for anim play */
-       IMB_exit();
-       BKE_images_exit();
+       
        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) {
+               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 */
@@ -1149,4 +1187,25 @@ void WM_main_playanim(int argc, const char **argv)
                MEM_printmemlist();
 #endif
        }
+       
+       return NULL;
+}
+
+
+void WM_main_playanim(int argc, const char **argv)
+{
+       bool looping = true;
+
+       while (looping) {
+               char *filepath = wm_main_playanim_intern(argc, argv);
+
+               if (filepath) { /* use simple args */
+                       argv[1] = "-a";
+                       argv[2] = filepath;
+                       argc = 3;
+               }
+               else {
+                       looping = false;
+               }
+       }
 }