Partly apply patch [#23746] Clarify azone->edge values.
authorNathan Letwory <nathan@letworyinteractive.com>
Mon, 20 Sep 2010 13:13:40 +0000 (13:13 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Mon, 20 Sep 2010 13:13:40 +0000 (13:13 +0000)
Submitted by Shane Ambler.

The original patches made an enum for action zone edges, changed positioning for minimised icons and repositioned minimised icon for operator properties panel.

I kept the enum idea, but further improved on the naming. Some switches used in place of if/else blocks and added some comments. See patch tracker for more comments.

source/blender/editors/include/ED_screen_types.h
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c

index c55dafa..c5abd54 100644 (file)
@@ -68,13 +68,21 @@ typedef struct ScreenFrameRateInfo {
 
 /* ----------------------------------------------------- */
 
+/* Enum for Action Zone Edges. Which edge of area is action zone. */
+typedef enum {
+       AE_RIGHT_TO_TOPLEFT,    /* Region located on the left, _right_ edge is action zone. Region minimised to the top left */
+       AE_LEFT_TO_TOPRIGHT,    /* Region located on the right, _left_ edge is action zone. Region minimised to the top right */
+       AE_TOP_TO_BOTTOMRIGHT,          /* Region located at the bottom, _top_ edge is action zone. Region minimised to the bottom right */
+       AE_BOTTOM_TO_TOPLEFT    /* Region located at the top, _bottom_edge is action zone. Region minimised to the top left */
+} AZEdge;
+
 /* for editing areas/regions */
 typedef struct AZone {
        struct AZone *next, *prev;
        ARegion *ar;
        int type;
        /* region-azone, which of the edges */
-       short edge;
+       AZEdge edge;
        /* internal */
        short do_draw;
        /* for draw */
index 07d1e47..d0361c5 100644 (file)
@@ -469,29 +469,31 @@ static void area_azone_initialize(ScrArea *sa)
 #define AZONEPAD_ICON  8
 static void region_azone_edge(AZone *az, ARegion *ar)
 {
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymax;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymin;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymin;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
        }
 
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
@@ -502,33 +504,38 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
        AZone *azt;
        int tot=0;
        
+       /* count how many actionzones with along same edge are available.
+          This allows for adding more action zones in the future without
+          having to worry about correct offset */
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
                if(azt->edge == az->edge) tot++;
        }
        
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmax - tot*2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax + AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax - tot*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax + 2*AZONEPAD_ICON;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymin - 2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymin - AZONEPAD_ICON;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin - 2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin - AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       az->x1= ar->winrct.xmax - tot*2*AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax + AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmax - tot*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax + 2*AZONEPAD_ICON;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin + AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymin - 2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmin + 2*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymin - AZONEPAD_ICON;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin - 2*AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmin - AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax + AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmax + 2*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+                       break;
        }
 
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
@@ -537,22 +544,21 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
                if(az!=azt) {
                        if( ABS(az->x1-azt->x1) < 2 && ABS(az->y1-azt->y1) < 2) {
-                               if(az->edge=='t' || az->edge=='b') {
+                               if(az->edge==AE_TOP_TO_BOTTOMRIGHT || az->edge==AE_BOTTOM_TO_TOPLEFT) {
                                        az->x1+= AZONESPOT;
                                        az->x2+= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                                }
-                               else {
+                               else{
                                        az->y1-= AZONESPOT;
                                        az->y2-= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                                }
+                               BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                        }
                }
        }
 }
 
-static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge) 
+static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge) 
 {
        AZone *az;
        
@@ -575,17 +581,16 @@ static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge)
 
 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
 {
-        /* edge code (t b l r) is where azone will be drawn */
+        /* edge code (t b l r) is along which area edge azone will be drawn */
        
        if(alignment==RGN_ALIGN_TOP)
-               region_azone_initialize(sa, ar, 'b');
+               region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT);
        else if(alignment==RGN_ALIGN_BOTTOM)
-               region_azone_initialize(sa, ar, 't');
+               region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
-               region_azone_initialize(sa, ar, 'l');
+               region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
-               region_azone_initialize(sa, ar, 'r');
-                                                               
+               region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT);
 }
 
 /* dir is direction to check, not the splitting edge direction! */
