style cleanup: spaces -> tabs
[blender.git] / source / blender / editors / interface / interface_panel.c
index 5b6a609e4d21b20525c3c613eebfff075774fe47..1b2034d6e4058db23f50fc6e1f7e4ad69d788ae9 100644 (file)
@@ -112,7 +112,7 @@ static int panel_aligned(ScrArea *sa, ARegion *ar)
        else if (sa->spacetype == SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS)
                return BUT_VERTICAL;
        else if (sa->spacetype == SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW)
-               return BUT_VERTICAL; 
+               return BUT_VERTICAL;
        else if (ELEM3(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS))
                return BUT_VERTICAL;
        
@@ -247,6 +247,14 @@ Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, int
                }
        }
 
+       /* Do not allow closed panels without headers! Else user could get "disappeared" UI! */
+       if ((pt->flag & PNL_NO_HEADER) && (pa->flag & PNL_CLOSED)) {
+               pa->flag &= ~PNL_CLOSED;
+               /* Force update of panels' positions! */
+               pa->sizex = 0;
+               pa->sizey = 0;
+       }
+
        BLI_strncpy(pa->drawname, drawname, UI_MAX_NAME_STR);
 
        /* if a new panel is added, we insert it right after the panel
@@ -522,11 +530,9 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, rcti *rect)
                float y = headrect.ymax;
 
                glEnable(GL_BLEND);
-
                
                if (UI_GetThemeValue(TH_PANEL_SHOW_HEADER)) {
                        /* draw with background color */
-                       glEnable(GL_BLEND);
                        UI_ThemeColor4(TH_PANEL_HEADER);
                        glRectf(minx, headrect.ymin + 1, maxx, y);
 
@@ -542,7 +548,6 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, rcti *rect)
                        fdrawline(minx, y, maxx, y);
                        glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
                        fdrawline(minx, y - 1, maxx, y - 1);
-                       glDisable(GL_BLEND);
                }
 
                glDisable(GL_BLEND);
@@ -812,8 +817,8 @@ static void ui_panels_size(ScrArea *sa, ARegion *ar, int *x, int *y)
 {
        Panel *pa;
        int align = panel_aligned(sa, ar);
-       int sizex = UI_PANEL_WIDTH;
-       int sizey = UI_PANEL_WIDTH;
+       int sizex = 0;
+       int sizey = 0;
 
        /* compute size taken up by panels, for setting in view2d */
        for (pa = ar->panels.first; pa; pa = pa->next) {
@@ -834,6 +839,11 @@ static void ui_panels_size(ScrArea *sa, ARegion *ar, int *x, int *y)
                }
        }
 
+       if (sizex == 0)
+               sizex = UI_PANEL_WIDTH;
+       if (sizey == 0)
+               sizey = -UI_PANEL_WIDTH;
+       
        *x = sizex;
        *y = sizey;
 }
@@ -865,7 +875,7 @@ static void ui_do_animate(const bContext *C, Panel *panel)
 void uiBeginPanels(const bContext *UNUSED(C), ARegion *ar)
 {
        Panel *pa;
-  
+
        /* set all panels as inactive, so that at the end we know
         * which ones were used */
        for (pa = ar->panels.first; pa; pa = pa->next) {
@@ -956,6 +966,25 @@ void uiDrawPanels(const bContext *C, ARegion *ar)
        }
 }
 
+void uiScalePanels(ARegion *ar, float new_width)
+{
+       uiBlock *block;
+       uiBut *but;
+       
+       for (block = ar->uiblocks.first; block; block = block->next) {
+               if (block->panel) {
+                       float fac = new_width / (float)block->panel->sizex;
+                       printf("scaled %f\n", fac);
+                       block->panel->sizex = new_width;
+                       
+                       for (but = block->buttons.first; but; but = but->next) {
+                               but->rect.xmin *= fac;
+                               but->rect.xmax *= fac;
+                       }
+               }
+       }
+}
+
 /* ------------ panel merging ---------------- */
 
 static void check_panel_overlap(ARegion *ar, Panel *panel)
@@ -987,7 +1016,7 @@ static void check_panel_overlap(ARegion *ar, Panel *panel)
 
 /************************ panel dragging ****************************/
 
-static void ui_do_drag(const bContext *C, wmEvent *event, Panel *panel)
+static void ui_do_drag(const bContext *C, const wmEvent *event, Panel *panel)
 {
        uiHandlePanelData *data = panel->activedata;
        ScrArea *sa = CTX_wm_area(C);
@@ -1105,7 +1134,7 @@ static void ui_handle_panel_header(const bContext *C, uiBlock *block, int mx, in
 /* XXX should become modal keymap */
 /* AKey is opening/closing panels, independent of button state now */
 
-int ui_handler_panel_region(bContext *C, wmEvent *event)
+int ui_handler_panel_region(bContext *C, const wmEvent *event)
 {
        ARegion *ar = CTX_wm_region(C);
        uiBlock *block;
@@ -1133,6 +1162,9 @@ int ui_handler_panel_region(bContext *C, wmEvent *event)
                        if (block->rect.xmin <= mx && block->rect.xmin + PNL_HEADER >= mx)
                                inside_header = 1;
                }
+               else if (block->rect.xmin > mx || block->rect.xmax < mx) {
+                       /* outside left/right side */
+               }
                else if ((block->rect.ymax <= my) && (block->rect.ymax + PNL_HEADER >= my)) {
                        inside_header = 1;
                }
@@ -1245,7 +1277,7 @@ int ui_handler_panel_region(bContext *C, wmEvent *event)
 /**************** window level modal panel interaction **************/
 
 /* note, this is modal handler and should not swallow events for animation */
-static int ui_handler_panel(bContext *C, wmEvent *event, void *userdata)
+static int ui_handler_panel(bContext *C, const wmEvent *event, void *userdata)
 {
        Panel *panel = userdata;
        uiHandlePanelData *data = panel->activedata;