Merging r50470 through r50477 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index ca52daa..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);
                }
        }
        
@@ -1187,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);
@@ -1783,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);
@@ -1950,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);
@@ -5696,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);
@@ -5773,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);
+                               }
                        }
                }
 
@@ -5785,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);