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-07-29 23:12:30 +00:00
|
|
|
#define IMASEL_BUTTONS_MARGIN 6
|
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-07-10 17:05:04 +00:00
|
|
|
B_FS_DIRNAME,
|
|
|
|
B_FS_FILENAME
|
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-10 17:53:10 +00:00
|
|
|
case B_FS_PARENT:
|
|
|
|
file_parent_exec(C, NULL); /* file_ops.c */
|
|
|
|
break;
|
2009-07-10 17:05:04 +00:00
|
|
|
case B_FS_FILENAME:
|
|
|
|
file_filename_exec(C, NULL);
|
|
|
|
break;
|
|
|
|
case B_FS_DIRNAME:
|
|
|
|
file_directory_exec(C, NULL);
|
|
|
|
break;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-10 17:26:19 +00:00
|
|
|
/* Note: This function uses pixelspace (0, 0, winx, winy), not view2d.
|
|
|
|
* The controls are laid out as follows:
|
|
|
|
*
|
|
|
|
* -------------------------------------------
|
|
|
|
* | Directory input | execute |
|
|
|
|
* -------------------------------------------
|
|
|
|
* | Filename input | + | - | cancel |
|
|
|
|
* -------------------------------------------
|
|
|
|
*
|
|
|
|
* The input widgets will stretch to fill any excess space.
|
|
|
|
* When there isn't enough space for all controls to be shown, they are
|
|
|
|
* hidden in this order: x/-, execute/cancel, input widgets.
|
|
|
|
*/
|
2009-01-06 14:42:54 +00:00
|
|
|
void file_draw_buttons(const bContext *C, ARegion *ar)
|
|
|
|
{
|
2009-07-10 17:26:19 +00:00
|
|
|
/* Button layout. */
|
2009-09-28 12:10:23 +00:00
|
|
|
const int max_x = ar->winx - 10;
|
|
|
|
const int line1_y = IMASEL_BUTTONS_HEIGHT/2 + IMASEL_BUTTONS_MARGIN*2;
|
|
|
|
const int line2_y = IMASEL_BUTTONS_MARGIN;
|
|
|
|
const int input_minw = 20;
|
|
|
|
const int btn_h = UI_UNIT_Y;
|
|
|
|
const int btn_fn_w = UI_UNIT_X;
|
|
|
|
const int btn_minw = 80;
|
|
|
|
const int btn_margin = 20;
|
|
|
|
const int separator = 4;
|
2009-07-10 17:26:19 +00:00
|
|
|
|
|
|
|
/* Additional locals. */
|
|
|
|
char name[20];
|
2009-09-28 12:10:23 +00:00
|
|
|
int loadbutton;
|
|
|
|
int fnumbuttons;
|
2010-01-18 03:36:19 +00:00
|
|
|
int min_x = 10;
|
2009-09-28 12:10:23 +00:00
|
|
|
int available_w = max_x - min_x;
|
|
|
|
int line1_w = available_w;
|
|
|
|
int line2_w = available_w;
|
2009-07-10 17:26:19 +00:00
|
|
|
|
|
|
|
uiBut* but;
|
|
|
|
uiBlock* block;
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile* sfile = CTX_wm_space_file(C);
|
2009-01-08 18:47:16 +00:00
|
|
|
FileSelectParams* params = ED_fileselect_get_params(sfile);
|
2010-01-18 03:36:19 +00:00
|
|
|
ARegion* artmp;
|
2009-07-10 17:26:19 +00:00
|
|
|
|
|
|
|
/* Initialize UI block. */
|
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);
|
2010-01-18 03:36:19 +00:00
|
|
|
|
|
|
|
/* exception to make space for collapsed region icon */
|
|
|
|
for (artmp=CTX_wm_area(C)->regionbase.first; artmp; artmp=artmp->next) {
|
|
|
|
if (artmp->regiontype == RGN_TYPE_CHANNELS && artmp->flag & RGN_FLAG_HIDDEN) {
|
|
|
|
min_x += 16;
|
|
|
|
available_w -= 16;
|
|
|
|
}
|
|
|
|
}
|
2009-07-10 17:26:19 +00:00
|
|
|
|
|
|
|
/* Is there enough space for the execute / cancel buttons? */
|
|
|
|
loadbutton = UI_GetStringWidth(sfile->params->title) + btn_margin;
|
|
|
|
if (loadbutton < btn_minw) {
|
|
|
|
loadbutton = MAX2(btn_minw,
|
|
|
|
btn_margin + UI_GetStringWidth(params->title));
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-07-10 17:26:19 +00:00
|
|
|
|
|
|
|
if (available_w <= loadbutton + separator + input_minw
|
|
|
|
|| params->title[0] == 0) {
|
|
|
|
loadbutton = 0;
|
|
|
|
} else {
|
|
|
|
line1_w -= (loadbutton + separator);
|
|
|
|
line2_w = line1_w;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 17:26:19 +00:00
|
|
|
/* Is there enough space for file number increment/decrement buttons? */
|
|
|
|
fnumbuttons = 2 * btn_fn_w;
|
|
|
|
if (!loadbutton || line2_w <= fnumbuttons + separator + input_minw) {
|
|
|
|
fnumbuttons = 0;
|
|
|
|
} else {
|
|
|
|
line2_w -= (fnumbuttons + separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Text input fields for directory and file. */
|
|
|
|
if (available_w > 0) {
|
2009-07-10 19:19:54 +00:00
|
|
|
but = uiDefBut(block, TEX, B_FS_DIRNAME, "",
|
2009-07-10 17:26:19 +00:00
|
|
|
min_x, line1_y, line1_w, btn_h,
|
2009-09-20 19:10:12 +00:00
|
|
|
params->dir, 0.0, (float)FILE_MAX-1, 0, 0,
|
2009-07-10 17:26:19 +00:00
|
|
|
"File path.");
|
2009-07-10 19:19:54 +00:00
|
|
|
uiButSetCompleteFunc(but, autocomplete_directory, NULL);
|
2009-07-10 17:26:19 +00:00
|
|
|
uiDefBut(block, TEX, B_FS_FILENAME, "",
|
|
|
|
min_x, line2_y, line2_w, btn_h,
|
|
|
|
params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0,
|
|
|
|
"File name.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filename number increment / decrement buttons. */
|
|
|
|
if (fnumbuttons) {
|
|
|
|
uiBlockBeginAlign(block);
|
2009-07-12 08:12:22 +00:00
|
|
|
but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMOUT,
|
2009-07-10 17:26:19 +00:00
|
|
|
min_x + line2_w + separator, line2_y,
|
|
|
|
btn_fn_w, btn_h,
|
|
|
|
"Decrement the filename number.");
|
|
|
|
RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", -1);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-07-12 08:12:22 +00:00
|
|
|
but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMIN,
|
2009-07-10 17:26:19 +00:00
|
|
|
min_x + line2_w + separator + btn_fn_w, line2_y,
|
|
|
|
btn_fn_w, btn_h,
|
|
|
|
"Increment the filename number.");
|
|
|
|
RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", 1);
|
|
|
|
uiBlockEndAlign(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute / cancel buttons. */
|
2009-01-06 14:42:54 +00:00
|
|
|
if(loadbutton) {
|
2010-01-20 12:28:33 +00:00
|
|
|
|
|
|
|
uiDefButO(block, BUT, "FILE_OT_execute", WM_OP_EXEC_REGION_WIN, params->title,
|
|
|
|
max_x - loadbutton, line1_y, loadbutton, btn_h,
|
|
|
|
params->title);
|
|
|
|
uiDefButO(block, BUT, "FILE_OT_cancel", WM_OP_EXEC_REGION_WIN, "Cancel",
|
|
|
|
max_x - loadbutton, line2_y, loadbutton, btn_h,
|
|
|
|
"Cancel");
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-07-10 17:26:19 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
uiEndBlock(C, block);
|
|
|
|
uiDrawBlock(C, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
static void draw_tile(int sx, int sy, int width, int height, int colorid, int shade)
|
2009-07-10 17:05:04 +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-26 21:34:20 +00:00
|
|
|
if (w <= 0) {
|
|
|
|
*string = '\0';
|
|
|
|
return 0.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 21:34:20 +00:00
|
|
|
while ((*s) && (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 21:34:20 +00:00
|
|
|
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
|
|
|
}
|
2009-05-26 21:34:20 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2009-10-26 11:03:12 +00:00
|
|
|
if (file->type & S_IFDIR) {
|
|
|
|
if ( strcmp(file->relname, "..") == 0) {
|
|
|
|
return ICON_FILE_PARENT;
|
|
|
|
}
|
2009-03-09 08:31:45 +00:00
|
|
|
return ICON_FILE_FOLDER;
|
2009-10-26 11:03:12 +00:00
|
|
|
}
|
2009-03-09 08:31:45 +00:00
|
|
|
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-12-10 14:26:06 +00:00
|
|
|
else if (file->flags & BTXFILE)
|
|
|
|
return ICON_FILE_BLANK;
|
2009-03-09 08:31:45 +00:00
|
|
|
else
|
|
|
|
return ICON_FILE_BLANK;
|
|
|
|
}
|
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
static void file_draw_icon(int sx, int sy, int icon, int width, int height)
|
2009-03-09 08:31:45 +00:00
|
|
|
{
|
|
|
|
float x,y;
|
Sorry, three commits in one, became difficult to untangle..
Editors Modules
* render/ module added in editors, moved the preview render code there and
also shading related operators.
* physics/ module made more consistent with other modules. renaming files,
making a single physics_ops.c for operators and keymaps. Also move all
particle related operators here now.
* space_buttons/ now should have only operators relevant to the buttons
specificially.
Updates & Notifiers
* Material/Texture/World/Lamp can now be passed to DAG_id_flush_update,
which will go back to a callback in editors. Eventually these should
be in the depsgraph itself, but for now this gives a unified call for
doing updates.
* GLSL materials are now refreshed on changes. There's still various
cases missing,
* Preview icons now hook into this system, solving various update cases
that were missed before.
* Also fixes issue in my last commit, where some preview would not render,
problem is avoided in the new system.
Icon Rendering
* On systems with support for non-power of two textures, an OpenGL texture
is now used instead of glDrawPixels. This avoids problems with icons get
clipped on region borders. On my Linux desktop, this gives an 1.1x speedup,
and on my Mac laptop a 2.3x speedup overall in redrawing the full window,
with the default setup. The glDrawPixels implementation on Mac seems to
have a lot of overhread.
* Preview icons are now drawn using proper premul alpha, and never faded so
you can see them clearly.
* Also tried to fix issue with texture node preview rendering, globals can't
be used with threads reliably.
2009-09-29 19:12:12 +00:00
|
|
|
float alpha=1.0f;
|
2009-03-09 08:31:45 +00:00
|
|
|
|
|
|
|
x = (float)(sx);
|
|
|
|
y = (float)(sy-height);
|
|
|
|
|
Sorry, three commits in one, became difficult to untangle..
Editors Modules
* render/ module added in editors, moved the preview render code there and
also shading related operators.
* physics/ module made more consistent with other modules. renaming files,
making a single physics_ops.c for operators and keymaps. Also move all
particle related operators here now.
* space_buttons/ now should have only operators relevant to the buttons
specificially.
Updates & Notifiers
* Material/Texture/World/Lamp can now be passed to DAG_id_flush_update,
which will go back to a callback in editors. Eventually these should
be in the depsgraph itself, but for now this gives a unified call for
doing updates.
* GLSL materials are now refreshed on changes. There's still various
cases missing,
* Preview icons now hook into this system, solving various update cases
that were missed before.
* Also fixes issue in my last commit, where some preview would not render,
problem is avoided in the new system.
Icon Rendering
* On systems with support for non-power of two textures, an OpenGL texture
is now used instead of glDrawPixels. This avoids problems with icons get
clipped on region borders. On my Linux desktop, this gives an 1.1x speedup,
and on my Mac laptop a 2.3x speedup overall in redrawing the full window,
with the default setup. The glDrawPixels implementation on Mac seems to
have a lot of overhread.
* Preview icons are now drawn using proper premul alpha, and never faded so
you can see them clearly.
* Also tried to fix issue with texture node preview rendering, globals can't
be used with threads reliably.
2009-09-29 19:12:12 +00:00
|
|
|
if (icon == ICON_FILE_BLANK) alpha = 0.375f;
|
2009-03-09 08:31:45 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
Sorry, three commits in one, became difficult to untangle..
Editors Modules
* render/ module added in editors, moved the preview render code there and
also shading related operators.
* physics/ module made more consistent with other modules. renaming files,
making a single physics_ops.c for operators and keymaps. Also move all
particle related operators here now.
* space_buttons/ now should have only operators relevant to the buttons
specificially.
Updates & Notifiers
* Material/Texture/World/Lamp can now be passed to DAG_id_flush_update,
which will go back to a callback in editors. Eventually these should
be in the depsgraph itself, but for now this gives a unified call for
doing updates.
* GLSL materials are now refreshed on changes. There's still various
cases missing,
* Preview icons now hook into this system, solving various update cases
that were missed before.
* Also fixes issue in my last commit, where some preview would not render,
problem is avoided in the new system.
Icon Rendering
* On systems with support for non-power of two textures, an OpenGL texture
is now used instead of glDrawPixels. This avoids problems with icons get
clipped on region borders. On my Linux desktop, this gives an 1.1x speedup,
and on my Mac laptop a 2.3x speedup overall in redrawing the full window,
with the default setup. The glDrawPixels implementation on Mac seems to
have a lot of overhread.
* Preview icons are now drawn using proper premul alpha, and never faded so
you can see them clearly.
* Also tried to fix issue with texture node preview rendering, globals can't
be used with threads reliably.
2009-09-29 19:12:12 +00:00
|
|
|
UI_icon_draw_aspect(x, y, icon, 1.f, alpha);
|
2009-03-09 08:31:45 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
static void file_draw_string(int sx, int sy, const char* string, float width, int height, int flag)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-09-28 12:10:23 +00:00
|
|
|
int soffs;
|
2009-01-06 14:42:54 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-06 14:42:54 +00:00
|
|
|
View2D *v2d= &ar->v2d;
|
2009-03-08 13:14:12 +00:00
|
|
|
|
|
|
|
ED_fileselect_init_layout(sfile, ar);
|
2009-09-28 12:10:23 +00:00
|
|
|
/* +SCROLL_HEIGHT is bad hack to work around issue in UI_view2d_totRect_set */
|
|
|
|
UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height+V2D_SCROLL_HEIGHT);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
static void file_draw_preview(int sx, int sy, ImBuf *imb, FileLayout *layout, short dropshadow)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-08-20 18:39:25 +00:00
|
|
|
if (imb) {
|
2009-05-14 18:08:14 +00:00
|
|
|
float fx, fy;
|
|
|
|
float dx, dy;
|
2009-09-28 12:10:23 +00:00
|
|
|
int xco, yco;
|
2009-05-14 18:08:14 +00:00
|
|
|
float scaledx, scaledy;
|
|
|
|
float scale;
|
2009-09-28 12:10:23 +00:00
|
|
|
int ex, ey;
|
2009-05-14 18:08:14 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2009-09-28 12:10:23 +00:00
|
|
|
ex = (int)scaledx;
|
|
|
|
ey = (int)scaledy;
|
2009-05-14 18:08:14 +00:00
|
|
|
fx = ((float)layout->prv_w - (float)ex)/2.0f;
|
|
|
|
fy = ((float)layout->prv_h - (float)ey)/2.0f;
|
2009-08-20 18:39:25 +00:00
|
|
|
dx = (fx + 0.5f + layout->prv_border_x);
|
|
|
|
dy = (fy + 0.5f - layout->prv_border_y);
|
2009-05-14 18:08:14 +00:00
|
|
|
xco = (float)sx + dx;
|
2009-08-20 18:39:25 +00:00
|
|
|
yco = (float)sy - layout->prv_h + dy;
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-03-09 08:31:45 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
/* shadow */
|
2009-08-20 18:39:25 +00:00
|
|
|
if (dropshadow)
|
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-08-20 18:39:25 +00:00
|
|
|
if (dropshadow) {
|
2009-03-11 23:22:07 +00:00
|
|
|
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-07-26 18:52:27 +00:00
|
|
|
static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
|
|
|
|
{
|
|
|
|
char newname[FILE_MAX+12];
|
|
|
|
char orgname[FILE_MAX+12];
|
|
|
|
char filename[FILE_MAX+12];
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
2009-07-28 18:07:00 +00:00
|
|
|
ARegion* ar = CTX_wm_region(C);
|
|
|
|
|
2009-07-26 18:52:27 +00:00
|
|
|
struct direntry *file = (struct direntry *)arg1;
|
|
|
|
|
|
|
|
BLI_make_file_string(G.sce, orgname, sfile->params->dir, oldname);
|
|
|
|
BLI_strncpy(filename, file->relname, sizeof(filename));
|
|
|
|
BLI_make_file_string(G.sce, newname, sfile->params->dir, filename);
|
|
|
|
|
|
|
|
if( strcmp(orgname, newname) != 0 ) {
|
2009-07-28 18:07:00 +00:00
|
|
|
if (!BLI_exists(newname)) {
|
|
|
|
BLI_rename(orgname, newname);
|
|
|
|
/* to make sure we show what is on disk */
|
|
|
|
filelist_free(sfile->files);
|
|
|
|
} else {
|
|
|
|
BLI_strncpy(file->relname, oldname, strlen(oldname)+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
2009-07-26 18:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
static void draw_background(FileLayout *layout, View2D *v2d)
|
|
|
|
{
|
|
|
|
int i;
|
2009-09-28 12:10:23 +00:00
|
|
|
int sy;
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
/* alternating flat shade background */
|
|
|
|
for (i=0; (i <= layout->rows); i+=2)
|
|
|
|
{
|
|
|
|
sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y;
|
|
|
|
|
|
|
|
UI_ThemeColorShade(TH_BACK, -7);
|
|
|
|
glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_dividers(FileLayout *layout, View2D *v2d)
|
|
|
|
{
|
2009-09-28 12:10:23 +00:00
|
|
|
int sx;
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
/* vertical column dividers */
|
|
|
|
sx = v2d->tot.xmin;
|
|
|
|
while (sx < v2d->cur.xmax) {
|
|
|
|
sx += (layout->tile_w+2*layout->tile_border_x);
|
|
|
|
|
|
|
|
UI_ThemeColorShade(TH_BACK, 30);
|
|
|
|
sdrawline(sx+1, v2d->cur.ymax - layout->tile_border_y , sx+1, v2d->cur.ymin);
|
|
|
|
UI_ThemeColorShade(TH_BACK, -30);
|
|
|
|
sdrawline(sx, v2d->cur.ymax - layout->tile_border_y , sx, v2d->cur.ymin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
void file_draw_list(const bContext *C, ARegion *ar)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(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;
|
2009-08-20 18:39:25 +00:00
|
|
|
ImBuf *imb;
|
2009-01-06 14:42:54 +00:00
|
|
|
int numfiles;
|
2009-07-26 12:40:44 +00:00
|
|
|
int numfiles_layout;
|
2009-01-06 14:42:54 +00:00
|
|
|
int colorid = 0;
|
2009-09-28 12:10:23 +00:00
|
|
|
int sx, sy;
|
2009-01-06 14:42:54 +00:00
|
|
|
int offset;
|
|
|
|
int i;
|
2009-03-08 13:14:12 +00:00
|
|
|
float sw, spos;
|
2009-08-20 18:39:25 +00:00
|
|
|
short is_icon;
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
numfiles = filelist_numfiles(files);
|
2009-06-04 20:07:06 +00:00
|
|
|
|
2009-08-20 18:39:25 +00:00
|
|
|
if (params->display != FILE_IMGDISPLAY) {
|
2009-05-14 18:08:14 +00:00
|
|
|
|
2009-08-20 18:39:25 +00:00
|
|
|
draw_background(layout, v2d);
|
2009-03-09 08:31:45 +00:00
|
|
|
|
2009-08-20 18:39:25 +00:00
|
|
|
draw_dividers(layout, v2d);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
offset = ED_fileselect_layout_offset(layout, ar->v2d.cur.xmin, -ar->v2d.cur.ymax);
|
|
|
|
if (offset<0) offset=0;
|
|
|
|
|
2009-07-26 12:40:44 +00:00
|
|
|
numfiles_layout = ED_fileselect_layout_numfiles(layout, ar);
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-07-26 12:40:44 +00:00
|
|
|
for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++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-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
file = filelist_file(files, i);
|
2009-07-26 18:52:27 +00:00
|
|
|
|
|
|
|
if (!(file->flags & EDITING)) {
|
|
|
|
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);
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
2009-03-10 08:54:35 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
spos = sx;
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
if ( FILE_IMGDISPLAY == params->display ) {
|
|
|
|
if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) {
|
|
|
|
filelist_loadimage(files, i);
|
|
|
|
}
|
|
|
|
is_icon = 0;
|
|
|
|
imb = filelist_getimage(files, i);
|
|
|
|
if (!imb) {
|
|
|
|
imb = filelist_geticon(files,i);
|
|
|
|
is_icon = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_draw_preview(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;
|
|
|
|
}
|
|
|
|
|
2009-03-10 08:54:35 +00:00
|
|
|
UI_ThemeColor4(TH_TEXT);
|
2009-08-20 18:39:25 +00:00
|
|
|
|
2009-05-14 18:08:14 +00:00
|
|
|
sw = file_string_width(file->relname);
|
2009-07-26 18:52:27 +00:00
|
|
|
if (file->flags & EDITING) {
|
2009-09-28 12:10:23 +00:00
|
|
|
int but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
|
2009-07-26 18:52:27 +00:00
|
|
|
uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS);
|
|
|
|
uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3,
|
2009-08-20 18:39:25 +00:00
|
|
|
but_width, layout->textheight*2, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
|
2009-07-26 18:52:27 +00:00
|
|
|
uiButSetRenameFunc(but, renamebutton_cb, file);
|
|
|
|
if ( 0 == uiButActiveOnly(C, block, but)) {
|
|
|
|
file->flags &= ~EDITING;
|
|
|
|
}
|
|
|
|
uiEndBlock(C, block);
|
|
|
|
uiDrawBlock(C, block);
|
|
|
|
} else {
|
2009-08-20 18:39:25 +00:00
|
|
|
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);
|
2009-07-26 18:52:27 +00:00
|
|
|
}
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
uiSetRoundBox(0);
|
|
|
|
|
|
|
|
if (params->display == FILE_SHORTDISPLAY) {
|
|
|
|
spos += layout->column_widths[COLUMN_NAME] + 12;
|
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);
|
|
|
|
file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END);
|
2009-09-28 12:10:23 +00:00
|
|
|
spos += layout->column_widths[COLUMN_SIZE] + 12;
|
2009-03-14 18:15:28 +00:00
|
|
|
}
|
2009-08-20 18:39:25 +00:00
|
|
|
} else if (params->display == FILE_LONGDISPLAY) {
|
|
|
|
spos += layout->column_widths[COLUMN_NAME] + 12;
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2009-03-08 13:14:12 +00:00
|
|
|
/* rwx rwx rwx */
|
2009-08-20 18:39:25 +00:00
|
|
|
sw = file_string_width(file->mode1);
|
|
|
|
file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END);
|
|
|
|
spos += layout->column_widths[COLUMN_MODE1] + 12;
|
2009-03-09 21:17:19 +00:00
|
|
|
|
2009-08-20 18:39:25 +00:00
|
|
|
sw = file_string_width(file->mode2);
|
|
|
|
file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, FILE_SHORTEN_END);
|
|
|
|
spos += layout->column_widths[COLUMN_MODE2] + 12;
|
|
|
|
|
|
|
|
sw = file_string_width(file->mode3);
|
|
|
|
file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, FILE_SHORTEN_END);
|
|
|
|
spos += layout->column_widths[COLUMN_MODE3] + 12;
|
|
|
|
|
|
|
|
sw = file_string_width(file->owner);
|
|
|
|
file_draw_string(spos, sy, file->owner, sw, layout->tile_h, FILE_SHORTEN_END);
|
|
|
|
spos += layout->column_widths[COLUMN_OWNER] + 12;
|
2009-03-08 13:14:12 +00:00
|
|
|
#endif
|
2009-03-09 21:17:19 +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);
|
2009-03-14 05:21:57 +00:00
|
|
|
file_draw_string(spos, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_END);
|
2009-09-28 12:10:23 +00:00
|
|
|
spos += layout->column_widths[COLUMN_SIZE] + 12;
|
2009-03-14 05:21:57 +00:00
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-08-20 18:39:25 +00:00
|
|
|
|
|
|
|
if (!sfile->loadimage_timer)
|
2009-10-20 13:58:53 +00:00
|
|
|
sfile->loadimage_timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 21:27:10 +00:00
|
|
|
|