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