Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / space_image / space_image.c
index 896522e..1506df8 100644 (file)
@@ -47,6 +47,7 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_image.h"
+#include "BKE_mesh.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
@@ -192,7 +193,7 @@ void image_operatortypes(void)
        WM_operatortype_append(IMAGE_OT_unpack);
 
        WM_operatortype_append(IMAGE_OT_sample);
-       WM_operatortype_append(IMAGE_OT_set_curves_point);
+       WM_operatortype_append(IMAGE_OT_curves_point_set);
 
        WM_operatortype_append(IMAGE_OT_record_composite);
 
@@ -233,17 +234,19 @@ void image_keymap(struct wmWindowManager *wm)
        WM_keymap_add_item(keymap, "PAINT_OT_image_paint", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", SELECTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_sample_color", SELECTMOUSE, KM_PRESS, 0, 0);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
 
        WM_keymap_add_item(keymap, "IMAGE_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
-       RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_set_curves_point", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0);
-       RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_set_curves_point", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1);
+       RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0);
+       RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1);
 
        WM_keymap_add_item(keymap, "IMAGE_OT_toolbox", SPACEKEY, KM_PRESS, 0, 0);
 }
 
 static void image_refresh(const bContext *C, ScrArea *sa)
 {
-       SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
+       SpaceImage *sima= CTX_wm_space_image(C);
        Object *obedit= CTX_data_edit_object(C);
        Image *ima;
 
@@ -253,7 +256,7 @@ static void image_refresh(const bContext *C, ScrArea *sa)
        if(ima && (ima->source==IMA_SRC_VIEWER || sima->pin));
        else if(obedit && obedit->type == OB_MESH) {
                Mesh *me= (Mesh*)obedit->data;
-               EditMesh *em= me->edit_mesh;
+               EditMesh *em= BKE_mesh_get_editmesh(me);
                MTFace *tf;
                
                if(em && EM_texFaceCheck(em)) {
@@ -267,22 +270,15 @@ static void image_refresh(const bContext *C, ScrArea *sa)
                                
                                if(sima->flag & SI_EDITTILE);
                                else sima->curtile= tf->tile;
-                               
-                               if(ima) {
-                                       if(tf->mode & TF_TILES)
-                                               ima->tpageflag |= IMA_TILES;
-                                       else
-                                               ima->tpageflag &= ~IMA_TILES;
-                               }
                        }
                }
+
+               BKE_mesh_end_editmesh(obedit->data, em);
        }
 }
 
 static void image_listener(ScrArea *sa, wmNotifier *wmn)
 {
-       SpaceImage *sima= sa->spacedata.first;
-
        /* context changes */
        switch(wmn->category) {
                case NC_SCENE:
@@ -296,22 +292,28 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn)
                        }
                        break;
                case NC_IMAGE:  
-                       if(!wmn->reference || wmn->reference == sima->image)
-                               ED_area_tag_redraw(sa);
+                       ED_area_tag_redraw(sa);
                        break;
+               case NC_OBJECT:
+                       switch(wmn->data) {
+                               case ND_GEOM_SELECT:
+                               case ND_GEOM_DATA:
+                                       ED_area_tag_redraw(sa);
+                                       break;
+                       }
        }
 }
 
