Merging r40615 through r40652 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index d7eba8c0ac75779aa4d76f1c134a0dbbc54e7cfa..9106453eb545095bb3ef35df64d3324830fa5ee3 100644 (file)
@@ -56,6 +56,7 @@
 #include "BKE_idprop.h"
 #include "BKE_report.h"
 #include "BKE_texture.h"
+#include "BKE_tracking.h"
 #include "BKE_unit.h"
 
 #include "ED_screen.h"
@@ -253,7 +254,7 @@ static uiBut *ui_but_last(uiBlock *block)
 static int ui_is_a_warp_but(uiBut *but)
 {
        if(U.uiflag & USER_CONTINUOUS_MOUSE)
-               if(ELEM3(but->type, NUM, NUMABS, HSVCIRCLE))
+               if(ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW))
                        return TRUE;
 
        return FALSE;
@@ -631,7 +632,7 @@ static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *dat
        data->applied= 1;
 }
 
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
 static void ui_apply_but_CHARTAB(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
        ui_apply_but_func(C, but);
@@ -916,6 +917,13 @@ static void ui_apply_but_WAVEFORM(bContext *C, uiBut *but, uiHandleButtonData *d
        data->applied= 1;
 }
 
+static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+       ui_apply_but_func(C, but);
+       data->retval= but->retval;
+       data->applied= 1;
+}
+
 
 static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
 {
@@ -1023,7 +1031,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                case IDPOIN:
                        ui_apply_but_IDPOIN(C, but, data);
                        break;
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
                case CHARTAB:
                        ui_apply_but_CHARTAB(C, but, data);
                        break;
@@ -1045,6 +1053,9 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                case WAVEFORM:
                        ui_apply_but_WAVEFORM(C, but, data);
                        break;
+               case TRACKPREVIEW:
+                       ui_apply_but_TRACKPREVIEW(C, but, data);
+                       break;
                default:
                        break;
        }
@@ -1113,9 +1124,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                if(but->poin==NULL && but->rnapoin.data==NULL);
                else if(mode=='c') {
                        if(ui_is_but_float(but))
-                               sprintf(buf, "%f", ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but));
                        else
-                               sprintf(buf, "%d", (int)ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but));
 
                        WM_clipboard_text_set(buf, 0);
                }
@@ -1136,7 +1147,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                else if(mode=='c') {
 
                        ui_get_but_vectorf(but, rgb);
-                       sprintf(buf, "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
+                       BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
                        WM_clipboard_text_set(buf, 0);
                        
                }
@@ -1235,7 +1246,7 @@ static short test_special_char(char ch)
                case ':':
                case ';':
                case '\'':
-               case '\"':
+               case '\"': // " - an extra closing one for Aligorith's text editor
                case '<':
                case '>':
                case ',':
@@ -1269,7 +1280,7 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data)
 /* note, but->block->aspect is used here, when drawing button style is getting scaled too */
 static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, short x)
 {
-       uiStyle *style= U.uistyles.first;       // XXX pass on as arg
+       uiStyle *style= UI_GetStyle();  // XXX pass on as arg
        uiFontStyle *fstyle = &style->widget;
        int startx= but->x1;
        char *origstr;
@@ -1684,7 +1695,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
                        /* not a file?, strip non utf-8 chars */
                        if(strip) {
                                /* wont happen often so isnt that annoying to keep it here for a while */
-                               printf("invalid utf8 - stripped chars %d\n", strip);
+                               printf("%s: invalid utf8 - stripped chars %d\n", __func__, strip);
                        }
                }
                
@@ -3924,7 +3935,7 @@ static int ui_do_but_VECTORSCOPE(bContext *C, uiBlock *block, uiBut *but, uiHand
        return WM_UI_HANDLER_CONTINUE;
 }
 
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
 static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut *UNUSED(but), uiHandleButtonData *UNUSED(data), wmEvent *UNUSED(event))
 {
        /* XXX 2.50 bad global and state access */
@@ -4060,6 +4071,88 @@ static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmE
        return WM_UI_HANDLER_CONTINUE;
 }
 