index eb70eef..05b6e07 100644 (file)
@@ -1162,7 +1162,7 @@ static void screen_cursor_set(wmWindow *win, wmEvent *event)
                if(az->type==AZONE_AREA)
                        WM_cursor_set(win, CURSOR_EDIT);
                else if(az->type==AZONE_REGION) {
-                       if(az->edge == 'l' || az->edge == 'r')
+                       if(az->edge == AE_LEFT_TO_TOPRIGHT || az->edge == AE_RIGHT_TO_TOPLEFT)
                                WM_cursor_set(win, CURSOR_X_MOVE);
                        else
                                WM_cursor_set(win, CURSOR_Y_MOVE);
index 0c92d6b..363e8a2 100644 (file)
@@ -1291,19 +1291,19 @@ typedef struct RegionMoveData {
        int bigger, smaller, origval;
        int origx, origy;
        int maxsize;
-       char edge;
+       AZEdge edge;
        
 } RegionMoveData;
 
 
-static int area_max_regionsize(ScrArea *sa, ARegion *scalear, char edge)
+static int area_max_regionsize(ScrArea *sa, ARegion *scalear, AZEdge edge)
 {
        ARegion *ar;
        int dist;
        
-       if(edge=='l' || edge=='r') {
+       if(edge==AE_RIGHT_TO_TOPLEFT || edge==AE_LEFT_TO_TOPRIGHT) {
                dist = sa->totrct.xmax - sa->totrct.xmin;
-       } else {        /* t, b */
+       } else {        /* AE_BOTTOM_TO_TOPLEFT, AE_TOP_TO_BOTTOMRIGHT */
                dist = sa->totrct.ymax - sa->totrct.ymin;
        }
        
@@ -1325,9 +1325,9 @@ static int area_max_regionsize(ScrArea *sa, ARegion *scalear, char edge)
                
                /* case of regions in regions, like operator properties panel */
                /* these can sit on top of other regions such as headers, so account for this */
-               else if (edge == 'b' && scalear->alignment & RGN_ALIGN_TOP && ar->alignment == RGN_ALIGN_TOP && ar->regiontype == RGN_TYPE_HEADER)
+               else if (edge == AE_BOTTOM_TO_TOPLEFT && scalear->alignment & RGN_ALIGN_TOP && ar->alignment == RGN_ALIGN_TOP && ar->regiontype == RGN_TYPE_HEADER)
                        dist -= ar->winy;
-               else if (edge == 't' && scalear->alignment & RGN_ALIGN_BOTTOM && ar->alignment == RGN_ALIGN_BOTTOM && ar->regiontype == RGN_TYPE_HEADER)
+               else if (edge == AE_TOP_TO_BOTTOMRIGHT && scalear->alignment & RGN_ALIGN_BOTTOM && ar->alignment == RGN_ALIGN_BOTTOM && ar->regiontype == RGN_TYPE_HEADER)
                        dist -= ar->winy;
        }
 
@@ -1367,7 +1367,7 @@ static int region_scale_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        rmd->ar->sizey= rmd->ar->type->prefsizey;
                
                /* now copy to regionmovedata */
-               if(rmd->edge=='l' || rmd->edge=='r') {
+               if(rmd->edge==AE_LEFT_TO_TOPRIGHT || rmd->edge==AE_RIGHT_TO_TOPLEFT) {
                        rmd->origval= rmd->ar->sizex;
                } else {
                        rmd->origval= rmd->ar->sizey;
@@ -1399,9 +1399,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, wmEvent *event)
        switch(event->type) {
                case MOUSEMOVE:
                        
-                       if(rmd->edge=='l' || rmd->edge=='r') {
+                       if(rmd->edge==AE_LEFT_TO_TOPRIGHT || rmd->edge==AE_RIGHT_TO_TOPLEFT) {
                                delta= event->x - rmd->origx;
-                               if(rmd->edge=='l') delta= -delta;
+                               if(rmd->edge==AE_LEFT_TO_TOPRIGHT) delta= -delta;
                                
                                rmd->ar->sizex= rmd->origval + delta;
                                CLAMP(rmd->ar->sizex, 0, rmd->maxsize);
@@ -1417,7 +1417,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, wmEvent *event)
                        else {
                                int maxsize=0;
                                delta= event->y - rmd->origy;
-                               if(rmd->edge=='b') delta= -delta;
+                               if(rmd->edge==AE_BOTTOM_TO_TOPLEFT) delta= -delta;
                                
                                rmd->ar->sizey= rmd->origval + delta;
                                CLAMP(rmd->ar->sizey, 0, rmd->maxsize);