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