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