Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2010-01-26 21:18:21 +0300
committerTon Roosendaal <ton@blender.org>2010-01-26 21:18:21 +0300
commitb119ce5fcc91466c6aeb1232e8bf4dca401adaed (patch)
tree1e3e7d0fde9aaaf1d4f622c518795c3aa9a366b0 /source/blender/editors/space_file
parent722f57ca75a7c4fb77e07d9ee43d5ea79c02c04b (diff)
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :) ** Drag works as follows: - drag-able items are defined by the standard interface ui toolkit - each button can get this feature, via uiButSetDragXXX(but, ...). There are calls to define drag-able images, ID blocks, RNA paths, file paths, and so on. By default you drag an icon, exceptionally an ImBuf - Drag items are registered centrally in the WM, it allows more drag items simultaneous too, but not implemented ** Drop works as follows: - On mouse release, and if drag items exist in the WM, it converts the mouse event to an EVT_DROP type. This event then gets the full drag info as customdata - drop regions are defined with WM_dropbox_add(), similar to keymaps you can make a "drop map" this way, which become 'drop map handlers' in the queues. - next to that the UI kit handles some common button types (like accepting ID or names) to be catching a drop event too. - Every "drop box" has two callbacks: - poll() = check if the event drag data is relevant for this box - copy() = fill in custom properties in the dropbox to initialize an operator - The dropbox handler then calls its standard Operator with its dropbox properties. ** Currently implemented Drag items: - ID icons in browse buttons - ID icons in context menu of properties region - ID icons in outliner and rna viewer - FileBrowser icons - FileBrowser preview images Drag-able icons are subtly visualized by making them brighter a bit on mouse-over. In case the icon is a button or UI element too (most cases), the drag-able feature will make the item react to mouse-release instead of mouse-press. Drop options: - UI buttons: ID and text buttons (paste name) - View3d: Object ID drop copies object - View3d: Material ID drop assigns to object under cursor - View3d: Image ID drop assigns to object UV texture under cursor - Sequencer: Path drop will add either Image or Movie strip - Image window: Path drop will open image ** Drag and drop Notes: - Dropping into another Blender window (from same application) works too. I've added code that passes on mousemoves and clicks to other windows, without activating them though. This does make using multi-window Blender a bit friendler. - Dropping a file path to an image, is not the same as dropping an Image ID... keep this in mind. Sequencer for example wants paths to be dropped, textures in 3d window wants an Image ID. - Although drop boxes could be defined via Python, I suggest they're part of the UI and editor design (= how we want an editor to work), and not default offered configurable like keymaps. - At the moment only one item can be dragged at a time. This is for several reasons.... For one, Blender doesn't have a well defined uniform way to define "what is selected" (files, outliner items, etc). Secondly there's potential conflicts on what todo when you drop mixed drag sets on spots. All undefined stuff... nice for later. - Example to bypass the above: a collection of images that form a strip, should be represented in filewindow as a single sequence anyway. This then will fit well and gets handled neatly by design. - Another option to check is to allow multiple options per drop... it could show the operator as a sort of menu, allowing arrow or scrollwheel to choose. For time being I'd prefer to try to design a singular drop though, just offer only one drop action per data type on given spots. - What does work already, but a tad slow, is to use a function that detects an object (type) under cursor, so a drag item's option can be further refined (like drop object on object = parent). (disabled) ** More notes - Added saving for Region layouts (like split points for toolbar) - Label buttons now handle mouse over - File list: added full path entry for drop feature. - Filesel bugfix: wm_operator_exec() got called there and fully handled, while WM event code tried same. Added new OPERATOR_HANDLED flag for this. Maybe python needs it too? - Cocoa: added window move event, so multi-win setups work OK (didnt save). - Interface_handlers.c: removed win->active - Severe area copy bug: area handlers were not set to NULL - Filesel bugfix: next/prev folder list was not copied on area copies ** Leftover todos - Cocoa windows seem to hang on cases still... needs check - Cocoa 'draw overlap' swap doesn't work - Cocoa window loses focus permanently on using Spotlight (for these reasons, makefile building has Carbon as default atm) - ListView templates in UI cannot become dragged yet, needs review... it consists of two overlapping UI elements, preventing handling icon clicks. - There's already Ghost library code to handle dropping from OS into Blender window. I've noticed this code is unfinished for Macs, but seems to be complete for Windows. Needs test... currently, an external drop event will print in console when succesfully delivered to Blender's WM.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r--source/blender/editors/space_file/file_draw.c136
-rw-r--r--source/blender/editors/space_file/file_ops.c2
-rw-r--r--source/blender/editors/space_file/filelist.c28
-rw-r--r--source/blender/editors/space_file/filelist.h1
-rw-r--r--source/blender/editors/space_file/space_file.c10
5 files changed, 103 insertions, 74 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index af0bf9413df..5db17d8bc7c 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -320,8 +320,9 @@ static int get_file_icon(struct direntry *file)
return ICON_FILE_BLANK;
}
-static void file_draw_icon(int sx, int sy, int icon, int width, int height)
+static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon, int width, int height)
{
+ uiBut *but;
float x,y;
float alpha=1.0f;
@@ -329,10 +330,9 @@ static void file_draw_icon(int sx, int sy, int icon, int width, int height)
y = (float)(sy-height);
if (icon == ICON_FILE_BLANK) alpha = 0.375f;
-
- glEnable(GL_BLEND);
-
- UI_icon_draw_aspect(x, y, icon, 1.f, alpha);
+
+ but= uiDefIconBut(block, LABEL, 0, icon, x, y, width, height, NULL, 0.0, 0.0, 0, 0, "");
+ uiButSetDragPath(but, path);
}
@@ -364,62 +364,67 @@ void file_calc_previews(const bContext *C, ARegion *ar)
UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height+V2D_SCROLL_HEIGHT);
}
-static void file_draw_preview(int sx, int sy, ImBuf *imb, FileLayout *layout, short dropshadow)
+static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int sy, ImBuf *imb, FileLayout *layout, short dropshadow)
{
if (imb) {
- float fx, fy;
- float dx, dy;
- int xco, yco;
- float scaledx, scaledy;
- float scale;
- int ex, ey;
-
- if ( (imb->x > layout->prv_w) || (imb->y > layout->prv_h) ) {
- if (imb->x > imb->y) {
- scaledx = (float)layout->prv_w;
- scaledy = ( (float)imb->y/(float)imb->x )*layout->prv_w;
- scale = scaledx/imb->x;
- }
- else {
- scaledy = (float)layout->prv_h;
- scaledx = ( (float)imb->x/(float)imb->y )*layout->prv_h;
- scale = scaledy/imb->y;
- }
- } else {
- scaledx = (float)imb->x;
- scaledy = (float)imb->y;
- scale = 1.0;
+ uiBut *but;
+ float fx, fy;
+ float dx, dy;
+ int xco, yco;
+ float scaledx, scaledy;
+ float scale;
+ int ex, ey;
+
+ if ( (imb->x > layout->prv_w) || (imb->y > layout->prv_h) ) {
+ if (imb->x > imb->y) {
+ scaledx = (float)layout->prv_w;
+ scaledy = ( (float)imb->y/(float)imb->x )*layout->prv_w;
+ scale = scaledx/imb->x;
}
- ex = (int)scaledx;
- ey = (int)scaledy;
- fx = ((float)layout->prv_w - (float)ex)/2.0f;
- fy = ((float)layout->prv_h - (float)ey)/2.0f;
- dx = (fx + 0.5f + layout->prv_border_x);
- dy = (fy + 0.5f - layout->prv_border_y);
- xco = (float)sx + dx;
- yco = (float)sy - layout->prv_h + dy;
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- /* shadow */
- if (dropshadow)
- uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
-
- glEnable(GL_BLEND);
-
- /* the image */
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
-
- /* border */
- if (dropshadow) {
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
- fdrawbox(xco, yco, xco + ex, yco + ey);
+ else {
+ scaledy = (float)layout->prv_h;
+ scaledx = ( (float)imb->x/(float)imb->y )*layout->prv_h;
+ scale = scaledy/imb->y;
}
-
- glDisable(GL_BLEND);
- imb = 0;
+ } else {
+ scaledx = (float)imb->x;
+ scaledy = (float)imb->y;
+ scale = 1.0;
+ }
+ ex = (int)scaledx;
+ ey = (int)scaledy;
+ fx = ((float)layout->prv_w - (float)ex)/2.0f;
+ fy = ((float)layout->prv_h - (float)ey)/2.0f;
+ dx = (fx + 0.5f + layout->prv_border_x);
+ dy = (fy + 0.5f - layout->prv_border_y);
+ xco = (float)sx + dx;
+ yco = (float)sy - layout->prv_h + dy;
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ /* shadow */
+ if (dropshadow)
+ uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
+
+ glEnable(GL_BLEND);
+
+ /* the image */
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
+
+ /* border */
+ if (dropshadow) {
+ glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+ fdrawbox(xco, yco, xco + ex, yco + ey);
}
+
+ /* dragregion */
+ but= uiDefBut(block, LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
+ uiButSetDragImage(but, file->path, get_file_icon(file), imb, scale);
+
+ glDisable(GL_BLEND);
+ imb = 0;
+ }
}
static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
@@ -491,6 +496,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
struct FileList* files = sfile->files;
struct direntry *file;
ImBuf *imb;
+ uiBlock *block = uiBeginBlock(C, ar, "FileNames", UI_EMBOSS);
int numfiles;
int numfiles_layout;
int colorid = 0;
@@ -526,10 +532,10 @@ void file_draw_list(const bContext *C, ARegion *ar)
if (params->active_file == i) {
if (file->flags & ACTIVE) colorid= TH_HILITE;
else colorid = TH_BACK;
- draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,20);
+ draw_tile(sx, sy-3, layout->tile_w+4, sfile->layout->tile_h+layout->tile_border_y, colorid,20);
} else if (file->flags & ACTIVE) {
colorid = TH_HILITE;
- draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,0);
+ draw_tile(sx, sy-3, layout->tile_w+4, sfile->layout->tile_h+layout->tile_border_y, colorid,0);
}
}
@@ -546,11 +552,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
is_icon = 1;
}
- file_draw_preview(sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE));
+ file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE));
} else {
- file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
- spos += ICON_DEFAULT_WIDTH + 4;
+ file_draw_icon(block, file->path, spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
+ spos += ICON_DEFAULT_WIDTH + 4;
}
UI_ThemeColor4(TH_TEXT);
@@ -558,15 +564,13 @@ void file_draw_list(const bContext *C, ARegion *ar)
sw = file_string_width(file->relname);
if (file->flags & EDITING) {
int but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
- uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS);
+
uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3,
but_width, layout->textheight*2, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
uiButSetRenameFunc(but, renamebutton_cb, file);
if ( 0 == uiButActiveOnly(C, block, but)) {
file->flags &= ~EDITING;
}
- uiEndBlock(C, block);
- uiDrawBlock(C, block);
} else {
float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw;
file_draw_string(spos, sy, file->relname, name_width, layout->tile_h, FILE_SHORTEN_END);
@@ -621,6 +625,10 @@ void file_draw_list(const bContext *C, ARegion *ar)
if (!sfile->loadimage_timer)
sfile->loadimage_timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */
+
+ uiEndBlock(C, block);
+ uiDrawBlock(C, block);
+
}
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 647c1d2be18..93230c79b19 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -588,7 +588,7 @@ int file_exec(bContext *C, wmOperator *exec_op)
RNA_string_set(op->ptr, "filename", sfile->params->file);
BLI_strncpy(name, sfile->params->dir, sizeof(name));
RNA_string_set(op->ptr, "directory", name);
- strcat(name, sfile->params->file);
+ strcat(name, sfile->params->file); // XXX unsafe
if(RNA_struct_find_property(op->ptr, "relative_paths"))
if(RNA_boolean_get(op->ptr, "relative_paths"))
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 7ccaa6e2789..dbe9417fd2a 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -440,18 +440,36 @@ int folderlist_clear_next(struct SpaceFile *sfile)
return 1;
}
+/* not listbase itself */
void folderlist_free(ListBase* folderlist)
{
FolderList *folder;
if (folderlist){
- for(folder= folderlist->last; folder; folder= folderlist->last) {
- MEM_freeN(folder->foldername);
- BLI_freelinkN(folderlist, folder);
- }
+ for(folder= folderlist->first; folder; folder= folder->next)
+ MEM_freeN(folder->foldername);
+ BLI_freelistN(folderlist);
}
folderlist= NULL;
}
+ListBase *folderlist_duplicate(ListBase* folderlist)
+{
+
+ if (folderlist) {
+ ListBase *folderlistn= MEM_callocN(sizeof(ListBase), "copy folderlist");
+ FolderList *folder;
+
+ BLI_duplicatelist(folderlistn, folderlist);
+
+ for(folder= folderlistn->first; folder; folder= folder->next) {
+ folder->foldername= MEM_dupallocN(folder->foldername);
+ }
+ return folderlistn;
+ }
+ return NULL;
+}
+
+
static void filelist_read_main(struct FileList* filelist);
static void filelist_read_library(struct FileList* filelist);
static void filelist_read_dir(struct FileList* filelist);
@@ -499,6 +517,8 @@ void filelist_free(struct FileList* filelist)
filelist->filelist[i].image = 0;
if (filelist->filelist[i].relname)
MEM_freeN(filelist->filelist[i].relname);
+ if (filelist->filelist[i].path)
+ MEM_freeN(filelist->filelist[i].path);
filelist->filelist[i].relname = 0;
if (filelist->filelist[i].string)
MEM_freeN(filelist->filelist[i].string);
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index a8d909f899e..157a2f5cd52 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -81,6 +81,7 @@ void filelist_hideparent(struct FileList* filelist, short hide);
struct ListBase * folderlist_new();
void folderlist_free(struct ListBase* folderlist);
+struct ListBase * folderlist_duplicate(ListBase* folderlist);
void folderlist_popdir(struct ListBase* folderlist, char *dir);
void folderlist_pushdir(struct ListBase* folderlist, const char *dir);
int folderlist_clear_next(struct SpaceFile* sfile);
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index bf18c938a8a..e73a8c9a7fa 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -173,10 +173,10 @@ static SpaceLink *file_duplicate(SpaceLink *sl)
if (sfileo->params)
sfilen->files = filelist_new(sfileo->params->type);
if(sfileo->folders_prev)
- sfilen->folders_prev = MEM_dupallocN(sfileo->folders_prev);
+ sfilen->folders_prev = folderlist_duplicate(sfileo->folders_prev);
if(sfileo->folders_next)
- sfilen->folders_next = MEM_dupallocN(sfileo->folders_next);
+ sfilen->folders_next = folderlist_duplicate(sfileo->folders_next);
if(sfileo->params) {
sfilen->params= MEM_dupallocN(sfileo->params);
@@ -531,7 +531,7 @@ void ED_spacetype_file(void)
/* regions: header */
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
art->regionid = RGN_TYPE_HEADER;
- art->minsizey= HEADERY;
+ art->prefsizey= HEADERY;
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
art->init= file_header_area_init;
art->draw= file_header_area_draw;
@@ -541,7 +541,7 @@ void ED_spacetype_file(void)
/* regions: ui */
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
art->regionid = RGN_TYPE_UI;
- art->minsizey= 60;
+ art->prefsizey= 60;
art->keymapflag= ED_KEYMAP_UI;
art->listener= file_ui_area_listener;
art->init= file_ui_area_init;
@@ -551,7 +551,7 @@ void ED_spacetype_file(void)
/* regions: channels (directories) */
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
art->regionid = RGN_TYPE_CHANNELS;
- art->minsizex= 240;
+ art->prefsizex= 240;
art->keymapflag= ED_KEYMAP_UI;
art->listener= file_channel_area_listener;
art->init= file_channel_area_init;