2009-01-06 14:42:54 +00:00
|
|
|
/**
|
|
|
|
* $Id:
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2009-01-06 16:15:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2009-03-14 05:21:57 +00:00
|
|
|
#include "BLI_dynstr.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "BLI_storage_types.h"
|
|
|
|
#ifdef WIN32
|
|
|
|
#include "BLI_winstuff.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "BKE_colortools.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
2009-05-14 18:54:41 +00:00
|
|
|
#include "BLF_api.h"
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
2009-01-06 16:47:01 +00:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
#include "ED_datafiles.h"
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2009-01-06 18:14:37 +00:00
|
|
|
#include "ED_fileselect.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_interface_icons.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "fsmenu.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
|
|
|
|
#include "file_intern.h" // own include
|
|
|
|
|
|
|
|
/* ui geometry */
|
2009-03-09 08:31:45 +00:00
|
|
|
#define IMASEL_BUTTONS_HEIGHT 40
|
2009-01-06 14:42:54 +00:00
|
|
|
#define TILE_BORDER_X 8
|
|
|
|
#define TILE_BORDER_Y 8
|
|
|
|
|
|
|
|
/* button events */
|
|
|
|
enum {
|
|
|
|
B_REDR = 0,
|
2009-02-14 14:25:48 +00:00
|
|
|
B_FS_EXEC,
|
2009-01-06 14:42:54 +00:00
|
|
|
B_FS_CANCEL,
|
2009-02-10 17:53:10 +00:00
|
|
|
B_FS_PARENT,
|
2009-01-06 14:42:54 +00:00
|
|
|
} eFile_ButEvents;
|
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
static void do_file_buttons(bContext *C, void *arg, int event)
|
|
|
|
{
|
|
|
|
switch(event) {
|
2009-02-14 14:25:48 +00:00
|
|
|
case B_FS_EXEC:
|
|
|
|
file_exec(C, NULL); /* file_ops.c */
|
2009-01-06 14:42:54 +00:00
|
|
|
break;
|
|
|
|
case B_FS_CANCEL:
|
2009-01-28 11:27:25 +00:00
|
|
|
file_cancel_exec(C, NULL); /* file_ops.c */
|
2009-01-06 14:42:54 +00:00
|
|
|
break;
|
2009-02-10 17:53:10 +00:00
|
|
|
case B_FS_PARENT:
|
|
|
|
file_parent_exec(C, NULL); /* file_ops.c */
|
|
|
|
break;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-17 13:11:09 +00:00
|
|
|
/* note; this function uses pixelspace (0, 0, winx, winy), not view2d */
|
2009-01-06 14:42:54 +00:00
|
|
|
void file_draw_buttons(const bContext *C, ARegion *ar)
|
|
|
|
{
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
2009-01-08 18:47:16 +00:00
|
|
|
FileSelectParams* params = ED_fileselect_get_params(sfile);
|
2009-01-06 14:42:54 +00:00
|
|
|
uiBlock *block;
|
|
|
|
int loadbutton;
|
|
|
|
char name[20];
|
|
|
|
float slen;
|
|
|
|
int filebuty1, filebuty2;
|
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
float xmin = 8;
|
2009-02-17 13:11:09 +00:00
|
|
|
float xmax = ar->winx - 10;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
filebuty1= ar->winy - IMASEL_BUTTONS_HEIGHT - 12;
|
|
|
|
filebuty2= filebuty1 + IMASEL_BUTTONS_HEIGHT/2 + 4;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
/* HEADER */
|
2009-02-17 13:11:09 +00:00
|
|
|
sprintf(name, "win %p", ar);
|
2.5
More cleanup!
- removed old UI font completely, including from uiBeginBlock
- emboss hints for uiBlock only have three types now;
Regular, Pulldown, or "Nothing" (only icon/text)
- removed old font path from Userdef
- removed all old button theme hinting
- removed old "auto block" to merge buttons in groups
(was only in use for radiosity buttons)
And went over all warnings. One hooray for make giving clean output :)
Well, we need uniform definitions for warnings, so people at least fix
them... here's the real bad bugs I found:
- in mesh code, a call to editmesh mixed *em and *me
- in armature, ED_util.h was not included, so no warnings for wrong call
to ED_undo_push()
- The extern Py api .h was not included in the bpy_interface.c, showing
a several calls using different args.
Further just added the missing includes, and removed unused vars.
2009-04-14 15:59:52 +00:00
|
|
|
block = uiBeginBlock(C, ar, name, UI_EMBOSS);
|
2009-01-06 14:42:54 +00:00
|
|
|
uiBlockSetHandleFunc(block, do_file_buttons, NULL);
|
|
|
|
|
|
|
|
/* XXXX
|
|
|
|
uiSetButLock( filelist_gettype(simasel->files)==FILE_MAIN && simasel->returnfunc, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* space available for load/save buttons? */
|
2009-04-10 16:30:28 +00:00
|
|
|
slen = UI_GetStringWidth(sfile->params->title);
|
|
|
|
loadbutton= slen > 60 ? slen + 20 : MAX2(80, 20+UI_GetStringWidth(params->title));
|
2009-02-17 13:11:09 +00:00
|
|
|
if(ar->winx > loadbutton+20) {
|
2009-01-06 19:22:29 +00:00
|
|
|
if(params->title[0]==0) {
|
2009-01-06 14:42:54 +00:00
|
|
|
loadbutton= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loadbutton= 0;
|
|
|
|
}
|
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+2, filebuty1, xmax-xmin-loadbutton-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
|
|
|
uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+2, filebuty2, xmax-xmin-loadbutton-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
if(loadbutton) {
|
2009-02-14 14:25:48 +00:00
|
|
|
uiDefBut(block, BUT, B_FS_EXEC, params->title, xmax-loadbutton, filebuty2, loadbutton, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
2009-01-06 14:42:54 +00:00
|
|
|
uiDefBut(block, BUT, B_FS_CANCEL, "Cancel", xmax-loadbutton, filebuty1, loadbutton, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
uiEndBlock(C, block);
|
|
|
|
uiDrawBlock(C, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-18 18:24:11 +00:00
|
|
|
static void draw_tile(short sx, short sy, short width, short height, int colorid, int shade)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
|
|
|
/* TODO: BIF_ThemeColor seems to need this to show the color, not sure why? - elubie */
|
2009-01-28 11:27:25 +00:00
|
|
|
//glEnable(GL_BLEND);
|
|
|
|
//glColor4ub(0, 0, 0, 100);
|
|
|
|
//glDisable(GL_BLEND);
|
|
|
|
/* I think it was a missing glDisable() - ton */
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-01-18 18:24:11 +00:00
|
|
|
UI_ThemeColorShade(colorid, shade);
|
2009-01-06 14:42:54 +00:00
|
|
|
uiSetRoundBox(15);
|
2009-01-28 11:27:25 +00:00
|
|
|
uiRoundBox(sx, sy - height, sx + width, sy, 6);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-14 05:21:57 +00:00
|
|
|
#define FILE_SHORTEN_END 0
|
|
|
|
#define FILE_SHORTEN_FRONT 1
|
2009-03-10 23:14:41 +00:00
|
|
|
|
|
|
|
static float shorten_string(char* string, float w, int flag)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-03-10 23:14:41 +00:00
|
|
|
char temp[FILE_MAX];
|
2009-01-06 14:42:54 +00:00
|
|
|
short shortened = 0;
|
|
|
|
float sw = 0;
|
2009-03-10 23:14:41 +00:00
|
|
|
float pad = 0;
|
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(string);
|
2009-03-10 23:14:41 +00:00
|
|
|
if (flag == FILE_SHORTEN_FRONT) {
|
|
|
|
char *s = string;
|
|
|
|
BLI_strncpy(temp, "...", 4);
|
2009-05-14 18:08:14 +00:00
|
|
|
pad = file_string_width(temp);
|
2009-05-26 18:54:39 +00:00
|
|
|
while (s && *s && (w > 0) && (sw+pad>w)) {
|
2009-03-10 23:14:41 +00:00
|
|
|
s++;
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(s);
|
2009-03-10 23:14:41 +00:00
|
|
|
shortened = 1;
|
|
|
|
}
|
|
|
|
if (shortened) {
|
|
|
|
int slen = strlen(s);
|
|
|
|
BLI_strncpy(temp+3, s, slen+1);
|
|
|
|
temp[slen+4] = '\0';
|
|
|
|
BLI_strncpy(string, temp, slen+4);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *s = string;
|
2009-05-26 18:54:39 +00:00
|
|
|
if (w>0) {
|
|
|
|
while (sw>w) {
|
|
|
|
int slen = strlen(string);
|
|
|
|
string[slen-1] = '\0';
|
|
|
|
sw = file_string_width(s);
|
|
|
|
shortened = 1;
|
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
}
|
|
|
|
if (shortened) {
|
|
|
|
int slen = strlen(string);
|
|
|
|
if (slen > 3) {
|
|
|
|
BLI_strncpy(string+slen-3, "...", 4);
|
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
static int get_file_icon(struct direntry *file)
|
|
|
|
{
|
|
|
|
if (file->type & S_IFDIR)
|
|
|
|
return ICON_FILE_FOLDER;
|
|
|
|
else if (file->flags & BLENDERFILE)
|
|
|
|
return ICON_FILE_BLEND;
|
|
|
|
else if (file->flags & IMAGEFILE)
|
|
|
|
return ICON_FILE_IMAGE;
|
|
|
|
else if (file->flags & MOVIEFILE)
|
|
|
|
return ICON_FILE_MOVIE;
|
|
|
|
else if (file->flags & PYSCRIPTFILE)
|
2009-03-11 23:22:07 +00:00
|
|
|
return ICON_FILE_SCRIPT;
|
|
|
|
else if (file->flags & PYSCRIPTFILE)
|
|
|
|
return ICON_FILE_SCRIPT;
|
|
|
|
else if (file->flags & SOUNDFILE)
|
|
|
|
return ICON_FILE_SOUND;
|
|
|
|
else if (file->flags & FTFONTFILE)
|
|
|
|
return ICON_FILE_FONT;
|
2009-03-09 08:31:45 +00:00
|
|
|
else
|
|
|
|
return ICON_FILE_BLANK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void file_draw_icon(short sx, short sy, int icon, short width, short height)
|
|
|
|
{
|
|
|
|
float x,y;
|
|
|
|
int blend=0;
|
|
|
|
|
|
|
|
x = (float)(sx);
|
|
|
|
y = (float)(sy-height);
|
|
|
|
|
|
|
|
if (icon == ICON_FILE_BLANK) blend = -80;
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
UI_icon_draw_aspect_blended(x, y, icon, 1.f, blend);
|
|
|
|
}
|
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
|
|
|
|
static void file_draw_string(short sx, short sy, const char* string, float width, short height, int flag)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
|
|
|
short soffs;
|
|
|
|
char fname[FILE_MAXFILE];
|
|
|
|
float sw;
|
|
|
|
float x,y;
|
|
|
|
|
|
|
|
BLI_strncpy(fname,string, FILE_MAXFILE);
|
2009-03-14 13:12:11 +00:00
|
|
|
sw = shorten_string(fname, width, flag );
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
soffs = (width - sw) / 2;
|
|
|
|
x = (float)(sx);
|
|
|
|
y = (float)(sy-height);
|
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
BLF_position(x, y, 0);
|
|
|
|
BLF_draw(fname);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void file_calc_previews(const bContext *C, ARegion *ar)
|
|
|
|
{
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
|
|
|
View2D *v2d= &ar->v2d;
|
2009-03-08 13:14:12 +00:00
|
|
|
|
|
|
|
ED_fileselect_init_layout(sfile, ar);
|
|
|
|
UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void file_draw_previews(const bContext *C, ARegion *ar)
|
|
|
|
{
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
2009-01-08 18:47:16 +00:00
|
|
|
FileSelectParams* params= ED_fileselect_get_params(sfile);
|
2009-03-08 13:14:12 +00:00
|
|
|
FileLayout* layout= ED_fileselect_get_layout(sfile, ar);
|
2009-01-06 14:42:54 +00:00
|
|
|
View2D *v2d= &ar->v2d;
|
2009-01-06 19:22:29 +00:00
|
|
|
struct FileList* files = sfile->files;
|
2009-01-06 14:42:54 +00:00
|
|
|
int numfiles;
|
|
|
|
struct direntry *file;
|
|
|
|
short sx, sy;
|
|
|
|
ImBuf* imb=0;
|
|
|
|
int i;
|
|
|
|
int colorid = 0;
|
|
|
|
int offset;
|
2009-03-11 23:22:07 +00:00
|
|
|
int is_icon;
|
2009-01-18 18:24:11 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
if (!files) return;
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
filelist_imgsize(files,sfile->layout->prv_w,sfile->layout->prv_h);
|
2009-01-06 14:42:54 +00:00
|
|
|
numfiles = filelist_numfiles(files);
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
sx = v2d->cur.xmin + layout->tile_border_x;
|
|
|
|
sy = v2d->cur.ymax - layout->tile_border_y;
|
|
|
|
|
|
|
|
offset = ED_fileselect_layout_offset(layout, 0, 0);
|
2009-01-06 14:42:54 +00:00
|
|
|
if (offset<0) offset=0;
|
2009-03-08 13:14:12 +00:00
|
|
|
for (i=offset; (i < numfiles) && (i < (offset+(layout->rows+2)*layout->columns)); ++i)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-03-08 13:14:12 +00:00
|
|
|
ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
|
|
|
|
sx += v2d->tot.xmin+2;
|
|
|
|
sy = v2d->tot.ymax - sy;
|
2009-05-14 18:08:14 +00:00
|
|
|
file = filelist_file(files, i);
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
if (file->flags & ACTIVE) {
|
2009-01-06 14:42:54 +00:00
|
|
|
colorid = TH_HILITE;
|
2009-03-08 13:14:12 +00:00
|
|
|
draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0);
|
2009-03-09 08:31:45 +00:00
|
|
|
} else if (params->active_file == i) {
|
|
|
|
colorid = TH_ACTIVE;
|
|
|
|
draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */)
|
2009-03-11 23:22:07 +00:00
|
|
|
{
|
|
|
|
filelist_loadimage(files, i);
|
|
|
|
}
|
|
|
|
is_icon = 0;
|
|
|
|
imb = filelist_getimage(files, i);
|
|
|
|
if (!imb) {
|
|
|
|
imb = filelist_geticon(files,i);
|
|
|
|
is_icon = 1;
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
if (imb) {
|
2009-05-14 18:08:14 +00:00
|
|
|
float fx, fy;
|
|
|
|
float dx, dy;
|
|
|
|
short xco, yco;
|
|
|
|
float scaledx, scaledy;
|
|
|
|
float scale;
|
|
|
|
short 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;
|
|
|
|
}
|
|
|
|
ex = (short)scaledx;
|
|
|
|
ey = (short)scaledy;
|
|
|
|
fx = ((float)layout->prv_w - (float)ex)/2.0f;
|
|
|
|
fy = ((float)layout->prv_h - (float)ey)/2.0f;
|
|
|
|
dx = (fx + 0.5f + sfile->layout->prv_border_x);
|
|
|
|
dy = (fy + 0.5f - sfile->layout->prv_border_y);
|
|
|
|
xco = (float)sx + dx;
|
|
|
|
yco = (float)sy - sfile->layout->prv_h + dy;
|
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
/* shadow */
|
2009-03-11 23:22:07 +00:00
|
|
|
if (!is_icon && (file->flags & IMAGEFILE))
|
2009-05-14 18:08:14 +00:00
|
|
|
uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
|
2009-03-08 13:14:12 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
|
|
|
/* the image */
|
2009-03-08 13:14:12 +00:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
2009-05-14 18:08:14 +00:00
|
|
|
glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
|
|
|
/* border */
|
2009-03-11 23:22:07 +00:00
|
|
|
if (!is_icon && (file->flags & IMAGEFILE)) {
|
|
|
|
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
|
2009-05-14 18:08:14 +00:00
|
|
|
fdrawbox(xco, yco, xco + ex, yco + ey);
|
2009-03-09 08:31:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
imb = 0;
|
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
/* shadow */
|
2009-03-10 08:54:35 +00:00
|
|
|
UI_ThemeColorShade(TH_BACK, -20);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-03-11 23:22:07 +00:00
|
|
|
|
|
|
|
if (S_ISDIR(file->type)) {
|
|
|
|
glColor4f(1.0f, 1.0f, 0.9f, 1.0f);
|
|
|
|
}
|
|
|
|
else if (file->flags & IMAGEFILE) {
|
|
|
|
UI_ThemeColor(TH_SEQ_IMAGE);
|
|
|
|
}
|
|
|
|
else if (file->flags & MOVIEFILE) {
|
|
|
|
UI_ThemeColor(TH_SEQ_MOVIE);
|
|
|
|
}
|
|
|
|
else if (file->flags & BLENDERFILE) {
|
|
|
|
UI_ThemeColor(TH_SEQ_SCENE);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-03-11 23:22:07 +00:00
|
|
|
if (params->active_file == i) {
|
|
|
|
UI_ThemeColor(TH_GRID); /* grid used for active text */
|
|
|
|
} else if (file->flags & ACTIVE) {
|
|
|
|
UI_ThemeColor(TH_TEXT_HI);
|
|
|
|
} else {
|
|
|
|
UI_ThemeColor(TH_TEXT);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-11 23:22:07 +00:00
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_string(sx + layout->prv_border_x, sy+4, file->relname, layout->tile_w, layout->tile_h, FILE_SHORTEN_END);
|
2009-01-18 18:24:11 +00:00
|
|
|
|
|
|
|
if (!sfile->loadimage_timer)
|
|
|
|
sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-01-18 18:24:11 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
uiSetRoundBox(0);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void file_draw_list(const bContext *C, ARegion *ar)
|
|
|
|
{
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
2009-01-08 18:47:16 +00:00
|
|
|
FileSelectParams* params = ED_fileselect_get_params(sfile);
|
2009-03-08 13:14:12 +00:00
|
|
|
FileLayout* layout= ED_fileselect_get_layout(sfile, ar);
|
|
|
|
View2D *v2d= &ar->v2d;
|
2009-01-06 19:22:29 +00:00
|
|
|
struct FileList* files = sfile->files;
|
2009-01-06 14:42:54 +00:00
|
|
|
struct direntry *file;
|
|
|
|
int numfiles;
|
|
|
|
int colorid = 0;
|
|
|
|
short sx, sy;
|
|
|
|
int offset;
|
|
|
|
short type;
|
|
|
|
int i;
|
2009-03-08 13:14:12 +00:00
|
|
|
float sw, spos;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
numfiles = filelist_numfiles(files);
|
|
|
|
type = filelist_gettype(files);
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
sx = ar->v2d.tot.xmin + layout->tile_border_x/2;
|
|
|
|
sy = ar->v2d.cur.ymax - layout->tile_border_y;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
offset = ED_fileselect_layout_offset(layout, 0, 0);
|
|
|
|
if (offset<0) offset=0;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
/* alternating flat shade background */
|
2009-05-14 18:08:14 +00:00
|
|
|
for (i=0; (i <= layout->rows); i+=2)
|
2009-03-09 08:31:45 +00:00
|
|
|
{
|
2009-03-14 18:15:28 +00:00
|
|
|
sx = v2d->cur.xmin;
|
|
|
|
sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y;
|
2009-05-14 18:08:14 +00:00
|
|
|
|
|
|
|
UI_ThemeColorShade(TH_BACK, -7);
|
2009-03-14 18:15:28 +00:00
|
|
|
glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y);
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vertical column dividers */
|
2009-03-14 18:15:28 +00:00
|
|
|
sx = v2d->tot.xmin;
|
2009-01-06 14:42:54 +00:00
|
|
|
while (sx < ar->v2d.cur.xmax) {
|
2009-03-08 13:14:12 +00:00
|
|
|
sx += (sfile->layout->tile_w+2*sfile->layout->tile_border_x);
|
2009-03-10 08:54:35 +00:00
|
|
|
|
|
|
|
UI_ThemeColorShade(TH_BACK, 30);
|
|
|
|
sdrawline(sx+1, ar->v2d.cur.ymax - layout->tile_border_y , sx+1, ar->v2d.cur.ymin);
|
|
|
|
UI_ThemeColorShade(TH_BACK, -30);
|
|
|
|
sdrawline(sx, ar->v2d.cur.ymax - layout->tile_border_y , sx, ar->v2d.cur.ymin);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
sx = ar->v2d.cur.xmin + layout->tile_border_x;
|
|
|
|
sy = ar->v2d.cur.ymax - layout->tile_border_y;
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
for (i=offset; (i < numfiles); ++i)
|
|
|
|
{
|
2009-03-08 13:14:12 +00:00
|
|
|
ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
|
|
|
|
sx += v2d->tot.xmin+2;
|
|
|
|
sy = v2d->tot.ymax - sy;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
file = filelist_file(files, i);
|
|
|
|
|
|
|
|
if (params->active_file == i) {
|
2009-01-28 11:27:25 +00:00
|
|
|
if (file->flags & ACTIVE) colorid= TH_HILITE;
|
|
|
|
else colorid = TH_BACK;
|
2009-03-10 08:54:35 +00:00
|
|
|
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,20);
|
2009-01-06 14:42:54 +00:00
|
|
|
} else if (file->flags & ACTIVE) {
|
|
|
|
colorid = TH_HILITE;
|
2009-03-10 08:54:35 +00:00
|
|
|
draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h+layout->tile_border_y, colorid,0);
|
2009-03-14 18:15:28 +00:00
|
|
|
}
|
2009-03-10 08:54:35 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
spos = sx;
|
2009-03-10 08:54:35 +00:00
|
|
|
file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
|
|
|
|
spos += ICON_DEFAULT_WIDTH + 4;
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-03-10 08:54:35 +00:00
|
|
|
UI_ThemeColor4(TH_TEXT);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->relname);
|
2009-03-14 18:15:28 +00:00
|
|
|
file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END);
|
2009-05-14 18:08:14 +00:00
|
|
|
spos += layout->column_widths[COLUMN_NAME] + 12;
|
2009-03-14 05:21:57 +00:00
|
|
|
if (params->display == FILE_SHOWSHORT) {
|
2009-03-14 18:15:28 +00:00
|
|
|
if (!(file->type & S_IFDIR)) {
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->size);
|
|
|
|
spos += layout->column_widths[COLUMN_SIZE] + 12 - sw;
|
|
|
|
file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END);
|
2009-03-14 18:15:28 +00:00
|
|
|
}
|
2009-03-14 05:21:57 +00:00
|
|
|
} else {
|
2009-03-08 13:14:12 +00:00
|
|
|
#if 0 // XXX TODO: add this for non-windows systems
|
|
|
|
/* rwx rwx rwx */
|
2009-03-09 21:17:19 +00:00
|
|
|
spos += 20;
|
2009-04-10 16:30:28 +00:00
|
|
|
sw = UI_GetStringWidth(file->mode1);
|
2009-03-09 21:17:19 +00:00
|
|
|
file_draw_string(spos, sy, file->mode1, sw, layout->tile_h);
|
|
|
|
|
|
|
|
spos += 30;
|
2009-04-10 16:30:28 +00:00
|
|
|
sw = UI_GetStringWidth(file->mode2);
|
2009-03-09 21:17:19 +00:00
|
|
|
file_draw_string(spos, sy, file->mode2, sw, layout->tile_h);
|
|
|
|
|
|
|
|
spos += 30;
|
2009-04-10 16:30:28 +00:00
|
|
|
sw = UI_GetStringWidth(file->mode3);
|
2009-03-09 21:17:19 +00:00
|
|
|
file_draw_string(spos, sy, file->mode3, sw, layout->tile_h);
|
|
|
|
|
|
|
|
spos += 30;
|
2009-04-10 16:30:28 +00:00
|
|
|
sw = UI_GetStringWidth(file->owner);
|
2009-03-09 21:17:19 +00:00
|
|
|
file_draw_string(spos, sy, file->owner, sw, layout->tile_h);
|
2009-03-08 13:14:12 +00:00
|
|
|
#endif
|
2009-03-09 21:17:19 +00:00
|
|
|
|
2009-03-14 18:15:28 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->date);
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END);
|
2009-05-14 18:08:14 +00:00
|
|
|
spos += layout->column_widths[COLUMN_DATE] + 12;
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->time);
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_string(spos, sy, file->time, sw, layout->tile_h, FILE_SHORTEN_END);
|
2009-05-14 18:08:14 +00:00
|
|
|
spos += layout->column_widths[COLUMN_TIME] + 12;
|
2009-03-14 18:15:28 +00:00
|
|
|
|
2009-03-14 05:21:57 +00:00
|
|
|
if (!(file->type & S_IFDIR)) {
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->size);
|
|
|
|
spos += layout->column_widths[COLUMN_SIZE] + 12 - sw;
|
2009-03-14 05:21:57 +00:00
|
|
|
file_draw_string(spos, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_END);
|
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCategory category, const char* category_name, short *starty)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-03-12 19:36:59 +00:00
|
|
|
struct FSMenu* fsmenu = fsmenu_get();
|
2009-01-06 14:42:54 +00:00
|
|
|
char bookmark[FILE_MAX];
|
2009-03-12 19:36:59 +00:00
|
|
|
int nentries = fsmenu_get_nentries(fsmenu, category);
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-03-10 08:54:35 +00:00
|
|
|
short sx, sy, xpos, ypos;
|
2009-03-10 23:14:41 +00:00
|
|
|
int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X - ICON_DEFAULT_WIDTH - 4;
|
2009-05-14 18:08:14 +00:00
|
|
|
int fontsize = file_font_pointsize();
|
2009-05-05 02:24:58 +00:00
|
|
|
int cat_icon;
|
2009-03-10 23:14:41 +00:00
|
|
|
int i;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
sx = ar->v2d.cur.xmin + TILE_BORDER_X;
|
|
|
|
sy = *starty;
|
|
|
|
|
2009-03-10 08:54:35 +00:00
|
|
|
UI_ThemeColor(TH_TEXT_HI);
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_string(sx, sy, category_name, bmwidth, fontsize, FILE_SHORTEN_END);
|
2009-03-10 08:54:35 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sy -= fontsize*2.0f;
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-05-05 02:24:58 +00:00
|
|
|
switch(category) {
|
|
|
|
case FS_CATEGORY_SYSTEM:
|
|
|
|
cat_icon = ICON_DISK_DRIVE; break;
|
|
|
|
case FS_CATEGORY_BOOKMARKS:
|
|
|
|
cat_icon = ICON_BOOKMARKS; break;
|
|
|
|
case FS_CATEGORY_RECENT:
|
|
|
|
cat_icon = ICON_FILE_FOLDER; break;
|
|
|
|
}
|
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
for (i=0; i< nentries && (sy > ar->v2d.cur.ymin) ;++i) {
|
2009-03-12 19:36:59 +00:00
|
|
|
char *fname = fsmenu_get_entry(fsmenu, category, i);
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
if (fname) {
|
|
|
|
int sl;
|
|
|
|
BLI_strncpy(bookmark, fname, FILE_MAX);
|
|
|
|
|
|
|
|
sl = strlen(bookmark)-1;
|
2009-05-02 03:09:40 +00:00
|
|
|
if (sl > 1) {
|
2009-05-14 18:08:14 +00:00
|
|
|
while (bookmark[sl] == '\\' || bookmark[sl] == '/') {
|
|
|
|
bookmark[sl] = '\0';
|
|
|
|
sl--;
|
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-05-02 03:09:40 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
if (fsmenu_is_selected(fsmenu, category, i) ) {
|
2009-03-08 13:14:12 +00:00
|
|
|
UI_ThemeColor(TH_HILITE);
|
2009-05-14 18:08:14 +00:00
|
|
|
uiRoundBox(sx, sy - fontsize*2.0f, ar->v2d.cur.xmax - TILE_BORDER_X, sy, 4.0f);
|
2009-03-08 13:14:12 +00:00
|
|
|
UI_ThemeColor(TH_TEXT);
|
2009-03-10 08:54:35 +00:00
|
|
|
} else {
|
|
|
|
UI_ThemeColor(TH_TEXT_HI);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-03-10 08:54:35 +00:00
|
|
|
xpos = sx;
|
|
|
|
ypos = sy - (TILE_BORDER_Y * 0.5);
|
|
|
|
|
2009-05-05 02:24:58 +00:00
|
|
|
file_draw_icon(xpos, ypos, cat_icon, ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
|
2009-03-10 08:54:35 +00:00
|
|
|
xpos += ICON_DEFAULT_WIDTH + 4;
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_string(xpos, ypos, bookmark, bmwidth, fontsize, FILE_SHORTEN_FRONT);
|
2009-05-14 18:08:14 +00:00
|
|
|
sy -= fontsize*2.0;
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu_set_pos(fsmenu, category, i, xpos, ypos);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
*starty = sy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_draw_fsmenu(const bContext *C, ARegion *ar)
|
|
|
|
{
|
2009-05-14 18:08:14 +00:00
|
|
|
int linestep = file_font_pointsize()*2.0f;
|
2009-03-11 23:22:07 +00:00
|
|
|
short sy= ar->v2d.cur.ymax-2*TILE_BORDER_Y;
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
file_draw_fsmenu_category(C, ar, FS_CATEGORY_SYSTEM, "SYSTEM", &sy);
|
|
|
|
sy -= linestep;
|
|
|
|
file_draw_fsmenu_category(C, ar, FS_CATEGORY_BOOKMARKS, "BOOKMARKS", &sy);
|
|
|
|
sy -= linestep;
|
|
|
|
file_draw_fsmenu_category(C, ar, FS_CATEGORY_RECENT, "RECENT", &sy);
|
|
|
|
|
2009-01-06 16:47:01 +00:00
|
|
|
}
|