Revision: 26415
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26415
Author:   aligorith
Date:     2010-01-30 05:43:36 +0100 (Sat, 30 Jan 2010)

Log Message:
-----------
View2D/TimeCode Drawing:

This commit introduces a few cleanups and tweaks to the way that timecodes 
(i.e. the timing indications used instead of frame numbers) get displayed.

1. Custom Spacing of TimeCodes/Gridlines
Made the minimum number of pixels between gridlines/timecode indications a 
user-preference, instead of being a hardcoded constant. This allows to set the 
spacing tighter/looser than the defaults, and is also used for the other 
changes.

2. Default timecode display style, (now named 'minimal') uses '+' as the 
delimeter for the sub-second frames. This hopefully makes it a bit clearer what 
those values represent, as opposed to the '!', which can sometimes look too 
much like a colon.

3. Added various timecode display styles as user-preference. - These include 
always displaying full SMPTE, to showing milliseconds instead of frams for 
sub-second times, and also an option to just show the times as seconds only.
- When changing the timecode style, the spacing setting is automatically 
modified so that the timecodes are spaced far apart enough so that they won't 
clash (under most circumstances). This automatic modification is only done if 
the spacing is too tight for the style being set.

4. Unified the code for generating timecode strings between the View2D 
scrollbar drawing and the current frame indicator drawing. 

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_userpref.py
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/interface/resources.c
    trunk/blender/source/blender/editors/interface/view2d.c
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/makesrna/intern/rna_userdef.c

Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py  2010-01-30 03:47:13 UTC 
(rev 26414)
+++ trunk/blender/release/scripts/ui/space_userpref.py  2010-01-30 04:43:36 UTC 
(rev 26415)
@@ -236,7 +236,14 @@
         col.prop(view, "auto_perspective")
         col.prop(view, "smooth_view")
         col.prop(view, "rotation_angle")
