utility function to find the biggest area: BKE_screen_find_big_area(...), was being...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 4 Nov 2011 01:15:04 +0000 (01:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 4 Nov 2011 01:15:04 +0000 (01:15 +0000)
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/intern/screen.c
source/blender/editors/interface/interface_ops.c
source/blender/editors/object/object_bake.c
source/blender/editors/render/render_view.c
source/blender/windowmanager/intern/wm_init_exit.c

index 5b6d7e3cd96a41eb9d999bcbec4d0bc978756e32..77a351d534e6a9a9edba04b55c9459afdef267e4 100644 (file)
  */
 
 struct ARegion;
-struct bContext;
-struct bContextDataResult;
-struct bScreen;
-struct ListBase;
-struct Panel;
 struct Header;
+struct ListBase;
 struct Menu;
+struct Panel;
+struct Scene;
 struct ScrArea;
 struct SpaceType;
-struct Scene;
+struct View3D;
+struct bContext;
+struct bContextDataResult;
+struct bScreen;
+struct uiLayout;
+struct uiMenuItem;
+struct wmKeyConfig;
 struct wmNotifier;
 struct wmWindow;
 struct wmWindowManager;
-struct wmKeyConfig;
-struct uiLayout;
-struct uiMenuItem;
 
 #include "RNA_types.h"
 
@@ -239,6 +240,7 @@ void        BKE_area_region_free(struct SpaceType *st, struct ARegion *ar);
 void   BKE_screen_area_free(struct ScrArea *sa);
 
 struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
+struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min);
 
 void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene);
 void BKE_screen_view3d_scene_sync(struct bScreen *sc);
index 02e6fe945f341dc26e5a6336ad21fc2978ce05a4..b7f49bbab4738f19855b8707486283a431088a3e 100644 (file)
@@ -351,6 +351,29 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type)
        return NULL;
 }
 