-static int image_context(const bContext *C, bContextDataMember member, bContextDataResult *result)
+static int image_context(const bContext *C, const char *member, bContextDataResult *result)
 {
-       SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
+       SpaceImage *sima= CTX_wm_space_image(C);
 
-       if(member == CTX_DATA_EDIT_IMAGE) {
-               CTX_data_pointer_set(result, ED_space_image(sima));
-               return 1;
+       if(CTX_data_dir(member)) {
+               static const char *dir[] = {"edit_image", NULL};
+               CTX_data_dir_set(result, dir);
        }
-       else if(member == CTX_DATA_EDIT_IMAGE_BUFFER) {
-               CTX_data_pointer_set(result, ED_space_image_buffer(sima));
+       else if(CTX_data_equals(member, "edit_image")) {
+               CTX_data_id_pointer_set(result, (ID*)ED_space_image(sima));
                return 1;
        }
 
@@ -332,12 +334,10 @@ static void image_main_area_set_view2d(SpaceImage *sima, ARegion *ar, Scene *sce
 #endif
        if(sima->image) {
                ImBuf *ibuf= ED_space_image_buffer(sima);
-               float xuser_asp, yuser_asp;
                
-               ED_image_aspect(sima->image, &xuser_asp, &yuser_asp);
                if(ibuf) {
-                       width= ibuf->x*xuser_asp;
-                       height= ibuf->y*yuser_asp;
+                       width= ibuf->x;
+                       height= ibuf->y;
                }
                else if(sima->image->type==IMA_TYPE_R_RESULT) {
                        /* not very important, just nice */
@@ -369,7 +369,6 @@ static void image_main_area_set_view2d(SpaceImage *sima, ARegion *ar, Scene *sce
        ar->v2d.mask.ymax= winy;
 
        /* which part of the image space do we see? */
-       /* same calculation as in lrectwrite: area left and down*/
        x1= ar->winrct.xmin+(winx-sima->zoom*w)/2;
        y1= ar->winrct.ymin+(winy-sima->zoom*h)/2;
 
@@ -402,6 +401,10 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
        /* image paint polls for mode */
        keymap= WM_keymap_listbase(wm, "ImagePaint", SPACE_IMAGE, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
+       /* XXX need context here?
+       keymap= WM_keymap_listbase(wm, "UVEdit", 0, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);*/
        
        /* own keymaps */
        keymap= WM_keymap_listbase(wm, "Image Generic", SPACE_IMAGE, 0);
@@ -413,7 +416,7 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void image_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
+       SpaceImage *sima= CTX_wm_space_image(C);
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene= CTX_data_scene(C);
        View2D *v2d= &ar->v2d;
@@ -466,13 +469,6 @@ static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
                                        break;
                        }
                        break;
-               case NC_OBJECT:
-                       switch(wmn->data) {
-                               case ND_GEOM_SELECT:
-                               case ND_GEOM_DATA:
-                                       ED_region_tag_redraw(ar);
-                                       break;
-                       }
        }
 }
 
@@ -482,32 +478,16 @@ static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
 static void image_buttons_area_init(wmWindowManager *wm, ARegion *ar)
 {
        ListBase *keymap;
+
+       ED_region_panels_init(wm, ar);
        
-       keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
-       WM_event_add_keymap_handler(&ar->handlers, keymap);
        keymap= WM_keymap_listbase(wm, "Image Generic", SPACE_IMAGE, 0);
        WM_event_add_keymap_handler(&ar->handlers, keymap);
-       
-       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST_UI, ar->winx, ar->winy);
 }
 
 static void image_buttons_area_draw(const bContext *C, ARegion *ar)
 {
-       float col[3];
-       
-       /* clear */
-       UI_GetThemeColor3fv(TH_BACK, col);
-       
-       glClearColor(col[0], col[1], col[2], 0.0);
-       glClear(GL_COLOR_BUFFER_BIT);
-       
-       /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, &ar->v2d);
-       
-       image_buttons_area_defbuts(C, ar);
-       
-       /* restore view matrix? */
-       UI_view2d_view_restore(C);
+       ED_region_panels(C, ar, 1, NULL, -1);
 }
 
 static void image_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
@@ -523,11 +503,17 @@ static void image_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
 /* add handlers, stuff you only do once or on area/region changes */
 static void image_header_area_init(wmWindowManager *wm, ARegion *ar)
 {
+#if 0
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
+#else
+       ED_region_header_init(ar);
+#endif
 }
 
 static void image_header_area_draw(const bContext *C, ARegion *ar)
 {
+       ED_region_header(C, ar);
+#if 0
        float col[3];
        
        /* clear */
@@ -546,6 +532,7 @@ static void image_header_area_draw(const bContext *C, ARegion *ar)
        
        /* restore view matrix? */
        UI_view2d_view_restore(C);
+#endif
 }
 
 /**************************** spacetype *****************************/
@@ -589,6 +576,8 @@ void ED_spacetype_image(void)
        art->draw= image_buttons_area_draw;
        BLI_addhead(&st->regiontypes, art);
 
+       image_buttons_register(art);
+
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
        art->regionid = RGN_TYPE_HEADER;
@@ -599,7 +588,6 @@ void ED_spacetype_image(void)
        
        BLI_addhead(&st->regiontypes, art);
        
-       
        BKE_spacetype_register(st);
 }
 
@@ -629,10 +617,12 @@ void ED_space_image_set(bContext *C, SpaceImage *sima, Scene *scene, Object *obe
        if(sima->image && sima->image->id.us==0)
                sima->image->id.us= 1;
 
-       if(obedit)
-               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit);
+       if(C) {
+               if(obedit)
+                       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit);
 
-       ED_area_tag_redraw(CTX_wm_area(C));
+               ED_area_tag_redraw(CTX_wm_area(C));
+       }
 }
 
 ImBuf *ED_space_image_buffer(SpaceImage *sima)
@@ -693,7 +683,7 @@ void ED_image_aspect(Image *ima, float *aspx, float *aspy)
        *aspx= *aspy= 1.0;
 
        if((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) ||
-          (ima->tpageflag & IMA_TILES) || (ima->aspx==0.0 || ima->aspy==0.0))
+          (ima->aspx==0.0 || ima->aspy==0.0))
                return;
 
        /* x is always 1 */
@@ -757,8 +747,15 @@ int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
        if(ED_space_image_show_paint(sima))
                return 0;
 
-       if(obedit && obedit->type == OB_MESH)
-               return EM_texFaceCheck(((Mesh*)obedit->data)->edit_mesh);
+       if(obedit && obedit->type == OB_MESH) {
+               EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+               int ret;
+       
+               ret = EM_texFaceCheck(em);
+
+               BKE_mesh_end_editmesh(obedit->data, em);
+               return ret;
+       }
 
        return 0;
 }
@@ -769,8 +766,15 @@ int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit)
                return 0;
 
        if(ED_space_image_show_paint(sima))
-               if(obedit && obedit->type == OB_MESH)
-                       return EM_texFaceCheck(((Mesh*)obedit->data)->edit_mesh);
+               if(obedit && obedit->type == OB_MESH) {
+                       EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+                       int ret;
+
+                       ret = EM_texFaceCheck(em);
+
+                       BKE_mesh_end_editmesh(obedit->data, em);
+                       return ret;
+               }
 
        return 0;
 }