merge with/from trunk at r35190
[blender.git] / source / blender / editors / space_image / space_image.c
index 60b43844034b4d46eeac778d02cca9798313eee0..ed59a35229ad034c6bb349424e21a79cb2b338b8 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -39,6 +39,7 @@
 #include "BLI_math.h"
 #include "BLI_editVert.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_colortools.h"
 #include "BKE_context.h"
@@ -49,6 +50,7 @@
 
 #include "IMB_imbuf_types.h"
 
+#include "ED_image.h"
 #include "ED_mesh.h"
 #include "ED_space_api.h"
 #include "ED_screen.h"
@@ -226,9 +228,18 @@ void ED_space_image_uv_aspect(SpaceImage *sima, float *aspx, float *aspy)
        
        ED_space_image_aspect(sima, aspx, aspy);
        ED_space_image_size(sima, &w, &h);
+
+       *aspx *= (float)w;
+       *aspy *= (float)h;
        
-       *aspx *= (float)w/256.0f;
-       *aspy *= (float)h/256.0f;
+       if(*aspx < *aspy) {
+               *aspy= *aspy / *aspx;
+               *aspx= 1.0f;
+       }
+       else {
+               *aspx= *aspx / *aspy;
+               *aspy= 1.0f;            
+       }
 }
 
 void ED_image_uv_aspect(Image *ima, float *aspx, float *aspy)
@@ -257,11 +268,9 @@ int ED_space_image_show_paint(SpaceImage *sima)
 
 int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
 {
-       if(ED_space_image_show_render(sima))
-               return 0;
-       if(ED_space_image_show_paint(sima))
+       if(sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima)))
                return 0;
-       
+
        if(obedit && obedit->type == OB_MESH) {
                BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh;
                int ret;
@@ -368,7 +377,7 @@ ARegion *image_has_scope_region(ScrArea *sa)
 
 /* ******************** default callbacks for image space ***************** */
 
-static SpaceLink *image_new(const bContext *C)
+static SpaceLink *image_new(const bContext *UNUSED(C))
 {
        ARegion *ar;
        SpaceImage *simage;
@@ -383,6 +392,7 @@ static SpaceLink *image_new(const bContext *C)
        simage->iuser.frames= 100;
        
        scopes_new(&simage->scopes);
+       simage->sample_line_hist.height= 100;
 
        /* header */
        ar= MEM_callocN(sizeof(ARegion), "header for image");
@@ -428,7 +438,7 @@ static void image_free(SpaceLink *sl)
 
 
 /* spacetype; init callback, add handlers */
-static void image_init(struct wmWindowManager *wm, ScrArea *sa)
+static void image_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
 {
        ListBase *lb= WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
 
@@ -448,7 +458,7 @@ static SpaceLink *image_duplicate(SpaceLink *sl)
        return (SpaceLink *)simagen;
 }
 
-void image_operatortypes(void)
+static void image_operatortypes(void)
 {
        WM_operatortype_append(IMAGE_OT_view_all);
        WM_operatortype_append(IMAGE_OT_view_pan);
@@ -467,6 +477,8 @@ void image_operatortypes(void)
        WM_operatortype_append(IMAGE_OT_save_sequence);
        WM_operatortype_append(IMAGE_OT_pack);
        WM_operatortype_append(IMAGE_OT_unpack);
+       
+       WM_operatortype_append(IMAGE_OT_invert);
 
        WM_operatortype_append(IMAGE_OT_cycle_render_slot);
 
@@ -481,9 +493,10 @@ void image_operatortypes(void)
        WM_operatortype_append(IMAGE_OT_scopes);
 }
 
-void image_keymap(struct wmKeyConfig *keyconf)
+static void image_keymap(struct wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap= WM_keymap_find(keyconf, "Image Generic", SPACE_IMAGE, 0);
+       wmKeyMapItem *kmi;
        
        WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
@@ -494,12 +507,14 @@ void image_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "IMAGE_OT_scopes", PKEY, KM_PRESS, 0, 0);
 
        WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, 0, 0);
+       RNA_boolean_set(WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, KM_ALT, 0)->ptr, "reverse", TRUE);
        
        keymap= WM_keymap_find(keyconf, "Image", SPACE_IMAGE, 0);
        
        WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0);
 
        WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
