merge with/from trunk at r35190
[blender.git] / source / blender / editors / space_image / image_buttons.c
index 44f3f5f57645d5036adddd42b7c7008d966b4884..dfaeccd7993c8d8cee8ad2a7ddc6202680a7f583 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -40,6 +40,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"
@@ -98,7 +99,7 @@
 static void image_editvertex_buts(const bContext *C, uiBlock *block);
 
 
-static void do_image_panel_events(bContext *C, void *arg, int event)
+static void do_image_panel_events(bContext *C, void *UNUSED(arg), int event)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
        
@@ -138,21 +139,28 @@ static void image_info(Image *ima, ImBuf *ibuf, char *str)
        
        if(ibuf->rect_float) {
                if(ibuf->channels!=4) {
-                       sprintf(str+ofs, "%d float channel(s)", ibuf->channels);
+                       ofs+= sprintf(str+ofs, "%d float channel(s)", ibuf->channels);
                }
                else if(ibuf->depth==32)
-                       strcat(str, " RGBA float");
+                       ofs+= sprintf(str+ofs, " RGBA float");
                else
-                       strcat(str, " RGB float");
+                       ofs+= sprintf(str+ofs, " RGB float");
        }
        else {
                if(ibuf->depth==32)
-                       strcat(str, " RGBA byte");
+                       ofs+= sprintf(str+ofs, " RGBA byte");
                else
-                       strcat(str, " RGB byte");
+                       ofs+= sprintf(str+ofs, " RGB byte");
        }
        if(ibuf->zbuf || ibuf->zbuf_float)
-               strcat(str, " + Z");
+               ofs+= sprintf(str+ofs, " + Z");
+
+       if(ima->source==IMA_SRC_SEQUENCE) {
+               char *file= BLI_last_slash(ibuf->name);
+               if(file==NULL)  file= ibuf->name;
+               else                    file++;
+               sprintf(str+ofs, ", %s", file);
+       }
        
 }
 
@@ -285,11 +293,18 @@ static void image_editvertex_buts(const bContext *C, uiBlock *block)
 
 /* is used for both read and write... */
 
-static int image_panel_poll(const bContext *C, PanelType *pt)
+static int image_panel_poll(const bContext *C, PanelType *UNUSED(pt))
 {
        SpaceImage *sima= CTX_wm_space_image(C);
+       ImBuf *ibuf;
+       void *lock;
+       int result;
+
+       ibuf= ED_space_image_acquire_buffer(sima, &lock);
+       result= ibuf && ibuf->rect_float;
+       ED_space_image_release_buffer(sima, lock);
        
-       return ED_space_image_has_buffer(sima);
+       return result;
 }
 
 static void image_panel_curves(const bContext *C, Panel *pa)
@@ -320,6 +335,8 @@ static void image_panel_curves(const bContext *C, Panel *pa)
 #if 0
 /* 0: disable preview 
    otherwise refresh preview
+   XXX if you put this back, also check XXX in image_main_area_draw() */
 */
 void image_preview_event(int event)
 {
@@ -455,7 +472,7 @@ static void image_panel_preview(ScrArea *sa, short cntrl)   // IMAGE_HANDLER_PREVI
 
 /* ********************* callbacks for standard image buttons *************** */
 
-static char *slot_menu()
+static char *slot_menu(void)
 {
        char *str;
        int a, slot;
@@ -471,7 +488,8 @@ static char *slot_menu()
        return str;
 }
 
-static char *layer_menu(RenderResult *rr, short *curlay)
+/* TODO, curlay should be removed? */
+static char *layer_menu(RenderResult *rr, short *UNUSED(curlay))
 {
        RenderLayer *rl;
        int len= 64 + 32*BLI_countlist(&rr->layers);
@@ -687,7 +705,7 @@ static void uiblock_layer_pass_arrow_buttons(uiLayout *layout, RenderResult *rr,
        if(rr==NULL || iuser==NULL)
                return;
        if(rr->layers.first==NULL) {
-               uiItemL(row, "No Layers in Render Result.", 0);
+               uiItemL(row, "No Layers in Render Result.", ICON_NULL);
                return;
        }
 
@@ -717,7 +735,7 @@ typedef struct RNAUpdateCb {
        ImageUser *iuser;
 } RNAUpdateCb;
 
-static void rna_update_cb(bContext *C, void *arg_cb, void *arg_unused)
+static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
 {
        RNAUpdateCb *cb= (RNAUpdateCb*)arg_cb;
 
@@ -731,7 +749,7 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *arg_unused)
        RNA_property_update(C, &cb->ptr, cb->prop);
 }
 
-void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, PointerRNA *userptr, int compact)
+void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *userptr, int compact)
 {
        PropertyRNA *prop;
        PointerRNA imaptr;
@@ -748,15 +766,21 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
 
        if(!ptr->data)
                return;
-       
+
        prop= RNA_struct_find_property(ptr, propname);
        if(!prop) {
                printf("uiTemplateImage: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
                return;
        }
 
+       if(RNA_property_type(prop) != PROP_POINTER) {
+               printf("uiTemplateImage: expected pointer property for %s.%s\n", RNA_struct_identifier(ptr->type), propname);
+               return;
+       }
+
        block= uiLayoutGetBlock(layout);
 
+
        imaptr= RNA_property_pointer_get(ptr, prop);
        ima= imaptr.data;
        iuser= userptr->data;
@@ -781,8 +805,8 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                        image_info(ima, ibuf, str);
                        BKE_image_release_ibuf(ima, lock);
 
-                       uiItemL(layout, ima->id.name+2, 0);
-                       uiItemL(layout, str, 0);
+                       uiItemL(layout, ima->id.name+2, ICON_NULL);
+                       uiItemL(layout, str, ICON_NULL);
 
                        if(ima->type==IMA_TYPE_COMPOSITE) {
                                // XXX not working yet
@@ -814,7 +838,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                }
                else {
                        row= uiLayoutRow(layout, 0);
-                       uiItemR(row, &imaptr, "source", 0, NULL, 0);
+                       uiItemR(row, &imaptr, "source", 0, NULL, ICON_NULL);
 
                        if(ima->source != IMA_SRC_GENERATED) {
                                row= uiLayoutRow(layout, 1);
@@ -828,7 +852,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                                row= uiLayoutRow(split, 1);
                                uiLayoutSetEnabled(row, ima->packedfile==NULL);
                                
-                               uiItemR(row, &imaptr, "filepath", 0, "", 0);
+                               uiItemR(row, &imaptr, "filepath", 0, "", ICON_NULL);
                                uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
                        }
 
@@ -852,7 +876,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                                        ibuf= BKE_image_acquire_ibuf(ima, iuser, &lock);
                                        image_info(ima, ibuf, str);
                                        BKE_image_release_ibuf(ima, lock);
-                                       uiItemL(layout, str, 0);
+                                       uiItemL(layout, str, ICON_NULL);
                                }
                        }
                        
@@ -863,13 +887,13 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                                        split= uiLayoutSplit(layout, 0, 0);
 
                                        col= uiLayoutColumn(split, 0);
-                                       uiItemR(col, &imaptr, "use_fields", 0, NULL, 0);
+                                       uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NULL);
                                        row= uiLayoutRow(col, 0);
