Two in one:
[blender.git] / source / blender / src / drawimage.c
index da41f40602be54adcf8adb4d79e1b88e0e646778..257d78c8b95772c6f67aa346e04742543892303a 100644 (file)
@@ -154,7 +154,7 @@ static int image_preview_active(ScrArea *sa, float *xim, float *yim)
        SpaceImage *sima= sa->spacedata.first;
        
        /* only when compositor shows, and image handler set */
-       if(sima->image == (Image *)find_id("IM", "Viewer Node")) {
+       if(sima->image && sima->image->type==IMA_TYPE_COMPOSITE) {
                short a;
        
                for(a=0; a<SPACE_MAXHANDLER; a+=2) {
@@ -271,6 +271,21 @@ void what_image(SpaceImage *sima)
        }
 }
 
+/* after a what_image(), this call will give ibufs, includes the spare image */
+ImBuf *imagewindow_get_ibuf(SpaceImage *sima)
+{
+       
+       if(G.sima->image) {
+               /* check for spare */
+               if(sima->image->type==IMA_TYPE_R_RESULT && sima->showspare)
+                       return sima->spare;
+               else
+                       return BKE_image_get_ibuf(sima->image, &sima->iuser);
+       }
+       return NULL;
+}
+
+
 /* called to assign images to UV faces */
 void image_changed(SpaceImage *sima, int dotile)
 {
@@ -737,7 +752,7 @@ void image_editvertex_buts(uiBlock *block)
        me= get_mesh(OBACT);
        
        if (G.sima->image) {
-               ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
+               ImBuf *ibuf= imagewindow_get_ibuf(G.sima);
                if(ibuf) {
                        imx= ibuf->x;
                        imy= ibuf->y;
@@ -1042,10 +1057,13 @@ static void image_panel_curves_reset(void *cumap_v, void *ibuf_v)
 
 static void image_panel_curves(short cntrl)    // IMAGE_HANDLER_CURVES
 {
-       ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
+       ImBuf *ibuf;
        uiBlock *block;
        uiBut *bt;
        
+       /* and we check for spare */
+       ibuf= imagewindow_get_ibuf(G.sima);
+       
        block= uiNewBlock(&curarea->uiblocks, "image_panel_curves", UI_EMBOSS, UI_HELV, curarea->win);
        uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
        uiSetPanelHandler(IMAGE_HANDLER_CURVES);  // for close and esc
@@ -1177,14 +1195,20 @@ static void preview_cb(struct ScrArea *sa, struct uiBlock *block)
 
 static int is_preview_allowed(ScrArea *cur)
 {
+       SpaceImage *sima= cur->spacedata.first;
        ScrArea *sa;
 
+       /* check if another areawindow has preview set */
        for(sa=G.curscreen->areabase.first; sa; sa= sa->next) {
                if(sa!=cur && sa->spacetype==SPACE_IMAGE) {
                        if(image_preview_active(sa, NULL, NULL))
                           return 0;
                }
        }
+       /* check image type */
+       if(sima->image==NULL || sima->image->type!=IMA_TYPE_COMPOSITE)
+               return 0;
+       
        return 1;
 }
 
@@ -1553,10 +1577,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                        }
                }
                /* and we check for spare */
-               if(sima->image->type==IMA_TYPE_R_RESULT && sima->showspare)
-                       ibuf= sima->spare;
-               else
-                       ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
+               ibuf= imagewindow_get_ibuf(sima);
        }
        
        if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
@@ -1784,7 +1805,7 @@ static void image_zoom_set_factor(float zoomfac)
        width= 256;
        height= 256;
        if (sima->image) {
-               ImBuf *ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
+               ImBuf *ibuf= imagewindow_get_ibuf(sima);
 
                if (ibuf) {
                        float xim, yim;
@@ -1896,12 +1917,13 @@ void image_viewzoom(unsigned short event, int invert)
  */
 void image_home(void)
 {
-       ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
+       ImBuf *ibuf;
        int width, height, imgwidth, imgheight;
        float zoomX, zoomY;
 
        if (curarea->spacetype != SPACE_IMAGE) return;
-
+       ibuf= imagewindow_get_ibuf(G.sima);
+       
        if (ibuf == NULL) {
                imgwidth = 256;
                imgheight = 256;