use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender.git] / source / blender / editors / armature / poseSlide.c
index 2ec91cc..c28b688 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -45,8 +43,6 @@
 #include "BLI_dlrbTree.h"
 #include "BLI_utildefines.h"
 
-#include "BLF_api.h"
-
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_object_types.h"
@@ -55,6 +51,7 @@
 #include "BKE_fcurve.h"
 
 #include "BKE_context.h"
+#include "BKE_object.h"
 #include "BKE_report.h"
 
 #include "RNA_access.h"
@@ -95,7 +92,8 @@
 /* Temporary data shared between these operators */
 typedef struct tPoseSlideOp {
        Scene *scene;           /* current scene */
-       ARegion *ar;            /* region that we're operating in (needed for  */
+       ScrArea *sa;            /* area that we're operating in (needed for modal()) */
+       ARegion *ar;            /* region that we're operating in (needed for modal()) */
        Object *ob;                     /* active object that Pose Info comes from */
        bArmature *arm;         /* armature for pose */
        
@@ -132,8 +130,9 @@ static int pose_slide_init (bContext *C, wmOperator *op, short mode)
        
        /* get info from context */
        pso->scene= CTX_data_scene(C);
-       pso->ob= ED_object_pose_armature(CTX_data_active_object(C));
+       pso->ob= object_pose_armature_get(CTX_data_active_object(C));
        pso->arm= (pso->ob)? pso->ob->data : NULL;
+       pso->sa= CTX_wm_area(C); /* only really needed when doing modal() */
        pso->ar= CTX_wm_region(C); /* only really needed when doing modal() */
        
        pso->cframe= pso->scene->r.cfra;
@@ -422,7 +421,7 @@ static void pose_slide_apply_quat (tPoseSlideOp *pso, tPChanFCurveLink *pfl)
                        sub_qt_qtqt(quat_diff, pchan->quat, quat_prev);
                        
                        /* make a copy of the original rotation */
-                       QUATCOPY(quat_orig, pchan->quat);
+                       copy_qt_qt(quat_orig, pchan->quat);
                        
                        /* increase the original by the delta transform, by an amount determined by percentage */
                        add_qt_qtqt(pchan->quat, quat_orig, quat_diff, pso->percentage);
@@ -437,7 +436,7 @@ static void pose_slide_apply_quat (tPoseSlideOp *pso, tPChanFCurveLink *pfl)
                                interp_qt_qtqt(quat_interp, quat_prev, quat_next, (cframe-pso->prevFrame) / (pso->nextFrame-pso->prevFrame) );
                                
                                /* make a copy of the original rotation */
-                               QUATCOPY(quat_orig, pchan->quat);
+                               copy_qt_qt(quat_orig, pchan->quat);
                                
                                /* tricky interpolations - blending between original and new */
                                interp_qt_qtqt(pchan->quat, quat_orig, quat_interp, 1.0f/6.0f);
@@ -521,6 +520,33 @@ static void pose_slide_reset (tPoseSlideOp *pso)
 
 /* ------------------------------------ */
 
+/* draw percentage indicator in header */
+static void pose_slide_draw_status (tPoseSlideOp *pso)
+{
+       char status_str[32];
+       char mode_str[32];
+       
+       switch (pso->mode) {
+               case POSESLIDE_PUSH:
+                       strcpy(mode_str, "Push Pose");
+                       break;
+               case POSESLIDE_RELAX:
+                       strcpy(mode_str, "Relax Pose");
+                       break;
+               case POSESLIDE_BREAKDOWN:
+                       strcpy(mode_str, "Breakdown");
+                       break;
+               
+               default:
+                       // unknown
+                       strcpy(mode_str, "Sliding-Tool");
+                       break;
+       }
+       
+       BLI_snprintf(status_str, sizeof(status_str), "%s: %d %%", mode_str, (int)(pso->percentage*100.0f));
+       ED_area_headerprint(pso->sa, status_str);
+}
+
 /* common code for invoke() methods */
 static int pose_slide_invoke_common (bContext *C, wmOperator *op, tPoseSlideOp *pso)
 {
@@ -574,7 +600,7 @@ static int pose_slide_invoke_common (bContext *C, wmOperator *op, tPoseSlideOp *
                }
        }
        else {
-               BKE_report(op->reports, RPT_ERROR, "No keyframes to slide between.");
+               BKE_report(op->reports, RPT_ERROR, "No keyframes to slide between");
                pose_slide_exit(op);
                return OPERATOR_CANCELLED;
        }
@@ -589,6 +615,9 @@ static int pose_slide_invoke_common (bContext *C, wmOperator *op, tPoseSlideOp *
        /* set cursor to indicate modal */
        WM_cursor_modal(win, BC_EW_SCROLLCURSOR);
        
+       /* header print */
+       pose_slide_draw_status(pso);
+       
        /* add a modal handler for this operator */
        WM_event_add_modal_handler(C, op);
        return OPERATOR_RUNNING_MODAL;
@@ -603,7 +632,8 @@ static int pose_slide_modal (bContext *C, wmOperator *op, wmEvent *evt)
        switch (evt->type) {
                case LEFTMOUSE: /* confirm */
                {
-                       /* return to normal cursor */
+                       /* return to normal cursor and header status */
+                       ED_area_headerprint(pso->sa, NULL);
                        WM_cursor_restore(win);
                        
                        /* insert keyframes as required... */
@@ -617,7 +647,8 @@ static int pose_slide_modal (bContext *C, wmOperator *op, wmEvent *evt)
                case ESCKEY:    /* cancel */
                case RIGHTMOUSE: 
                {
-                       /* return to normal cursor */
+                       /* return to normal cursor and header status */
+                       ED_area_headerprint(pso->sa, NULL);
                        WM_cursor_restore(win);
                        
                        /* reset transforms back to original state */
@@ -641,6 +672,9 @@ static int pose_slide_modal (bContext *C, wmOperator *op, wmEvent *evt)
                        pso->percentage= (evt->x - pso->ar->winrct.xmin) / ((float)pso->ar->winx);
                        RNA_float_set(op->ptr, "percentage", pso->percentage);
                        
+                       /* update percentage indicator in header */
+                       pose_slide_draw_status(pso);
+                       
                        /* reset transforms (to avoid accumulation errors) */
                        pose_slide_reset(pso);
                        
@@ -684,9 +718,9 @@ static int pose_slide_exec_common (bContext *C, wmOperator *op, tPoseSlideOp *ps
 /* common code for defining RNA properties */
 static void pose_slide_opdef_properties (wmOperatorType *ot)
 {
-       RNA_def_int(ot->srna, "prev_frame", 0, MINAFRAME, MAXFRAME, _("Previous Keyframe"), _("Frame number of keyframe immediately before the current frame."), 0, 50);
-       RNA_def_int(ot->srna, "next_frame", 0, MINAFRAME, MAXFRAME, _("Next Keyframe"), _("Frame number of keyframe immediately after the current frame."), 0, 50);
-       RNA_def_float_percentage(ot->srna, "percentage", 0.5f, 0.0f, 1.0f, _("Percentage"), _("Weighting factor for the sliding operation"), 0.3, 0.7);
+       RNA_def_int(ot->srna, "prev_frame", 0, MINAFRAME, MAXFRAME, "Previous Keyframe", "Frame number of keyframe immediately before the current frame", 0, 50);
+       RNA_def_int(ot->srna, "next_frame", 0, MINAFRAME, MAXFRAME, "Next Keyframe", "Frame number of keyframe immediately after the current frame", 0, 50);
+       RNA_def_float_percentage(ot->srna, "percentage", 0.5f, 0.0f, 1.0f, "Percentage", "Weighting factor for the sliding operation", 0.3, 0.7);
 }
 
 /* ------------------------------------ */
@@ -728,9 +762,9 @@ static int pose_slide_push_exec (bContext *C, wmOperator *op)
 void POSE_OT_push (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Push Pose");
+       ot->name= "Push Pose";
        ot->idname= "POSE_OT_push";
-       ot->description= _("Exaggerate the current pose");
+       ot->description= "Exaggerate the current pose";
        
        /* callbacks */
        ot->exec= pose_slide_push_exec;
@@ -785,9 +819,9 @@ static int pose_slide_relax_exec (bContext *C, wmOperator *op)
 void POSE_OT_relax (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Relax Pose");
+       ot->name= "Relax Pose";
        ot->idname= "POSE_OT_relax";
-       ot->description= _("Make the current pose more similar to its surrounding ones");
+       ot->description= "Make the current pose more similar to its surrounding ones";
        
        /* callbacks */
        ot->exec= pose_slide_relax_exec;
@@ -842,9 +876,9 @@ static int pose_slide_breakdown_exec (bContext *C, wmOperator *op)
 void POSE_OT_breakdown (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Pose Breakdowner");
+       ot->name= "Pose Breakdowner";
        ot->idname= "POSE_OT_breakdown";
-       ot->description= _("Create a suitable breakdown pose on the current frame");
+       ot->description= "Create a suitable breakdown pose on the current frame";
        
        /* callbacks */
        ot->exec= pose_slide_breakdown_exec;
@@ -1002,7 +1036,7 @@ static short pose_propagate_get_refVal (Object *ob, FCurve *fcu, float *value)
        
        /* resolve the property... */
        if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
-               if (RNA_property_array_check(&ptr, prop)) {
+               if (RNA_property_array_check(prop)) {
                        /* array */
                        if (fcu->array_index < RNA_property_array_length(&ptr, prop)) {
                                found= TRUE;
@@ -1131,7 +1165,7 @@ static void pose_propagate_fcurve (wmOperator *op, Object *ob, FCurve *fcu,
 static int pose_propagate_exec (bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
+       Object *ob= object_pose_armature_get(CTX_data_active_object(C));
        bAction *act= (ob && ob->adt)? ob->adt->action : NULL;
        
        ListBase pflinks = {NULL, NULL};
@@ -1197,18 +1231,18 @@ static int pose_propagate_exec (bContext *C, wmOperator *op)
 void POSE_OT_propagate (wmOperatorType *ot)
 {
        static EnumPropertyItem terminate_items[]= {
-               {POSE_PROPAGATE_SMART_HOLDS, "WHILE_HELD", 0, N_("While Held"), N_("Propagate pose to all keyframes after current frame that don't change (Default behaviour)")},
-               {POSE_PROPAGATE_NEXT_KEY, "NEXT_KEY", 0, N_("To Next Keyframe"), N_("Propagate pose to first keyframe following the current frame only")},
-               {POSE_PROPAGATE_LAST_KEY, "LAST_KEY", 0, N_("To Last Keyframe"), N_("Propagate pose to the last keyframe only (i.e. making action cyclic)")},
-               {POSE_PROPAGATE_BEFORE_FRAME, "BEFORE_FRAME", 0, N_("Before Frame"), N_("Propagate pose to all keyframes between current frame and 'Frame' property")},
-               {POSE_PROPAGATE_BEFORE_END, "BEFORE_END", 0, N_("Before Last Keyframe"), N_("Propagate pose to all keyframes from current frame until no more are found")},
-               {POSE_PROPAGATE_SELECTED_MARKERS, "SELECTED_MARKERS", 0, N_("On Selected Markers"), N_("Propagate pose to all keyframes occurring on frames with Scene Markers after the current frame")},
+               {POSE_PROPAGATE_SMART_HOLDS, "WHILE_HELD", 0, "While Held", "Propagate pose to all keyframes after current frame that don't change (Default behaviour)"},
+               {POSE_PROPAGATE_NEXT_KEY, "NEXT_KEY", 0, "To Next Keyframe", "Propagate pose to first keyframe following the current frame only"},
+               {POSE_PROPAGATE_LAST_KEY, "LAST_KEY", 0, "To Last Keyframe", "Propagate pose to the last keyframe only (i.e. making action cyclic)"},
+               {POSE_PROPAGATE_BEFORE_FRAME, "BEFORE_FRAME", 0, "Before Frame", "Propagate pose to all keyframes between current frame and 'Frame' property"},
+               {POSE_PROPAGATE_BEFORE_END, "BEFORE_END", 0, "Before Last Keyframe", "Propagate pose to all keyframes from current frame until no more are found"},
+               {POSE_PROPAGATE_SELECTED_MARKERS, "SELECTED_MARKERS", 0, "On Selected Markers", "Propagate pose to all keyframes occurring on frames with Scene Markers after the current frame"},
                {0, NULL, 0, NULL, NULL}};
                
        /* identifiers */
-       ot->name= _("Propagate Pose");
+       ot->name= "Propagate Pose";
        ot->idname= "POSE_OT_propagate";
-       ot->description= _("Copy selected aspects of the current pose to subsequent poses already keyframed");
+       ot->description= "Copy selected aspects of the current pose to subsequent poses already keyframed";
        
        /* callbacks */
        ot->exec= pose_propagate_exec;
@@ -1219,8 +1253,8 @@ void POSE_OT_propagate (wmOperatorType *ot)
        
        /* properties */
        // TODO: add "fade out" control for tapering off amount of propagation as time goes by?
-       ot->prop= RNA_def_enum(ot->srna, "mode", RNA_enum_items_gettexted(terminate_items), POSE_PROPAGATE_SMART_HOLDS, _("Terminate Mode"), _("Method used to determine when to stop propagating pose to keyframes"));
-       RNA_def_float(ot->srna, "end_frame", 250.0, FLT_MIN, FLT_MAX, _("End Frame"), _("Frame to stop propagating frames to (for 'Before Frame' mode)"), 1.0, 250.0);
+       ot->prop= RNA_def_enum(ot->srna, "mode", terminate_items, POSE_PROPAGATE_SMART_HOLDS, "Terminate Mode", "Method used to determine when to stop propagating pose to keyframes");
+       RNA_def_float(ot->srna, "end_frame", 250.0, FLT_MIN, FLT_MAX, "End Frame", "Frame to stop propagating frames to (for 'Before Frame' mode)", 1.0, 250.0);
 }
 
 /* **************************************************** */