+/* note, using this function is generally a last resort, you really want to be
+ * using the context when you can - campbell
+ * -1 for any type */
+struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min)
+{
+       ScrArea *sa, *big= NULL;
+       int size, maxsize= 0;
+
+       for(sa= sc->areabase.first; sa; sa= sa->next) {
+               if ((spacetype == -1) || sa->spacetype == spacetype) {
+                       if (min >= sa->winx && min >= sa->winy) {
+                               size= sa->winx*sa->winy;
+                               if (size > maxsize) {
+                                       maxsize= size;
+                                       big= sa;
+                               }
+                       }
+               }
+       }
+
+       return big;
+}
+
 void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene)
 {
        int bit;
index d420b5c24c3c412f293c5de8d22ab95eb7cf2f88..5803054caa71d80d37bbdd62b997b1e95f51bf04 100644 (file)
@@ -43,6 +43,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_context.h"
+#include "BKE_screen.h"
 #include "BKE_global.h"
 #include "BKE_text.h" /* for UI_OT_reports_to_text */
 #include "BKE_report.h"
@@ -577,24 +578,6 @@ void UI_editsource_active_but_test(uiBut *but)
 
 /* editsource operator component */
 
-static ScrArea *biggest_text_view(bContext *C)
-{
-       bScreen *sc= CTX_wm_screen(C);
-       ScrArea *sa, *big= NULL;
-       int size, maxsize= 0;
-
-       for(sa= sc->areabase.first; sa; sa= sa->next) {
-               if(sa->spacetype==SPACE_TEXT) {
-                       size= sa->winx * sa->winy;
-                       if(size > maxsize) {
-                               maxsize= size;
-                               big= sa;
-                       }
-               }
-       }
-       return big;
-}
-
 static int editsource_text_edit(bContext *C, wmOperator *op,
                                 char filepath[240], int line)
 {
@@ -619,7 +602,7 @@ static int editsource_text_edit(bContext *C, wmOperator *op,
        else {
                /* naughty!, find text area to set, not good behavior
                 * but since this is a dev tool lets allow it - campbell */
-               ScrArea *sa= biggest_text_view(C);
+               ScrArea *sa= BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
                if(sa) {
                        SpaceText *st= sa->spacedata.first;
                        st->text= text;
index e29dfaa0a239badab6d8e06800a2b48211608b07..5487cbdadb2307dfc189ec937f4b45487337dc64 100644 (file)
@@ -54,6 +54,7 @@
 #include "BLI_math_geom.h"
 
 #include "BKE_blender.h"
+#include "BKE_screen.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
@@ -1202,24 +1203,6 @@ static int thread_break(void *UNUSED(arg))
        return G.afbreek;
 }
 
-static ScrArea *biggest_image_area(bScreen *screen)
-{
-       ScrArea *sa, *big= NULL;
-       int size, maxsize= 0;
-
-       for(sa= screen->areabase.first; sa; sa= sa->next) {
-               if(sa->spacetype==SPACE_IMAGE) {
-                       size= sa->winx*sa->winy;
-                       if(sa->winx > 10 && sa->winy > 10 && size > maxsize) {
-                               maxsize= size;
-                               big= sa;
-                       }
-               }
-       }
-       return big;
-}
-
-
 typedef struct BakeRender {
        Render *re;
        Main *main;
@@ -1270,7 +1253,7 @@ static void init_bake_internal(BakeRender *bkr, bContext *C)
        /* get editmode results */
        ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */
 
-       bkr->sa= biggest_image_area(CTX_wm_screen(C)); /* can be NULL */
+       bkr->sa= BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_IMAGE, 10); /* can be NULL */
        bkr->main= CTX_data_main(C);
        bkr->scene= scene;
        bkr->actob= (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL;
index 47957c0bb5ad8631193024a2d21e3c66d7f72fbd..d8719c7d7cdbae895f470468f6daa53d39596770 100644 (file)
@@ -58,6 +58,7 @@
 
 /* returns biggest area that is not uv/image editor. Note that it uses buttons */
 /* window as the last possible alternative.                                                                       */
+/* would use BKE_screen_find_big_area(...) but this is too specific            */
 static ScrArea *biggest_non_image_area(bContext *C)
 {
        bScreen *sc= CTX_wm_screen(C);
@@ -85,22 +86,6 @@ static ScrArea *biggest_non_image_area(bContext *C)
        return big;
 }
 
-static ScrArea *biggest_area(bContext *C)
-{
-       bScreen *sc= CTX_wm_screen(C);
-       ScrArea *sa, *big= NULL;
-       int size, maxsize= 0;
-
-       for(sa= sc->areabase.first; sa; sa= sa->next) {
-               size= sa->winx*sa->winy;
-               if(size > maxsize) {
-                       maxsize= size;
-                       big= sa;
-               }
-       }
-       return big;
-}
-
 static ScrArea *find_area_showing_r_result(bContext *C, wmWindow **win)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
@@ -206,7 +191,7 @@ void render_view_open(bContext *C, int mx, int my)
                        }
                        else {
                                /* use any area of decent size */
-                               sa= biggest_area(C);
+                               sa= BKE_screen_find_big_area(CTX_wm_screen(C), -1, 0);
                                if(sa->spacetype!=SPACE_IMAGE) {
                                        // XXX newspace(sa, SPACE_IMAGE);
                                        sima= sa->spacedata.first;
index f32e2afa3e08c6cc601a40187603c51b89ee832d..0795bc8deee8c4448e615d05926164d22a4690d9 100644 (file)
@@ -212,24 +212,6 @@ void WM_init_splash(bContext *C)
        }
 }
 
-static ScrArea *biggest_view3d(bContext *C)
-{
-       bScreen *sc= CTX_wm_screen(C);
-       ScrArea *sa, *big= NULL;
-       int size, maxsize= 0;
-
-       for(sa= sc->areabase.first; sa; sa= sa->next) {
-               if(sa->spacetype==SPACE_VIEW3D) {
-                       size= sa->winx * sa->winy;
-                       if(size > maxsize) {
-                               maxsize= size;
-                               big= sa;
-                       }
-               }
-       }
-       return big;
-}
-
 int WM_init_game(bContext *C)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
@@ -252,7 +234,7 @@ int WM_init_game(bContext *C)
        if(win)
                CTX_wm_window_set(C, win);
 
-       sa = biggest_view3d(C);
+       sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0);
        ar= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
 
        // if we have a valid 3D view