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