From 198295e9caf72e2523138817427179b44f5790d5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 17 Sep 2011 16:57:37 +0000 Subject: image button was hard coded to draw the splash screen which it loaded from PNG data on every draw. 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 | 3 +++ source/blender/editors/interface/interface_draw.c | 10 ++-------- source/blender/windowmanager/intern/wm_operators.c | 8 +++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 0dee7a3813a..abc668d72dd 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -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); } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 8889c419c35..a1275e237c1 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -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 } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 68a4eebf93f..5e4505abaa5 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -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); -- cgit v1.2.3