-                                       uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, 0);
+                                       uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, ICON_NULL);
                                        uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
 
                                        col= uiLayoutColumn(split, 0);
-                                       uiItemR(col, &imaptr, "use_premultiply", 0, NULL, 0);
+                                       uiItemR(col, &imaptr, "use_premultiply", 0, NULL, ICON_NULL);
                                }
                        }
 
@@ -882,30 +906,30 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                                 
                                sprintf(str, "(%d) Frames", iuser->framenr);
                                row= uiLayoutRow(col, 1);
-                               uiItemR(col, userptr, "frame_duration", 0, str, 0);
+                               uiItemR(col, userptr, "frame_duration", 0, str, ICON_NULL);
                                if(ima->anim) {
                                        block= uiLayoutGetBlock(row);
                                        but= uiDefBut(block, BUT, 0, "Match Movie Length", 0, 0, UI_UNIT_X*2, UI_UNIT_Y, 0, 0, 0, 0, 0, "Set the number of frames to match the movie or sequence.");
                                        uiButSetFunc(but, set_frames_cb, ima, iuser);
                                }
 
-                               uiItemR(col, userptr, "frame_start", 0, "Start", 0);
-                               uiItemR(col, userptr, "frame_offset", 0, NULL, 0);
+                               uiItemR(col, userptr, "frame_start", 0, "Start", ICON_NULL);
+                               uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NULL);
 
                                col= uiLayoutColumn(split, 0);
-                               uiItemR(col, userptr, "fields_per_frame", 0, "Fields", 0);
-                               uiItemR(col, userptr, "use_auto_refresh", 0, NULL, 0);
-                               uiItemR(col, userptr, "use_cyclic", 0, NULL, 0);
+                               uiItemR(col, userptr, "fields_per_frame", 0, "Fields", ICON_NULL);
+                               uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NULL);
+                               uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NULL);
                        }
                        else if(ima->source==IMA_SRC_GENERATED) {
                                split= uiLayoutSplit(layout, 0, 0);
 
                                col= uiLayoutColumn(split, 1);
-                               uiItemR(col, &imaptr, "generated_width", 0, "X", 0);
-                               uiItemR(col, &imaptr, "generated_height", 0, "Y", 0);
+                               uiItemR(col, &imaptr, "generated_width", 0, "X", ICON_NULL);
+                               uiItemR(col, &imaptr, "generated_height", 0, "Y", ICON_NULL);
 
                                col= uiLayoutColumn(split, 0);
-                               uiItemR(col, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, 0);
+                               uiItemR(col, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NULL);
                        }
 
                                        }
@@ -929,7 +953,7 @@ void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser
        }
 }
 
-static int image_panel_uv_poll(const bContext *C, PanelType *pt)
+static int image_panel_uv_poll(const bContext *C, PanelType *UNUSED(pt))
 {
        Object *obedit= CTX_data_edit_object(C);
        return ED_uvedit_test(obedit);
@@ -974,7 +998,7 @@ void image_buttons_register(ARegionType *art)
        BLI_addtail(&art->paneltypes, pt);
 }
 
-static int image_properties(bContext *C, wmOperator *op)
+static int image_properties(bContext *C, wmOperator *UNUSED(op))
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= image_has_buttons_region(sa);
@@ -989,6 +1013,7 @@ void IMAGE_OT_properties(wmOperatorType *ot)
 {
        ot->name= "Properties";
        ot->idname= "IMAGE_OT_properties";
+       ot->description= "Toggle display properties panel";
        
        ot->exec= image_properties;
        ot->poll= ED_operator_image_active;
@@ -997,7 +1022,7 @@ void IMAGE_OT_properties(wmOperatorType *ot)
        ot->flag= 0;
 }
 
-static int image_scopes(bContext *C, wmOperator *op)
+static int image_scopes(bContext *C, wmOperator *UNUSED(op))
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= image_has_scope_region(sa);
@@ -1012,6 +1037,7 @@ void IMAGE_OT_scopes(wmOperatorType *ot)
 {
        ot->name= "Scopes";
        ot->idname= "IMAGE_OT_scopes";
+       ot->description= "Toggle display scopes panel";
        
        ot->exec= image_scopes;
        ot->poll= ED_operator_image_active;