style cleanup: interface

This commit is contained in:
2012-03-30 01:51:25 +00:00
parent 7b60ebf398
commit a6ebffe182
16 changed files with 7611 additions and 7595 deletions

View File

@@ -75,15 +75,15 @@
#include "interface_intern.h"
#define ICON_IMAGE_W 600
#define ICON_IMAGE_H 640
#define ICON_IMAGE_W 600
#define ICON_IMAGE_H 640
#define ICON_GRID_COLS 26
#define ICON_GRID_ROWS 30
#define ICON_GRID_COLS 26
#define ICON_GRID_ROWS 30
#define ICON_GRID_MARGIN 5
#define ICON_GRID_W 16
#define ICON_GRID_H 16
#define ICON_GRID_MARGIN 5
#define ICON_GRID_W 16
#define ICON_GRID_H 16
typedef struct IconImage {
int w;
@@ -93,10 +93,10 @@ typedef struct IconImage {
typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
#define ICON_TYPE_PREVIEW 0
#define ICON_TYPE_TEXTURE 1
#define ICON_TYPE_BUFFER 2
#define ICON_TYPE_VECTOR 3
#define ICON_TYPE_PREVIEW 0
#define ICON_TYPE_TEXTURE 1
#define ICON_TYPE_BUFFER 2
#define ICON_TYPE_VECTOR 3
typedef struct DrawInfo {
int type;
@@ -107,7 +107,7 @@ typedef struct DrawInfo {
VectorDrawFunc func;
} vector;
struct {
IconImage* image;
IconImage *image;
} buffer;
struct {
int x, y, w, h;
@@ -145,24 +145,24 @@ static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int
new_icon->type = 0;
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
di->type= type;
di->type = type;
if (type == ICON_TYPE_TEXTURE) {
di->data.texture.x= xofs;
di->data.texture.y= yofs;
di->data.texture.w= size;
di->data.texture.h= size;
di->data.texture.x = xofs;
di->data.texture.y = yofs;
di->data.texture.w = size;
di->data.texture.h = size;
}
else if (type == ICON_TYPE_BUFFER) {
iimg = MEM_mallocN(sizeof(IconImage), "icon_img");
iimg->rect = MEM_mallocN(size*size*sizeof(unsigned int), "icon_rect");
iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect");
iimg->w = size;
iimg->h = size;
/* Here we store the rect in the icon - same as before */
imgsize = bbuf->x;
for (y=0; y<size; y++) {
memcpy(&iimg->rect[y*size], &bbuf->rect[(y+yofs)*imgsize+xofs], size*sizeof(int));
for (y = 0; y < size; y++) {
memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
}
di->data.buffer.image = iimg;
@@ -174,10 +174,10 @@ static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int
BKE_icon_set(icon_id, new_icon);
}
static void def_internal_vicon( int icon_id, VectorDrawFunc drawFunc)
static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
{
Icon *new_icon = NULL;
DrawInfo* di;
DrawInfo *di;
new_icon = MEM_callocN(sizeof(Icon), "texicon");
@@ -185,7 +185,7 @@ static void def_internal_vicon( int icon_id, VectorDrawFunc drawFunc)
new_icon->type = 0;
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
di->type= ICON_TYPE_VECTOR;
di->type = ICON_TYPE_VECTOR;
di->data.vector.func = drawFunc;
new_icon->drawinfo_free = NULL;
@@ -196,7 +196,7 @@ static void def_internal_vicon( int icon_id, VectorDrawFunc drawFunc)
/* Vector Icon Drawing Routines */
/* Utilities */
/* Utilities */
static void viconutil_set_point(GLint pt[2], int x, int y)
{
@@ -204,7 +204,7 @@ static void viconutil_set_point(GLint pt[2], int x, int y)
pt[1] = y;
}
static void viconutil_draw_tri(GLint (*pts)[2])
static void viconutil_draw_tri(GLint(*pts)[2])
{
glBegin(GL_TRIANGLES);
glVertex2iv(pts[0]);
@@ -213,41 +213,41 @@ static void viconutil_draw_tri(GLint (*pts)[2])
glEnd();
}
static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
static void viconutil_draw_lineloop(GLint(*pts)[2], int numPoints)
{
int i;
glBegin(GL_LINE_LOOP);
for (i=0; i<numPoints; i++) {
for (i = 0; i < numPoints; i++) {
glVertex2iv(pts[i]);
}
glEnd();
}
static void viconutil_draw_lineloop_smooth(GLint (*pts)[2], int numPoints)
static void viconutil_draw_lineloop_smooth(GLint(*pts)[2], int numPoints)
{
glEnable(GL_LINE_SMOOTH);
viconutil_draw_lineloop(pts, numPoints);
glDisable(GL_LINE_SMOOTH);
}
static void viconutil_draw_points(GLint (*pts)[2], int numPoints, int pointSize)
static void viconutil_draw_points(GLint(*pts)[2], int numPoints, int pointSize)
{
int i;
glBegin(GL_QUADS);
for (i=0; i<numPoints; i++) {
for (i = 0; i < numPoints; i++) {
int x = pts[i][0], y = pts[i][1];
glVertex2i(x-pointSize,y-pointSize);
glVertex2i(x+pointSize,y-pointSize);
glVertex2i(x+pointSize,y+pointSize);
glVertex2i(x-pointSize,y+pointSize);
glVertex2i(x - pointSize, y - pointSize);
glVertex2i(x + pointSize, y - pointSize);
glVertex2i(x + pointSize, y + pointSize);
glVertex2i(x - pointSize, y + pointSize);
}
glEnd();
}
/* Drawing functions */
/* Drawing functions */
static void vicon_x_draw(int x, int y, int w, int h, float alpha)
{
@@ -256,48 +256,48 @@ static void vicon_x_draw(int x, int y, int w, int h, float alpha)
w -= 6;
h -= 6;
glEnable( GL_LINE_SMOOTH );
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.5);
glColor4f(0.0, 0.0, 0.0, alpha);
glBegin(GL_LINES);
glVertex2i(x ,y );
glVertex2i(x+w,y+h);
glVertex2i(x+w,y );
glVertex2i(x ,y+h);
glVertex2i(x, y);
glVertex2i(x + w, y + h);
glVertex2i(x + w, y);
glVertex2i(x, y + h);
glEnd();
glLineWidth(1.0);
glDisable( GL_LINE_SMOOTH );
glDisable(GL_LINE_SMOOTH);
}
static void vicon_view3d_draw(int x, int y, int w, int h, float alpha)
{
int cx = x + w/2;
int cy = y + h/2;
int d = MAX2(2, h/3);
int cx = x + w / 2;
int cy = y + h / 2;
int d = MAX2(2, h / 3);
glColor4f(0.5, 0.5, 0.5, alpha);
glBegin(GL_LINES);
glVertex2i(x , cy-d);
glVertex2i(x+w, cy-d);
glVertex2i(x , cy+d);
glVertex2i(x+w, cy+d);
glVertex2i(x, cy - d);
glVertex2i(x + w, cy - d);
glVertex2i(x, cy + d);
glVertex2i(x + w, cy + d);
glVertex2i(cx-d, y );
glVertex2i(cx-d, y+h);
glVertex2i(cx+d, y );
glVertex2i(cx+d, y+h);
glVertex2i(cx - d, y);
glVertex2i(cx - d, y + h);
glVertex2i(cx + d, y);
glVertex2i(cx + d, y + h);
glEnd();
glColor4f(0.0, 0.0, 0.0, alpha);
glBegin(GL_LINES);
glVertex2i(x , cy);
glVertex2i(x+w, cy);
glVertex2i(cx, y );
glVertex2i(cx, y+h);
glVertex2i(x, cy);
glVertex2i(x + w, cy);
glVertex2i(cx, y);
glVertex2i(cx, y + h);
glEnd();
}
@@ -305,10 +305,10 @@ static void vicon_edit_draw(int x, int y, int w, int h, float alpha)
{
GLint pts[4][2];
viconutil_set_point(pts[0], x+3 , y+3 );
viconutil_set_point(pts[1], x+w-3, y+3 );
viconutil_set_point(pts[2], x+w-3, y+h-3);
viconutil_set_point(pts[3], x+3 , y+h-3);
viconutil_set_point(pts[0], x + 3, y + 3);
viconutil_set_point(pts[1], x + w - 3, y + 3);
viconutil_set_point(pts[2], x + w - 3, y + h - 3);
viconutil_set_point(pts[3], x + 3, y + h - 3);
glColor4f(0.0, 0.0, 0.0, alpha);
viconutil_draw_lineloop(pts, 4);
@@ -321,9 +321,9 @@ static void vicon_editmode_hlt_draw(int x, int y, int w, int h, float alpha)
{
GLint pts[3][2];
viconutil_set_point(pts[0], x+w/2, y+h-2);
viconutil_set_point(pts[1], x+3, y+4);
viconutil_set_point(pts[2], x+w-3, y+4);
viconutil_set_point(pts[0], x + w / 2, y + h - 2);
viconutil_set_point(pts[1], x + 3, y + 4);
viconutil_set_point(pts[2], x + w - 3, y + 4);
glColor4f(0.5, 0.5, 0.5, alpha);
viconutil_draw_tri(pts);
@@ -339,9 +339,9 @@ static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float UNUSED(a
{
GLint pts[3][2];
viconutil_set_point(pts[0], x+w/2, y+h-2);
viconutil_set_point(pts[1], x+3, y+4);
viconutil_set_point(pts[2], x+w-3, y+4);
viconutil_set_point(pts[0], x + w / 2, y + h - 2);
viconutil_set_point(pts[1], x + 3, y + 4);
viconutil_set_point(pts[2], x + w - 3, y + 4);
glColor4f(0.0f, 0.0f, 0.0f, 1);
viconutil_draw_lineloop_smooth(pts, 3);
@@ -353,13 +353,13 @@ static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float UNUSED(a
static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha)
{
GLint pts[3][2];
int cx = x+w/2;
int cy = y+w/2;
int d = w/3, d2 = w/5;
int cx = x + w / 2;
int cy = y + w / 2;
int d = w / 3, d2 = w / 5;
viconutil_set_point(pts[0], cx-d2, cy+d);
viconutil_set_point(pts[1], cx-d2, cy-d);
viconutil_set_point(pts[2], cx+d2, cy);
viconutil_set_point(pts[0], cx - d2, cy + d);
viconutil_set_point(pts[1], cx - d2, cy - d);
viconutil_set_point(pts[2], cx + d2, cy);
glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
@@ -378,13 +378,13 @@ static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h),
static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha)
{
GLint pts[3][2];
int cx = x+w/2-4;
int cy = y+w/2;
int d = w/5, d2 = w/7;
int cx = x + w / 2 - 4;
int cy = y + w / 2;
int d = w / 5, d2 = w / 7;
viconutil_set_point(pts[0], cx-d2, cy+d);
viconutil_set_point(pts[1], cx-d2, cy-d);
viconutil_set_point(pts[2], cx+d2, cy);
viconutil_set_point(pts[0], cx - d2, cy + d);
viconutil_set_point(pts[1], cx - d2, cy - d);
viconutil_set_point(pts[2], cx + d2, cy);
glColor4f(0.2f, 0.2f, 0.2f, alpha);
@@ -400,13 +400,13 @@ static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha)
{
GLint pts[3][2];
int cx = x+w/2;
int cy = y+w/2;
int d = w/3, d2 = w/5;
int cx = x + w / 2;
int cy = y + w / 2;
int d = w / 3, d2 = w / 5;
viconutil_set_point(pts[0], cx+d, cy+d2);
viconutil_set_point(pts[1], cx-d, cy+d2);
viconutil_set_point(pts[2], cx, cy-d2);
viconutil_set_point(pts[0], cx + d, cy + d2);
viconutil_set_point(pts[1], cx - d, cy + d2);
viconutil_set_point(pts[2], cx, cy - d2);
glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
@@ -424,16 +424,16 @@ static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), f
static void vicon_move_up_draw(int x, int y, int w, int h, float UNUSED(alpha))
{
int d=-2;
int d = -2;
glEnable(GL_LINE_SMOOTH);
glLineWidth(1);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2i(x+w/2-d*2, y+h/2+d);
glVertex2i(x+w/2, y+h/2-d + 1);
glVertex2i(x+w/2+d*2, y+h/2+d);
glVertex2i(x + w / 2 - d * 2, y + h / 2 + d);
glVertex2i(x + w / 2, y + h / 2 - d + 1);
glVertex2i(x + w / 2 + d * 2, y + h / 2 + d);
glEnd();
glLineWidth(1.0);
@@ -442,16 +442,16 @@ static void vicon_move_up_draw(int x, int y, int w, int h, float UNUSED(alpha))
static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha))
{
int d=2;
int d = 2;
glEnable(GL_LINE_SMOOTH);
glLineWidth(1);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2i(x+w/2-d*2, y+h/2+d);
glVertex2i(x+w/2, y+h/2-d - 1);
glVertex2i(x+w/2+d*2, y+h/2+d);
glVertex2i(x + w / 2 - d * 2, y + h / 2 + d);
glVertex2i(x + w / 2, y + h / 2 - d - 1);
glVertex2i(x + w / 2 + d * 2, y + h / 2 + d);
glEnd();
glLineWidth(1.0);
@@ -462,12 +462,15 @@ static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha)
static void init_brush_icons(void)
{
#define INIT_BRUSH_ICON(icon_id, name) \
bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_ ##name## _png, \
datatoc_ ##name## _png_size, IB_rect, "<brush icon>"); \
def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \
IMB_freeImBuf(bbuf);
// end INIT_BRUSH_ICON
#define INIT_BRUSH_ICON(icon_id, name) \
{ \
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_ ##name## _png, \
datatoc_ ##name## _png_size, \
IB_rect, "<brush icon>"); \
def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \
IMB_freeImBuf(bbuf); \
} (void)0
/* end INIT_BRUSH_ICON */
ImBuf *bbuf;
const int w = 96;
@@ -507,34 +510,34 @@ static void init_brush_icons(void)
static void init_internal_icons(void)
{
bTheme *btheme= UI_GetTheme();
ImBuf *bbuf= NULL;
bTheme *btheme = UI_GetTheme();
ImBuf *bbuf = NULL;
int x, y, icontype;
char iconfilestr[FILE_MAX];
if ((btheme!=NULL) && btheme->tui.iconfile[0]) {
char *icondir= BLI_get_folder(BLENDER_DATAFILES, "icons");
if ((btheme != NULL) && btheme->tui.iconfile[0]) {
char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
if (icondir) {
BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile);
bbuf = IMB_loadiffname(iconfilestr, IB_rect); /* if the image is missing bbuf will just be NULL */
if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) {
printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
IMB_freeImBuf(bbuf);
bbuf= NULL;
bbuf = NULL;
}
}
else {
printf("%s: 'icons' data path not found, continuing\n", __func__);
}
}
if (bbuf==NULL)
bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
if (bbuf == NULL)
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
if (bbuf) {
/* free existing texture if any */
if (icongltex.id) {
glDeleteTextures(1, &icongltex.id);
icongltex.id= 0;
icongltex.id = 0;
}
/* we only use a texture for cards with non-power of two */
@@ -544,8 +547,8 @@ static void init_internal_icons(void)
if (icongltex.id) {
icongltex.w = bbuf->x;
icongltex.h = bbuf->y;
icongltex.invw = 1.0f/bbuf->x;
icongltex.invh = 1.0f/bbuf->y;
icongltex.invw = 1.0f / bbuf->x;
icongltex.invh = 1.0f / bbuf->y;
glBindTexture(GL_TEXTURE_2D, icongltex.id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect);
@@ -555,24 +558,24 @@ static void init_internal_icons(void)
if (glGetError() == GL_OUT_OF_MEMORY) {
glDeleteTextures(1, &icongltex.id);
icongltex.id= 0;
icongltex.id = 0;
}
}
}
}
if (icongltex.id)
icontype= ICON_TYPE_TEXTURE;
icontype = ICON_TYPE_TEXTURE;
else
icontype= ICON_TYPE_BUFFER;
icontype = ICON_TYPE_BUFFER;
if (bbuf) {
for (y=0; y<ICON_GRID_ROWS; y++) {
for (x=0; x<ICON_GRID_COLS; x++) {
def_internal_icon(bbuf, BIFICONID_FIRST + y*ICON_GRID_COLS + x,
x*(ICON_GRID_W+ICON_GRID_MARGIN)+ICON_GRID_MARGIN,
y*(ICON_GRID_H+ICON_GRID_MARGIN)+ICON_GRID_MARGIN, ICON_GRID_W,
icontype);
for (y = 0; y < ICON_GRID_ROWS; y++) {
for (x = 0; x < ICON_GRID_COLS; x++) {
def_internal_icon(bbuf, BIFICONID_FIRST + y * ICON_GRID_COLS + x,
x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN,
y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W,
icontype);
}
}
}
@@ -597,14 +600,14 @@ static void init_iconfile_list(struct ListBase *list)
IconFile *ifile;
struct direntry *dir;
int restoredir = 1; /* restore to current directory */
int totfile, i, index=1;
int totfile, i, index = 1;
const char *icondir;
char olddir[FILE_MAX];
list->first = list->last = NULL;
icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
if (icondir==NULL)
if (icondir == NULL)
return;
/* since BLI_dir_contents changes the current working directory, restore it
@@ -614,7 +617,7 @@ static void init_iconfile_list(struct ListBase *list)
totfile = BLI_dir_contents(icondir, &dir);
if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */
for (i=0; i<totfile; i++) {
for (i = 0; i < totfile; i++) {
if ( (dir[i].type & S_IFREG) ) {
char *filename = dir[i].relname;
@@ -623,13 +626,13 @@ static void init_iconfile_list(struct ListBase *list)
* its possible they change size after blender load anyway. */
#if 0
int ifilex, ifiley;
char iconfilestr[FILE_MAX+16]; /* allow 256 chars for file+dir */
ImBuf *bbuf= NULL;
char iconfilestr[FILE_MAX + 16]; /* allow 256 chars for file+dir */
ImBuf *bbuf = NULL;
/* check to see if the image is the right size, continue if not */
/* copying strings here should go ok, assuming that we never get back
* a complete path to file longer than 256 chars */
BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename);
bbuf= IMB_loadiffname(iconfilestr, IB_rect);
bbuf = IMB_loadiffname(iconfilestr, IB_rect);
if (bbuf) {
ifilex = bbuf->x;
@@ -637,7 +640,7 @@ static void init_iconfile_list(struct ListBase *list)
IMB_freeImBuf(bbuf);
}
else {
ifilex= ifiley= 0;
ifilex = ifiley = 0;
}
/* bad size or failed to load */
@@ -645,7 +648,7 @@ static void init_iconfile_list(struct ListBase *list)
printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley);
continue;
}
#endif /* removed */
#endif /* removed */
/* found a potential icon file, so make an entry for it in the cache list */
ifile = MEM_callocN(sizeof(IconFile), "IconFile");
@@ -661,9 +664,9 @@ static void init_iconfile_list(struct ListBase *list)
}
/* free temporary direntry structure that's been created by BLI_dir_contents() */
i= totfile-1;
i = totfile - 1;
for (; i>=0; i--) {
for (; i >= 0; i--) {
MEM_freeN(dir[i].relname);
MEM_freeN(dir[i].path);
if (dir[i].string) {
@@ -671,14 +674,14 @@ static void init_iconfile_list(struct ListBase *list)
}
}
free(dir);
dir= NULL;
dir = NULL;
}
static void free_iconfile_list(struct ListBase *list)
{
IconFile *ifile=NULL, *next_ifile=NULL;
IconFile *ifile = NULL, *next_ifile = NULL;
for (ifile=list->first; ifile; ifile=next_ifile) {
for (ifile = list->first; ifile; ifile = next_ifile) {
next_ifile = ifile->next;
BLI_freelinkN(list, ifile);
}
@@ -687,9 +690,9 @@ static void free_iconfile_list(struct ListBase *list)
int UI_iconfile_get_index(const char *filename)
{
IconFile *ifile;
ListBase *list=&(iconfilelist);
ListBase *list = &(iconfilelist);
for (ifile=list->first; ifile; ifile=ifile->next) {
for (ifile = list->first; ifile; ifile = ifile->next) {
if (BLI_path_cmp(filename, ifile->filename) == 0) {
return ifile->index;
}
@@ -700,7 +703,7 @@ int UI_iconfile_get_index(const char *filename)
ListBase *UI_iconfile_list(void)
{
ListBase *list=&(iconfilelist);
ListBase *list = &(iconfilelist);
return list;
}
@@ -711,7 +714,7 @@ void UI_icons_free(void)
#ifndef WITH_HEADLESS
if (icongltex.id) {
glDeleteTextures(1, &icongltex.id);
icongltex.id= 0;
icongltex.id = 0;
}
free_iconfile_list(&iconfilelist);
@@ -740,7 +743,7 @@ static DrawInfo *icon_create_drawinfo(void)
DrawInfo *di = NULL;
di = MEM_callocN(sizeof(DrawInfo), "di_icon");
di->type= ICON_TYPE_PREVIEW;
di->type = ICON_TYPE_PREVIEW;
return di;
}
@@ -753,7 +756,7 @@ int UI_icon_get_width(int icon_id)
icon = BKE_icon_get(icon_id);
if (icon==NULL) {
if (icon == NULL) {
if (G.f & G_DEBUG)
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
return 0;
@@ -778,13 +781,13 @@ int UI_icon_get_height(int icon_id)
icon = BKE_icon_get(icon_id);
if (icon==NULL) {
if (icon == NULL) {
if (G.f & G_DEBUG)
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
return 0;
}
di = (DrawInfo*)icon->drawinfo;
di = (DrawInfo *)icon->drawinfo;
if (!di) {
di = icon_create_drawinfo();
@@ -814,7 +817,7 @@ void UI_icons_init(int first_dyn_id)
static int preview_render_size(enum eIconSizes size)
{
switch (size) {
case ICON_SIZE_ICON: return 32;
case ICON_SIZE_ICON: return 32;
case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
}
return 0;
@@ -822,7 +825,7 @@ static int preview_render_size(enum eIconSizes size)
/* Create rect for the icon
*/
static void icon_create_rect(struct PreviewImage* prv_img, enum eIconSizes size)
static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
{
unsigned int render_size = preview_render_size(size);
@@ -835,13 +838,13 @@ static void icon_create_rect(struct PreviewImage* prv_img, enum eIconSizes size)
prv_img->h[size] = render_size;
prv_img->changed[size] = 1;
prv_img->changed_timestamp[size] = 0;
prv_img->rect[size] = MEM_callocN(render_size*render_size*sizeof(unsigned int), "prv_rect");
prv_img->rect[size] = MEM_callocN(render_size * render_size * sizeof(unsigned int), "prv_rect");
}
}
/* only called when icon has changed */
/* only call with valid pointer from UI_icon_draw */
static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, enum eIconSizes size)
static void icon_set_image(bContext *C, ID *id, PreviewImage *prv_img, enum eIconSizes size)
{
if (!prv_img) {
if (G.f & G_DEBUG)
@@ -852,15 +855,15 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, enum eIco
icon_create_rect(prv_img, size);
ED_preview_icon_job(C, prv_img, id, prv_img->rect[size],
prv_img->w[size], prv_img->h[size]);
prv_img->w[size], prv_img->h[size]);
}
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, float *rgb, short is_preview)
{
ImBuf *ima= NULL;
ImBuf *ima = NULL;
/* sanity check */
if (w<=0 || h<=0 || w>2000 || h>2000) {
if (w <= 0 || h <= 0 || w > 2000 || h > 2000) {
printf("%s: icons are %i x %i pixels?\n", __func__, w, h);
BLI_assert(!"invalid icon size");
return;
@@ -877,12 +880,12 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
}
/* rect contains image in 'rendersize', we only scale if needed */
if (rw!=w && rh!=h) {
if (rw != w && rh != h) {
/* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int));
memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int));
IMB_scaleImBuf(ima, w, h); /* scale it */
rect= ima->rect;
rect = ima->rect;
}
/* draw */
@@ -915,10 +918,10 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy
if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
else glColor4f(1.0f, 1.0f, 1.0f, alpha);
x1= ix*icongltex.invw;
x2= (ix + ih)*icongltex.invw;
y1= iy*icongltex.invh;
y2= (iy + ih)*icongltex.invh;
x1 = ix * icongltex.invw;
x2 = (ix + ih) * icongltex.invw;
y1 = iy * icongltex.invh;
y2 = (iy + ih) * icongltex.invh;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, icongltex.id);
@@ -928,13 +931,13 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy
glVertex2f(x, y);
glTexCoord2f(x2, y1);
glVertex2f(x+w, y);
glVertex2f(x + w, y);
glTexCoord2f(x2, y2);
glVertex2f(x+w, y+h);
glVertex2f(x + w, y + h);
glTexCoord2f(x1, y2);
glVertex2f(x, y+h);
glVertex2f(x, y + h);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
@@ -953,23 +956,23 @@ static int get_draw_size(enum eIconSizes size)
static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview)
{
bTheme *btheme= UI_GetTheme();
bTheme *btheme = UI_GetTheme();
Icon *icon = NULL;
DrawInfo *di = NULL;
IconImage *iimg;
float fdraw_size= is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
float fdraw_size = is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
int w, h;
icon = BKE_icon_get(icon_id);
alpha *= btheme->tui.icon_alpha;
if (icon==NULL) {
if (icon == NULL) {
if (G.f & G_DEBUG)
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
return;
}
di = (DrawInfo*)icon->drawinfo;
di = (DrawInfo *)icon->drawinfo;
if (!di) {
di = icon_create_drawinfo();
@@ -979,8 +982,8 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al
}
/* scale width and height according to aspect */
w = (int)(fdraw_size/aspect + 0.5f);
h = (int)(fdraw_size/aspect + 0.5f);
w = (int)(fdraw_size / aspect + 0.5f);
h = (int)(fdraw_size / aspect + 0.5f);
if (di->type == ICON_TYPE_VECTOR) {
/* vector icons use the uiBlock transformation, they are not drawn
@@ -989,22 +992,22 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al
}
else if (di->type == ICON_TYPE_TEXTURE) {
icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
di->data.texture.w, di->data.texture.h, alpha, rgb);
di->data.texture.w, di->data.texture.h, alpha, rgb);
}
else if (di->type == ICON_TYPE_BUFFER) {
/* it is a builtin icon */
iimg= di->data.buffer.image;
iimg = di->data.buffer.image;
if (!iimg->rect) return; /* something has gone wrong! */
if (!iimg->rect) return; /* something has gone wrong! */
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
}
else if (di->type == ICON_TYPE_PREVIEW) {
PreviewImage* pi = BKE_previewimg_get((ID*)icon->obj);
PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj);
if (pi) {
/* no create icon on this level in code */
if (!pi->rect[size]) return; /* something has gone wrong! */
if (!pi->rect[size]) return; /* something has gone wrong! */
/* preview images use premul alpha ... */
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
@@ -1016,7 +1019,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al
static void ui_id_preview_image_render_size(bContext *C, ID *id, PreviewImage *pi, int size)
{
if ((pi->changed[size] ||!pi->rect[size])) { /* changed only ever set by dynamic icons */
if ((pi->changed[size] || !pi->rect[size])) { /* changed only ever set by dynamic icons */
/* create the rect if necessary */
icon_set_image(C, id, pi, size);
@@ -1030,9 +1033,9 @@ static void ui_id_icon_render(bContext *C, ID *id, int big)
if (pi) {
if (big)
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW); /* bigger preview size */
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW); /* bigger preview size */
else
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON); /* icon size */
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON); /* icon size */
}
}
@@ -1057,7 +1060,7 @@ static void ui_id_brush_render(bContext *C, ID *id)
static int ui_id_brush_get_icon(bContext *C, ID *id)
{
Brush *br = (Brush*)id;
Brush *br = (Brush *)id;
if (br->flag & BRUSH_CUSTOM_ICON) {
BKE_icon_getid(id);
@@ -1076,13 +1079,14 @@ static int ui_id_brush_get_icon(bContext *C, ID *id)
if (CTX_wm_view3d(C) && ob) {
if (ob->mode & OB_MODE_SCULPT)
mode = OB_MODE_SCULPT;
else if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT))
else if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))
mode = OB_MODE_VERTEX_PAINT;
else if (ob->mode & OB_MODE_TEXTURE_PAINT)
mode = OB_MODE_TEXTURE_PAINT;
}
else if ((sima = CTX_wm_space_image(C)) &&
(sima->flag & SI_DRAWTOOL)) {
(sima->flag & SI_DRAWTOOL))
{
mode = OB_MODE_TEXTURE_PAINT;
}
@@ -1109,19 +1113,19 @@ static int ui_id_brush_get_icon(bContext *C, ID *id)
int ui_id_icon_get(bContext *C, ID *id, int big)
{
int iconid= 0;
int iconid = 0;
/* icon */
switch(GS(id->name)) {
switch (GS(id->name)) {
case ID_BR:
iconid= ui_id_brush_get_icon(C, id);
iconid = ui_id_brush_get_icon(C, id);
break;
case ID_MA: /* fall through */
case ID_TE: /* fall through */
case ID_IM: /* fall through */
case ID_WO: /* fall through */
case ID_LA: /* fall through */
iconid= BKE_icon_getid(id);
iconid = BKE_icon_getid(id);
/* checks if not exists, or changed */
ui_id_icon_render(C, id, big);
break;