Big commit in orange: Interface icons for materials, textures
world and lamp. Also for images in pupmenus. Also preparation for work on using preview images in imagebrowser. -- Andrea
This commit is contained in:
75
source/blender/blenkernel/BKE_icons.h
Normal file
75
source/blender/blenkernel/BKE_icons.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef BKE_ICONS_H
|
||||
#define BKE_ICONS_H
|
||||
|
||||
/*
|
||||
Resizable Icons for Blender
|
||||
*/
|
||||
|
||||
typedef void (*DrawInfoFreeFP) (void *drawinfo);
|
||||
|
||||
struct Icon
|
||||
{
|
||||
void *drawinfo;
|
||||
void *obj;
|
||||
short type;
|
||||
short changed;
|
||||
DrawInfoFreeFP drawinfo_free;
|
||||
};
|
||||
|
||||
typedef struct Icon Icon;
|
||||
|
||||
void BKE_icons_init(int first_dyn_id);
|
||||
|
||||
/* return icon id for library object or create new icon if not found */
|
||||
int BKE_icon_getid(struct ID* id);
|
||||
|
||||
/* retrieve icon for id */
|
||||
struct Icon* BKE_icon_get(int icon_id);
|
||||
|
||||
/* set icon for id if not already defined */
|
||||
/* used for inserting the internal icons */
|
||||
void BKE_icon_set(int icon_id, struct Icon* icon);
|
||||
|
||||
/* remove icon and free date if library object becomes invalid */
|
||||
void BKE_icon_delete(struct ID* id);
|
||||
|
||||
/* report changes - icon needs to be recalculated */
|
||||
void BKE_icon_changed(int icon_id);
|
||||
|
||||
/* free all icons */
|
||||
void BKE_icons_free();
|
||||
|
||||
|
||||
#endif /* BKE_ICONS_H */
|
@@ -8,6 +8,7 @@ source_files = ['intern/constraint.c',
|
||||
'intern/depsgraph.c',
|
||||
'intern/DerivedMesh.c',
|
||||
'intern/group.c',
|
||||
'intern/icons.c',
|
||||
'intern/material.c',
|
||||
'intern/sca.c',
|
||||
'intern/world.c',
|
||||
|
197
source/blender/blenkernel/intern/icons.c
Normal file
197
source/blender/blenkernel/intern/icons.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_ID.h"
|
||||
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "BKE_icons.h"
|
||||
|
||||
#define GS(a) (*((short *)(a)))
|
||||
|
||||
/* GLOBALS */
|
||||
|
||||
static GHash* gIcons = 0;
|
||||
|
||||
static int gNextIconId = 1;
|
||||
|
||||
static int gFirstIconId = 1;
|
||||
|
||||
|
||||
static void icon_free(void *val)
|
||||
{
|
||||
Icon* icon = val;
|
||||
|
||||
if (icon)
|
||||
{
|
||||
if (icon->drawinfo_free) {
|
||||
icon->drawinfo_free(icon->drawinfo);
|
||||
}
|
||||
else if (icon->drawinfo) {
|
||||
MEM_freeN(icon->drawinfo);
|
||||
}
|
||||
MEM_freeN(icon);
|
||||
}
|
||||
}
|
||||
|
||||
/* create an id for a new icon and make sure that ids from deleted icons get reused
|
||||
after the integer number range is used up */
|
||||
static int get_next_free_id()
|
||||
{
|
||||
int startId = gFirstIconId;
|
||||
|
||||
/* if we haven't used up the int number range, we just return the next int */
|
||||
if (gNextIconId>=gFirstIconId)
|
||||
return gNextIconId++;
|
||||
|
||||
/* now we try to find the smallest icon id not stored in the gIcons hash */
|
||||
while (BLI_ghash_lookup(gIcons, (void *)startId) && startId>=gFirstIconId)
|
||||
startId++;
|
||||
|
||||
/* if we found a suitable one that isnt used yet, return it */
|
||||
if (startId>=gFirstIconId)
|
||||
return startId;
|
||||
|
||||
/* fail */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BKE_icons_init(int first_dyn_id)
|
||||
{
|
||||
gNextIconId = first_dyn_id;
|
||||
gFirstIconId = first_dyn_id;
|
||||
|
||||
if (!gIcons)
|
||||
gIcons = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
|
||||
}
|
||||
|
||||
void BKE_icons_free()
|
||||
{
|
||||
BLI_ghash_free(gIcons, 0, icon_free);
|
||||
gIcons = 0;
|
||||
}
|
||||
|
||||
|
||||
void BKE_icon_changed(int id)
|
||||
{
|
||||
Icon* icon = 0;
|
||||
|
||||
if (!id) return;
|
||||
|
||||
icon = BLI_ghash_lookup(gIcons, (void *)id);
|
||||
|
||||
if (icon)
|
||||
{
|
||||
icon->changed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int BKE_icon_getid(struct ID* id)
|
||||
{
|
||||
Icon* new_icon = 0;
|
||||
|
||||
if (!id)
|
||||
return 0;
|
||||
|
||||
if (id->icon_id)
|
||||
return id->icon_id;
|
||||
|
||||
id->icon_id = get_next_free_id();
|
||||
|
||||
if (!id->icon_id){
|
||||
printf("BKE_icon_getid: Internal error - not enough IDs\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
new_icon = MEM_callocN(sizeof(Icon), "texicon");
|
||||
|
||||
new_icon->obj = id;
|
||||
new_icon->type = GS(id->name);
|
||||
|
||||
/* next two lines make sure image gets created */
|
||||
new_icon->drawinfo = 0;
|
||||
new_icon->drawinfo_free = 0;
|
||||
new_icon->changed = 1;
|
||||
|
||||
BLI_ghash_insert(gIcons, (void *)id->icon_id, new_icon);
|
||||
|
||||
return id->icon_id;
|
||||
}
|
||||
|
||||
Icon* BKE_icon_get(int icon_id)
|
||||
{
|
||||
Icon* icon = 0;
|
||||
|
||||
icon = BLI_ghash_lookup(gIcons, (void*)icon_id);
|
||||
|
||||
if (!icon) {
|
||||
printf("BKE_icon_get: Internal error, no icon for icon ID: %d\n", icon_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
void BKE_icon_set(int icon_id, struct Icon* icon)
|
||||
{
|
||||
Icon* old_icon = 0;
|
||||
|
||||
old_icon = BLI_ghash_lookup(gIcons, (void*)icon_id);
|
||||
|
||||
if (old_icon)
|
||||
{
|
||||
printf("BKE_icon_set: Internal error, icon already set: %d\n", icon_id);
|
||||
return;
|
||||
}
|
||||
|
||||
BLI_ghash_insert(gIcons, (void *)icon_id, icon);
|
||||
}
|
||||
|
||||
void BKE_icon_delete(struct ID* id)
|
||||
{
|
||||
Icon* new_icon = 0;
|
||||
|
||||
if (!id->icon_id) return; /* no icon defined for library object */
|
||||
|
||||
BLI_ghash_remove(gIcons, (void*)id->icon_id, 0, icon_free);
|
||||
id->icon_id = 0;
|
||||
}
|
@@ -61,6 +61,7 @@
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_texture.h"
|
||||
@@ -103,6 +104,8 @@ void free_image(Image *ima)
|
||||
freePackedFile(ima->packedfile);
|
||||
ima->packedfile = NULL;
|
||||
}
|
||||
BKE_icon_delete(ima);
|
||||
ima->id.icon_id = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -93,6 +93,7 @@
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_ipo.h"
|
||||
#include "BKE_key.h"
|
||||
@@ -334,6 +335,7 @@ void *alloc_libblock(ListBase *lb, short type, char *name)
|
||||
if(id) {
|
||||
BLI_addtail(lb, id);
|
||||
id->us= 1;
|
||||
id->icon_id = 0;
|
||||
*( (short *)id->name )= type;
|
||||
new_id(lb, id, name);
|
||||
/* alphabetic insterion: is in new_id */
|
||||
@@ -573,6 +575,20 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor
|
||||
sprintf(buf, "%%x%d", i+1);
|
||||
BLI_dynstr_append(pupds, buf);
|
||||
|
||||
switch(GS(id->name))
|
||||
{
|
||||
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 */
|
||||
sprintf(buf, "%%i%d", BKE_icon_getid(id) );
|
||||
BLI_dynstr_append(pupds, buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(id->next)
|
||||
BLI_dynstr_append(pupds, "|");
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@
|
||||
#include "BKE_blender.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_material.h"
|
||||
@@ -76,6 +77,9 @@ void free_material(Material *ma)
|
||||
if(ma->ramp_col) MEM_freeN(ma->ramp_col);
|
||||
if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
|
||||
|
||||
BKE_icon_delete((struct ID*)ma);
|
||||
ma->id.icon_id = 0;
|
||||
|
||||
for(ml= ma->layers.first; ml; ml= ml->next)
|
||||
if(ml->mat) ml->mat->id.us--;
|
||||
|
||||
|
@@ -91,6 +91,7 @@
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_group.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_ipo.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_lattice.h"
|
||||
@@ -674,6 +675,9 @@ void free_lamp(Lamp *la)
|
||||
if(mtex) MEM_freeN(mtex);
|
||||
}
|
||||
la->ipo= 0;
|
||||
|
||||
BKE_icon_delete(la);
|
||||
la->id.icon_id = 0;
|
||||
}
|
||||
|
||||
void *add_wave()
|
||||
|
@@ -74,6 +74,7 @@
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_ipo.h"
|
||||
|
||||
|
||||
@@ -336,6 +337,8 @@ void free_texture(Tex *tex)
|
||||
free_plugin_tex(tex->plugin);
|
||||
if(tex->coba) MEM_freeN(tex->coba);
|
||||
if(tex->env) RE_free_envmap(tex->env);
|
||||
BKE_icon_delete((struct ID*)tex);
|
||||
tex->id.icon_id = 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include "BKE_world.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_icons.h"
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
@@ -75,6 +76,8 @@ void free_world(World *wrld)
|
||||
if(mtex) MEM_freeN(mtex);
|
||||
}
|
||||
wrld->ipo= 0;
|
||||
BKE_icon_delete((struct ID*)wrld);
|
||||
wrld->id.icon_id = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -48,6 +48,7 @@ GHash* BLI_ghash_new (GHashHashFP hashfp, GHashCmpFP cmpfp);
|
||||
void BLI_ghash_free (GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
|
||||
|
||||
void BLI_ghash_insert (GHash *gh, void *key, void *val);
|
||||
int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
|
||||
void* BLI_ghash_lookup (GHash *gh, void *key);
|
||||
int BLI_ghash_haskey (GHash *gh, void *key);
|
||||
|
||||
@@ -110,5 +111,8 @@ int BLI_ghashutil_ptrcmp (void *a, void *b);
|
||||
unsigned int BLI_ghashutil_strhash (void *key);
|
||||
int BLI_ghashutil_strcmp (void *a, void *b);
|
||||
|
||||
unsigned int BLI_ghashutil_inthash (void *ptr);
|
||||
int BLI_ghashutil_intcmp(void *a, void *b);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -128,6 +128,34 @@ void* BLI_ghash_lookup(GHash *gh, void *key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
|
||||
{
|
||||
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
|
||||
Entry *e;
|
||||
Entry *p = 0;
|
||||
|
||||
for (e= gh->buckets[hash]; e; e= e->next) {
|
||||
if (gh->cmpfp(key, e->key)==0) {
|
||||
Entry *n= e->next;
|
||||
|
||||
if (keyfreefp) keyfreefp(e->key);
|
||||
if (valfreefp) valfreefp(e->val);
|
||||
free(e);
|
||||
|
||||
|
||||
e= n;
|
||||
if (p)
|
||||
p->next = n;
|
||||
else
|
||||
gh->buckets[hash] = n;
|
||||
return 1;
|
||||
}
|
||||
p = e;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BLI_ghash_haskey(GHash *gh, void *key) {
|
||||
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
|
||||
Entry *e;
|
||||
@@ -161,6 +189,9 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef
|
||||
}
|
||||
|
||||
free(gh->buckets);
|
||||
gh->buckets = 0;
|
||||
gh->nentries = 0;
|
||||
gh->nbuckets = 0;
|
||||
MEM_freeN(gh);
|
||||
}
|
||||
|
||||
@@ -223,6 +254,30 @@ int BLI_ghashutil_ptrcmp(void *a, void *b) {
|
||||
return (a<b)?-1:1;
|
||||
}
|
||||
|
||||
unsigned int BLI_ghashutil_inthash(void *ptr) {
|
||||
#if defined(_WIN64)
|
||||
unsigned __int64 key = (unsigned __int64)ptr;
|
||||
#else
|
||||
unsigned long key = (unsigned long)ptr;
|
||||
#endif
|
||||
|
||||
key += ~(key << 16);
|
||||
key ^= (key >> 5);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 13);
|
||||
key += ~(key << 9);
|
||||
key ^= (key >> 17);
|
||||
|
||||
return (unsigned int)(key & 0xffffffff);
|
||||
}
|
||||
|
||||
int BLI_ghashutil_intcmp(void *a, void *b) {
|
||||
if (a==b)
|
||||
return 0;
|
||||
else
|
||||
return (a<b)?-1:1;
|
||||
}
|
||||
|
||||
unsigned int BLI_ghashutil_strhash(void *ptr) {
|
||||
char *s= ptr;
|
||||
unsigned int i= 0;
|
||||
|
@@ -126,7 +126,7 @@
|
||||
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
|
||||
|
||||
#include "BIF_butspace.h" // for do_versions, patching event codes
|
||||
|
||||
#include "BIF_previewrender.h" // for struct RenderInfo
|
||||
#include "BLO_readfile.h"
|
||||
#include "BLO_undofile.h"
|
||||
#include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory
|
||||
@@ -2766,8 +2766,8 @@ static void lib_link_screen(FileData *fd, Main *main)
|
||||
}
|
||||
else if(sl->spacetype==SPACE_BUTS) {
|
||||
SpaceButs *sbuts= (SpaceButs *)sl;
|
||||
sbuts->rect= NULL;
|
||||
sbuts->lockpoin= NULL;
|
||||
sbuts->ri= NULL;
|
||||
if(main->versionfile<132) set_rects_butspace(sbuts);
|
||||
}
|
||||
else if(sl->spacetype==SPACE_FILE) {
|
||||
@@ -2935,7 +2935,7 @@ void lib_link_screen_restore(Main *newmain, Scene *curscene)
|
||||
else if(sl->spacetype==SPACE_BUTS) {
|
||||
SpaceButs *sbuts= (SpaceButs *)sl;
|
||||
sbuts->lockpoin= NULL;
|
||||
sbuts->cury= 0; // we leave rect, for nicer redraws
|
||||
if (sbuts->ri) sbuts->ri->cury = 0;
|
||||
}
|
||||
else if(sl->spacetype==SPACE_FILE) {
|
||||
SpaceFile *sfile= (SpaceFile *)sl;
|
||||
@@ -3247,6 +3247,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
|
||||
id->lib= main->curlib;
|
||||
if(id->flag & LIB_FAKEUSER) id->us= 1;
|
||||
else id->us= 0;
|
||||
id->icon_id = 0;
|
||||
|
||||
/* this case cannot be direct_linked: it's just the ID part */
|
||||
if(bhead->code==ID_ID) {
|
||||
|
55
source/blender/include/BIF_interface_icons.h
Normal file
55
source/blender/include/BIF_interface_icons.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef BIF_PREVIEW_ICONS_H
|
||||
#define BIF_PREVIEW_ICONS_H
|
||||
|
||||
struct Image;
|
||||
struct ImBuf;
|
||||
struct World;
|
||||
struct Tex;
|
||||
struct Lamp;
|
||||
struct Material;
|
||||
|
||||
/*
|
||||
Resizable Icons for Blender
|
||||
*/
|
||||
void BIF_icons_init(int first_dyn_id);
|
||||
int BIF_icon_get_width(int icon_id);
|
||||
int BIF_icon_get_height(int icon_id);
|
||||
void BIF_icon_set_aspect(int icon_id, float aspect);
|
||||
void BIF_icon_draw(int x, int y, int icon_id);
|
||||
void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade);
|
||||
void BIF_icons_free();
|
||||
void BIF_icons_free_drawinfo(void *drawinfo);
|
||||
|
||||
#endif /* BIF_ICONS_H */
|
@@ -31,9 +31,36 @@
|
||||
*/
|
||||
|
||||
struct SpaceButs;
|
||||
struct RenderInfo;
|
||||
struct Image;
|
||||
struct ScrArea;
|
||||
|
||||
typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
|
||||
|
||||
/* stores rendered preview - is also used for icons */
|
||||
typedef struct RenderInfo {
|
||||
int pr_rectx;
|
||||
int pr_recty;
|
||||
unsigned int* rect;
|
||||
short cury;
|
||||
} RenderInfo;
|
||||
|
||||
/* Set the previewrect for drawing */
|
||||
void BIF_set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short pr_rectx, short pr_recty);
|
||||
void BIF_end_previewrect(void);
|
||||
|
||||
void BIF_all_preview_changed(void);
|
||||
void BIF_preview_changed (struct SpaceButs *area);
|
||||
void BIF_previewrender (struct SpaceButs *area);
|
||||
void BIF_previewdraw (void);
|
||||
void BIF_preview_changed (struct SpaceButs *sbuts);
|
||||
void BIF_previewrender_buts (struct SpaceButs *sbuts);
|
||||
/* Render the preview
|
||||
* a) into the ri->rect
|
||||
* b) draw it in the area using the block UIMat
|
||||
|
||||
if doDraw is false, the preview is not drawn and the function is not dynamic,
|
||||
so no events are processed. Hopefully fast enough for 64x64 rendering or
|
||||
at least 32x32 */
|
||||
void BIF_previewrender (struct ID* id, struct RenderInfo *ri, struct ScrArea *area, int doDraw);
|
||||
void BIF_previewdraw (void);
|
||||
void BIF_previewdraw_render(struct RenderInfo* ri, struct ScrArea* area);
|
||||
|
||||
void BIF_calcpreview_image(struct Image* img, struct RenderInfo* ri, unsigned int w, unsigned int h);
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#ifndef BIF_RESOURCES_H
|
||||
#define BIF_RESOURCES_H
|
||||
|
||||
/* elubie: TODO: move the typedef for icons to BIF_interface_icons.h */
|
||||
/* and add/replace include of BIF_resources.h by BIF_interface_icons.h */
|
||||
typedef enum {
|
||||
#define BIFICONID_FIRST (ICON_VIEW3D)
|
||||
ICON_VIEW3D,
|
||||
@@ -508,13 +510,6 @@ void BIF_resources_free (void);
|
||||
void BIF_colors_init (void);
|
||||
void BIF_load_ui_colors (void);
|
||||
|
||||
|
||||
// icon API
|
||||
int BIF_get_icon_width (BIFIconID icon);
|
||||
int BIF_get_icon_height (BIFIconID icon);
|
||||
void BIF_draw_icon (float x, float y, BIFIconID icon);
|
||||
void BIF_draw_icon_blended (float x, float y, BIFIconID icon, int colorid, int shade);
|
||||
|
||||
/* only for buttons in theme editor! */
|
||||
char *BIF_ThemeGetColorPtr(struct bTheme *btheme, int spacetype, int colorid);
|
||||
char *BIF_ThemeColorsPup(int spacetype);
|
||||
|
@@ -62,7 +62,7 @@ typedef struct ID {
|
||||
* to.
|
||||
*/
|
||||
short flag;
|
||||
int pad;
|
||||
int icon_id;
|
||||
} ID;
|
||||
|
||||
/**
|
||||
|
@@ -48,6 +48,7 @@ struct Image;
|
||||
struct SpaceIpo;
|
||||
struct BlendHandle;
|
||||
struct TreeStore;
|
||||
struct RenderInfo;
|
||||
struct bNodeTree;
|
||||
struct uiBlock;
|
||||
|
||||
@@ -107,6 +108,7 @@ typedef struct SpaceButs {
|
||||
int spacetype;
|
||||
float blockscale;
|
||||
struct ScrArea *area;
|
||||
struct RenderInfo *ri;
|
||||
|
||||
short blockhandler[8];
|
||||
|
||||
@@ -121,13 +123,10 @@ typedef struct SpaceButs {
|
||||
short texnr;
|
||||
char texfrom, showgroup;
|
||||
|
||||
short rectx, recty; /* preview render */
|
||||
unsigned int *rect;
|
||||
short cury, modeltype;
|
||||
|
||||
short modeltype;
|
||||
short scriptblock;
|
||||
short scaflag;
|
||||
short re_align, pad1;
|
||||
short re_align;
|
||||
|
||||
int oldkeypress; /* for keeping track of the sub tab key cycling */
|
||||
|
||||
|
@@ -100,6 +100,7 @@ source_files = ['B.blend.c',
|
||||
'interface.c',
|
||||
'interface_panel.c',
|
||||
'interface_draw.c',
|
||||
'interface_icons.c',
|
||||
'keyval.c',
|
||||
'lorem.c',
|
||||
'mainqueue.c',
|
||||
|
@@ -601,6 +601,7 @@ void do_texbuts(unsigned short event)
|
||||
}
|
||||
break;
|
||||
case B_TEXPRV:
|
||||
allqueue(REDRAWBUTSSHADING, 0);
|
||||
BIF_all_preview_changed();
|
||||
break;
|
||||
case B_TEXREDR_PRV:
|
||||
@@ -2646,6 +2647,7 @@ void do_matbuts(unsigned short event)
|
||||
case B_MATPRV:
|
||||
/* this event also used by lamp, tex and sky */
|
||||
BIF_preview_changed(G.buts);
|
||||
allqueue(REDRAWBUTSSHADING, 0);
|
||||
shade_buttons_change_3d();
|
||||
break;
|
||||
case B_MATPRV_DRAW:
|
||||
|
@@ -787,8 +787,8 @@ static void draw_keylist(gla2DDrawInfo *di, int totvert, BezTriple **blist, floa
|
||||
gla2DDrawTranslatePt(di, blist[v]->vec[1][0], ypos, &sc_x, &sc_y);
|
||||
// draw_key_but(sc_x-5, sc_y-6, 13, 13, (blist[v]->f2 & 1));
|
||||
|
||||
if(blist[v]->f2 & 1) BIF_draw_icon_blended(sc_x-7, sc_y-6, ICON_SPACE2, TH_HEADER, 0);
|
||||
else BIF_draw_icon_blended(sc_x-7, sc_y-6, ICON_SPACE3, TH_HEADER, 0);
|
||||
if(blist[v]->f2 & 1) BIF_icon_draw_blended(sc_x-7, sc_y-6, ICON_SPACE2, TH_HEADER, 0);
|
||||
else BIF_icon_draw_blended(sc_x-7, sc_y-6, ICON_SPACE3, TH_HEADER, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -593,16 +593,16 @@ static void draw_image_view_icon(void)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
if(G.sima->flag & SI_STICKYUVS) {
|
||||
BIF_draw_icon(xPos, 5.0, ICON_STICKY2_UVS);
|
||||
BIF_icon_draw(xPos, 5.0, ICON_STICKY2_UVS);
|
||||
xPos = 25.0;
|
||||
}
|
||||
else if(G.sima->flag & SI_LOCALSTICKY) {
|
||||
BIF_draw_icon(xPos, 5.0, ICON_STICKY_UVS);
|
||||
BIF_icon_draw(xPos, 5.0, ICON_STICKY_UVS);
|
||||
xPos = 25.0;
|
||||
}
|
||||
|
||||
if(G.sima->flag & SI_SELACTFACE) {
|
||||
BIF_draw_icon(xPos, 5.0, ICON_DRAW_UVFACES);
|
||||
BIF_icon_draw(xPos, 5.0, ICON_DRAW_UVFACES);
|
||||
}
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
|
@@ -509,23 +509,23 @@ void draw_sima_area(SpaceImaSel *simasel)
|
||||
sy = simasel->deey+6;
|
||||
|
||||
if (bitset(simasel->fase, IMS_FOUND_BIP)) {
|
||||
BIF_draw_icon(sx+16*0, sy, ICON_BPIBFOLDER_HLT);
|
||||
BIF_icon_draw(sx+16*0, sy, ICON_BPIBFOLDER_HLT);
|
||||
} else if (bitset(simasel->fase, IMS_WRITE_NO_BIP)) {
|
||||
BIF_draw_icon(sx+16*0, sy, ICON_BPIBFOLDER_DEHLT);
|
||||
BIF_icon_draw(sx+16*0, sy, ICON_BPIBFOLDER_DEHLT);
|
||||
} else {
|
||||
BIF_draw_icon(sx+16*0, sy, ICON_BPIBFOLDER_DEHLT);
|
||||
BIF_icon_draw(sx+16*0, sy, ICON_BPIBFOLDER_DEHLT);
|
||||
}
|
||||
|
||||
if (bitset(simasel->fase, IMS_KNOW_INF)) {
|
||||
BIF_draw_icon(sx+16*1, sy, ICON_FOLDER_HLT);
|
||||
BIF_icon_draw(sx+16*1, sy, ICON_FOLDER_HLT);
|
||||
} else {
|
||||
BIF_draw_icon(sx+16*1, sy, ICON_FOLDER_DEHLT);
|
||||
BIF_icon_draw(sx+16*1, sy, ICON_FOLDER_DEHLT);
|
||||
}
|
||||
|
||||
if (bitset(simasel->fase, IMS_KNOW_IMA)) {
|
||||
BIF_draw_icon(sx+16*2, sy, ICON_BLUEIMAGE_HLT);
|
||||
BIF_icon_draw(sx+16*2, sy, ICON_BLUEIMAGE_HLT);
|
||||
} else {
|
||||
BIF_draw_icon(sx+16*2, sy, ICON_BLUEIMAGE_DEHLT);
|
||||
BIF_icon_draw(sx+16*2, sy, ICON_BLUEIMAGE_DEHLT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -131,9 +131,9 @@ static void draw_nla_channels(void)
|
||||
if(ob->nlastrips.first && ob->action) {
|
||||
glEnable(GL_BLEND);
|
||||
if(ob->nlaflag & OB_NLA_OVERRIDE)
|
||||
BIF_draw_icon_blended(x+5, y-8, ICON_NLA, TH_HEADER, 0);
|
||||
BIF_icon_draw_blended(x+5, y-8, ICON_NLA, TH_HEADER, 0);
|
||||
else
|
||||
BIF_draw_icon_blended(x+5, y-8, ICON_ACTION, TH_HEADER, 0);
|
||||
BIF_icon_draw_blended(x+5, y-8, ICON_ACTION, TH_HEADER, 0);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
y-=NLACHANNELHEIGHT+NLACHANNELSKIP;
|
||||
@@ -155,7 +155,7 @@ static void draw_nla_channels(void)
|
||||
if(strip->flag & ACTSTRIP_ACTIVE) break;
|
||||
if(strip==NULL) {
|
||||
glEnable(GL_BLEND);
|
||||
BIF_draw_icon_blended(x, y-8, ICON_DOT, TH_BACK, 0);
|
||||
BIF_icon_draw_blended(x, y-8, ICON_DOT, TH_BACK, 0);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ static void draw_nla_channels(void)
|
||||
|
||||
if(strip->flag & ACTSTRIP_ACTIVE) {
|
||||
glEnable(GL_BLEND);
|
||||
BIF_draw_icon_blended(x+16, y-8, ICON_DOT, TH_BACK, 0);
|
||||
BIF_icon_draw_blended(x+16, y-8, ICON_DOT, TH_BACK, 0);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
@@ -220,7 +220,7 @@ void draw_icon_oops(float *co, short type)
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
BIF_draw_icon(co[0], co[1]-0.2, icon);
|
||||
BIF_icon_draw(co[0], co[1]-0.2, icon);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
|
@@ -135,9 +135,9 @@ static void draw_marker(TimeMarker *marker)
|
||||
|
||||
/* 5 px to offset icon to align properly, space / pixels corrects for zoom */
|
||||
if(marker->flag & SELECT)
|
||||
BIF_draw_icon_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER_HLT, TH_BACK, 0);
|
||||
BIF_icon_draw_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER_HLT, TH_BACK, 0);
|
||||
else
|
||||
BIF_draw_icon_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER, TH_BACK, 0);
|
||||
BIF_icon_draw_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER, TH_BACK, 0);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
|
@@ -1124,7 +1124,7 @@ static void draw_view_icon(void)
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
BIF_draw_icon(5.0, 5.0, icon);
|
||||
BIF_icon_draw(5.0, 5.0, icon);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
|
@@ -3517,10 +3517,10 @@ void draw_area_emboss(ScrArea *sa)
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
BIF_draw_icon(8.0, 10.0, ICON_MATERIAL_HLT);
|
||||
BIF_draw_icon(8.0, 30.0, ICON_IPO_HLT);
|
||||
BIF_draw_icon(8.0, 50.0, ICON_HOME);
|
||||
BIF_draw_icon(8.0, 70.0, ICON_BORDERMOVE);
|
||||
BIF_icon_draw(8.0, 10.0, ICON_MATERIAL_HLT);
|
||||
BIF_icon_draw(8.0, 30.0, ICON_IPO_HLT);
|
||||
BIF_icon_draw(8.0, 50.0, ICON_HOME);
|
||||
BIF_icon_draw(8.0, 70.0, ICON_BORDERMOVE);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
|
@@ -88,8 +88,10 @@
|
||||
#include "BIF_glutil.h"
|
||||
#include "BIF_editfont.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_interface_icons.h"
|
||||
#include "BIF_butspace.h"
|
||||
|
||||
|
||||
#include "BSE_view.h"
|
||||
|
||||
#include "mydevice.h"
|
||||
@@ -1138,6 +1140,7 @@ static int ui_do_but_MENU(uiBut *but)
|
||||
|
||||
for(a=0; a<md->nitems; a++) {
|
||||
xmax= but->aspect*BIF_GetStringWidth(block->curfont, md->items[a].str, (U.transopts & USER_TR_MENUS));
|
||||
if ( md->items[a].icon) xmax += 20*but->aspect;
|
||||
if(xmax>width) width= xmax;
|
||||
}
|
||||
|
||||
@@ -1194,6 +1197,7 @@ static int ui_do_but_MENU(uiBut *but)
|
||||
else if(md->items[md->nitems-a-1].icon) {
|
||||
uiBut *bt= uiDefIconTextBut(block, BUTM|but->pointype, but->retval, md->items[md->nitems-a-1].icon ,md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), but->poin, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
|
||||
if(active==a) bt->flag |= UI_ACTIVE;
|
||||
BIF_icon_set_aspect(bt->icon, bt->aspect); /* aspect for the icon has to be stored */
|
||||
}
|
||||
else {
|
||||
uiBut *bt= uiDefBut(block, BUTM|but->pointype, but->retval, md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), but->poin, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
|
||||
@@ -5120,6 +5124,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, char *str, short
|
||||
but->pointype= type & BUTPOIN;
|
||||
but->bit= type & BIT;
|
||||
but->bitnr= type & 31;
|
||||
but->icon = 0;
|
||||
|
||||
BLI_addtail(&block->buttons, but);
|
||||
|
||||
@@ -5913,6 +5918,8 @@ short pupmenu_col(char *instr, int maxrow)
|
||||
for(a=0; a<md->nitems; a++) {
|
||||
char *name= md->items[a].str;
|
||||
|
||||
int icon = md->items[a].icon;
|
||||
|
||||
x1= startx + width*((int)a/rows);
|
||||
y1= starty - boxh*(a%rows) + (rows-1)*boxh;
|
||||
|
||||
@@ -5920,6 +5927,10 @@ short pupmenu_col(char *instr, int maxrow)
|
||||
uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
|
||||
y1 -= PUP_LABELH;
|
||||
}
|
||||
else if (icon) {
|
||||
uiDefIconButI(block, BUTM, B_NOP, icon, x1, y1, width+16, boxh-1, &val, (float) md->items[a].retval, 0.0, 0, 0, "");
|
||||
y1 -= boxh;
|
||||
}
|
||||
else {
|
||||
uiDefButI(block, BUTM, B_NOP, name, x1, y1, width, boxh-1, &val, (float) md->items[a].retval, 0.0, 0, 0, "");
|
||||
y1 -= boxh;
|
||||
|
@@ -79,6 +79,7 @@
|
||||
#include "BIF_space.h"
|
||||
#include "BIF_glutil.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_interface_icons.h"
|
||||
#include "BIF_butspace.h"
|
||||
#include "BIF_language.h"
|
||||
|
||||
@@ -169,15 +170,15 @@ static void ui_draw_icon(uiBut *but, BIFIconID icon)
|
||||
else {
|
||||
xs= but->x1+6.0;
|
||||
}
|
||||
ys= (but->y1+but->y2- BIF_get_icon_height(icon))/2.0;
|
||||
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0;
|
||||
}
|
||||
if(but->flag & UI_ICON_RIGHT) {
|
||||
xs= but->x2-17.0;
|
||||
ys= (but->y1+but->y2- BIF_get_icon_height(icon))/2.0;
|
||||
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0;
|
||||
}
|
||||
if (!((but->flag & UI_ICON_RIGHT) || (but->flag & UI_ICON_LEFT))) {
|
||||
xs= (but->x1+but->x2- BIF_get_icon_width(icon))/2.0;
|
||||
ys= (but->y1+but->y2- BIF_get_icon_height(icon))/2.0;
|
||||
xs= (but->x1+but->x2- BIF_icon_get_width(icon))/2.0;
|
||||
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0;
|
||||
}
|
||||
|
||||
if(but->aspect>1.1) glPixelZoom(1.0/but->aspect, 1.0/but->aspect);
|
||||
@@ -192,7 +193,7 @@ static void ui_draw_icon(uiBut *but, BIFIconID icon)
|
||||
else if(but->flag & UI_ACTIVE);
|
||||
else blend= -60;
|
||||
}
|
||||
BIF_draw_icon_blended(xs, ys, icon, but->themecol, blend);
|
||||
BIF_icon_draw_blended(xs, ys, icon, but->themecol, blend);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
@@ -1520,7 +1521,7 @@ static void ui_draw_text_icon(uiBut *but)
|
||||
if ( (but->flag & UI_HAS_ICON) && (but->flag & UI_ICON_LEFT) ) {
|
||||
ui_draw_icon(but, but->icon);
|
||||
|
||||
if(but->flag & UI_TEXT_LEFT) x= but->x1+24.0;
|
||||
if(but->flag & UI_TEXT_LEFT) x= but->x1 + BIF_icon_get_width(but->icon)+4.0;
|
||||
else x= (but->x1+but->x2-but->strwidth+1)/2.0;
|
||||
}
|
||||
else {
|
||||
|
758
source/blender/src/interface_icons.c
Normal file
758
source/blender/src/interface_icons.c
Normal file
@@ -0,0 +1,758 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_arithb.h"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_texture_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_texture_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_world.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_icons.h"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
#include "BIF_interface_icons.h"
|
||||
#include "BIF_previewrender.h"
|
||||
#include "BIF_resources.h" /* elubie: should be removed once the enum for the ICONS is in BIF_preview_icons.h */
|
||||
|
||||
#include "PIL_time.h"
|
||||
|
||||
#include "RE_renderconverter.h"
|
||||
|
||||
#include "blendef.h" // CLAMP
|
||||
#include "datatoc.h"
|
||||
#include "render.h"
|
||||
#include "mydevice.h"
|
||||
|
||||
/* OpenGL textures have to be size 2n+2 x 2m+2 for some n,m */
|
||||
/* choose ICON_RENDERSIZE accordingly */
|
||||
#define ICON_RENDERSIZE 32
|
||||
#define ICON_MIPMAPS 8
|
||||
|
||||
typedef struct DrawInfo {
|
||||
int w;
|
||||
int h;
|
||||
int rw;
|
||||
int rh;
|
||||
VectorDrawFunc drawFunc; /* If drawFunc is defined then it is a vector icon, otherwise use rect */
|
||||
float aspect;
|
||||
unsigned int* rect;
|
||||
} DrawInfo;
|
||||
|
||||
static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int w, int h)
|
||||
{
|
||||
Icon* new_icon = 0;
|
||||
DrawInfo* di;
|
||||
int y = 0;
|
||||
|
||||
new_icon = MEM_callocN(sizeof(Icon), "texicon");
|
||||
|
||||
new_icon->obj = 0; /* icon is not for library object */
|
||||
new_icon->type = 0;
|
||||
new_icon->changed = 0;
|
||||
|
||||
|
||||
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
|
||||
di->drawFunc = 0;
|
||||
di->w = w;
|
||||
di->h = h;
|
||||
di->rw = w;
|
||||
di->rh = h;
|
||||
di->aspect = 1.0f;
|
||||
di->rect = MEM_mallocN(w*h*sizeof(unsigned int), "icon_rect");
|
||||
|
||||
/* Here we store the rect in the icon - same as before */
|
||||
for (y=0; y<h; y++) {
|
||||
memcpy(&di->rect[y*w], &bbuf->rect[(y+yofs)*512+xofs], w*sizeof(int));
|
||||
}
|
||||
|
||||
new_icon->drawinfo_free = BIF_icons_free_drawinfo;
|
||||
new_icon->drawinfo = di;
|
||||
|
||||
BKE_icon_set(icon_id, new_icon);
|
||||
}
|
||||
|
||||
static void def_internal_vicon( int icon_id, int w, int h, VectorDrawFunc drawFunc)
|
||||
{
|
||||
Icon* new_icon = 0;
|
||||
DrawInfo* di;
|
||||
|
||||
new_icon = MEM_callocN(sizeof(Icon), "texicon");
|
||||
|
||||
new_icon->obj = 0; /* icon is not for library object */
|
||||
new_icon->type = 0;
|
||||
new_icon->changed = 0;
|
||||
|
||||
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
|
||||
di->drawFunc =drawFunc;
|
||||
di->w = w;
|
||||
di->h = h;
|
||||
di->rw = w;
|
||||
di->rh = h;
|
||||
di->aspect = 1.0f;
|
||||
di->rect = 0;
|
||||
|
||||
new_icon->drawinfo_free = 0;
|
||||
new_icon->drawinfo = di;
|
||||
|
||||
BKE_icon_set(icon_id, new_icon);
|
||||
}
|
||||
|
||||
/* Vector Icon Drawing Routines */
|
||||
|
||||
/* Utilities */
|
||||
|
||||
static void viconutil_set_point(GLint pt[2], int x, int y)
|
||||
{
|
||||
pt[0] = x;
|
||||
pt[1] = y;
|
||||
}
|
||||
|
||||
static void viconutil_draw_tri(GLint (*pts)[2])
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void viconutil_draw_quad(GLint (*pts)[2])
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glVertex2iv(pts[2]);
|
||||
glVertex2iv(pts[3]);
|
||||
glEnd();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
|
||||
{
|
||||
int i;
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (i=0; i<numPoints; i++) {
|
||||
glVertex2iv(pts[i]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
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);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/* Drawing functions */
|
||||
|
||||
static void vicon_x_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
x += 3;
|
||||
y += 3;
|
||||
w -= 6;
|
||||
h -= 6;
|
||||
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
|
||||
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);
|
||||
|
||||
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(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);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, alpha);
|
||||
viconutil_draw_lineloop(pts, 4);
|
||||
|
||||
glColor3f(1, 1, 0.0);
|
||||
viconutil_draw_points(pts, 4, 1);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
glColor4f(0.5, 0.5, 0.5, alpha);
|
||||
viconutil_draw_tri(pts);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
|
||||
glColor3f(1, 1, 0.0);
|
||||
viconutil_draw_points(pts, 3, 1);
|
||||
}
|
||||
|
||||
static void vicon_editmode_dehlt_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);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
|
||||
glColor3f(.9, .9, .9);
|
||||
viconutil_draw_points(pts, 3, 1);
|
||||
}
|
||||
|
||||
static void vicon_disclosure_tri_right_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
GLint pts[3][2];
|
||||
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);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(0.8, 0.8, 0.8, alpha);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glColor4f(0.3, 0.3, 0.3, alpha);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
}
|
||||
|
||||
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
GLint pts[3][2];
|
||||
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);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(0.8, 0.8, 0.8, alpha);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glColor4f(0.3, 0.3, 0.3, alpha);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
}
|
||||
|
||||
static void vicon_move_up_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
static void vicon_move_down_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
/***/
|
||||
|
||||
|
||||
/* this only works for the hardcoded buttons image, turning the grey AA pixels to alpha, and slight off-grey to half alpha */
|
||||
|
||||
static void clear_transp_rect_soft(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
|
||||
{
|
||||
int x, y, val;
|
||||
|
||||
for (y=1; y<h-1; y++) {
|
||||
unsigned char *row0= &rect[(y-1)*rowstride];
|
||||
unsigned char *row= &rect[y*rowstride];
|
||||
unsigned char *row1= &rect[(y+1)*rowstride];
|
||||
for (x=1; x<w-1; x++) {
|
||||
unsigned char *pxl0= &row0[x*4];
|
||||
unsigned char *pxl= &row[x*4];
|
||||
unsigned char *pxl1= &row1[x*4];
|
||||
|
||||
if(pxl[3]!=0) {
|
||||
val= (abs(pxl[0]-transp[0]) + abs(pxl[1]-transp[1]) + abs(pxl[2]-transp[2]))/3;
|
||||
if(val<20) {
|
||||
pxl[3]= 128;
|
||||
}
|
||||
else if(val<50) {
|
||||
// one of pixels surrounding has alpha null?
|
||||
if(pxl[3-4]==0 || pxl[3+4]==0 || pxl0[3]==0 || pxl1[3]==0) {
|
||||
|
||||
if(pxl[0]>val) pxl[0]-= val; else pxl[0]= 0;
|
||||
if(pxl[1]>val) pxl[1]-= val; else pxl[1]= 0;
|
||||
if(pxl[2]>val) pxl[2]-= val; else pxl[2]= 0;
|
||||
|
||||
pxl[3]= 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void clear_transp_rect(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
|
||||
{
|
||||
int x,y;
|
||||
for (y=0; y<h; y++) {
|
||||
unsigned char *row= &rect[y*rowstride];
|
||||
for (x=0; x<w; x++) {
|
||||
unsigned char *pxl= &row[x*4];
|
||||
if (*((unsigned int*) pxl)==*((unsigned int*) transp)) {
|
||||
pxl[3]= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void prepare_internal_icons(ImBuf* bbuf)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
/* hack! */
|
||||
for (y=0; y<12; y++) {
|
||||
for (x=0; x<21; x++) {
|
||||
int rowstride= bbuf->x*4;
|
||||
unsigned char *start= ((unsigned char*) bbuf->rect) + (y*21 + 3)*rowstride + (x*20 + 3)*4;
|
||||
unsigned char transp[4];
|
||||
/* this sets backdrop of icon to zero alpha */
|
||||
transp[0]= start[0];
|
||||
transp[1]= start[1];
|
||||
transp[2]= start[2];
|
||||
transp[3]= start[3];
|
||||
clear_transp_rect(transp, start, 20, 21, rowstride);
|
||||
clear_transp_rect_soft(transp, start, 20, 21, rowstride);
|
||||
|
||||
/* this sets outside of icon to zero alpha */
|
||||
start= ((unsigned char*) bbuf->rect) + (y*21)*rowstride + (x*20)*4;
|
||||
QUATCOPY(transp, start);
|
||||
clear_transp_rect(transp, start, 20, 21, rowstride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void init_internal_icons()
|
||||
{
|
||||
ImBuf *bbuf= IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
|
||||
int x, y;
|
||||
|
||||
prepare_internal_icons(bbuf);
|
||||
|
||||
for (y=0; y<12; y++) {
|
||||
for (x=0; x<21; x++) {
|
||||
if (x==11 && y==6) {
|
||||
def_internal_icon(bbuf, ICON_BEVELBUT_HLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
|
||||
} else if (x==12 && y==6) {
|
||||
def_internal_icon(bbuf, ICON_BEVELBUT_DEHLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
|
||||
} else {
|
||||
def_internal_icon(bbuf, BIFICONID_FIRST + y*21 + x, x*20+3, y*21+3, 15, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def_internal_vicon(VICON_VIEW3D, 16, 16, vicon_view3d_draw);
|
||||
def_internal_vicon(VICON_EDIT, 16, 16, vicon_edit_draw);
|
||||
def_internal_vicon(VICON_EDITMODE_DEHLT, 16, 16, vicon_editmode_dehlt_draw);
|
||||
def_internal_vicon(VICON_EDITMODE_HLT, 16, 16, vicon_editmode_hlt_draw);
|
||||
def_internal_vicon(VICON_DISCLOSURE_TRI_RIGHT, 16, 16, vicon_disclosure_tri_right_draw);
|
||||
def_internal_vicon(VICON_DISCLOSURE_TRI_DOWN, 16, 16, vicon_disclosure_tri_down_draw);
|
||||
def_internal_vicon(VICON_MOVE_UP, 16, 16, vicon_move_up_draw);
|
||||
def_internal_vicon(VICON_MOVE_DOWN, 16, 16, vicon_move_down_draw);
|
||||
def_internal_vicon(VICON_X, 16, 16, vicon_x_draw);
|
||||
|
||||
IMB_freeImBuf(bbuf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BIF_icons_free()
|
||||
{
|
||||
BKE_icons_free();
|
||||
}
|
||||
|
||||
void BIF_icons_free_drawinfo(void *drawinfo)
|
||||
{
|
||||
DrawInfo* di = drawinfo;
|
||||
|
||||
if (di)
|
||||
{
|
||||
MEM_freeN(di->rect);
|
||||
MEM_freeN(di);
|
||||
}
|
||||
}
|
||||
|
||||
static DrawInfo* icon_create_drawinfo()
|
||||
{
|
||||
DrawInfo* di = 0;
|
||||
|
||||
di = MEM_callocN(sizeof(DrawInfo), "di_icon");
|
||||
|
||||
di->drawFunc = 0;
|
||||
di->w = 16;
|
||||
di->h = 16;
|
||||
di->rw = ICON_RENDERSIZE;
|
||||
di->rh = ICON_RENDERSIZE;
|
||||
di->rect = 0;
|
||||
di->aspect = 1.0f;
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
int BIF_icon_get_width(int icon_id)
|
||||
{
|
||||
Icon* icon = 0;
|
||||
DrawInfo* di = 0;
|
||||
|
||||
icon = BKE_icon_get(icon_id);
|
||||
|
||||
if (!icon) {
|
||||
printf("BIF_icon_get_width: Internal error, no icon for icon ID: %d\n", icon_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
di = (DrawInfo*)icon->drawinfo;
|
||||
if (!di) {
|
||||
di = icon_create_drawinfo();
|
||||
icon->drawinfo = di;
|
||||
}
|
||||
|
||||
if (di)
|
||||
return di->w;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BIF_icon_get_height(int icon_id)
|
||||
{
|
||||
Icon* icon = 0;
|
||||
DrawInfo* di = 0;
|
||||
|
||||
icon = BKE_icon_get(icon_id);
|
||||
|
||||
if (!icon) {
|
||||
printf("BIF_icon_get_width: Internal error, no icon for icon ID: %d\n", icon_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
di = (DrawInfo*)icon->drawinfo;
|
||||
|
||||
if (!di) {
|
||||
di = icon_create_drawinfo();
|
||||
icon->drawinfo = di;
|
||||
}
|
||||
|
||||
if (di)
|
||||
return di->h;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BIF_icons_init(int first_dyn_id)
|
||||
{
|
||||
DrawInfo* di;
|
||||
|
||||
BKE_icons_init(first_dyn_id);
|
||||
init_internal_icons();
|
||||
}
|
||||
|
||||
/* only called when icon has changed */
|
||||
/* only call with valid pointer from BIF_icon_draw */
|
||||
static void icon_set_image(ID* id, DrawInfo* di)
|
||||
{
|
||||
ImBuf* ima = 0;
|
||||
RenderInfo ri;
|
||||
int it;
|
||||
|
||||
if (!di) return;
|
||||
|
||||
if (!di->rect)
|
||||
di->rect = MEM_callocN(di->rw*di->rh*sizeof(unsigned int), "laprevrect");
|
||||
|
||||
ri.cury = 0;
|
||||
ri.rect = 0;
|
||||
ri.pr_rectx = di->rw;
|
||||
ri.pr_recty = di->rh;
|
||||
|
||||
/* no drawing (see last parameter doDraw, just calculate preview image
|
||||
- hopefully small enough to be fast */
|
||||
if (GS(id->name) == ID_IM)
|
||||
BIF_calcpreview_image((struct Image*)id, &ri, ri.pr_rectx, ri.pr_recty);
|
||||
else {
|
||||
BIF_previewrender(id, &ri, NULL, 0);
|
||||
|
||||
/* need to correct alpha */
|
||||
/*
|
||||
for( it = 0; it < ri.pr_rectx*ri.pr_recty; ++it) {
|
||||
ri.rect[it] |= 0xFF000000;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* and copy the image into the icon */
|
||||
memcpy(di->rect, ri.rect,di->rw*di->rh*sizeof(unsigned int));
|
||||
|
||||
/* and clean up */
|
||||
MEM_freeN(ri.rect);
|
||||
ri.rect = 0;
|
||||
|
||||
}
|
||||
|
||||
void BIF_icon_draw( int x, int y, int icon_id)
|
||||
{
|
||||
Icon* icon = 0;
|
||||
DrawInfo* di = 0;
|
||||
int pr_size = 0;
|
||||
|
||||
ImBuf *ima;
|
||||
|
||||
icon = BKE_icon_get(icon_id);
|
||||
|
||||
if (!icon) {
|
||||
printf("BIF_icon_draw: Internal error, no icon for icon ID: %d\n", icon_id);
|
||||
return;
|
||||
}
|
||||
|
||||
di = (DrawInfo*)icon->drawinfo;
|
||||
|
||||
if (!di) {
|
||||
|
||||
di = icon_create_drawinfo();
|
||||
|
||||
icon->changed = 1;
|
||||
icon->drawinfo = di;
|
||||
icon->drawinfo_free = BIF_icons_free_drawinfo;
|
||||
}
|
||||
|
||||
if (di->drawFunc) {
|
||||
di->drawFunc(x, y, di->w, di->h, 1.0f);
|
||||
}
|
||||
else {
|
||||
if (icon->changed) /* changed only ever set by dynamic icons */
|
||||
{
|
||||
icon_set_image((ID*)icon->obj, icon->drawinfo);
|
||||
icon->changed = 0;
|
||||
}
|
||||
|
||||
if (!di->rect) return; /* something has gone wrong! */
|
||||
|
||||
/* di->rect contains image in 'rendersize' */
|
||||
|
||||
/* first allocate imbuf for scaling and copy preview into it */
|
||||
ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);
|
||||
memcpy(ima->rect, di->rect,di->rw*di->rh*sizeof(unsigned int));
|
||||
|
||||
/* scale it */
|
||||
IMB_scaleImBuf(ima, di->w, di->h);
|
||||
|
||||
glRasterPos2f(x, y);
|
||||
glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
|
||||
|
||||
IMB_freeImBuf(ima);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade)
|
||||
{
|
||||
int done;
|
||||
|
||||
if(shade < 0) {
|
||||
float r= (128+shade)/128.0;
|
||||
glPixelTransferf(GL_ALPHA_SCALE, r);
|
||||
}
|
||||
|
||||
BIF_icon_draw(x, y, icon_id);
|
||||
|
||||
glPixelTransferf(GL_ALPHA_SCALE, 1.0);
|
||||
}
|
||||
|
||||
void BIF_icon_set_aspect(int icon_id, float aspect) {
|
||||
Icon* icon = 0;
|
||||
DrawInfo* di = 0;
|
||||
|
||||
icon = BKE_icon_get(icon_id);
|
||||
|
||||
if (!icon) {
|
||||
printf("BIF_icon_set_aspect: Internal error, no icon for icon ID: %d\n", icon_id);
|
||||
return;
|
||||
}
|
||||
|
||||
di = (DrawInfo*)icon->drawinfo;
|
||||
|
||||
if (!di) {
|
||||
di = icon_create_drawinfo();
|
||||
|
||||
icon->changed = 1;
|
||||
icon->drawinfo = di;
|
||||
icon->drawinfo_free = BIF_icons_free_drawinfo;
|
||||
}
|
||||
di->aspect = aspect;
|
||||
/* scale width and height according to aspect */
|
||||
di->w = 16.0 / di->aspect;
|
||||
di->h = 16.0 / di->aspect;
|
||||
|
||||
}
|
||||
|
@@ -1117,7 +1117,7 @@ void ui_draw_panel(uiBlock *block)
|
||||
ui_draw_x_icon(block->minx+2+ofsx, block->maxy+5);
|
||||
/*
|
||||
if(block->aspect>1.1) glPixelZoom(1.0/block->aspect, 1.0/block->aspect);
|
||||
BIF_draw_icon(block->minx+4, block->maxy+3, ICON_PANEL_CLOSE);
|
||||
BIF_icon_draw(block->minx+4, block->maxy+3, ICON_PANEL_CLOSE);
|
||||
if(block->aspect>1.1) glPixelZoom(1.0, 1.0);
|
||||
*/
|
||||
ofsx= 22;
|
||||
|
@@ -82,6 +82,7 @@
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_graphics.h"
|
||||
#include "BIF_interface.h"
|
||||
#include "BIF_interface_icons.h"
|
||||
#include "BIF_mywindow.h"
|
||||
#include "BIF_outliner.h"
|
||||
#include "BIF_language.h"
|
||||
@@ -2092,104 +2093,104 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
|
||||
if(tselem->type) {
|
||||
switch( tselem->type) {
|
||||
case TSE_NLA:
|
||||
BIF_draw_icon(x, y, ICON_NLA); break;
|
||||
BIF_icon_draw(x, y, ICON_NLA); break;
|
||||
case TSE_NLA_ACTION:
|
||||
BIF_draw_icon(x, y, ICON_ACTION); break;
|
||||
BIF_icon_draw(x, y, ICON_ACTION); break;
|
||||
case TSE_DEFGROUP_BASE:
|
||||
BIF_draw_icon(x, y, ICON_VERTEXSEL); break;
|
||||
BIF_icon_draw(x, y, ICON_VERTEXSEL); break;
|
||||
case TSE_BONE:
|
||||
case TSE_EBONE:
|
||||
BIF_draw_icon(x, y, ICON_WPAINT_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_WPAINT_DEHLT); break;
|
||||
case TSE_CONSTRAINT_BASE:
|
||||
BIF_draw_icon(x, y, ICON_CONSTRAINT); break;
|
||||
BIF_icon_draw(x, y, ICON_CONSTRAINT); break;
|
||||
case TSE_MODIFIER_BASE:
|
||||
BIF_draw_icon(x, y, ICON_MODIFIER); break;
|
||||
BIF_icon_draw(x, y, ICON_MODIFIER); break;
|
||||
case TSE_LINKED_OB:
|
||||
BIF_draw_icon(x, y, ICON_OBJECT); break;
|
||||
BIF_icon_draw(x, y, ICON_OBJECT); break;
|
||||
case TSE_MODIFIER:
|
||||
{
|
||||
Object *ob= (Object *)tselem->id;
|
||||
ModifierData *md= BLI_findlink(&ob->modifiers, tselem->nr);
|
||||
switch(md->type) {
|
||||
case eModifierType_Subsurf:
|
||||
BIF_draw_icon(x, y, ICON_MOD_SUBSURF); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_SUBSURF); break;
|
||||
case eModifierType_Armature:
|
||||
BIF_draw_icon(x, y, ICON_ARMATURE); break;
|
||||
BIF_icon_draw(x, y, ICON_ARMATURE); break;
|
||||
case eModifierType_Lattice:
|
||||
BIF_draw_icon(x, y, ICON_LATTICE); break;
|
||||
BIF_icon_draw(x, y, ICON_LATTICE); break;
|
||||
case eModifierType_Curve:
|
||||
BIF_draw_icon(x, y, ICON_CURVE); break;
|
||||
BIF_icon_draw(x, y, ICON_CURVE); break;
|
||||
case eModifierType_Build:
|
||||
BIF_draw_icon(x, y, ICON_MOD_BUILD); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_BUILD); break;
|
||||
case eModifierType_Mirror:
|
||||
BIF_draw_icon(x, y, ICON_MOD_MIRROR); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_MIRROR); break;
|
||||
case eModifierType_Decimate:
|
||||
BIF_draw_icon(x, y, ICON_MOD_DECIM); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_DECIM); break;
|
||||
case eModifierType_Wave:
|
||||
BIF_draw_icon(x, y, ICON_MOD_WAVE); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_WAVE); break;
|
||||
case eModifierType_Hook:
|
||||
BIF_draw_icon(x, y, ICON_HOOK); break;
|
||||
BIF_icon_draw(x, y, ICON_HOOK); break;
|
||||
case eModifierType_Softbody:
|
||||
BIF_draw_icon(x, y, ICON_MOD_SOFT); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_SOFT); break;
|
||||
case eModifierType_Boolean:
|
||||
BIF_draw_icon(x, y, ICON_MOD_BOOLEAN); break;
|
||||
BIF_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
|
||||
default:
|
||||
BIF_draw_icon(x, y, ICON_DOT); break;
|
||||
BIF_icon_draw(x, y, ICON_DOT); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSE_SCRIPT_BASE:
|
||||
BIF_draw_icon(x, y, ICON_TEXT); break;
|
||||
BIF_icon_draw(x, y, ICON_TEXT); break;
|
||||
case TSE_POSE_BASE:
|
||||
BIF_draw_icon(x, y, ICON_ARMATURE_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_ARMATURE_DEHLT); break;
|
||||
case TSE_POSE_CHANNEL:
|
||||
BIF_draw_icon(x, y, ICON_WPAINT_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_WPAINT_DEHLT); break;
|
||||
default:
|
||||
BIF_draw_icon(x, y, ICON_DOT); break;
|
||||
BIF_icon_draw(x, y, ICON_DOT); break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch( GS(tselem->id->name)) {
|
||||
case ID_SCE:
|
||||
BIF_draw_icon(x, y, ICON_SCENE_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_SCENE_DEHLT); break;
|
||||
case ID_OB:
|
||||
BIF_draw_icon(x, y, ICON_OBJECT); break;
|
||||
BIF_icon_draw(x, y, ICON_OBJECT); break;
|
||||
case ID_ME:
|
||||
BIF_draw_icon(x, y, ICON_MESH); break;
|
||||
BIF_icon_draw(x, y, ICON_MESH); break;
|
||||
case ID_CU:
|
||||
BIF_draw_icon(x, y, ICON_CURVE); break;
|
||||
BIF_icon_draw(x, y, ICON_CURVE); break;
|
||||
case ID_MB:
|
||||
BIF_draw_icon(x, y, ICON_MBALL); break;
|
||||
BIF_icon_draw(x, y, ICON_MBALL); break;
|
||||
case ID_LT:
|
||||
BIF_draw_icon(x, y, ICON_LATTICE); break;
|
||||
BIF_icon_draw(x, y, ICON_LATTICE); break;
|
||||
case ID_LA:
|
||||
BIF_draw_icon(x, y, ICON_LAMP_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_LAMP_DEHLT); break;
|
||||
case ID_MA:
|
||||
BIF_draw_icon(x, y, ICON_MATERIAL_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_MATERIAL_DEHLT); break;
|
||||
case ID_TE:
|
||||
BIF_draw_icon(x, y, ICON_TEXTURE_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_TEXTURE_DEHLT); break;
|
||||
case ID_IP:
|
||||
BIF_draw_icon(x, y, ICON_IPO_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_IPO_DEHLT); break;
|
||||
case ID_IM:
|
||||
BIF_draw_icon(x, y, ICON_IMAGE_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_IMAGE_DEHLT); break;
|
||||
case ID_SO:
|
||||
BIF_draw_icon(x, y, ICON_SPEAKER); break;
|
||||
BIF_icon_draw(x, y, ICON_SPEAKER); break;
|
||||
case ID_AR:
|
||||
BIF_draw_icon(x, y, ICON_ARMATURE); break;
|
||||
BIF_icon_draw(x, y, ICON_ARMATURE); break;
|
||||
case ID_CA:
|
||||
BIF_draw_icon(x, y, ICON_CAMERA_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_CAMERA_DEHLT); break;
|
||||
case ID_KE:
|
||||
BIF_draw_icon(x, y, ICON_EDIT_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_EDIT_DEHLT); break;
|
||||
case ID_WO:
|
||||
BIF_draw_icon(x, y, ICON_WORLD_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_WORLD_DEHLT); break;
|
||||
case ID_AC:
|
||||
BIF_draw_icon(x, y, ICON_ACTION); break;
|
||||
BIF_icon_draw(x, y, ICON_ACTION); break;
|
||||
case ID_NLA:
|
||||
BIF_draw_icon(x, y, ICON_NLA); break;
|
||||
BIF_icon_draw(x, y, ICON_NLA); break;
|
||||
case ID_TXT:
|
||||
BIF_draw_icon(x, y, ICON_SCRIPT); break;
|
||||
BIF_icon_draw(x, y, ICON_SCRIPT); break;
|
||||
case ID_GR:
|
||||
BIF_draw_icon(x, y, ICON_CIRCLE_DEHLT); break;
|
||||
BIF_icon_draw(x, y, ICON_CIRCLE_DEHLT); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2307,9 +2308,9 @@ static void outliner_draw_tree_element(SpaceOops *soops, TreeElement *te, int st
|
||||
|
||||
// icons a bit higher
|
||||
if(tselem->flag & TSE_CLOSED)
|
||||
BIF_draw_icon(icon_x, *starty+2, ICON_TRIA_RIGHT);
|
||||
BIF_icon_draw(icon_x, *starty+2, ICON_TRIA_RIGHT);
|
||||
else
|
||||
BIF_draw_icon(icon_x, *starty+2, ICON_TRIA_DOWN);
|
||||
BIF_icon_draw(icon_x, *starty+2, ICON_TRIA_DOWN);
|
||||
}
|
||||
offsx+= OL_X;
|
||||
|
||||
@@ -2322,9 +2323,9 @@ static void outliner_draw_tree_element(SpaceOops *soops, TreeElement *te, int st
|
||||
if(tselem->id->lib && tselem->type==0) {
|
||||
glPixelTransferf(GL_ALPHA_SCALE, 0.5);
|
||||
if(tselem->id->flag & LIB_INDIRECT)
|
||||
BIF_draw_icon(startx+offsx, *starty+2, ICON_DATALIB);
|
||||
BIF_icon_draw(startx+offsx, *starty+2, ICON_DATALIB);
|
||||
else
|
||||
BIF_draw_icon(startx+offsx, *starty+2, ICON_PARLIB);
|
||||
BIF_icon_draw(startx+offsx, *starty+2, ICON_PARLIB);
|
||||
glPixelTransferf(GL_ALPHA_SCALE, 1.0);
|
||||
offsx+= OL_X;
|
||||
}
|
||||
|
@@ -73,6 +73,9 @@
|
||||
#include "BKE_world.h"
|
||||
#include "BKE_texture.h"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "BSE_headerbuttons.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
@@ -92,13 +95,13 @@
|
||||
#include "blendef.h" /* CLAMP */
|
||||
#include "interface.h" /* ui_graphics_to_window() SOLVE! (ton) */
|
||||
|
||||
#define PR_RECTX 141
|
||||
#define PR_RECTY 141
|
||||
#define PR_XMIN 10
|
||||
#define PR_YMIN 5
|
||||
#define PR_XMAX 200
|
||||
#define PR_YMAX 195
|
||||
|
||||
#define PREVIEW_RENDERSIZE 141;
|
||||
|
||||
#define PR_FACY (PR_YMAX-PR_YMIN-4)/(PR_RECTY)
|
||||
|
||||
static rctf prerect;
|
||||
@@ -172,9 +175,10 @@ static int rcubi[3][4]= {
|
||||
{3, 0, 2, 6} };
|
||||
|
||||
|
||||
static int ray_previewrender(int x, int y, float *vec, float *vn)
|
||||
static int ray_previewrender(int x, int y, float *vec, float *vn, short pr_rectx, short pr_recty)
|
||||
{
|
||||
float scalef= 10.0f/100.0f;
|
||||
/* float scalef= 10.0/100.0; - not fixed any more because of different render sizes */
|
||||
float scalef= ( 64.0f / (float)pr_rectx ) * 0.25f;
|
||||
float ray1[3], ray2[3];
|
||||
float minlabda, labda;
|
||||
int totface= 3, hitface= -1;
|
||||
@@ -217,6 +221,8 @@ static int ray_previewrender(int x, int y, float *vec, float *vn)
|
||||
|
||||
static unsigned int previewback(int type, int x, int y)
|
||||
{
|
||||
unsigned int col;
|
||||
char* pcol;
|
||||
|
||||
/* checkerboard, for later
|
||||
x+= PR_RECTX/2;
|
||||
@@ -226,16 +232,20 @@ static unsigned int previewback(int type, int x, int y)
|
||||
*/
|
||||
|
||||
if(type & MA_DARK) {
|
||||
if(abs(x)>abs(y)) return 0;
|
||||
else return 0x40404040;
|
||||
if(abs(x)>abs(y)) col= 0;
|
||||
else col= 0x40404040;
|
||||
}
|
||||
else {
|
||||
if(abs(x)>abs(y)) return 0x40404040;
|
||||
else return 0xa0a0a0a0;
|
||||
if(abs(x)>abs(y)) col= 0x40404040;
|
||||
else col= 0xa0a0a0a0;
|
||||
}
|
||||
pcol = (char*) &col;
|
||||
pcol[3] = 0; /* set alpha to zero - endianess!*/
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
static void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax)
|
||||
void BIF_set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short pr_rectx, short pr_recty)
|
||||
{
|
||||
float pr_sizex, pr_sizey;
|
||||
|
||||
@@ -250,8 +260,8 @@ static void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax)
|
||||
pr_sizex= (prerect.xmax-prerect.xmin);
|
||||
pr_sizey= (prerect.ymax-prerect.ymin);
|
||||
|
||||
pr_facx= ( pr_sizex-1.0f)/PR_RECTX;
|
||||
pr_facy= ( pr_sizey-1.0f)/PR_RECTY;
|
||||
pr_facx= ( pr_sizex-1.0f)/pr_rectx;
|
||||
pr_facy= ( pr_sizey-1.0f)/pr_recty;
|
||||
|
||||
/* correction for gla draw */
|
||||
prerect.xmin-= curarea->winrct.xmin;
|
||||
@@ -268,7 +278,7 @@ static void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax)
|
||||
|
||||
}
|
||||
|
||||
static void end_previewrect(void)
|
||||
void BIF_end_previewrect(void)
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
@@ -283,18 +293,18 @@ static void end_previewrect(void)
|
||||
|
||||
}
|
||||
|
||||
static void display_pr_scanline(unsigned int *rect, int recty)
|
||||
static void display_pr_scanline(unsigned int *rect, int recty, short pr_rectx)
|
||||
{
|
||||
|
||||
/* we do steps of 4 scanlines. but draw 5, because of errors in some gfx cards (nvidia geforce, ati...) */
|
||||
if( (recty & 3)==3) {
|
||||
|
||||
if(recty == 3) {
|
||||
glaDrawPixelsSafe(prerect.xmin, prerect.ymin, PR_RECTX, 4, rect);
|
||||
glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, rect);
|
||||
}
|
||||
else {
|
||||
rect+= (recty-4)*PR_RECTX;
|
||||
glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), PR_RECTX, 5, rect);
|
||||
rect+= (recty-4)*pr_rectx;
|
||||
glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,7 +350,7 @@ void BIF_all_preview_changed(void)
|
||||
while(sa) {
|
||||
if(sa->spacetype==SPACE_BUTS) {
|
||||
sbuts= sa->spacedata.first;
|
||||
sbuts->cury= 0;
|
||||
if (sbuts->ri) sbuts->ri->cury= 0;
|
||||
addafterqueue(sa->win, RENDERPREVIEW, 1);
|
||||
}
|
||||
sa= sa->next;
|
||||
@@ -362,7 +372,7 @@ void BIF_preview_changed(SpaceButs *sbuts)
|
||||
if(sa->spacetype==SPACE_BUTS) {
|
||||
sbuts= sa->spacedata.first;
|
||||
if(sbuts->mainb==mainb && sbuts->tab[mainb]==tab) {
|
||||
sbuts->cury= 0;
|
||||
if (sbuts->ri) sbuts->ri->cury= 0;
|
||||
addafterqueue(sbuts->area->win, RENDERPREVIEW, 1);
|
||||
}
|
||||
}
|
||||
@@ -371,61 +381,167 @@ void BIF_preview_changed(SpaceButs *sbuts)
|
||||
}
|
||||
}
|
||||
|
||||
void BIF_previewdraw_render(struct RenderInfo* ri, ScrArea* area)
|
||||
{
|
||||
int y;
|
||||
|
||||
if (!ri) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y=0; y<ri->pr_recty; y++) {
|
||||
display_pr_scanline(ri->rect, y, ri->pr_rectx);
|
||||
}
|
||||
}
|
||||
|
||||
/* is panel callback, supposed to be called with correct panel offset matrix */
|
||||
void BIF_previewdraw(void)
|
||||
{
|
||||
SpaceButs *sbuts= curarea->spacedata.first;
|
||||
|
||||
if (sbuts->rect==0) BIF_preview_changed(sbuts);
|
||||
if (!sbuts->ri) {
|
||||
sbuts->ri= MEM_callocN(sizeof(RenderInfo), "butsrenderinfo");
|
||||
sbuts->ri->cury = 0;
|
||||
sbuts->ri->rect = 0;
|
||||
sbuts->ri->pr_rectx = PREVIEW_RENDERSIZE;
|
||||
sbuts->ri->pr_recty = PREVIEW_RENDERSIZE;
|
||||
}
|
||||
|
||||
if (sbuts->ri->rect==0) BIF_preview_changed(sbuts);
|
||||
else {
|
||||
int y;
|
||||
|
||||
set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX);
|
||||
|
||||
for (y=0; y<PR_RECTY; y++) {
|
||||
display_pr_scanline(sbuts->rect, y);
|
||||
}
|
||||
|
||||
end_previewrect();
|
||||
|
||||
if (sbuts->mainb==CONTEXT_SHADING && sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
|
||||
draw_tex_crop(sbuts->lockpoin);
|
||||
}
|
||||
BIF_set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty);
|
||||
BIF_previewdraw_render(sbuts->ri, sbuts->area);
|
||||
BIF_end_previewrect();
|
||||
}
|
||||
if(sbuts->cury==0) BIF_preview_changed(sbuts);
|
||||
if(sbuts->ri->cury==0) BIF_preview_changed(sbuts);
|
||||
|
||||
}
|
||||
|
||||
static void sky_preview_pixel(float lens, int x, int y, char *rect)
|
||||
static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rectx, short pr_recty)
|
||||
{
|
||||
float view[3];
|
||||
|
||||
if(R.wrld.skytype & WO_SKYPAPER) {
|
||||
view[0]= (2*x)/(float)PR_RECTX;
|
||||
view[1]= (2*y)/(float)PR_RECTY;
|
||||
view[0]= (2*x)/(float)pr_rectx;
|
||||
view[1]= (2*y)/(float)pr_recty;
|
||||
view[2]= 0.0f;
|
||||
}
|
||||
else {
|
||||
view[0]= x;
|
||||
view[1]= y;
|
||||
view[2]= -lens*PR_RECTX/32.0;
|
||||
view[2]= -lens*pr_rectx/32.0;
|
||||
Normalise(view);
|
||||
}
|
||||
RE_sky_char(view, rect);
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
|
||||
static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char *rect)
|
||||
static void init_preview_world(World* wrld)
|
||||
{
|
||||
int a;
|
||||
char *cp;
|
||||
|
||||
if(wrld) {
|
||||
R.wrld= *(wrld);
|
||||
|
||||
cp= (char *)&R.wrld.fastcol;
|
||||
|
||||
cp[0]= 255.0*R.wrld.horr;
|
||||
cp[1]= 255.0*R.wrld.horg;
|
||||
cp[2]= 255.0*R.wrld.horb;
|
||||
cp[3]= 1;
|
||||
|
||||
VECCOPY(R.grvec, R.viewmat[2]);
|
||||
Normalise(R.grvec);
|
||||
Mat3CpyMat4(R.imat, R.viewinv);
|
||||
|
||||
for(a=0; a<MAX_MTEX; a++)
|
||||
if(R.wrld.mtex[a] && R.wrld.mtex[a]->tex) R.wrld.skytype |= WO_SKYTEX;
|
||||
|
||||
while(R.wrld.aosamp*R.wrld.aosamp < R.osa) R.wrld.aosamp++;
|
||||
}
|
||||
else {
|
||||
memset(&R.wrld, 0, sizeof(World));
|
||||
R.wrld.exp= 0.0;
|
||||
R.wrld.range= 1.0;
|
||||
}
|
||||
|
||||
R.wrld.linfac= 1.0 + pow((2.0*R.wrld.exp + 0.5), -10);
|
||||
R.wrld.logfac= log( (R.wrld.linfac-1.0)/R.wrld.linfac )/R.wrld.range;
|
||||
}
|
||||
|
||||
/* This function carefully copies over the struct members
|
||||
from the struct Lamp to a new struct LampRen.
|
||||
It only copies the struct members that are needed
|
||||
in the lamp_preview_pixel function.
|
||||
Replacement for the RE_add_render_lamp function in
|
||||
the preview, because this only works for the
|
||||
current selected lamp.
|
||||
*/
|
||||
static LampRen* create_preview_render_lamp(Lamp* la)
|
||||
{
|
||||
LampRen *lar;
|
||||
int c;
|
||||
|
||||
lar= (LampRen *)MEM_callocN(sizeof(LampRen),"lampren");
|
||||
|
||||
MTC_Mat3One(lar->mat);
|
||||
MTC_Mat3One(lar->imat);
|
||||
|
||||
lar->type= la->type;
|
||||
lar->mode= la->mode;
|
||||
lar->energy= la->energy;
|
||||
if(la->mode & LA_NEG) lar->energy= -lar->energy;
|
||||
lar->r= lar->energy*la->r;
|
||||
lar->g= lar->energy*la->g;
|
||||
lar->b= lar->energy*la->b;
|
||||
lar->k= la->k;
|
||||
lar->dist= la->dist;
|
||||
lar->ld1= la->att1;
|
||||
lar->ld2= la->att2;
|
||||
|
||||
/* exceptions: */
|
||||
lar->spottexfac= 1.0;
|
||||
lar->spotsi= cos( M_PI/3.0 );
|
||||
lar->spotbl= (1.0-lar->spotsi)*la->spotblend;
|
||||
|
||||
MTC_Mat3One(lar->imat);
|
||||
|
||||
if(lar->type==LA_SPOT) {
|
||||
if(lar->mode & LA_ONLYSHADOW) {
|
||||
if((lar->mode & (LA_SHAD|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW;
|
||||
}
|
||||
}
|
||||
memcpy(lar->mtex, la->mtex, MAX_MTEX*sizeof(void *));
|
||||
|
||||
for(c=0; c<MAX_MTEX; c++) {
|
||||
if(la->mtex[c] && la->mtex[c]->tex) {
|
||||
lar->mode |= LA_TEXTURE;
|
||||
|
||||
if(R.flag & R_RENDERING) {
|
||||
if(R.osa) {
|
||||
if(la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lar;
|
||||
}
|
||||
|
||||
static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char *rect, short pr_rectx, short pr_recty)
|
||||
{
|
||||
float inpr, i, t, dist, distkw, vec[3], lacol[3];
|
||||
int col;
|
||||
|
||||
shi->co[0]= (float)x/(PR_RECTX/4);
|
||||
shi->co[1]= (float)y/(PR_RECTX/4);
|
||||
shi->co[0]= (float)x/(pr_rectx/4);
|
||||
shi->co[1]= (float)y/(pr_rectx/4);
|
||||
shi->co[2]= 0;
|
||||
|
||||
vec[0]= 0.02f*x;
|
||||
vec[1]= 0.02f*y;
|
||||
vec[2]= 0.005f*PR_RECTX;
|
||||
vec[2]= 0.005f*pr_rectx;
|
||||
VECCOPY(shi->view, vec);
|
||||
dist= Normalise(shi->view);
|
||||
|
||||
@@ -492,24 +608,26 @@ static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char
|
||||
|
||||
col= 255.0*dist*lacol[2];
|
||||
if(col<=0) rect[2]= 0; else if(col>=255) rect[2]= 255; else rect[2]= col;
|
||||
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
|
||||
static void init_previewhalo(HaloRen *har, Material *mat)
|
||||
static void init_previewhalo(HaloRen *har, Material *mat, short pr_rectx, short pr_recty)
|
||||
{
|
||||
|
||||
har->type= 0;
|
||||
if(mat->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
|
||||
har->mat= mat;
|
||||
har->hard= mat->har;
|
||||
har->rad= PR_RECTX/2.0;
|
||||
har->radsq= PR_RECTX*PR_RECTX/4.0;
|
||||
har->rad= pr_rectx/2.0;
|
||||
har->radsq= pr_rectx*pr_rectx/4.0;
|
||||
har->alfa= mat->alpha;
|
||||
har->add= 255.0*mat->add;
|
||||
har->r= mat->r;
|
||||
har->g= mat->g;
|
||||
har->b= mat->b;
|
||||
har->xs= PR_RECTX/2.0;
|
||||
har->ys= PR_RECTX/2.0;
|
||||
har->xs= pr_rectx/2.0;
|
||||
har->ys= pr_rectx/2.0;
|
||||
har->zs= har->zd= 0;
|
||||
har->seed= (mat->seed1 % 256);
|
||||
|
||||
@@ -521,8 +639,8 @@ static void init_previewhalo(HaloRen *har, Material *mat)
|
||||
if(mat->mode & MA_HALO_FLARE) har->flarec= mat->flarec; else har->flarec= 0;
|
||||
|
||||
if(har->flarec) {
|
||||
har->xs-= PR_RECTX/3;
|
||||
har->ys+= PR_RECTX/3;
|
||||
har->xs-= pr_rectx/3;
|
||||
har->ys+= pr_rectx/3;
|
||||
|
||||
har->rad*= 0.3;
|
||||
har->radsq= har->rad*har->rad;
|
||||
@@ -531,19 +649,19 @@ static void init_previewhalo(HaloRen *har, Material *mat)
|
||||
}
|
||||
}
|
||||
|
||||
static void halo_preview_pixel(HaloRen *har, int startx, int endx, int y, char *rect)
|
||||
static void halo_preview_pixel(HaloRen *har, int startx, int endx, int y, char *rect, short pr_rectx)
|
||||
{
|
||||
float dist, xn, yn, xsq, ysq, colf[4];
|
||||
int x;
|
||||
char front[4];
|
||||
|
||||
if(har->flarec) yn= y-PR_RECTX/3;
|
||||
if(har->flarec) yn= y-pr_rectx/3;
|
||||
else yn= y;
|
||||
ysq= yn*yn;
|
||||
|
||||
for(x=startx; x<endx; x++) {
|
||||
|
||||
if(har->flarec) xn= x+PR_RECTX/3;
|
||||
if(har->flarec) xn= x+pr_rectx/3;
|
||||
else xn= x;
|
||||
|
||||
xsq= xn*xn;
|
||||
@@ -552,20 +670,19 @@ static void halo_preview_pixel(HaloRen *har, int startx, int endx, int y, char *
|
||||
if(dist<har->radsq) {
|
||||
RE_shadehalo(har, front, colf, 0, dist, xn, yn, har->flarec);
|
||||
RE_addalphaAddfac(rect, front, har->add);
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
rect+= 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect)
|
||||
static void previewflare(RenderInfo *ri, HaloRen *har, short pr_rectx, short pr_recty, int doDraw)
|
||||
{
|
||||
uiBlock *block;
|
||||
float ycor;
|
||||
unsigned int *rectot;
|
||||
int afmx, afmy, rectx, recty, y;
|
||||
|
||||
block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Preview");
|
||||
if(block==NULL) return;
|
||||
/* check for "Preview" block already in calling function BIF_previewrender! - elubie */
|
||||
|
||||
/* temps */
|
||||
ycor= R.ycor;
|
||||
@@ -578,11 +695,11 @@ static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect)
|
||||
R.r.postmul= R.r.postgamma= R.r.postsat= 1.0f;
|
||||
R.r.posthue= R.r.postadd= 0.0f;
|
||||
R.ycor= 1.0f;
|
||||
R.rectx= PR_RECTX;
|
||||
R.recty= PR_RECTY;
|
||||
R.afmx= PR_RECTX/2;
|
||||
R.afmy= PR_RECTY/2;
|
||||
R.rectot= rect;
|
||||
R.rectx= pr_rectx;
|
||||
R.recty= pr_recty;
|
||||
R.afmx= pr_rectx/2;
|
||||
R.afmy= pr_recty/2;
|
||||
R.rectot= ri->rect;
|
||||
|
||||
waitcursor(1);
|
||||
RE_renderflare(har);
|
||||
@@ -591,8 +708,10 @@ static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect)
|
||||
//areawinset(curarea->win);
|
||||
|
||||
/* draw can just be this way, all settings are OK */
|
||||
for (y=0; y<PR_RECTY; y++) {
|
||||
display_pr_scanline(sbuts->rect, y);
|
||||
if (doDraw) {
|
||||
for (y=0; y<pr_recty; y++) {
|
||||
display_pr_scanline(ri->rect, y, pr_rectx);
|
||||
}
|
||||
}
|
||||
|
||||
/* temps */
|
||||
@@ -604,14 +723,14 @@ static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect)
|
||||
R.rectot= rectot;
|
||||
}
|
||||
|
||||
static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
|
||||
static void texture_preview_pixel(Tex *tex, int x, int y, char *rect, short pr_rectx, short pr_recty)
|
||||
{
|
||||
float i, v1, xsq, ysq, texvec[3];
|
||||
float tin=1.0f, tr, tg, tb, ta;
|
||||
int rgbnor, tracol, skip=0;
|
||||
|
||||
if(tex->type==TEX_IMAGE) {
|
||||
v1= 1.0f/PR_RECTX;
|
||||
v1= 1.0f/pr_rectx;
|
||||
|
||||
texvec[0]= 0.5+v1*x;
|
||||
texvec[1]= 0.5+v1*y;
|
||||
@@ -636,8 +755,8 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
|
||||
if(tex->env) {
|
||||
ysq= y*y;
|
||||
xsq= x*x;
|
||||
if(xsq+ysq < (PR_RECTX/2)*(PR_RECTY/2)) {
|
||||
texvec[2]= sqrt( (float)((PR_RECTX/2)*(PR_RECTY/2)-xsq-ysq) );
|
||||
if(xsq+ysq < (pr_rectx/2)*(pr_recty/2)) {
|
||||
texvec[2]= sqrt( (float)((pr_rectx/2)*(pr_recty/2)-xsq-ysq) );
|
||||
texvec[0]= -x;
|
||||
texvec[1]= -y;
|
||||
Normalise(texvec);
|
||||
@@ -659,7 +778,7 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
|
||||
}
|
||||
}
|
||||
else {
|
||||
v1= 2.0/PR_RECTX;
|
||||
v1= 2.0/pr_rectx;
|
||||
|
||||
texvec[0]= v1*x;
|
||||
texvec[1]= v1*y;
|
||||
@@ -687,11 +806,14 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
|
||||
rect[2]= tracol+ (rect[2]*ta) ;
|
||||
|
||||
}
|
||||
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
else {
|
||||
rect[0]= 255.0*tin;
|
||||
rect[1]= 255.0*tin;
|
||||
rect[2]= 255.0*tin;
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,7 +1025,7 @@ static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr, int pr_la
|
||||
}
|
||||
}
|
||||
|
||||
static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char *rect, int smooth)
|
||||
static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char *rect, int smooth, short pr_rectx, short pr_recty)
|
||||
{
|
||||
Material *mat;
|
||||
MaterialLayer *ml;
|
||||
@@ -914,7 +1036,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
|
||||
|
||||
mat= shi->mat;
|
||||
|
||||
v1= 1.0/PR_RECTX;
|
||||
v1= 1.0/pr_rectx;
|
||||
shi->view[0]= v1*x;
|
||||
shi->view[1]= v1*y;
|
||||
shi->view[2]= 1.0f;
|
||||
@@ -1065,6 +1187,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
|
||||
rect[2]= tracol+ (rect[2]*shr.alpha) ;
|
||||
}
|
||||
}
|
||||
rect[3] = 0xFF;
|
||||
}
|
||||
|
||||
static void preview_init_render_textures(MTex **mtex)
|
||||
@@ -1087,25 +1210,15 @@ static void preview_init_render_textures(MTex **mtex)
|
||||
|
||||
}
|
||||
|
||||
void BIF_previewrender(SpaceButs *sbuts)
|
||||
void BIF_previewrender_buts(SpaceButs *sbuts)
|
||||
{
|
||||
static double lasttime= 0;
|
||||
ID *id, *idfrom;
|
||||
Material *mat= NULL;
|
||||
Tex *tex= NULL;
|
||||
Lamp *la= NULL;
|
||||
World *wrld= NULL;
|
||||
LampRen *lar= NULL;
|
||||
Image *ima;
|
||||
HaloRen har;
|
||||
Object *ob;
|
||||
uiBlock *block;
|
||||
ShadeInput shi;
|
||||
float lens = 0.0, vec[3];
|
||||
int x, y, starty, startx, endy, endx, radsq, xsq, ysq, last = 0;
|
||||
unsigned int *rect;
|
||||
struct ID* id = 0;
|
||||
struct ID* idfrom = 0;
|
||||
struct ID* idshow = 0;
|
||||
Object *ob;
|
||||
|
||||
if(sbuts->cury>=PR_RECTY) return;
|
||||
if (!sbuts->ri) return;
|
||||
|
||||
/* we safely assume curarea has panel "preview" */
|
||||
/* quick hack for now, later on preview should become uiBlock itself */
|
||||
@@ -1123,32 +1236,77 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
int tab= sbuts->tab[CONTEXT_SHADING];
|
||||
|
||||
if(tab==TAB_SHADING_MAT)
|
||||
mat= sbuts->lockpoin;
|
||||
idshow = sbuts->lockpoin;
|
||||
else if(tab==TAB_SHADING_TEX)
|
||||
tex= sbuts->lockpoin;
|
||||
idshow = sbuts->lockpoin;
|
||||
else if(tab==TAB_SHADING_LAMP) {
|
||||
if(ob && ob->type==OB_LAMP) la= ob->data;
|
||||
if(ob && ob->type==OB_LAMP) idshow= ob->data;
|
||||
}
|
||||
else if(tab==TAB_SHADING_WORLD)
|
||||
wrld= sbuts->lockpoin;
|
||||
idshow = sbuts->lockpoin;
|
||||
}
|
||||
else if(sbuts->mainb==CONTEXT_OBJECT) {
|
||||
if(ob && ob->type==OB_LAMP) la= ob->data;
|
||||
if(ob && ob->type==OB_LAMP) idshow = ob->data;
|
||||
}
|
||||
|
||||
/* return: when no active block to render. but we do draw black if possible */
|
||||
if(mat==NULL && tex==NULL && la==NULL && wrld==NULL) {
|
||||
if(sbuts->rect) {
|
||||
memset(sbuts->rect, 0, sizeof(int)*PR_RECTX*PR_RECTY);
|
||||
sbuts->cury= PR_RECTY;
|
||||
if (idshow) {
|
||||
BKE_icon_changed(BKE_icon_getid(idshow));
|
||||
uiPanelPush(block);
|
||||
BIF_set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty); // uses UImat
|
||||
BIF_previewrender(idshow, sbuts->ri, sbuts->area, 1);
|
||||
uiPanelPop(block);
|
||||
BIF_end_previewrect();
|
||||
}
|
||||
else {
|
||||
/* no active block to draw. But we do draw black if possible */
|
||||
if(sbuts->ri->rect) {
|
||||
memset(sbuts->ri->rect, 0, sizeof(int)*sbuts->ri->pr_rectx*sbuts->ri->pr_recty);
|
||||
sbuts->ri->cury= sbuts->ri->pr_recty;
|
||||
addqueue(curarea->win, REDRAW, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *area, int doDraw)
|
||||
{
|
||||
static double lasttime= 0;
|
||||
Material *mat= NULL;
|
||||
Tex *tex= NULL;
|
||||
Lamp *la= NULL;
|
||||
World *wrld= NULL;
|
||||
LampRen *lar= NULL;
|
||||
Image *ima;
|
||||
HaloRen har;
|
||||
Object *ob;
|
||||
ShadeInput shi;
|
||||
float lens = 0.0, vec[3];
|
||||
int x, y, starty, startx, endy, endx, radsq, xsq, ysq, last = 0;
|
||||
unsigned int *rect;
|
||||
Link* li;
|
||||
|
||||
if(ri->cury>=ri->pr_rectx) return;
|
||||
|
||||
ob= ((G.scene->basact)? (G.scene->basact)->object: 0);
|
||||
|
||||
switch(GS(id->name))
|
||||
{
|
||||
case ID_MA:
|
||||
mat = (Material*)id; break;
|
||||
case ID_TE:
|
||||
tex = (Tex*)id; break;
|
||||
case ID_LA:
|
||||
la = (Lamp*)id; break;
|
||||
case ID_WO:
|
||||
wrld = (World*)id; break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
har.flarec= 0; /* below is a test for postrender flare */
|
||||
|
||||
if(qtest()) {
|
||||
|
||||
if(doDraw && qtest()) {
|
||||
addafterqueue(curarea->win, RENDERPREVIEW, 1);
|
||||
return;
|
||||
}
|
||||
@@ -1178,7 +1336,7 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
shi.vlr= NULL;
|
||||
shi.mat= mat;
|
||||
|
||||
if(mat->mode & MA_HALO) init_previewhalo(&har, mat);
|
||||
if(mat->mode & MA_HALO) init_previewhalo(&har, mat, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
else if(tex) {
|
||||
|
||||
@@ -1198,8 +1356,12 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
init_render_world();
|
||||
preview_init_render_textures(la->mtex);
|
||||
|
||||
RE_add_render_lamp(ob, 0); /* 0=no shadbuf or tables */
|
||||
lar= ((GroupObject *)R.lights.first)->lampren;
|
||||
/* lar= ((GroupObject *)R.lights.first)->lampren;
|
||||
RE_add_render_lamp(ob, 0); */ /* 0=no shadbuf or tables */
|
||||
|
||||
/* elubie: not nice, but ob contains current object, not usable if you
|
||||
need to render lamp that's not active object :( */
|
||||
lar = create_preview_render_lamp(la);
|
||||
|
||||
/* exceptions: */
|
||||
lar->spottexfac= 1.0f;
|
||||
@@ -1219,34 +1381,43 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
MTC_Mat4Ortho(R.viewinv);
|
||||
MTC_Mat4Invert(R.viewmat, R.viewinv);
|
||||
}
|
||||
init_render_world();
|
||||
init_preview_world(wrld);
|
||||
preview_init_render_textures(wrld->mtex);
|
||||
}
|
||||
|
||||
uiPanelPush(block); // sets UImat
|
||||
|
||||
set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX); // uses UImat
|
||||
if (doDraw) {
|
||||
/* BIF_set_previewrect(area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, ri->pr_rectx, ri->pr_recty); // uses UImat */
|
||||
}
|
||||
|
||||
if(sbuts->rect==NULL) {
|
||||
sbuts->rect= MEM_callocN(sizeof(int)*PR_RECTX*PR_RECTY, "butsrect");
|
||||
if(ri->rect==NULL) {
|
||||
ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
|
||||
|
||||
/* built in emboss */
|
||||
rect= sbuts->rect;
|
||||
for(y=0; y<PR_RECTY; y++, rect++) *rect= 0xFFFFFFFF;
|
||||
|
||||
rect= sbuts->rect + PR_RECTX-1;
|
||||
for(y=0; y<PR_RECTY; y++, rect+=PR_RECTX) *rect= 0xFFFFFFFF;
|
||||
if (doDraw) {
|
||||
rect= ri->rect;
|
||||
for(y=0; y<ri->pr_recty; y++, rect++) *rect= 0xFFFFFFFF;
|
||||
|
||||
rect= ri->rect + ri->pr_rectx-1;
|
||||
for(y=0; y<ri->pr_recty; y++, rect+=ri->pr_rectx) *rect= 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
starty= -PR_RECTY/2;
|
||||
endy= starty+PR_RECTY;
|
||||
starty+= sbuts->cury;
|
||||
starty= -ri->pr_recty/2;
|
||||
endy= starty+ri->pr_recty;
|
||||
starty+= ri->cury;
|
||||
|
||||
if (doDraw) {
|
||||
/* offset +1 for emboss */
|
||||
startx= -PR_RECTX/2 +1;
|
||||
endx= startx+PR_RECTX -2;
|
||||
startx= -ri->pr_rectx/2 +1;
|
||||
endx= startx+ri->pr_rectx -2;
|
||||
}
|
||||
else {
|
||||
/* offset +1 for emboss */
|
||||
startx= -ri->pr_rectx/2;
|
||||
endx= startx+ri->pr_rectx-1;
|
||||
}
|
||||
|
||||
radsq= (PR_RECTX/2)*(PR_RECTY/2);
|
||||
radsq= (ri->pr_rectx/2-1)*(ri->pr_recty/2-1); /* -1 to make sure sphere fits into preview rect completely */
|
||||
|
||||
if(mat) {
|
||||
if(mat->pr_type==MA_SPHERE) {
|
||||
@@ -1260,25 +1431,26 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
}
|
||||
|
||||
/* here it starts! */
|
||||
glDrawBuffer(GL_FRONT);
|
||||
if (doDraw) glDrawBuffer(GL_FRONT);
|
||||
|
||||
for(y=starty; y<endy; y++) {
|
||||
|
||||
rect= sbuts->rect + 1 + PR_RECTX*sbuts->cury;
|
||||
rect= ri->rect + 1 + ri->pr_rectx*ri->cury;
|
||||
|
||||
if(y== -PR_RECTY/2 || y==endy-1); /* emboss */
|
||||
if(y== -ri->pr_recty/2 || y==endy-1); /* emboss */
|
||||
else if(mat) {
|
||||
|
||||
if(mat->mode & MA_HALO) {
|
||||
for(x=startx; x<endx; x++, rect++) {
|
||||
rect[0]= previewback(mat->pr_back, x, y);
|
||||
rect[0] |= 0xFF000000;
|
||||
}
|
||||
|
||||
if(har.flarec) {
|
||||
if(y==endy-2) previewflare(sbuts, &har, sbuts->rect);
|
||||
if(y==endy-2) previewflare(ri, &har, ri->pr_rectx, ri->pr_recty, doDraw);
|
||||
}
|
||||
else {
|
||||
halo_preview_pixel(&har, startx, endx, y, (char *) (rect-PR_RECTX));
|
||||
halo_preview_pixel(&har, startx, endx, y, (char *) (rect-ri->pr_rectx), ri->pr_rectx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1305,85 +1477,139 @@ void BIF_previewrender(SpaceButs *sbuts)
|
||||
Normalise(shi.tang);
|
||||
}
|
||||
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 1);
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 1, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
else {
|
||||
rect[0]= previewback(mat->pr_back, x, y);
|
||||
}
|
||||
}
|
||||
else if(mat->pr_type==MA_CUBE) {
|
||||
if( ray_previewrender(x, y, vec, shi.vn) ) {
|
||||
if( ray_previewrender(x, y, vec, shi.vn, ri->pr_rectx, ri->pr_recty) ) {
|
||||
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0);
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
else {
|
||||
rect[0]= previewback(mat->pr_back, x, y);
|
||||
}
|
||||
}
|
||||
else {
|
||||
vec[0]= x*(2.0f/PR_RECTX);
|
||||
vec[1]= y*(2.0f/PR_RECTX);
|
||||
vec[0]= x*(2.0f/ri->pr_rectx);
|
||||
vec[1]= y*(2.0f/ri->pr_recty);
|
||||
vec[2]= 0.0;
|
||||
|
||||
shi.vn[0]= shi.vn[1]= 0.0f;
|
||||
shi.vn[2]= 1.0f;
|
||||
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0);
|
||||
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tex) {
|
||||
for(x=startx; x<endx; x++, rect++) {
|
||||
texture_preview_pixel(tex, x, y, (char *)rect);
|
||||
texture_preview_pixel(tex, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
}
|
||||
else if(la) {
|
||||
for(x=startx; x<endx; x++, rect++) {
|
||||
lamp_preview_pixel(&shi, lar, x, y, (char *)rect);
|
||||
lamp_preview_pixel(&shi, lar, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(x=startx; x<endx; x++, rect++) {
|
||||
sky_preview_pixel(lens, x, y, (char *)rect);
|
||||
sky_preview_pixel(lens, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
|
||||
}
|
||||
}
|
||||
|
||||
if(y<endy-2) {
|
||||
if (doDraw) {
|
||||
if(y<endy-2) {
|
||||
if(qtest()) {
|
||||
addafterqueue(curarea->win, RENDERPREVIEW, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
display_pr_scanline(ri->rect, ri->cury, ri->pr_rectx);
|
||||
|
||||
if(qtest()) {
|
||||
addafterqueue(curarea->win, RENDERPREVIEW, 1);
|
||||
break;
|
||||
/* flush opengl for cards with frontbuffer slowness */
|
||||
if(ri->cury==ri->pr_recty-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) {
|
||||
lasttime= PIL_check_seconds_timer();
|
||||
glFlush();
|
||||
}
|
||||
}
|
||||
|
||||
display_pr_scanline(sbuts->rect, sbuts->cury);
|
||||
|
||||
/* flush opengl for cards with frontbuffer slowness */
|
||||
if(sbuts->cury==PR_RECTY-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) {
|
||||
lasttime= PIL_check_seconds_timer();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
sbuts->cury++;
|
||||
ri->cury++;
|
||||
}
|
||||
|
||||
end_previewrect();
|
||||
if (doDraw) {
|
||||
/* BIF_end_previewrect(); */
|
||||
|
||||
if(sbuts->cury>=PR_RECTY && tex)
|
||||
if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX)
|
||||
draw_tex_crop(sbuts->lockpoin);
|
||||
if(ri->cury>=ri->pr_recty && tex)
|
||||
draw_tex_crop((Tex*)id);
|
||||
|
||||
glDrawBuffer(GL_BACK);
|
||||
/* draw again for clean swapbufers */
|
||||
BIF_previewdraw();
|
||||
|
||||
uiPanelPop(block);
|
||||
glDrawBuffer(GL_BACK);
|
||||
/* draw again for clean swapbufers */
|
||||
BIF_previewdraw_render(ri, area);
|
||||
}
|
||||
|
||||
if(lar) {
|
||||
MEM_freeN(lar);
|
||||
/*
|
||||
MEM_freeN(R.lights.first);
|
||||
R.lights.first= R.lights.last= NULL;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* create single icon from jpg, png etc. */
|
||||
void BIF_calcpreview_image(Image* img, RenderInfo* ri, unsigned int w, unsigned int h)
|
||||
{
|
||||
struct ImBuf *ima;
|
||||
struct ImBuf *imb;
|
||||
short ex, ey, dx, dy;
|
||||
float scaledx, scaledy;
|
||||
int pr_size = w*h*sizeof(unsigned int);
|
||||
|
||||
if (!img)
|
||||
return;
|
||||
|
||||
if (!ri->rect) {
|
||||
ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
|
||||
memset(ri->rect, 0xFF, w*h*sizeof(unsigned int));
|
||||
}
|
||||
|
||||
if(img->ibuf==0) {
|
||||
load_image(img, IB_rect, G.sce, G.scene->r.cfra);
|
||||
}
|
||||
ima = IMB_dupImBuf(img->ibuf);
|
||||
|
||||
if (!ima)
|
||||
return;
|
||||
|
||||
if (ima->x > ima->y) {
|
||||
scaledx = (float)w;
|
||||
scaledy = ( (float)ima->y/(float)ima->x )*(float)w;
|
||||
}
|
||||
else {
|
||||
scaledx = ( (float)ima->x/(float)ima->y )*(float)h;
|
||||
scaledy = (float)h;
|
||||
}
|
||||
|
||||
ex = (short)scaledx;
|
||||
ey = (short)scaledy;
|
||||
|
||||
dx = (w - ex) / 2;
|
||||
dy = (h - ey) / 2;
|
||||
|
||||
IMB_scaleImBuf(ima, ex, ey);
|
||||
|
||||
imb = IMB_allocImBuf(w, h, 32, IB_rect, 0);
|
||||
|
||||
IMB_rectop(imb, 0, 0, 0, 0, 0, w, h, IMB_rectfill, 0x00000000);
|
||||
|
||||
IMB_rectop(imb, ima, dx, dy, 0, 0, ex, ey, IMB_rectcpy, 0);
|
||||
|
||||
IMB_freeImBuf(ima);
|
||||
|
||||
memcpy(ri->rect, imb->rect,pr_size);
|
||||
|
||||
IMB_freeImBuf(imb);
|
||||
}
|
||||
|
@@ -52,6 +52,7 @@
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_resources.h"
|
||||
#include "BIF_interface_icons.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "blendef.h" // CLAMP
|
||||
@@ -63,578 +64,15 @@ typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
|
||||
static bTheme *theme_active=NULL;
|
||||
static int theme_spacetype= SPACE_VIEW3D;
|
||||
|
||||
typedef struct {
|
||||
/* If drawFunc is defined then it is a vector icon, otherwise use data */
|
||||
VectorDrawFunc drawFunc;
|
||||
|
||||
int w, h;
|
||||
|
||||
/* Data for image icons */
|
||||
unsigned char *data;
|
||||
float uv[4][2];
|
||||
GLuint texid;
|
||||
} Icon;
|
||||
|
||||
static Icon *icon_new_vector(VectorDrawFunc drawFunc, int w, int h)
|
||||
{
|
||||
Icon *icon= MEM_callocN(sizeof(*icon), "internicon");
|
||||
icon->drawFunc = drawFunc;
|
||||
icon->w = w;
|
||||
icon->h = h;
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
static Icon *icon_from_data(unsigned char *rect, GLuint texid, int xofs, int yofs, int w, int h, int rowstride)
|
||||
{
|
||||
Icon *icon= MEM_mallocN(sizeof(*icon), "internicon");
|
||||
int y;
|
||||
|
||||
icon->drawFunc = NULL;
|
||||
icon->texid= texid;
|
||||
icon->uv[0][0]= ((float)xofs)/512.0;
|
||||
icon->uv[0][1]= ((float)yofs)/256.0;
|
||||
icon->uv[1][0]= icon->uv[0][0] + ((float)w)/512.0;
|
||||
icon->uv[1][1]= icon->uv[0][1];
|
||||
icon->uv[2][0]= icon->uv[0][0] + ((float)w)/512.0;
|
||||
icon->uv[2][1]= icon->uv[0][1] + ((float)w)/256.0;
|
||||
icon->uv[3][0]= icon->uv[0][0];
|
||||
icon->uv[3][1]= icon->uv[0][1] + ((float)w)/256.0;
|
||||
|
||||
icon->w= w;
|
||||
icon->h= h;
|
||||
|
||||
icon->data= MEM_mallocN(w*h*4, "icon->data");
|
||||
for (y=0; y<h; y++)
|
||||
memcpy(&icon->data[y*w*4], &rect[y*rowstride], w*4);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static float icon_x=0.0, icon_y=0.0;
|
||||
void BIF_icon_pos(float xs, float ys)
|
||||
{
|
||||
icon_x= xs; icon_y= ys;
|
||||
}
|
||||
|
||||
static GLuint init_icon_texture(ImBuf *bbuf)
|
||||
{
|
||||
GLuint texid;
|
||||
|
||||
glGenTextures(1, &texid);
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
return texid;
|
||||
}
|
||||
|
||||
/* texture version for drawpixels */
|
||||
static void icon_draw_tex(Icon *icon)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, icon->texid);
|
||||
|
||||
/* drawing it */
|
||||
glColor3ub(255, 255, 255);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2fv(icon->uv[0]);
|
||||
glVertex2f(icon_x, icon_y);
|
||||
glTexCoord2fv(icon->uv[1]);
|
||||
glVertex2f(icon_x+icon->w, icon_y);
|
||||
glTexCoord2fv(icon->uv[2]);
|
||||
glVertex2f(icon_x+icon->w, icon_y+icon->h);
|
||||
glTexCoord2fv(icon->uv[3]);
|
||||
glVertex2f(icon_x, icon_y+icon->h);
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void icon_draw(float x, float y, Icon *icon)
|
||||
{
|
||||
if (icon->drawFunc) {
|
||||
icon->drawFunc(x, y, icon->w, icon->h, 1.0);
|
||||
} else {
|
||||
glRasterPos2f(x, y);
|
||||
glDrawPixels(icon->w, icon->h, GL_RGBA, GL_UNSIGNED_BYTE, icon->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void icon_draw_blended(float x, float y, Icon *icon, char *blendcol, int shade)
|
||||
{
|
||||
if (icon->drawFunc) {
|
||||
icon->drawFunc(x, y, icon->w, icon->h, shade<0?((128+shade)/128.0):1.0);
|
||||
} else {
|
||||
if(shade < 0) {
|
||||
float r= (128+shade)/128.0;
|
||||
glPixelTransferf(GL_ALPHA_SCALE, r);
|
||||
}
|
||||
glRasterPos2f(x, y);
|
||||
glDrawPixels(icon->w, icon->h, GL_RGBA, GL_UNSIGNED_BYTE, icon->data);
|
||||
glPixelTransferf(GL_ALPHA_SCALE, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void icon_free(Icon *icon)
|
||||
{
|
||||
if (icon->data) MEM_freeN(icon->data);
|
||||
MEM_freeN(icon);
|
||||
}
|
||||
|
||||
|
||||
static Icon **common_icons_arr= NULL;
|
||||
|
||||
static Icon *get_icon(BIFIconID icon)
|
||||
{
|
||||
int iconidx= icon-BIFICONID_FIRST;
|
||||
if (iconidx>=0 && iconidx<BIFNICONIDS) {
|
||||
return common_icons_arr[iconidx];
|
||||
} else {
|
||||
return common_icons_arr[ICON_ERROR-BIFICONID_FIRST];
|
||||
}
|
||||
}
|
||||
static void free_common_icons(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<BIFNICONIDS; i++) {
|
||||
icon_free(common_icons_arr[i+BIFICONID_FIRST]);
|
||||
}
|
||||
}
|
||||
|
||||
void BIF_draw_icon(float x, float y, BIFIconID icon)
|
||||
{
|
||||
icon_draw(x, y, get_icon(icon));
|
||||
}
|
||||
|
||||
void BIF_draw_icon_blended(float x, float y, BIFIconID icon, int colorid, int shade)
|
||||
{
|
||||
char *cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
|
||||
icon_draw_blended(x, y, get_icon(icon), cp, shade);
|
||||
// icon_draw_tex(get_icon(icon));
|
||||
}
|
||||
|
||||
int BIF_get_icon_width(BIFIconID icon)
|
||||
{
|
||||
return get_icon(icon)->w;
|
||||
}
|
||||
|
||||
int BIF_get_icon_height(BIFIconID icon)
|
||||
{
|
||||
return get_icon(icon)->h;
|
||||
}
|
||||
|
||||
static void def_icon(ImBuf *bbuf, GLuint texid, BIFIconID icon, int xidx, int yidx, int w, int h, int offsx, int offsy)
|
||||
{
|
||||
int iconidx= icon-BIFICONID_FIRST;
|
||||
|
||||
if (iconidx>=0 && iconidx<BIFNICONIDS) {
|
||||
int rowstride= bbuf->x*4;
|
||||
unsigned char *start= ((unsigned char*) bbuf->rect) + (yidx*21 + 3 + offsy)*rowstride + (xidx*20 + 3 + offsx)*4;
|
||||
|
||||
common_icons_arr[iconidx]=
|
||||
icon_from_data(start, texid, (xidx*20 + 3 + offsx), (yidx*21 + 3 + offsy), w, h, rowstride);
|
||||
|
||||
} else {
|
||||
printf("def_icon: Internal error, bad icon ID: %d\n", icon);
|
||||
}
|
||||
}
|
||||
|
||||
static void def_vicon(BIFIconID icon, int w, int h, VectorDrawFunc drawFunc)
|
||||
{
|
||||
int iconidx= icon-BIFICONID_FIRST;
|
||||
|
||||
if (iconidx>=0 && iconidx<BIFNICONIDS) {
|
||||
common_icons_arr[iconidx]= icon_new_vector(drawFunc, w, h);
|
||||
} else {
|
||||
printf("def_icon: Internal error, bad icon ID: %d\n", icon);
|
||||
}
|
||||
}
|
||||
|
||||
/* this only works for the hardcoded buttons image, turning the grey AA pixels to alpha, and slight off-grey to half alpha */
|
||||
|
||||
static void clear_transp_rect_soft(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
|
||||
{
|
||||
int x, y, val;
|
||||
|
||||
for (y=1; y<h-1; y++) {
|
||||
unsigned char *row0= &rect[(y-1)*rowstride];
|
||||
unsigned char *row= &rect[y*rowstride];
|
||||
unsigned char *row1= &rect[(y+1)*rowstride];
|
||||
for (x=1; x<w-1; x++) {
|
||||
unsigned char *pxl0= &row0[x*4];
|
||||
unsigned char *pxl= &row[x*4];
|
||||
unsigned char *pxl1= &row1[x*4];
|
||||
|
||||
if(pxl[3]!=0) {
|
||||
val= (abs(pxl[0]-transp[0]) + abs(pxl[1]-transp[1]) + abs(pxl[2]-transp[2]))/3;
|
||||
if(val<20) {
|
||||
pxl[3]= 128;
|
||||
}
|
||||
else if(val<50) {
|
||||
// one of pixels surrounding has alpha null?
|
||||
if(pxl[3-4]==0 || pxl[3+4]==0 || pxl0[3]==0 || pxl1[3]==0) {
|
||||
|
||||
if(pxl[0]>val) pxl[0]-= val; else pxl[0]= 0;
|
||||
if(pxl[1]>val) pxl[1]-= val; else pxl[1]= 0;
|
||||
if(pxl[2]>val) pxl[2]-= val; else pxl[2]= 0;
|
||||
|
||||
pxl[3]= 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void clear_transp_rect(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
|
||||
{
|
||||
int x,y;
|
||||
for (y=0; y<h; y++) {
|
||||
unsigned char *row= &rect[y*rowstride];
|
||||
for (x=0; x<w; x++) {
|
||||
unsigned char *pxl= &row[x*4];
|
||||
if (*((unsigned int*) pxl)==*((unsigned int*) transp)) {
|
||||
pxl[3]= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Vector Icon Drawing Routines */
|
||||
|
||||
/* Utilities */
|
||||
|
||||
static void viconutil_set_point(GLint pt[2], int x, int y)
|
||||
{
|
||||
pt[0] = x;
|
||||
pt[1] = y;
|
||||
}
|
||||
|
||||
static void viconutil_draw_tri(GLint (*pts)[2])
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void viconutil_draw_quad(GLint (*pts)[2])
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glVertex2iv(pts[2]);
|
||||
glVertex2iv(pts[3]);
|
||||
glEnd();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
|
||||
{
|
||||
int i;
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (i=0; i<numPoints; i++) {
|
||||
glVertex2iv(pts[i]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
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);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/* Drawing functions */
|
||||
|
||||
static void vicon_x_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
x += 3;
|
||||
y += 3;
|
||||
w -= 6;
|
||||
h -= 6;
|
||||
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
|
||||
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);
|
||||
|
||||
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(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);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, alpha);
|
||||
viconutil_draw_lineloop(pts, 4);
|
||||
|
||||
glColor3f(1, 1, 0.0);
|
||||
viconutil_draw_points(pts, 4, 1);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
glColor4f(0.5, 0.5, 0.5, alpha);
|
||||
viconutil_draw_tri(pts);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
|
||||
glColor3f(1, 1, 0.0);
|
||||
viconutil_draw_points(pts, 3, 1);
|
||||
}
|
||||
|
||||
static void vicon_editmode_dehlt_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);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
|
||||
glColor3f(.9, .9, .9);
|
||||
viconutil_draw_points(pts, 3, 1);
|
||||
}
|
||||
|
||||
static void vicon_disclosure_tri_right_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
GLint pts[3][2];
|
||||
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);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(0.8, 0.8, 0.8, alpha);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glColor4f(0.3, 0.3, 0.3, alpha);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
}
|
||||
|
||||
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
GLint pts[3][2];
|
||||
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);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(0.8, 0.8, 0.8, alpha);
|
||||
glVertex2iv(pts[0]);
|
||||
glVertex2iv(pts[1]);
|
||||
glColor4f(0.3, 0.3, 0.3, alpha);
|
||||
glVertex2iv(pts[2]);
|
||||
glEnd();
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glColor4f(0.0, 0.0, 0.0, 1);
|
||||
viconutil_draw_lineloop_smooth(pts, 3);
|
||||
}
|
||||
|
||||
static void vicon_move_up_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
static void vicon_move_down_draw(int x, int y, int w, int h, float alpha)
|
||||
{
|
||||
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);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
/***/
|
||||
|
||||
void BIF_resources_init(void)
|
||||
{
|
||||
ImBuf *bbuf= IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
|
||||
GLuint texid=0;
|
||||
int x, y;
|
||||
|
||||
common_icons_arr= MEM_mallocN(sizeof(*common_icons_arr)*BIFNICONIDS, "common_icons");
|
||||
|
||||
/* hack! */
|
||||
for (y=0; y<12; y++) {
|
||||
for (x=0; x<21; x++) {
|
||||
int rowstride= bbuf->x*4;
|
||||
unsigned char *start= ((unsigned char*) bbuf->rect) + (y*21 + 3)*rowstride + (x*20 + 3)*4;
|
||||
unsigned char transp[4];
|
||||
/* this sets backdrop of icon to zero alpha */
|
||||
transp[0]= start[0];
|
||||
transp[1]= start[1];
|
||||
transp[2]= start[2];
|
||||
transp[3]= start[3];
|
||||
clear_transp_rect(transp, start, 20, 21, rowstride);
|
||||
clear_transp_rect_soft(transp, start, 20, 21, rowstride);
|
||||
|
||||
/* this sets outside of icon to zero alpha */
|
||||
start= ((unsigned char*) bbuf->rect) + (y*21)*rowstride + (x*20)*4;
|
||||
QUATCOPY(transp, start);
|
||||
clear_transp_rect(transp, start, 20, 21, rowstride);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// disabled for now (ton)
|
||||
// texid= init_icon_texture(bbuf);
|
||||
|
||||
/* hack! */
|
||||
for (y=0; y<12; y++) {
|
||||
for (x=0; x<21; x++) {
|
||||
if (x==11 && y==6) {
|
||||
def_icon(bbuf, texid, ICON_BEVELBUT_HLT, x, y, 7, 13, 4, 2);
|
||||
} else if (x==12 && y==6) {
|
||||
def_icon(bbuf, texid, ICON_BEVELBUT_DEHLT, x, y, 7, 13, 4, 2);
|
||||
} else {
|
||||
def_icon(bbuf, texid, BIFICONID_FIRST + y*21 + x, x, y, 15, 16, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def_vicon(VICON_VIEW3D, 16, 16, vicon_view3d_draw);
|
||||
def_vicon(VICON_EDIT, 16, 16, vicon_edit_draw);
|
||||
def_vicon(VICON_EDITMODE_DEHLT, 16, 16, vicon_editmode_dehlt_draw);
|
||||
def_vicon(VICON_EDITMODE_HLT, 16, 16, vicon_editmode_hlt_draw);
|
||||
def_vicon(VICON_DISCLOSURE_TRI_RIGHT, 16, 16, vicon_disclosure_tri_right_draw);
|
||||
def_vicon(VICON_DISCLOSURE_TRI_DOWN, 16, 16, vicon_disclosure_tri_down_draw);
|
||||
def_vicon(VICON_MOVE_UP, 16, 16, vicon_move_up_draw);
|
||||
def_vicon(VICON_MOVE_DOWN, 16, 16, vicon_move_down_draw);
|
||||
def_vicon(VICON_X, 16, 16, vicon_x_draw);
|
||||
|
||||
IMB_freeImBuf(bbuf);
|
||||
BIF_icons_init(BIFICONID_LAST+1);
|
||||
}
|
||||
|
||||
void BIF_resources_free(void)
|
||||
{
|
||||
free_common_icons();
|
||||
|
||||
MEM_freeN(common_icons_arr);
|
||||
|
||||
BIF_icons_free();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -3215,7 +3215,7 @@ static void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
scrarea_queue_winredraw(curarea);
|
||||
break;
|
||||
case RENDERPREVIEW:
|
||||
BIF_previewrender(sbuts);
|
||||
BIF_previewrender_buts(sbuts);
|
||||
break;
|
||||
|
||||
case HOMEKEY:
|
||||
@@ -3300,6 +3300,8 @@ static void init_butspace(ScrArea *sa)
|
||||
/* set_rects only does defaults, so after reading a file the cur has not changed */
|
||||
set_rects_butspace(buts);
|
||||
buts->v2d.cur= buts->v2d.tot;
|
||||
|
||||
buts->ri = NULL;
|
||||
}
|
||||
|
||||
void extern_set_butspace(int fkey)
|
||||
@@ -4592,7 +4594,10 @@ void freespacelist(ListBase *lb)
|
||||
}
|
||||
else if(sl->spacetype==SPACE_BUTS) {
|
||||
SpaceButs *buts= (SpaceButs*) sl;
|
||||
if(buts->rect) MEM_freeN(buts->rect);
|
||||
if(buts->ri) {
|
||||
if (buts->ri->rect) MEM_freeN(buts->ri->rect);
|
||||
MEM_freeN(buts->ri);
|
||||
}
|
||||
if(G.buts==buts) G.buts= NULL;
|
||||
}
|
||||
else if(sl->spacetype==SPACE_IPO) {
|
||||
@@ -4692,7 +4697,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
|
||||
|
||||
if(sl->spacetype==SPACE_BUTS) {
|
||||
SpaceButs *buts= (SpaceButs *)sl;
|
||||
buts->rect= NULL;
|
||||
buts->ri= NULL;
|
||||
}
|
||||
else if(sl->spacetype==SPACE_IPO) {
|
||||
SpaceIpo *si= (SpaceIpo *)sl;
|
||||
|
Reference in New Issue
Block a user