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