Another huge commit!!!
authorTon Roosendaal <ton@blender.org>
Fri, 10 Oct 2003 17:29:01 +0000 (17:29 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 10 Oct 2003 17:29:01 +0000 (17:29 +0000)
First, check on the new files, which are listed below.
The new butspace.h is a local include, only to be used for the buttons
drawn in the buttonswindow.

- editbuts, animbuts, gamebuts, displaybuts, paintbuts,  work now
- i quite completely reorganized it, it's now nicely telling you what
  context it is in
- sorting error in panel align fixed (tabs were flipping)
- align works correctly automatic when you click around in Blender
- editsca.c renamed to buttons_logic.h
- button names are truncated from the right for allmost all buttons
  (except text buttons and number buttons)
- while dragging panels, you cannot move them outside window anymore

And of course fixed loads of little bugs I encountered while testing
it all. This is a version I really need good test & feedback for.

Next step: restoring material/lamp/texture/world

29 files changed:
source/blender/blenkernel/BKE_utildefines.h
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/include/BIF_butspace.h
source/blender/include/BIF_editarmature.h
source/blender/include/BIF_interface.h
source/blender/include/butspace.h [new file with mode: 0644]
source/blender/makesdna/DNA_screen_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/src/butspace.c
source/blender/src/buttons.txt
source/blender/src/buttons_editing.c [new file with mode: 0644]
source/blender/src/buttons_logic.c [moved from source/blender/src/editsca.c with 99% similarity]
source/blender/src/buttons_object.c [new file with mode: 0644]
source/blender/src/buttons_scene.c
source/blender/src/buttons_script.c [new file with mode: 0644]
source/blender/src/buttons_shading.c [new file with mode: 0644]
source/blender/src/editarmature.c
source/blender/src/editconstraint.c
source/blender/src/editface.c
source/blender/src/editipo.c
source/blender/src/editscreen.c
source/blender/src/ghostwinlay.c
source/blender/src/header_buttonswin.c
source/blender/src/headerbuttons.c
source/blender/src/interface.c
source/blender/src/previewrender.c
source/blender/src/space.c

index d0f418ec192b5d50ace373365ae69bc45e5f9911..4fae54369c119f31e04ebed940f7764edb8d37db 100644 (file)
@@ -88,9 +88,8 @@
                                                          if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
                                                          if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1];
 
-
 /* interferes elsewhere */
-/* deze getallen ook invullen in blender.h SpaceFile: struct dna herkent geen defines */
+/* also fill in structs itself, dna cannot handle defines */
 #define FILE_MAXDIR                    160
 #define FILE_MAXFILE           80
 
index 84b55ca8fb5750a74a08b3bc66a44c74e4127a22..36f2c10b5188e54f95e54155c7fe577655a7d8dd 100644 (file)
@@ -663,7 +663,7 @@ void shadeDispList(Object *ob)
        Mesh *me;
        Curve *cu;
 /*     extern Material defmaterial;     *//* initrender.c, already in bad lev calls*/
-       float *orco, imat[3][3], tmat[4][4], mat[4][4], vec[3], xn, yn, zn;
+       float *orco=NULL, imat[3][3], tmat[4][4], mat[4][4], vec[3], xn, yn, zn;
        float *fp, *nor, n1[3];
        unsigned int *col1, *col2, *vertcol;
        int a, lastmat= -1, need_orco = 0;
index 13c3b921dee69974364dc9554dc72aeda7dcb47b..859e009cbd4542dd17b928b51d34fa7d74fcf27d 100644 (file)
@@ -1444,7 +1444,7 @@ void solve_constraints (Object *ob, short obtype, void *obdata, float ctime)
        bConstraint *con;
        float tmat[4][4], focusmat[4][4], lastmat[4][4];
        int i, clear=1, tot=0;
-       float   a;
+       float   a=0;
        float   aquat[4], quat[4];
        float   aloc[3], loc[3];
        float   asize[3], size[3];
index ceaee7788b8600f9a0b992be6c97dddcb5a4ea84..5ee56d80052c8c02701c9cd2d2aaa2a630ac94bb 100644 (file)
@@ -47,6 +47,7 @@
 #include <stdio.h> // for printf fopen fwrite fclose sprintf FILE
 #include <stdlib.h> // for getenv atoi
 #include <fcntl.h> // for open
+#include <string.h> // for strcasecmp strrchr strncmp strstr
 
 #ifndef WIN32 
     #include <unistd.h> // for read close
 
 #include "BPY_extern.h" // for BPY_do_pyscript
 
+#include "BIF_butspace.h" // for do_versions, patching event codes
+
 #include "BLO_readfile.h"
 #include "readfile.h"
 
 
 #include "mydevice.h"
 
-#include <string.h> // for strcasecmp strrchr strncmp strstr
 
 
 
index b2c9aec0f8344aded3f6d4041b85f28a541f9b64..9023a88310a10289f23fec140e516d002a828276 100644 (file)
 #ifndef BIF_BUTSPACE_H
 #define BIF_BUTSPACE_H
 
-/* all internal calls and event codes for buttons space */
+/* all internal/external calls and event codes for buttons space */
+/* should be split in 2 parts... */
+
 struct Base;
 struct ID;
 
-extern void render_panels(void);
-extern void do_render_panels(unsigned short event);
-
+/* external, butspace.c */
 extern void do_butspace(unsigned short event);
-
 extern void redraw_test_buttons(struct Base *new);
 
-void test_meshpoin_but(char *name, struct ID **idpp);
-void test_obpoin_but(char *name, struct ID **idpp);
-void test_scenepoin_but(char *name, struct ID **idpp);
-void test_matpoin_but(char *name, struct ID **idpp);
-void test_scriptpoin_but(char *name, struct ID **idpp);
-void test_actionpoin_but(char *name, ID **idpp);
-
-
-/* -------------- event defines ------------ */
-
-
-#define B_DIFF                 1       
-
-/* *********************** */
-#define B_VIEWBUTS             1100
-
-#define B_LOADBGPIC            1001
-#define B_BLENDBGPIC   1002
-#define B_BGPICBROWSE  1003
-#define B_BGPICTEX             1004
-#define B_BGPICCLEAR   1005
-#define B_BGPICTEXCLEAR        1006
-
-/* *********************** */
-#define B_LAMPBUTS             1200
-
-#define B_LAMPREDRAW   1101
-#define B_COLLAMP              1102
-#define B_TEXCLEARLAMP 1103
-#define B_SBUFF                        1104
-
-/* *********************** */
-#define B_MATBUTS              1300
-
-#define B_MATCOL               1201
-#define B_SPECCOL              1202
-#define B_MIRCOL               1203
-#define B_ACTCOL               1204
-#define B_MATFROM              1205
-#define B_MATPRV               1206
-#define B_MTEXCOL              1207
-#define B_TEXCLEAR             1208
-#define B_MATPRV_DRAW  1209
-#define B_MTEXPASTE            1210
-#define B_MTEXCOPY             1211
-#define B_MATLAY               1212
-
-/* *********************** */
-#define B_TEXBUTS              1400
-
-#define B_TEXTYPE              1301
-#define B_DEFTEXVAR            1302
-#define B_LOADTEXIMA   1303
-#define B_NAMEIMA              1304
-#define B_TEXCHANNEL   1305
-#define B_TEXREDR_PRV  1306
-#define B_TEXIMABROWSE 1307
-#define B_IMAPTEST             1308
-#define B_RELOADIMA            1309
-#define B_LOADPLUGIN   1310
-#define B_NAMEPLUGIN   1311
-#define B_COLORBAND            1312
-#define B_ADDCOLORBAND 1313
-#define B_DELCOLORBAND 1314
-#define B_CALCCBAND            1315
-#define B_CALCCBAND2   1316
-#define B_DOCOLORBAND  1317
-#define B_REDRAWCBAND  1318
-#define B_BANDCOL              1319
-#define B_LOADTEXIMA1  1320
-#define B_PLUGBUT              1321
-
-/* plugbut reserves 24 buttons at least! */
-
-#define B_ENV_MAKE             1350
-#define B_ENV_FREE             1351
-#define B_ENV_DELETE   1352
-#define B_ENV_SAVE             1353
-#define B_ENV_OB               1354
-
-#define B_PACKIMA              1355
-#define B_TEXSETFRAMES 1356
-
-#define B_ENV_FREE_ALL 1357
-
-/* *********************** */
-#define B_ANIMBUTS             1500
-
-#define B_RECALCPATH   1401
-#define B_MUL_IPO              1402
-#define B_AUTOTIMEOFS  1403
-#define B_FRAMEMAP             1404
-#define B_NEWEFFECT            1405
-#define B_PREVEFFECT   1406
-#define B_NEXTEFFECT   1407
-#define B_CHANGEEFFECT 1408
-#define B_CALCEFFECT   1409
-#define B_DELEFFECT            1410
-#define B_RECALCAL             1411
-#define B_SETSPEED             1412
-#define B_PRINTSPEED   1413
-#define B_PRINTLEN             1414
-#define B_RELKEY               1415
-
-       /* this has MAX_EFFECT settings! Next free define is 1450... */
-#define B_SELEFFECT    1430    
-
-
-/* *********************** */
-#define B_WORLDBUTS            1600
-
-#define B_TEXCLEARWORLD        1501
-
-/* *********************** */
-#define B_RENDERBUTS   1700
-
-#define B_FS_PIC               1601
-#define B_FS_BACKBUF   1602
-
-#define B_FS_FTYPE             1604
-#define B_DORENDER             1605
-#define B_DOANIM               1606
-#define B_PLAYANIM             1607
-#define B_PR_PAL               1608
-#define B_PR_FULL              1609
-#define B_PR_PRV               1610
-#define B_PR_CDI               1611
-#define B_PR_PAL169            1612
-#define B_PR_D2MAC             1613
-#define B_PR_MPEG              1614
-#define B_REDRAWDISP   1615
-#define B_SETBROWSE            1616
-#define B_CLEARSET             1617
-#define B_PR_PRESET            1618
-#define B_PR_PANO              1619
-#define B_PR_NTSC              1620
-
-#define B_IS_FTYPE             1622
-#define B_IS_BACKBUF   1623
-#define B_PR_PC                        1624
-
-#define B_PR_PANO360    1627
-#define B_PR_HALFFIELDS        1628
-#define B_NEWRENDERPIPE 1629
-#define B_R_SCALE       1630
-#define B_G_SCALE       1631
-#define B_B_SCALE       1632
-#define B_USE_R_SCALE   1633
-#define B_USE_G_SCALE   1634
-#define B_USE_B_SCALE   1635
-#define B_EDGECOLSLI    1636
-#define B_GAMMASLI      1637
-
-#define B_FILETYPEMENU  1638
-#define B_SELECTCODEC   1639
-#define B_RTCHANGED            1640
-
-#ifdef __NLA
-/* *********************** */
-enum {
-       B_ARMATUREBUTS  =       1800,
-       B_POSE                  =       1701
-};
-#endif
-
-/* *********************** */
-#define B_COMMONEDITBUTS       2049
-
-#define B_MATWICH              2003
-#define B_MATNEW               2004
-#define B_MATDEL               2005
-#define B_MATASS               2006
-#define B_MATSEL               2007
-#define B_MATDESEL             2008
-#define B_HIDE                 2009
-#define B_REVEAL               2010
-#define B_SELSWAP              2011
-#define B_SETSMOOTH            2012
-#define B_SETSOLID             2013
-#define B_AUTOTEX              2014
-#define B_DOCENTRE             2015
-#define B_DOCENTRENEW  2016
-#define B_DOCENTRECURSOR       2017
-
-       /* 32 values! */
-#define B_OBLAY                        2018
-
-#define B_MESHBUTS             2100
-
-#define B_FLIPNORM             2050
-#define B_SPIN                 2051
-#define B_SPINDUP              2052
-#define B_EXTR                 2053
-#define B_SCREW                        2054
-#define B_EXTREP               2055
-#define B_SPLIT                        2056
-#define B_REMDOUB              2057
-#define B_SUBDIV               2058
-#define B_FRACSUBDIV   2059
-#define B_XSORT                        2060
-#define B_HASH                 2061
-#define B_DELSTICKY            2062
-#define B_DELVERTCOL   2063
-#define B_MAKE_TFACES  2064
-#define B_TOSPHERE             2065
-#define B_DEL_TFACES   2066
-#define B_NEWVGROUP            2067
-#define B_DELVGROUP            2068
-#define B_ASSIGNVGROUP 2069
-#define B_REMOVEVGROUP 2070
-#define B_SELVGROUP            2071    
-#define B_DESELVGROUP  2072
-#define B_DECIM_FACES  2073
-#define B_DECIM_CANCEL 2074
-#define B_DECIM_APPLY  2075
-#define B_AUTOVGROUP   2076
-#define B_SLOWERDRAW   2077
-#define B_FASTERDRAW   2078
-#define B_VERTEXNOISE  2079
-#define B_VERTEXSMOOTH 2080
-#define B_MAKESTICKY   2082
-#define B_MAKEVERTCOL  2083
-
-/* *********************** */
-#define B_CURVEBUTS            2200
-
-#define B_CONVERTPOLY  2101
-#define B_CONVERTBEZ   2102
-#define B_CONVERTBSPL  2103
-#define B_CONVERTCARD  2104
-#define B_CONVERTNURB  2105
-#define B_UNIFU                        2106
-#define B_ENDPU                        2107
-#define B_BEZU                 2108
-#define B_UNIFV                        2109
-#define B_ENDPV                        2110
-#define B_BEZV                 2111
-#define B_SETWEIGHT            2112
-#define B_SETW1                        2113
-#define B_SETW2                        2114
-#define B_SETW3                        2115
-#define B_SETORDER             2116
-#define B_MAKEDISP             2117
-#define B_SUBDIVCURVE  2118
-#define B_SPINNURB             2119
-#define B_CU3D                 2120
-#define B_SETRESOLU            2121
-#define B_SETW4                        2122
-
-
-/* *********************** */
-#define B_FONTBUTS             2300
-
-#define B_MAKEFONT             2201
-#define B_TOUPPER              2202
-#define B_SETFONT              2203
-#define B_LOADFONT             2204
-#define B_TEXTONCURVE  2205
-#define B_PACKFONT             2206
-
-/* *********************** */
-#define B_IKABUTS              2400
-
-#define B_IKASETREF            2301
-#define B_IKARECALC            2302
-
-/* *********************** */
-#define B_CAMBUTS              2500
-
-/* *********************** */
-#define B_MBALLBUTS            2600
-
-#define B_RECALCMBALL  2501
-
-/* *********************** */
-#define B_LATTBUTS             2700
-
-#define B_RESIZELAT            2601
-#define B_DRAWLAT              2602
-#define B_LATTCHANGED  2603
-
-/* *********************** */
-#define B_GAMEBUTS             2800
-
-/* in editsca.c */
-
-/* *********************** */
-#define B_FPAINTBUTS   2900
-
-#define B_VPCOLSLI             2801
-#define B_VPGAMMA              2802
-
-#define B_COPY_TF_MODE 2804
-#define B_COPY_TF_UV   2805
-#define B_COPY_TF_COL  2806
-#define B_REDR_3D_IMA  2807
-#define B_SET_VCOL             2808
-
-#define B_COPY_TF_TEX  2814
-#define B_TFACE_HALO   2815
-#define B_TFACE_BILLB  2816
-
-#define B_SHOWTEX              2832
-#define B_ASSIGNMESH   2833
-
-
-/* *********************** */
-#define B_RADIOBUTS            3000
-
-#define B_RAD_GO               2901
-#define B_RAD_INIT             2902
-#define B_RAD_LIMITS   2903
-#define B_RAD_FAC              2904
-#define B_RAD_NODELIM  2905
-#define B_RAD_NODEFILT 2906
-#define B_RAD_FACEFILT 2907
-#define B_RAD_ADD              2908
-#define B_RAD_DELETE   2909
-#define B_RAD_COLLECT  2910
-#define B_RAD_SHOOTP   2911
-#define B_RAD_SHOOTE   2912
-#define B_RAD_REPLACE  2913
-#define B_RAD_DRAW             2914
-#define B_RAD_FREE             2915
-#define B_RAD_ADDMESH  2916
-
-/* *********************** */
-#define B_SCRIPTBUTS   3100
-
-#define B_SCRIPT_ADD   3001
-#define B_SCRIPT_DEL   3002
-#define B_SCRIPT_TYPE  3003
-
-/* Scene script buttons */
-#define B_SSCRIPT_ADD  3004
-#define B_SSCRIPT_DEL  3005
-#define B_SSCRIPT_TYPE 3006
-
-/* *********************** */
-#define B_SOUNDBUTS            3200
-enum B_SOUND_BUTTONS {
-       B_SOUND_CHANGED = 3101,
-               B_SOUND_REDRAW,
-               B_SOUND_VOLUME,
-               B_SOUND_PANNING,
-               B_SOUND_PITCH,
-               B_SOUND_LOAD_SAMPLE,
-               B_SOUND_MENU_SAMPLE,
-               B_SOUND_NAME_SAMPLE,
-               B_SOUND_UNLINK_SAMPLE,
-               B_SOUND_RELOAD_SAMPLE,
-               B_SOUND_UNPACK_SAMPLE,
-               B_SOUND_PLAY_SAMPLE,
-               B_SOUND_COPY_SOUND,
-               B_SOUND_LOOPSTART,
-               B_SOUND_LOOPEND,
-               B_SOUND_BIDIRECTIONAL,
-               B_SOUND_RECALC,
-               B_SOUND_RATECHANGED,
-               B_SOUND_MIXDOWN
-};
-
-/* *********************** */
-#define B_CONSTRAINTBUTS       3300
-enum {
-       B_CONSTRAINT_REDRAW = 3201,
-       B_CONSTRAINT_ADD,
-       B_CONSTRAINT_DEL,
-       B_CONSTRAINT_TEST,
-       B_CONSTRAINT_CHANGETYPE,
-       B_CONSTRAINT_CHANGENAME,
-       B_CONSTRAINT_CHANGETARGET
-};
-
-/* *********************** */
-/*  BUTTON BUT: > 4000    */
-/*  BUTTON 4001-4032: layers */
+/* buts->mainb old */
+#define BUTS_VIEW                      0
+#define BUTS_LAMP                      1
+#define BUTS_MAT                       2
+#define BUTS_TEX                       3
+#define BUTS_ANIM                      4
+#define BUTS_WORLD                     5
+#define BUTS_RENDER                    6
+#define BUTS_EDIT                      7
+#define BUTS_GAME                      8
+#define BUTS_FPAINT                    9
+#define BUTS_RADIO                     10
+#define BUTS_SCRIPT                    11
+#define BUTS_SOUND                     12
+#define BUTS_CONSTRAINT                13
+
+/* warning: the values of these defines are used in sbuts->tabs[7] */
+/* buts->mainb new */
+#define CONTEXT_SCENE  0
+#define CONTEXT_OBJECT 1
+#define CONTEXT_TYPES  2
+#define CONTEXT_SHADING        3
+#define CONTEXT_EDITING        4
+#define CONTEXT_SCRIPT 5
+#define CONTEXT_LOGIC  6
+
+/* buts->tab new */
+#define TAB_SCENE_RENDER       0
+#define TAB_SCENE_WORLD                1
+#define TAB_SCENE_ANIM         2
+#define TAB_SCENE_SOUND                3
+
+#define TAB_SHADING_MAT        0
+#define TAB_SHADING_TEX        1
+#define TAB_SHADING_RAD        2
+#define TAB_SHADING_WORLD      3
+#define TAB_SHADING_LAMP       4
+
+/* buts->scaflag */            
+#define BUTS_SENS_SEL          1
+#define BUTS_SENS_ACT          2
+#define BUTS_SENS_LINK         4
+#define BUTS_CONT_SEL          8
+#define BUTS_CONT_ACT          16
+#define BUTS_CONT_LINK         32
+#define BUTS_ACT_SEL           64
+#define BUTS_ACT_ACT           128
+#define BUTS_ACT_LINK          256
 
 
 
index f33349c61e640f6759166896c33cb7b892767b50..c0c8c726906ce108b09b482e82c420488dbca496 100644 (file)
@@ -83,7 +83,7 @@ void  adduplicate_armature(void);
 void   addvert_armature(void);
 void   add_primitiveArmature(int type);
 void   apply_rot_armature (struct Object *ob, float mat[3][3]);
-void   armaturebuts(void);
+
 void   clear_armature(struct Object *ob, char mode);
 void   clever_numbuts_armature (void);
 void   clever_numbuts_posearmature (void);
@@ -105,6 +105,8 @@ void        remake_editArmature(void);
 void   selectconnected_armature(void);
 void   selectconnected_posearmature(void);
 void   select_bone_by_name (struct bArmature *arm, char *name, int select);
+void    unique_editbone_name (char* name);
+
 struct Bone *get_first_selected_bone (void);
 void auto_align_armature(void);
 void create_vgroups_from_armature(Object *ob, Object *par);
index c8471a5c01f3106b360507a638e64b000cda45cc..578ee41020ec289394ab107b2bde90a79675dd34 100644 (file)
@@ -141,11 +141,14 @@ short pupmenu(char *instr);
 short pupmenu_col(char *instr, int maxrow);
 
 extern void uiFreePanels(struct ListBase *lb);
-extern void uiNewPanel(struct ScrArea *sa, struct uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey);
+extern int uiNewPanel(struct ScrArea *sa, struct uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey);
 extern void uiScalePanelBlock(struct uiBlock *block);
 extern int uiIsPanelClosed(struct uiBlock *block);
 extern void uiAnimatePanels(struct ScrArea *sa);       
 extern void uiSetPanel_view2d(struct ScrArea *sa);
+extern void uiDrawBlocksPanels(struct ScrArea *sa, int re_align);
+extern void uiNewPanelHeight(struct uiBlock *block, int sizey);
+
 
 #endif /*  BIF_INTERFACE_H */
 
diff --git a/source/blender/include/butspace.h b/source/blender/include/butspace.h
new file mode 100644 (file)
index 0000000..8d32878
--- /dev/null
@@ -0,0 +1,482 @@
+/**
+ * $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 BUTSPACE_H
+#define BUTSPACE_H
+
+/* all internal calls and event codes for buttons space */
+
+struct Base;
+struct ID;
+
+
+/* buts->scaflag */            
+#define BUTS_SENS_SEL          1
+#define BUTS_SENS_ACT          2
+#define BUTS_SENS_LINK         4
+#define BUTS_CONT_SEL          8
+#define BUTS_CONT_ACT          16
+#define BUTS_CONT_LINK         32
+#define BUTS_ACT_SEL           64
+#define BUTS_ACT_ACT           128
+#define BUTS_ACT_LINK          256
+
+/* internal */
+
+/* scene */
+extern void render_panels(void);
+extern void do_render_panels(unsigned short event);
+extern void anim_panels(void);
+extern void sound_panels(void);
+
+/* object */
+extern void object_panels(void);
+extern void do_object_panels(unsigned short event);
+
+/* types */
+extern void types_panels(void);
+
+/* editing */
+extern void editing_panels(void);
+extern void do_common_editbuts(unsigned short event);
+extern void do_meshbuts(unsigned short event);
+extern void do_curvebuts(unsigned short event);
+extern void do_fontbuts(unsigned short event);
+extern void do_mballbuts(unsigned short event);
+extern void do_latticebuts(unsigned short event);
+extern void do_fpaintbuts(unsigned short event);
+
+/* shading */
+
+/* logic */
+extern void do_logic_buts(unsigned short event);
+extern void logic_buts(void);
+
+
+/* butspace.c */
+void test_meshpoin_but(char *name, struct ID **idpp);
+void test_obpoin_but(char *name, struct ID **idpp);
+void test_scenepoin_but(char *name, struct ID **idpp);
+void test_matpoin_but(char *name, struct ID **idpp);
+void test_scriptpoin_but(char *name, struct ID **idpp);
+void test_actionpoin_but(char *name, ID **idpp);
+void test_obcurpoin_but(char *name, ID **idpp);
+
+
+/* -------------- internal event defines ------------ */
+
+
+#define B_DIFF                 1       
+
+/* *********************** */
+#define B_VIEWBUTS             1100
+
+#define B_LOADBGPIC            1001
+#define B_BLENDBGPIC   1002
+#define B_BGPICBROWSE  1003
+#define B_BGPICTEX             1004
+#define B_BGPICCLEAR   1005
+#define B_BGPICTEXCLEAR        1006
+
+/* *********************** */
+#define B_LAMPBUTS             1200
+
+#define B_LAMPREDRAW   1101
+#define B_COLLAMP              1102
+#define B_TEXCLEARLAMP 1103
+#define B_SBUFF                        1104
+
+/* *********************** */
+#define B_MATBUTS              1300
+
+#define B_MATCOL               1201
+#define B_SPECCOL              1202
+#define B_MIRCOL               1203
+#define B_ACTCOL               1204
+#define B_MATFROM              1205
+#define B_MATPRV               1206
+#define B_MTEXCOL              1207
+#define B_TEXCLEAR             1208
+#define B_MATPRV_DRAW  1209
+#define B_MTEXPASTE            1210
+#define B_MTEXCOPY             1211
+#define B_MATLAY               1212
+
+/* *********************** */
+#define B_TEXBUTS              1400
+
+#define B_TEXTYPE              1301
+#define B_DEFTEXVAR            1302
+#define B_LOADTEXIMA   1303
+#define B_NAMEIMA              1304
+#define B_TEXCHANNEL   1305
+#define B_TEXREDR_PRV  1306
+#define B_TEXIMABROWSE 1307
+#define B_IMAPTEST             1308
+#define B_RELOADIMA            1309
+#define B_LOADPLUGIN   1310
+#define B_NAMEPLUGIN   1311
+#define B_COLORBAND            1312
+#define B_ADDCOLORBAND 1313
+#define B_DELCOLORBAND 1314
+#define B_CALCCBAND            1315
+#define B_CALCCBAND2   1316
+#define B_DOCOLORBAND  1317
+#define B_REDRAWCBAND  1318
+#define B_BANDCOL              1319
+#define B_LOADTEXIMA1  1320
+#define B_PLUGBUT              1321
+
+/* plugbut reserves 24 buttons at least! */
+
+#define B_ENV_MAKE             1350
+#define B_ENV_FREE             1351
+#define B_ENV_DELETE   1352
+#define B_ENV_SAVE             1353
+#define B_ENV_OB               1354
+
+#define B_PACKIMA              1355
+#define B_TEXSETFRAMES 1356
+
+#define B_ENV_FREE_ALL 1357
+
+/* *********************** */
+#define B_ANIMBUTS             1500
+
+#define B_RECALCPATH   1401
+#define B_MUL_IPO              1402
+#define B_AUTOTIMEOFS  1403
+#define B_FRAMEMAP             1404
+#define B_NEWEFFECT            1405
+#define B_PREVEFFECT   1406
+#define B_NEXTEFFECT   1407
+#define B_CHANGEEFFECT 1408
+#define B_CALCEFFECT   1409
+#define B_DELEFFECT            1410
+#define B_RECALCAL             1411
+#define B_SETSPEED             1412
+#define B_PRINTSPEED   1413
+#define B_PRINTLEN             1414
+#define B_RELKEY               1415
+
+       /* this has MAX_EFFECT settings! Next free define is 1450... */
+#define B_SELEFFECT    1430    
+
+
+/* *********************** */
+#define B_WORLDBUTS            1600
+
+#define B_TEXCLEARWORLD        1501
+
+/* *********************** */
+#define B_RENDERBUTS   1700
+
+#define B_FS_PIC               1601
+#define B_FS_BACKBUF   1602
+
+#define B_FS_FTYPE             1604
+#define B_DORENDER             1605
+#define B_DOANIM               1606
+#define B_PLAYANIM             1607
+#define B_PR_PAL               1608
+#define B_PR_FULL              1609
+#define B_PR_PRV               1610
+#define B_PR_CDI               1611
+#define B_PR_PAL169            1612
+#define B_PR_D2MAC             1613
+#define B_PR_MPEG              1614
+#define B_REDRAWDISP   1615
+#define B_SETBROWSE            1616
+#define B_CLEARSET             1617
+#define B_PR_PRESET            1618
+#define B_PR_PANO              1619
+#define B_PR_NTSC              1620
+
+#define B_IS_FTYPE             1622
+#define B_IS_BACKBUF   1623
+#define B_PR_PC                        1624
+
+#define B_PR_PANO360    1627
+#define B_PR_HALFFIELDS        1628
+#define B_NEWRENDERPIPE 1629
+#define B_R_SCALE       1630
+#define B_G_SCALE       1631
+#define B_B_SCALE       1632
+#define B_USE_R_SCALE   1633
+#define B_USE_G_SCALE   1634
+#define B_USE_B_SCALE   1635
+#define B_EDGECOLSLI    1636
+#define B_GAMMASLI      1637
+
+#define B_FILETYPEMENU  1638
+#define B_SELECTCODEC   1639
+#define B_RTCHANGED            1640
+
+#ifdef __NLA
+/* *********************** */
+enum {
+       B_ARMATUREBUTS  =       1800,
+       B_POSE                  =       1701
+};
+#endif
+
+/* *********************** */
+#define B_COMMONEDITBUTS       2049
+
+#define B_MATWICH              2003
+#define B_MATNEW               2004
+#define B_MATDEL               2005
+#define B_MATASS               2006
+#define B_MATSEL               2007
+#define B_MATDESEL             2008
+#define B_HIDE                 2009
+#define B_REVEAL               2010
+#define B_SELSWAP              2011
+#define B_SETSMOOTH            2012
+#define B_SETSOLID             2013
+#define B_AUTOTEX              2014
+#define B_DOCENTRE             2015
+#define B_DOCENTRENEW  2016
+#define B_DOCENTRECURSOR       2017
+
+       /* 32 values! */
+#define B_OBLAY                        2018
+
+#define B_MESHBUTS             2100
+
+#define B_FLIPNORM             2050
+#define B_SPIN                 2051
+#define B_SPINDUP              2052
+#define B_EXTR                 2053
+#define B_SCREW                        2054
+#define B_EXTREP               2055
+#define B_SPLIT                        2056
+#define B_REMDOUB              2057
+#define B_SUBDIV               2058
+#define B_FRACSUBDIV   2059
+#define B_XSORT                        2060
+#define B_HASH                 2061
+#define B_DELSTICKY            2062
+#define B_DELVERTCOL   2063
+#define B_MAKE_TFACES  2064
+#define B_TOSPHERE             2065
+#define B_DEL_TFACES   2066
+#define B_NEWVGROUP            2067
+#define B_DELVGROUP            2068
+#define B_ASSIGNVGROUP 2069
+#define B_REMOVEVGROUP 2070
+#define B_SELVGROUP            2071    
+#define B_DESELVGROUP  2072
+#define B_DECIM_FACES  2073
+#define B_DECIM_CANCEL 2074
+#define B_DECIM_APPLY  2075
+#define B_AUTOVGROUP   2076
+#define B_SLOWERDRAW   2077
+#define B_FASTERDRAW   2078
+#define B_VERTEXNOISE  2079
+#define B_VERTEXSMOOTH 2080
+#define B_MAKESTICKY   2082
+#define B_MAKEVERTCOL  2083
+
+/* *********************** */
+#define B_CURVEBUTS            2200
+
+#define B_CONVERTPOLY  2101
+#define B_CONVERTBEZ   2102
+#define B_CONVERTBSPL  2103
+#define B_CONVERTCARD  2104
+#define B_CONVERTNURB  2105
+#define B_UNIFU                        2106
+#define B_ENDPU                        2107
+#define B_BEZU                 2108
+#define B_UNIFV                        2109
+#define B_ENDPV                        2110
+#define B_BEZV                 2111
+#define B_SETWEIGHT            2112
+#define B_SETW1                        2113
+#define B_SETW2                        2114
+#define B_SETW3                        2115
+#define B_SETORDER             2116
+#define B_MAKEDISP             2117
+#define B_SUBDIVCURVE  2118
+#define B_SPINNURB             2119
+#define B_CU3D                 2120
+#define B_SETRESOLU            2121
+#define B_SETW4                        2122
+
+
+/* *********************** */
+#define B_FONTBUTS             2300
+
+#define B_MAKEFONT             2201
+#define B_TOUPPER              2202
+#define B_SETFONT              2203
+#define B_LOADFONT             2204
+#define B_TEXTONCURVE  2205
+#define B_PACKFONT             2206
+
+/* *********************** */
+#define B_IKABUTS              2400
+
+#define B_IKASETREF            2301
+#define B_IKARECALC            2302
+
+/* *********************** */
+#define B_CAMBUTS              2500
+
+/* *********************** */
+#define B_MBALLBUTS            2600
+
+#define B_RECALCMBALL  2501
+
+/* *********************** */
+#define B_LATTBUTS             2700
+
+#define B_RESIZELAT            2601
+#define B_DRAWLAT              2602
+#define B_LATTCHANGED  2603
+
+/* *********************** */
+#define B_GAMEBUTS             2800
+
+#define B_ADD_PROP             2701
+#define B_CHANGE_PROP  2702
+
+#define B_ADD_SENS             2703
+#define B_CHANGE_SENS  2704
+#define B_DEL_SENS             2705
+
+#define B_ADD_CONT             2706
+#define B_CHANGE_CONT  2707
+#define B_DEL_CONT             2708
+
+#define B_ADD_ACT              2709
+#define B_CHANGE_ACT   2710
+#define B_DEL_ACT              2711
+
+#define B_SOUNDACT_BROWSE      2712
+
+/* *********************** */
+#define B_FPAINTBUTS   2900
+
+#define B_VPCOLSLI             2801
+#define B_VPGAMMA              2802
+
+#define B_COPY_TF_MODE 2804
+#define B_COPY_TF_UV   2805
+#define B_COPY_TF_COL  2806
+#define B_REDR_3D_IMA  2807
+#define B_SET_VCOL             2808
+
+#define B_COPY_TF_TEX  2814
+#define B_TFACE_HALO   2815
+#define B_TFACE_BILLB  2816
+
+#define B_SHOWTEX              2832
+#define B_ASSIGNMESH   2833
+
+
+/* *********************** */
+#define B_RADIOBUTS            3000
+
+#define B_RAD_GO               2901
+#define B_RAD_INIT             2902
+#define B_RAD_LIMITS   2903
+#define B_RAD_FAC              2904
+#define B_RAD_NODELIM  2905
+#define B_RAD_NODEFILT 2906
+#define B_RAD_FACEFILT 2907
+#define B_RAD_ADD              2908
+#define B_RAD_DELETE   2909
+#define B_RAD_COLLECT  2910
+#define B_RAD_SHOOTP   2911
+#define B_RAD_SHOOTE   2912
+#define B_RAD_REPLACE  2913
+#define B_RAD_DRAW             2914
+#define B_RAD_FREE             2915
+#define B_RAD_ADDMESH  2916
+
+/* *********************** */
+#define B_SCRIPTBUTS   3100
+
+#define B_SCRIPT_ADD   3001
+#define B_SCRIPT_DEL   3002
+#define B_SCRIPT_TYPE  3003
+
+/* Scene script buttons */
+#define B_SSCRIPT_ADD  3004
+#define B_SSCRIPT_DEL  3005
+#define B_SSCRIPT_TYPE 3006
+
+/* *********************** */
+#define B_SOUNDBUTS            3200
+enum B_SOUND_BUTTONS {
+       B_SOUND_CHANGED = 3101,
+               B_SOUND_REDRAW,
+               B_SOUND_VOLUME,
+               B_SOUND_PANNING,
+               B_SOUND_PITCH,
+               B_SOUND_LOAD_SAMPLE,
+               B_SOUND_MENU_SAMPLE,
+               B_SOUND_NAME_SAMPLE,
+               B_SOUND_UNLINK_SAMPLE,
+               B_SOUND_RELOAD_SAMPLE,
+               B_SOUND_UNPACK_SAMPLE,
+               B_SOUND_PLAY_SAMPLE,
+               B_SOUND_COPY_SOUND,
+               B_SOUND_LOOPSTART,
+               B_SOUND_LOOPEND,
+               B_SOUND_BIDIRECTIONAL,
+               B_SOUND_RECALC,
+               B_SOUND_RATECHANGED,
+               B_SOUND_MIXDOWN
+};
+
+/* *********************** */
+#define B_CONSTRAINTBUTS       3300
+enum {
+       B_CONSTRAINT_REDRAW = 3201,
+       B_CONSTRAINT_ADD,
+       B_CONSTRAINT_DEL,
+       B_CONSTRAINT_TEST,
+       B_CONSTRAINT_CHANGETYPE,
+       B_CONSTRAINT_CHANGENAME,
+       B_CONSTRAINT_CHANGETARGET
+};
+
+/* *********************** */
+/*  BUTTON BUT: > 4000    */
+/*  BUTTON 4001-4032: layers */
+
+
+
+#endif
+
index c90acd929a0ee551a2eeb5e72372dfe9dea26887..fbb9be3c653d89bada216553bf4279abe3a9cb9d 100644 (file)
@@ -89,7 +89,7 @@ typedef struct Panel {                /* the part from uiBlock that needs saved in file */
        struct Panel *next, *prev;
        char panelname[64], tabname[64];        /* defined as UI_MAX_NAME_STR */
        short ofsx, ofsy, sizex, sizey;
-       short flag, pad;
+       short flag, active;                                     /* active= used currently by a uiBlock */
        int pad2;
        struct Panel *paneltab;         /* this panel is tabbed in *paneltab */
 } Panel;
