2.5
authorTon Roosendaal <ton@blender.org>
Wed, 28 Jan 2009 11:27:25 +0000 (11:27 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 28 Jan 2009 11:27:25 +0000 (11:27 +0000)
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

source/blender/editors/space_file/file_draw.c
source/blender/editors/space_file/file_intern.h
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/space_file.c
source/blender/windowmanager/intern/wm_operators.c

index 604f5d505fd2951e640116ef4566970e88a17b1e..4f34aac70c056f7e0f31546893063d12d0b69071 100644 (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);
index a551832772b7c3dd3ba73443a97ee81c31cf50de..4f9e6681e6d9b161e8a79141948be16b8a7fa212 100644 (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 */
 
index 4c2b7d59368d71bd9c95dc1effc129ceb28d5acb..3f057e8a7f44731487ead9f4c061b6dc79e27b4b 100644 (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;
 }
 
-
-static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
+int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
 {
-       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);
+       int numfiles, actfile;
+       
+       if(sfile==NULL || sfile->files==NULL) return 0;
        
-       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);
+               actfile = find_file_mouse_hor(sfile, ar, mx , my);
        } else {
-               actfile = find_file_mouse_vert(sfile, ar, x, y);
+               actfile = find_file_mouse_vert(sfile, ar, mx, my);
        }
-
-       if (actfile >= 0 && actfile < numfiles )
-       {
+       
+       if (actfile >= 0 && actfile < numfiles ) {
                params->active_file=actfile;
-               ED_area_tag_redraw(sa);
+               return 1;
+       }
+       return 0;
+}
+
+static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ARegion *ar= CTX_wm_region(C);
+       SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+       
+       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;
+}
+
+
+
index e90436a0c59d954c5fa10605c64892acdae3d482..828661933995dfeb25c3265c152ca7b3566904c0 100644 (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);
index fe9fe2e29a4f918e7a08776943eb98cf61b6346d..4aa363c78f5e230e3451aaece32cacfee97d2f4c 100644 (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 */