Filewindow: restored some usability issues :)
(Andrea: Hope you're OK, I needed to test stuff, and 
file open was a pain!)

- F1: shows last saved/opened file now
- Enter key loads, ESC cancels
- Hilites on mousemove now show same theme colors as before
- Enabled intended roundbox draw (was added to UI api)
- Tweaked roundbox hilites to nicely surround text
- Text was drawing too close to collumn dividers
- Brought back missing glDisable(GL_BLEND), messed with draw
- On file-open, mouse position is used to show active file
This commit is contained in:
Ton Roosendaal
2009-01-28 11:27:25 +00:00
parent 5b14573d0b
commit 4a1a8271c1
5 changed files with 139 additions and 77 deletions

View File

@@ -89,38 +89,12 @@ enum {
static void do_file_buttons(bContext *C, void *arg, int event)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
switch(event) {
case B_FS_LOAD:
{
char name[FILE_MAX];
ED_screen_full_prevspace(C);
if(sfile->op) {
wmOperator *op= sfile->op;
/* if load .blend, all UI pointers after exec are invalid! */
/* but, operator can be freed still */
sfile->op = NULL;
BLI_strncpy(name, sfile->params->dir, sizeof(name));
strcat(name, sfile->params->file);
RNA_string_set(op->ptr, "filename", name);
op->type->exec(C, op);
WM_operator_free(op);
}
}
file_load_exec(C, NULL); /* file_ops.c */
break;
case B_FS_CANCEL:
if(sfile->op) {
WM_operator_free(sfile->op);
sfile->op = NULL;
}
ED_screen_full_prevspace(C);
file_cancel_exec(C, NULL); /* file_ops.c */
break;
}
}
@@ -203,15 +177,16 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
static void draw_tile(short sx, short sy, short width, short height, int colorid, int shade)
{
/* TODO: BIF_ThemeColor seems to need this to show the color, not sure why? - elubie */
glEnable(GL_BLEND);
glColor4ub(0, 0, 0, 100);
glDisable(GL_BLEND);
//glEnable(GL_BLEND);
//glColor4ub(0, 0, 0, 100);
//glDisable(GL_BLEND);
/* I think it was a missing glDisable() - ton */
UI_ThemeColorShade(colorid, shade);
uiSetRoundBox(15);
glRecti(sx, sy - height, sx + width, sy);
// glRecti(sx, sy - height, sx + width, sy);
// uiRoundBox(sx+TILE_BORDER_X, sy - sfile->prv_h - TILE_BORDER_Y*3 - U.fontsize, sx + sfile->prv_w + TILE_BORDER_X*3, sy, 6);
uiRoundBox(sx, sy - height, sx + width, sy, 6);
}
static float shorten_string(char* string, float w)
@@ -367,10 +342,10 @@ void file_draw_previews(const bContext *C, ARegion *ar)
if (params->active_file == i) {
colorid = TH_ACTIVE;
draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid,0);
draw_tile(sx - 1, sy, sfile->tile_w + 1, sfile->tile_h, colorid,0);
} else if (file->flags & ACTIVE) {
colorid = TH_HILITE;
draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid,0);
draw_tile(sx - 1, sy, sfile->tile_w + 1, sfile->tile_h, colorid,0);
} else {
colorid = TH_BACK;
draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid, -5);
@@ -424,18 +399,18 @@ void file_draw_previews(const bContext *C, ARegion *ar)
// glaDrawPixelsSafe((float)sx+8 + dx, (float)sy - imgwidth + dy - 8, imb->x, imb->y, imb->x, GL_RGBA, GL_UNSIGNED_BYTE, imb->rect);
glColor4f(1.0, 1.0, 1.0, 1.0);
glaDrawPixelsTex((float)sx + dx, (float)sy - sfile->prv_h + dy, imb->x, imb->y,GL_UNSIGNED_BYTE, imb->rect);
// glDisable(GL_BLEND);
glDisable(GL_BLEND);
imb = 0;
}
#if 0
}
#endif
if (type == FILE_MAIN) {
glColor3f(1.0f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
else {
if (S_ISDIR(file->type)) {
glColor3f(1.0f, 1.0f, 0.9f);
glColor4f(1.0f, 1.0f, 0.9f, 1.0f);
}
else if (file->flags & IMAGEFILE) {
UI_ThemeColor(TH_SEQ_IMAGE);
@@ -506,16 +481,17 @@ void file_draw_list(const bContext *C, ARegion *ar)
for (i=offset; (i < numfiles); ++i)
{
sy = ar->v2d.tot.ymax-sfile->tile_border_y - (i%rows)*(sfile->tile_h+sfile->tile_border_y);
sx = ar->v2d.tot.xmin +sfile->tile_border_x + (i/rows)*(sfile->tile_w+sfile->tile_border_x);
sx = 2 + ar->v2d.tot.xmin +sfile->tile_border_x + (i/rows)*(sfile->tile_w+sfile->tile_border_x);
file = filelist_file(files, i);
if (params->active_file == i) {
colorid = TH_ACTIVE;
draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid,0);
if (file->flags & ACTIVE) colorid= TH_HILITE;
else colorid = TH_BACK;
draw_tile(sx, sy-3, sfile->tile_w, sfile->tile_h, colorid,20);
} else if (file->flags & ACTIVE) {
colorid = TH_HILITE;
draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid,0);
draw_tile(sx, sy-3, sfile->tile_w, sfile->tile_h, colorid,0);
} else {
/*
colorid = TH_PANEL;
@@ -523,11 +499,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
*/
}
if (type == FILE_MAIN) {
glColor3f(1.0f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
else {
if (S_ISDIR(file->type)) {
glColor3f(1.0f, 1.0f, 0.9f);
glColor4f(1.0f, 1.0f, 0.9f, 1.0f);
}
else if (file->flags & IMAGEFILE) {
UI_ThemeColor(TH_SEQ_IMAGE);
@@ -550,7 +526,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
}
sw = UI_GetStringWidth(G.font, file->size, 0);
file_draw_string(sx, sy, file->relname, sfile->tile_w - sw - 2, sfile->tile_h);
file_draw_string(sx, sy, file->relname, sfile->tile_w - sw - 5, sfile->tile_h);
file_draw_string(sx + sfile->tile_w - sw, sy, file->size, sfile->tile_w - sw, sfile->tile_h);
}
}
@@ -584,9 +560,9 @@ void file_draw_fsmenu(const bContext *C, ARegion *ar)
if (params->active_bookmark == i ) {
glColor4ub(0, 0, 0, 100);
UI_ThemeColor(TH_HILITE);
// uiSetRoundBox(15);
// uiRoundBox(simasel->bookmarkrect.xmin + TILE_BORDER_X - 1, sy - linestep*0.25, simasel->bookmarkrect.xmax - TILE_BORDER_X + 1, sy + linestep*0.75, 6);
glRecti(sx, sy - linestep, sx + bmwidth, sy);
uiSetRoundBox(15);
uiRoundBox(sx, sy - linestep, sx + bmwidth, sy, 6);
// glRecti(sx, sy - linestep, sx + bmwidth, sy);
UI_ThemeColor(TH_TEXT_HI);
} else {
UI_ThemeColor(TH_TEXT);

View File

@@ -47,12 +47,20 @@ void file_draw_fsmenu(const bContext *C, ARegion *ar);
/* file_ops.h */
struct wmOperatorType;
struct wmOperator;
struct wmEvent;
void ED_FILE_OT_highlight(struct wmOperatorType *ot);
void ED_FILE_OT_select(struct wmOperatorType *ot);
void ED_FILE_OT_select_all(struct wmOperatorType *ot);
void ED_FILE_OT_border_select(struct wmOperatorType *ot);
void ED_FILE_OT_select_bookmark(struct wmOperatorType *ot);
void ED_FILE_OT_loadimages(struct wmOperatorType *ot);
void ED_FILE_OT_load(struct wmOperatorType *ot);
void ED_FILE_OT_cancel(struct wmOperatorType *ot);
int file_load_exec(bContext *C, struct wmOperator *unused);
int file_cancel_exec(bContext *C, struct wmOperator *unused);
int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my);
#endif /* ED_FILE_INTERN_H */

View File

@@ -398,38 +398,39 @@ void ED_FILE_OT_loadimages(wmOperatorType *ot)
/* api callbacks */
ot->invoke= loadimages_invoke;
ot->poll= ED_operator_areaactive;
ot->poll= ED_operator_file_active;
}
int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
{
FileSelectParams* params;
int numfiles, actfile;
if(sfile==NULL || sfile->files==NULL) return 0;
numfiles = filelist_numfiles(sfile->files);
params = ED_fileselect_get_params(sfile);
if (params->display) {
actfile = find_file_mouse_hor(sfile, ar, mx , my);
} else {
actfile = find_file_mouse_vert(sfile, ar, mx, my);
}
if (actfile >= 0 && actfile < numfiles ) {
params->active_file=actfile;
return 1;
}
return 0;
}
static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
FileSelectParams* params;
short x, y;
int actfile;
int numfiles;
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if (!sfile || !sfile->files) return OPERATOR_FINISHED;
numfiles = filelist_numfiles(sfile->files);
x = event->x - ar->winrct.xmin;
y = event->y - ar->winrct.ymin;
params = ED_fileselect_get_params(sfile);
if (params->display) {
actfile = find_file_mouse_hor(sfile, ar,x , y);
} else {
actfile = find_file_mouse_vert(sfile, ar, x, y);
}
if (actfile >= 0 && actfile < numfiles )
{
params->active_file=actfile;
ED_area_tag_redraw(sa);
if( file_hilight_set(sfile, ar, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin)) {
ED_area_tag_redraw(CTX_wm_area(C));
}
return OPERATOR_FINISHED;
@@ -443,6 +444,70 @@ void ED_FILE_OT_highlight(struct wmOperatorType *ot)
/* api callbacks */
ot->invoke= file_highlight_invoke;
ot->poll= ED_operator_areaactive;
ot->poll= ED_operator_file_active;
}
int file_cancel_exec(bContext *C, wmOperator *unused)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
if(sfile->op) {
WM_operator_free(sfile->op);
sfile->op = NULL;
}
ED_screen_full_prevspace(C);
return OPERATOR_FINISHED;
}
void ED_FILE_OT_cancel(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= "Cancel File Load";
ot->idname= "ED_FILE_OT_cancel";
/* api callbacks */
ot->exec= file_cancel_exec;
ot->poll= ED_operator_file_active;
}
int file_load_exec(bContext *C, wmOperator *unused)
{
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
char name[FILE_MAX];
ED_screen_full_prevspace(C);
if(sfile->op) {
wmOperator *op= sfile->op;
/* if load .blend, all UI pointers after exec are invalid! */
/* but, operator can be freed still */
sfile->op = NULL;
BLI_strncpy(name, sfile->params->dir, sizeof(name));
strcat(name, sfile->params->file);
RNA_string_set(op->ptr, "filename", name);
op->type->exec(C, op);
WM_operator_free(op);
}
return OPERATOR_FINISHED;
}
void ED_FILE_OT_load(struct wmOperatorType *ot)
{
/* identifiers */
ot->name= "Load File";
ot->idname= "ED_FILE_OT_load";
/* api callbacks */
ot->exec= file_load_exec;
ot->poll= ED_operator_file_active;
}

View File

@@ -195,6 +195,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
sfile->files = filelist_new();
filelist_setdir(sfile->files, params->dir);
filelist_settype(sfile->files, params->type);
params->active_file = -1; // added this so it opens nicer (ton)
}
if (filelist_empty(sfile->files))
@@ -213,15 +214,21 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
if(params->sort!=FILE_SORTALPHA) filelist_sort(sfile->files, params->sort);
}
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
file_calc_previews(C,ar);
/* sets tile/border settings in sfile */
file_calc_previews(C, ar);
/* on first read, find active file */
if (params->active_file == -1) {
wmEvent *event= CTX_wm_window(C)->eventstate;
file_hilight_set(sfile, ar, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin);
}
/* data... */
UI_view2d_view_ortho(C, v2d);
@@ -250,6 +257,8 @@ void file_operatortypes(void)
WM_operatortype_append(ED_FILE_OT_select_bookmark);
WM_operatortype_append(ED_FILE_OT_loadimages);
WM_operatortype_append(ED_FILE_OT_highlight);
WM_operatortype_append(ED_FILE_OT_load);
WM_operatortype_append(ED_FILE_OT_cancel);
}
void file_keymap(struct wmWindowManager *wm)
@@ -259,6 +268,9 @@ void file_keymap(struct wmWindowManager *wm)
WM_keymap_add_item(keymap, "ED_FILE_OT_select_all", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ED_FILE_OT_border_select", BKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ED_FILE_OT_highlight", MOUSEMOVE, KM_ANY, 0, 0);
WM_keymap_add_item(keymap, "ED_FILE_OT_load", RETKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ED_FILE_OT_cancel", ESCKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ED_FILE_OT_loadimages", TIMER1, KM_ANY, KM_ANY, 0);
keymap= WM_keymap_listbase(wm, "FileBookmark", SPACE_FILE, 0);

View File

@@ -368,7 +368,8 @@ static int wm_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
/* settings for filebrowser */
sfile= (SpaceFile*)CTX_wm_space_data(C);
sfile->op = op;
ED_fileselect_set_params(sfile, FILE_BLENDER, "Load", "C:\\", 0, 0, 0);
// XXX replace G.sce
ED_fileselect_set_params(sfile, FILE_BLENDER, "Load As", G.sce, 0, 0, 0);
/* screen and area have been reset already in ED_screen_full_newspace */