-
+        
+        col.separator()
+        col.separator()
+        
+        col.label(text="2D Viewports:")
+        col.prop(view, "view2d_grid_minimum_spacing", text="Minimum Grid 
Spacing")
+        col.prop(view, "timecode_style")
+        
         row.separator()
         row.separator()
 

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c  2010-01-30 
03:47:13 UTC (rev 26414)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c  2010-01-30 
04:43:36 UTC (rev 26415)
@@ -75,71 +75,147 @@
 extern void ui_rasterpos_safe(float x, float y, float aspect);
 
 /* *************************************************** */
-/* CURRENT FRAME DRAWING */
+/* TIME CODE FORMATTING */
 
-/* Draw current frame number in a little green box beside the current frame 
indicator */
-static void draw_cfra_number (Scene *scene, View2D *v2d, float cfra, short 
time)
+/* Generate timecode/frame number string and store in the supplied string 
+ *     - buffer: must be at least 13 chars long 
+ *     - power: special setting for View2D grid drawing, 
+ *       used to specify how detailed we need to be
+ *     - timecodes: boolean specifying whether timecodes or
+ *       frame numbers get drawn
+ *     - cfra: time in frames or seconds, consistent with the values shown by 
timecodes
+ */
+// TODO: have this in kernel instead under scene?
+void ANIM_timecode_string_from_frame (char *str, Scene *scene, int power, 
short timecodes, float cfra)
 {
-       float xscale, yscale, x, y;
-       char str[32];
-       short slen;
-       
-       /* because the frame number text is subject to the same scaling as the 
contents of the view */
-       UI_view2d_getscale(v2d, &xscale, &yscale);
-       glScalef(1.0f/xscale, 1.0f, 1.0f);
-       
-       if (time) {
-               /* Timecode:
-                *      - In general, minutes and seconds should be shown, as 
most clips will be
-                *        within this length. Hours will only be included if 
relevant.
-                *      - Only show frames when zoomed in enough for them to be 
relevant 
-                *        (using separator of '!' for frames).
-                *        When showing frames, use slightly different display 
to avoid confusion with mm:ss format
-                * TODO: factor into reusable function.
-                * Meanwhile keep in sync:
-                *        source/blender/editors/animation/anim_draw.c
-                *        source/blender/editors/interface/view2d.c
-                */
-               float val= FRA2TIME(CFRA);
+       if (timecodes) {
                int hours=0, minutes=0, seconds=0, frames=0;
+               float raw_seconds= cfra;
                char neg[2]= "";
                
-               /* get values */
-               if (val < 0) {
-                       /* correction for negative values */
+               /* get cframes */
+               if (cfra < 0) {
+                       /* correction for negative cfraues */
                        sprintf(neg, "-");
-                       val = -val;
+                       cfra = -cfra;
                }
-               if (val >= 3600) {
+               if (cfra >= 3600) {
                        /* hours */
                        /* XXX should we only display a single digit for hours 
since clips are 
                         *         VERY UNLIKELY to be more than 1-2 hours max? 
However, that would 
                         *         go against conventions...
                         */
-                       hours= (int)val / 3600;
-                       val= (float)fmod(val, 3600);
+                       hours= (int)cfra / 3600;
+                       cfra= (float)fmod(cfra, 3600);
                }
-               if (val >= 60) {
+               if (cfra >= 60) {
                        /* minutes */
-                       minutes= (int)val / 60;
-                       val= (float)fmod(val, 60);
+                       minutes= (int)cfra / 60;
+                       cfra= (float)fmod(cfra, 60);
                }
-               {
+               if (power <= 0) {
                        /* seconds + frames
                         *      Frames are derived from 'fraction' of second. 
We need to perform some additional rounding
                         *      to cope with 'half' frames, etc., which should 
be fine in most cases
                         */
-                       seconds= (int)val;
-                       frames= (int)floor( ((val - seconds) * FPS) + 0.5f );
+                       seconds= (int)cfra;
+                       frames= (int)floor( ((cfra - seconds) * FPS) + 0.5f );
                }
+               else {
+                       /* seconds (with pixel offset rounding) */
+                       seconds= (int)floor(cfra + 0.375f);
+               }
                
-               /* print timecode to temp string buffer */
-               if (hours) sprintf(str, "   %s%02d:%02d:%02d!%02d", neg, hours, 
minutes, seconds, frames);
-               else if (minutes) sprintf(str, "   %s%02d:%02d!%02d", neg, 
minutes, seconds, frames);
-               else sprintf(str, "   %s%d!%02d", neg, seconds, frames);
+               switch (U.timecode_style) {
+                       case USER_TIMECODE_MINIMAL: 
+                       {
+                               /*      - In general, minutes and seconds 
should be shown, as most clips will be
+                                *        within this length. Hours will only 
be included if relevant.
+                                *      - Only show frames when zoomed in 
enough for them to be relevant 
+                                *        (using separator of '+' for frames).
+                                *        When showing frames, use slightly 
different display to avoid confusion with mm:ss format
+                                */
+                               if (power <= 0) {
+                                       /* include "frames" in display */
+                                       if (hours) sprintf(str, 
"%s%02d:%02d:%02d+%02d", neg, hours, minutes, seconds, frames);
+                                       else if (minutes) sprintf(str, 
"%s%02d:%02d+%02d", neg, minutes, seconds, frames);
+                                       else sprintf(str, "%s%d+%02d", neg, 
seconds, frames);
+                               }
+                               else {
+                                       /* don't include 'frames' in display */
+                                       if (hours) sprintf(str, 
"%s%02d:%02d:%02d", neg, hours, minutes, seconds);
+                                       else sprintf(str, "%s%02d:%02d", neg, 
minutes, seconds);
+                               }
+                       }
+                               break;
+                               
+                       case USER_TIMECODE_SMPTE_MSF:
+                       {
+                               /* reduced SMPTE format that always shows 
minutes, seconds, frames. Hours only shown as needed. */
+                               if (hours) sprintf(str, 
"%s%02d:%02d:%02d:%02d", neg, hours, minutes, seconds, frames);
+                               else sprintf(str, "%s%02d:%02d:%02d", neg, 
minutes, seconds, frames);
+                       }
+                               break;
+                       
+                       case USER_TIMECODE_MILLISECONDS:
+                       {
+                               /* reduced SMPTE. Instead of frames, 
milliseconds are shown */
+                               int ms_dp= (power <= 0) ? (1 - power) : 1; /* 
precision of decimal part */
+                               int s_pad= ms_dp+3;     /* to get 2 digit 
whole-number part for seconds display (i.e. 3 is for 2 digits + radix, on top 
of full length) */
+                               
+                               if (hours) sprintf(str, "%s%02d:%02d:%0*.*f", 
neg, hours, minutes, s_pad, ms_dp, cfra);
+                               else sprintf(str, "%s%02d:%0*.*f", neg, 
minutes, s_pad,  ms_dp, cfra);
+                       }
+                               break;
+                               
+                       case USER_TIMECODE_SECONDS_ONLY:
+                       {
+                               /* only show the original seconds display */
+                               /* round to whole numbers if power is >= 1 
(i.e. scale is coarse) */
+                               if (power <= 0) sprintf(str, "%.*f", 1-power, 
raw_seconds);
+                               else sprintf(str, "%d", (int)floor(raw_seconds 
+ 0.375f));
+                       }
+                               break;
+                       
+                       case USER_TIMECODE_SMPTE_FULL:
+                       default:
+                       {
+                               /* full SMPTE format */
+                               sprintf(str, "%s%02d:%02d:%02d:%02d", neg, 
hours, minutes, seconds, frames);
+                       }
+                               break;
+               }
        }
-       else 
-               sprintf(str, "   %d", CFRA);
+       else {
+               /* round to whole numbers if power is >= 1 (i.e. scale is 
coarse) */
+               if (power <= 0) sprintf(str, "%.*f", 1-power, cfra);
+               else sprintf(str, "%d", (int)floor(cfra + 0.375f));
+       }
+} 
+
+/* *************************************************** */
+/* CURRENT FRAME DRAWING */
+
+/* Draw current frame number in a little green box beside the current frame 
indicator */
+static void draw_cfra_number (Scene *scene, View2D *v2d, float cfra, short 
time)
+{
+       float xscale, yscale, x, y;
+       char str[32] = "    t"; /* t is the character to start replacing from */
+       short slen;
+       
+       /* because the frame number text is subject to the same scaling as the 
contents of the view */
+       UI_view2d_getscale(v2d, &xscale, &yscale);
+       glScalef(1.0f/xscale, 1.0f, 1.0f);
+       
+       /* get timecode string 
+        *      - padding on str-buf passed so that it doesn't sit on the frame 
indicator
+        *      - power = 0, gives 'standard' behaviour for time
+        *        but power = 1 is required for frames (to get integer frames)
+        */
+       if (time)
+               ANIM_timecode_string_from_frame(&str[4], scene, 0, time, 
FRA2TIME(cfra));
+       else    
+               ANIM_timecode_string_from_frame(&str[4], scene, 1, time, cfra);
        slen= (short)UI_GetStringWidth(str) - 1;
        
        /* get starting coordinates for drawing */

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h  2010-01-30 
03:47:13 UTC (rev 26414)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h  2010-01-30 
04:43:36 UTC (rev 26415)
@@ -409,6 +409,9 @@
 /* DRAWING API */
 /* anim_draw.c */
 
+/* Get string representing the given frame number as an appropriately 
represented frame or timecode */
+void ANIM_timecode_string_from_frame(char *str, struct Scene *scene, int 
power, short timecodes, float cfra);
+
 /* ---------- Current Frame Drawing ---------------- */
 
 /* flags for Current Frame Drawing */

Modified: trunk/blender/source/blender/editors/interface/resources.c
===================================================================
--- trunk/blender/source/blender/editors/interface/resources.c  2010-01-30 
03:47:13 UTC (rev 26414)
+++ trunk/blender/source/blender/editors/interface/resources.c  2010-01-30 
04:43:36 UTC (rev 26415)
@@ -1377,6 +1377,9 @@
                U.scrcastfps = 10;
                U.scrcastwait = 50;
        }
+       if (U.v2d_min_gridsize == 0) {
+               U.v2d_min_gridsize= 35;
+       }
 
        /* funny name, but it is GE stuff, moves userdef stuff to engine */
 // XXX space_set_commmandline_options();

Modified: trunk/blender/source/blender/editors/interface/view2d.c
===================================================================
--- trunk/blender/source/blender/editors/interface/view2d.c     2010-01-30 
03:47:13 UTC (rev 26414)
+++ trunk/blender/source/blender/editors/interface/view2d.c     2010-01-30 
04:43:36 UTC (rev 26415)
@@ -51,6 +51,7 @@
 
 #include "BLF_api.h"
 
+#include "ED_anim_api.h"
 #include "ED_screen.h"
 
 #include "UI_interface.h"
@@ -1038,9 +1039,6 @@
 /* *********************************************************************** */
 /* Gridlines */
 
-/* minimum pixels per gridstep */
-#define MINGRIDSTEP    35
-
 /* View2DGrid is typedef'd in UI_view2d.h */
 struct View2DGrid {
        float dx, dy;                   /* stepsize (in pixels) between 
gridlines */
@@ -1131,7 +1129,7 @@
                space= v2d->cur.xmax - v2d->cur.xmin;
                pixels= (float)(v2d->mask.xmax - v2d->mask.xmin);
                
-               grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to