Merging r50470 through r50477 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index 90f8bb5..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);
                }
        }
        
@@ -686,20 +686,19 @@ static int ui_but_mouse_inside_icon(uiBut *but, ARegion *ar, wmEvent *event)
        
        ui_window_to_block(ar, but->block, &x, &y);
        
-       rect.xmin = but->x1; rect.xmax = but->x2;
-       rect.ymin = but->y1; rect.ymax = but->y2;
+       BLI_rcti_rctf_copy(&rect, &but->rect);
        
        if (but->imb) ;  /* use button size itself */
        else if (but->flag & UI_ICON_LEFT) {
-               rect.xmax = rect.xmin + (rect.ymax - rect.ymin);
+               rect.xmax = rect.xmin + (BLI_RCT_SIZE_Y(&rect));
        }
        else {
-               int delta = (rect.xmax - rect.xmin) - (rect.ymax - rect.ymin);
+               int delta = BLI_RCT_SIZE_X(&rect) - BLI_RCT_SIZE_Y(&rect);
                rect.xmin += delta / 2;
                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)
@@ -715,7 +714,7 @@ static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data,
                
                drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but));
                if (but->imb)
-                       WM_event_drag_image(drag, but->imb, but->imb_scale, but->x2 - but->x1, but->y2 - but->y1);
+                       WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_RCT_SIZE_X(&but->rect), BLI_RCT_SIZE_Y(&but->rect));
                return 1;
        }
        