+static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
+{
+       MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
+       int changed= 1;
+       float dx, dy;
+
+       dx = mx - data->draglastx;
+       dy = my - data->draglasty;
+
+       if(shift) {
+               dx /= 5.0f;
+               dy /= 5.0f;
+       }
+
+       if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
+                /* resize preview widget itself */
+               scopes->track_preview_height = (but->y2 - but->y1) + (data->dragstarty - my);
+       } else {
+               if(scopes->marker) {
+                       if(scopes->marker->framenr!=scopes->framenr)
+                               scopes->marker= BKE_tracking_ensure_marker(scopes->track, scopes->framenr);
+
+                       scopes->marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
+                       scopes->marker->pos[0]+= -dx*scopes->slide_scale[0] / (but->block->maxx-but->block->minx);
+                       scopes->marker->pos[1]+= -dy*scopes->slide_scale[1] / (but->block->maxy-but->block->miny);
+
+                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
+               }
+
+               scopes->ok= 0;
+       }
+
+       data->draglastx= mx;
+       data->draglasty= my;
+
+       return changed;
+}
+
+static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
+{
+       int mx, my;
+
+       mx= event->x;
+       my= event->y;
+       ui_window_to_block(data->region, block, &mx, &my);
+
+       if(data->state == BUTTON_STATE_HIGHLIGHT) {
+               if(event->type==LEFTMOUSE && event->val==KM_PRESS) {
+                       data->dragstartx= mx;
+                       data->dragstarty= my;
+                       data->draglastx= mx;
+                       data->draglasty= my;
+                       button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
+
+                       /* also do drag the first time */
+                       if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
+                               ui_numedit_apply(C, block, but, data);
+
+                       return WM_UI_HANDLER_BREAK;
+               }
+       }
+       else if(data->state == BUTTON_STATE_NUM_EDITING) {
+               if(event->type == ESCKEY) {
+                       data->cancel= 1;
+                       data->escapecancel= 1;
+                       button_activate_state(C, but, BUTTON_STATE_EXIT);
+               }
+               else if(event->type == MOUSEMOVE) {
+                       if(mx!=data->draglastx || my!=data->draglasty) {
+                               if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
+                                       ui_numedit_apply(C, block, but, data);
+                       }
+               }
+               else if(event->type==LEFTMOUSE && event->val!=KM_PRESS) {
+                       button_activate_state(C, but, BUTTON_STATE_EXIT);
+               }
+               return WM_UI_HANDLER_BREAK;
+       }
+
+       return WM_UI_HANDLER_CONTINUE;
+}
+
 static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
 {
        uiBut *but = (uiBut *)arg1;
@@ -4101,7 +4194,7 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg)
        wmKeyMapItem *kmi;
        PointerRNA ptr;
        uiLayout *layout;
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
        int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
 
@@ -4133,7 +4226,7 @@ static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg)
        wmKeyMapItem *kmi;
        PointerRNA ptr;
        uiLayout *layout;
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
        int kmi_id;
        
@@ -4234,6 +4327,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                
                /* Keyframes */
                if(but->flag & UI_BUT_ANIMATED_KEY) {
+                       /* replace/delete keyfraemes */
                        if(length) {
                                uiItemBooleanO(layout, "Replace Keyframes", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
                                uiItemBooleanO(layout, "Replace Single Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
@@ -4244,6 +4338,11 @@ static int ui_but_menu(bContext *C, uiBut *but)
                                uiItemBooleanO(layout, "Replace Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
                                uiItemBooleanO(layout, "Delete Keyframe", ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0);
                        }
+                       
+                       /* keyframe settings */
+                       uiItemS(layout);
+                       
+                       
                }
                else if(but->flag & UI_BUT_DRIVEN);
                else if(is_anim) {
@@ -4286,6 +4385,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                }
                
                /* Keying Sets */
+               // TODO: check on modifyability of Keying Set when doing this
                if(is_anim) {
                        uiItemS(layout);
 
@@ -4360,7 +4460,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                PointerRNA ptr_props;
 
                if(but->rnapoin.data && but->rnaprop) {
-                       sprintf(buf, "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+                       BLI_snprintf(buf, sizeof(buf), "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
 
                        WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
                        RNA_string_set(&ptr_props, "doc_id", buf);
@@ -4577,7 +4677,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        case HSVCIRCLE:
                retval= ui_do_but_HSVCIRCLE(C, block, but, data, event);
                break;
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
        case CHARTAB:
                retval= ui_do_but_CHARTAB(C, block, but, data, event);
                break;
@@ -4587,6 +4687,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        case INLINK:
                retval= ui_do_but_LINK(C, but, data, event);
                break;
+       case TRACKPREVIEW:
+               retval= ui_do_but_TRACKPREVIEW(C, block, but, data, event);
+               break;
        }
        
        return retval;
@@ -5907,7 +6010,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                                                        ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE);
                                                                }
                                                                else {
-                                                                       printf("Error, but->menu_key type: %d\n", but->type);
+                                                                       printf("%s: error, but->menu_key type: %d\n", __func__, but->type);
                                                                }
 
                                                                break;