@@ -522,10 +537,15 @@ void image_keymap(struct wmKeyConfig *keyconf)
        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);
+
+       /* toggle editmode is handy to have while UV unwrapping */
+       kmi= WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
+       RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
+       RNA_boolean_set(kmi->ptr, "toggle", 1);
 }
 
 /* dropboxes */
-static int image_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+static int image_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
 {
        if(drag->type==WM_DRAG_PATH)
                if(ELEM3(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_BLANK))      /* rule might not work? */
@@ -549,7 +569,7 @@ static void image_dropboxes(void)
 
 
 
-static void image_refresh(const bContext *C, ScrArea *sa)
+static void image_refresh(const bContext *C, ScrArea *UNUSED(sa))
 {
        SpaceImage *sima= CTX_wm_space_image(C);
        Object *obedit= CTX_data_edit_object(C);
@@ -568,13 +588,13 @@ static void image_refresh(const bContext *C, ScrArea *sa)
                MTexPoly *tf;
                
                if(em && EDBM_texFaceCheck(em)) {
-                       sima->image= ima= NULL;
+                       sima->image= NULL;
                        
                        tf = EDBM_get_active_mtexpoly(em, NULL, 1); /* partially selected face is ok */
                        
                        if(tf && (tf->mode & TF_TEX)) {
                                /* don't need to check for pin here, see above */
-                               sima->image= ima= tf->tpage;
+                               sima->image= tf->tpage;
                                
                                if(sima->flag & SI_EDITTILE);
                                else sima->curtile= tf->tile;
@@ -623,29 +643,35 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn)
                        switch(wmn->data) {
                                case ND_DATA:
                                case ND_SELECT:
+                                       image_scopes_tag_refresh(sa);
                                        ED_area_tag_refresh(sa);
                                        ED_area_tag_redraw(sa);
                                        break;
                        }
                case NC_OBJECT:
+               {
+                       Object *ob= (Object *)wmn->reference;
                        switch(wmn->data) {
                                case ND_TRANSFORM:
-                                       if(sima->lock && (sima->flag & SI_DRAWSHADOW)) {
+                               case ND_MODIFIER:
+                                       if(ob && (ob->mode & OB_MODE_EDIT) && sima->lock && (sima->flag & SI_DRAWSHADOW)) {
                                                ED_area_tag_refresh(sa);
                                                ED_area_tag_redraw(sa);
                                        }
                                        break;
                        }
+               }
        }
 }
 
+const char *image_context_dir[] = {"edit_image", NULL};
+
 static int image_context(const bContext *C, const char *member, bContextDataResult *result)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
 
        if(CTX_data_dir(member)) {
-               static const char *dir[] = {"edit_image", NULL};
-               CTX_data_dir_set(result, dir);
+               CTX_data_dir_set(result, image_context_dir);
        }
        else if(CTX_data_equals(member, "edit_image")) {
                CTX_data_id_pointer_set(result, (ID*)ED_space_image(sima));
@@ -743,6 +769,9 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
        //View2DScrollers *scrollers;
        float col[3];
        
+       /* XXX not supported yet, disabling for now */
+       scene->r.scemode &= ~R_COMP_CROP;
+       
        /* clear and setup matrix */
        UI_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0.0);
@@ -758,7 +787,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
        draw_image_main(sima, ar, scene);
 
        /* and uvs in 0.0-1.0 space */
-       UI_view2d_view_ortho(C, v2d);
+       UI_view2d_view_ortho(v2d);
        draw_uvedit_main(sima, ar, scene, obedit);
 
        ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
@@ -874,7 +903,7 @@ static void image_scope_area_listener(ARegion *ar, wmNotifier *wmn)
 /************************* header region **************************/
 
 /* add handlers, stuff you only do once or on area/region changes */
-static void image_header_area_init(wmWindowManager *wm, ARegion *ar)
+static void image_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
 {
        ED_region_header_init(ar);
 }