@@ -839,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");
@@ -1140,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 */
@@ -1186,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);
@@ -1282,7 +1291,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
 {
        uiStyle *style = UI_GetStyle();  // XXX pass on as arg
        uiFontStyle *fstyle = &style->widget;
-       int startx = but->x1;
+       int startx = but->rect.xmin;
        char *origstr;
 
        uiStyleFontSet(fstyle);
@@ -1296,7 +1305,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
        
        /* XXX solve generic */
        if (but->type == NUM || but->type == NUMSLI)
-               startx += (int)(0.5f * (but->y2 - but->y1));
+               startx += (int)(0.5f * (BLI_RCT_SIZE_Y(&but->rect)));
        else if (ELEM(but->type, TEX, SEARCH_MENU)) {
                startx += 5;
                if (but->flag & UI_HAS_ICON)
@@ -1782,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);
@@ -1949,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);
@@ -2537,11 +2547,11 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                /* XXX hardcoded keymap check.... */
                if (event->type == WHEELDOWNMOUSE && event->alt) {
-                       mx = but->x1;
+                       mx = but->rect.xmin;
                        click = 1;
                }
                else if (event->type == WHEELUPMOUSE && event->alt) {
-                       mx = but->x2;
+                       mx = but->rect.xmax;
                        click = 1;
                }
                else if (event->val == KM_PRESS) {
@@ -2611,7 +2621,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                softmax = but->softmax;
 
                if (!ui_is_but_float(but)) {
-                       if (mx < (but->x1 + (but->x2 - but->x1) / 3 - 3)) {
+                       if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                temp = (int)data->value - 1;
@@ -2622,7 +2632,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
-                       else if (mx > (but->x1 + (2 * (but->x2 - but->x1) / 3) + 3)) {
+                       else if (mx > (but->rect.xmin + (2 * BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                temp = (int)data->value + 1;
@@ -2637,7 +2647,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                                button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
                }
                else {
-                       if (mx < (but->x1 + (but->x2 - but->x1) / 3 - 3)) {
+                       if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                tempf = (float)data->value - 0.01f * but->a1;
@@ -2646,7 +2656,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
-                       else if (mx > but->x1 + (2 * ((but->x2 - but->x1) / 3) + 3)) {
+                       else if (mx > but->rect.xmin + (2 * (BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                tempf = (float)data->value + 0.01f * but->a1;
@@ -2674,14 +2684,14 @@ static int ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, const short
        softmax = but->softmax;
        softrange = softmax - softmin;
 
-       if (but->type == NUMSLI) deler = ((but->x2 - but->x1) - 5.0f * but->aspect);
-       else if (but->type == HSVSLI) deler = ((but->x2 - but->x1) / 2.0f - 5.0f * but->aspect);
+       if (but->type == NUMSLI) deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
+       else if (but->type == HSVSLI) deler = (BLI_RCT_SIZE_X(&but->rect) / 2.0f - 5.0f * but->aspect);
        else if (but->type == SCROLL) {
-               int horizontal = (but->x2 - but->x1 > but->y2 - but->y1);
-               float size = (horizontal) ? (but->x2 - but->x1) : -(but->y2 - but->y1);
+               int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
+               float size = (horizontal) ? BLI_RCT_SIZE_X(&but->rect) : -BLI_RCT_SIZE_Y(&but->rect);
                deler = size * (but->softmax - but->softmin) / (but->softmax - but->softmin + but->a1);
        }
-       else deler = (but->x2 - but->x1 - 5.0f * but->aspect);
+       else deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
 
        f = (float)(mx - data->dragstartx) / deler + data->dragfstart;
        
@@ -2750,11 +2760,11 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                /* XXX hardcoded keymap check.... */
                if (event->type == WHEELDOWNMOUSE && event->alt) {
-                       mx = but->x1;
+                       mx = but->rect.xmin;
                        click = 2;
                }
                else if (event->type == WHEELUPMOUSE && event->alt) {
-                       mx = but->x2;
+                       mx = but->rect.xmax;
                        click = 2;
                }
                else if (event->val == KM_PRESS) {
@@ -2764,12 +2774,12 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                        }
                        /* alt-click on sides to get "arrows" like in NUM buttons, and match wheel usage above */
                        else if (event->type == LEFTMOUSE && event->alt) {
-                               int halfpos = (but->x1 + but->x2) / 2;
+                               int halfpos = BLI_RCT_CENTER_X(&but->rect);
                                click = 2;
                                if (mx < halfpos)
-                                       mx = but->x1;
+                                       mx = but->rect.xmin;
                                else
-                                       mx = but->x2;
+                                       mx = but->rect.xmax;
                        }
                        else if (event->type == LEFTMOUSE) {
                                data->dragstartx = mx;
@@ -2831,12 +2841,12 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
 #if 0
                        if (but->type == SLI) {
-                               f = (float)(mx - but->x1) / (but->x2 - but->x1); /* same as below */
+                               f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect)); /* same as below */
                        }
                        else
 #endif
                        {
-                               f = (float)(mx - but->x1) / (but->x2 - but->x1);
+                               f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect));
                        }
                        
                        f = softmin + f * softrange;
@@ -2877,7 +2887,7 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
 {
        int mx, my /*, click= 0 */;
        int retval = WM_UI_HANDLER_CONTINUE;
-       int horizontal = (but->x2 - but->x1 > but->y2 - but->y1);
+       int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
        
        mx = event->x;
        my = event->y;
@@ -2946,9 +2956,11 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                        return WM_UI_HANDLER_BREAK;
                }
                else if (ELEM3(but->type, MENU, ICONROW, ICONTEXTROW)) {
-                       
-                       if (event->type == WHEELDOWNMOUSE && event->alt) {
-                               data->value = ui_step_name_menu(but, -1);
+                       if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
+                               const int direction = (event->type == WHEELDOWNMOUSE) ? -1 : 1;
+
+                               data->value = ui_step_name_menu(but, direction);
+
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                                ui_apply_button(C, but->block, but, data, 1);
 
@@ -2962,16 +2974,15 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                                data->postbut = but;
                                data->posttype = BUTTON_ACTIVATE_OVER;
 
-                               return WM_UI_HANDLER_BREAK;
-                       }
-                       else if (event->type == WHEELUPMOUSE && event->alt) {
-                               data->value = ui_step_name_menu(but, 1);
-                               button_activate_state(C, but, BUTTON_STATE_EXIT);
-                               ui_apply_button(C, but->block, but, data, 1);
-
-                               /* why this is needed described above */
-                               data->postbut = but;
-                               data->posttype = BUTTON_ACTIVATE_OVER;
+                               /* without this, a new interface that draws as result of the menu change
+                                * won't register that the mouse is over it, eg:
+                                * Alt+MouseWheel over the render slots, without this,
+                                * the slot menu fails to switch a second time.
+                                *
+                                * The active state of the button could be maintained some other way
+                                * and remove this mousemove event.
+                                */
+                               WM_event_add_mousemove(C);
 
                                return WM_UI_HANDLER_BREAK;
                        }
@@ -3034,7 +3045,7 @@ static int ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data, int mx, i
         * else we'll get a harmless but annoying jump when first clicking */
 
        fp = data->origvec;
-       rad = (but->x2 - but->x1);
+       rad = BLI_RCT_SIZE_X(&but->rect);
        radsq = rad * rad;
        
        if (fp[2] > 0.0f) {
@@ -3142,8 +3153,8 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
 
 
        /* relative position within box */
-       x = ((float)mx_fl - but->x1) / (but->x2 - but->x1);
-       y = ((float)my_fl - but->y1) / (but->y2 - but->y1);
+       x = ((float)mx_fl - but->rect.xmin) / BLI_RCT_SIZE_X(&but->rect);
+       y = ((float)my_fl - but->rect.ymin) / BLI_RCT_SIZE_Y(&but->rect);
        CLAMP(x, 0.0f, 1.0f);
        CLAMP(y, 0.0f, 1.0f);
 
@@ -3348,9 +3359,8 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, float
        
        ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
 
-       rect.xmin = but->x1; rect.xmax = but->x2;
-       rect.ymin = but->y1; rect.ymax = but->y2;
-       
+       BLI_rcti_rctf_copy(&rect, &but->rect);
+
        ui_get_but_vectorf(but, rgb);
        copy_v3_v3(hsv, ui_block_hsv_get(but->block));
        rgb_to_hsv_compat_v(rgb, hsv);
@@ -3541,7 +3551,7 @@ static int ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx
        if (data->draglastx == mx)
                return changed;
 
-       dx = ((float)(mx - data->draglastx)) / (but->x2 - but->x1);
+       dx = ((float)(mx - data->draglastx)) / BLI_RCT_SIZE_X(&but->rect);
        data->dragcbd->pos += dx;
        CLAMP(data->dragcbd->pos, 0.0f, 1.0f);
        
@@ -3570,7 +3580,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
 
                        if (event->ctrl) {
                                /* insert new key on mouse location */
-                               float pos = ((float)(mx - but->x1)) / (but->x2 - but->x1);
+                               float pos = ((float)(mx - but->rect.xmin)) / BLI_RCT_SIZE_X(&but->rect);
                                colorband_element_add(coba, pos);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
@@ -3582,7 +3592,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
 
                                /* activate new key when mouse is close */
                                for (a = 0, cbd = coba->data; a < coba->tot; a++, cbd++) {
-                                       xco = but->x1 + (cbd->pos * (but->x2 - but->x1));
+                                       xco = but->rect.xmin + (cbd->pos * BLI_RCT_SIZE_X(&but->rect));
                                        xco = ABS(xco - mx);
                                        if (a == coba->cur) xco += 5;  // selected one disadvantage
                                        if (xco < mindist) {
@@ -3623,8 +3633,8 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
        float fx, fy, zoomx, zoomy /*, offsx, offsy */ /* UNUSED */;
        int a, changed = 0;
 
-       zoomx = (but->x2 - but->x1) / (cumap->curr.xmax - cumap->curr.xmin);
-       zoomy = (but->y2 - but->y1) / (cumap->curr.ymax - cumap->curr.ymin);
+       zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+       zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
        /* offsx= cumap->curr.xmin; */
        /* offsy= cumap->curr.ymin; */
 
@@ -3649,7 +3659,7 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
                fy *= mval_factor;
 
                for (a = 0; a < cuma->totpoint; a++) {
-                       if (cmp[a].flag & SELECT) {
+                       if (cmp[a].flag & CUMA_SELECT) {
                                float origx = cmp[a].x, origy = cmp[a].y;
                                cmp[a].x += fx;
                                cmp[a].y += fy;
@@ -3662,7 +3672,7 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
                        }
                }
 
-               curvemapping_changed(cumap, 0); /* no remove doubles */
+               curvemapping_changed(cumap, FALSE);
                
                if (moved_point) {
                        data->draglastx = mx;
@@ -3719,25 +3729,25 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                        float dist, mindist = 200.0f; // 14 pixels radius
                        int sel = -1;
 
-                       zoomx = (but->x2 - but->x1) / (cumap->curr.xmax - cumap->curr.xmin);
-                       zoomy = (but->y2 - but->y1) / (cumap->curr.ymax - cumap->curr.ymin);
+                       zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+                       zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
                        offsx = cumap->curr.xmin;
                        offsy = cumap->curr.ymin;
 
                        if (event->ctrl) {
-                               fx = ((float)mx - but->x1) / zoomx + offsx;
-                               fy = ((float)my - but->y1) / zoomy + offsy;
+                               fx = ((float)mx - but->rect.xmin) / zoomx + offsx;
+                               fy = ((float)my - but->rect.ymin) / zoomy + offsy;
                                
                                curvemap_insert(cuma, fx, fy);
-                               curvemapping_changed(cumap, 0);
+                               curvemapping_changed(cumap, FALSE);
                                changed = 1;
                        }
 
                        /* check for selecting of a point */
                        cmp = cuma->curve;   /* ctrl adds point, new malloc */
                        for (a = 0; a < cuma->totpoint; a++) {
-                               fx = but->x1 + zoomx * (cmp[a].x - offsx);
-                               fy = but->y1 + zoomy * (cmp[a].y - offsy);
+                               fx = but->rect.xmin + zoomx * (cmp[a].x - offsx);
+                               fy = but->rect.ymin + zoomy * (cmp[a].y - offsy);
                                dist = (fx - mx) * (fx - mx) + (fy - my) * (fy - my);
                                if (dist < mindist) {
                                        sel = a;
@@ -3750,20 +3760,20 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
 
                                /* if the click didn't select anything, check if it's clicked on the 
                                 * curve itself, and if so, add a point */
-                               fx = ((float)mx - but->x1) / zoomx + offsx;
-                               fy = ((float)my - but->y1) / zoomy + offsy;
+                               fx = ((float)mx - but->rect.xmin) / zoomx + offsx;
+                               fy = ((float)my - but->rect.ymin) / zoomy + offsy;
                                
                                cmp = cuma->table;
 
                                /* loop through the curve segment table and find what's near the mouse.
                                 * 0.05 is kinda arbitrary, but seems to be what works nicely. */
                                for (i = 0; i <= CM_TABLE; i++) {
-                                       if ( (fabsf(fx - cmp[i].x) < 0.05f) &&
-                                            (fabsf(fy - cmp[i].y) < 0.05f))
+                                       if ((fabsf(fx - cmp[i].x) < 0.05f) &&
+                                           (fabsf(fy - cmp[i].y) < 0.05f))
                                        {
                                        
                                                curvemap_insert(cuma, fx, fy);
-                                               curvemapping_changed(cumap, 0);
+                                               curvemapping_changed(cumap, FALSE);
 
                                                changed = 1;
                                                
@@ -3785,11 +3795,11 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                /* deselect all if this one is deselect. except if we hold shift */
                                if (event->shift == FALSE) {
                                        for (a = 0; a < cuma->totpoint; a++)
-                                               cmp[a].flag &= ~SELECT;
-                                       cmp[sel].flag |= SELECT;
+                                               cmp[a].flag &= ~CUMA_SELECT;
+                                       cmp[sel].flag |= CUMA_SELECT;
                                }
                                else
-                                       cmp[sel].flag ^= SELECT;
+                                       cmp[sel].flag ^= CUMA_SELECT;
                        }
                        else {
                                /* move the view */
@@ -3824,12 +3834,13 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                        /* deselect all, select one */
                                        if (event->shift == FALSE) {
                                                for (a = 0; a < cuma->totpoint; a++)
-                                                       cmp[a].flag &= ~SELECT;
-                                               cmp[data->dragsel].flag |= SELECT;
+                                                       cmp[a].flag &= ~CUMA_SELECT;
+                                               cmp[data->dragsel].flag |= CUMA_SELECT;
                                        }
                                }
-                               else
-                                       curvemapping_changed(cumap, 1);  /* remove doubles */
+                               else {
+                                       curvemapping_changed(cumap, TRUE);  /* remove doubles */
+                               }
                        }
 
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -3846,8 +3857,8 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
 
 static int in_scope_resize_zone(uiBut *but, int UNUSED(x), int y)
 {
-       /* bottom corner return (x > but->x2 - SCOPE_RESIZE_PAD) && (y < but->y1 + SCOPE_RESIZE_PAD); */
-       return (y < but->y1 + SCOPE_RESIZE_PAD);
+       /* bottom corner return (x > but->rect.xmax - SCOPE_RESIZE_PAD) && (y < but->rect.ymin + SCOPE_RESIZE_PAD); */
+       return (y < but->rect.ymin + SCOPE_RESIZE_PAD);
 }
 
 static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx, int my)
@@ -3857,15 +3868,14 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
        int changed = 1;
        float /* dx, */ dy; /* UNUSED */
        
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
        
        /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize histogram widget itself */
-               hist->height = (but->y2 - but->y1) + (data->dragstarty - my);
+               hist->height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
                /* scale histogram values (dy / 10 for better control) */
@@ -3941,8 +3951,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
        int changed = 1;
        float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */
 
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
 
        /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
@@ -3950,7 +3959,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize waveform widget itself */
-               scopes->wavefrm_height = (but->y2 - but->y1) + (data->dragstarty - my);
+               scopes->wavefrm_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
                /* scale waveform values */
@@ -4025,15 +4034,14 @@ static int ui_numedit_but_VECTORSCOPE(uiBut *but, uiHandleButtonData *data, int
        int changed = 1;
        /* float dx, dy; */
 
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
 
        /* dx = mx - data->draglastx; */
        /* dy = my - data->draglasty; */
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize vectorscope widget itself */
-               scopes->vecscope_height = (but->y2 - but->y1) + (data->dragstarty - my);
+               scopes->vecscope_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
 
        data->draglastx = mx;
@@ -4103,17 +4111,17 @@ static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                if (ELEM3(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) {
                        /* Calculate the size of the button */
-                       width = abs(but->x2 - but->x1);
-                       height = abs(but->y2 - but->y1);
+                       width  = abs(BLI_RCT_SIZE_X(&but->rect));
+                       height = abs(BLI_RCT_SIZE_Y(&but->rect));
 
                        butw = floor(width / 12);
                        buth = floor(height / 6);
 
                        /* Initialize variables */
-                       sx = but->x1;
-                       ex = but->x1 + butw;
-                       sy = but->y1 + height - buth;
-                       ey = but->y1 + height;
+                       sx = but->rect.xmin;
+                       ex = but->rect.xmin + butw;
+                       sy = but->rect.ymin + height - buth;
+                       ey = but->rect.ymin + height;
 
                        cs = G.charstart;
 
@@ -4236,7 +4244,7 @@ static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDa
 
        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);
+               scopes->track_preview_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
                if (!scopes->track_locked) {
@@ -4244,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->maxx - but->block->minx);
-                       scopes->marker->pos[1] += -dy * scopes->slide_scale[1] / (but->block->maxy - but->block->miny);
+                       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);
                }
@@ -4712,7 +4720,6 @@ static int ui_but_menu(bContext *C, uiBut *but)
 
 static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
 {
-//     Scene *scene= CTX_data_scene(C);
        uiHandleButtonData *data;
        int retval;
 
@@ -4796,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);
@@ -4879,7 +4886,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
                        retval = ui_do_but_BUT(C, but, data, event);
                        break;
                case COL:
-                       if (but->a1 == UI_GRAD_V_ALT) // signal to prevent calling up color picker
+                       if (but->a1 == UI_GRAD_V_ALT)  /* signal to prevent calling up color picker */
                                retval = ui_do_but_EXIT(C, but, data, event);
                        else
                                retval = ui_do_but_BLOCK(C, but, data, event);
@@ -4921,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 ((but->x1 < mx && but->x2 >= mx) && (but->y1 < my && but->y2 >= my));
+       return BLI_rctf_isect_pt(&but->rect, mx, my);
 }
 
 static uiBut *ui_but_find_activated(ARegion *ar)
@@ -4997,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;
                
@@ -5020,10 +5027,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
                ui_window_to_region(ar, &mx, &my);
                
                /* make a copy of the mask rect, and tweak accordingly for hidden scrollbars */
-               mask_rct.xmin = v2d->mask.xmin;
-               mask_rct.xmax = v2d->mask.xmax;
-               mask_rct.ymin = v2d->mask.ymin;
-               mask_rct.ymax = v2d->mask.ymax;
+               mask_rct = v2d->mask;
                
                if (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR)) {
                        if (v2d->scroll & V2D_SCROLL_LEFT)
@@ -5039,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;
        }
        
@@ -5092,9 +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 (block->minx <= mx && block->maxx >= mx &&
-                           block->miny <= my && block->maxy >= my)
-                       {
+                       if (BLI_rctf_isect_pt(&block->rect, mx, my)) {
                                break;
                        }
                }
@@ -5290,8 +5292,13 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
        data->wm = CTX_wm_manager(C);
        data->window = CTX_wm_window(C);
        data->region = ar;
-       if (ELEM(but->type, BUT_CURVE, SEARCH_MENU) ) ;  // XXX curve is temp
-       else data->interactive = 1;
+
+       if (ELEM(but->type, BUT_CURVE, SEARCH_MENU)) {
+               /* XXX curve is temp */
+       }
+       else {
+               data->interactive = 1;
+       }
        
        data->state = BUTTON_STATE_INIT;
 
@@ -5698,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);
@@ -5775,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);
+                               }
                        }
                }
 
@@ -5787,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);
@@ -5979,17 +5993,17 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men
        /* verify that we are moving towards one of the edges of the
         * menu block, in other words, in the triangle formed by the
         * initial mouse location and two edge points. */
-       p1[0] = block->minx - 20;
-       p1[1] = block->miny - 20;
+       p1[0] = block->rect.xmin - 20;
+       p1[1] = block->rect.ymin - 20;
 
-       p2[0] = block->maxx + 20;
-       p2[1] = block->miny - 20;
+       p2[0] = block->rect.xmax + 20;
+       p2[1] = block->rect.ymin - 20;
        
-       p3[0] = block->maxx + 20;
-       p3[1] = block->maxy + 20;
+       p3[0] = block->rect.xmax + 20;
+       p3[1] = block->rect.ymax + 20;
 
-       p4[0] = block->minx - 20;
-       p4[1] = block->maxy + 20;
+       p4[0] = block->rect.xmin - 20;
+       p4[1] = block->rect.ymax + 20;
 
        oldp[0] = menu->towardsx;
        oldp[1] = menu->towardsy;
@@ -6019,10 +6033,10 @@ static char ui_menu_scroll_test(uiBlock *block, int my)
 {
        if (block->flag & (UI_BLOCK_CLIPTOP | UI_BLOCK_CLIPBOTTOM)) {
                if (block->flag & UI_BLOCK_CLIPTOP) 
-                       if (my > block->maxy - 14)
+                       if (my > block->rect.ymax - 14)
                                return 't';
                if (block->flag & UI_BLOCK_CLIPBOTTOM)
-                       if (my < block->miny + 14)
+                       if (my < block->rect.ymin + 14)
                                return 'b';
        }
        return 0;
@@ -6053,25 +6067,25 @@ static int ui_menu_scroll(ARegion *ar, uiBlock *block, int my)
                
                if (test == 't') {
                        /* bottom button is first button */
-                       if (b1->y1 < b2->y1)
-                               dy = bnext->y1 - b1->y1;
+                       if (b1->rect.ymin < b2->rect.ymin)
+                               dy = bnext->rect.ymin - b1->rect.ymin;
                        /* bottom button is last button */
                        else 
-                               dy = bprev->y1 - b2->y1;
+                               dy = bprev->rect.ymin - b2->rect.ymin;
                }
                else if (test == 'b') {
                        /* bottom button is first button */
-                       if (b1->y1 < b2->y1)
-                               dy = b1->y1 - bnext->y1;
+                       if (b1->rect.ymin < b2->rect.ymin)
+                               dy = b1->rect.ymin - bnext->rect.ymin;
                        /* bottom button is last button */
                        else 
-                               dy = b2->y1 - bprev->y1;
+                               dy = b2->rect.ymin - bprev->rect.ymin;
                }
                if (dy) {
                        
                        for (b1 = block->buttons.first; b1; b1 = b1->next) {
-                               b1->y1 -= dy;
-                               b1->y2 -= dy;
+                               b1->rect.ymin -= dy;
+                               b1->rect.ymax -= dy;
                        }
                        /* set flags again */
                        ui_popup_block_scrolltest(block);
@@ -6103,10 +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 = 0;
-       if (block->minx <= mx && block->maxx >= mx)
-               if (block->miny <= my && block->maxy >= my)
-                       inside = 1;
+       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);
@@ -6355,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
@@ -6388,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;
                                                }
                                        }