[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48739] branches/soc-2011-tomato/source/ blender/windowmanager/intern/wm_playanim.c: play animation now works switching between scrubbing and pingpong
Campbell Barton
ideasman42 at gmail.com
Sun Jul 8 20:20:29 CEST 2012
Revision: 48739
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48739
Author: campbellbarton
Date: 2012-07-08 18:20:29 +0000 (Sun, 08 Jul 2012)
Log Message:
-----------
play animation now works switching between scrubbing and pingpong
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c
Modified: branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c
===================================================================
--- branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c 2012-07-08 18:10:53 UTC (rev 48738)
+++ branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c 2012-07-08 18:20:29 UTC (rev 48739)
@@ -36,6 +36,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#ifndef WIN32
# include <unistd.h>
@@ -48,11 +49,12 @@
#include "PIL_time.h"
-#include <math.h>
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_path_util.h"
+#include "BLI_fileops.h"
+#include "BLI_rect.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -79,13 +81,10 @@
#include "GHOST_C-api.h"
#include "BLF_api.h"
-#define WINCLOSE -1
-#define REDRAW -3
-#define RESHAPE -2
-#define WINQUIT -4
-/* use */
typedef struct PlayState {
+
+ /* playback state */
short direction;
short next;
short once;
@@ -98,6 +97,7 @@
short stopped;
short go;
+ /* current picture */
struct PlayAnimPict *picture;
/* set once at the start */
@@ -108,31 +108,53 @@
struct ImBuf *curframe_ibuf;
} PlayState;
-/* ***************** gl_util.c ****************** */
+/* for debugging */
+#if 0
+void print_ps(PlayState *ps)
+{
+ printf("ps:\n");
+ printf(" direction=%d,\n", (int)ps->direction);
+ printf(" next=%d,\n", ps->next);
+ printf(" once=%d,\n", ps->once);
+ printf(" turbo=%d,\n", ps->turbo);
+ printf(" pingpong=%d,\n", ps->pingpong);
+ printf(" noskip=%d,\n", ps->noskip);
+ printf(" sstep=%d,\n", ps->sstep);
+ printf(" pause=%d,\n", ps->pause);
+ printf(" wait2=%d,\n", ps->wait2);
+ printf(" stopped=%d,\n", ps->stopped);
+ printf(" go=%d,\n\n", ps->go);
+ fflush(stdout);
+}
+#endif
-static GHOST_SystemHandle g_system = NULL;
-static void *g_window = NULL;
+/* global for window and events */
+typedef enum eWS_Qual {
+ WS_QUAL_LSHIFT = (1 << 0),
+ WS_QUAL_RSHIFT = (1 << 1),
+ WS_QUAL_SHIFT = (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT),
+ WS_QUAL_LALT = (1 << 2),
+ WS_QUAL_RALT = (1 << 3),
+ WS_QUAL_ALT = (WS_QUAL_LALT | WS_QUAL_RALT),
+ WS_QUAL_LCTRL = (1 << 4),
+ WS_QUAL_RCTRL = (1 << 5),
+ WS_QUAL_LMOUSE = (1 << 16),
+ WS_QUAL_MMOUSE = (1 << 17),
+ WS_QUAL_RMOUSE = (1 << 18),
+ WS_QUAL_MOUSE = (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE)
+} eWS_Qual;
-static int qualN = 0;
+static struct WindowStateGlobal {
+ GHOST_SystemHandle ghost_system;
+ void *ghost_window;
-#define LSHIFT (1 << 0)
-#define RSHIFT (1 << 1)
-#define SHIFT (LSHIFT | RSHIFT)
-#define LALT (1 << 2)
-#define RALT (1 << 3)
-#define ALT (LALT | RALT)
-#define LCTRL (1 << 4)
-#define RCTRL (1 << 5)
-#define LMOUSE (1 << 16)
-#define MMOUSE (1 << 17)
-#define RMOUSE (1 << 18)
-#define MOUSE (LMOUSE | MMOUSE | RMOUSE)
+ /* events */
+ eWS_Qual qual;
+} g_WS = {NULL};
-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);
+ GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window);
*width_r = GHOST_GetWidthRectangle(bounds);
*height_r = GHOST_GetHeightRectangle(bounds);
GHOST_DisposeRectangle(bounds);
@@ -144,46 +166,46 @@
int val;
/* Shift */
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyLeftShift, &val);
- if (val) qualN |= LSHIFT;
- else qualN &= ~LSHIFT;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftShift, &val);
+ if (val) g_WS.qual |= WS_QUAL_LSHIFT;
+ else g_WS.qual &= ~WS_QUAL_LSHIFT;
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyRightShift, &val);
- if (val) qualN |= RSHIFT;
- else qualN &= ~RSHIFT;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightShift, &val);
+ if (val) g_WS.qual |= WS_QUAL_RSHIFT;
+ else g_WS.qual &= ~WS_QUAL_RSHIFT;
/* Control */
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyLeftControl, &val);
- if (val) qualN |= LCTRL;
- else qualN &= ~LCTRL;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftControl, &val);
+ if (val) g_WS.qual |= WS_QUAL_LCTRL;
+ else g_WS.qual &= ~WS_QUAL_LCTRL;
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyRightControl, &val);
- if (val) qualN |= RCTRL;
- else qualN &= ~RCTRL;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightControl, &val);
+ if (val) g_WS.qual |= WS_QUAL_RCTRL;
+ else g_WS.qual &= ~WS_QUAL_RCTRL;
/* Alt */
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyLeftAlt, &val);
- if (val) qualN |= LCTRL;
- else qualN &= ~LCTRL;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftAlt, &val);
+ if (val) g_WS.qual |= WS_QUAL_LCTRL;
+ else g_WS.qual &= ~WS_QUAL_LCTRL;
- GHOST_GetModifierKeyState(g_system, GHOST_kModifierKeyRightAlt, &val);
- if (val) qualN |= RCTRL;
- else qualN &= ~RCTRL;
+ GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightAlt, &val);
+ if (val) g_WS.qual |= WS_QUAL_RCTRL;
+ else g_WS.qual &= ~WS_QUAL_RCTRL;
/* LMB */
- GHOST_GetButtonState(g_system, GHOST_kButtonMaskLeft, &val);
- if (val) qualN |= LMOUSE;
- else qualN &= ~LMOUSE;
+ GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskLeft, &val);
+ if (val) g_WS.qual |= WS_QUAL_LMOUSE;
+ else g_WS.qual &= ~WS_QUAL_LMOUSE;
/* MMB */
- GHOST_GetButtonState(g_system, GHOST_kButtonMaskMiddle, &val);
- if (val) qualN |= MMOUSE;
- else qualN &= ~MMOUSE;
+ GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskMiddle, &val);
+ if (val) g_WS.qual |= WS_QUAL_MMOUSE;
+ else g_WS.qual &= ~WS_QUAL_MMOUSE;
/* RMB */
- GHOST_GetButtonState(g_system, GHOST_kButtonMaskRight, &val);
- if (val) qualN |= RMOUSE;
- else qualN &= ~RMOUSE;
+ GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskRight, &val);
+ if (val) g_WS.qual |= WS_QUAL_RMOUSE;
+ else g_WS.qual &= ~WS_QUAL_RMOUSE;
}
typedef struct PlayAnimPict {
@@ -197,8 +219,7 @@
int IB_flags;
} PlayAnimPict;
-static struct ListBase _picsbase = {NULL, NULL};
-static struct ListBase *picsbase = &_picsbase;
+static struct ListBase picsbase = {NULL, NULL};
static int fromdisk = FALSE;
static int fstep = 1;
static float zoomx = 1.0, zoomy = 1.0;
@@ -216,7 +237,7 @@
return (ptottime < 0);
}
-static void toscreen(PlayAnimPict *picture, struct ImBuf *ibuf, int fontid)
+static void playanim_toscreen(PlayAnimPict *picture, struct ImBuf *ibuf, int fontid)
{
if (ibuf == NULL) {
@@ -230,7 +251,7 @@
if (ibuf->rect == NULL)
return;
- GHOST_ActivateWindowDrawingContext(g_window);
+ GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
glRasterPos2f(0.0f, 0.0f);
@@ -238,14 +259,12 @@
pupdate_time();
- if (picture && (qualN & (SHIFT | LMOUSE)) && (fontid != -1)) {
+ if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) {
int sizex, sizey;
float fsizex_inv, fsizey_inv;
char str[32 + FILE_MAX];
cpack(-1);
-// glRasterPos2f(0.02f, 0.03f);
BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime);
-// BMF_DrawString(font, str);
playanim_window_get_size(&sizex, &sizey);
fsizex_inv = 1.0f / sizex;
@@ -254,11 +273,10 @@
BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f);
BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f);
- BLF_draw(fontid, str, 256); // XXX
- // printf("Drawing text '%s'\n", str);
+ BLF_draw(fontid, str, sizeof(str));
}
- GHOST_SwapWindowBuffers(g_window);
+ GHOST_SwapWindowBuffers(g_WS.ghost_window);
}
static void build_pict_list(char *first, int totframes, int fstep, int fontid)
@@ -276,7 +294,7 @@
int pic;
ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
if (ibuf) {
- toscreen(NULL, ibuf, fontid);
+ playanim_toscreen(NULL, ibuf, fontid);
IMB_freeImBuf(ibuf);
}
@@ -287,7 +305,7 @@
picture->IB_flags = IB_rect;
BLI_snprintf(str, sizeof(str), "%s : %4.d", first, pic + 1);
picture->name = strdup(str);
- BLI_addtail(picsbase, picture);
+ BLI_addtail(&picsbase, picture);
}
}
else {
@@ -321,7 +339,7 @@
if (file < 0) return;
picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture");
if (picture == NULL) {
- printf("Not enough memory for pict struct \n");
+ printf("Not enough memory for pict struct '%s'\n", filepath);
close(file);
return;
}
@@ -360,7 +378,7 @@
picture->mem = mem;
picture->name = strdup(filepath);
close(file);
- BLI_addtail(picsbase, picture);
+ BLI_addtail(&picsbase, picture);
count++;
pupdate_time();
@@ -374,7 +392,7 @@
ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
}
if (ibuf) {
- toscreen(picture, ibuf, fontid);
+ playanim_toscreen(picture, ibuf, fontid);
IMB_freeImBuf(ibuf);
}
pupdate_time();
@@ -401,10 +419,11 @@
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
{
PlayState *ps = (PlayState *)ps_void;
-
GHOST_TEventType type = GHOST_GetEventType(evt);
int val;
+ // print_ps(ps);
+
playanim_event_qual_update();
/* convert ghost event into value keyboard or mouse */
@@ -438,7 +457,7 @@
if (val) swaptime = fstep / 30.0;
break;
case GHOST_kKeyNumpad4:
- if (qualN & SHIFT)
+ if (g_WS.qual & WS_QUAL_SHIFT)
swaptime = fstep / 24.0;
else
swaptime = fstep / 25.0;
@@ -462,8 +481,8 @@
if (val) {
ps->sstep = TRUE;
ps->wait2 = FALSE;
- if (qualN & SHIFT) {
- ps->picture = picsbase->first;
+ if (g_WS.qual & WS_QUAL_SHIFT) {
+ ps->picture = picsbase.first;
ps->next = 0;
}
else {
@@ -474,7 +493,7 @@
case GHOST_kKeyDownArrow:
if (val) {
ps->wait2 = FALSE;
- if (qualN & SHIFT) {
+ if (g_WS.qual & WS_QUAL_SHIFT) {
ps->next = ps->direction = -1;
}
else {
@@ -487,8 +506,8 @@
if (val) {
ps->sstep = TRUE;
ps->wait2 = FALSE;
- if (qualN & SHIFT) {
- ps->picture = picsbase->last;
+ if (g_WS.qual & WS_QUAL_SHIFT) {
+ ps->picture = picsbase.last;
ps->next = 0;
}
else {
@@ -499,7 +518,7 @@
case GHOST_kKeyUpArrow:
if (val) {
ps->wait2 = FALSE;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list