Modified interface texture font support, which should work nicely with the freshly...
[blender.git] / source / blender / src / header_image.c
1 /**
2  * header_image.c oct-2003
3  *
4  * Functions to draw the "UV/Image Editor" window header
5  * and handle user events sent to it.
6  * 
7  * $Id$
8  *
9  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version. The Blender
15  * Foundation also sells licenses for use in proprietary software under
16  * the Blender License.  See http://www.blender.org/BL/ for information
17  * about this.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
27  *
28  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
29  * All rights reserved.
30  *
31  * The Original Code is: all of this file.
32  *
33  * Contributor(s): none yet.
34  *
35  * ***** END GPL/BL DUAL LICENSE BLOCK *****
36  */
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifdef WIN32
46 #include "BLI_winstuff.h"
47 #endif
48
49 #include "DNA_ID.h"
50 #include "DNA_image_types.h"
51 #include "DNA_mesh_types.h"
52 #include "DNA_packedFile_types.h"
53 #include "DNA_scene_types.h"
54 #include "DNA_screen_types.h"
55 #include "DNA_space_types.h"
56 #include "DNA_userdef_types.h"
57
58 #include "BDR_drawmesh.h"
59 #include "BDR_unwrapper.h"
60 #include "BKE_global.h"
61 #include "BKE_image.h"
62 #include "BKE_main.h"
63 #include "BKE_packedFile.h"
64 #include "BKE_utildefines.h"
65
66 #include "BLI_blenlib.h"
67 #include "BIF_drawimage.h"
68 #include "BIF_editsima.h"
69 #include "BIF_interface.h"
70 #include "BIF_resources.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toets.h"
74 #include "BIF_toolbox.h"
75 #include "BIF_writeimage.h"
76
77 #include "BSE_filesel.h"
78 #include "BSE_headerbuttons.h"
79
80 #include "BPY_extern.h"
81 #include "BPY_menus.h"
82
83 #include "IMB_imbuf.h"
84 #include "IMB_imbuf_types.h"
85
86 #include "blendef.h"
87 #include "mydevice.h"
88
89 #include "TPT_DependKludge.h"
90
91 void load_space_image(char *str)        /* called from fileselect */
92 {
93         Image *ima=0;
94  
95         if(G.obedit) {
96                 error("Can't perfom this in editmode");
97                 return;
98         }
99
100         ima= add_image(str);
101         if(ima) {
102
103                 G.sima->image= ima;
104
105                 free_image_buffers(ima);        /* force read again */
106                 ima->ok= 1;
107                 image_changed(G.sima, 0);
108
109         }
110         BIF_undo_push("Load image UV");
111         allqueue(REDRAWIMAGE, 0);
112 }
113
114 void image_replace(Image *old, Image *new)
115 {
116         TFace *tface;
117         Mesh *me;
118         int a, rep=0;
119
120         new->tpageflag= old->tpageflag;
121         new->twsta= old->twsta;
122         new->twend= old->twend;
123         new->xrep= old->xrep;
124         new->yrep= old->yrep;
125  
126         me= G.main->mesh.first;
127         while(me) {
128
129                 if(me->tface) {
130                         tface= me->tface;
131                         a= me->totface;
132                         while(a--) {
133                                 if(tface->tpage==old) {
134                                         tface->tpage= new;
135                                         rep++;
136                                 }
137                                 tface++;
138                         }
139                 }
140                 me= me->id.next;
141  
142         }
143         if(rep) {
144                 if(new->id.us==0) new->id.us= 1;
145         }
146         else error("Nothing replaced");
147 }
148
149 void replace_space_image(char *str)             /* called from fileselect */
150 {
151         Image *ima=0;
152
153         if(G.obedit) {
154                 error("Can't perfom this in editmode");
155                 return;
156         }
157
158         ima= add_image(str);
159         if(ima) {
160  
161                 if(G.sima->image && G.sima->image != ima) {
162                         image_replace(G.sima->image, ima);
163                 }
164  
165                 G.sima->image= ima;
166
167                 free_image_buffers(ima);        /* force read again */
168                 ima->ok= 1;
169                 /* replace also assigns: */
170                 image_changed(G.sima, 0);
171
172         }
173         BIF_undo_push("Replace image UV");
174         allqueue(REDRAWIMAGE, 0);
175 }
176
177 void save_paint(char *name)
178 {
179         char str[FILE_MAXDIR+FILE_MAXFILE];
180         Image *ima = G.sima->image;
181         ImBuf *ibuf;
182
183         if (ima  && ima->ibuf) {
184                 BLI_strncpy(str, name, sizeof(str));
185
186                 BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
187
188                 if (saveover(str)) {
189                         ibuf = IMB_dupImBuf(ima->ibuf);
190
191                         if (ibuf) {
192                                 if (BIF_write_ibuf(ibuf, str)) {
193                                         BLI_strncpy(ima->name, name, sizeof(ima->name));
194                                         ima->ibuf->userflags &= ~IB_BITMAPDIRTY;
195                                         allqueue(REDRAWHEADERS, 0);
196                                         allqueue(REDRAWBUTSSHADING, 0);
197                                 } else {
198                                         error("Couldn't write image: %s", str);
199                                 }
200
201                                 IMB_freeImBuf(ibuf);
202                         }
203                 }
204         }
205 }
206
207 void do_image_buttons(unsigned short event)
208 {
209         Image *ima;
210         ID *id, *idtest;
211         int nr;
212         char name[256];
213
214         if(curarea->win==0) return;
215
216         switch(event) {
217         case B_SIMAGEHOME:
218                 image_home();
219                 break;
220
221         case B_SIMABROWSE:      
222                 if(G.sima->imanr== -2) {
223                         activate_databrowse((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
224                                                                                         &G.sima->imanr, do_image_buttons);
225                         return;
226                 }
227                 if(G.sima->imanr < 0) break;
228         
229                 nr= 1;
230                 id= (ID *)G.sima->image;
231
232                 idtest= G.main->image.first;
233                 while(idtest) {
234                         if(nr==G.sima->imanr) {
235                                 break;
236                         }
237                         nr++;
238                         idtest= idtest->next;
239                 }
240                 if(idtest==0) { /* no new */
241                         return;
242                 }
243         
244                 if(idtest!=id) {
245                         G.sima->image= (Image *)idtest;
246                         if(idtest->us==0) idtest->us= 1;
247                         allqueue(REDRAWIMAGE, 0);
248                 }
249                 /* also when image is the same: assign! 0==no tileflag: */
250                 image_changed(G.sima, 0);
251                 BIF_undo_push("Assign image UV");
252
253                 break;
254         case B_SIMAGELOAD:
255                 
256                 if(G.sima->image) strcpy(name, G.sima->image->name);
257                 else strcpy(name, U.textudir);
258                 
259                 if(G.qual==LR_CTRLKEY)
260                         activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image);
261                 else
262                         activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image);
263                 break;
264                 
265         case B_SIMAGEREPLACE:
266                 
267                 if(G.sima->image) strcpy(name, G.sima->image->name);
268                 else strcpy(name, U.textudir);
269                 
270                 if(G.qual==LR_CTRLKEY)
271                         activate_imageselect(FILE_SPECIAL, "REPLACE IMAGE", name, replace_space_image);
272                 else
273                         activate_fileselect(FILE_SPECIAL, "REPLACE IMAGE", name, replace_space_image);
274                 break;
275                 
276         case B_SIMAGEDRAW:
277                 
278                 if(G.f & G_FACESELECT) {
279                         make_repbind(G.sima->image);
280                         image_changed(G.sima, 1);
281                 }
282                 allqueue(REDRAWVIEW3D, 0);
283                 allqueue(REDRAWIMAGE, 0);
284                 break;
285
286         case B_SIMAGEDRAW1:
287                 image_changed(G.sima, 2);               /* 2: only tileflag */
288                 allqueue(REDRAWVIEW3D, 0);
289                 allqueue(REDRAWIMAGE, 0);
290                 break;
291                 
292         case B_TWINANIM:
293                 ima = G.sima->image;
294                 if (ima) {
295                         if(ima->flag & IMA_TWINANIM) {
296                                 nr= ima->xrep*ima->yrep;
297                                 if(ima->twsta>=nr) ima->twsta= 1;
298                                 if(ima->twend>=nr) ima->twend= nr-1;
299                                 if(ima->twsta>ima->twend) ima->twsta= 1;
300                                 allqueue(REDRAWIMAGE, 0);
301                         }
302                 }
303                 break;
304
305         case B_CLIP_UV:
306                 tface_do_clip();
307                 allqueue(REDRAWIMAGE, 0);
308                 allqueue(REDRAWVIEW3D, 0);
309                 break;
310
311         case B_SIMAGEPAINTTOOL:
312                 // check for packed file here
313                 allqueue(REDRAWIMAGE, 0);
314                 allqueue(REDRAWVIEW3D, 0);
315                 break;
316         case B_SIMAPACKIMA:
317                 ima = G.sima->image;
318                 if (ima) {
319                         if (ima->packedfile) {
320                                 if (G.fileflags & G_AUTOPACK) {
321                                         if (okee("Disable AutoPack ?")) {
322                                                 G.fileflags &= ~G_AUTOPACK;
323                                         }
324                                 }
325                                 
326                                 if ((G.fileflags & G_AUTOPACK) == 0) {
327                                         unpackImage(ima, PF_ASK);
328                                 }
329                         } else {
330                                 if (ima->ibuf && (ima->ibuf->userflags & IB_BITMAPDIRTY)) {
331                                         error("Can't pack painted image. Save image first.");
332                                 } else {
333                                         ima->packedfile = newPackedFile(ima->name);
334                                 }
335                         }
336                         allqueue(REDRAWBUTSSHADING, 0);
337                         allqueue(REDRAWHEADERS, 0);
338                 }
339                 break;
340         case B_SIMAGESAVE:
341                 ima = G.sima->image;
342                 if (ima) {
343                         strcpy(name, ima->name);
344                         if (ima->ibuf) {
345                                 char str[32];   // sufficient for message
346                                 save_image_filesel_str(str);
347                                 activate_fileselect(FILE_SPECIAL, str, name, save_paint);
348                         }
349                 }
350                 break;
351         }
352 }
353
354 static void do_image_view_viewnavmenu(void *arg, int event)
355 {
356         switch(event) {
357         case 1: /* Zoom In */
358                 image_viewzoom(PADPLUSKEY);
359                 break;
360         case 2: /* Zoom Out */
361                 image_viewzoom(PADMINUS);
362                 break;
363         }
364         allqueue(REDRAWIMAGE, 0);
365 }
366
367 static uiBlock *image_view_viewnavmenu(void *arg_unused)
368 {
369 /*              static short tog=0; */
370         uiBlock *block;
371         short yco= 0, menuwidth=120;
372         
373         block= uiNewBlock(&curarea->uiblocks, "image_view_viewnavmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
374         uiBlockSetButmFunc(block, do_image_view_viewnavmenu, NULL);
375         
376         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom In|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
377         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Out|NumPad -",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
378
379         uiBlockSetDirection(block, UI_RIGHT);
380         uiTextBoundsBlock(block, 50);
381         return block;
382 }
383
384 static void do_image_viewmenu(void *arg, int event)
385 {
386
387         switch(event) {
388         case 0: /* Update Automatically */
389                 if(G.sima->lock) G.sima->lock = 0;
390                 else G.sima->lock = 1;
391                 break;
392         case 1: /* View All */
393                 do_image_buttons(B_SIMAGEHOME);
394                 break;
395         case 2: /* Maximize Window */
396                 /* using event B_FULL */
397                 break;
398         case 5: /* Draw Shadow Mesh */
399                 if(G.sima->flag & SI_DRAWSHADOW)
400                         G.sima->flag &= ~SI_DRAWSHADOW;
401                 else
402                         G.sima->flag |= SI_DRAWSHADOW;
403                 allqueue(REDRAWIMAGE, 0);
404                 break;
405         case 6: /* Draw Faces */
406                 if(G.f & G_DRAWFACES)
407                         G.f &= ~G_DRAWFACES;
408                 else
409                         G.f |= G_DRAWFACES;
410                 allqueue(REDRAWIMAGE, 0);
411                 break;
412         case 7: /* Properties  Panel */
413                 add_blockhandler(curarea, IMAGE_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
414                 break;
415         case 8: /* Paint Panel... */
416                 add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
417                 break;
418         }
419         allqueue(REDRAWVIEW3D, 0);
420 }
421
422 static uiBlock *image_viewmenu(void *arg_unused)
423 {
424 /*      static short tog=0; */
425         uiBlock *block;
426         short yco= 0, menuwidth=120;
427         
428         block= uiNewBlock(&curarea->uiblocks, "image_viewmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
429         uiBlockSetButmFunc(block, do_image_viewmenu, NULL);
430
431         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Properties...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
432         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Paint Tool...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
433
434         
435         if(G.f & G_DRAWFACES) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Draw Faces", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
436         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Faces|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
437         if(G.sima->flag & SI_DRAWSHADOW) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Draw Shadow Mesh", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
438         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Shadow Mesh|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
439         
440         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
441         uiDefIconTextBlockBut(block, image_view_viewnavmenu, NULL, ICON_RIGHTARROW_THIN, "View Navigation", 0, yco-=20, 120, 19, "");
442
443         if(G.sima->lock) {
444                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
445         } else {
446                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
447         } 
448
449         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
450         
451         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
452                 
453         if(!curarea->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
454         else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
455         
456         if(curarea->headertype==HEADERTOP) {
457                 uiBlockSetDirection(block, UI_DOWN);
458         }
459         else {
460                 uiBlockSetDirection(block, UI_TOP);
461                 uiBlockFlipOrder(block);
462         }
463
464         uiTextBoundsBlock(block, 50);
465         
466         return block;
467 }
468
469 static void do_image_selectmenu(void *arg, int event)
470 {
471         switch(event)
472         {
473         case 0: /* Border Select */
474                 borderselect_sima();
475                 break;
476         case 1: /* Select/Deselect All */
477                 select_swap_tface_uv();
478                 break;
479         case 2: /* Unlink Selection */
480                 unlink_selection();
481                 break;
482         case 3: /* Select Linked UVs */
483                 select_linked_tface_uv();
484                 break;
485         case 4: /* Toggle Local UVs Stick to Vertex in Mesh */
486                 if(G.sima->flag & SI_LOCALSTICKY)
487                         G.sima->flag &= ~SI_LOCALSTICKY;
488                 else {
489                         G.sima->flag |= SI_LOCALSTICKY;
490                         G.sima->flag &= ~SI_STICKYUVS;
491                 }
492                 allqueue(REDRAWIMAGE, 0);
493                 break;  
494         case 5: /* Toggle UVs Stick to Vertex in Mesh */
495                 if(G.sima->flag & SI_STICKYUVS)
496                         G.sima->flag &= ~SI_STICKYUVS;
497                 else {
498                         G.sima->flag |= SI_STICKYUVS;
499                         G.sima->flag &= ~SI_LOCALSTICKY;
500                 }
501                 allqueue(REDRAWIMAGE, 0);
502                 break;  
503         case 6: /* Toggle Active Face Select */
504                 if(G.sima->flag & SI_SELACTFACE)
505                         G.sima->flag &= ~SI_SELACTFACE;
506                 else
507                         G.sima->flag |= SI_SELACTFACE;
508                 allqueue(REDRAWIMAGE, 0);
509                 break;
510         }
511 }
512
513 static uiBlock *image_selectmenu(void *arg_unused)
514 {
515         uiBlock *block;
516         short yco= 0, menuwidth=120;
517
518         block= uiNewBlock(&curarea->uiblocks, "image_selectmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
519         uiBlockSetButmFunc(block, do_image_selectmenu, NULL);
520
521         if(G.sima->flag & SI_SELACTFACE) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
522         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
523
524         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
525
526         if(G.sima->flag & SI_LOCALSTICKY) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Stick Local UVs to Mesh Vertex|Shift C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
527         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Stick Local UVs to Mesh Vertex|Shift C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
528
529         if(G.sima->flag & SI_STICKYUVS) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Stick UVs to Mesh Vertex|Ctrl C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
530         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Stick UVs to Mesh Vertex|Ctrl C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
531
532         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
533
534         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
535
536         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
537
538         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unlink Selection|Alt L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
539
540         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Linked UVs|L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
541
542         if(curarea->headertype==HEADERTOP) {
543                 uiBlockSetDirection(block, UI_DOWN);
544         }
545         else {
546                 uiBlockSetDirection(block, UI_TOP);
547                 uiBlockFlipOrder(block);
548         }
549
550         uiTextBoundsBlock(block, 50);
551
552         return block;
553 }
554
555 static void do_image_image_rtmappingmenu(void *arg, int event)
556 {
557         switch(event) {
558         case 0: /* UV Co-ordinates */
559                 G.sima->image->flag = BCLR(G.sima->image->flag, 4);
560                 break;
561         case 1: /* Reflection */
562                 G.sima->image->flag = BSET(G.sima->image->flag, 4);
563                 break;
564                 }
565
566         allqueue(REDRAWVIEW3D, 0);
567 }
568
569 static uiBlock *image_image_rtmappingmenu(void *arg_unused)
570 {
571         uiBlock *block;
572         short yco = 20, menuwidth = 120;
573
574         block= uiNewBlock(&curarea->uiblocks, "image_image_rtmappingmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
575         uiBlockSetButmFunc(block, do_image_image_rtmappingmenu, NULL);
576         
577         if (G.sima->image->flag & IMA_REFLECT) {
578                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Co-ordinates",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
579                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Reflection",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
580         } else {
581                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "UV Co-ordinates",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
582                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Reflection",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
583         }
584
585         uiBlockSetDirection(block, UI_RIGHT);
586         uiTextBoundsBlock(block, 60);
587         return block;
588 }
589
590 static void do_image_imagemenu(void *arg, int event)
591 {
592         Image *ima;
593         char name[256];
594
595         switch(event)
596         {
597         case 0: /* Open */
598                 if(G.sima->image) strcpy(name, G.sima->image->name);
599                 else strcpy(name, U.textudir);
600                 if(G.qual==LR_CTRLKEY)
601                         activate_imageselect(FILE_SPECIAL, "Open Image", name, load_space_image);
602                 else
603                         activate_fileselect(FILE_SPECIAL, "Open Image", name, load_space_image);
604                 break;
605         case 1: /* Replace */
606                 if(G.sima->image) strcpy(name, G.sima->image->name);
607                 else strcpy(name, U.textudir);
608                 
609                 if(G.qual==LR_CTRLKEY)
610                         activate_imageselect(FILE_SPECIAL, "Replace Image", name, replace_space_image);
611                 else
612                         activate_fileselect(FILE_SPECIAL, "Replace Image", name, replace_space_image);
613                 break;
614         case 2: /* Pack Image */
615                 ima = G.sima->image;
616                 if (ima) {
617                         if (ima->packedfile) {
618                                 error("Image is already packed.");
619                         } else {
620                                 if (ima->ibuf && (ima->ibuf->userflags & IB_BITMAPDIRTY)) {
621                                         error("Can't pack painted image. Save the painted image first.");
622                                 } else {
623                                         ima->packedfile = newPackedFile(ima->name);
624                                 }
625                         }
626                 }
627                 BIF_undo_push("Pack image");
628                 allqueue(REDRAWBUTSSHADING, 0);
629                 allqueue(REDRAWHEADERS, 0);
630                 break;
631         case 3: /* Unpack Image */
632                 ima = G.sima->image;
633                 if (ima) {
634                         if (ima->packedfile) {
635                                 if (G.fileflags & G_AUTOPACK) {
636                                         if (okee("Disable AutoPack?")) {
637                                                 G.fileflags &= ~G_AUTOPACK;
638                                         }
639                                 }
640                                 
641                                 if ((G.fileflags & G_AUTOPACK) == 0) {
642                                         unpackImage(ima, PF_ASK);
643                                 }
644                         } else {
645                                 error("There are no packed images to unpack");
646                         }
647                 }
648                 BIF_undo_push("Unpack image");
649                 allqueue(REDRAWBUTSSHADING, 0);
650                 allqueue(REDRAWHEADERS, 0);
651                 break;
652         case 4: /* Texture Painting */
653                 if(G.sima->flag & SI_DRAWTOOL) G.sima->flag &= ~SI_DRAWTOOL;
654                 else G.sima->flag |= SI_DRAWTOOL;
655                 break;
656         case 5: /* Save Painted Image */
657                 ima = G.sima->image;
658                 if (ima) {
659                         strcpy(name, ima->name);
660                         if (ima->ibuf) {
661                                 char str[32];   // sufficient for message
662                                 save_image_filesel_str(str);
663                                 activate_fileselect(FILE_SPECIAL, str, name, save_paint);
664                         }
665                 }
666                 break;
667         case 6: /* Reload Image */
668                 ima = G.sima->image;
669                 if (ima) {
670                         if (ima->packedfile) {
671                                 PackedFile *pf;
672                                 pf = newPackedFile(ima->name);
673                                 if (pf) {
674                                         freePackedFile(ima->packedfile);
675                                         ima->packedfile = pf;
676                                 }
677                                 else
678                                         error("Image not available. Keeping packed image.");
679                         }
680                         free_image_buffers(ima);        /* force read again */
681                         ima->ok= 1;
682                         image_changed(G.sima, 0);
683                 }
684                 allqueue(REDRAWIMAGE, 0);
685                 allqueue(REDRAWVIEW3D, 0);
686                 break;
687         }
688 }
689
690 static uiBlock *image_imagemenu(void *arg_unused)
691 {
692         uiBlock *block;
693         short yco= 0, menuwidth=150;
694
695         block= uiNewBlock(&curarea->uiblocks, "image_imagemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
696         uiBlockSetButmFunc(block, do_image_imagemenu, NULL);
697
698         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
699         
700         if (G.sima->image) {
701                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
702                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
703                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reload", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
704
705                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
706                 
707                 if (G.sima->image->packedfile) {
708                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
709                 } else {
710                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
711                 }
712                         
713                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
714
715                 if(G.sima->flag & SI_DRAWTOOL) {
716                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
717                 } else {
718                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
719                 }
720                 
721                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
722                 
723                 uiDefIconTextBlockBut(block, image_image_rtmappingmenu, NULL, ICON_RIGHTARROW_THIN, "Realtime Texture Mapping", 0, yco-=20, 120, 19, "");
724                 // uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Realtime Texture Animation|",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
725         }
726         
727         if(curarea->headertype==HEADERTOP) {
728                 uiBlockSetDirection(block, UI_DOWN);
729         }
730         else {
731                 uiBlockSetDirection(block, UI_TOP);
732                 uiBlockFlipOrder(block);
733         }
734
735         uiTextBoundsBlock(block, 80);
736
737         return block;
738 }
739
740 static void do_image_uvs_showhidemenu(void *arg, int event)
741 {
742         switch(event) {
743         case 4: /* show hidden faces */
744                 reveal_tface_uv();
745                 break;
746         case 5: /* hide selected faces */
747                 hide_tface_uv(0);
748                 break;
749         case 6: /* hide deselected faces */
750                 hide_tface_uv(1);
751                 break;
752         }
753         allqueue(REDRAWVIEW3D, 0);
754 }
755
756 static uiBlock *image_uvs_showhidemenu(void *arg_unused)
757 {
758         uiBlock *block;
759         short yco = 20, menuwidth = 120;
760
761         block= uiNewBlock(&curarea->uiblocks, "image_uvs_showhidemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
762         uiBlockSetButmFunc(block, do_image_uvs_showhidemenu, NULL);
763         
764         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden Faces|Alt H",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
765         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected Faces|H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
766         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected Faces|Shift H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
767
768         uiBlockSetDirection(block, UI_RIGHT);
769         uiTextBoundsBlock(block, 60);
770         return block;
771 }
772
773 static void do_image_uvs_propfalloffmenu(void *arg, int event)
774 {
775         extern int prop_mode;
776         
777         switch(event) {
778         case 0: /* proportional edit - sharp*/
779                 prop_mode = 0;
780                 break;
781         case 1: /* proportional edit - smooth*/
782                 prop_mode = 1;
783                 break;
784         }
785 }
786
787 static uiBlock *image_uvs_propfalloffmenu(void *arg_unused)
788 {
789         uiBlock *block;
790         short yco = 20, menuwidth = 120;
791         extern int prop_mode;
792
793         block= uiNewBlock(&curarea->uiblocks, "image_uvs_propfalloffmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
794         uiBlockSetButmFunc(block, do_image_uvs_propfalloffmenu, NULL);
795         
796         if (prop_mode==0) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Sharp|Shift O",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
797         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Sharp|Shift O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
798         if (prop_mode==1) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Smooth|Shift O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
799         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Smooth|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
800                 
801         uiBlockSetDirection(block, UI_RIGHT);
802         uiTextBoundsBlock(block, 60);
803         return block;
804 }
805
806 static void do_image_uvs_transformmenu(void *arg, int event)
807 {
808         switch(event) {
809         case 0: /* Grab */
810                 transform_tface_uv('g');
811                 break;
812         case 1: /* Rotate */
813                 transform_tface_uv('r');
814                 break;
815         case 2: /* Scale */
816                 transform_tface_uv('s');
817                 break;
818         case 3: /* Weld / Align */
819                 transform_tface_uv('w');
820                 break;
821         case 4: /* Mirror */
822                 mirrormenu_tface_uv();
823                 break;
824         }
825 }
826
827 static uiBlock *image_uvs_transformmenu(void *arg_unused)
828 {
829         uiBlock *block;
830         short yco = 20, menuwidth = 120;
831
832         block= uiNewBlock(&curarea->uiblocks, "image_uvs_transformmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
833         uiBlockSetButmFunc(block, do_image_uvs_transformmenu, NULL);
834         
835         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
836         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rotate|R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
837         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
838
839         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
840
841         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Weld/Align|W", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
842         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Mirror...|M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
843
844         uiBlockSetDirection(block, UI_RIGHT);
845         uiTextBoundsBlock(block, 60);
846         return block;
847 }
848
849
850 static void do_image_uvsmenu(void *arg, int event)
851 {
852         /* events >=20 are registered bpython scripts */
853         if (event >= 20) BPY_menu_do_python(PYMENU_UV, event - 20);
854
855         else switch(event)
856         {
857         case 1: /* UVs Constrained Rectangular */
858                 if(G.sima->flag & SI_BE_SQUARE) G.sima->flag &= ~SI_BE_SQUARE;
859                 else G.sima->flag |= SI_BE_SQUARE;
860                 break;
861         case 2: /* UVs Clipped to Image Size */
862                 if(G.sima->flag & SI_CLIP_UV) G.sima->flag &= ~SI_CLIP_UV;
863                 else G.sima->flag |= SI_CLIP_UV;
864                 break;
865         case 3: /* Limit Stitch UVs */
866                 stitch_uv_tface(1);
867                 break;
868         case 4: /* Stitch UVs */
869                 stitch_uv_tface(0);
870                 break;
871         case 5: /* Proportional Edit (toggle) */
872                 if(G.f & G_PROPORTIONAL)
873                         G.f &= ~G_PROPORTIONAL;
874                 else
875                         G.f |= G_PROPORTIONAL;
876                 break;
877         case 7: /* UVs Snap to Pixel */
878                 if(G.sima->flag & SI_NOPIXELSNAP) G.sima->flag &= ~SI_NOPIXELSNAP;
879                 else G.sima->flag |= SI_NOPIXELSNAP;
880                 break;
881     case 8:
882                 pin_tface_uv(1);
883                 break;
884     case 9:
885                 pin_tface_uv(0);
886                 break;
887     case 10:
888                 if (okee("LSCM unwrap"))
889                         unwrap_lscm();
890                 break;
891         }
892 }
893
894 static uiBlock *image_uvsmenu(void *arg_unused)
895 {
896         uiBlock *block;
897         short yco= 0, menuwidth=120;
898         BPyMenu *pym;
899         int i = 0;
900
901         block= uiNewBlock(&curarea->uiblocks, "image_uvsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
902         uiBlockSetButmFunc(block, do_image_uvsmenu, NULL);
903
904         // uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
905         // uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
906         if(G.sima->flag & SI_NOPIXELSNAP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
907         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
908
909         if(G.sima->flag & SI_BE_SQUARE) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
910         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
911         
912         if(G.sima->flag & SI_CLIP_UV) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Layout Clipped to Image Size|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
913         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Layout Clipped to Image Size|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
914
915         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
916
917         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpin|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
918         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pin|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
919         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "LSCM Unwrap|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
920
921         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
922
923         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Limit Stitch...|Shift V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
924         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Stitch|V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
925         uiDefIconTextBlockBut(block, image_uvs_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 19, "");
926
927         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
928
929         if(G.f & G_PROPORTIONAL)
930                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
931         else
932                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
933
934         uiDefIconTextBlockBut(block, image_uvs_propfalloffmenu, NULL, ICON_RIGHTARROW_THIN, "Proportional Falloff", 0, yco-=20, 120, 19, "");
935
936         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
937         
938         /* note that we acount for the 3 previous entries with i+3: */
939         for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
940
941                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
942                                  NULL, 0.0, 0.0, 1, i+20, 
943                                  pym->tooltip?pym->tooltip:pym->filename);
944         }
945
946         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
947
948         uiDefIconTextBlockBut(block, image_uvs_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Faces", 0, yco-=20, menuwidth, 19, "");
949
950         if(curarea->headertype==HEADERTOP) {
951                 uiBlockSetDirection(block, UI_DOWN);
952         }
953         else {
954                 uiBlockSetDirection(block, UI_TOP);
955                 uiBlockFlipOrder(block);
956         }
957
958         uiTextBoundsBlock(block, 50);
959
960         return block;
961 }
962
963 void image_buttons(void)
964 {
965         uiBlock *block;
966         short xco, xmax;
967         char naam[256];
968         /* This should not be a static var */
969         static int headerbuttons_packdummy;
970
971         headerbuttons_packdummy = 0;
972                 
973         sprintf(naam, "header %d", curarea->headwin);
974         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
975
976         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
977         else uiBlockSetCol(block, TH_HEADERDESEL);
978
979         what_image(G.sima);
980
981         curarea->butspacetype= SPACE_IMAGE;
982
983         xco = 8;
984         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0, "Current Window Type. Click for menu of available types.");
985         xco+= XIC+14;
986
987         uiBlockSetEmboss(block, UI_EMBOSSN);
988         if(curarea->flag & HEADER_NO_PULLDOWN) {
989                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
990                                 xco,2,XIC,YIC-2,
991                                 &(curarea->flag), 0, 0, 0, 0, "Show pulldown menus");
992         } else {
993                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
994                                 xco,2,XIC,YIC-2,
995                                 &(curarea->flag), 0, 0, 0, 0, "Hide pulldown menus");
996         }
997         uiBlockSetEmboss(block, UI_EMBOSS);
998         xco+=XIC;
999
1000         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1001                 /* pull down menus */
1002                 uiBlockSetEmboss(block, UI_EMBOSSP);
1003         
1004                 xmax= GetButStringLength("View");
1005                 uiDefPulldownBut(block, image_viewmenu, NULL, "View", xco, -2, xmax-3, 24, "");
1006                 xco+= xmax;
1007                 
1008                 xmax= GetButStringLength("Select");
1009                 uiDefPulldownBut(block, image_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
1010         
1011                 xco+= xmax;
1012                 
1013                 xmax= GetButStringLength("Image");
1014                 uiDefPulldownBut(block, image_imagemenu, NULL, "Image", xco, -2, xmax-3, 24, "");
1015                 xco+= xmax;
1016                 
1017                 xmax= GetButStringLength("UVs");
1018                 uiDefPulldownBut(block, image_uvsmenu, NULL, "UVs", xco, -2, xmax-3, 24, "");
1019                 xco+= xmax;
1020         }
1021         
1022         
1023         /* other buttons: */
1024         uiBlockSetEmboss(block, UI_EMBOSS);
1025
1026         // xco+=XIC;
1027
1028         /*xco = 8;
1029         
1030         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu of available types.");
1031 */
1032         // xco+= XIC+22;
1033         
1034         /* FULL WINDOW */
1035         /* if(curarea->full) uiDefIconBut(block, BUT,B_FULL, ICON_SPLITSCREEN,  xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Returns to multiple views window (CTRL+Up arrow)");
1036         else uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN,   xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
1037         */
1038         
1039         /* HOME*/
1040         /*      uiDefIconBut(block, BUT, B_SIMAGEHOME, ICON_HOME,       xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Zooms window to home view showing all items (HOMEKEY)"); 
1041         
1042         
1043         uiDefIconButS(block, TOG|BIT|0, B_BE_SQUARE, ICON_KEEPRECT,     xco+=XIC,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Toggles constraining UV polygons to squares while editing");
1044         uiDefIconButS(block, ICONTOG|BIT|2, B_CLIP_UV, ICON_CLIPUV_DEHLT,xco+=XIC,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Toggles clipping UV with image size");
1045         */
1046     
1047         xco= std_libbuttons(block, xco, 0, 0, NULL, B_SIMABROWSE, (ID *)G.sima->image, 0, &(G.sima->imanr), 0, 0, B_IMAGEDELETE, 0, 0);
1048
1049         
1050         if (G.sima->image) {
1051         
1052                 xco+= 8;
1053         
1054                 if (G.sima->image->packedfile) {
1055                         headerbuttons_packdummy = 1;
1056                 }
1057                 uiDefIconButI(block, TOG|BIT|0, B_SIMAPACKIMA, ICON_PACKAGE,    xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
1058                 
1059                 xco+= XIC;
1060         }
1061         
1062         
1063         /*
1064         uiBlockSetCol(block, TH_AUTO);
1065         uiDefBut(block, BUT, B_SIMAGELOAD, "Load",              xco, 0, 2*XIC, YIC, 0, 0, 0, 0, 0, "Loads image - file select");
1066         xco+= 2*XIC;
1067         
1068         if (G.sima->image) {
1069                 uiBlockSetCol(block, TH_AUTO);
1070                 uiDefBut(block, BUT, B_SIMAGEREPLACE, "Replace",xco,0,(short)(3*XIC),YIC, 0, 0, 0, 0, 0, "Replaces current image - file select");
1071                 xco+= 3.5*XIC;
1072                 uiDefIconButS(block, TOG|BIT|4, 0, ICON_ENVMAP, xco,0,XIC,YIC, &G.sima->image->flag, 0, 0, 0, 0, "Uses this image as a reflection map (Ignores UV Coordinates)");
1073
1074                 uiDefIconButS(block, TOG|BIT|0, B_SIMAGEDRAW1, ICON_GRID, xco+=XIC,0,XIC,YIC, &G.sima->image->flag, 0, 0, 0, 0, "");
1075                 uiDefButS(block, NUM, B_SIMAGEDRAW, "", xco+=XIC,0,XIC,YIC, &G.sima->image->xrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the X direction");
1076                 uiDefButS(block, NUM, B_SIMAGEDRAW, "", xco+=XIC,0,XIC,YIC, &G.sima->image->yrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the Y direction");
1077         
1078                 uiDefButS(block, TOG|BIT|1, B_TWINANIM, "Anim", xco,0,(2*XIC),YIC, &G.sima->image->tpageflag, 0, 0, 0, 0, "Toggles use of animated texture");
1079                 xco+= XIC;
1080                 uiDefButS(block, NUM, B_TWINANIM, "",   xco+=XIC,0,XIC,YIC, &G.sima->image->twsta, 0.0, 128.0, 0, 0, "Displays the start frame of an animated texture. Click to change.");
1081                 uiDefButS(block, NUM, B_TWINANIM, "",   xco+=XIC,0,XIC,YIC, &G.sima->image->twend, 0.0, 128.0, 0, 0, "Displays the end frame of an animated texture. Click to change.");
1082 //              uiDefButS(block, TOG|BIT|2, 0, "Cycle", xco+=XIC,0,2*XIC,YIC, &G.sima->image->tpageflag, 0, 0, 0, 0, "");
1083                 
1084                 uiDefButS(block, NUM, 0, "Speed", xco,0,4*XIC,YIC, &G.sima->image->animspeed, 1.0, 100.0, 0, 0, "Displays Speed of the animation in frames per second. Click to change.");
1085                 xco+= 4.5*XIC;
1086
1087                 // texture paint button used to be here
1088                 
1089                 xco+= XIC;
1090                 if (G.sima->image && G.sima->image->ibuf && (G.sima->image->ibuf->userflags & IB_BITMAPDIRTY)) {
1091                         uiDefBut(block, BUT, B_SIMAGESAVE, "Save",              xco,0,2*XIC,YIC, 0, 0, 0, 0, 0, "Saves image");
1092                         xco += 2*XIC;
1093                 }
1094         }
1095 */
1096
1097         xco+= 8;
1098
1099         if (G.sima->image) {
1100
1101 #ifdef NAN_TPT
1102                 
1103                 uiDefIconButS(block, TOG|BIT|3, B_SIMAGEPAINTTOOL, ICON_TPAINT_HLT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Enables painting textures on the image with left mouse button");
1104                 xco+= XIC+8;
1105 #endif /* NAN_TPT */
1106
1107         }
1108
1109         /* draw LOCK */
1110         uiDefIconButS(block, ICONTOG, 0, ICON_UNLOCKED, xco,0,XIC,YIC, &(G.sima->lock), 0, 0, 0, 0, "Updates other affected window spaces automatically to reflect changes in real time");
1111         
1112         /* Always do this last */
1113         curarea->headbutlen= xco+2*XIC;
1114         
1115         uiDrawBlock(block);
1116 }
1117