image button was hard coded to draw the splash screen which it loaded from PNG data...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 17 Sep 2011 16:57:37 +0000 (16:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 17 Sep 2011 16:57:37 +0000 (16:57 +0000)
now pass the ImBuf when callign the image button so we could have different images in buttons later on.

source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_draw.c
source/blender/windowmanager/intern/wm_operators.c

index 0dee7a3..abc668d 100644 (file)
@@ -58,6 +58,7 @@
 
 #include "UI_interface.h"
 
+#include "IMB_imbuf.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -1894,6 +1895,8 @@ static void ui_free_but(const bContext *C, uiBut *but)
        if(but->str && but->str != but->strdata) MEM_freeN(but->str);
        ui_free_link(but->link);
 
+       if((but->type == BUT_IMAGE) && but->poin) IMB_freeImBuf((struct ImBuf *)but->poin);
+
        MEM_freeN(but);
 }
 
index 8889c41..a1275e2 100644 (file)
@@ -461,19 +461,14 @@ void uiEmboss(float x1, float y1, float x2, float y2, int sel)
 
 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
 
-void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *UNUSED(but), uiWidgetColors *UNUSED(wcol), rcti *rect)
+void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
 {
 #ifdef WITH_HEADLESS
        (void)rect;
 #else
-       extern char datatoc_splash_png[];
-       extern int datatoc_splash_png_size;
-       ImBuf *ibuf;
+       ImBuf *ibuf= (ImBuf *)but->poin;
        //GLint scissor[4];
        //int w, h;
-       
-       /* hardcoded to splash, loading and freeing every draw, eek! */
-       ibuf= IMB_ibImageFromMemory((unsigned char*)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
 
        if (!ibuf) return;
        
@@ -501,7 +496,6 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *UNUSED(but), uiWidgetColors *
        glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
        */
        
-       IMB_freeImBuf(ibuf);
 #endif
 }
 
index 68a4eeb..5e4505a 100644 (file)
@@ -80,6 +80,7 @@
 #include "BIF_glutil.h" /* for paint cursor */
 
 #include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
 
 #include "ED_screen.h"
 #include "ED_util.h"
@@ -1206,6 +1207,9 @@ static int wm_resource_check_prev(void)
 
 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(arg))
 {
+       extern char datatoc_splash_png[];
+       extern int datatoc_splash_png_size;
+
        uiBlock *block;
        uiBut *but;
        uiLayout *layout, *split, *col;
@@ -1214,6 +1218,8 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
        int i;
        MenuType *mt= WM_menutype_find("USERPREF_MT_splash", TRUE);
        char url[96];
+       /* hardcoded to splash, loading and freeing every draw, eek! */
+       ImBuf *ibuf= IMB_ibImageFromMemory((unsigned char*)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
        
 #ifdef WITH_BUILDINFO
        int ver_width, rev_width;
@@ -1237,7 +1243,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
        block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
        uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN);
        
-       but= uiDefBut(block, BUT_IMAGE, 0, "", 0, 10, 501, 282, NULL, 0.0, 0.0, 0, 0, "");
+       but= uiDefBut(block, BUT_IMAGE, 0, "", 0, 10, 501, 282, ibuf, 0.0, 0.0, 0, 0, ""); /* button owns the imbuf now */
        uiButSetFunc(but, wm_block_splash_close, block, NULL);
        uiBlockSetFunc(block, wm_block_splash_refreshmenu, block, NULL);