Commit: c1506454ecb4630119ed7ce13b3f8cdfef6dcee0
Author: Bastien Montagne
Date:   Mon Aug 10 18:01:11 2015 +0200
Branches: master
https://developer.blender.org/rBc1506454ecb4630119ed7ce13b3f8cdfef6dcee0

UI drag&drop: make code able to free dragpoin if needed.

Only for image and strings for now. Needed for incomming filebrowser work.

===================================================================

M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface.c
M       source/blender/editors/interface/interface_intern.h
M       source/blender/editors/space_file/file_draw.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index 330484b..027a8f4 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -467,10 +467,11 @@ int     UI_but_return_value_get(uiBut *but);
 
 void    UI_but_drag_set_id(uiBut *but, struct ID *id);
 void    UI_but_drag_set_rna(uiBut *but, struct PointerRNA *ptr);
-void    UI_but_drag_set_path(uiBut *but, const char *path);
+void    UI_but_drag_set_path(uiBut *but, const char *path, const bool 
use_free);
 void    UI_but_drag_set_name(uiBut *but, const char *name);
 void    UI_but_drag_set_value(uiBut *but);
-void    UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct 
ImBuf *ima, float scale);
+void    UI_but_drag_set_image(
+                uiBut *but, const char *path, int icon, struct ImBuf *ima, 
float scale, const bool use_free);
 
 bool    UI_but_active_drop_name(struct bContext *C);
 bool    UI_but_active_drop_color(struct bContext *C);
diff --git a/source/blender/editors/interface/interface.c 
b/source/blender/editors/interface/interface.c
index d11c195..19b7803 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -753,6 +753,10 @@ static bool ui_but_update_from_old_block(const bContext 
*C, uiBlock *block, uiBu
                        BLI_strncpy(oldbut->strdata, but->strdata, 
sizeof(oldbut->strdata));
                }
 
+               if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+                       SWAP(void *, but->dragpoin, oldbut->dragpoin);
+               }
+
                BLI_remlink(&block->buttons, but);
                ui_but_free(C, but);
 
@@ -2520,6 +2524,10 @@ static void ui_but_free(const bContext *C, uiBut *but)
                IMB_freeImBuf((struct ImBuf *)but->poin);
        }
 
+       if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_freeN(but->dragpoin);
+       }
+
        BLI_assert(UI_butstore_is_registered(but->block, but) == false);
 
        MEM_freeN(but);
@@ -4046,24 +4054,43 @@ int UI_but_return_value_get(uiBut *but)
 void UI_but_drag_set_id(uiBut *but, ID *id)
 {
        but->dragtype = WM_DRAG_ID;
+       if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_SAFE_FREE(but->dragpoin);
+               but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+       }
        but->dragpoin = (void *)id;
 }
 
 void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
 {
        but->dragtype = WM_DRAG_RNA;
+       if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_SAFE_FREE(but->dragpoin);
+               but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+       }
        but->dragpoin = (void *)ptr;
 }
 
-void UI_but_drag_set_path(uiBut *but, const char *path)
+void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free)
 {
        but->dragtype = WM_DRAG_PATH;
+       if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_SAFE_FREE(but->dragpoin);
+               but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+       }
        but->dragpoin = (void *)path;
+       if (use_free) {
+               but->dragflag |= UI_BUT_DRAGPOIN_FREE;
+       }
 }
 
 void UI_but_drag_set_name(uiBut *but, const char *name)
 {
        but->dragtype = WM_DRAG_NAME;
+       if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_SAFE_FREE(but->dragpoin);
+               but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+       }
        but->dragpoin = (void *)name;
 }
 
@@ -4073,11 +4100,18 @@ void UI_but_drag_set_value(uiBut *but)
        but->dragtype = WM_DRAG_VALUE;
 }
 
-void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct 
ImBuf *imb, float scale)
+void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct 
ImBuf *imb, float scale, const bool use_free)
 {
        but->dragtype = WM_DRAG_PATH;
        ui_def_but_icon(but, icon, 0);  /* no flag UI_HAS_ICON, so icon doesnt 
draw in button */
+       if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+               MEM_SAFE_FREE(but->dragpoin);
+               but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+       }
        but->dragpoin = (void *)path;
+       if (use_free) {
+               but->dragflag |= UI_BUT_DRAGPOIN_FREE;
+       }
        but->imb = imb;
        but->imb_scale = scale;
 }
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index fc477d8..df554a2 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -129,6 +129,11 @@ typedef enum uiButExtraIconType {
        UI_BUT_ICONEXTRA_EYEDROPPER,
 } uiButExtraIconType;
 
+/* uiBut->dragflag */
+enum {
+       UI_BUT_DRAGPOIN_FREE = (1 << 0),
+};
+
 /* but->pie_dir */
 typedef enum RadialDirection {
        UI_RADIAL_NONE  = -1,
@@ -297,6 +302,7 @@ struct uiBut {
 
        /* Draggable data, type is WM_DRAG_... */
        char dragtype;
+       short dragflag;
        void *dragpoin;
        struct ImBuf *imb;
        float imb_scale;
diff --git a/source/blender/editors/space_file/file_draw.c 
b/source/blender/editors/space_file/file_draw.c
index 7863833..7f96321 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -296,7 +296,7 @@ static void file_draw_icon(uiBlock *block, const char 
*path, int sx, int sy, int
        but = uiDefIconBut(block, UI_BTYPE_LABEL, 0, icon, x, y, width, height, 
NULL, 0.0f, 0.0f, 0.0f, 0.0f, "");
 
        if (drag) {
-               UI_but_drag_set_path(but, path);
+               UI_but_drag_set_path(but, path, false);
        }
 }
 
@@ -411,7 +411,7 @@ static void file_draw_preview(uiBlock *block, struct 
direntry *file, int sx, int
        /* dragregion */
        if (drag) {
                but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, 
NULL, 0.0, 0.0, 0, 0, "");
-               UI_but_drag_set_image(but, file->path, get_file_icon(file), 
imb, scale);
+               UI_but_drag_set_image(but, file->path, get_file_icon(file), 
imb, scale, false);
        }
 
        glDisable(GL_BLEND);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to