Merging r50470 through r50477 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index 957482b..dcd652a 100644 (file)
@@ -501,9 +501,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
        lvalue = (int)value;
        
        if (but->bit) {
-               w = BTST(lvalue, but->bitnr);
-               if (w) lvalue = BCLR(lvalue, but->bitnr);
-               else lvalue = BSET(lvalue, but->bitnr);
+               w = UI_BITBUT_TEST(lvalue, but->bitnr);
+               if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr);
+               else   lvalue = UI_BITBUT_SET(lvalue, but->bitnr);
                
                if (but->type == TOGR) {
                        if (!data->togonly) {
@@ -605,27 +605,27 @@ static void ui_apply_but_TOG3(bContext *C, uiBut *but, uiHandleButtonData *data)
        if (but->pointype == SHO) {
                short *sp = (short *)but->poin;
                
-               if (BTST(sp[1], but->bitnr)) {
-                       sp[1] = BCLR(sp[1], but->bitnr);
-                       sp[0] = BCLR(sp[0], but->bitnr);
+               if (UI_BITBUT_TEST(sp[1], but->bitnr)) {
+                       sp[1] = UI_BITBUT_CLR(sp[1], but->bitnr);
+                       sp[0] = UI_BITBUT_CLR(sp[0], but->bitnr);
                }
-               else if (BTST(sp[0], but->bitnr)) {
-                       sp[1] = BSET(sp[1], but->bitnr);
+               else if (UI_BITBUT_TEST(sp[0], but->bitnr)) {
+                       sp[1] = UI_BITBUT_SET(sp[1], but->bitnr);
                }
                else {
-                       sp[0] = BSET(sp[0], but->bitnr);
+                       sp[0] = UI_BITBUT_SET(sp[0], but->bitnr);
                }
        }
        else {
-               if (BTST(*(but->poin + 2), but->bitnr)) {
-                       *(but->poin + 2) = BCLR(*(but->poin + 2), but->bitnr);
-                       *(but->poin) = BCLR(*(but->poin), but->bitnr);
+               if (UI_BITBUT_TEST(*(but->poin + 2), but->bitnr)) {
+                       *(but->poin + 2) = UI_BITBUT_CLR(*(but->poin + 2), but->bitnr);
+                       *(but->poin)     = UI_BITBUT_CLR(*(but->poin),     but->bitnr);
                }
-               else if (BTST(*(but->poin), but->bitnr)) {
-                       *(but->poin + 2) = BSET(*(but->poin + 2), but->bitnr);
+               else if (UI_BITBUT_TEST(*(but->poin), but->bitnr)) {
+                       *(but->poin + 2) = UI_BITBUT_SET(*(but->poin + 2), but->bitnr);
                }
                else {
-                       *(but->poin) = BSET(*(but->poin), but->bitnr);
+                       *(but->poin) = UI_BITBUT_SET(*(but->poin), but->bitnr);
                }
        }
        
@@ -698,7 +698,7 @@ static int ui_but_mouse_inside_icon(uiBut *but, ARegion *ar, wmEvent *event)
                rect.xmax -= delta / 2;
        }
        
-       return BLI_in_rcti(&rect, x, y);
+       return BLI_rcti_isect_pt(&rect, x, y);
 }
 
 static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event)
@@ -838,6 +838,7 @@ static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to)
        /* (3) add a new controller */
        if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, NULL) & OPERATOR_FINISHED) {
                cont = (bController *)ob->controllers.last;
+               cont->type = CONT_LOGIC_AND; /* Quick fix to make sure we always have an AND controller. It might be nicer to make sure the operator gives us the right one though... */
 
                /* (4) link the sensor->controller->actuator */
                tmp_but = MEM_callocN(sizeof(uiBut), "uiBut");
@@ -1139,8 +1140,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
        static ColorBand but_copypaste_coba = {0};
        char buf[UI_MAX_DRAW_STR + 1] = {0};
 
-       if (mode == 'v' && but->lock)
+       if (mode == 'v' && but->lock  == TRUE) {
                return;
+       }
 
        if (mode == 'v') {
                /* extract first line from clipboard in case of multi-line copies */
@@ -1185,12 +1187,20 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                else if (mode == 'c') {
 
                        ui_get_but_vectorf(but, rgb);
+                       /* convert to linear color to do compatible copy between gamma and non-gamma */
+                       if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
+                               srgb_to_linearrgb_v3_v3(rgb, rgb);
+
                        BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
                        WM_clipboard_text_set(buf, 0);
                        
                }
                else {
                        if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) {
+                               /* assume linear colors in buffer */
+                               if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
+                                       linearrgb_to_srgb_v3_v3(rgb, rgb);
+
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
                                ui_set_but_vectorf(but, rgb);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -1781,8 +1791,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
                        retval = WM_UI_HANDLER_BREAK;
                        break;
-               case LEFTMOUSE: {
-                       
+               case LEFTMOUSE:
+               {
                        /* exit on LMB only on RELEASE for searchbox, to mimic other popups, and allow multiple menu levels */
                        if (data->searchbox)
                                inbox = ui_searchbox_inside(data->searchbox, event->x, event->y);
@@ -1948,7 +1958,8 @@ static void ui_do_but_textedit_select(bContext *C, uiBlock *block, uiBut *but, u
        int mx, my, retval = WM_UI_HANDLER_CONTINUE;
 
        switch (event->type) {
-               case MOUSEMOVE: {
+               case MOUSEMOVE:
+               {
                        mx = event->x;
                        my = event->y;
                        ui_window_to_block(data->region, block, &mx, &my);
@@ -2968,7 +2979,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                                 * Alt+MouseWheel over the render slots, without this,
                                 * the slot menu fails to switch a second time.
                                 *
-                                * Theactive state of the button could be maintained some other way
+                                * The active state of the button could be maintained some other way
                                 * and remove this mousemove event.
                                 */
                                WM_event_add_mousemove(C);
@@ -4241,8 +4252,8 @@ static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDa
                                scopes->marker = BKE_tracking_marker_ensure(scopes->track, scopes->framenr);
 
                        scopes->marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED);
-                       scopes->marker->pos[0] += -dx * scopes->slide_scale[0] / (but->block->rect.xmax - but->block->rect.xmin);
-                       scopes->marker->pos[1] += -dy * scopes->slide_scale[1] / (but->block->rect.ymax - but->block->rect.ymin);
+                       scopes->marker->pos[0] += -dx * scopes->slide_scale[0] / BLI_RCT_SIZE_X(&but->block->rect);
+                       scopes->marker->pos[1] += -dy * scopes->slide_scale[1] / BLI_RCT_SIZE_Y(&but->block->rect);
 
                        WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
                }
@@ -4792,7 +4803,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        /* verify if we can edit this button */
        if (ELEM(event->type, LEFTMOUSE, RETKEY)) {
                /* this should become disabled button .. */
-               if (but->lock) {
+               if (but->lock == TRUE) {
                        if (but->lockstr) {
                                BKE_report(NULL, RPT_WARNING, but->lockstr);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -4917,7 +4928,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
 
 static int ui_but_contains_pt(uiBut *but, int mx, int my)
 {
-       return BLI_in_rctf(&but->rect, mx, my);
+       return BLI_rctf_isect_pt(&but->rect, mx, my);
 }
 
 static uiBut *ui_but_find_activated(ARegion *ar)
@@ -4993,7 +5004,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
        uiBlock *block;
        
        /* check if the mouse is in the region */
-       if (!BLI_in_rcti(&ar->winrct, x, y)) {
+       if (!BLI_rcti_isect_pt(&ar->winrct, x, y)) {
                for (block = ar->uiblocks.first; block; block = block->next)
                        block->auto_open = FALSE;
                
@@ -5032,7 +5043,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
                }
                
                /* check if in the rect */
-               if (!BLI_in_rcti(&mask_rct, mx, my)) 
+               if (!BLI_rcti_isect_pt(&mask_rct, mx, my)) 
                        return 0;
        }
        
@@ -5085,7 +5096,7 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
                /* CLIP_EVENTS prevents the event from reaching other blocks */
                if (block->flag & UI_BLOCK_CLIP_EVENTS) {
                        /* check if mouse is inside block */
-                       if (BLI_in_rctf(&block->rect, mx, my)) {
+                       if (BLI_rctf_isect_pt(&block->rect, mx, my)) {
                                break;
                        }
                }
@@ -5694,7 +5705,8 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
                                }
 
                                break;
-                       case TIMER: {
+                       case TIMER:
+                       {
                                /* handle tooltip timer */
                                if (event->customdata == data->tooltiptimer) {
                                        WM_event_remove_timer(data->wm, data->window, data->tooltiptimer);
@@ -5771,9 +5783,11 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
        }
        else if (data->state == BUTTON_STATE_WAIT_FLASH) {
                switch (event->type) {
-                       case TIMER: {
-                               if (event->customdata == data->flashtimer)
+                       case TIMER:
+                       {
+                               if (event->customdata == data->flashtimer) {
                                        button_activate_state(C, but, BUTTON_STATE_EXIT);
+                               }
                        }
                }
 
@@ -5783,21 +5797,25 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
                /* check for exit because of mouse-over another button */
                switch (event->type) {
                        case MOUSEMOVE:
-                               
-                               if (data->menu && data->menu->region)
-                                       if (ui_mouse_inside_region(data->menu->region, event->x, event->y))
+                       {
+                               uiBut *bt;
+
+                               if (data->menu && data->menu->region) {
+                                       if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) {
                                                break;
-                       
-                               {
-                                       uiBut *bt = ui_but_find_mouse_over(ar, event->x, event->y);
+                                       }
+                               }
 
-                                       if (bt && bt->active != data) {
-                                               if (but->type != COL) /* exception */
-                                                       data->cancel = 1;
-                                               button_activate_state(C, but, BUTTON_STATE_EXIT);
+                               bt = ui_but_find_mouse_over(ar, event->x, event->y);
+
+                               if (bt && bt->active != data) {
+                                       if (but->type != COL) {  /* exception */
+                                               data->cancel = 1;
                                        }
-                                       break;
+                                       button_activate_state(C, but, BUTTON_STATE_EXIT);
                                }
+                               break;
+                       }
                }
 
                ui_do_button(C, block, but, event);
@@ -6099,7 +6117,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
        ui_window_to_block(ar, block, &mx, &my);
 
        /* check if mouse is inside block */
-       inside = BLI_in_rctf(&block->rect, mx, my);
+       inside = BLI_rctf_isect_pt(&block->rect, mx, my);
 
        /* if there's an active modal button, don't check events or outside, except for search menu */
        but = ui_but_find_activated(ar);
@@ -6348,7 +6366,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                uiSafetyRct *saferct = block->saferct.first;
 
                                if (ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) && event->val == KM_PRESS) {
-                                       if (saferct && !BLI_in_rctf(&saferct->parent, event->x, event->y)) {
+                                       if (saferct && !BLI_rctf_isect_pt(&saferct->parent, event->x, event->y)) {
                                                if (block->flag & (UI_BLOCK_OUT_1))
                                                        menu->menuretval = UI_RETURN_OK;
                                                else
@@ -6381,9 +6399,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                                 * events we check all preceding block rects too to make
                                                 * arrow keys navigation work */
                                                if (event->type != MOUSEMOVE || saferct == block->saferct.first) {
-                                                       if (BLI_in_rctf(&saferct->parent, (float)event->x, (float)event->y))
+                                                       if (BLI_rctf_isect_pt(&saferct->parent, (float)event->x, (float)event->y))
                                                                break;
-                                                       if (BLI_in_rctf(&saferct->safety, (float)event->x, (float)event->y))
+                                                       if (BLI_rctf_isect_pt(&saferct->safety, (float)event->x, (float)event->y))
                                                                break;
                                                }
                                        }