index e8e274157b8a0902397376d0c91b0a4c5b14c9e0..8674eb3fb4c5eb8c2476d71ea006c8ab07d33cc4 100644 (file)
@@ -89,7 +89,8 @@ typedef struct SpaceIpo {
 
 typedef struct SpaceButs {
        SpaceLink *next, *prev;
-       int spacetype, pad1;
+       int spacetype;
+       short re_align, pad1;
        struct ScrArea *area;
 
        short cursens, curact;
@@ -333,53 +334,7 @@ typedef struct SpaceImaSel {
 #define V3D_LOCAL              2
 */
 
-/* buts->mainb old */
-#define BUTS_VIEW                      0
-#define BUTS_LAMP                      1
-#define BUTS_MAT                       2
-#define BUTS_TEX                       3
-#define BUTS_ANIM                      4
-#define BUTS_WORLD                     5
-#define BUTS_RENDER                    6
-#define BUTS_EDIT                      7
-#define BUTS_GAME                      8
-#define BUTS_FPAINT                    9
-#define BUTS_RADIO                     10
-#define BUTS_SCRIPT                    11
-#define BUTS_SOUND                     12
-#define BUTS_CONSTRAINT                13
-
-/* warning: the values of these defines are used in sbuts->tabs[7] */
-/* buts->mainb new */
-#define CONTEXT_SCENE  0
-#define CONTEXT_OBJECT 1
-#define CONTEXT_TYPES  2
-#define CONTEXT_SHADING        3
-#define CONTEXT_EDITING        4
-#define CONTEXT_SCRIPT 5
-#define CONTEXT_LOGIC  6
-
-/* buts->tab new */
-#define TAB_SCENE_RENDER       0
-#define TAB_SCENE_WORLD                1
-#define TAB_SCENE_SETTINGS     2
-
-#define TAB_SHADING_MAT        0
-#define TAB_SHADING_TEX        1
-#define TAB_SHADING_RAD        2
-#define TAB_SHADING_WORLD      3
-#define TAB_SHADING_LAMP       4
-
-/* buts->scaflag */            
-#define BUTS_SENS_SEL          1
-#define BUTS_SENS_ACT          2
-#define BUTS_SENS_LINK         4
-#define BUTS_CONT_SEL          8
-#define BUTS_CONT_ACT          16
-#define BUTS_CONT_LINK         32
-#define BUTS_ACT_SEL           64
-#define BUTS_ACT_ACT           128
-#define BUTS_ACT_LINK          256
+/* buts defines in BIF_butspace.h */
 
 /* these values need to be hardcoded in blender.h SpaceFile: struct dna does not recognize defines */
 #define FILE_MAXDIR                    160
index b2b3cc4e06439ea630c4907392e403b56c845c69..730da7bc186262f69a0345e6031794f5bca41bd9 100644 (file)
 #endif
 
 #include "MEM_guardedalloc.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_effect_types.h"
-#include "DNA_group_types.h"
-#include "DNA_ika_types.h"
-#include "DNA_image_types.h"
-#include "DNA_key_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_material_types.h"
-#include "DNA_meta_types.h"
-#include "DNA_mesh_types.h"
+
 #include "DNA_object_types.h"
-#include "DNA_packedFile_types.h"
-#include "DNA_radio_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_sound_types.h"
+#include "DNA_view3d_types.h"
 #include "DNA_space_types.h"
 #include "DNA_texture_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_vfont_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_world_types.h"
-
-#include "BKE_anim.h"
-#include "BKE_armature.h"
-#include "BKE_constraint.h"
-#include "BKE_curve.h"
-#include "BKE_displist.h"
-#include "BKE_effect.h"
-#include "BKE_font.h"
+
 #include "BKE_global.h"
-#include "BKE_ika.h"
-#include "BKE_image.h"
-#include "BKE_ipo.h"
-#include "BKE_lattice.h"
-#include "BKE_library.h"
 #include "BKE_main.h"
-#include "BKE_material.h"
-#include "BKE_mball.h"
-#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_packedFile.h"
-#include "BKE_plugin_types.h"
-#include "BKE_sound.h"
-#include "BKE_texture.h"
+#include "BKE_library.h"
 #include "BKE_utildefines.h"
-#include "BKE_writeavi.h"
 
 #include "BLI_blenlib.h"
 
 #include "BIF_gl.h"
 #include "BIF_graphics.h"
 #include "BIF_keyval.h"
-#include "BIF_mainqueue.h"
-#include "BIF_resources.h"
-#include "BIF_screen.h"
-#include "BIF_mywindow.h"
-#include "BIF_space.h"
-#include "BIF_glutil.h"
 #include "BIF_interface.h"
-#include "BIF_editsca.h"
-#include "BIF_butspace.h"
-#include "BIF_previewrender.h"
 #include "BIF_toolbox.h"
-
+#include "BIF_space.h"
+#include "BIF_screen.h"
+#include "BIF_butspace.h"
 #include "BSE_headerbuttons.h"
+#include "BIF_previewrender.h"
+#include "BIF_mywindow.h"
+#include "BIF_glutil.h"
+#include "BIF_resources.h"
 
 #include "mydevice.h"
+#include "butspace.h" // own module
 
 
 /* Local vars ---------------------------------------------------------- */
 short bgpicmode=0, near=1000, far=1000;
-short degr= 90, step= 9, turn= 1, editbutflag= 1;
-float hspeed=0.1f, prspeed=0.0f, prlen=0.0f, doublimit= 0.001f;
-int decim_faces=0;
-
-float editbutvweight=1;
-float extr_offs= 1.0, editbutweight=1.0, editbutsize=0.1, cumapsize= 1.0;
 MTex emptytex;
 MTex mtexcopybuf;
 
@@ -281,7 +233,6 @@ void do_butspace(unsigned short event)
        buts= curarea->spacedata.first;
        if(buts->mainb==CONTEXT_SCENE) allqueue(REDRAWBUTSSCENE, curarea->win);
        if(buts->mainb==CONTEXT_OBJECT) allqueue(REDRAWBUTSOBJECT, curarea->win);
-       if(buts->mainb==CONTEXT_TYPES) allqueue(REDRAWBUTSTYPES, curarea->win);
        if(buts->mainb==CONTEXT_SHADING) allqueue(REDRAWBUTSSHADING, curarea->win);
        if(buts->mainb==CONTEXT_EDITING) allqueue(REDRAWBUTSEDIT, curarea->win);
        if(buts->mainb==CONTEXT_SCRIPT) allqueue(REDRAWBUTSSCRIPT, curarea->win);
@@ -303,7 +254,7 @@ void do_butspace(unsigned short event)
                //do_texbuts(event);
        }
        else if(event<=B_ANIMBUTS) {
-               //do_animbuts(event);
+               do_object_panels(event);
        }
        else if(event<=B_WORLDBUTS) {
                //do_worldbuts(event);
@@ -312,34 +263,31 @@ void do_butspace(unsigned short event)
                do_render_panels(event);        // buttons_scene.c
        }
        else if(event<=B_COMMONEDITBUTS) {
-               //do_common_editbuts(event);
+               do_common_editbuts(event);
        }
        else if(event<=B_MESHBUTS) {
-               //do_meshbuts(event);
+               do_meshbuts(event);
        }
        else if(event<=B_CURVEBUTS) {
-               //do_curvebuts(event);
+               do_curvebuts(event);
        }
        else if(event<=B_FONTBUTS) {
-               //do_fontbuts(event);
-       }
-       else if(event<=B_IKABUTS) {
-               //do_ikabuts(event);
+               do_fontbuts(event);
        }
        else if(event<=B_CAMBUTS) {
                ;
        }
        else if(event<=B_MBALLBUTS) {
-               //do_mballbuts(event);
+               do_mballbuts(event);
        }
        else if(event<=B_LATTBUTS) {
-               //do_latticebuts(event);
+               do_latticebuts(event);
        }
        else if(event<=B_GAMEBUTS) {
-               do_gamebuts(event);     // editsca.c
+               do_logic_buts(event);   // buttons_logic.c
        }
        else if(event<=B_FPAINTBUTS) {
-               //do_fpaintbuts(event);
+               do_fpaintbuts(event);
        }
        else if(event<=B_RADIOBUTS) {
                //do_radiobuts(event);
@@ -367,13 +315,15 @@ void redraw_test_buttons(Base *new)
                if(sa->spacetype==SPACE_BUTS) {
                        buts= sa->spacedata.first;
                        
-                       if(ELEM5(buts->mainb, CONTEXT_OBJECT, CONTEXT_TYPES, CONTEXT_EDITING, CONTEXT_SHADING, CONTEXT_LOGIC)) {
+                       if(ELEM4(buts->mainb, CONTEXT_OBJECT, CONTEXT_EDITING, CONTEXT_SHADING, CONTEXT_LOGIC)) {
                                addqueue(sa->win, REDRAW, 1);
+                               buts->re_align= 1;
                        }
                        
                        if(buts->mainb==CONTEXT_SHADING) {
-                               // change type automatically
+                               buts->re_align= 1;
                                
+                               // change type automatically
                                if(new) {
                                        if(buts->tab[CONTEXT_SHADING] == TAB_SHADING_WORLD);
                                        else if(buts->tab[CONTEXT_SHADING] == TAB_SHADING_TEX);
@@ -395,68 +345,13 @@ void redraw_test_buttons(Base *new)
 }
 
 
-
-/* here the calls for building the button main/tabs tree */
-
-
-static void context_scene_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       if(sbuts->tab[CONTEXT_SCENE] == TAB_SCENE_RENDER) 
-               render_panels();
-       
-}
-
-static void context_object_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       
-}
-
-static void context_types_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       
-}
-
-static void context_shading_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       
-}
-
-static void context_editing_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       
-}
-
-static void context_logic_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* no tabs */
-       gamebuts();             /* (editsca.c) */
-       
-}
-
-static void context_script_buttons(ScrArea *sa, SpaceButs *sbuts)
-{
-
-       /* select tabs */
-       
-}
-
 /* callback */
 void drawbutspace(ScrArea *sa, void *spacedata)
 {
        SpaceButs *sbuts= sa->spacedata.first;
        View2D *v2d= &sbuts->v2d;
-
+       int align=0;
+       
        myortho2(v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
 
        glClearColor(0.73, 0.73, 0.73, 0.0);
@@ -468,30 +363,54 @@ void drawbutspace(ScrArea *sa, void *spacedata)
        /* select the context to be drawn, per contex/tab the actual context is tested */
        switch(sbuts->mainb) {
        case CONTEXT_SCENE:
-               context_scene_buttons(sa, sbuts);
+               /* select tabs */
+               if(sbuts->tab[CONTEXT_SCENE] == TAB_SCENE_RENDER) 
+                       render_panels();
+               else if(sbuts->tab[CONTEXT_SCENE] == TAB_SCENE_ANIM) 
+                       anim_panels();
+               else if(sbuts->tab[CONTEXT_SCENE] == TAB_SCENE_SOUND) 
+                       sound_panels();
+
                break;
        case CONTEXT_OBJECT:
-               context_object_buttons(sa, sbuts);
+               /* no tabs */
+               object_panels();
                break;
-       case CONTEXT_TYPES:
-               context_types_buttons(sa, sbuts);
+               
                break;
        case CONTEXT_SHADING:
-               context_shading_buttons(sa, sbuts);
+
                break;
        case CONTEXT_EDITING:
-               context_editing_buttons(sa, sbuts);
+               /* no tabs */
+               editing_panels();
+
                break;
        case CONTEXT_SCRIPT:
-               context_script_buttons(sa, sbuts);
+
                break;
        case CONTEXT_LOGIC:
-               context_logic_buttons(sa, sbuts);
+               /* no tabs */
+               logic_buts();
                break;
        }
 
        uiClearButLock();
 
+
+       /* when align changes, also do this for new panels */
+       /* don't always align, this function is called during AnmatePanels too */
+       if(sbuts->align)
+               if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb)
+                       align= 1;
+
+       uiDrawBlocksPanels(sa, align);  
+       
+       sbuts->re_align= 0;
+       // also for memory for finding which texture you'd like to see
+       sbuts->mainbo= sbuts->mainb;
+       sbuts->tabo= sbuts->tab[sbuts->mainb];
+
        myortho2(-0.5, (float)(sa->winx)-.05, -0.5, (float)(sa->winy)-0.5);
        draw_area_emboss(sa);
        myortho2(v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
index b32ad5ea201763df98c56bfead3e3a31af61f98a..1b209c3515ed1dfd010c179277f15b0072db9981 100644 (file)
@@ -593,2825 +593,2028 @@ static void draw_buttons_edge(int win, float x1)
 
 static int packdummy = 0;
 
-void test_scriptpoin_but(char *name, ID **idpp)
-{
-       ID *id;
-       
-       id= G.main->text.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
-#ifdef __NLA
-void test_actionpoin_but(char *name, ID **idpp)
-{
-       ID *id;
-       
-       id= G.main->action.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
-#endif
-
-void test_obpoin_but(char *name, ID **idpp)
-{
-       ID *id;
-       
-       if(idpp == (ID **)&(emptytex.object)) {
-               error("You must add a Texture first!");
-               *idpp= 0;
-               return;
-       }
-       
-       id= G.main->object.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
-
-void test_obcurpoin_but(char *name, ID **idpp)
-{
-       ID *id;
-       
-       if(idpp == (ID **)&(emptytex.object)) {
-               error("You must add a Texture first!");
-               *idpp= 0;
-               return;
-       }
-       
-       id= G.main->object.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       if (((Object *)id)->type != OB_CURVE) {
-                               error ("Bevel object must be a Curve.");
-                               break;
-                       } 
-                       *idpp= id;
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
-
-void test_meshpoin_but(char *name, ID **idpp)
-{
-       ID *id;
 
-       if( *idpp ) (*idpp)->us--;
-       
-       id= G.main->mesh.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       id_us_plus(id);
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
+// Bish made it to here. (reviewing tooltips)
 
-void test_matpoin_but(char *name, ID **idpp)
-{
-       ID *id;
 
-       if( *idpp ) (*idpp)->us--;
-       
-       id= G.main->mat.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       id_us_plus(id);
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
+/* *************************** RADIO ******************************** */
 
-void test_scenepoin_but(char *name, ID **idpp)
+void do_radiobuts(short event)
 {
-       ID *id;
+       Radio *rad;
+       int phase;
        
-       if( *idpp ) (*idpp)->us--;
+       phase= rad_phase();
+       rad= G.scene->radio;
        
-       id= G.main->scene.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       id_us_plus(id);
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= 0;
-}
-
-
-
-/* ************************************* */
-
-static void do_common_editbuts(unsigned short event)
-{
-       EditVlak *evl;
-       Base *base;
-       Object *ob;
-       Mesh *me;
-       Nurb *nu;
-       Curve *cu;
-       MFace *mface;
-       BezTriple *bezt;
-       BPoint *bp;
-       unsigned int local;
-       int a, bit, index= -1;
-
        switch(event) {
-               
-       case B_MATWICH:
-               if(G.obedit && G.obedit->actcol>0) {
-                       if(G.obedit->type == OB_MESH) {
-                               evl= G.edvl.first;
-                               while(evl) {
-                                       if( vlakselectedAND(evl, 1) ) {
-                                               if(index== -1) index= evl->mat_nr;
-                                               else if(index!=evl->mat_nr) {
-                                                       error("Mixed colors");
-                                                       return;
-                                               }
-                                       }
-                                       evl= evl->next;
-                               }
-                       }
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
-                               nu= editNurb.first;
-                               while(nu) {
-                                       if( isNurbsel(nu) ) {
-                                               if(index== -1) index= nu->mat_nr;
-                                               else if(index!=nu->mat_nr) {
-                                                       error("Mixed colors");
-                                                       return;
-                                               }
-                                       }
-                                       nu= nu->next;
-                               }                               
-                       }
-                       if(index>=0) {
-                               G.obedit->actcol= index+1;
-                               scrarea_queue_winredraw(curarea);
-                       }
-               }
-               break;
-       case B_MATNEW:
-               new_material_to_objectdata((G.scene->basact) ? (G.scene->basact->object) : 0);
-               scrarea_queue_winredraw(curarea);
-               allqueue(REDRAWVIEW3D_Z, 0);
+       case B_RAD_ADD:
+               add_radio();
+               allqueue(REDRAWBUTSRADIO, 0);
+               allqueue(REDRAWVIEW3D, 0);
                break;
-       case B_MATDEL:
-               delete_material_index();
-               scrarea_queue_winredraw(curarea);
-               allqueue(REDRAWVIEW3D_Z, 0);
+       case B_RAD_DELETE:
+               delete_radio();
+               allqueue(REDRAWBUTSRADIO, 0);
+               allqueue(REDRAWVIEW3D, 0);
                break;
-       case B_MATASS:
-               if(G.obedit && G.obedit->actcol>0) {
-                       if(G.obedit->type == OB_MESH) {
-                               evl= G.edvl.first;
-                               while(evl) {
-                                       if( vlakselectedAND(evl, 1) )
-                                               evl->mat_nr= G.obedit->actcol-1;
-                                       evl= evl->next;
-                               }
-                               allqueue(REDRAWVIEW3D_Z, 0);
-                               makeDispList(G.obedit);
-                       }
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
-                               nu= editNurb.first;
-                               while(nu) {
-                                       if( isNurbsel(nu) )
-                                               nu->mat_nr= G.obedit->actcol-1;
-                                       nu= nu->next;
-                               }
-                       }
-               }
+       case B_RAD_FREE:
+               freeAllRad();
+               allqueue(REDRAWBUTSRADIO, 0);
+               allqueue(REDRAWVIEW3D, 0);
                break;
-       case B_MATSEL:
-       case B_MATDESEL:
-               if(G.obedit) {
-                       if(G.obedit->type == OB_MESH) {
-                               evl= G.edvl.first;
-                               while(evl) {
-                                       if(evl->mat_nr== G.obedit->actcol-1) {
-                                               if(event==B_MATSEL) {
-                                                       if(evl->v1->h==0) evl->v1->f |= 1;
-                                                       if(evl->v2->h==0) evl->v2->f |= 1;
-                                                       if(evl->v3->h==0) evl->v3->f |= 1;
-                                                       if(evl->v4 && evl->v4->h==0) evl->v4->f |= 1;
-                                               }
-                                               else {
-                                                       if(evl->v1->h==0) evl->v1->f &= ~1;
-                                                       if(evl->v2->h==0) evl->v2->f &= ~1;
-                                                       if(evl->v3->h==0) evl->v3->f &= ~1;
-                                                       if(evl->v4 && evl->v4->h==0) evl->v4->f &= ~1;
-                                               }
-                                       }
-                                       evl= evl->next;
-                               }
-                               tekenvertices_ext( event==B_MATSEL );
-                       }
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
-                               nu= editNurb.first;
-                               while(nu) {
-                                       if(nu->mat_nr==G.obedit->actcol-1) {
-                                               if(nu->bezt) {
-                                                       a= nu->pntsu;
-                                                       bezt= nu->bezt;
-                                                       while(a--) {
-                                                               if(bezt->hide==0) {
-                                                                       if(event==B_MATSEL) {
-                                                                               bezt->f1 |= 1;
-                                                                               bezt->f2 |= 1;
-                                                                               bezt->f3 |= 1;
-                                                                       }
-                                                                       else {
-                                                                               bezt->f1 &= ~1;
-                                                                               bezt->f2 &= ~1;
-                                                                               bezt->f3 &= ~1;
-                                                                       }
-                                                               }
-                                                               bezt++;
-                                                       }
-                                               }
-                                               else if(nu->bp) {
-                                                       a= nu->pntsu*nu->pntsv;
-                                                       bp= nu->bp;
-                                                       while(a--) {
-                                                               if(bp->hide==0) {
-                                                                       if(event==B_MATSEL) bp->f1 |= 1;
-                                                                       else bp->f1 &= ~1;
-                                                               }
-                                                               bp++;
-                                                       }
-                                               }
-                                       }
-                                       nu= nu->next;
-                               }
-                               allqueue(REDRAWVIEW3D, 0);
-                       }
-               }
+       case B_RAD_COLLECT:
+               rad_collect_meshes();
+               allqueue(REDRAWBUTSRADIO, 0);
+               allqueue(REDRAWVIEW3D, 0);
                break;
-       case B_HIDE:
-               if(G.obedit) {
-                       if(G.obedit->type == OB_MESH) hide_mesh(0);
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
+       case B_RAD_INIT:
+               if(phase==RAD_PHASE_PATCHES) {
+                       rad_limit_subdivide();
+                       allqueue(REDRAWBUTSRADIO, 0);
+                       allqueue(REDRAWVIEW3D, 0);
                }
                break;
-       case B_REVEAL:
-               if(G.obedit) {
-                       if(G.obedit->type == OB_MESH) reveal_mesh();
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
+       case B_RAD_SHOOTP:
+               if(phase==RAD_PHASE_PATCHES) {
+                       waitcursor(1);
+                       rad_subdivshootpatch();
+                       allqueue(REDRAWBUTSRADIO, 0);
+                       allqueue(REDRAWVIEW3D, 0);
+                       waitcursor(0);
                }
-               else if(G.f & G_FACESELECT) reveal_tface();
-               
                break;
-       case B_SELSWAP:
-               if(G.obedit) {
-                       if(G.obedit->type == OB_MESH) selectswap_mesh();
-                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
+       case B_RAD_SHOOTE:
+               if(phase==RAD_PHASE_PATCHES) {
+                       waitcursor(1);
+                       rad_subdivshootelem();
+                       allqueue(REDRAWBUTSRADIO, 0);
+                       allqueue(REDRAWVIEW3D, 0);
+                       waitcursor(0);
                }
                break;
-       case B_AUTOTEX:
-               ob= OBACT;
-               if(ob && G.obedit==0) {
-                       if(ob->type==OB_MESH) tex_space_mesh(ob->data);
-                       else if(ob->type==OB_MBALL) ;
-                       else tex_space_curve(ob->data);
+       case B_RAD_GO:
+               if(phase==RAD_PHASE_PATCHES) {
+                       waitcursor(1);
+                       rad_go();
+                       waitcursor(0);
+                       allqueue(REDRAWBUTSRADIO, 0);
+                       allqueue(REDRAWVIEW3D, 0);
                }
                break;
-       case B_DOCENTRE:
-               docentre();
-               break;
-       case B_DOCENTRENEW:
-               docentre_new();
+       case B_RAD_LIMITS:
+               rad_setlimits();
+               allqueue(REDRAWVIEW3D, 0);
+               allqueue(REDRAWBUTSRADIO, 0);
                break;
-       case B_DOCENTRECURSOR:
-               docentre_cursor();
+       case B_RAD_FAC:
+               set_radglobal();
+               if(phase & RAD_PHASE_FACES) make_face_tab();
+               else make_node_display();
+               allqueue(REDRAWVIEW3D, 0);
                break;
-       case B_SETSMOOTH:
-       case B_SETSOLID:
-               if(G.obedit) {
-                       if(G.obedit->type == OB_MESH) {
-                               evl= G.edvl.first;
-                               while(evl) {
-                                       if( vlakselectedAND(evl, 1) ) {
-                                               if(event==B_SETSMOOTH) evl->flag |= ME_SMOOTH;
-                                               else evl->flag &= ~ME_SMOOTH;
-                                       }
-                                       evl= evl->next;
-                               }
-
-                               makeDispList(G.obedit);
-                               allqueue(REDRAWVIEW3D, 0);
-                       }
-                       else {
-                               nu= editNurb.first;
-                               while(nu) {
-                                       if(isNurbsel(nu)) {
-                                               if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
-                                               else nu->flag &= ~ME_SMOOTH;
-                                       }
-                                       nu= nu->next;
-                               }
-                               
-                       }
+       case B_RAD_NODELIM:
+               if(phase & RAD_PHASE_FACES) {
+                       set_radglobal();
+                       removeEqualNodes(rad->nodelim);
+                       make_face_tab();
+                       allqueue(REDRAWVIEW3D, 0);
+                       allqueue(REDRAWBUTSRADIO, 0);
                }
-               else {
-                       base= FIRSTBASE;
-                       while(base) {
-                               if(TESTBASELIB(base)) {
-                                       if(base->object->type==OB_MESH) {
-                                               me= base->object->data;
-                                               mface= me->mface;
-                                               for(a=0; a<me->totface; a++, mface++) {
-                                                       if(event==B_SETSMOOTH) mface->flag |= ME_SMOOTH;
-                                                       else mface->flag &= ~ME_SMOOTH;
-                                               }
-
-                                               makeDispList(base->object);
-                                       }
-                                       else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
-                                               cu= base->object->data;
-                                               nu= cu->nurb.first;
-                                               while(nu) {
-                                                       if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
-                                                       else nu->flag &= ~ME_SMOOTH;
-                                                       nu= nu->next;
-                                               }
-                                       }
-                               }
-                               base= base->next;
-                       }
+               break;
+       case B_RAD_NODEFILT:
+               if(phase & RAD_PHASE_FACES) {
+                       set_radglobal();
+                       filterNodes();
+                       make_face_tab();
                        allqueue(REDRAWVIEW3D, 0);
                }
                break;
-
-       default:
-               if(event>=B_OBLAY && event<=B_OBLAY+31) {
-                       local= BASACT->lay & 0xFF000000;
-                       BASACT->lay -= local;
-                       if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
-                               bit= event-B_OBLAY;
-                               BASACT->lay= 1<<bit;
-                               scrarea_queue_winredraw(curarea);
-                       }
-                       BASACT->lay += local;
-                       /* optimal redraw */
-                       if( (OBACT->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
-                       else if( (OBACT->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
-                       else allqueue(REDRAWVIEW3D, 0);
-                       
-                       OBACT->lay= BASACT->lay;
+       case B_RAD_FACEFILT:
+               if(phase & RAD_PHASE_FACES) {
+                       filterFaces();
+                       allqueue(REDRAWVIEW3D, 0);
                }
+               break;
+       case B_RAD_DRAW:
+               set_radglobal();
+               allqueue(REDRAWVIEW3D, 0);
+               break;
+       case B_RAD_ADDMESH:
+               if(phase & RAD_PHASE_FACES) rad_addmesh();
+               allqueue(REDRAWVIEW3D, 0);
+               break;
+       case B_RAD_REPLACE:
+               if(phase & RAD_PHASE_FACES) rad_replacemesh();
+               allqueue(REDRAWVIEW3D, 0);
+               break;
        }
 
 }
 
-void common_editbuts(void)
+
+void radiobuts(void)
 {
-       Object *ob;
-       ID *id;
-       Material *ma;
+       Radio *rad;
        uiBlock *block;
-       void *poin;
-       float min;
-       int xco, a, dx, dy;
-       char str[32];
-       
-       ob= OBACT;
-       if(ob==0) return;
+       int flag;
+       char str[128];
+
+       rad= G.scene->radio;
+       if(rad==0) {
+               add_radio();
+               rad= G.scene->radio;
+       }
        
        sprintf(str, "buttonswin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
 
-       /* LAYERS */
-       xco= 291;
-       dx= 32;
-       dy= 30;
-       for(a=0; a<10; a++) {
-               /* the (a+10) evaluates correctly because of
-           precedence... brackets aren't a bad idea though */
-               uiDefButI(block, TOG|BIT|(a+10), B_OBLAY+a+10, "",      (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
-               uiDefButI(block, TOG|BIT|a, B_OBLAY+a, "",(short)(xco+a*(dx/2)), (short)(180+dy/2), (short)(dx/2), (short)(1+dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
-               if(a==4) xco+= 5;
-       }
-
-       id= ob->data;
-       if(id && id->lib) uiSetButLock(1, "Can't edit library data");
-
-       uiBlockSetCol(block, BUTGREY);
-       uiDefBut(block, LABEL, 0, "Drawtype",                                           28,200,100,18, 0, 0, 0, 0, 0, "");
-       uiDefButC(block, MENU, REDRAWVIEW3D, "Drawtype%t|Bounds %x1|Wire %x2|Solid %x3|Shaded %x4",     
-                                                                                                                               28,180,100,18, &ob->dt, 0, 0, 0, 0, "Sets the drawing type of the active object");
-       uiDefBut(block, LABEL, 0, "Draw Extra",                                         28,160,100,18, 0, 0, 0, 0, 0, "");
-       uiDefButC(block, TOG|BIT|0, REDRAWVIEW3D, "Bounds",             28, 140, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
-       uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder",
-                                                                                                                               28, 120, 100, 18, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
-       uiDefButC(block, TOG|BIT|5, REDRAWVIEW3D, "Wire",               28, 100, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's wireframe in shaded drawing modes");
-       uiDefButC(block, TOG|BIT|1, REDRAWVIEW3D, "Axis",               28, 80, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's centre and axis");
-       uiDefButC(block, TOG|BIT|2, REDRAWVIEW3D, "TexSpace",   28, 60, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
-       uiDefButC(block, TOG|BIT|3, REDRAWVIEW3D, "Name",               28, 40, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
-       
-       uiBlockSetCol(block, BUTGREY);
-       
-       /* material and select swap and hide */
-       if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
-               
-                       if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
-                       else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
-                       else poin= &( ((Curve *)ob->data)->texflag );
-                       uiDefButI(block, TOG|BIT|0, B_AUTOTEX, "AutoTexSpace",  143,180,130,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
+       flag= rad_phase();
 
-               sprintf(str,"%d Mat:", ob->totcol);
-               if(ob->totcol) min= 1.0; else min= 0.0;
-               ma= give_current_material(ob, ob->actcol);
-               
-               if(ma) {
-                       uiDefButF(block, COL, 0, "",                    291,123,24,30, &(ma->r), 0, 0, 0, 0, "");
-                       uiDefBut(block, LABEL, 0, ma->id.name+2, 318,146, 103, 30, 0, 0, 0, 0, 0, "");
-               }
-               uiDefButC(block, NUM, B_REDR,   str,            318,123,103,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index");
-               uiDefBut(block, BUT,B_MATWICH,  "?",            423,123,31,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
-               
+       if(flag & RAD_PHASE_PATCHES) {
                uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT,B_MATNEW,   "New",          292,101,80,21, 0, 0, 0, 0, 0, "Adds a new Material index");
-               uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,101,80,21, 0, 0, 0, 0, 0, "Deletes this Material index");
-               uiDefBut(block, BUT,B_MATASS,   "Assign",       291,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
+               uiDefBut(block,  BUT, B_RAD_INIT, "Limit Subdivide",    10, 70, 190, 40, NULL, 0, 0, 0, 0, "Subdivide patches");
+       }
+       if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTPURPLE);
+       else uiBlockSetCol(block, BUTSALMON);
+       uiDefBut(block,  BUT, B_RAD_COLLECT, "Collect Meshes",  10, 30, 190, 40, NULL, 0, 0, 0, 0, "Convert selected and visible meshes to patches");
+       uiDrawBlock(block);
 
+       if(flag==0) {
+       
+               sprintf(str, "buttonswin1 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
                uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,79,22, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
-               uiDefBut(block, BUT,B_MATDESEL, "Deselect",     373,76,79,21, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
-               
-               if(ob->type!=OB_FONT) {
-                       uiDefBut(block, BUT,B_HIDE,             "Hide",         1091,152,77,18, 0, 0, 0, 0, 0, "Hides selected faces");
-                       uiDefBut(block, BUT,B_REVEAL,   "Reveal",       1171,152,86,18, 0, 0, 0, 0, 0, "Reveals selected faces");
-                       uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  1091,129,166,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
-               }
-               uiDefBut(block, BUT,B_SETSMOOTH,        "Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
-               uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
-
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",        0, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
+               uiDefButS(block,  NUM, 0, "Max Iterations:",            1, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
+               uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      2, 0, 50, 10, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
+               uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     2, 0, 50, 10, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
+               uiDefButF(block,  NUM, 0, "Convergence:",                       3, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
+               uiDrawBlock(block);
        }
+       else {
        
-       if ELEM3(ob->type, OB_MESH, OB_SURF, OB_CURVE) {
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT,B_DOCENTRE, "Centre",                               961, 115, 100, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
-               uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        961, 95, 100, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
-               uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          961, 75, 100, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
-       }
-
        
-       uiDrawBlock(block);
+               sprintf(str, "buttonswin1 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
+               
+               uiBlockSetCol(block, BUTGREEN);
+               uiDefButS(block,  ROW, B_RAD_DRAW, "Wire",                      0, 0, 10, 10, &rad->drawtype, 0.0, 0.0, 0, 0, "Enable wireframe drawmode");
+               uiDefButS(block,  ROW, B_RAD_DRAW, "Solid",                     0, 0, 10, 10, &rad->drawtype, 0.0, 1.0, 0, 0, "Enable solid drawmode");
+               uiDefButS(block,  ROW, B_RAD_DRAW, "Gour",                      0, 0, 10, 10, &rad->drawtype, 0.0, 2.0, 0, 0, "Enable Gourad drawmode");
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block,  TOG|BIT|0, B_RAD_DRAW, "ShowLim",  1, 0, 10, 10, &rad->flag, 0, 0, 0, 0, "Visualize patch and element limits");
+               uiDefButS(block,  TOG|BIT|1, B_RAD_DRAW, "Z",           1, 0, 3, 10, &rad->flag, 0, 0, 0, 0, "Draw limits different");
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMax:",          2, 0, 10, 10, &rad->elma, 1.0, 500.0, 0, 0, "Set maximum size of an element");
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMin:",          2, 0, 10, 10, &rad->elmi, 1.0, 100.0, 0, 0, "Set minimum size of an element");
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMax:",          3, 0, 10, 10, &rad->pama, 10.0, 1000.0, 0, 0, "Set maximum size of a patch");
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMin:",          3, 0, 10, 10, &rad->pami, 10.0, 1000.0, 0, 0, "Set minimum size of a patch");
+               uiDrawBlock(block);
+               
+               sprintf(str, "buttonswin2 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 450, 30, 180, 150, UI_BLOCK_ROWS);
+               
+               if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_SHOOTE, "Subdiv Shoot Element", 0, 0, 12, 10, NULL, 0, 0, 0, 0, "");
+               uiDefBut(block,  BUT, B_RAD_SHOOTP, "Subdiv Shoot Patch",       1, 0, 12, 10, NULL, 0, 0, 0, 0, "Detect high energy changes");
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block,  NUM, 0, "Max Subdiv Shoot:",                  2, 0, 10, 10, &rad->maxsublamp, 1.0, 250.0, 0, 0, "Set the maximum number of shoot patches that are evaluated");
+               uiDefButI(block,  NUM, 0, "MaxEl:",                                             3, 0, 10, 10, &rad->maxnode, 1.0, 250000.0, 0, 0, "Set the maximum allowed number of elements");
+               uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",                4, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
+               uiDrawBlock(block);
+               
+               sprintf(str, "buttonswin3 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 640, 30, 200, 150, UI_BLOCK_ROWS);
+               
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block,  NUM, 0, "Max Iterations:",    0, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
+               uiDefButF(block,  NUM, 0, "Convergence:",               1, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
+               uiDefButS(block,  NUM, 0, "SubSh P:",                   2, 0, 10, 10, &rad->subshootp, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect pathes");
+               uiDefButS(block,  NUM, 0, "SubSh E:",                   2, 0, 10, 10, &rad->subshoote, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect elements");
+               if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
+               uiDefBut(block,  BUT, B_RAD_GO, "GO",                           3, 0, 10, 15, NULL, 0, 0, 0, 0, "Start the radiosity simulation");
+               uiDrawBlock(block);
+               
+               sprintf(str, "buttonswin4 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 850, 30, 200, 150, UI_BLOCK_ROWS);
+       
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      0, 0, 50, 17, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
+               uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     0, 0, 50, 17, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
+               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_FACEFILT, "FaceFilter",             1, 0, 10, 10, NULL, 0, 0, 0, 0, "Force an extra smoothing");
+               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_NODELIM, "RemoveDoubles",   2, 0, 30, 10, NULL, 0.0, 50.0, 0, 0, "Join elements which differ less than 'Lim'");
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block,  NUM, 0, "Lim:",                                       2, 0, 10, 10, &rad->nodelim, 0.0, 50.0, 0, 0, "Set the range for removing doubles");
+               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_NODEFILT, "Element Filter", 3, 0, 10, 10, NULL, 0, 0, 0, 0, "Filter elements to remove aliasing artefacts");
+               uiDrawBlock(block);
        
+               sprintf(str, "buttonswin5 %d", curarea->win);
+               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiAutoBlock(block, 1060, 30, 190, 150, UI_BLOCK_ROWS);
+       
+               if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_FREE, "Free Radio Data",    0, 0, 10, 10, NULL, 0, 0, 0, 0, "Release all memory used by Radiosity");        
+               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
+               else uiBlockSetCol(block, BUTGREY);
+               uiDefBut(block,  BUT, B_RAD_REPLACE, "Replace Meshes",  1, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, changing input-meshes");
+               uiDefBut(block,  BUT, B_RAD_ADDMESH, "Add new Meshes",  2, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, unchanging input-meshes");
+               uiDrawBlock(block);
+               
+               rad_status_str(str);
+               cpack(0);
+               glRasterPos2i(210, 189);
+               BMF_DrawString(uiBlockGetCurFont(block), str);
+       }
 }
 
 
 
-/* *************************** MESH ******************************** */
-
-#ifdef NAN_DECIMATION
+/* *************************** SCRIPT ******************************** */
 
-static int decimate_count_tria(Object *ob)
+static void extend_scriptlink(ScriptLink *slink)
 {
-       int tottria;
-       MFace *mface;
-       Mesh *me;
-       int a;
+       void *stmp, *ftmp;
+
+       if (!slink) return;
+               
+       stmp= slink->scripts;           
+       slink->scripts= MEM_mallocN(sizeof(ID*)*(slink->totscript+1), "scriptlistL");
        
-       me= ob->data;
+       ftmp= slink->flag;              
+       slink->flag= MEM_mallocN(sizeof(short*)*(slink->totscript+1), "scriptlistF");
        
-       /* count number of trias, since decimator doesnt allow quads */
-       tottria= 0;
-       mface= me->mface;
-       for(a=0; a<me->totface; a++, mface++) {
-               if(mface->v4) tottria++;
-               if(mface->v3) tottria++;                
+       if (slink->totscript) {
+               memcpy(slink->scripts, stmp, sizeof(ID*)*(slink->totscript));
+               MEM_freeN(stmp);
+
+               memcpy(slink->flag, ftmp, sizeof(short)*(slink->totscript));
+               MEM_freeN(ftmp);
        }
-       
-       return tottria;
+
+       slink->scripts[slink->totscript]= NULL;
+       slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
+
+       slink->totscript++;
+                               
+       if(slink->actscript<1) slink->actscript=1;
 }
 
-static void decimate_faces(void)
+static void delete_scriptlink(ScriptLink *slink)
 {
-       Object *ob;
-       Mesh *me;
-       MVert *mvert;
-       MFace *mface;
-       LOD_Decimation_Info lod; 
-       float *vb=NULL;
-       float *vnb=NULL;
-       int *tib=NULL;
-       int a, tottria;
-       
-       /* we assume the active object being decimated */
-       ob= OBACT;
-       if(ob==NULL || ob->type!=OB_MESH) return;
-       me= ob->data;
-
-       /* add warning for vertex col and tfaces */
-       if(me->tface || me->mcol) {
-               if(okee("This will remove UV coordinates and vertexcolors")==0) return;
-               if(me->tface) MEM_freeN(me->tface);
-               if(me->mcol) MEM_freeN(me->mcol);
-               me->tface= NULL;
-               me->mcol= NULL;
-       }
+       int i;
        
-       /* count number of trias, since decimator doesnt allow quads */
-       tottria= decimate_count_tria(ob);
-
-       if(tottria<3) {
-               error("You must have more than 3 input faces selected.");
-               return;
+       if (!slink) return;
+       
+       if (slink->totscript>0) {
+               for (i=slink->actscript-1; i<slink->totscript-1; i++) {
+                       slink->flag[i]= slink->flag[i+1];
+                       slink->scripts[i]= slink->scripts[i+1];
+               }
+               
+               slink->totscript--;
        }
-       /* allocate and init */
-       lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "vertices");
-       lod.vertex_normal_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "normals");
-       lod.triangle_index_buffer= MEM_mallocN(3*sizeof(int)*tottria, "trias");
-       lod.vertex_num= me->totvert;
-       lod.face_num= tottria;
-       
-       /* fill vertex buffer */
-       vb= lod.vertex_buffer;
-       vnb= lod.vertex_normal_buffer;
-       mvert= me->mvert;
-       for(a=0; a<me->totvert; a++, mvert++, vb+=3, vnb+=3) {
-               VECCOPY(vb, mvert->co);
-               VECCOPY(vnb, mvert->no);
-               Normalise(vnb);
+               
+       CLAMP(slink->actscript, 1, slink->totscript);
+               
+       if (slink->totscript==0) {
+               if (slink->scripts) MEM_freeN(slink->scripts);
+               if (slink->flag) MEM_freeN(slink->flag);
+
+               slink->scripts= NULL;
+               slink->flag= NULL;
+               slink->totscript= slink->actscript= 0;                  
        }
+}
+
+void do_scriptbuts(short event)
+{
+       Object *ob=NULL;
+       ScriptLink *script=NULL;
+       Material *ma;
        
-       /* fill index buffer */
-       mface= me->mface;
-       tib= lod.triangle_index_buffer;
-       for(a=0; a<me->totface; a++, mface++) {
-               if(mface->v4) {
-                       tib[0]= mface->v1;
-                       tib[1]= mface->v3;
-                       tib[2]= mface->v4;
-                       tib+= 3;
-               }
-               if(mface->v3) {
-                       tib[0]= mface->v1;
-                       tib[1]= mface->v2;
-                       tib[2]= mface->v3;
-                       tib+= 3;
+       switch (event) {
+       case B_SSCRIPT_ADD:
+               extend_scriptlink(&G.scene->scriptlink);
+               break;
+       case B_SSCRIPT_DEL:
+               delete_scriptlink(&G.scene->scriptlink);
+               break;
+               
+       case B_SCRIPT_ADD:
+       case B_SCRIPT_DEL:
+               ob= OBACT;
+
+               if (ob && G.buts->scriptblock==ID_OB) {
+                               script= &ob->scriptlink;
+
+               } else if (ob && G.buts->scriptblock==ID_MA) {
+                       ma= give_current_material(ob, ob->actcol);
+                       if (ma) script= &ma->scriptlink;
+
+               } else if (ob && G.buts->scriptblock==ID_CA) {
+                       if (ob->type==OB_CAMERA)
+                               script= &((Camera *)ob->data)->scriptlink;
+
+               } else if (ob && G.buts->scriptblock==ID_LA) {
+                       if (ob->type==OB_LAMP)
+                               script= &((Lamp *)ob->data)->scriptlink;
+
+               } else if (G.buts->scriptblock==ID_WO) {
+                       if (G.scene->world) 
+                               script= &(G.scene->world->scriptlink);
                }
+               
+               if (event==B_SCRIPT_ADD) extend_scriptlink(script);
+               else delete_scriptlink(script);
+               
+               break;
+       default:
+               break;
        }
 
-       if(LOD_LoadMesh(&lod) ) {
-               if( LOD_PreprocessMesh(&lod) ) {
-                       DispList *dl;
-                       DispListMesh *dlm;
-                       MFaceInt *mfaceint;
-                       
-                       /* we assume the decim_faces tells how much to reduce */
-                       
-                       while(lod.face_num > decim_faces) {
-                               if( LOD_CollapseEdge(&lod)==0) break;
-                       }
+       allqueue(REDRAWBUTSSCRIPT, 0);
+}
 
-                       /* ok, put back the stuff in a displist */
-                       freedisplist(&(ob->disp));
-                       dl= MEM_callocN(sizeof(DispList), "disp");
-                       BLI_addtail(&ob->disp, dl);
-                       dl->type= DL_MESH;
-                       dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
-                       dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
-                       dlm->mface= MEM_callocN(lod.face_num*sizeof(MFaceInt), "mface");
-                       dlm->totvert= lod.vertex_num;
-                       dlm->totface= lod.face_num;
-                       
-                       mvert= dlm->mvert;
-                       vb= lod.vertex_buffer;
-                       for(a=0; a<lod.vertex_num; a++, vb+=3, mvert++) {
-                               VECCOPY(mvert->co, vb);
-                       }
-                       
-                       mfaceint= dlm->mface;
-                       tib= lod.triangle_index_buffer;
-                       for(a=0; a<lod.face_num; a++, mfaceint++, tib+=3) {
-                               mfaceint->v1= tib[0];
-                               mfaceint->v2= tib[1];
-                               mfaceint->v3= tib[2];
-                       }
+void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int scene) 
+{
+       char str[256];
+
+       uiBlockSetCol(block, BUTGREY);
+
+       if (script->totscript) {
+               strcpy(str, "FrameChanged%x 1|");
+               strcat(str, "Redraw%x 4|");
+               if (scene) {
+                       strcat(str, "OnLoad%x 2");
                }
-               else error("No memory");
 
-               LOD_FreeDecimationData(&lod);
+               uiDefButS(block, MENU, 1, str, (short)sx, (short)sy, 148, 19, &script->flag[script->actscript-1], 0, 0, 0, 0, "Script links for the Frame changed event");
+
+               uiDefIDPoinBut(block, test_scriptpoin_but, 1, "", (short)(sx+150),(short)sy, 98, 19, &script->scripts[script->actscript-1], "Name of Script to link");
        }
-       else error("No manifold Mesh");
-       
-       MEM_freeN(lod.vertex_buffer);
-       MEM_freeN(lod.vertex_normal_buffer);
-       MEM_freeN(lod.triangle_index_buffer);
-       
-       allqueue(REDRAWVIEW3D, 0);
-}
 
+       sprintf(str,"%d Scr:", script->totscript);
+       uiDefButS(block, NUM, REDRAWBUTSSCRIPT, str, (short)(sx+250), (short)sy,98,19, &script->actscript, 1, script->totscript, 0, 0, "Total / Active Script link (LeftMouse + Drag to change)");
 
+       uiBlockSetCol(block, BUTSALMON);
 
-static void decimate_cancel(void)
-{
-       Object *ob;
-       
-       ob= OBACT;
-       if(ob) {
-               freedisplist(&ob->disp);
-               makeDispList(ob);
-       }
-       allqueue(REDRAWVIEW3D, 0);
+       if (scene) {
+               if (script->totscript<32767) 
+                       uiDefBut(block, BUT, B_SSCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
+               if (script->totscript) 
+                       uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
+       } else {
+               if (script->totscript<32767) 
+                       uiDefBut(block, BUT, B_SCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
+               if (script->totscript) 
+                       uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
+       }               
 }
 
-static void decimate_apply(void)
+void scriptbuts(void)
 {
-       Object *ob;
-       DispList *dl;
-       DispListMesh *dlm;
-       Mesh *me;
-       MFace *mface;
-       MFaceInt *mfaceint;
-       int a;
-       
-       if(G.obedit) return;
+       Object *ob=NULL;
+       ScriptLink *script=NULL;
+       Material *ma;
+       uiBlock *block;
+       char str[64];
        
        ob= OBACT;
-       if(ob) {
-               dl= ob->disp.first;
-               if(dl && dl->mesh) {
-                       dlm= dl->mesh;
-                       me= ob->data;
-                       
-                       // vertices 
-                       if(me->mvert) MEM_freeN(me->mvert);
-                       me->mvert= dlm->mvert;
-                       dlm->mvert= NULL;
-                       me->totvert= dlm->totvert;
-                       
-                       // faces
-                       if(me->mface) MEM_freeN(me->mface);
-                       me->mface= MEM_callocN(dlm->totface*sizeof(MFace), "mface");
-                       me->totface= dlm->totface;
-                       mface= me->mface;
-                       mfaceint= dlm->mface;
-                       for(a=0; a<me->totface; a++, mface++, mfaceint++) {
-                               mface->v1= mfaceint->v1;
-                               mface->v2= mfaceint->v2;
-                               mface->v3= mfaceint->v3;
-                               test_index_mface(mface, 3);
-                       }
-                       
-                       freedisplist(&ob->disp);
-                       
-                       G.obedit= ob;
-                       make_editMesh();
-                       load_editMesh();
-                       free_editMesh();
-                       G.obedit= NULL;
-                       tex_space_mesh(me);
-               }
-               else error("Not a decimated Mesh");
-       }
-}
-
-#endif
 
-void do_meshbuts(unsigned short event)
-{
-       Object *ob;
-       Mesh *me;
-       float fac;
-       short randfac;
+       sprintf(str, "buttonswin %d", curarea->win);
+       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
 
-       ob= OBACT;
-       if(ob && ob->type==OB_MESH) {
+       if (ob && G.buts->scriptblock==ID_OB) {
+               script= &ob->scriptlink;
                
-               me= get_mesh(ob);
-               if(me==0) return;
+       } else if (ob && G.buts->scriptblock==ID_MA) {
+               ma= give_current_material(ob, ob->actcol);
+               if (ma) script= &ma->scriptlink;
                
-               switch(event) {
-#ifdef __NLA
-               case B_AUTOVGROUP:
-                       if (!get_armature(ob->parent)){
-                               error ("Mesh must be the child of an armature");
-                               break;
-                       }
-                               /* Verify that there are vertex groups for bones in armature */
-                               /* Remove selected vertices from all defgroups */
-                               /* Perform assignment for selected vertices */
+       } else if (ob && G.buts->scriptblock==ID_CA) {
+               if (ob->type==OB_CAMERA)
+                       script= &((Camera *)ob->data)->scriptlink;
+                       
+       } else if (ob && G.buts->scriptblock==ID_LA) {
+               if (ob->type==OB_LAMP)
+                       script= &((Lamp *)ob->data)->scriptlink;
 
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-               case B_NEWVGROUP:
-                       add_defgroup (G.obedit);
-                       scrarea_queue_winredraw(curarea);
-                       break;
-               case B_DELVGROUP:
-                       del_defgroup (G.obedit);
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-               case B_ASSIGNVGROUP:
-                       assign_verts_defgroup ();
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-               case B_REMOVEVGROUP:
-                       remove_verts_defgroup (0);
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-               case B_SELVGROUP:
-                       sel_verts_defgroup(1);
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-               case B_DESELVGROUP:
-                       sel_verts_defgroup(0);
-                       allqueue (REDRAWVIEW3D, 1);
-                       break;
-#endif
-               case B_DELSTICKY:
-               
-                       if(me->msticky) MEM_freeN(me->msticky);
-                       me->msticky= 0;
-                       allqueue(REDRAWBUTSEDIT, 0);
-                       break;
-               case B_MAKESTICKY:
-                       make_sticky();
-                       break;
-               case B_MAKEVERTCOL:
-                       make_vertexcol();
-                       break;
-               case B_DELVERTCOL:
-                       if(me->mcol) MEM_freeN(me->mcol);
-                       me->mcol= 0;
-                       G.f &= ~G_VERTEXPAINT;
-                       freedisplist(&(ob->disp));
-                       allqueue(REDRAWBUTSEDIT, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-                       break;
+       } else if (G.buts->scriptblock==ID_WO) {
+               if (G.scene->world)
+                       script= &(G.scene->world->scriptlink);
+       }
 
-               case B_MAKE_TFACES:
-                       make_tfaces(me);
-                       allqueue(REDRAWBUTSEDIT, 0);
-                       break;
+       if (script) draw_scriptlink(block, script, 25, 180, 0);                 
+       
+       /* EVENTS */
+       draw_buttons_edge(curarea->win, 540);
 
-               case B_DEL_TFACES:
-                       if(me->tface) MEM_freeN(me->tface);
-                       me->tface= 0;
-                       G.f &= ~G_FACESELECT;
-                       allqueue(REDRAWBUTSEDIT, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWIMAGE, 0);
-                       break;
-                       
-               case B_FLIPNORM:
-                       if(G.obedit) {
-                               flip_editnormals();
-                       }
-                       else flipnorm_mesh( get_mesh(ob) );
-                       
-                       allqueue(REDRAWVIEW3D, 0);
-                       break;
+       draw_scriptlink(block, &G.scene->scriptlink, 600, 180, 1);
 
-               case B_DECIM_FACES:
-                       decimate_faces();
-                       break;
-               case B_DECIM_CANCEL:
-                       decimate_cancel();
-                       break;
-               case B_DECIM_APPLY:
-                       decimate_apply();
-                       break;
+       uiDrawBlock(block);
+}
 
-               case B_SLOWERDRAW:
-                       slowerdraw();
-                       break;
-               case B_FASTERDRAW:
-                       fasterdraw();
-                       break;
-               }
-       }
+/* *************************** IKA ******************************** */
+/* is this number used elsewhere? */
+/*  static int ika_del_number; */
+void do_ikabuts(unsigned short event)
+{
+       Base *base;
+       Object *ob;
        
-       if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
+       ob= OBACT;
        
        switch(event) {
-       case B_SPIN:
-               if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
-               break;
-       case B_SPINDUP:
-               if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
-               break;
-       case B_EXTR:
-               G.f |= G_DISABLE_OK;
-               if( select_area(SPACE_VIEW3D)) extrude_mesh();
-               G.f -= G_DISABLE_OK;
-               break;
-       case B_SCREW:
-               if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
-               break;
-       case B_EXTREP:
-               if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
-               break;
-       case B_SPLIT:
-               G.f |= G_DISABLE_OK;
-               split_mesh();
-               G.f -= G_DISABLE_OK;
-               break;
-       case B_REMDOUB:
-               notice("Removed: %d", removedoublesflag(1, doublimit));
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_SUBDIV:
-               waitcursor(1);
-               subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
-               countall();
-               waitcursor(0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_FRACSUBDIV:
-               randfac= 10;
-               if(button(&randfac, 1, 100, "Rand fac:")==0) return;
-               waitcursor(1);
-               fac= -( (float)randfac )/100;
-               subdivideflag(1, fac, editbutflag & B_BEAUTY);
-               countall();
-               waitcursor(0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_XSORT:
-               if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
-               break;
-       case B_HASH:
-               hashvert_flag(1);
-               break;
-       case B_TOSPHERE:
-               vertices_to_sphere();
-               break;
-       case B_VERTEXNOISE:
-               vertexnoise();
-               break;
-       case B_VERTEXSMOOTH:
-               vertexsmooth();
+       case B_IKASETREF:
+               base= FIRSTBASE;
+               while(base) {
+                       if TESTBASELIB(base) {
+                               if(base->object->type==OB_IKA) init_defstate_ika(base->object);
+                       }
+                       base= base->next;
+               }
+               break;  
+       case B_IKARECALC:
+               itterate_ika(ob);
                break;
        }
-       /* WATCH IT: previous events only in editmode! */
-}
-
-static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
-{
-       unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
 }
 
-void meshbuts(void)
+void ikabuts(void)
 {
+       Ika *ika;
        Object *ob;
-       Mesh *me;
+       Limb *li;
+       Deform *def;
        uiBlock *block;
-       uiBut *but;
-       float val;
-       char str[64];
-#ifdef __NLA
-       int by;
-       float   min;
-       int     defCount;
-       bDeformGroup    *defGroup;
-#endif
-
+       int nr, cury, nlimbs;
+       char str[32];
+       
        ob= OBACT;
        if(ob==0) return;
-       
+
        sprintf(str, "editbuttonswin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
 
-       me= get_mesh(ob);
-       
-       if(me) {
-               uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "No V.Normal Flip",   143,160,130,18, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render");
-               uiBlockSetCol(block, BUTGREEN);
-               uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Auto Smooth",        143,140,130,18, &me->flag, 0, 0, 0, 0, "Treats all faces with angles less than Degr: as 'smooth' during render");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, NUM, B_DIFF, "Degr:",                                                  143, 120, 130, 18, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
-               uiBlockSetCol(block, BUTGREEN);
-               uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      143,100,130,18, &me->flag, 0, 0, 0, 0, "Treats the active object as a Catmull-Clark Subdivision Surface");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",                    143, 80, 100, 18, &me->subdiv, 0, 12, 0, 0, "Defines the level of subdivision to display in real time interactively");
-               uiDefButS(block, NUM, B_MAKEDISP, "",                           243, 80, 30, 18, &me->subdivr, 0, 12, 0, 0, "Defines the level of subdivision to apply during rendering");
-               uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       1090,184,164,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
-               
-               uiBlockSetCol(block, BUTSALMON);
-               
-               if(me->msticky) val= 1.0; else val= 0.0;
-               uiDefBut(block, LABEL, 0, "Sticky", 137,55,70,20, 0, val, 0, 0, 0, "");
-               if(me->msticky==0) {
-                       uiDefBut(block, BUT, B_MAKESTICKY, "Make",      210,58,63,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active object from the current camera view background picture");
-               }
-               else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 210,58,63,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
-       
-               if(me->mcol) val= 1.0; else val= 0.0;
-               uiDefBut(block, LABEL, 0, "VertCol", 140,33,70,20, 0, val, 0, 0, 0, "");
-               if(me->mcol==0) {
-                       uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",     209,36,64,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active object");
-               }
-               else uiDefBut(block, BUT, B_DELVERTCOL, "Delete", 209,36,64,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active object");
-
-                       if(me->tface) val= 1.0; else val= 0.0;
-                       uiDefBut(block, LABEL, 0, "TexFace", 142,13,70,20, 0, val, 0, 0, 0, "");
-                       if(me->tface==0) {
-                               uiDefBut(block, BUT, B_MAKE_TFACES, "Make",     209,14,64,20, 0, 0, 0, 0, 0, "Enables the active object's faces for UV coordinate mapping");
-                       }
-                       else uiDefBut(block, BUT, B_DEL_TFACES, "Delete", 209,14,64,20, 0, 0, 0, 0, 0, "Deletes UV coordinates for active object's faces");
-               
-               uiBlockSetCol(block, BUTGREY);
-       
-               uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh: ",                477,185,249,19, &me->texcomesh, "Enter the name of a Meshblock");
-       }               
-       
-
-       /* EDIT */
-               
-       if(me) {
-#ifdef NAN_DECIMATION
-               int tottria= decimate_count_tria(ob);
-               DispList *dl;
-
-               // wacko, wait for new displist system (ton)
-               if( (dl=ob->disp.first) && dl->mesh);
-               else decim_faces= tottria;
-
-               uiBlockSetCol(block, BUTPURPLE);
-               uiDefButI(block, NUMSLI,B_DECIM_FACES, "Decimator: ",   477,155,249,20, &decim_faces, 4.0, tottria, 10, 10, "Defines the number of triangular faces to decimate the active Mesh object to");
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   477,135,124,19, 0, 0, 0, 0, 0, "Restores the Mesh to its original number of faces");
-               uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             602,135,124,19, 0, 0, 0, 0, 0, "Applies the decimation to the active Mesh object");
-#endif
-       
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT,B_EXTR,"Extrude",   477,100,249,24, 0, 0, 0, 0, 0, "Converts selected edges to faces and selects the new vertices");
-               uiDefBut(block, BUT,B_SPINDUP,"Spin Dupe",      639,75,87,24, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a circle around the cursor in the indicated viewport");
-               uiDefBut(block, BUT,B_SPIN, "Spin",             558,75,78,24, 0, 0, 0, 0, 0, "Extrudes the selected vertices in a circle around the cursor in the indicated viewport");
-               uiDefBut(block, BUT,B_SCREW,"Screw",            477,75,79,24, 0, 0, 0, 0, 0, "Activates the screw tool");  // Bish - This could use some more definition
-               uiDefBut(block, BUT,B_EXTREP, "Extrude Dupe",477,15,128,19, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a straight line away from the current viewport");
+       ika= ob->data;
        
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, NUM, B_DIFF, "Degr:",          477,55,78,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
-               uiDefButS(block, NUM, B_DIFF, "Steps:",         558,55,78,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
-               uiDefButS(block, NUM, B_DIFF, "Turns:",         639,55,86,19, &turn,1.0,360.0, 0, 0, "Specifies the number of revolutions the screw turns");
-               uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        639,35,86,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
-               uiDefButS(block, TOG|BIT|1, B_DIFF, "Keep Original",    477,35,156,19, &editbutflag, 0, 0, 0, 0, "Keeps a copy of the original vertices and faces after executing tools");
-               uiDefButF(block, NUM, B_DIFF, "Offset:",                608,15,117,19, &extr_offs, 0.01, 10.0, 100, 0, "Sets the distance between each copy for 'Extrude Dupe'");
-       }
-
-       by=206;
-
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, TOG|BIT|2, 0, "Beauty",        847,by-=20,94,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters");
        uiBlockSetCol(block, BUTSALMON);
+       uiDefBut(block, BUT, B_IKASETREF,       "Set Reference",470,180,200,20, 0, 0, 0, 0, 0, "");
 
-       uiDefBut(block, BUT,B_SPLIT,"Split",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Separates selected faces from unselected faces");
-       uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",     847,by-=19,94,18, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
-       uiDefBut(block, BUT,B_SUBDIV,"Subdivide",       847,by-=19,94,18, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
-       uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd",847,by-=19,94,18, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
-       
-       uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",                              847,by-=19,94,18, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
-       uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",                            847,by-=19,94,18, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
-       uiDefBut(block, BUT,B_XSORT,"Xsort",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
-       uiDefBut(block, BUT,B_HASH,"Hash",                      847,by-=19,94,18, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
-
+       uiBlockSetCol(block, BUTGREEN);
+       uiDefButS(block, TOG|BIT|1, B_DIFF, "Lock XY Plane",    470,140,200,20, &ika->flag, 0.0, 1.0, 0, 0, "New IK option: allows both X and Y axes to rotate");
        uiBlockSetCol(block, BUTGREY);
-       uiDefButF(block, NUM, B_DIFF, "Limit:",                 959,151,100,19, &doublimit, 0.0001, 1.0, 10, 0, "Specifies the max distance 'Rem Doubles' will consider vertices as 'doubled'");
+       uiDefButF(block, NUM, B_DIFF, "XY constraint ",         470,120,200,20, &ika->xyconstraint, 0.0, 1.0, 100, 0, "Constrain in radians");
 
-       uiBlockSetCol(block, BUTSALMON);
-       
-       uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    958,173,101,32, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
+       uiDefButF(block, NUMSLI, B_DIFF, "Mem ",                                470,80,200,20, &ika->mem, 0.0, 1.0, 0, 0, "");
+       uiDefButS(block, NUM, B_DIFF, "Iter: ",                         470,60,200,20, &ika->iter, 2.0, 16.0, 0, 0, "");
 
-       uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",          961,55,100,19, 0, 0, 0, 0, 0, "Toggles the direction of the selected face's normals");
 
-       uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 961,35,100,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
-       uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 961,15,100,19, 0, 0, 0, 0, 0, "Displays the active object faster by omitting some edges when drawing");
+       uiBlockSetCol(block, BUTGREY);
 
-#ifdef __NLA
-               
-               /* Draw Vertex grouping buttons if we're in editmode*/
-       if (ob){
-               char *s, *menustr;
-               bDeformGroup *dg;
-               int index;
-               
-               by = 210;
-               uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block, LABEL,0,"Vertex Groups",                        740,by-=19,93,18, 0, 0, 0, 0, 0, "");
+       uiDefBut(block, LABEL, 0, "Limb Weight",                        680, 200, 150, 19, 0, 0, 0, 0, 0, "");
+       cury= 180;
+       li= ika->limbbase.first;
 
-               defCount=BLI_countlist(&ob->defbase);
+       nlimbs= BLI_countlist(&ika->limbbase);
 
-               if (!defCount)
-                       min=0;
-               else
-                       min=1;
-                               
-#if 0
-               sprintf (str, "%d Group:", defCount);
-               uiDefButS(block, NUM, REDRAWBUTSEDIT, str,      740, by-=22,93,18, &ob->actdef, min, defCount, 0, 0, "");
-#else
-               s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
+       for (nr = 0; nr < nlimbs; nr++) {
+               sprintf(str, "Limb %d:", nr);
+               uiDefButF(block, NUM, B_DIFF, str, 680, (short)cury, 150, 19, &li->fac, 0.01, 1.0, 10, 0, "");
+               cury-= 20;
+               li= li->next;
+       }
 
-               for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next){
-                       int cnt= sprintf (s, "%s%%x%d|", dg->name, index);
-                       
-                       if (cnt>0)
-                               s+= cnt;
+       
+       
+       uiDefBut(block, LABEL, 0, "Deform Max Dist",    955, 200, 140, 19, 0, 0, 0, 0, 0, "");
+       uiDefBut(block, LABEL, 0, "Deform Weight",      1095, 200, 140, 19, 0, 0, 0, 0, 0, "");
+       
+
+       cury= 180;
+       def= ika->def;
+       for (nr = 0; nr < ika->totdef; nr++) {
+               def = ika->def+nr;
+               if(def->ob) {
+                       if(def->ob->type!=OB_IKA) sprintf(str, "%s   :", def->ob->id.name+2);
+                       else sprintf(str, "%s (%d):", def->ob->id.name+2, def->par1);
                }
                
-               by-=22;
-               if (defCount)
-                       uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr, 740, by,18,18, &ob->actdef, min, defCount, 0, 0, "Browses available vertex groups");
-               MEM_freeN (menustr);
-#endif
-               if (ob->actdef){
-                       defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
-                       but= uiDefBut(block, TEX,REDRAWBUTSEDIT,"",                     758,by,93-18,18, defGroup->name, 0, 32, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)");
-                       uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
-               }
-               uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          740, by-=22, 93, 18, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
+               uiDefBut(block, LABEL, 0, str,                  855, (short)cury, 100, 19, 0, 0.01, 0.0, 0, 0, "");
+               uiDefButF(block, NUM, B_DIFF, "",       955, (short)cury, 140, 19, &def->dist, 0.0, 40.0, 100, 0, "Beyond this distance the Limb doesn't influence deformation. '0.0' is global influence.");
+               uiDefButF(block, NUM, B_DIFF, "",       1095,(short)cury, 140, 19, &def->fac, 0.01, 10.0, 10, 0, "");
 
+               cury-= 20;
        }
-               
-       if (G.obedit && G.obedit==ob){
-
-               uiBlockSetCol(block, BUTSALMON);
-/*             uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
-               uiDefBut(block, BUT,B_NEWVGROUP,"New",                          740,by-=22,45,18, 0, 0, 0, 0, 0, "Creates a new vertex group");
-               uiDefBut(block, BUT,B_DELVGROUP,"Delete",                       788,by,45,18, 0, 0, 0, 0, 0, "Removes the current vertex group");
-
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
-               uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
-
-               uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block, BUT,B_SELVGROUP,"Select",                       740,by-=22,93,18, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
-               uiDefBut(block, BUT,B_DESELVGROUP,"Deselect",                   740,by-=22,93,18, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
-
+       uiDrawBlock(block);
 }
-#endif
 
-       uiBlockSetCol(block, BUTGREY);
-       uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 90, 164, 19, &editbutsize, 0.001, 2.0, 10, 0, "Sets the length to use when displaying face normals");
-       uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,70,164,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
-       uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 1090,50,164,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
-       uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges", 1090,30,164,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
-       uiDefButI(block, TOG|BIT|11, 0, "All edges",                            1090,10,164,19, &G.f, 0, 0, 0, 0, "Displays all edges in object mode without optimization");
+/* *************************** TEXTURE ******************************** */
 
-       uiDrawBlock(block);
-}
+Tex *cur_imatex=0;
+int prv_win= 0;
 
-// Bish made it to here. (reviewing tooltips)
+void load_tex_image(char *str) /* called from fileselect */
+{
+       Image *ima=0;
+       Tex *tex;
+       
+       tex= cur_imatex;
+       if(tex->type==TEX_IMAGE || tex->type==TEX_ENVMAP) {
 
+               ima= add_image(str);
+               if(ima) {
+                       if(tex->ima) {
+                               tex->ima->id.us--;
+                       }
+                       tex->ima= ima;
+
+                       free_image_buffers(ima);        /* force reading again */
+                       ima->ok= 1;
+               }
 
-/* *************************** FONT ******************************** */
+               allqueue(REDRAWBUTSTEX, 0);
 
-short give_vfontnr(VFont *vfont)
-{
-       VFont *vf;
-       short nr= 1;
-
-       vf= G.main->vfont.first;
-       while(vf) {
-               if(vf==vfont) return nr;
-               nr++;
-               vf= vf->id.next;
+               BIF_preview_changed(G.buts);
        }
-       return -1;
 }
 
-VFont *give_vfontpointer(int nr)       /* nr= button */
+void load_plugin_tex(char *str)        /* called from fileselect */
 {
-       VFont *vf;
-       short tel= 1;
-
-       vf= G.main->vfont.first;
-       while(vf) {
-               if(tel==nr) return vf;
-               tel++;
-               vf= vf->id.next;
-       }
-       return G.main->vfont.first;
+       Tex *tex;
+       
+       tex= cur_imatex;
+       if(tex->type!=TEX_PLUGIN) return;
+       
+       if(tex->plugin) free_plugin_tex(tex->plugin);
+       
+       tex->stype= 0;
+       tex->plugin= add_plugin_tex(str);
+
+       allqueue(REDRAWBUTSTEX, 0);
+       BIF_preview_changed(G.buts);
 }
 
-VFont *exist_vfont(char *str)
+int vergcband(const void *a1, const void *a2)
 {
-       VFont *vf;
+       const CBData *x1=a1, *x2=a2;
 
-       vf= G.main->vfont.first;
-       while(vf) {
-               if(strcmp(vf->name, str)==0) return vf;
-               vf= vf->id.next;
-       }
+       if( x1->pos > x2->pos ) return 1;
+       else if( x1->pos < x2->pos) return -1;
        return 0;
 }
 
-static char *give_vfontbutstr(void)
-{
-       VFont *vf;
-       int len= 0;
-       char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
-
-       vf= G.main->vfont.first;
-       while(vf) {
-               strcpy(di, vf->name);
-               BLI_splitdirstring(di, fi);
-               len+= strlen(fi)+4;
-               vf= vf->id.next;
-       }
-       
-       str= MEM_callocN(len+21, "vfontbutstr");
-       strcpy(str, "FONTS %t");
-       vf= G.main->vfont.first;
-       while(vf) {
-               
-               if(vf->id.us==0) strcat(str, "|0 ");
-               else strcat(str, "|   ");
-               
-               strcpy(di, vf->name);
-               BLI_splitdirstring(di, fi);
-               
-               strcat(str, fi);
-               vf= vf->id.next;
-       }
-       return str;
-}
 
-void load_buts_vfont(char *name)
+
+void save_env(char *name)
 {
-       VFont *vf;
-       Curve *cu;
+       Tex *tex;
+       char str[FILE_MAXFILE];
        
-       if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
-       else return;
+       strcpy(str, name);
+       BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
+       tex= G.buts->lockpoin;
        
-       vf= exist_vfont(name);
-       if(vf==0) {
-               vf= load_vfont(name);
-               if(vf==0) return;
-       }
-       else id_us_plus((ID *)vf);
-       
-       if(cu->vfont) cu->vfont->id.us--;
-       cu->vfont= vf;
-       
-       text_to_curve(OBACT, 0);
-       makeDispList(OBACT);
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWBUTSEDIT, 0);
-}
-
-void do_fontbuts(unsigned short event)
-{
-       Curve *cu;
-       VFont *vf;
-       Object *ob;
-       ScrArea *sa;
-       char str[80];
-       
-       ob= OBACT;
-       
-       switch(event) {
-       case B_MAKEFONT:
-               text_to_curve(ob, 0);
-               makeDispList(ob);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_TOUPPER:
-               to_upper();
-               break;
-       case B_LOADFONT:
-               vf= give_vfontpointer(G.buts->texnr);
-               if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
-               else strcpy(str, U.fontdir);
-               
-               sa= closest_bigger_area();
-               areawinset(sa->win);
-
-               activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
-
-               break;
-       case B_PACKFONT:
-               if (ob) {
-                       cu= ob->data;
-                       if(cu && cu->vfont) {
-                               if (cu->vfont->packedfile) {
-                                       if (G.fileflags & G_AUTOPACK) {
-                                               if (okee("Disable AutoPack ?")) {
-                                                       G.fileflags &= ~G_AUTOPACK;
-                                               }
-                                       }
-                                       
-                                       if ((G.fileflags & G_AUTOPACK) == 0) {
-                                               if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
-                                                       text_to_curve(ob, 0);
-                                                       makeDispList(ob);
-                                                       allqueue(REDRAWVIEW3D, 0);
-                                               }
-                                       }
-                               } else {
-                                       cu->vfont->packedfile = newPackedFile(cu->vfont->name);
-                               }
-                       }
-               }
-               allqueue(REDRAWHEADERS, 0);
-               allqueue(REDRAWBUTSEDIT, 0);
-               break;
-
-       case B_SETFONT:
-               if(ob) {
-                       cu= ob->data;
-
-                       vf= give_vfontpointer(G.buts->texnr);
-                       if(vf) {
-                               id_us_plus((ID *)vf);
-                               cu->vfont->id.us--;
-                               cu->vfont= vf;
-                               text_to_curve(ob, 0);
-                               makeDispList(ob);
-                               allqueue(REDRAWVIEW3D, 0);
-                               allqueue(REDRAWBUTSEDIT, 0);
-                       }
-               }       
-               break;
-       case B_TEXTONCURVE:
-               if(ob) {
-                       cu= ob->data;
-                       if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
-                               error("Only Curve Objects");
-                               cu->textoncurve= 0;
-                               allqueue(REDRAWBUTSEDIT, 0);
-                       }
-                       text_to_curve(ob, 0);
-                       makeDispList(ob);
+       if(tex && GS(tex->id.name)==ID_TE) {
+               if(tex->env && tex->env->ok && saveover(str)) {
+                       waitcursor(1);
+                       BIF_save_envmap(tex->env, str);
+                       strcpy(G.ima, name);
+                       waitcursor(0);
                }
        }
+       
 }
 
-
-
-void fontbuts(void)
+void drawcolorband(ColorBand *coba, float x1, float y1, float sizex, float sizey)
 {
-       Curve *cu;
-       uiBlock *block;
-       char *strp, str[64];
+       CBData *cbd;
+       float v3[2], v1[2], v2[2];
+       int a;
        
-       if(OBACT==0) return;
-
-       sprintf(str, "editbuttonswin1 %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-
-       cu= OBACT->data;
-
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, ROW,B_MAKEFONT, "Left",                484,139,53,18, &cu->spacemode, 0.0,0.0, 0, 0, "");
-       uiDefButS(block, ROW,B_MAKEFONT, "Middle",      604,139,61,18, &cu->spacemode, 0.0,1.0, 0, 0, "");
-       uiDefButS(block, ROW,B_MAKEFONT, "Right",               540,139,62,18, &cu->spacemode, 0.0,2.0, 0, 0, "");
-       uiDefButS(block, ROW,B_MAKEFONT, "Flush",               665,139,61,18, &cu->spacemode, 0.0,3.0, 0, 0, "");
-
-       uiBlockSetCol(block, BUTGREY);
-
-       uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   484,115,243,19, &cu->textoncurve, "");
-
-       uiDefButF(block, NUM,B_MAKEFONT, "Size:",               482,56,121,19, &cu->fsize, 0.1,10.0, 10, 0, "");
-       uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   605,56,121,19, &cu->linedist, 0.0,10.0, 10, 0, "");
-       uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    482,34,121,19, &cu->spacing, 0.0,10.0, 10, 0, "");
-       uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   605,34,121,19, &cu->yof, -50.0,50.0, 10, 0, "");
-       uiDefButF(block, NUM,B_MAKEFONT, "Shear:",      482,12,121,19, &cu->shear, -1.0,1.0, 10, 0, "");
-       uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   605,12,121,19, &cu->xof, -50.0,50.0, 10, 0, "");
+       if(coba==0) return;
+       
+       /* outline */
+       v1[0]= x1; v1[1]= y1;
+       glLineWidth((GLfloat)(3));
+       cpack(0x0);
+       glBegin(GL_LINE_LOOP);
+               glVertex2fv(v1);
+               v1[0]+= sizex;
+               glVertex2fv(v1);
+               v1[1]+= sizey;
+               glVertex2fv(v1);
+               v1[0]-= sizex;
+               glVertex2fv(v1);
+       glEnd();
+       glLineWidth((GLfloat)(1));
 
-       uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 752,192,164,19, cu->family, 0.0, 20.0, 0, 0, "");
 
-       uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              623,163,103,23, 0, 0, 0, 0, 0, "");
+       glShadeModel(GL_SMOOTH);
+       cbd= coba->data;
        
-       uiBlockSetCol(block, BUTGREY);
-
-       G.buts->texnr= give_vfontnr(cu->vfont);
+       v1[0]= v2[0]= x1;
+       v1[1]= y1;
+       v2[1]= y1+sizey;
        
-       strp= give_vfontbutstr();
+       glBegin(GL_QUAD_STRIP);
        
-       uiDefButS(block, MENU, B_SETFONT, strp, 484,191,220,20, &G.buts->texnr, 0, 0, 0, 0, "");
+       glColor3fv( &cbd->r );
+       glVertex2fv(v1); glVertex2fv(v2);
        
-       if (cu->vfont->packedfile) {
-               packdummy = 1;
-       } else {
-               packdummy = 0;
+       for(a=0; a<coba->tot; a++, cbd++) {
+               
+               v1[0]=v2[0]= x1+ cbd->pos*sizex;
+
+               glColor3fv( &cbd->r );
+               glVertex2fv(v1); glVertex2fv(v2);
        }
        
-       uiBlockSetCol(block, BUTYELLOW);
-       uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       706,191,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Vectorfont");
+       v1[0]=v2[0]= x1+ sizex;
+       glVertex2fv(v1); glVertex2fv(v2);
+       
+       glEnd();
+       glShadeModel(GL_FLAT);
        
-       MEM_freeN(strp);
+       /* help lines */
        
-       uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block, BUT,B_LOADFONT, "Load Font",    484,163,103,23, 0, 0, 0, 0, 0, "");
+       v1[0]= v2[0]=v3[0]= x1;
+       v1[1]= y1;
+       v2[1]= y1+0.5*sizey;
+       v3[1]= y1+sizey;
        
-       uiDrawBlock(block);
+       cbd= coba->data;
+       glBegin(GL_LINES);
+       for(a=0; a<coba->tot; a++, cbd++) {
+               v1[0]=v2[0]=v3[0]= x1+ cbd->pos*sizex;
+               
+               glColor3ub(0, 0, 0);
+               glVertex2fv(v1);
+               glVertex2fv(v2);
+
+               if(a==coba->cur) {
+                       glVertex2f(v1[0]-1, v1[1]);
+                       glVertex2f(v2[0]-1, v2[1]);
+                       glVertex2f(v1[0]+1, v1[1]);
+                       glVertex2f(v2[0]+1, v2[1]);
+               }
+                       
+               glColor3ub(255, 255, 255);
+               glVertex2fv(v2);
+               glVertex2fv(v3);
+               
+               if(a==coba->cur) {
+                       glVertex2f(v2[0]-1, v2[1]);
+                       glVertex2f(v3[0]-1, v3[1]);
+                       glVertex2f(v2[0]+1, v2[1]);
+                       glVertex2f(v3[0]+1, v3[1]);
+               }
+       }
+       glEnd();
+       
+       glFlush();
 }
 
-/* *************************** CURVE ******************************** */
 
 
-void do_curvebuts(unsigned short event)
+void do_texbuts(unsigned short event)
 {
-       extern Nurb *lastnu;
-       Object *ob;
-       Curve *cu;
-       Nurb *nu;
+       Tex *tex;
+       ImBuf *ibuf;
+       ScrArea *sa;
+       ID *id;
+       CBData *cbd;
+       float dx;
+       int a, nr;
+       short mvalo[2], mval[2];
+       char *name, str[80];
        
-       ob= OBACT;
-       if(ob==0) return;
+       tex= G.buts->lockpoin;
        
-       switch(event) { 
-
-       case B_CONVERTPOLY:
-       case B_CONVERTBEZ:
-       case B_CONVERTBSPL:
-       case B_CONVERTCARD:
-       case B_CONVERTNURB:
-               if(G.obedit) {
-                       setsplinetype(event-B_CONVERTPOLY);
-                       makeDispList(G.obedit);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
-               break;
-       case B_UNIFU:
-       case B_ENDPU:
-       case B_BEZU:
-       case B_UNIFV:
-       case B_ENDPV:
-       case B_BEZV:
-               if(G.obedit) {
-                       nu= editNurb.first;
-                       while(nu) {
-                               if(isNurbsel(nu)) {
-                                       if((nu->type & 7)==CU_NURBS) {
-                                               if(event<B_UNIFV) {
-                                                       nu->flagu &= 1;
-                                                       nu->flagu += ((event-B_UNIFU)<<1);
-                                                       makeknots(nu, 1, nu->flagu>>1);
-                                               }
-                                               else if(nu->pntsv>1) {
-                                                       nu->flagv &= 1;
-                                                       nu->flagv += ((event-B_UNIFV)<<1);
-                                                       makeknots(nu, 2, nu->flagv>>1);
-                                               }
-                                       }
-                               }
-                               nu= nu->next;
-                       }
-                       makeDispList(G.obedit);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
+       switch(event) {
+       case B_TEXCHANNEL:
+               scrarea_queue_headredraw(curarea);
+               BIF_preview_changed(G.buts);
+               allqueue(REDRAWBUTSTEX, 0);
                break;
-       case B_SETWEIGHT:
-               if(G.obedit) {
-                       weightflagNurb(1, editbutweight, 0);
-                       makeDispList(G.obedit);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
+       case B_TEXTYPE:
+               if(tex==0) return;
+               tex->stype= 0;
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
                break;
-       case B_SETW1:
-               editbutweight= 1.0;
-               scrarea_queue_winredraw(curarea);
+       case B_DEFTEXVAR:
+               if(tex==0) return;
+               default_tex(tex);
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
                break;
-       case B_SETW2:
-               editbutweight= sqrt(2.0)/4.0;
-               scrarea_queue_winredraw(curarea);
+       case B_LOADTEXIMA:
+       case B_LOADTEXIMA1:
+               if(tex==0) return;
+               /* globals: temporal store them: we make another area a fileselect */
+               cur_imatex= tex;
+               prv_win= curarea->win;
+               
+               sa= closest_bigger_area();
+               areawinset(sa->win);
+               if(tex->ima) name= tex->ima->name;
+#ifdef _WIN32
+               else {
+                       if (strcmp (U.textudir, "/") == 0)
+                               name= G.sce;
+                       else
+                               name= U.textudir;
+               }
+#else
+               else name = U.textudir;
+#endif
+               
+               if(event==B_LOADTEXIMA)
+                       activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_tex_image);
+               else 
+                       activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_tex_image);
+               
                break;
-       case B_SETW3:
-               editbutweight= 0.25;
-               scrarea_queue_winredraw(curarea);
+       case B_NAMEIMA:
+               if(tex==0) return;
+               if(tex->ima) {
+                       cur_imatex= tex;
+                       prv_win= curarea->win;
+                       
+                       /* name in tex->ima has been changed by button! */
+                       strcpy(str, tex->ima->name);
+                       if(tex->ima->ibuf) strcpy(tex->ima->name, tex->ima->ibuf->name);
+
+                       load_tex_image(str);
+               }
                break;
-       case B_SETW4:
-               editbutweight= sqrt(0.5);
-               scrarea_queue_winredraw(curarea);
+       case B_TEXREDR_PRV:
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
                break;
-       case B_SETORDER:
-               if(G.obedit) {
-                       nu= lastnu;
-                       if(nu && (nu->type & 7)==CU_NURBS ) {
-                               if(nu->orderu>nu->pntsu) {
-                                       nu->orderu= nu->pntsu;
-                                       scrarea_queue_winredraw(curarea);
-                               }
-                               makeknots(nu, 1, nu->flagu>>1);
-                               if(nu->orderv>nu->pntsv) {
-                                       nu->orderv= nu->pntsv;
-                                       scrarea_queue_winredraw(curarea);
+       case B_TEXIMABROWSE:
+               if(tex) {
+                       id= (ID*) tex->ima;
+                       
+                       if(G.buts->menunr== -2) {
+                               activate_databrowse(id, ID_IM, 0, B_TEXIMABROWSE, &G.buts->menunr, do_texbuts);
+                       } else if (G.buts->menunr>0) {
+                               Image *newima= (Image*) BLI_findlink(&G.main->image, G.buts->menunr-1);
+                               
+                               if (newima && newima!=(Image*) id) {
+                                       tex->ima= newima;
+                                       id_us_plus((ID*) newima);
+                                       if(id) id->us--;
+                               
+                                       allqueue(REDRAWBUTSTEX, 0);
+                                       BIF_preview_changed(G.buts);
                                }
-                               makeknots(nu, 2, nu->flagv>>1);
                        }
-                       makeDispList(G.obedit);
-                       allqueue(REDRAWVIEW3D, 0);
                }
                break;
-       case B_MAKEDISP:
-               if(ob->type==OB_FONT) text_to_curve(ob, 0);
-               makeDispList(ob);
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
-               break;
-       
-       case B_SUBDIVCURVE:
-               subdivideNurb();
-               break;
-       case B_SPINNURB:
-               /* bad bad bad!!! use brackets!!! In case you wondered:
-                 {==,!=} goes before & goes before || */
-               if( (G.obedit==0) || 
-                   (G.obedit->type!=OB_SURF) || 
-                       ((G.obedit->lay & G.vd->lay) == 0) ) return;
-               spinNurb(0, 0);
-               countall();
-               makeDispList(G.obedit);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_CU3D:        /* allow 3D curve */
-               if(G.obedit) {
-                       cu= G.obedit->data;
-                       nu= editNurb.first;
-                       while(nu) {
-                               nu->type &= ~CU_2D;
-                               if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
-                               test2DNurb(nu);
-                               nu= nu->next;
-                       }
-               }
-               if(ob->type==OB_CURVE) {
-                       cu= ob->data;
-                       nu= cu->nurb.first;
-                       while(nu) {
-                               nu->type &= ~CU_2D;
-                               if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
-                               test2DNurb(nu);
-                               nu= nu->next;
+       case B_IMAPTEST:
+               if(tex) {
+                       if( (tex->imaflag & (TEX_FIELDS+TEX_MIPMAP))== TEX_FIELDS+TEX_MIPMAP ) {
+                               error("Cannot combine fields and mipmap");
+                               tex->imaflag -= TEX_MIPMAP;
+                               allqueue(REDRAWBUTSTEX, 0);
                        }
-               }
-               break;
-       case B_SETRESOLU:
-               if(ob->type==OB_CURVE) {
-                       cu= ob->data;
-                       if(ob==G.obedit) nu= editNurb.first;
-                       else nu= cu->nurb.first;
                        
-                       while(nu) {
-                               nu->resolu= cu->resolu;
-                               nu= nu->next;
-                       }
-               }
-               else if(ob->type==OB_FONT) text_to_curve(ob, 0);
-               
-               makeDispList(ob);
-               allqueue(REDRAWVIEW3D, 0);
-
+                       if(tex->ima && tex->ima->ibuf) {
+                               ibuf= tex->ima->ibuf;
+                               nr= 0;
+                               if( !(tex->imaflag & TEX_FIELDS) && (ibuf->flags & IB_fields) ) nr= 1;
+                               if( (tex->imaflag & TEX_FIELDS) && !(ibuf->flags & IB_fields) ) nr= 1;
+                               if(nr) {
+                                       IMB_freeImBuf(ibuf);
+                                       tex->ima->ibuf= 0;
+                                       tex->ima->ok= 1;
+                                       BIF_preview_changed(G.buts);
+                               }
+                       }
+               }
                break;
-       }
-}
+       case B_RELOADIMA:
+               if(tex && tex->ima) {
+                       // check if there is a newer packedfile
 
-void curvebuts(void)
-{
-       Object *ob;
-       Curve *cu;
-       Nurb *nu;
-       extern Nurb *lastnu;
-       uiBlock *block;
-       short *sp;
-       char str[64];
-       
-       ob= OBACT;
-       if(ob==0) return;
+                       if (tex->ima->packedfile) {
+                               PackedFile *pf;
+                               pf = newPackedFile(tex->ima->name);
+                               if (pf) {
+                                       freePackedFile(tex->ima->packedfile);
+                                       tex->ima->packedfile = pf;
+                               } else {
+                                       error("Image not available. Keeping packed image.");
+                               }
+                       }
 
-       sprintf(str, "editbuttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+                       IMB_freeImBuf(tex->ima->ibuf);
+                       tex->ima->ibuf= 0;
+                       tex->ima->ok= 1;
+                       allqueue(REDRAWBUTSTEX, 0);
+                       allqueue(REDRAWVIEW3D, 0);
+                       allqueue(REDRAWIMAGE, 0);
+                       BIF_preview_changed(G.buts);
+               }
+               break;
 
-       cu= ob->data;
+       case B_TEXSETFRAMES:
+               if(tex->ima->anim) tex->frames = IMB_anim_get_duration(tex->ima->anim);
+               allqueue(REDRAWBUTSTEX, 0);
+               break;
 
-       if(ob->type==OB_CURVE || ob->type==OB_SURF) {
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
-       
-               uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_BEZU,"Bezier U",  565,112,102, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_UNIFV,"V",                670,152,50, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_ENDPV,"V",                670,132,50, 18, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_BEZV,"V",         670,112,50, 18, 0, 0, 0, 0, 0, "");
-       
-               uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButF(block, NUM,0,"Weight:",       564,36,102,22, &editbutweight, 0.01, 10.0, 10, 0, "");
-               uiDefBut(block, BUT,B_SETW1,"1.0",              669,36,50,22, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",        564,11,57,20, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_SETW3,"0.25",             621,11,43,20, 0, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",        664,11,57,20, 0, 0, 0, 0, 0, "");
-               
-               if(ob==G.obedit) {
-                       nu= lastnu;
-                       if(nu==NULL) nu= editNurb.first;
-                       if(nu) {
-                               sp= &(nu->orderu); 
-                               uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,91,102, 18, sp, 2.0, 6.0, 0, 0, "");
-                               sp= &(nu->orderv); 
-                               uiDefButS(block, NUM, B_SETORDER, "V:",  670,91,50, 18, sp, 2.0, 6.0, 0, 0, "");
-                               sp= &(nu->resolu); 
-                               uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 18, sp, 1.0, 128.0, 0, 0, "");
-                               sp= &(nu->resolv); 
-                               uiDefButS(block, NUM, B_MAKEDISP, "V:", 670,70,50, 18, sp, 1.0, 128.0, 0, 0, "");
+       case B_PACKIMA:
+               if(tex && tex->ima) {
+                       if (tex->ima->packedfile) {
+                               if (G.fileflags & G_AUTOPACK) {
+                                       if (okee("Disable AutoPack ?")) {
+                                               G.fileflags &= ~G_AUTOPACK;
+                                       }
+                               }
+                               
+                               if ((G.fileflags & G_AUTOPACK) == 0) {
+                                       unpackImage(tex->ima, PF_ASK);
+                               }
+                       } else {
+                               if (tex->ima->ibuf && (tex->ima->ibuf->userflags & IB_BITMAPDIRTY)) {
+                                       error("Can't pack painted image. Save image from Image window first.");
+                               } else {
+                                       tex->ima->packedfile = newPackedFile(tex->ima->name);
+                               }
                        }
+                       allqueue(REDRAWBUTSTEX, 0);
+                       allqueue(REDRAWHEADERS, 0);
                }
+               break;
+       case B_LOADPLUGIN:
+               if(tex==0) return;
 
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide",        1092,105,165,20, 0, 0, 0, 0, 0, "");
-       }
-
-       if(ob->type==OB_SURF) {
-               uiDefBut(block, BUT, B_SPINNURB, "Spin",        808,92,101,36, 0, 0, 0, 0, 0, "");
-
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
-               uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       143,140,130,18, &cu->flag, 0, 0, 0, 0, "");
-       }
-       else {
-
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
-               
-               uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 752,163,132,21, &cu->resolu, 1.0, 128.0, 0, 0, "");
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block, BUT, B_SETRESOLU, "Set",                                887,163,29,21, 0, 0, 0, 0, 0, "");
-               
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  753,30,163,18, &cu->bevresol, 0.0, 10.0, 0, 0, "");
-
-               uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         753,10,163,18, &cu->bevobj, "");
-               uiDefButF(block, NUM, B_MAKEDISP, "Width:",             753,90,163,18, &cu->width, 0.0, 2.0, 1, 0, "");
-               uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              753,70,163,18, &cu->ext1, 0.0, 5.0, 10, 0, "");
-               uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              753,50,163,18, &cu->ext2, 0.0, 2.0, 1, 0, "");
-               uiBlockSetCol(block, BUTBLUE);
-               if(ob->type==OB_FONT) {
-                       uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        833,130,79,18, &cu->flag, 0, 0, 0, 0, "");
-                       uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,76,18, &cu->flag, 0, 0, 0, 0, "");
-               }
+               /* globals: store temporal: we make another area a fileselect */
+               cur_imatex= tex;
+               prv_win= curarea->win;
+                       
+               sa= closest_bigger_area();
+               areawinset(sa->win);
+               if(tex->plugin) strcpy(str, tex->plugin->name);
                else {
-                       uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",                       867,130,47,18, &cu->flag, 0, 0, 0, 0, "");
-                       uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        810,130,55,18, &cu->flag, 0, 0, 0, 0, "");
-                       uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,53,18, &cu->flag, 0, 0, 0, 0, "");
+                       strcpy(str, U.plugtexdir);
                }
-               uiBlockSetCol(block, BUTGREY);
-       }
-
-       uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 80, 164, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
-
-       uiDrawBlock(block);
-}
-
-
-/* *************************** CAMERA ******************************** */
-
-
-void camerabuts(void)
-{
-       Camera *cam;
-       Object *ob;
-       uiBlock *block;
-       float grid=0.0;
-       char str[64];
-       
-       if(G.vd) grid= G.vd->grid; 
-       if(grid<1.0) grid= 1.0;
-       
-       ob= OBACT;
-       if(ob==0) return;
+               activate_fileselect(FILE_SPECIAL, "SELECT PLUGIN", str, load_plugin_tex);
+               
+               break;
 
-       sprintf(str, "editbuttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+       case B_NAMEPLUGIN:
+               if(tex==0 || tex->plugin==0) return;
+               strcpy(str, tex->plugin->name);
+               free_plugin_tex(tex->plugin);
+               tex->stype= 0;
+               tex->plugin= add_plugin_tex(str);
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
+               break;
        
-       cam= ob->data;
-       uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
-       uiDefButF(block, NUM,REDRAWVIEW3D, "ClipSta:", 470,147,160,20, &cam->clipsta, 0.001*grid, 100.0*grid, 10, 0, "Specify the startvalue of the the field of view");
-       uiDefButF(block, NUM,REDRAWVIEW3D, "ClipEnd:", 470,125,160,20, &cam->clipend, 1.0, 5000.0*grid, 100, 0, "Specify the endvalue of the the field of view");
-       uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
-
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
-
-       uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
-       uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist", 533,49,97,20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
+       case B_COLORBAND:
+               if(tex==0) return;
+               if(tex->coba==0) tex->coba= add_colorband();
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
+               break;
        
-       if(G.special1 & G_HOLO) {
-               uiBlockSetCol(block, BUTGREY);
-               if(cam->netend==0.0) cam->netend= EFRA;
-               uiDefButF(block, NUM, REDRAWVIEW3D, "Anim len",         670,80,100,20, &cam->netend, 1.0, 2500.0, 0, 0, "");
-               uiDefButF(block, NUM, REDRAWVIEW3D, "Path len:",                670,160,100,20, &cam->hololen, 0.1, 25.0, 10, 0, "");
-               uiDefButF(block, NUM, REDRAWVIEW3D, "Shear fac:",               670,140,100,20, &cam->hololen1, 0.1, 5.0, 10, 0, "");
-               uiBlockSetCol(block, BUTGREEN);
-               uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Holo 1",     670,120,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
-               uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Holo 2",     670,100,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
+       case B_ADDCOLORBAND:
+               if(tex==0 || tex->coba==0) return;
                
-       }
-       uiDrawBlock(block);
-}
+               if(tex->coba->tot < MAXCOLORBAND-1) tex->coba->tot++;
+               tex->coba->cur= tex->coba->tot-1;
+               
+               do_texbuts(B_CALCCBAND);
+               
+               break;
 
-/* *************************** FACE/PAINT *************************** */
+       case B_DELCOLORBAND:
+               if(tex==0 || tex->coba==0 || tex->coba->tot<2) return;
+               
+               for(a=tex->coba->cur; a<tex->coba->tot; a++) {
+                       tex->coba->data[a]= tex->coba->data[a+1];
+               }
+               if(tex->coba->cur) tex->coba->cur--;
+               tex->coba->tot--;
 
-void do_fpaintbuts(unsigned short event)
-{
-       Mesh *me;
-       Object *ob;
-       extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
-       
-       ob= OBACT;
-       if(ob==0) return;
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
+               break;
 
-       switch(event) { 
+       case B_CALCCBAND:
+       case B_CALCCBAND2:
+               if(tex==0 || tex->coba==0 || tex->coba->tot<2) return;
+               
+               for(a=0; a<tex->coba->tot; a++) tex->coba->data[a].cur= a;
+               qsort(tex->coba->data, tex->coba->tot, sizeof(CBData), vergcband);
+               for(a=0; a<tex->coba->tot; a++) {
+                       if(tex->coba->data[a].cur==tex->coba->cur) {
+                               if(tex->coba->cur!=a) addqueue(curarea->win, REDRAW, 0);        /* button cur */
+                               tex->coba->cur= a;
+                               break;
+                       }
+               }
+               if(event==B_CALCCBAND2) return;
+               
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
                
-       case B_VPGAMMA:
-               vpaint_dogamma();
                break;
-       case B_COPY_TF_MODE:
-       case B_COPY_TF_UV:
-       case B_COPY_TF_COL:
-       case B_COPY_TF_TEX:
-               me= get_mesh(ob);
-               if(me && me->tface) {
-/*                     extern TFace *lasttface; */
-                       TFace *tface= me->tface;
-                       int a= me->totface;
-                       
-                       set_lasttface();
-                       if(lasttface) {
-                       
-                               while(a--) {
-                                       if(tface!=lasttface && (tface->flag & TF_SELECT)) {
-                                               if(event==B_COPY_TF_MODE) {
-                                                       tface->mode= lasttface->mode;
-                                                       tface->transp= lasttface->transp;
-                                               }
-                                               else if(event==B_COPY_TF_UV) {
-                                                       memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
-                                                       tface->tpage= lasttface->tpage;
-                                                       tface->tile= lasttface->tile;
-                                                       
-                                                       if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
-                                                       else tface->mode &= ~TF_TILES;
-                                                       
-                                               }
-                                               else if(event==B_COPY_TF_TEX) {
-                                                       tface->tpage= lasttface->tpage;
-                                                       tface->tile= lasttface->tile;
+               
+       case B_DOCOLORBAND:
+               if(tex==0 || tex->coba==0) return;
+               
+               cbd= tex->coba->data + tex->coba->cur;
+               uiGetMouse(mywinget(), mvalo);
 
-                                                       if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
-                                                       else tface->mode &= ~TF_TILES;
-                                               }
-                                               else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
-                                       }
-                                       tface++;
-                               }
+               while(get_mbut() & L_MOUSE) {
+                       uiGetMouse(mywinget(), mval);
+                       if(mval[0]!=mvalo[0]) {
+                               dx= mval[0]-mvalo[0];
+                               dx/= 345.0;
+                               cbd->pos+= dx;
+                               CLAMP(cbd->pos, 0.0, 1.0);
+
+                               glDrawBuffer(GL_FRONT);
+                               drawcolorband(tex->coba, 923,81,345,20);
+                               /* uiSetButs(B_CALCCBAND, B_CALCCBAND); */
+                               glDrawBuffer(GL_BACK);
+                               
+                               do_texbuts(B_CALCCBAND2);
+                               cbd= tex->coba->data + tex->coba->cur;  /* because qsort */
+                               
+                               mvalo[0]= mval[0];
                        }
-                       do_shared_vertexcol(me);
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWIMAGE, 0);
+                       BIF_wait_for_statechange();
                }
-               break;
-       case B_SET_VCOL:
-               clear_vpaint_selectedfaces();
-               break;
-       case B_REDR_3D_IMA:
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWIMAGE, 0);
-               break;
-       case B_ASSIGNMESH:
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
                
-               test_object_materials(ob->data);
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWBUTSGAME, 0);
                break;
-               
-       case B_TFACE_HALO:
-               set_lasttface();
-               if(lasttface) {
-                       lasttface->mode &= ~TF_BILLBOARD2;
-                       allqueue(REDRAWBUTSGAME, 0);
+       
+       case B_REDRAWCBAND:
+               glDrawBuffer(GL_FRONT);
+               drawcolorband(tex->coba, 923,81,345,20);
+               glDrawBuffer(GL_BACK);
+               BIF_preview_changed(G.buts);
+               break;
+       
+       case B_ENV_DELETE:
+               if(tex->env) {
+                       RE_free_envmap(tex->env);
+                       tex->env= 0;
+                       allqueue(REDRAWBUTSTEX, 0);
+                       BIF_preview_changed(G.buts);
                }
                break;
-
-       case B_TFACE_BILLB:
-               set_lasttface();
-               if(lasttface) {
-                       lasttface->mode &= ~TF_BILLBOARD;
-                       allqueue(REDRAWBUTSGAME, 0);
+       case B_ENV_FREE:
+               if(tex->env) {
+                       RE_free_envmapdata(tex->env);
+                       allqueue(REDRAWBUTSTEX, 0);
+                       BIF_preview_changed(G.buts);
                }
                break;
-       }       
-}
+       case B_ENV_FREE_ALL:
+               tex= G.main->tex.first;
+               while(tex) {
+                       if(tex->id.us && tex->type==TEX_ENVMAP) {
+                               if(tex->env) {
+                                       if(tex->env->stype!=ENV_LOAD) RE_free_envmapdata(tex->env);
+                               }
+                       }
+                       tex= tex->id.next;
+               }
+               allqueue(REDRAWBUTSTEX, 0);
+               BIF_preview_changed(G.buts);
+               break;
+       case B_ENV_SAVE:
+               if(tex->env && tex->env->ok) {
+                       sa= closest_bigger_area();
+                       areawinset(sa->win);
+                       save_image_filesel_str(str);
+                       activate_fileselect(FILE_SPECIAL, str, G.ima, save_env);
+               }
+               break;  
+       case B_ENV_OB:
+               if(tex->env && tex->env->object) {
+                       BIF_preview_changed(G.buts);
+                       if ELEM(tex->env->object->type, OB_CAMERA, OB_LAMP) {
+                               error("Camera or Lamp not allowed");
+                               tex->env->object= 0;
+                       }
+               }
+               break;
+               
+       default:
+               if(event>=B_PLUGBUT && event<=B_PLUGBUT+23) {
+                       PluginTex *pit= tex->plugin;
+                       if(pit && pit->callback) {
+                               pit->callback(event - B_PLUGBUT);
+                               BIF_preview_changed(G.buts);
+                       }
+               }
+       }
+}
+
+static         void test_idbutton_cb(void *namev, void *arg2_unused)
+{
+       char *name= namev;
+       test_idbutton(name+2);
+}
 
-void fpaintbuts(void)
+void texbuts(void)
 {
-/*     extern VPaint Gvp; already in the top of the file */
        Object *ob;
+       Material *ma=0;
+       World *wrld=0;
+       Lamp *la=0;
+       ID *id = NULL;
+       MTex *mtex = NULL;
+       Tex *tex;
+       VarStruct *varstr;
+       PluginTex *pit;
+       CBData *cbd;
+       EnvMap *env;
        uiBlock *block;
-       char str[32];
+       uiBut *but;
+       int a, xco, yco, loos, dx, dy, ok;
+       char str[30], *strp;
        
-       ob= OBACT;
-       if(ob==0) return;
-
        sprintf(str, "buttonswin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
 
-       /* VPAINT BUTTONS */
-       uiBlockSetCol(block, BUTGREY);
-
-       if (G.f & G_VERTEXPAINT) {
-               uiDefBut(block, LABEL, 0, "Vertex Paint",       1037,180,194,18, 0, 0, 0, 0, 0, "");
-       } else if (G.f & G_TEXTUREPAINT) {
-               uiDefBut(block, LABEL, 0, "Texture Paint",      1037,180,194,18, 0, 0, 0, 0, 0, "");
-       } 
-
-       uiDefButF(block, NUMSLI, 0, "R ",                       979,160,194,19, &Gvp.r, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of red used for painting");
-       uiDefButF(block, NUMSLI, 0, "G ",                       979,140,194,19, &Gvp.g, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of green used for painting");
-       uiDefButF(block, NUMSLI, 0, "B ",                       979,120,194,19, &Gvp.b, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of blue used for painting");
-       uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
-       uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
-
-       uiDefButF(block, COL, B_VPCOLSLI, "",           1176,100,28,80, &(Gvp.r), 0, 0, 0, 0, "");
-
-       uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
-       uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
-       uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
-       uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
-       uiDefButS(block, ROW, B_DIFF, "Filter",         1212, 80,63,19, &Gvp.mode, 1.0, 4.0, 0, 0, "Mix the colours with an alpha factor");
-
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
-       uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
-       uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
-
        uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
+
+       uiDefButC(block, ROW, B_TEXREDR_PRV, "Mat",             200,172,40,20, &G.buts->texfrom, 3.0, 0.0, 0, 0, "Display the texture of the active material");
+       uiDefButC(block, ROW, B_TEXREDR_PRV, "World",           240,172,52,20, &G.buts->texfrom, 3.0, 1.0, 0, 0, "Display the texture of the world block");
+       uiDefButC(block, ROW, B_TEXREDR_PRV, "Lamp",            292,172,46,20, &G.buts->texfrom, 3.0, 2.0, 0, 0, "Display the texture of the lamp");
        uiBlockSetCol(block, BUTGREY);
-       uiDefButF(block, NUM, B_DIFF, "Mul:",           1061,30,112,19, &Gvp.mul, 0.1, 50.0, 10, 0, "Set the number to multiply vertex colours with");
-       uiDefButF(block, NUM, B_DIFF, "Gamma:",         1174,30,102,19, &Gvp.gamma, 0.1, 5.0, 10, 0, "Change the clarity of the vertex colours");
        
-       uiDefBut(block, LABEL, 0, "Face Select",        600,180,194,18, 0, 0, 0, 0, 0, "");
-       if(G.f & G_FACESELECT) {
-               extern TFace *lasttface;
+       ok= 0;
+       
+       if(G.buts->texfrom==0) {
+               ob= OBACT;
+               if(ob) {
+                       id= ob->data;
+                       if(id) {
+                               ma= give_current_material(ob, ob->actcol);
+                               if(ma) ok= 1;
+                       }
+               }
                
-               set_lasttface();
-               if(lasttface) {
-                       
-                       uiBlockSetCol(block, BUTGREEN);
-                       uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
-                       uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
-                       uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
-                       uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
-                       uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
-
-                       uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "Shared",     600,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Blend vertex colours across face when vertices are shared");
-                       uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",    660,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
-                       uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
-
-                       uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
-                       uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
-                       uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
-                       uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
-
-                       uiBlockSetCol(block, BUTPURPLE);
-                       uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,100,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
-                       uiDefButC(block, ROW, REDRAWVIEW3D, "Add",              660,100,60,19, &lasttface->transp, 2.0, 1.0, 0, 0, "Render face transparent and add colour of face");
-                       uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha",            720,100,60,19, &lasttface->transp, 2.0, 2.0, 0, 0, "Render polygon transparent, depending on alpha channel of the texture");
-                       /* uiDefButC(block, ROW, REDRAWVIEW3D, "Sub",   780,100,60,19, &lasttface->transp, 2.0, 3.0, 0, 0); ,""*/
-
+       }
+       else if(G.buts->texfrom==1) {
+               wrld= G.scene->world;
+               if(wrld) {
+                       id= (ID *)wrld;
+                       ok= 1;
                }
        }
-       uiBlockSetCol(block, BUTSALMON);
-       if(G.f & G_FACESELECT) {
-               uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 859,37,103,28, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
-
+       else if(G.buts->texfrom==2) {
+               ob= OBACT;
+               if(ob) {
+                       if(ob->type==OB_LAMP) {
+                               la= ob->data;
+                               id= (ID *)la;
+                               ok= 1;
+                       }
+               }
        }
-       uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 650,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode");
-       uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",               771,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures");
-       uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",     859,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours");
-
-       uiDrawBlock(block);
-}
-
-/* *************************** RADIO ******************************** */
-
-void do_radiobuts(short event)
-{
-       Radio *rad;
-       int phase;
        
-       phase= rad_phase();
-       rad= G.scene->radio;
+       if(ok==0) {
+               uiDrawBlock(block);
+               return;
+       }
        
-       switch(event) {
-       case B_RAD_ADD:
-               add_radio();
-               allqueue(REDRAWBUTSRADIO, 0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_DELETE:
-               delete_radio();
-               allqueue(REDRAWBUTSRADIO, 0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_FREE:
-               freeAllRad();
-               allqueue(REDRAWBUTSRADIO, 0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_COLLECT:
-               rad_collect_meshes();
-               allqueue(REDRAWBUTSRADIO, 0);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_INIT:
-               if(phase==RAD_PHASE_PATCHES) {
-                       rad_limit_subdivide();
-                       allqueue(REDRAWBUTSRADIO, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
-               break;
-       case B_RAD_SHOOTP:
-               if(phase==RAD_PHASE_PATCHES) {
-                       waitcursor(1);
-                       rad_subdivshootpatch();
-                       allqueue(REDRAWBUTSRADIO, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-                       waitcursor(0);
-               }
-               break;
-       case B_RAD_SHOOTE:
-               if(phase==RAD_PHASE_PATCHES) {
-                       waitcursor(1);
-                       rad_subdivshootelem();
-                       allqueue(REDRAWBUTSRADIO, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-                       waitcursor(0);
-               }
-               break;
-       case B_RAD_GO:
-               if(phase==RAD_PHASE_PATCHES) {
-                       waitcursor(1);
-                       rad_go();
-                       waitcursor(0);
-                       allqueue(REDRAWBUTSRADIO, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
-               break;
-       case B_RAD_LIMITS:
-               rad_setlimits();
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWBUTSRADIO, 0);
-               break;
-       case B_RAD_FAC:
-               set_radglobal();
-               if(phase & RAD_PHASE_FACES) make_face_tab();
-               else make_node_display();
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_NODELIM:
-               if(phase & RAD_PHASE_FACES) {
-                       set_radglobal();
-                       removeEqualNodes(rad->nodelim);
-                       make_face_tab();
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWBUTSRADIO, 0);
+       uiSetButLock(id->lib!=0, "Can't edit library data");
+
+       /* CHANNELS */
+       yco= 140;
+       for(a= 0; a<8; a++) {
+               if(G.buts->texfrom==0) mtex= ma->mtex[a];
+               else if(G.buts->texfrom==1) mtex= wrld->mtex[a];
+               else if(G.buts->texfrom==2)  mtex= la->mtex[a];
+               
+               if(mtex && mtex->tex) splitIDname(mtex->tex->id.name+2, str, &loos);
+               else strcpy(str, "");
+               str[14]= 0;
+               if(G.buts->texfrom==0) {
+                       uiDefButC(block, ROW, B_TEXCHANNEL, str,        200,(short)yco,140,18, &(ma->texact), 0.0, (float)a, 0, 0, "Linked channel");
                }
-               break;
-       case B_RAD_NODEFILT:
-               if(phase & RAD_PHASE_FACES) {
-                       set_radglobal();
-                       filterNodes();
-                       make_face_tab();
-                       allqueue(REDRAWVIEW3D, 0);
+               else if(G.buts->texfrom==1) {
+                       uiDefButS(block, ROW, B_TEXCHANNEL, str,        200,(short)yco,140,18, &(wrld->texact), 0.0, (float)a, 0, 0, "");
+                       if(a==5) break;
                }
-               break;
-       case B_RAD_FACEFILT:
-               if(phase & RAD_PHASE_FACES) {
-                       filterFaces();
-                       allqueue(REDRAWVIEW3D, 0);
+               else if(G.buts->texfrom==2) {
+                       uiDefButS(block, ROW, B_TEXCHANNEL, str,        200,(short)yco,140,18, &(la->texact), 0.0, (float)a, 0, 0, "");
+                       if(a==5) break;
                }
-               break;
-       case B_RAD_DRAW:
-               set_radglobal();
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_ADDMESH:
-               if(phase & RAD_PHASE_FACES) rad_addmesh();
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_RAD_REPLACE:
-               if(phase & RAD_PHASE_FACES) rad_replacemesh();
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       }
-
-}
-
-
-void radiobuts(void)
-{
-       Radio *rad;
-       uiBlock *block;
-       int flag;
-       char str[128];
-
-       rad= G.scene->radio;
-       if(rad==0) {
-               add_radio();
-               rad= G.scene->radio;
+               yco-= 19;
        }
        
-       sprintf(str, "buttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-
-       flag= rad_phase();
-
-       if(flag & RAD_PHASE_PATCHES) {
-               uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block,  BUT, B_RAD_INIT, "Limit Subdivide",    10, 70, 190, 40, NULL, 0, 0, 0, 0, "Subdivide patches");
+       if(G.buts->texfrom==0) {
+               but= uiDefBut(block, TEX, B_IDNAME, "MA:",      200,195,140,20, ma->id.name+2, 0.0, 18.0, 0, 0, "Name of the datablock");
+               uiButSetFunc(but, test_idbutton_cb, ma->id.name, NULL);
+               mtex= ma->mtex[ ma->texact ];
+       }
+       else if(G.buts->texfrom==1) {
+               but= uiDefBut(block, TEX, B_IDNAME, "WO:",                                      200,195,140,20, wrld->id.name+2, 0.0, 18.0, 0, 0, "Name of the datablock");
+               uiButSetFunc(but, test_idbutton_cb, wrld->id.name, NULL);
+               mtex= wrld->mtex[ wrld->texact ];
+       }
+       else if(G.buts->texfrom==2) {
+               but= uiDefBut(block, TEX, B_IDNAME, "LA:",                                      200,195,140,20, la->id.name+2, 0.0, 18.0, 0, 0, "Name of the datablock");
+               uiButSetFunc(but, test_idbutton_cb, la->id.name, NULL);
+               mtex= la->mtex[ la->texact ];
        }
-       if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTPURPLE);
-       else uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block,  BUT, B_RAD_COLLECT, "Collect Meshes",  10, 30, 190, 40, NULL, 0, 0, 0, 0, "Convert selected and visible meshes to patches");
-       uiDrawBlock(block);
 
-       if(flag==0) {
+       if(mtex && mtex->tex) {
+               tex= mtex->tex;
+
+               uiSetButLock(tex->id.lib!=0, "Can't edit library data");
+               xco= 275;
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[0],     (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, 0.0, 0, 0, "Default");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_IMAGE],(short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_IMAGE, 0, 0, "Use image texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_ENVMAP],    (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_ENVMAP, 0, 0, "Use environment maps");
+               if(tex->plugin && tex->plugin->doit) strp= tex->plugin->pname; else strp= texstr[TEX_PLUGIN];
+               uiDefButS(block, ROW, B_TEXTYPE, strp,                          (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_PLUGIN, 0, 0, "Use plugin");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_CLOUDS],    (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_CLOUDS, 0, 0, "Use clouds texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_WOOD],      (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_WOOD, 0, 0, "Use wood texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_MARBLE],    (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_MARBLE, 0, 0, "Use marble texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_MAGIC],     (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_MAGIC, 0, 0, "Use magic texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_BLEND],     (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_BLEND, 0, 0, "Use blend texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_STUCCI],    (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_STUCCI, 0, 0, "Use strucci texture");
+               uiDefButS(block, ROW, B_TEXTYPE, texstr[TEX_NOISE],     (short)(xco+=75), 195, 75, 20, &tex->type, 1.0, (float)TEX_NOISE, 0, 0, "Use noise texture");
+               
+               /* TYPES */
+               uiBlockSetCol(block, BUTGREEN); 
+               switch(tex->type) {
+               case TEX_CLOUDS:
+                       uiDefButS(block, ROW, B_MATPRV, "Default",      350, 170, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Use standard noise"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Color",                425, 170, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Let Noise give RGB value"); 
+                       uiBlockSetCol(block, BUTGREY);  
+                       uiDefButF(block, NUM, B_MATPRV, "NoiseSize :",  350, 110, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Set the dimension of the noise table");
+                       uiDefButS(block, NUM, B_MATPRV, "NoiseDepth:",  350, 90, 150, 19, &tex->noisedepth, 0.0, 6.0, 0, 0, "Set the depth of the cloud calculation");
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, ROW, B_MATPRV, "Soft noise",           350, 40, 100, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Use soft noise");
+                       uiDefButS(block, ROW, B_MATPRV, "Hard noise",           450, 40, 100, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Use hard noise");
+                       break;
        
-               sprintf(str, "buttonswin1 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",        0, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
-               uiDefButS(block,  NUM, 0, "Max Iterations:",            1, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
-               uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      2, 0, 50, 10, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
-               uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     2, 0, 50, 10, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
-               uiDefButF(block,  NUM, 0, "Convergence:",                       3, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
-               uiDrawBlock(block);
-       }
-       else {
+               case TEX_WOOD:
+                       uiDefButS(block, ROW, B_MATPRV, "Bands",                350, 170, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Use standard wood texture"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Rings",                425, 170, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Use wood rings"); 
+                       uiDefButS(block, ROW, B_MATPRV, "BandNoise",    500, 170, 75, 18, &tex->stype, 2.0, 2.0, 0, 0, "Add noise to standard wood"); 
+                       uiDefButS(block, ROW, B_MATPRV, "RingNoise",    575, 170, 75, 18, &tex->stype, 2.0, 3.0, 0, 0, "Add noise to rings"); 
+                       uiBlockSetCol(block, BUTGREY);  
+                       uiDefButF(block, NUM, B_MATPRV, "NoiseSize :",  350, 110, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Set the dimension of the noise table");
+                       uiDefButF(block, NUM, B_MATPRV, "Turbulence:",  350, 90, 150, 19, &tex->turbul, 0.0, 200.0, 10, 0, "Set the turbulence of the bandnoise and ringnoise types");
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, ROW, B_MATPRV, "Soft noise",           350, 40, 100, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Use soft noise");
+                       uiDefButS(block, ROW, B_MATPRV, "Hard noise",           450, 40, 100, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Use hard noise");
+                       break;
        
+               case TEX_MARBLE:
+                       uiDefButS(block, ROW, B_MATPRV, "Soft",         350, 170, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Use soft marble"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Sharp",                425, 170, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Use more clearly defined marble"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Sharper",      500, 170, 75, 18, &tex->stype, 2.0, 2.0, 0, 0, "Use very clear defined marble"); 
+                       uiBlockSetCol(block, BUTGREY);  
+                       uiDefButF(block, NUM, B_MATPRV, "NoiseSize :",  350, 110, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Set the dimension of the noise table");
+                       uiDefButS(block, NUM, B_MATPRV, "NoiseDepth:",  350, 90, 150, 19, &tex->noisedepth, 0.0, 6.0, 0, 0, "Set the depth of the marble calculation");
+                       uiDefButF(block, NUM, B_MATPRV, "Turbulence:",  350, 70, 150, 19, &tex->turbul, 0.0, 200.0, 10, 0, "Set the turbulence of the sine bands");
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, ROW, B_MATPRV, "Soft noise",           350, 40, 100, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Use soft noise");
+                       uiDefButS(block, ROW, B_MATPRV, "Hard noise",           450, 40, 100, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Use hard noise");
+                       break;
        
-               sprintf(str, "buttonswin1 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
-               
-               uiBlockSetCol(block, BUTGREEN);
-               uiDefButS(block,  ROW, B_RAD_DRAW, "Wire",                      0, 0, 10, 10, &rad->drawtype, 0.0, 0.0, 0, 0, "Enable wireframe drawmode");
-               uiDefButS(block,  ROW, B_RAD_DRAW, "Solid",                     0, 0, 10, 10, &rad->drawtype, 0.0, 1.0, 0, 0, "Enable solid drawmode");
-               uiDefButS(block,  ROW, B_RAD_DRAW, "Gour",                      0, 0, 10, 10, &rad->drawtype, 0.0, 2.0, 0, 0, "Enable Gourad drawmode");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  TOG|BIT|0, B_RAD_DRAW, "ShowLim",  1, 0, 10, 10, &rad->flag, 0, 0, 0, 0, "Visualize patch and element limits");
-               uiDefButS(block,  TOG|BIT|1, B_RAD_DRAW, "Z",           1, 0, 3, 10, &rad->flag, 0, 0, 0, 0, "Draw limits different");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMax:",          2, 0, 10, 10, &rad->elma, 1.0, 500.0, 0, 0, "Set maximum size of an element");
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMin:",          2, 0, 10, 10, &rad->elmi, 1.0, 100.0, 0, 0, "Set minimum size of an element");
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMax:",          3, 0, 10, 10, &rad->pama, 10.0, 1000.0, 0, 0, "Set maximum size of a patch");
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMin:",          3, 0, 10, 10, &rad->pami, 10.0, 1000.0, 0, 0, "Set minimum size of a patch");
-               uiDrawBlock(block);
-               
-               sprintf(str, "buttonswin2 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 450, 30, 180, 150, UI_BLOCK_ROWS);
-               
-               if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_SHOOTE, "Subdiv Shoot Element", 0, 0, 12, 10, NULL, 0, 0, 0, 0, "");
-               uiDefBut(block,  BUT, B_RAD_SHOOTP, "Subdiv Shoot Patch",       1, 0, 12, 10, NULL, 0, 0, 0, 0, "Detect high energy changes");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  NUM, 0, "Max Subdiv Shoot:",                  2, 0, 10, 10, &rad->maxsublamp, 1.0, 250.0, 0, 0, "Set the maximum number of shoot patches that are evaluated");
-               uiDefButI(block,  NUM, 0, "MaxEl:",                                             3, 0, 10, 10, &rad->maxnode, 1.0, 250000.0, 0, 0, "Set the maximum allowed number of elements");
-               uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",                4, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
-               uiDrawBlock(block);
+               case TEX_MAGIC:
+                       uiBlockSetCol(block, BUTGREY);
+                       uiDefButF(block, NUM, B_MATPRV, "Size :",                       350, 110, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Set the dimension of the pattern");
+                       uiDefButS(block, NUM, B_MATPRV, "Depth:",                       350, 90, 150, 19, &tex->noisedepth, 0.0, 10.0, 0, 0, "Set the depth of the pattern");
+                       uiDefButF(block, NUM, B_MATPRV, "Turbulence:",  350, 70, 150, 19, &tex->turbul, 0.0, 200.0, 10, 0, "Set the strength of the pattern");
+                       break;
+       
+               case TEX_BLEND:
+                       uiDefButS(block, ROW, B_MATPRV, "Lin",          350, 170, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Use a linear progresion"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Quad",         425, 170, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Use a quadratic progression"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Ease",         500, 170, 75, 18, &tex->stype, 2.0, 2.0, 0, 0, ""); 
+                       uiDefButS(block, ROW, B_MATPRV, "Diag",         575, 170, 75, 18, &tex->stype, 2.0, 3.0, 0, 0, "Use a diagonal progression");
+                       uiDefButS(block, ROW, B_MATPRV, "Sphere",               650, 170, 75, 18, &tex->stype, 2.0, 4.0, 0, 0, "Use progression with the shape of a sphere");
+                       uiDefButS(block, ROW, B_MATPRV, "Halo",         725, 170, 75, 18, &tex->stype, 2.0, 5.0, 0, 0, "Use a quadratic progression with the shape of a sphere");
+                       
+                       uiDefButS(block, TOG|BIT|1, B_MATPRV, "Flip XY",        350, 130, 75, 18, &tex->flag, 0, 0, 0, 0, "Flip the direction of the progression a quarter turn");
+                       break;
+                       
+               case TEX_STUCCI:
+                       uiDefButS(block, ROW, B_MATPRV, "Plastic",      350, 170, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Use standard stucci");
+                       uiDefButS(block, ROW, B_MATPRV, "Wall In",      425, 170, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Set start value"); 
+                       uiDefButS(block, ROW, B_MATPRV, "Wall Out",     500, 170, 75, 18, &tex->stype, 2.0, 2.0, 0, 0, "Set end value"); 
+                       uiBlockSetCol(block, BUTGREY);  
+                       uiDefButF(block, NUM, B_MATPRV, "NoiseSize :",  350, 110, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Set the dimension of the noise table");
+                       uiDefButF(block, NUM, B_MATPRV, "Turbulence:",  350, 90, 150, 19, &tex->turbul, 0.0, 200.0, 10, 0, "Set the depth of the stucci");
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, ROW, B_MATPRV, "Soft noise",           350, 40, 100, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Use soft noise");
+                       uiDefButS(block, ROW, B_MATPRV, "Hard noise",           450, 40, 100, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Use hard noise");
+       
+                       break;
+                       
+               case TEX_NOISE:
+                       break;
+                       
+               case TEX_IMAGE:
+                       
+                       break;
+               }
                
-               sprintf(str, "buttonswin3 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 640, 30, 200, 150, UI_BLOCK_ROWS);
+               uiBlockSetCol(block, BUTSALMON);
+               uiDefBut(block, BUT, B_DEFTEXVAR, "Default Vars",       1180,169,93,47, 0, 0, 0, 0, 0, "Return to standard values");
                
                uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  NUM, 0, "Max Iterations:",    0, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
-               uiDefButF(block,  NUM, 0, "Convergence:",               1, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
-               uiDefButS(block,  NUM, 0, "SubSh P:",                   2, 0, 10, 10, &rad->subshootp, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect pathes");
-               uiDefButS(block,  NUM, 0, "SubSh E:",                   2, 0, 10, 10, &rad->subshoote, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect elements");
-               if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
-               uiDefBut(block,  BUT, B_RAD_GO, "GO",                           3, 0, 10, 15, NULL, 0, 0, 0, 0, "Start the radiosity simulation");
-               uiDrawBlock(block);
-               
-               sprintf(str, "buttonswin4 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 850, 30, 200, 150, UI_BLOCK_ROWS);
+               /* SPECIFIC */
+               if(tex->type==TEX_IMAGE) {
+                       uiDefButF(block, NUM, B_REDR, "MinX ",          350,30,140,19, &tex->cropxmin, -10.0, 10.0, 10, 0, "Set minimum X value for cropping");
+                       uiDefButF(block, NUM, B_REDR, "MaxX ",          350,10,140,19, &tex->cropxmax, -10.0, 10.0, 10, 0, "Set maximum X value for cropping");
+                       uiDefButF(block, NUM, B_REDR, "MinY ",          494,30,140,19, &tex->cropymin, -10.0, 10.0, 10, 0, "Set minimum Y value for cropping");
+                       uiDefButF(block, NUM, B_REDR, "MaxY ",          494,10,140,19, &tex->cropymax, -10.0, 10.0, 10, 0, "Set maximum Y value for cropping");
        
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      0, 0, 50, 17, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
-               uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     0, 0, 50, 17, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
-               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_FACEFILT, "FaceFilter",             1, 0, 10, 10, NULL, 0, 0, 0, 0, "Force an extra smoothing");
-               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_NODELIM, "RemoveDoubles",   2, 0, 30, 10, NULL, 0.0, 50.0, 0, 0, "Join elements which differ less than 'Lim'");
-               uiBlockSetCol(block, BUTGREY);
-               uiDefButS(block,  NUM, 0, "Lim:",                                       2, 0, 10, 10, &rad->nodelim, 0.0, 50.0, 0, 0, "Set the range for removing doubles");
-               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_NODEFILT, "Element Filter", 3, 0, 10, 10, NULL, 0, 0, 0, 0, "Filter elements to remove aliasing artefacts");
-               uiDrawBlock(block);
        
-               sprintf(str, "buttonswin5 %d", curarea->win);
-               block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-               uiAutoBlock(block, 1060, 30, 190, 150, UI_BLOCK_ROWS);
+                       uiDefButS(block, ROW, 0, "Extend",                      350,85,69,19, &tex->extend, 4.0, 1.0, 0, 0, "Extend the colour of the edge");
+                       uiDefButS(block, ROW, 0, "Clip",                                421,85,59,19, &tex->extend, 4.0, 2.0, 0, 0, "Return alpha 0.0 outside image");
+                       uiDefButS(block, ROW, 0, "Repeat",                      565,85,68,19, &tex->extend, 4.0, 3.0, 0, 0, "Repeat image horizontally and vertically");
+                       uiDefButS(block, ROW, 0, "ClipCube",                    482,85,82,19, &tex->extend, 4.0, 4.0, 0, 0, "Return alpha 0.0 outside cubeshaped area around image");
        
-               if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_FREE, "Free Radio Data",    0, 0, 10, 10, NULL, 0, 0, 0, 0, "Release all memory used by Radiosity");        
-               if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
-               else uiBlockSetCol(block, BUTGREY);
-               uiDefBut(block,  BUT, B_RAD_REPLACE, "Replace Meshes",  1, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, changing input-meshes");
-               uiDefBut(block,  BUT, B_RAD_ADDMESH, "Add new Meshes",  2, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, unchanging input-meshes");
-               uiDrawBlock(block);
-               
-               rad_status_str(str);
-               cpack(0);
-               glRasterPos2i(210, 189);
-               BMF_DrawString(uiBlockGetCurFont(block), str);
-       }
-}
-
-
-/* *************************** MBALL ******************************** */
-
-void do_mballbuts(unsigned short event)
-{
-       switch(event) {
-       case B_RECALCMBALL:
-               makeDispList(OBACT);
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       }
-}
-
-void mballbuts(void)
-{
-       extern MetaElem *lastelem;
-       MetaBall *mb;
-       Object *ob;
-       uiBlock *block;
-       char str[64];
+                       uiDefButF(block, NUM, B_MATPRV, "Filter :",     352,109,135,19, &tex->filtersize, 0.1, 25.0, 0, 0, "Set the filter size used by mipmap and interpol");
+                       
+                       uiDefButS(block, NUM, B_MATPRV, "Xrepeat:",     350,60,140,19, &tex->xrepeat, 1.0, 512.0, 0, 0, "Set the degree of repetition in the X direction");
+                       uiDefButS(block, NUM, B_MATPRV, "Yrepeat:",     494,60,140,19, &tex->yrepeat, 1.0, 512.0, 0, 0, "Set the degree of repetition in the Y direction");
+                       
+                       uiDefButS(block, NUM, B_MATPRV, "Frames :",     642,110,150,19, &tex->frames, 0.0, 18000.0, 0, 0, "Activate animation option");
+                       uiDefButS(block, NUM, B_MATPRV, "Offset :",     642,90,150,19, &tex->offset, -9000.0, 9000.0, 0, 0, "Set the number of the first picture of the animation");
+                       uiDefButS(block, NUM, B_MATPRV, "Fie/Ima:",     642,60,98,19, &tex->fie_ima, 1.0, 200.0, 0, 0, "Set the number of fields per rendered frame");
+                       uiDefButS(block, NUM, B_MATPRV, "StartFr:",     642,30,150,19, &tex->sfra, 1.0, 9000.0, 0, 0, "Set the start frame of the animation");
+                       uiDefButS(block, NUM, B_MATPRV, "Len:",         642,10,150,19, &tex->len, 0.0, 9000.0, 0, 0, "Set the length of the animation");
        
-       ob= OBACT;
-       if(ob==0) return;
-
-       sprintf(str, "editbuttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+                       uiDefButS(block, NUM, B_MATPRV, "Fra:",         802,70,73,19, &(tex->fradur[0][0]), 0.0, 18000.0, 0, 0, "Montage mode: frame start");
+                       uiDefButS(block, NUM, B_MATPRV, "",                     879,70,37,19, &(tex->fradur[0][1]), 0.0, 250.0, 0, 0, "Montage mode: amount of displayed frames");
+                       uiDefButS(block, NUM, B_MATPRV, "Fra:",         802,50,73,19, &(tex->fradur[1][0]), 0.0, 18000.0, 0, 0, "Montage mode: frame start");
+                       uiDefButS(block, NUM, B_MATPRV, "",                     879,50,37,19, &(tex->fradur[1][1]), 0.0, 250.0, 0, 0, "Montage mode: amount of displayed frames");
+                       uiDefButS(block, NUM, B_MATPRV, "Fra:",         802,30,73,19, &(tex->fradur[2][0]), 0.0, 18000.0, 0, 0, "Montage mode: frame start");
+                       uiDefButS(block, NUM, B_MATPRV, "",                     879,30,37,19, &(tex->fradur[2][1]), 0.0, 250.0, 0, 0, "Montage mode: amount of displayed frames");
+                       uiDefButS(block, NUM, B_MATPRV, "Fra:",         802,10,73,19, &(tex->fradur[3][0]), 0.0, 18000.0, 0, 0, "Montage mode: frame start");
+                       uiDefButS(block, NUM, B_MATPRV, "",                     879,10,37,19, &(tex->fradur[3][1]), 0.0, 250.0, 0, 0, "Montage mode: amount of displayed frames");
        
-       mb= ob->data;   
-       if (ob==find_basis_mball(ob)) {
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
-               uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
-
-               uiBlockSetCol(block, BUTBLUE);
-               uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
-               uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
-               uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
-               uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
-               uiBlockSetCol(block, BUTGREY);
-       }
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, TOG|BIT|6, 0, "Cyclic",                743,60,48,19, &tex->imaflag, 0, 0, 0, 0, "Repeat animation image");
+                       
+                       uiBlockSetCol(block, BUTSALMON);
+                       uiDefBut(block, BUT, B_LOADTEXIMA, "Load Image", 350,137,132,24, 0, 0, 0, 0, 0, "Load image - thumbnail view");
+                       uiBlockSetCol(block, BUTGREY);
+                       uiDefBut(block, BUT, B_LOADTEXIMA1, "", 485,137,10,24, 0, 0, 0, 0, 0, "Load image - file view");
        
-       if(ob==G.obedit && lastelem) {
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
-               if(lastelem->type!=MB_BALL)
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "dx:",          750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "");
-               if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "dy:",          750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "");
-
-               if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
-               uiDefButF(block, NUMSLI, B_RECALCMBALL, "dz:",          750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "");
-
-               uiBlockSetCol(block, BUTGREEN);
-               uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,60,19, &lastelem->flag, 0, 0, 0, 0, "");
-
-               uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "");
-       }
-       uiDrawBlock(block);
-}
-
-/* *************************** SCRIPT ******************************** */
-
-static void extend_scriptlink(ScriptLink *slink)
-{
-       void *stmp, *ftmp;
+                       id= (ID *)tex->ima;
+                       IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->image), id, &(G.buts->menunr));
+                       if(strp[0])
+                               uiDefButS(block, MENU, B_TEXIMABROWSE, strp, 496,137,23,24, &(G.buts->menunr), 0, 0, 0, 0, "Browse");
+                       MEM_freeN(strp);
+       
+                       if(tex->ima) {
+                               uiDefBut(block, TEX, B_NAMEIMA, "",                     520,137,412,24, tex->ima->name, 0.0, 79.0, 0, 0, "Texture name");
+                               sprintf(str, "%d", tex->ima->id.us);
+                               uiDefBut(block, BUT, 0, str,                                    934,137,23,24, 0, 0, 0, 0, 0, "Number of users");
+                               uiDefBut(block, BUT, B_RELOADIMA, "Reload",     986,137,68,24, 0, 0, 0, 0, 0, "Reload");
 
-       if (!slink) return;
-               
-       stmp= slink->scripts;           
-       slink->scripts= MEM_mallocN(sizeof(ID*)*(slink->totscript+1), "scriptlistL");
+                               if (tex->ima->packedfile) {
+                                       packdummy = 1;
+                               } else {
+                                       packdummy = 0;
+                               }
+                               uiDefIconButI(block, TOG|BIT|0, B_PACKIMA, ICON_PACKAGE,        960,137,24,24, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Image");
+                       }
+                       
+                       uiBlockSetCol(block, BUTGREEN);
+                       
+                       uiDefButS(block, TOG|BIT|0, 0, "InterPol",                      350, 170, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Interpolate pixels of the image");
+                       uiDefButS(block, TOG|BIT|1, B_MATPRV, "UseAlpha",       425, 170, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Use the alpha layer");
+                       uiDefButS(block, TOG|BIT|5, B_MATPRV, "CalcAlpha",      500, 170, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Calculate an alpha based on the RGB");
+                       uiDefButS(block, TOG|BIT|2, B_MATPRV, "NegAlpha",       575, 170, 75, 18, &tex->flag, 0, 0, 0, 0, "Reverse the alpha value");
+                       uiDefButS(block, TOG|BIT|2, B_IMAPTEST, "MipMap",       650, 170, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Generate a series of pictures used for mipmapping");
+                       uiDefButS(block, TOG|BIT|3, B_IMAPTEST, "Fields",       725, 170, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Work with field images");
+                       uiDefButS(block, TOG|BIT|4, B_MATPRV, "Rot90",          800, 170, 50, 18, &tex->imaflag, 0, 0, 0, 0, "Rotate image 90 degrees when rendered");
+                       uiDefButS(block, TOG|BIT|7, B_RELOADIMA, "Movie",       850, 170, 50, 18, &tex->imaflag, 0, 0, 0, 0, "Use a movie for an image");
+                       uiDefButS(block, TOG|BIT|8, 0, "Anti",                          900, 170, 50, 18, &tex->imaflag, 0, 0, 0, 0, "Use anti-aliasing");
+                       uiDefButS(block, TOG|BIT|10, 0, "StField",                      950, 170, 50, 18, &tex->imaflag, 0, 0, 0, 0, "");
+                       
+                       uiBlockSetCol(block, BUTGREY);
        
-       ftmp= slink->flag;              
-       slink->flag= MEM_mallocN(sizeof(short*)*(slink->totscript+1), "scriptlistF");
+                       /* print amount of frames anim */
+                       if(tex->ima && tex->ima->anim) {
+                               uiDefBut(block, BUT, B_TEXSETFRAMES, "<",      802, 110, 20, 18, 0, 0, 0, 0, 0, "Paste number of frames in Frames: button");
+                               sprintf(str, "%d frs  ", IMB_anim_get_duration(tex->ima->anim));
+                               uiDefBut(block, LABEL, 0, str,      834, 110, 90, 18, 0, 0, 0, 0, 0, "");
+                               sprintf(str, "%d cur  ", tex->ima->lastframe);
+                               uiDefBut(block, LABEL, 0, str,      834, 90, 90, 18, 0, 0, 0, 0, 0, "");
+                       }
+                       
+                       
+               }
+               else if(tex->type==TEX_PLUGIN) {
+                       if(tex->plugin && tex->plugin->doit) {
+                               
+                               pit= tex->plugin;
        
-       if (slink->totscript) {
-               memcpy(slink->scripts, stmp, sizeof(ID*)*(slink->totscript));
-               MEM_freeN(stmp);
-
-               memcpy(slink->flag, ftmp, sizeof(short)*(slink->totscript));
-               MEM_freeN(ftmp);
-       }
-
-       slink->scripts[slink->totscript]= NULL;
-       slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
-
-       slink->totscript++;
+                               uiBlockSetCol(block, BUTGREEN);
+                               for(a=0; a<pit->stypes; a++) {
+                                       uiDefButS(block, ROW, B_MATPRV, pit->stnames+16*a, (short)(350+75*a), 170, 75, 18, &tex->stype, 2.0, (float)a, 0, 0, "");
+                               }
                                
-       if(slink->actscript<1) slink->actscript=1;
-}
+                               uiBlockSetCol(block, BUTGREY);
+                               varstr= pit->varstr;
+                               if(varstr) {
+                                       for(a=0; a<pit->vars; a++, varstr++) {
+                                               xco= 350 + 140*(a/6);
+                                               yco= 110 - 20*(a % 6);
+                                               pit->data[a] = varstr->def;
+                                               uiDefBut(block, varstr->type, B_PLUGBUT+a, varstr->name, (short)xco,(short)yco,137,19, &(pit->data[a]), varstr->min, varstr->max, 100, 0, varstr->tip);
+                                       }
+                               }
+                               uiDefBut(block, TEX, B_NAMEPLUGIN, "",                  520,137,412,24, pit->name, 0.0, 159.0, 0, 0, "Browse");
+                       }
+       
+                       uiBlockSetCol(block, BUTSALMON);
+                       uiDefBut(block, BUT, B_LOADPLUGIN, "Load Plugin", 350,137,137,24, 0, 0, 0, 0, 0, "");
+                       
+               }
+               else if(tex->type==TEX_ENVMAP) {
+                       
+                       if(tex->env==0) {
+                               tex->env= RE_add_envmap();
+                               tex->env->object= OBACT;
+                       }
+                       if(tex->env) {
+                               env= tex->env;
+                               
+                               uiBlockSetCol(block, BUTGREEN);
+                               uiDefButS(block, ROW, B_REDR,   "Static", 350, 170, 75, 18, &env->stype, 2.0, 0.0, 0, 0, "Calculate map only once");
+                               uiDefButS(block, ROW, B_REDR,   "Anim", 425, 170, 75, 18, &env->stype, 2.0, 1.0, 0, 0, "Calculate map each rendering");
+                               uiDefButS(block, ROW, B_ENV_FREE, "Load", 500, 170, 75, 18, &env->stype, 2.0, 2.0, 0, 0, "Load map from disk");
+                               
+                               if(env->stype==ENV_LOAD) {
+                                       uiBlockSetCol(block, BUTSALMON);
+                                       uiDefBut(block, BUT, B_LOADTEXIMA, "Load Image", 350,137,132,24, 0, 0, 0, 0, 0, "Load image - thumbnail view");
+                                       uiBlockSetCol(block, BUTGREY);
+                                       uiDefBut(block, BUT, B_LOADTEXIMA1, "", 485,137,10,24, 0, 0, 0, 0, 0, "Load image - file view");
+                                       
+                                       id= (ID *)tex->ima;
+                                       IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->image), id, &(G.buts->menunr));
+                                       if(strp[0])
+                                               uiDefButS(block, MENU, B_TEXIMABROWSE, strp, 496,137,23,24, &(G.buts->menunr), 0, 0, 0, 0, "");
+                                       MEM_freeN(strp);
+       
+                                       if(tex->ima) {
+                                               uiDefBut(block, TEX, B_NAMEIMA, "",                     520,137,412,24, tex->ima->name, 0.0, 79.0, 0, 0, "");
+                                               sprintf(str, "%d", tex->ima->id.us);
+                                               uiDefBut(block, BUT, 0, str,                                    934,137,23,24, 0, 0, 0, 0, 0, "");
+                                               if (tex->ima->packedfile) {
+                                                       packdummy = 1;
+                                               } else {
+                                                       packdummy = 0;
+                                               }
+                                               uiDefIconButI(block, TOG|BIT|0, B_PACKIMA, ICON_PACKAGE,        960,137,24,24, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Image");
+                                               uiDefBut(block, BUT, B_RELOADIMA, "Reload",     986,137,68,24, 0, 0, 0, 0, 0, "");
+                                       }
+                               }
+                               else {
+                                       uiBlockSetCol(block, BUTSALMON);
+                                       uiDefBut(block, BUT, B_ENV_FREE, "Free Data", 350,137,107,24, 0, 0, 0, 0, 0, "Release all images associated with environment map");
+                                       uiBlockSetCol(block, BUTGREY);
+                                       uiDefBut(block, BUT, B_ENV_SAVE, "Save EnvMap", 461,137,115,24, 0, 0, 0, 0, 0, "Save environment map");
+                                       uiBlockSetCol(block, BUTSALMON);
+                                       uiDefBut(block, BUT, B_ENV_FREE_ALL, "Free all EnvMaps", 600,137,160,24, 0, 0, 0, 0, 0, "Frees all rendered environment maps");
+                               }
+                               uiBlockSetCol(block, BUTGREY);
+                               uiDefIDPoinBut(block, test_obpoin_but, B_ENV_OB, "Ob:",   350,95,166,24, &(env->object), "Object name");
+                               uiDefButF(block, NUM, B_MATPRV, "Filter :",                               518,95,120,24, &tex->filtersize, 0.1, 25.0, 0, 0, "Adjust sharpness or blurriness of the reflection"),
+                               uiDefButS(block, NUM, B_ENV_FREE, "Depth:",                               640,95,120,24, &env->depth, 0, 5.0, 0, 0, "Number of times a map gets rendered again, for recursive mirror effect"),
 
-static void delete_scriptlink(ScriptLink *slink)
-{
-       int i;
+                               uiDefButF(block, NUM, REDRAWVIEW3D,     "ClipSta",              350,68,122,24, &env->clipsta, 0.01, 50.0, 100, 0, "Set start value for clipping");
+                               uiDefButF(block, NUM, 0,        "ClipEnd",                                      475,68,142,24, &env->clipend, 0.1, 5000.0, 1000, 0, "Set end value for clipping");
+                               if(env->stype!=ENV_LOAD) uiDefButS(block, NUM, B_ENV_FREE,      "CubeRes", 620,68,140,24, &env->cuberes, 50, 2048.0, 0, 0, "Set the resolution in pixels");
        
-       if (!slink) return;
+                               uiDefBut(block, LABEL, 0, "Don't render layer:",                772,100,140,22, 0, 0.0, 0.0, 0, 0, ""); 
+                               xco= 772;
+                               dx= 28;
+                               dy= 26;
+                               for(a=0; a<10; a++) {
+                                       uiDefButI(block, TOG|BIT|(a+10), 0, "",(short)(xco+a*(dx/2)), 68, (short)(dx/2), (short)(dy/2), &env->notlay, 0, 0, 0, 0, "Render this layer");
+                                       uiDefButI(block, TOG|BIT|a, 0, "",      (short)(xco+a*(dx/2)), (short)(68+dy/2), (short)(dx/2), (short)(1+dy/2), &env->notlay, 0, 0, 0, 0, "Render this layer");
+                                       if(a==4) xco+= 5;
+                               }
        
-       if (slink->totscript>0) {
-               for (i=slink->actscript-1; i<slink->totscript-1; i++) {
-                       slink->flag[i]= slink->flag[i+1];
-                       slink->scripts[i]= slink->scripts[i+1];
+                       }
+               }
+       
+               /* COLORBAND */
+               uiBlockSetCol(block, BUTSALMON);
+               uiDefButS(block, TOG|BIT|0, B_COLORBAND, "Colorband",           923,103,102,20, &tex->flag, 0, 0, 0, 0, "Use colorband");
+               if(tex->flag & TEX_COLORBAND) {
+                       uiDefBut(block, BUT, B_ADDCOLORBAND, "Add",                             1029,103,50,20, 0, 0, 0, 0, 0, "Add new colour to the colorband");
+                       uiDefBut(block, BUT, B_DELCOLORBAND, "Del",                             1218,104,50,20, 0, 0, 0, 0, 0, "Delete the active colour");
+                       uiBlockSetCol(block, BUTPURPLE);
+                       uiDefButS(block, NUM, B_REDR,           "Cur:",                         1082,104,132,20, &tex->coba->cur, 0.0, (float)(tex->coba->tot-1), 0, 0, "The active colour from the colorband");
+       
+                       uiDefBut(block, LABEL, B_DOCOLORBAND, "", 923,81,345,20, 0, 0, 0, 0, 0, "Colorband"); /* only for event! */
+                       
+                       drawcolorband(tex->coba, 923,81,345,20);
+                       cbd= tex->coba->data + tex->coba->cur;
+                       
+                       uiDefButF(block, NUM, B_CALCCBAND, "Pos",                       923,59,89,20, &cbd->pos, 0.0, 1.0, 10, 0, "Set the position of the active colour");
+                       uiBlockSetCol(block, BUTGREEN);
+                       uiDefButS(block, ROW, B_REDRAWCBAND, "E",               1013,59,20,20, &tex->coba->ipotype, 5.0, 1.0, 0, 0, "Interpolation type Ease");
+                       uiDefButS(block, ROW, B_REDRAWCBAND, "L",               1033,59,20,20, &tex->coba->ipotype, 5.0, 0.0, 0, 0, "Interpolation type Linear");
+                       uiDefButS(block, ROW, B_REDRAWCBAND, "S",               1053,59,20,20, &tex->coba->ipotype, 5.0, 2.0, 0, 0, "Interpolation type Spline");
+                       uiBlockSetCol(block, BUTPURPLE);
+                       uiDefButF(block, COL, B_BANDCOL, "",                                    1076,59,28,20, &(cbd->r), 0, 0, 0, 0, "");
+                       uiDefButF(block, NUMSLI, B_REDRAWCBAND, "A ",                   1107,58,163,20, &cbd->a, 0.0, 1.0, 0, 0, "Set the alpha value");
+                       
+                       uiDefButF(block, NUMSLI, B_REDRAWCBAND, "R ",                   923,37,116,20, &cbd->r, 0.0, 1.0, B_BANDCOL, 0, "Set the red value");
+                       uiDefButF(block, NUMSLI, B_REDRAWCBAND, "G ",                   1042,37,111,20, &cbd->g, 0.0, 1.0, B_BANDCOL, 0, "Set the green value");
+                       uiDefButF(block, NUMSLI, B_REDRAWCBAND, "B ",                   1156,36,115,20, &cbd->b, 0.0, 1.0, B_BANDCOL, 0, "Set the blue value");
+                       
                }
+       
+       
+               /* RGB-BRICON */
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButF(block, NUMSLI, B_MATPRV, "Bright",                    923,11,166,20, &tex->bright, 0.0, 2.0, 0, 0, "Set the brightness of the colour or intensity of a texture");
                
-               slink->totscript--;
+               uiDefButF(block, NUMSLI, B_MATPRV, "Contr",                     1093,11,180,20, &tex->contrast, 0.01, 2.0, 0, 0, "Set the contrast of the colour or intensity of a texture");
+       
+               if((tex->flag & TEX_COLORBAND)==0) {
+                       uiDefButF(block, NUMSLI, B_MATPRV, "R ",                        923,37,116,20, &tex->rfac, 0.0, 2.0, 0, 0, "Set the red value");
+                       uiDefButF(block, NUMSLI, B_MATPRV, "G ",                        1042,37,111,20, &tex->gfac, 0.0, 2.0, 0, 0, "Set the green value");
+                       uiDefButF(block, NUMSLI, B_MATPRV, "B ",                        1156,36,115,20, &tex->bfac, 0.0, 2.0, 0, 0, "Set the blue value");
+               }
        }
-               
-       CLAMP(slink->actscript, 1, slink->totscript);
-               
-       if (slink->totscript==0) {
-               if (slink->scripts) MEM_freeN(slink->scripts);
-               if (slink->flag) MEM_freeN(slink->flag);
+       
+       /* PREVIEW RENDER */
+       
+       BIF_previewdraw(G.buts);
 
-               slink->scripts= NULL;
-               slink->flag= NULL;
-               slink->totscript= slink->actscript= 0;                  
-       }
+       uiDrawBlock(block);
 }
 
-void do_scriptbuts(short event)
-{
-       Object *ob=NULL;
-       ScriptLink *script=NULL;
-       Material *ma;
-       
-       switch (event) {
-       case B_SSCRIPT_ADD:
-               extend_scriptlink(&G.scene->scriptlink);
-               break;
-       case B_SSCRIPT_DEL:
-               delete_scriptlink(&G.scene->scriptlink);
-               break;
-               
-       case B_SCRIPT_ADD:
-       case B_SCRIPT_DEL:
-               ob= OBACT;
-
-               if (ob && G.buts->scriptblock==ID_OB) {
-                               script= &ob->scriptlink;
+/* ****************************** MATERIAL ************************ */
+MTex mtexcopybuf;
 
-               } else if (ob && G.buts->scriptblock==ID_MA) {
-                       ma= give_current_material(ob, ob->actcol);
-                       if (ma) script= &ma->scriptlink;
 
-               } else if (ob && G.buts->scriptblock==ID_CA) {
-                       if (ob->type==OB_CAMERA)
-                               script= &((Camera *)ob->data)->scriptlink;
+void do_matbuts(unsigned short event)
+{
+       static short mtexcopied=0;
+       Material *ma;
+       MTex *mtex;
 
-               } else if (ob && G.buts->scriptblock==ID_LA) {
-                       if (ob->type==OB_LAMP)
-                               script= &((Lamp *)ob->data)->scriptlink;
+       switch(event) {         
+       case B_ACTCOL:
+               scrarea_queue_headredraw(curarea);
+               allqueue(REDRAWBUTSMAT, 0);
+               allqueue(REDRAWIPO, 0);
+               BIF_preview_changed(G.buts);
+               break;
+       case B_MATFROM:
 
-               } else if (G.buts->scriptblock==ID_WO) {
-                       if (G.scene->world) 
-                               script= &(G.scene->world->scriptlink);
+               scrarea_queue_headredraw(curarea);
+               allqueue(REDRAWBUTSMAT, 0);
+               BIF_previewdraw(G.buts);
+               break;
+       case B_MATPRV:
+               /* this event also used by lamp, tex and sky */
+               BIF_preview_changed(G.buts);
+               break;
+       case B_MATPRV_DRAW:
+               BIF_preview_changed(G.buts);
+               allqueue(REDRAWBUTSMAT, 0);
+               break;
+       case B_TEXCLEAR:
+               ma= G.buts->lockpoin;
+               mtex= ma->mtex[(int) ma->texact ];
+               if(mtex) {
+                       if(mtex->tex) mtex->tex->id.us--;
+                       MEM_freeN(mtex);
+                       ma->mtex[ (int) ma->texact ]= 0;
+                       allqueue(REDRAWBUTSMAT, 0);
+                       allqueue(REDRAWOOPS, 0);
+                       BIF_preview_changed(G.buts);
                }
-               
-               if (event==B_SCRIPT_ADD) extend_scriptlink(script);
-               else delete_scriptlink(script);
-               
                break;
-       default:
+       case B_MTEXCOPY:
+               ma= G.buts->lockpoin;
+               if(ma && ma->mtex[(int)ma->texact] ) {
+                       mtex= ma->mtex[(int)ma->texact];
+                       if(mtex->tex==0) {
+                               error("No texture available");
+                       }
+                       else {
+                               memcpy(&mtexcopybuf, ma->mtex[(int)ma->texact], sizeof(MTex));
+                               notice("copied!");
+                               mtexcopied= 1;
+                       }
+               }
                break;
-       }
-
-       allqueue(REDRAWBUTSSCRIPT, 0);
-}
-
-void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int scene) 
-{
-       char str[256];
-
-       uiBlockSetCol(block, BUTGREY);
-
-       if (script->totscript) {
-               strcpy(str, "FrameChanged%x 1|");
-               strcat(str, "Redraw%x 4|");
-               if (scene) {
-                       strcat(str, "OnLoad%x 2");
+       case B_MTEXPASTE:
+               ma= G.buts->lockpoin;
+               if(ma && mtexcopied && mtexcopybuf.tex) {
+                       if(ma->mtex[(int)ma->texact]==0 ) ma->mtex[(int)ma->texact]= MEM_mallocN(sizeof(MTex), "mtex"); 
+                       memcpy(ma->mtex[(int)ma->texact], &mtexcopybuf, sizeof(MTex));
+                       
+                       id_us_plus((ID *)mtexcopybuf.tex);
+                       notice("pasted!");
+                       BIF_preview_changed(G.buts);
+                       scrarea_queue_winredraw(curarea);
+               }
+               break;
+       case B_MATLAY:
+               ma= G.buts->lockpoin;
+               if(ma && ma->lay==0) {
+                       ma->lay= 1;
+                       scrarea_queue_winredraw(curarea);
                }
-
-               uiDefButS(block, MENU, 1, str, (short)sx, (short)sy, 148, 19, &script->flag[script->actscript-1], 0, 0, 0, 0, "Script links for the Frame changed event");
-
-               uiDefIDPoinBut(block, test_scriptpoin_but, 1, "", (short)(sx+150),(short)sy, 98, 19, &script->scripts[script->actscript-1], "Name of Script to link");
        }
-
-       sprintf(str,"%d Scr:", script->totscript);
-       uiDefButS(block, NUM, REDRAWBUTSSCRIPT, str, (short)(sx+250), (short)sy,98,19, &script->actscript, 1, script->totscript, 0, 0, "Total / Active Script link (LeftMouse + Drag to change)");
-
-       uiBlockSetCol(block, BUTSALMON);
-
-       if (scene) {
-               if (script->totscript<32767) 
-                       uiDefBut(block, BUT, B_SSCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
-               if (script->totscript) 
-                       uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
-       } else {
-               if (script->totscript<32767) 
-                       uiDefBut(block, BUT, B_SCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
-               if (script->totscript) 
-                       uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
-       }               
 }
 
-void scriptbuts(void)
+void matbuts(void)
 {
-       Object *ob=NULL;
-       ScriptLink *script=NULL;
+       Object *ob;
        Material *ma;
+       ID *id, *idn;
+       MTex *mtex;
        uiBlock *block;
-       char str[64];
+       uiBut *but;
+       float *colpoin = NULL, min;
+       int rgbsel = 0, a, loos;
+       char str[30], *strp;
+       short xco;
        
        ob= OBACT;
+       if(ob==0 || ob->data==0) return;
 
        sprintf(str, "buttonswin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
 
-       if (ob && G.buts->scriptblock==ID_OB) {
-               script= &ob->scriptlink;
-               
-       } else if (ob && G.buts->scriptblock==ID_MA) {
-               ma= give_current_material(ob, ob->actcol);
-               if (ma) script= &ma->scriptlink;
-               
-       } else if (ob && G.buts->scriptblock==ID_CA) {
-               if (ob->type==OB_CAMERA)
-                       script= &((Camera *)ob->data)->scriptlink;
-                       
-       } else if (ob && G.buts->scriptblock==ID_LA) {
-               if (ob->type==OB_LAMP)
-                       script= &((Lamp *)ob->data)->scriptlink;
-
-       } else if (G.buts->scriptblock==ID_WO) {
-               if (G.scene->world)
-                       script= &(G.scene->world->scriptlink);
-       }
-
-       if (script) draw_scriptlink(block, script, 25, 180, 0);                 
+       if(ob->actcol==0) ob->actcol= 1;        /* because of TOG|BIT button */
        
-       /* EVENTS */
-       draw_buttons_edge(curarea->win, 540);
-
-       draw_scriptlink(block, &G.scene->scriptlink, 600, 180, 1);
-
-       uiDrawBlock(block);
-}
+       /* indicate which one is linking a material */
+       uiBlockSetCol(block, BUTSALMON);
+       uiDefButS(block, TOG|BIT|(ob->actcol-1), B_MATFROM, "OB",       342, 195, 33, 20, &ob->colbits, 0, 0, 0, 0, "Link material to object");
+       idn= ob->data;
+       strncpy(str, idn->name, 2);
+       str[2]= 0;
+       uiBlockSetCol(block, BUTGREEN);
+       uiDefButS(block, TOGN|BIT|(ob->actcol-1), B_MATFROM, str,               380, 195, 33, 20, &ob->colbits, 0, 0, 0, 0, "Show the block the material is linked to");
+       uiBlockSetCol(block, BUTGREY);
+       
+       /* id is the block from which the material is used */
+       if( BTST(ob->colbits, ob->actcol-1) ) id= (ID *)ob;
+       else id= ob->data;
 
-/* *************************** IKA ******************************** */
-/* is this number used elsewhere? */
-/*  static int ika_del_number; */
-void do_ikabuts(unsigned short event)
-{
-       Base *base;
-       Object *ob;
+       sprintf(str, "%d Mat", ob->totcol);
+       if(ob->totcol) min= 1.0; else min= 0.0;
+       uiDefButC(block, NUM, B_ACTCOL, str,    415,195,150,20, &(ob->actcol), min, (float)ob->totcol, 0, 0, "Number of materials on object / Active material");
        
-       ob= OBACT;
+       uiSetButLock(id->lib!=0, "Can't edit library data");
        
-       switch(event) {
-       case B_IKASETREF:
-               base= FIRSTBASE;
-               while(base) {
-                       if TESTBASELIB(base) {
-                               if(base->object->type==OB_IKA) init_defstate_ika(base->object);
-                       }
-                       base= base->next;
-               }
-               break;  
-       case B_IKARECALC:
-               itterate_ika(ob);
-               break;
-       }
-}
+       strncpy(str, id->name, 2);
+       str[2]= ':'; str[3]= 0;
+       but= uiDefBut(block, TEX, B_IDNAME, str,                200,195,140,20, id->name+2, 0.0, 18.0, 0, 0, "Show the block the material is linked to");
+       uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
 
-void ikabuts(void)
-{
-       Ika *ika;
-       Object *ob;
-       Limb *li;
-       Deform *def;
-       uiBlock *block;
-       int nr, cury, nlimbs;
-       char str[32];
+       if(ob->totcol==0) {
+               uiDrawBlock(block);
+               return;
+       }
        
-       ob= OBACT;
-       if(ob==0) return;
-
-       sprintf(str, "editbuttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
-
-       ika= ob->data;
+       ma= give_current_material(ob, ob->actcol);
+       
+       if(ma==0) {
+               uiDrawBlock(block);
+               return;
+       }
+       uiSetButLock(ma->id.lib!=0, "Can't edit library data");
        
-       uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block, BUT, B_IKASETREF,       "Set Reference",470,180,200,20, 0, 0, 0, 0, 0, "");
-
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, TOG|BIT|1, B_DIFF, "Lock XY Plane",    470,140,200,20, &ika->flag, 0.0, 1.0, 0, 0, "New IK option: allows both X and Y axes to rotate");
        uiBlockSetCol(block, BUTGREY);
-       uiDefButF(block, NUM, B_DIFF, "XY constraint ",         470,120,200,20, &ika->xyconstraint, 0.0, 1.0, 100, 0, "Constrain in radians");
-
-       uiDefButF(block, NUMSLI, B_DIFF, "Mem ",                                470,80,200,20, &ika->mem, 0.0, 1.0, 0, 0, "");
-       uiDefButS(block, NUM, B_DIFF, "Iter: ",                         470,60,200,20, &ika->iter, 2.0, 16.0, 0, 0, "");
-
-
-       uiBlockSetCol(block, BUTGREY);
-
-       uiDefBut(block, LABEL, 0, "Limb Weight",                        680, 200, 150, 19, 0, 0, 0, 0, 0, "");
-       cury= 180;
-       li= ika->limbbase.first;
-
-       nlimbs= BLI_countlist(&ika->limbbase);
+       uiDefButS(block, ROW, REDRAWBUTSMAT, "RGB",                     200,166,35,22, &(ma->colormodel), 1.0, (float)MA_RGB, 0, 0, "Create colour by red, green and blue");
+       uiDefButS(block, ROW, REDRAWBUTSMAT, "HSV",                     200,143,35,22, &(ma->colormodel), 1.0, (float)MA_HSV, 0, 0, "Mix colour with hue, saturation and value");
+       uiDefButS(block, TOG|BIT|0, REDRAWBUTSMAT, "DYN",       200,120,35,22, &(ma->dynamode), 0.0, 0.0, 0, 0, "Adjust parameters for dynamics options");
+       
+       if(ma->dynamode & MA_DRAW_DYNABUTS) {
+               uiDefButF(block, NUMSLI, 0, "Restitut ",                390,168,175,21, &ma->reflect, 0.0, 1.0, 0, 0, "Elasticity of collisions");
+               uiDefButF(block, NUMSLI, 0, "Friction ",                390,144,175,21, &ma->friction, 0.0, 100.0, 0, 0,   "Coulomb friction coefficient");
 
-       for (nr = 0; nr < nlimbs; nr++) {
-               sprintf(str, "Limb %d:", nr);
-               uiDefButF(block, NUM, B_DIFF, str, 680, (short)cury, 150, 19, &li->fac, 0.01, 1.0, 10, 0, "");
-               cury-= 20;
-               li= li->next;
+               uiDefButF(block, NUMSLI, 0, "Fh Force ",                390,120,175,21, &ma->fh, 0.0, 1.0, 0, 0, "Upward spring force within the Fh area");
+               uiDefButF(block, NUM, 0,         "Fh Damp ",            260,144,120,21, &ma->xyfrict, 0.0, 1.0, 10, 0, "Damping of the Fh spring force");
+               uiDefButF(block, NUM, 0, "Fh Dist ",                    260,120,120,21, &ma->fhdist, 0.0, 20.0, 10, 0, "Height of the Fh area");
+               uiBlockSetCol(block, BUTGREEN);
+               uiDefButS(block, TOG|BIT|1, 0, "Fh Norm",               260,168,120,21, &ma->dynamode, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
+               uiBlockSetCol(block, BUTGREY);
        }
-
-       
-       
-       uiDefBut(block, LABEL, 0, "Deform Max Dist",    955, 200, 140, 19, 0, 0, 0, 0, 0, "");
-       uiDefBut(block, LABEL, 0, "Deform Weight",      1095, 200, 140, 19, 0, 0, 0, 0, 0, "");
+       else {
+               uiDefButF(block, COL, B_MIRCOL, "",             235,143,30,45, &(ma->mirr), 0, 0, 0, 0, "");
+               uiDefButF(block, COL, B_SPECCOL, "",    265,143,39,45, &(ma->specr), 0, 0, 0, 0, "");
+               uiDefButF(block, COL, B_MATCOL, "",             304,143,39,45, &(ma->r), 0, 0, 0, 0, "");
        
-
-       cury= 180;
-       def= ika->def;
-       for (nr = 0; nr < ika->totdef; nr++) {
-               def = ika->def+nr;
-               if(def->ob) {
-                       if(def->ob->type!=OB_IKA) sprintf(str, "%s   :", def->ob->id.name+2);
-                       else sprintf(str, "%s (%d):", def->ob->id.name+2, def->par1);
+               if(ma->mode & MA_HALO) {
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Ring",            235,120,30,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Mix the colour of the rings with the RGB sliders");
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Line",            265,120,39,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Mix the colour of the lines with the RGB sliders");
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Halo",            304,120,39,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Mix the colour of the halo with the RGB sliders");
+               }
+               else {
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Mir",                     235,120,30,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Use mirror colour");
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Spe",                     265,120,39,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Set the colour of the specularity");
+                       uiDefButC(block, ROW, REDRAWBUTSMAT, "Col",                     304,120,39,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Set the basic colour of the material");
                }
+               if(ma->rgbsel==0) {colpoin= &(ma->r); rgbsel= B_MATCOL;}
+               else if(ma->rgbsel==1) {colpoin= &(ma->specr); rgbsel= B_SPECCOL;}
+               else if(ma->rgbsel==2) {colpoin= &(ma->mirr); rgbsel= B_MIRCOL;}
                
-               uiDefBut(block, LABEL, 0, str,                  855, (short)cury, 100, 19, 0, 0.01, 0.0, 0, 0, "");
-               uiDefButF(block, NUM, B_DIFF, "",       955, (short)cury, 140, 19, &def->dist, 0.0, 40.0, 100, 0, "Beyond this distance the Limb doesn't influence deformation. '0.0' is global influence.");
-               uiDefButF(block, NUM, B_DIFF, "",       1095,(short)cury, 140, 19, &def->fac, 0.01, 10.0, 10, 0, "");
-
-               cury-= 20;
-       }
-       uiDrawBlock(block);
-}
-
-/* *************************** LATTICE ******************************** */
-
-void do_latticebuts(unsigned short event)
-{
-       Object *ob;
-       Lattice *lt;
-       
-       ob= OBACT;
-       
-       switch(event) {
-       case B_RESIZELAT:
-               if(ob) {
-                       if(ob==G.obedit) resizelattice(editLatt);
-                       else resizelattice(ob->data);
+               if(ma->rgbsel==0 && (ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE) && !(ma->mode & MA_HALO)));
+               else if(ma->colormodel==MA_HSV) {
+                       uiBlockSetCol(block, BUTPURPLE);
+                       uiDefButF(block, HSVSLI, B_MATPRV, "H ",                        350,168,150,21, colpoin, 0.0, 0.9999, rgbsel, 0, "");
+                       uiBlockSetCol(block, BUTPURPLE);
+                       uiDefButF(block, HSVSLI, B_MATPRV, "S ",                        350,144,150,21, colpoin, 0.0001, 1.0, rgbsel, 0, "");
+                       uiBlockSetCol(block, BUTPURPLE);
+                       uiDefButF(block, HSVSLI, B_MATPRV, "V ",                        350,120,150,21, colpoin, 0.0001, 1.0, rgbsel, 0, "");
+                       uiBlockSetCol(block, BUTGREY);
                }
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_DRAWLAT:
-               if(ob==G.obedit) calc_lattverts_ext();
-               allqueue(REDRAWVIEW3D, 0);
-               break;
-       case B_LATTCHANGED:
+               else {
+                       uiDefButF(block, NUMSLI, B_MATPRV, "R ",                        350,168,150,21, colpoin, 0.0, 1.0, rgbsel, 0, "");
+                       uiDefButF(block, NUMSLI, B_MATPRV, "G ",                        350,144,150,21, colpoin+1, 0.0, 1.0, rgbsel, 0, "");
+                       uiDefButF(block, NUMSLI, B_MATPRV, "B ",                        350,120,150,21, colpoin+2, 0.0, 1.0, rgbsel, 0, "");
+               }
+               if(!(ma->mode & MA_HALO)) {
+                       uiBlockSetCol(block, BUTBLUE);
+                       uiDefButI(block, TOG|BIT|4, B_REDR,     "VCol Light",           505, 168, 60, 21, &(ma->mode), 0, 0, 0, 0, "Add vertex colours as extra light");
+                       uiDefButI(block, TOG|BIT|7, B_REDR, "VCol Paint",               505, 144, 60, 21, &(ma->mode), 0, 0, 0, 0, "Replace basic colours with vertex colours");
+                       uiDefButI(block, TOG|BIT|11, B_REDR, "TexFace",                 505, 120, 60, 21, &(ma->mode), 0, 0, 0, 0, "UV-Editor assigned texture gives color and texture info for the faces");
+               }
+       }
+       if(ma->mode & MA_HALO) {
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButF(block, NUM, B_MATPRV, "HaloSize: ",           200,90,175,18, &(ma->hasize), 0.0, 100.0, 10, 0, "Set the dimension of the halo");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Alpha ",            200,50,175,18, &(ma->alpha), 0.0, 1.0, 0, 0, "Set the degree of coverage");
+               uiDefButS(block, NUMSLI, B_MATPRV, "Hard ",                     200,30,175,18, &(ma->har), 1.0, 127.0, 0, 0, "Set the hardness of the halo");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Add  ",                     200,10,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Strength of the add effect");
                
-               lt= ob->data;
-               if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
+               uiDefButS(block, NUM, B_MATPRV, "Rings: ",                      380,90,85,18, &(ma->ringc), 0.0, 24.0, 0, 0, "Set the number of rings rendered over the basic halo");
+               uiDefButS(block, NUM, B_MATPRV, "Lines: ",                      465,90,90,18, &(ma->linec), 0.0, 250.0, 0, 0, "Set the number of star shaped lines rendered over the halo");
+               uiDefButS(block, NUM, B_MATPRV, "Star: ",                       380,70,85,18, &(ma->starc), 3.0, 50.0, 0, 0, "Set the number of points on the star shaped halo");
+               uiDefButC(block, NUM, B_MATPRV, "Seed: ",                       465,70,90,18, &(ma->seed1), 0.0, 255.0, 0, 0, "Use random values for ring dimension and line location");
                
-               make_displists_by_parent(ob);
+               uiDefButF(block, NUM, B_MATPRV, "FlareSize: ",          380,50,85,18, &(ma->flaresize), 0.1, 25.0, 10, 0, "Set the factor the flare is larger than the halo");
+               uiDefButF(block, NUM, B_MATPRV, "Sub Size: ",           465,50,90,18, &(ma->subsize), 0.1, 25.0, 10, 0, "Set the dimension of the subflares, dots and circles");
+               uiDefButF(block, NUM, B_MATPRV, "FlareBoost: ",         380,30,175,18, &(ma->flareboost), 0.1, 10.0, 10, 0, "Give the flare extra strength");
+               uiDefButC(block, NUM, B_MATPRV, "Fl.seed: ",            380,10,85,18, &(ma->seed2), 0.0, 255.0, 0, 0, "Specify an offset in the seed table");
+               uiDefButS(block, NUM, B_MATPRV, "Flares: ",                     465,10,90,18, &(ma->flarec), 1.0, 32.0, 0, 0, "Set the nuber of subflares");
 
-               allqueue(REDRAWVIEW3D, 0);
+               uiBlockSetCol(block, BUTBLUE);
                
-               break;
+               uiDefButI(block, TOG|BIT|15, B_MATPRV, "Flare",         576, 181, 77, 36, &(ma->mode), 0, 0, 0, 0, "Render halo as a lensflare");
+               uiDefButI(block, TOG|BIT|8, B_MATPRV, "Rings",          576, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render rings over basic halo");
+               uiDefButI(block, TOG|BIT|9, B_MATPRV, "Lines",          576, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render star shaped lines over the basic halo");
+               uiDefButI(block, TOG|BIT|11, B_MATPRV, "Star",          576, 105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render halo as a star");
+               uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo",      576, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo");
+               
+               uiDefButI(block, TOG|BIT|12, B_MATPRV, "HaloTex",       576, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Give halo a texture");
+               uiDefButI(block, TOG|BIT|13, B_MATPRV, "HaloPuno",      576, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use the vertex normal to specify the dimension of the halo");
+               uiDefButI(block, TOG|BIT|10, B_MATPRV, "X Alpha",       576, 28, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use extreme alpha");
+               uiDefButI(block, TOG|BIT|14, B_MATPRV, "Shaded",        576, 10, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let halo receive light");
        }
-}
+       else {
+               char *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2";
+               char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3";
+               
+               /* shader buttons */
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButS(block, MENU, B_MATPRV_DRAW, str1,             200,90,95,18, &(ma->diff_shader), 0.0, 0.0, 0, 0, "Set a diffuse shader");
+               uiDefButS(block, MENU, B_MATPRV_DRAW, str2,             295,90,90,18, &(ma->spec_shader), 0.0, 0.0, 0, 0, "Set a specular shader");
 
-void latticebuts(void)
-{
-       Lattice *lt;
-       Object *ob;
-       uiBlock *block;
-       char str[64];
-       
-       ob= OBACT;
-       if(ob==0) return;
+               if(ma->diff_shader==MA_DIFF_ORENNAYAR)
+                       uiDefButF(block, NUM, B_MATPRV, "Rough:",               200, 70, 95,18, &(ma->roughness), 0.0, 3.14, 0, 0, "Oren Nayar Roughness");
+               else if(ma->diff_shader==MA_DIFF_TOON) {
+                       uiDefButF(block, NUM, B_MATPRV, "Size:",                200, 70, 95,18, &(ma->param[0]), 0.0, 3.14, 0, 0, "Size of diffuse toon area");
+                       uiDefButF(block, NUM, B_MATPRV, "Smooth:",              200, 50, 95,18, &(ma->param[1]), 0.0, 1.0, 0, 0, "Smoothness of diffuse toon area");
+               }
+               
+               if ELEM3(ma->spec_shader, MA_SPEC_COOKTORR, MA_SPEC_PHONG, MA_SPEC_BLINN) {
+                       uiDefButS(block, NUM, B_MATPRV, "Hard:",                295, 70, 90,18, &(ma->har), 1.0, 255, 0, 0, "Set the hardness of the specularity");
+               }
+               if(ma->spec_shader==MA_SPEC_BLINN)
+                       uiDefButF(block, NUM, B_MATPRV, "Refr:",                295, 50, 90,18, &(ma->refrac), 1.0, 10.0, 0, 0, "Refraction index");
+               if(ma->spec_shader==MA_SPEC_TOON) {
+                       uiDefButF(block, NUM, B_MATPRV, "Size:",                295, 70, 90,18, &(ma->param[2]), 0.0, 1.53, 0, 0, "Size of specular toon area");
+                       uiDefButF(block, NUM, B_MATPRV, "Smooth:",              295, 50, 90,18, &(ma->param[3]), 0.0, 1.0, 0, 0, "Smoothness of specular toon area");
+               }
 
-       sprintf(str, "editbuttonswin %d", curarea->win);
-       block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
+               uiDefButF(block, NUMSLI, B_MATPRV, "Ref   ",            200,30,185,18, &(ma->ref), 0.0, 1.0, 0, 0, "Set the amount of reflection");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Spec ",                     200,10,185,18, &(ma->spec), 0.0, 2.0, 0, 0, "Set the degree of specularity");
+       
+               /* default shading variables */
+               uiDefButF(block, NUMSLI, B_MATPRV, "Alpha ",            390,90,175,18, &(ma->alpha), 0.0, 1.0, 0, 0, "Set the amount of coverage, to make materials transparent");
+               uiDefButF(block, NUMSLI, B_MATPRV, "SpecTra ",          390,70,175,18, &(ma->spectra), 0.0, 1.0, 0, 0, "Make specular areas opaque");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Add  ",                     390,50,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Glow factor for transparant");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Emit  ",            390,30,175,18, &(ma->emit), 0.0, 1.0, 0, 0, "Set the amount of emitting light");
+               uiDefButF(block, NUMSLI, B_MATPRV, "Amb   ",            390,10,175,18, &(ma->amb), 0.0, 1.0, 0, 0, "Set the amount of global ambient color");
+       
+               uiBlockSetCol(block, BUTBLUE);
+       
+               uiDefButI(block, TOG|BIT|0, 0,  "Traceable",            576,200,77,18, &(ma->mode), 0, 0, 0, 0, "Make material visible for shadow lamps");
+               uiDefButI(block, TOG|BIT|1, 0,  "Shadow",                       576,181,77,18, &(ma->mode), 0, 0, 0, 0, "Enable material for shadows");
+               uiDefButI(block, TOG|BIT|16, 0, "Radio",                        576, 162, 77,18, &(ma->mode), 0, 0, 0, 0, "Set the material insensitive to mist");
+               uiDefButI(block, TOG|BIT|2, B_MATPRV, "Shadeless",      576, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Make material insensitive to light or shadow");
+               uiDefButI(block, TOG|BIT|3, 0,  "Wire",                         576, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render only the edges of faces");
+               uiDefButI(block, TOG|BIT|6, 0,  "ZTransp",                      576, 105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Z-Buffer transparent faces");
+               uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo",      576, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo");
+               uiDefButI(block, TOG|BIT|9, 0,  "Env",                          576, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Do not render material");
+               uiDefButI(block, TOG|BIT|10, 0, "OnlyShadow",           576, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let alpha be determined on the degree of shadow");
+               uiDefButI(block, TOG|BIT|14, 0, "No Mist",                      576, 29, 77,18, &(ma->mode), 0, 0, 0, 0, "Set the material insensitive to mist");
+               uiDefButI(block, TOG|BIT|8, 0,  "ZInvert",                      576, 10, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render with inverted Z Buffer");
+               uiBlockSetCol(block, BUTGREY);
+               uiDefButF(block, NUM, 0, "Zoffs:",                                      576, -9, 77,18, &(ma->zoffs), 0.0, 10.0, 0, 0, "Give face an artificial offset");
+       }
+       /* PREVIEW RENDER */
+       
+       BIF_previewdraw(G.buts);
 
-       if(ob==G.obedit) lt= editLatt;
-       else lt= ob->data;
+       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE,              10,195,25,20, &(ma->pr_type), 10, 0, 0, 0, "");
+       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE,             35,195,25,20, &(ma->pr_type), 10, 1, 0, 0, "");
+       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE,               60,195,25,20, &(ma->pr_type), 10, 2, 0, 0, "");
 
-       uiSetButLock(lt->key!=0, "Not with VertexKeys");
-       uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
-       uiDefButS(block, NUM, B_RESIZELAT,      "U:",                   470,178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "");
-       uiDefButS(block, NUM, B_RESIZELAT,      "V:",                   470,158,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "");
-       uiDefButS(block, NUM, B_RESIZELAT,      "W:",                   470,138,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "");
-       uiClearButLock();
+       uiDefIconButS(block, ICONTOG|BIT|0, B_MATPRV, ICON_TRANSP_HLT,          95,195,25,20, &(ma->pr_back), 0, 0, 0, 0, "");
        
-       uiBlockSetCol(block, BUTGREEN);
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "");
-
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 158, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 158, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 158, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "");
+       uiDefIconBut(block, BUT, B_MATPRV, ICON_EYE,            159,195,30,20, 0, 0, 0, 0, 0, "");
 
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 138, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 138, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "");
-       uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 138, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "");
+       /* TEX CHANNELS */
+       uiBlockSetCol(block, BUTGREY);
+       xco= 665;
+       for(a= 0; a<8; a++) {
+               mtex= ma->mtex[a];
+               if(mtex && mtex->tex) splitIDname(mtex->tex->id.name+2, str, &loos);
+               else strcpy(str, "");
+               str[10]= 0;
+               uiDefButC(block, ROW, B_MATPRV_DRAW, str,       xco, 195, 63, 20, &(ma->texact), 3.0, (float)a, 0, 0, "");
+               xco+= 65;
+       }
        
-       uiBlockSetCol(block, BUTSALMON);
-       uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         470,101,99,32, 0, 0, 0, 0, 0, "");
+       uiDefIconBut(block, BUT, B_MTEXCOPY, ICON_COPYUP,       (short)xco,195,20,21, 0, 0, 0, 0, 0, "Copy the material settings to the buffer");
+       uiDefIconBut(block, BUT, B_MTEXPASTE, ICON_PASTEUP,     (short)(xco+20),195,20,21, 0, 0, 0, 0, 0, "Paste the material settings from the buffer");
 
+       
        uiBlockSetCol(block, BUTGREEN);
-       uiDefButS(block, TOG|BIT|1, B_LATTCHANGED, "Outside",   571,101,120,31, &lt->flag, 0, 0, 0, 0, "");
-
-       uiDrawBlock(block);
-}
-
-
-/* *************************** TEXTURE ******************************** */
+       uiDefButC(block, TOG, B_MATPRV, "SepT", (short)(xco+40), 195, 40, 20, &(ma->septex), 0, 0, 0, 0, "Render only use active texture channel");
+       uiBlockSetCol(block, BUTGREY);
 
-Tex *cur_imatex=0;
-int prv_win= 0;
+       mtex= ma->mtex[ ma->texact ];
+       if(mtex==0) {
+               mtex= &emptytex;
+               default_mtex(mtex);
+       }
+       
+       /* TEXCO */
+       uiBlockSetCol(block, BUTGREEN);
+       uiDefButS(block, ROW, B_MATPRV, "Object",               694,166,49,18, &(mtex->texco), 4.0, (float)TEXCO_OBJECT, 0, 0, "Use linked object's coordinates for texture coordinates");
+       uiDefIDPoinBut(block, test_obpoin_but, B_MATPRV, "",            745,166,133,18, &(mtex->object), "");
+       uiDefButS(block, ROW, B_MATPRV, "UV",                   664,166,29,18, &(mtex->texco), 4.0, (float)TEXCO_UV, 0, 0, "Use UV coordinates for texture coordinates");
 
-void load_tex_image(char *str) /* called from fileselect */
-{
-       Image *ima=0;
-       Tex *tex;
+       uiDefButS(block, ROW, B_MATPRV, "Glob",                 665,146,35,18, &(mtex->texco), 4.0, (float)TEXCO_GLOB, 0, 0, "Use global coordinates for the texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "Orco",                 701,146,38,18, &(mtex->texco), 4.0, (float)TEXCO_ORCO, 0, 0, "Use the original coordinates of the mesh");
+       uiDefButS(block, ROW, B_MATPRV, "Stick",                        739,146,38,18, &(mtex->texco), 4.0, (float)TEXCO_STICKY, 0, 0, "Use mesh sticky coordaintes for the texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "Win",                  779,146,31,18, &(mtex->texco), 4.0, (float)TEXCO_WINDOW, 0, 0, "Use screen coordinates as texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "Nor",                  811,146,32,18, &(mtex->texco), 4.0, (float)TEXCO_NORM, 0, 0, "Use normal vector as texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "Refl",                 844,146,33,18, &(mtex->texco), 4.0, (float)TEXCO_REFL, 0, 0, "Use reflection vector as texture coordinates");
        
-       tex= cur_imatex;
-       if(tex->type==TEX_IMAGE || tex->type==TEX_ENVMAP) {
+       uiBlockSetCol(block, BUTGREY);
+       
+       /* COORDS */
+       uiDefButC(block, ROW, B_MATPRV, "Flat",                 666,114,48,18, &(mtex->mapping), 5.0, (float)MTEX_FLAT, 0, 0, "Map X and Y coordinates directly");
+       uiDefButC(block, ROW, B_MATPRV, "Cube",                 717,114,50,18, &(mtex->mapping), 5.0, (float)MTEX_CUBE, 0, 0, "Map using the normal vector");
+       uiDefButC(block, ROW, B_MATPRV, "Tube",                 666,94,48,18, &(mtex->mapping), 5.0, (float)MTEX_TUBE, 0, 0, "Map with Z as central axis (tube-like)");
+       uiDefButC(block, ROW, B_MATPRV, "Sphe",                 716,94,50,18, &(mtex->mapping), 5.0, (float)MTEX_SPHERE, 0, 0, "Map with Z as central axis (sphere-like)");
 
-               ima= add_image(str);
-               if(ima) {
-                       if(tex->ima) {
-                               tex->ima->id.us--;
-                       }
-                       tex->ima= ima;
+       xco= 665;
+       for(a=0; a<4; a++) {
+               if(a==0) strcpy(str, "");
+               else if(a==1) strcpy(str, "X");
+               else if(a==2) strcpy(str, "Y");
+               else strcpy(str, "Z");
+               
+               uiDefButC(block, ROW, B_MATPRV, str,                    (short)xco, 50, 24, 18, &(mtex->projx), 6.0, (float)a, 0, 0, "");
+               uiDefButC(block, ROW, B_MATPRV, str,                    (short)xco, 30, 24, 18, &(mtex->projy), 7.0, (float)a, 0, 0, "");
+               uiDefButC(block, ROW, B_MATPRV, str,                    (short)xco, 10, 24, 18, &(mtex->projz), 8.0, (float)a, 0, 0, "");
+               xco+= 26;
+       }
+       
+       uiDefButF(block, NUM, B_MATPRV, "ofsX",         778,114,100,18, mtex->ofs, -10.0, 10.0, 10, 0, "Fine tune X coordinate");
+       uiDefButF(block, NUM, B_MATPRV, "ofsY",         778,94,100,18, mtex->ofs+1, -10.0, 10.0, 10, 0, "Fine tune Y coordinate");
+       uiDefButF(block, NUM, B_MATPRV, "ofsZ",         778,74,100,18, mtex->ofs+2, -10.0, 10.0, 10, 0, "Fine tune Z coordinate");
+       uiDefButF(block, NUM, B_MATPRV, "sizeX",        778,50,100,18, mtex->size, -100.0, 100.0, 10, 0, "Set an extra scaling for the texture coordinate");
+       uiDefButF(block, NUM, B_MATPRV, "sizeY",        778,30,100,18, mtex->size+1, -100.0, 100.0, 10, 0, "Set an extra scaling for the texture coordinate");
+       uiDefButF(block, NUM, B_MATPRV, "sizeZ",        778,10,100,18, mtex->size+2, -100.0, 100.0, 10, 0, "Set an extra scaling for the texture coordinate");
+       
+       /* TEXTUREBLOK SELECT */
+       if(G.main->tex.first==0)
+               id= NULL;
+       else
+               id= (ID*) mtex->tex;
+       IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->tex), id, &(G.buts->texnr));
+       uiDefButS(block, MENU, B_EXTEXBROWSE, strp, 900,146,20,19, &(G.buts->texnr), 0, 0, 0, 0, "The name of the texture");
+       MEM_freeN(strp);
 
-                       free_image_buffers(ima);        /* force reading again */
-                       ima->ok= 1;
+       if(id) {
+               uiDefBut(block, TEX, B_IDNAME, "TE:",   900,166,163,19, id->name+2, 0.0, 18.0, 0, 0, "The name of the texture block");
+               sprintf(str, "%d", id->us);
+               uiDefBut(block, BUT, 0, str,                            996,146,21,19, 0, 0, 0, 0, 0, "");
+               uiDefIconBut(block, BUT, B_AUTOTEXNAME, ICON_AUTO, 1041,146,21,19, 0, 0, 0, 0, 0, "Auto-assign name to texture");
+               if(id->lib) {
+                       if(ma->id.lib) uiDefIconBut(block, BUT, 0, ICON_DATALIB,        1019,146,21,19, 0, 0, 0, 0, 0, "");
+                       else uiDefIconBut(block, BUT, 0, ICON_PARLIB,   1019,146,21,19, 0, 0, 0, 0, 0, "");             
                }
-
-               allqueue(REDRAWBUTSTEX, 0);
-
-               BIF_preview_changed(G.buts);
+               uiBlockSetCol(block, BUTSALMON);
+               uiDefBut(block, BUT, B_TEXCLEAR, "Clear", 922, 146, 72, 19, 0, 0, 0, 0, 0, "Erase link to datablock");
+               uiBlockSetCol(block, BUTGREY);
        }
-}
+       
+       /* TEXTURE OUTPUT */
+       uiDefButS(block, TOG|BIT|1, B_MATPRV, "Stencil",        900,114,52,18, &(mtex->texflag), 0, 0, 0, 0, "Set the mapping to stencil mode");
+       uiDefButS(block, TOG|BIT|2, B_MATPRV, "Neg",            954,114,38,18, &(mtex->texflag), 0, 0, 0, 0, "Reverse the effect of the texture");
+       uiDefButS(block, TOG|BIT|0, B_MATPRV, "No RGB", 994,114,69,18, &(mtex->texflag), 0, 0, 0, 0, "Use an RGB texture as an intensity texture");
+       
+       uiDefButF(block, COL, B_MTEXCOL, "",                            900,100,163,12, &(mtex->r), 0, 0, 0, 0, "Browse datablocks");
 
-void load_plugin_tex(char *str)        /* called from fileselect */
-{
-       Tex *tex;
+       if(ma->colormodel==MA_HSV) {
+               uiBlockSetCol(block, BUTPURPLE);
+               uiDefButF(block, HSVSLI, B_MATPRV, "H ",                        900,80,163,18, &(mtex->r), 0.0, 0.9999, B_MTEXCOL, 0, "");
+               uiBlockSetCol(block, BUTPURPLE);
+               uiDefButF(block, HSVSLI, B_MATPRV, "S ",                        900,60,163,18, &(mtex->r), 0.0001, 1.0, B_MTEXCOL, 0, "");
+               uiBlockSetCol(block, BUTPURPLE);
+               uiDefButF(block, HSVSLI, B_MATPRV, "V ",                        900,40,163,18, &(mtex->r), 0.0001, 1.0, B_MTEXCOL, 0, "");
+               uiBlockSetCol(block, BUTGREY);
+       }
+       else {
+               uiDefButF(block, NUMSLI, B_MATPRV, "R ",                        900,80,163,18, &(mtex->r), 0.0, 1.0, B_MTEXCOL, 0, "Set the amount of red the intensity texture blends with");
+               uiDefButF(block, NUMSLI, B_MATPRV, "G ",                        900,60,163,18, &(mtex->g), 0.0, 1.0, B_MTEXCOL, 0, "Set the amount of green the intensity texture blends with");
+               uiDefButF(block, NUMSLI, B_MATPRV, "B ",                        900,40,163,18, &(mtex->b), 0.0, 1.0, B_MTEXCOL, 0, "Set the amount of blue the intensity texture blends with");
+       }
        
-       tex= cur_imatex;
-       if(tex->type!=TEX_PLUGIN) return;
+       uiDefButF(block, NUMSLI, B_MATPRV, "DVar ",             900,10,163,18, &(mtex->def_var), 0.0, 1.0, 0, 0, "Set the value the texture blends with the current value");
        
-       if(tex->plugin) free_plugin_tex(tex->plugin);
+       /* MAP TO */
+       uiBlockSetCol(block, BUTGREEN);
+       uiDefButS(block, TOG|BIT|0, B_MATPRV, "Col",            1087,166,35,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect basic colour of the material");
+       uiDefButS(block, TOG3|BIT|1, B_MATPRV, "Nor",           1126,166,31,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the rendered normal");
+       uiDefButS(block, TOG|BIT|2, B_MATPRV, "Csp",            1160,166,34,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the specularity colour");
+       uiDefButS(block, TOG|BIT|3, B_MATPRV, "Cmir",           1196,166,35,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affext the mirror colour");
+       uiDefButS(block, TOG3|BIT|4, B_MATPRV, "Ref",           1234,166,31,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the value of the materials reflectivity");
+       uiDefButS(block, TOG3|BIT|5, B_MATPRV, "Spec",  1087,146,36,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the value of specularity");
+       uiDefButS(block, TOG3|BIT|8, B_MATPRV, "Hard",  1126,146,44,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the hardness value");
+       uiDefButS(block, TOG3|BIT|7, B_MATPRV, "Alpha", 1172,146,45,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the alpha value");
+       uiDefButS(block, TOG3|BIT|6, B_MATPRV, "Emit",  1220,146,45,18, &(mtex->mapto), 0, 0, 0, 0, "Let the texture affect the emit value");
        
-       tex->stype= 0;
-       tex->plugin= add_plugin_tex(str);
+/*     uiDefButS(block, TOG|BIT|3, B_MATPRV, "Alpha Mix",1087,114,100,18, &(mtex->texflag), 0, 0, 0, 0); ,""*/
 
-       allqueue(REDRAWBUTSTEX, 0);
-       BIF_preview_changed(G.buts);
+       uiBlockSetCol(block, BUTGREY);
+       uiDefButS(block, ROW, B_MATPRV, "Mix",                  1087,94,48,18, &(mtex->blendtype), 9.0, (float)MTEX_BLEND, 0, 0, "The texture blends the values or colour");
+       uiDefButS(block, ROW, B_MATPRV, "Mul",                  1136,94,44,18, &(mtex->blendtype), 9.0, (float)MTEX_MUL, 0, 0, "The texture multiplies the values or colour");
+       uiDefButS(block, ROW, B_MATPRV, "Add",                  1182,94,41,18, &(mtex->blendtype), 9.0, (float)MTEX_ADD, 0, 0, "The texture adds the values or colour");
+       uiDefButS(block, ROW, B_MATPRV, "Sub",                  1226,94,40,18, &(mtex->blendtype), 9.0, (float)MTEX_SUB, 0, 0, "The texture subtracts the values or colour");
+       
+       uiDefButF(block, NUMSLI, B_MATPRV, "Col ",              1087,50,179,18, &(mtex->colfac), 0.0, 1.0, 0, 0, "Set the amount the texture affects colour");
+       uiDefButF(block, NUMSLI, B_MATPRV, "Nor ",              1087,30,179,18, &(mtex->norfac), 0.0, 5.0, 0, 0, "Set the amount the texture affects the normal");
+       uiDefButF(block, NUMSLI, B_MATPRV, "Var ",              1087,10,179,18, &(mtex->varfac), 0.0, 1.0, 0, 0, "Set the amount the texture affects a value");
+       
+       uiDrawBlock(block);
 }
 
-int vergcband(const void *a1, const void *a2)
-{
-       const CBData *x1=a1, *x2=a2;
 
-       if( x1->pos > x2->pos ) return 1;
-       else if( x1->pos < x2->pos) return -1;
-       return 0;
-}
+/* ************************ SOUND *************************** */
+static void load_new_sample(char *str) /* called from fileselect */
+{
+       char name[FILE_MAXDIR+FILE_MAXFILE];
+       bSound *sound;
+       bSample *sample, *newsample;
 
+       sound = G.buts->lockpoin;
 
+       if (sound) {
+               // save values
+               sample = sound->sample;
+               strcpy(name, sound->sample->name);
 
-void save_env(char *name)
-{
-       Tex *tex;
-       char str[FILE_MAXFILE];
-       
-       strcpy(str, name);
-       BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
-       tex= G.buts->lockpoin;
-       
-       if(tex && GS(tex->id.name)==ID_TE) {
-               if(tex->env && tex->env->ok && saveover(str)) {
-                       waitcursor(1);
-                       BIF_save_envmap(tex->env, str);
-                       strcpy(G.ima, name);
-                       waitcursor(0);
-               }
-       }
-       
-}
+               strcpy(sound->name, str);
+               sound_set_sample(sound, NULL);
+               sound_initialize_sample(sound);
 
-void drawcolorband(ColorBand *coba, float x1, float y1, float sizex, float sizey)
-{
-       CBData *cbd;
-       float v3[2], v1[2], v2[2];
-       int a;
-       
-       if(coba==0) return;
-       
-       /* outline */
-       v1[0]= x1; v1[1]= y1;
-       glLineWidth((GLfloat)(3));
-       cpack(0x0);
-       glBegin(GL_LINE_LOOP);
-               glVertex2fv(v1);
-               v1[0]+= sizex;
-               glVertex2fv(v1);
-               v1[1]+= sizey;
-               glVertex2fv(v1);
-               v1[0]-= sizex;
-               glVertex2fv(v1);
-       glEnd();
-       glLineWidth((GLfloat)(1));
+               if (sound->sample->type == SAMPLE_INVALID) {
+                       error("Not a valid sample: %s", str);
 
+                       newsample = sound->sample;
 
-       glShadeModel(GL_SMOOTH);
-       cbd= coba->data;
-       
-       v1[0]= v2[0]= x1;
-       v1[1]= y1;
-       v2[1]= y1+sizey;
-       
-       glBegin(GL_QUAD_STRIP);
-       
-       glColor3fv( &cbd->r );
-       glVertex2fv(v1); glVertex2fv(v2);
-       
-       for(a=0; a<coba->tot; a++, cbd++) {
-               
-               v1[0]=v2[0]= x1+ cbd->pos*sizex;
+                       // restore values
+                       strcpy(sound->name, name);
+                       sound_set_sample(sound, sample);
 
-               glColor3fv( &cbd->r );
-               glVertex2fv(v1); glVertex2fv(v2);
-       }
-       
-       v1[0]=v2[0]= x1+ sizex;
-       glVertex2fv(v1); glVertex2fv(v2);
-       
-       glEnd();
-       glShadeModel(GL_FLAT);
-       
-       /* help lines */
-       
-       v1[0]= v2[0]=v3[0]= x1;
-       v1[1]= y1;
-       v2[1]= y1+0.5*sizey;
-       v3[1]= y1+sizey;
-       
-       cbd= coba->data;
-       glBegin(GL_LINES);
-       for(a=0; a<coba->tot; a++, cbd++) {
-               v1[0]=v2[0]=v3[0]= x1+ cbd->pos*sizex;
-               
-               glColor3ub(0, 0, 0);
-               glVertex2fv(v1);
-               glVertex2fv(v2);
+                       // remove invalid sample
 
-               if(a==coba->cur) {
-                       glVertex2f(v1[0]-1, v1[1]);
-                       glVertex2f(v2[0]-1, v2[1]);
-                       glVertex2f(v1[0]+1, v1[1]);
-                       glVertex2f(v2[0]+1, v2[1]);
-               }
-                       
-               glColor3ub(255, 255, 255);
-               glVertex2fv(v2);
-               glVertex2fv(v3);
-               
-               if(a==coba->cur) {
-                       glVertex2f(v2[0]-1, v2[1]);
-                       glVertex2f(v3[0]-1, v3[1]);
-                       glVertex2f(v2[0]+1, v2[1]);
-                       glVertex2f(v3[0]+1, v3[1]);
+                       sound_free_sample(newsample);
+                       BLI_remlink(samples, newsample);
+                       MEM_freeN(newsample);
                }
        }
-       glEnd();
-       
-       glFlush();
-}
 
+       allqueue(REDRAWBUTSSOUND, 0);
+       if (curarea) BIF_preview_changed(G.buts);
+}
 
 
-void do_texbuts(unsigned short event)
+void do_soundbuts(unsigned short event)
 {
-       Tex *tex;
-       ImBuf *ibuf;
-       ScrArea *sa;
+       char name[FILE_MAXDIR+FILE_MAXFILE];
+       bSound *sound;
+       bSample *sample;
+       bSound* tempsound;
        ID *id;
-       CBData *cbd;
-       float dx;
-       int a, nr;
-       short mvalo[2], mval[2];
-       char *name, str[80];
        
-       tex= G.buts->lockpoin;
+       sound = G.buts->lockpoin;
        
-       switch(event) {
-       case B_TEXCHANNEL:
-               scrarea_queue_headredraw(curarea);
-               BIF_preview_changed(G.buts);
-               allqueue(REDRAWBUTSTEX, 0);
-               break;
-       case B_TEXTYPE:
-               if(tex==0) return;
-               tex->stype= 0;
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-       case B_DEFTEXVAR:
-               if(tex==0) return;
-               default_tex(tex);
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-       case B_LOADTEXIMA:
-       case B_LOADTEXIMA1:
-               if(tex==0) return;
-               /* globals: temporal store them: we make another area a fileselect */
-               cur_imatex= tex;
-               prv_win= curarea->win;
-               
-               sa= closest_bigger_area();
-               areawinset(sa->win);
-               if(tex->ima) name= tex->ima->name;
-#ifdef _WIN32
-               else {
-                       if (strcmp (U.textudir, "/") == 0)
-                               name= G.sce;
-                       else
-                               name= U.textudir;
+       switch(event)
+       {
+       case B_SOUND_REDRAW:
+               {
+                       allqueue(REDRAWBUTSSOUND, 0);
+                       break;
                }
-#else
-               else name = U.textudir;
-#endif
-               
-               if(event==B_LOADTEXIMA)
-                       activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_tex_image);
-               else 
-                       activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_tex_image);
-               
-               break;
-       case B_NAMEIMA:
-               if(tex==0) return;
-               if(tex->ima) {
-                       cur_imatex= tex;
-                       prv_win= curarea->win;
+       case B_SOUND_LOAD_SAMPLE:
+               {
+                       if (sound) strcpy(name, sound->name);
+                       else strcpy(name, U.sounddir);
                        
-                       /* name in tex->ima has been changed by button! */
-                       strcpy(str, tex->ima->name);
-                       if(tex->ima->ibuf) strcpy(tex->ima->name, tex->ima->ibuf->name);
-
-                       load_tex_image(str);
+                       activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
+                       break;
                }
-               break;
-       case B_TEXREDR_PRV:
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-       case B_TEXIMABROWSE:
-               if(tex) {
-                       id= (ID*) tex->ima;
-                       
-                       if(G.buts->menunr== -2) {
-                               activate_databrowse(id, ID_IM, 0, B_TEXIMABROWSE, &G.buts->menunr, do_texbuts);
-                       } else if (G.buts->menunr>0) {
-                               Image *newima= (Image*) BLI_findlink(&G.main->image, G.buts->menunr-1);
-                               
-                               if (newima && newima!=(Image*) id) {
-                                       tex->ima= newima;
-                                       id_us_plus((ID*) newima);
-                                       if(id) id->us--;
-                               
-                                       allqueue(REDRAWBUTSTEX, 0);
-                                       BIF_preview_changed(G.buts);
+       case B_SOUND_PLAY_SAMPLE:
+               {
+                       if (sound)
+                       {
+                               if (sound->sample->type != SAMPLE_INVALID)
+                               {
+                                       sound_play_sound(sound);
+                                       allqueue(REDRAWBUTSSOUND, 0);
                                }
                        }
+                       break;
                }
-               break;
-       case B_IMAPTEST:
-               if(tex) {
-                       if( (tex->imaflag & (TEX_FIELDS+TEX_MIPMAP))== TEX_FIELDS+TEX_MIPMAP ) {
-                               error("Cannot combine fields and mipmap");
-                               tex->imaflag -= TEX_MIPMAP;
-                               allqueue(REDRAWBUTSTEX, 0);
-                       }
-                       
-                       if(tex->ima && tex->ima->ibuf) {
-                               ibuf= tex->ima->ibuf;
-                               nr= 0;
-                               if( !(tex->imaflag & TEX_FIELDS) && (ibuf->flags & IB_fields) ) nr= 1;
-                               if( (tex->imaflag & TEX_FIELDS) && !(ibuf->flags & IB_fields) ) nr= 1;
-                               if(nr) {
-                                       IMB_freeImBuf(ibuf);
-                                       tex->ima->ibuf= 0;
-                                       tex->ima->ok= 1;
-                                       BIF_preview_changed(G.buts);
+       case B_SOUND_MENU_SAMPLE:
+               {
+                       if (G.buts->menunr == -2) {
+                               if (sound) {
+                                       activate_databrowse((ID *)sound->sample, ID_SAMPLE, 0, B_SOUND_MENU_SAMPLE, &G.buts->menunr, do_soundbuts);
                                }
-                       }
-               }
-               break;
-       case B_RELOADIMA:
-               if(tex && tex->ima) {
-                       // check if there is a newer packedfile
-
-                       if (tex->ima->packedfile) {
-                               PackedFile *pf;
-                               pf = newPackedFile(tex->ima->name);
-                               if (pf) {
-                                       freePackedFile(tex->ima->packedfile);
-                                       tex->ima->packedfile = pf;
-                               } else {
-                                       error("Image not available. Keeping packed image.");
+                       } else if (G.buts->menunr > 0) {
+                               sample = BLI_findlink(samples, G.buts->menunr - 1);
+                               if (sample && sound) {
+                                       BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
+                                       sound_set_sample(sound, sample);
+                                       do_soundbuts(B_SOUND_REDRAW);
                                }
                        }
-
-                       IMB_freeImBuf(tex->ima->ibuf);
-                       tex->ima->ibuf= 0;
-                       tex->ima->ok= 1;
-                       allqueue(REDRAWBUTSTEX, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWIMAGE, 0);
-                       BIF_preview_changed(G.buts);
+                       
+                       break;
                }
-               break;
-
-       case B_TEXSETFRAMES:
-               if(tex->ima->anim) tex->frames = IMB_anim_get_duration(tex->ima->anim);
-               allqueue(REDRAWBUTSTEX, 0);
-               break;
-
-       case B_PACKIMA:
-               if(tex && tex->ima) {
-                       if (tex->ima->packedfile) {
+       case B_SOUND_NAME_SAMPLE:
+               {
+                       load_new_sample(sound->name);
+                       break;
+               }
+       case B_SOUND_UNPACK_SAMPLE:
+               if(sound && sound->sample) {
+                       sample = sound->sample;
+                       
+                       if (sample->packedfile) {
                                if (G.fileflags & G_AUTOPACK) {
                                        if (okee("Disable AutoPack ?")) {
                                                G.fileflags &= ~G_AUTOPACK;
@@ -3419,3393 +2622,985 @@ void do_texbuts(unsigned short event)
                                }
                                
                                if ((G.fileflags & G_AUTOPACK) == 0) {
-                                       unpackImage(tex->ima, PF_ASK);
+                                       unpackSample(sample, PF_ASK);
                                }
                        } else {
-                               if (tex->ima->ibuf && (tex->ima->ibuf->userflags & IB_BITMAPDIRTY)) {
-                                       error("Can't pack painted image. Save image from Image window first.");
-                               } else {
-                                       tex->ima->packedfile = newPackedFile(tex->ima->name);
-                               }
+                               sound_set_packedfile(sample, newPackedFile(sample->name));
                        }
-                       allqueue(REDRAWBUTSTEX, 0);
                        allqueue(REDRAWHEADERS, 0);
+                       do_soundbuts(B_SOUND_REDRAW);
                }
                break;
-       case B_LOADPLUGIN:
-               if(tex==0) return;
-
-               /* globals: store temporal: we make another area a fileselect */
-               cur_imatex= tex;
-               prv_win= curarea->win;
-                       
-               sa= closest_bigger_area();
-               areawinset(sa->win);
-               if(tex->plugin) strcpy(str, tex->plugin->name);
-               else {
-                       strcpy(str, U.plugtexdir);
+       case B_SOUND_COPY_SOUND:
+               {
+                       if (sound)
+                       {
+                               tempsound = sound_make_copy(sound);
+                               sound = tempsound;
+                               id = &sound->id;
+                               G.buts->lockpoin = (bSound*)id;
+                               do_soundbuts(B_SOUND_REDRAW);
+                       }
+                       break;
                }
-               activate_fileselect(FILE_SPECIAL, "SELECT PLUGIN", str, load_plugin_tex);
-               
-               break;
-
-       case B_NAMEPLUGIN:
-               if(tex==0 || tex->plugin==0) return;
-               strcpy(str, tex->plugin->name);
-               free_plugin_tex(tex->plugin);
-               tex->stype= 0;
-               tex->plugin= add_plugin_tex(str);
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-       
-       case B_COLORBAND:
-               if(tex==0) return;
-               if(tex->coba==0) tex->coba= add_colorband();
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-       
-       case B_ADDCOLORBAND:
-               if(tex==0 || tex->coba==0) return;
-               
-               if(tex->coba->tot < MAXCOLORBAND-1) tex->coba->tot++;
-               tex->coba->cur= tex->coba->tot-1;
-               
-               do_texbuts(B_CALCCBAND);
-               
-               break;
-
-       case B_DELCOLORBAND:
-               if(tex==0 || tex->coba==0 || tex->coba->tot<2) return;
-               
-               for(a=tex->coba->cur; a<tex->coba->tot; a++) {
-                       tex->coba->data[a]= tex->coba->data[a+1];
+       case B_SOUND_RECALC:
+               {
+                       waitcursor(1);
+                       sound = G.main->sound.first;
+                       while (sound)
+                       {
+                               MEM_freeN(sound->stream);
+                               sound->stream = 0;
+                               audio_makestream(sound);
+                               sound = (bSound *) sound->id.next;
+                       }
+                       waitcursor(0);
+                       allqueue(REDRAWSEQ, 0);
+                       break;
                }
-               if(tex->coba->cur) tex->coba->cur--;
-               tex->coba->tot--;
-
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               break;
-
-       case B_CALCCBAND:
-       case B_CALCCBAND2:
-               if(tex==0 || tex->coba==0 || tex->coba->tot<2) return;
-               
-               for(a=0; a<tex->coba->tot; a++) tex->coba->data[a].cur= a;
-               qsort(tex->coba->data, tex->coba->tot, sizeof(CBData), vergcband);
-               for(a=0; a<tex->coba->tot; a++) {
-                       if(tex->coba->data[a].cur==tex->coba->cur) {
-                               if(tex->coba->cur!=a) addqueue(curarea->win, REDRAW, 0);        /* button cur */
-                               tex->coba->cur= a;
-                               break;
-                       }
-               }
-               if(event==B_CALCCBAND2) return;
-               
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               
-               break;
-               
-       case B_DOCOLORBAND:
-               if(tex==0 || tex->coba==0) return;
-               
-               cbd= tex->coba->data + tex->coba->cur;
-               uiGetMouse(mywinget(), mvalo);
-
-               while(get_mbut() & L_MOUSE) {
-                       uiGetMouse(mywinget(), mval);
-                       if(mval[0]!=mvalo[0]) {
-                               dx= mval[0]-mvalo[0];
-                               dx/= 345.0;
-                               cbd->pos+= dx;
-                               CLAMP(cbd->pos, 0.0, 1.0);
-
-                               glDrawBuffer(GL_FRONT);
-                               drawcolorband(tex->coba, 923,81,345,20);
-                               /* uiSetButs(B_CALCCBAND, B_CALCCBAND); */
-                               glDrawBuffer(GL_BACK);
-                               
-                               do_texbuts(B_CALCCBAND2);
-                               cbd= tex->coba->data + tex->coba->cur;  /* because qsort */
-                               
-                               mvalo[0]= mval[0];
-                       }
-                       BIF_wait_for_statechange();
-               }
-               allqueue(REDRAWBUTSTEX, 0);
-               BIF_preview_changed(G.buts);
-               
-               break;
-       
-       case B_REDRAWCBAND:
-               glDrawBuffer(GL_FRONT);
-               drawcolorband(tex->coba, 923,81,345,20);
-               glDrawBuffer(GL_BACK);
-               BIF_preview_changed(G.buts);
-               break;
-       
-       case B_ENV_DELETE:
-               if(tex->env) {
-                       RE_free_envmap(tex->env);
-                       tex->env= 0;
-                       allqueue(REDRAWBUTSTEX, 0);
-                       BIF_preview_changed(G.buts);
-               }
-               break;
-       case B_ENV_FREE:
-               if(tex->env) {
-                       RE_free_envmapdata(tex->env);
-                       allqueue(REDRAW