[#11152] [C] key shortcut is broken in UV/Image Editor
[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 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.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
24  *
25  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26  * All rights reserved.
27  *
28  * The Original Code is: all of this file.
29  *
30  * Contributor(s): none yet.
31  *
32  * ***** END GPL LICENSE BLOCK *****
33  */
34
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "DNA_brush_types.h"
43 #include "DNA_ID.h"
44 #include "DNA_image_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
48 #include "DNA_texture_types.h"
49 #include "DNA_userdef_types.h"
50 #include "DNA_customdata_types.h" /* for UV layer menu */
51
52 #include "BLI_arithb.h"
53 #include "BLI_blenlib.h"
54
55 #include "BDR_drawmesh.h"
56 #include "BDR_unwrapper.h"
57
58 #include "BKE_brush.h"
59 #include "BKE_colortools.h"
60 #include "BKE_global.h"
61 #include "BKE_image.h"
62 #include "BKE_main.h"
63 #include "BKE_utildefines.h"
64 #include "BLI_editVert.h" /* for UV layer menu */
65 #include "BKE_customdata.h" /* ditto */
66
67 #include "BIF_butspace.h"
68 #include "BIF_drawimage.h"
69 #include "BIF_editsima.h"
70 #include "BIF_imasel.h"
71 #include "BIF_interface.h"
72 #include "BIF_resources.h"
73 #include "BIF_screen.h"
74 #include "BIF_space.h"
75 #include "BIF_transform.h"
76 #include "BIF_toolbox.h"
77 #include "BIF_editmesh.h"
78
79 #include "BSE_drawview.h"
80 #include "BSE_filesel.h"
81 #include "BSE_headerbuttons.h"
82 #include "BSE_trans_types.h"
83 #include "BSE_edit.h"
84
85 #include "BPY_extern.h"
86 #include "BPY_menus.h"
87
88 #include "IMB_imbuf_types.h"
89
90 #include "RE_pipeline.h"
91
92 #include "blendef.h"
93 #include "butspace.h"
94 #include "mydevice.h"
95
96 void do_image_buttons(unsigned short event)
97 {
98         ToolSettings *settings= G.scene->toolsettings;
99         ID *id, *idtest;
100         int nr;
101
102         if(curarea->win==0) return;
103
104         if(event<=100) {
105                 if(event<=50) do_global_buttons2(event);
106                 else do_global_buttons(event);
107                 return;
108         }
109         
110         switch(event) {
111         case B_SIMAPIN:
112                 allqueue (REDRAWIMAGE, 0);
113                 break;
114         case B_SIMAGEHOME:
115                 image_home();
116                 break;
117
118         case B_SIMABROWSE:      
119                 if(G.sima->imanr== -2) {
120                         if(G.qual & LR_CTRLKEY) {
121                                 activate_databrowse_imasel((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
122                                                                                         &G.sima->imanr, do_image_buttons);
123                         } else {
124                                 activate_databrowse((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
125                                                                                         &G.sima->imanr, do_image_buttons);
126                         }
127                         return;
128                 }
129                 if(G.sima->imanr < 0) break;
130         
131                 nr= 1;
132                 id= (ID *)G.sima->image;
133
134                 idtest= BLI_findlink(&G.main->image, G.sima->imanr-1);
135                 if(idtest==NULL) { /* no new */
136                         return;
137                 }
138         
139                 if(idtest!=id) {
140                         G.sima->image= (Image *)idtest;
141                         if(idtest->us==0) idtest->us= 1;
142                         BKE_image_signal(G.sima->image, &G.sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
143                         allqueue(REDRAWIMAGE, 0);
144                 }
145                 /* also when image is the same: assign! 0==no tileflag: */
146                 image_changed(G.sima, (Image *)idtest);
147                 BIF_undo_push("Assign image UV");
148
149                 break;
150         case B_SIMAGETILE:
151                 image_set_tile(G.sima, 1);              /* 1: only tileflag */
152                 allqueue(REDRAWVIEW3D, 0);
153                 allqueue(REDRAWIMAGE, 0);
154                 break;
155         case B_SIMA3DVIEWDRAW:
156                 allqueue(REDRAWVIEW3D, 0);
157                 break;
158         case B_SIMA_REDR_IMA_3D:
159                 allqueue(REDRAWVIEW3D, 0);
160                 allqueue(REDRAWIMAGE, 0);
161                 break;
162         case B_SIMAGEPAINTTOOL:
163                 if(G.sima->flag & SI_DRAWTOOL)
164                         /* add new brush if none exists */
165                         brush_check_exists(&G.scene->toolsettings->imapaint.brush);
166                 allqueue(REDRAWBUTSSHADING, 0);
167                 allqueue(REDRAWIMAGE, 0);
168                 allqueue(REDRAWVIEW3D, 0);
169                 break;
170
171         case B_SIMAPACKIMA:
172                 pack_image_sima();
173                 break;
174                 
175         case B_SIMA_REPACK:
176                 BKE_image_memorypack(G.sima->image);
177                 allqueue(REDRAWIMAGE, 0);
178                 break;
179                 
180         case B_SIMA_USE_ALPHA:
181                 G.sima->flag &= ~(SI_SHOW_ALPHA|SI_SHOW_ZBUF);
182                 scrarea_queue_winredraw(curarea);
183                 scrarea_queue_headredraw(curarea);
184                 break;
185         case B_SIMA_SHOW_ALPHA:
186                 G.sima->flag &= ~(SI_USE_ALPHA|SI_SHOW_ZBUF);
187                 scrarea_queue_winredraw(curarea);
188                 scrarea_queue_headredraw(curarea);
189                 break;
190         case B_SIMA_SHOW_ZBUF:
191                 G.sima->flag &= ~(SI_SHOW_ALPHA|SI_USE_ALPHA);
192                 scrarea_queue_winredraw(curarea);
193                 scrarea_queue_headredraw(curarea);
194                 break;
195         case B_SIMARELOAD:
196                 reload_image_sima();
197                 break;
198         case B_SIMAGELOAD:
199                 open_image_sima(0);
200                 break;
201         case B_SIMANAME:
202                 if(G.sima->image) {
203                         Image *ima;
204                         char str[FILE_MAXDIR+FILE_MAXFILE];
205                         
206                         /* name in ima has been changed by button! */
207                         BLI_strncpy(str, G.sima->image->name, sizeof(str));
208                         ima= BKE_add_image_file(str);
209                         if(ima) {
210                                 BKE_image_signal(ima, &G.sima->iuser, IMA_SIGNAL_RELOAD);
211                                 image_changed(G.sima, ima);
212                         }
213                         BIF_undo_push("Load image");
214                         allqueue(REDRAWIMAGE, 0);
215                 }
216                 break;
217         case B_SIMAMULTI:
218                 if(G.sima && G.sima->image) {
219                         BKE_image_multilayer_index(G.sima->image->rr, &G.sima->iuser);
220                         allqueue(REDRAWIMAGE, 0);
221                 }
222                 break;
223         case B_TRANS_IMAGE:
224                 image_editvertex_buts(NULL);
225                 break;
226         case B_CURSOR_IMAGE:
227                 image_editcursor_buts(NULL);
228                 break;
229                 
230         case B_TWINANIM:
231         {
232                 Image *ima;
233                 int nr;
234                 
235                 ima = G.sima->image;
236                 if (ima) {
237                         if(ima->flag & IMA_TWINANIM) {
238                                 nr= ima->xrep*ima->yrep;
239                                 if(ima->twsta>=nr) ima->twsta= 1;
240                                 if(ima->twend>=nr) ima->twend= nr-1;
241                                 if(ima->twsta>ima->twend) ima->twsta= 1;
242                                 allqueue(REDRAWIMAGE, 0);
243                         }
244                 }
245                 break;
246         }       
247         case B_SIMACLONEBROWSE:
248                 if (settings->imapaint.brush)
249                         if (brush_clone_image_set_nr(settings->imapaint.brush, G.sima->menunr))
250                                 allqueue(REDRAWIMAGE, 0);
251                 break;
252                 
253         case B_SIMACLONEDELETE:
254                 if (settings->imapaint.brush)
255                         if (brush_clone_image_delete(settings->imapaint.brush))
256                                 allqueue(REDRAWIMAGE, 0);
257                 break;
258                 
259         case B_SIMABRUSHCHANGE:
260                 allqueue(REDRAWIMAGE, 0);
261                 allqueue(REDRAWBUTSEDIT, 0);
262                 break;
263                 
264         case B_SIMACURVES:
265                 curvemapping_do_ibuf(G.sima->cumap, imagewindow_get_ibuf(G.sima));
266                 allqueue(REDRAWIMAGE, 0);
267                 break;
268                 
269         case B_SIMARANGE:
270                 curvemapping_set_black_white(G.sima->cumap, NULL, NULL);
271                 curvemapping_do_ibuf(G.sima->cumap, imagewindow_get_ibuf(G.sima));
272                 allqueue(REDRAWIMAGE, 0);
273                 break;
274                 
275         case B_SIMABRUSHBROWSE:
276                 if(G.sima->menunr==-2) {
277                         activate_databrowse((ID*)settings->imapaint.brush, ID_BR, 0, B_SIMABRUSHBROWSE, &G.sima->menunr, do_global_buttons);
278                         break;
279                 }
280                 else if(G.sima->menunr < 0) break;
281                 
282                 if(brush_set_nr(&settings->imapaint.brush, G.sima->menunr)) {
283                         BIF_undo_push("Browse Brush");
284                         allqueue(REDRAWBUTSEDIT, 0);
285                         allqueue(REDRAWIMAGE, 0);
286                 }
287                 break;
288         case B_SIMABRUSHDELETE:
289                 if(brush_delete(&settings->imapaint.brush)) {
290                         BIF_undo_push("Unlink Brush");
291                         allqueue(REDRAWIMAGE, 0);
292                         allqueue(REDRAWBUTSEDIT, 0);
293                 }
294                 break;
295         case B_KEEPDATA:
296                 brush_toggled_fake_user(settings->imapaint.brush);
297                 allqueue(REDRAWIMAGE, 0);
298                 allqueue(REDRAWBUTSEDIT, 0);
299                 break;
300         case B_SIMABRUSHLOCAL:
301                 if(settings->imapaint.brush && settings->imapaint.brush->id.lib) {
302                         if(okee("Make local")) {
303                                 make_local_brush(settings->imapaint.brush);
304                                 allqueue(REDRAWIMAGE, 0);
305                                 allqueue(REDRAWBUTSEDIT, 0);
306                         }
307                 }
308                 break;
309         case B_SIMABTEXBROWSE:
310                 if(settings->imapaint.brush) {
311                         Brush *brush= settings->imapaint.brush;
312                         
313                         if(G.sima->menunr==-2) {
314                                 MTex *mtex= brush->mtex[brush->texact];
315                                 ID *id= (ID*)((mtex)? mtex->tex: NULL);
316                                 if(G.qual & LR_CTRLKEY) {
317                                         activate_databrowse_imasel(id, ID_TE, 0, B_SIMABTEXBROWSE, &G.sima->menunr, do_image_buttons);
318                                 } else {
319                                         activate_databrowse(id, ID_TE, 0, B_SIMABTEXBROWSE, &G.sima->menunr, do_image_buttons);
320                                 }
321                                 break;
322                         }
323                         else if(G.sima->menunr < 0) break;
324                         
325                         if(brush_texture_set_nr(brush, G.sima->menunr)) {
326                                 BIF_undo_push("Browse Brush Texture");
327                                 allqueue(REDRAWBUTSSHADING, 0);
328                                 allqueue(REDRAWBUTSEDIT, 0);
329                                 allqueue(REDRAWIMAGE, 0);
330                         }
331                 }
332                 break;
333         case B_SIMABTEXDELETE:
334                 if(settings->imapaint.brush) {
335                         if (brush_texture_delete(settings->imapaint.brush)) {
336                                 BIF_undo_push("Unlink Brush Texture");
337                                 allqueue(REDRAWBUTSSHADING, 0);
338                                 allqueue(REDRAWBUTSEDIT, 0);
339                                 allqueue(REDRAWIMAGE, 0);
340                         }
341                 }
342                 break;
343         case B_SIMA_PLAY:
344                 play_anim(0);
345                 break;
346         case B_SIMA_RECORD:
347                 imagespace_composite_flipbook(curarea);
348                 break;
349         }
350 }
351
352 static void do_image_buttons_set_uvlayer_callback(void *act, void *data)
353 {
354         CustomData_set_layer_active(&G.editMesh->fdata, CD_MTFACE, *((int *)act));
355         
356         BIF_undo_push("Set Active UV Texture");
357         allqueue(REDRAWVIEW3D, 0);
358         allqueue(REDRAWBUTSEDIT, 0);
359         allqueue(REDRAWIMAGE, 0);
360 }
361
362 static void do_image_view_viewnavmenu(void *arg, int event)
363 {
364         switch(event) {
365         case 1: /* Zoom In */
366                 image_viewzoom(PADPLUSKEY, 0);
367                 break;
368         case 2: /* Zoom Out */
369                 image_viewzoom(PADMINUS, 0);
370                 break;
371         case 3: /* Zoom 8:1 */
372                 image_viewzoom(PAD8, 0);
373                 break;
374         case 4: /* Zoom 4:1 */
375                 image_viewzoom(PAD4, 0);
376                 break;
377         case 5: /* Zoom 2:1 */
378                 image_viewzoom(PAD2, 0);
379                 break;
380         case 6: /* Zoom 1:1 */
381                 image_viewzoom(PAD1, 0);
382                 break;
383         case 7: /* Zoom 1:2 */
384                 image_viewzoom(PAD2, 1);
385                 break;
386         case 8: /* Zoom 1:4 */
387                 image_viewzoom(PAD4, 1);
388                 break;
389         case 9: /* Zoom 1:8 */
390                 image_viewzoom(PAD8, 1);
391                 break;
392         }
393         allqueue(REDRAWIMAGE, 0);
394 }
395
396 static uiBlock *image_view_viewnavmenu(void *arg_unused)
397 {
398 /*              static short tog=0; */
399         uiBlock *block;
400         short yco= 0, menuwidth=120;
401         
402         block= uiNewBlock(&curarea->uiblocks, "image_view_viewnavmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
403         uiBlockSetButmFunc(block, do_image_view_viewnavmenu, NULL);
404         
405         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom In|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
406         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Out|NumPad -",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
407
408         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
409
410         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:8|Shift+NumPad 8", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
411         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:4|Shift+NumPad 4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
412         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:2|Shift+NumPad 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
413         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:1|NumPad 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
414         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 2:1|NumPad 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
415         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 4:1|NumPad 4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
416         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 8:1|NumPad 8", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
417
418         uiBlockSetDirection(block, UI_RIGHT);
419         uiTextBoundsBlock(block, 50);
420         return block;
421 }
422
423 static void do_image_viewmenu(void *arg, int event)
424 {
425
426         switch(event) {
427         case 0: /* Update Automatically */
428                 if(G.sima->lock) G.sima->lock = 0;
429                 else G.sima->lock = 1;
430                 break;
431         case 1: /* View All */
432                 do_image_buttons(B_SIMAGEHOME);
433                 break;
434         case 2: /* Maximize Window */
435                 /* using event B_FULL */
436                 break;
437         case 4: /* Realtime Panel... */
438                 add_blockhandler(curarea, IMAGE_HANDLER_VIEW_PROPERTIES, UI_PNL_UNSTOW);
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_viewcenter();
448                 break;
449         case 11: /* Curves Panel... */
450                 add_blockhandler(curarea, IMAGE_HANDLER_CURVES, UI_PNL_UNSTOW);
451                 break;
452         case 12: /* composite preview */
453                 toggle_blockhandler(curarea, IMAGE_HANDLER_PREVIEW, 0);
454                 scrarea_queue_winredraw(curarea);
455                 break;
456         case 13: /* Realtime Panel... */
457                 add_blockhandler(curarea, IMAGE_HANDLER_GAME_PROPERTIES, UI_PNL_UNSTOW);
458                 break;
459         case 14: /* Draw active image UV's only*/
460                 G.sima->flag ^= SI_LOCAL_UV;
461                 allqueue(REDRAWIMAGE, 0);
462                 break;
463         }
464         allqueue(REDRAWVIEW3D, 0);
465 }
466
467 static uiBlock *image_viewmenu(void *arg_unused)
468 {
469 /*      static short tog=0; */
470         uiBlock *block;
471         short yco= 0, menuwidth=120;
472         
473         block= uiNewBlock(&curarea->uiblocks, "image_viewmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
474         uiBlockSetButmFunc(block, do_image_viewmenu, NULL);
475
476         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Properties...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
477         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Image Properties...|N",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
478         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Real-time Properties...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 13, "");
479         if (G.sima->image && (G.sima->flag & SI_DRAWTOOL)) {
480                 uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Paint Tool...|C",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
481         }
482         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Curves Tool...",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
483         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Composite Preview...|Shift P",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
484         
485         if(G.sima->flag & SI_LOCAL_UV) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "UV Local View|NumPad /",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
486         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Local View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
487         if(!(G.sima->flag & SI_LOCAL_UV)) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "UV Global View|NumPad /",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
488         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Global View|NumPad /",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
489         
490         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
491         
492         uiDefIconTextBlockBut(block, image_view_viewnavmenu, NULL, ICON_RIGHTARROW_THIN, "View Navigation", 0, yco-=20, 120, 19, "");
493
494         if(G.sima->lock) {
495                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
496         } else {
497                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
498         } 
499
500         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
501         
502         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View Selected|NumPad .",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
503         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
504                 
505         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, "");
506         else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
507         
508         if(curarea->headertype==HEADERTOP) {
509                 uiBlockSetDirection(block, UI_DOWN);
510         }
511         else {
512                 uiBlockSetDirection(block, UI_TOP);
513                 uiBlockFlipOrder(block);
514         }
515
516         uiTextBoundsBlock(block, 50);
517         
518         return block;
519 }
520
521 static void do_image_selectmenu(void *arg, int event)
522 {
523         switch(event)
524         {
525         case 0: /* Border Select */
526                 borderselect_sima(UV_SELECT_ALL);
527                 break;
528         case 8: /* Border Select Pinned */
529                 borderselect_sima(UV_SELECT_PINNED);
530                 break;
531         case 1: /* Select/Deselect All */
532                 select_swap_tface_uv();
533                 break;
534         case 9: /* Select Inverse */
535                 select_invert_tface_uv();
536                 break;
537         case 2: /* Unlink Selection */
538                 unlink_selection();
539                 break;
540         case 3: /* Linked UVs */
541                 select_linked_tface_uv(2);
542                 break;
543         case 6: /* Toggle Active Face Select */
544                 if(G.sima->flag & SI_SELACTFACE)
545                         G.sima->flag &= ~SI_SELACTFACE;
546                 else
547                         G.sima->flag |= SI_SELACTFACE;
548                 allqueue(REDRAWIMAGE, 0);
549                 break;
550         case 7: /* Pinned UVs */
551                 select_pinned_tface_uv();
552                 break;
553         }
554 }
555
556 static uiBlock *image_selectmenu(void *arg_unused)
557 {
558         uiBlock *block;
559         short yco= 0, menuwidth=120;
560
561         block= uiNewBlock(&curarea->uiblocks, "image_selectmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
562         uiBlockSetButmFunc(block, do_image_selectmenu, NULL);
563         
564         
565         if ((G.sima->flag & SI_SYNC_UVSEL)==0 || (G.sima->flag & SI_SYNC_UVSEL && (G.scene->selectmode != SCE_SELECT_FACE))) {
566                 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, "");
567                 else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
568         
569                 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
570         }
571         
572         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
573         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select Pinned|Shift B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
574
575         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
576
577         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
578
579         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
580
581         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unlink Selection|Alt L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
582         
583         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
584
585         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pinned UVs|Shift P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
586         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Linked UVs|Ctrl L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
587
588         if(curarea->headertype==HEADERTOP) {
589                 uiBlockSetDirection(block, UI_DOWN);
590         }
591         else {
592                 uiBlockSetDirection(block, UI_TOP);
593                 uiBlockFlipOrder(block);
594         }
595
596         uiTextBoundsBlock(block, 50);
597
598         return block;
599 }
600
601 static void do_image_image_rtmappingmenu(void *arg, int event)
602 {
603         switch(event) {
604         case 0: /* UV Co-ordinates */
605                 G.sima->image->flag &= ~IMA_REFLECT;
606                 break;
607         case 1: /* Reflection */
608                 G.sima->image->flag |= IMA_REFLECT;
609                 break;
610         }
611
612         allqueue(REDRAWVIEW3D, 0);
613 }
614
615 static uiBlock *image_image_rtmappingmenu(void *arg_unused)
616 {
617         uiBlock *block;
618         short yco = 20, menuwidth = 120;
619
620         block= uiNewBlock(&curarea->uiblocks, "image_image_rtmappingmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
621         uiBlockSetButmFunc(block, do_image_image_rtmappingmenu, NULL);
622         
623         if (G.sima->image->flag & IMA_REFLECT) {
624                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Co-ordinates",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
625                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Reflection",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
626         } else {
627                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "UV Co-ordinates",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
628                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Reflection",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
629         }
630
631         uiBlockSetDirection(block, UI_RIGHT);
632         uiTextBoundsBlock(block, 60);
633         return block;
634 }
635
636 static void do_image_imagemenu(void *arg, int event)
637 {
638         /* events >=20 are registered bpython scripts */
639         if (event >= 20) BPY_menu_do_python(PYMENU_IMAGE, event - 20);
640         
641         switch(event)
642         {
643         case 0:
644                 open_image_sima((G.qual==LR_CTRLKEY));
645                 break;
646         case 1:
647                 replace_image_sima((G.qual==LR_CTRLKEY));
648                 break;
649         case 2:
650                 pack_image_sima();
651                 break;
652         case 4: /* Texture Painting */
653                 brush_check_exists(&G.scene->toolsettings->imapaint.brush);
654                 if(G.sima->flag & SI_DRAWTOOL) G.sima->flag &= ~SI_DRAWTOOL;
655                 else G.sima->flag |= SI_DRAWTOOL;
656                 allqueue(REDRAWBUTSSHADING, 0);
657                 break;
658         case 5:
659                 save_as_image_sima();
660                 break;
661         case 6:
662                 reload_image_sima();
663                 break;
664         case 7:
665                 new_image_sima();
666                 break;
667         case 8:
668                 save_image_sima();
669                 break;
670         case 9:
671                 save_image_sequence_sima();
672                 break;
673         case 10:
674                 BKE_image_memorypack(G.sima->image);
675                 allqueue(REDRAWIMAGE, 0);
676                 break;
677         }
678 }
679
680 static uiBlock *image_imagemenu(void *arg_unused)
681 {
682         ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
683         uiBlock *block;
684         short yco= 0, menuwidth=150;
685         BPyMenu *pym;
686         int i = 0;
687
688         block= uiNewBlock(&curarea->uiblocks, "image_imagemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
689         uiBlockSetButmFunc(block, do_image_imagemenu, NULL);
690
691         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New...|Alt N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
692         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|Alt O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
693         
694         if (G.sima->image) {
695                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
696                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reload|Alt R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
697                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
698
699                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
700                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
701                 if(G.sima->image->source==IMA_SRC_SEQUENCE)
702                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Changed Images", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
703                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
704                 
705                 if (G.sima->image->packedfile) {
706                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
707                 } else {
708                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
709                 }
710                 
711                 /* only for dirty && specific image types */
712                 if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
713                         if( ELEM(G.sima->image->source, IMA_SRC_FILE, IMA_SRC_GENERATED))
714                                 if(G.sima->image->type!=IMA_TYPE_MULTILAYER)
715                                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image as PNG", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
716                 
717                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
718
719                 if(G.sima->flag & SI_DRAWTOOL) {
720                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
721                 } else {
722                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
723                 }
724                 
725                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
726                 
727                 uiDefIconTextBlockBut(block, image_image_rtmappingmenu, NULL, ICON_RIGHTARROW_THIN, "Realtime Texture Mapping", 0, yco-=20, 120, 19, "");
728                 // uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Realtime Texture Animation|",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
729         }
730         
731         /* note that we acount for the N previous entries with i+20: */
732         for (pym = BPyMenuTable[PYMENU_IMAGE]; pym; pym = pym->next, i++) {
733
734                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
735                                  NULL, 0.0, 0.0, 1, i+20, 
736                                  pym->tooltip?pym->tooltip:pym->filename);
737         }
738         
739         if(curarea->headertype==HEADERTOP) {
740                 uiBlockSetDirection(block, UI_DOWN);
741         }
742         else {
743                 uiBlockSetDirection(block, UI_TOP);
744                 uiBlockFlipOrder(block);
745         }
746
747         uiTextBoundsBlock(block, 80);
748
749         return block;
750 }
751
752 static void do_image_uvs_showhidemenu(void *arg, int event)
753 {
754         switch(event) {
755         case 4: /* show hidden faces */
756                 reveal_tface_uv();
757                 break;
758         case 5: /* hide selected faces */
759                 hide_tface_uv(0);
760                 break;
761         case 6: /* hide deselected faces */
762                 hide_tface_uv(1);
763                 break;
764         }
765         allqueue(REDRAWVIEW3D, 0);
766 }
767
768 static uiBlock *image_uvs_showhidemenu(void *arg_unused)
769 {
770         uiBlock *block;
771         short yco = 20, menuwidth = 120;
772
773         block= uiNewBlock(&curarea->uiblocks, "image_uvs_showhidemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
774         uiBlockSetButmFunc(block, do_image_uvs_showhidemenu, NULL);
775         
776         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden Faces|Alt H",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
777         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected Faces|H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
778         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected Faces|Shift H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
779
780         uiBlockSetDirection(block, UI_RIGHT);
781         uiTextBoundsBlock(block, 60);
782         return block;
783 }
784
785 static void do_image_uvs_propfalloffmenu(void *arg, int event)
786 {
787         G.scene->prop_mode= event;
788         allqueue(REDRAWVIEW3D, 1);
789 }
790
791 static uiBlock *image_uvs_propfalloffmenu(void *arg_unused)
792 {
793         uiBlock *block;
794         short yco = 20, menuwidth = 120;
795
796         block= uiNewBlock(&curarea->uiblocks, "image_uvs_propfalloffmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
797         uiBlockSetButmFunc(block, do_image_uvs_propfalloffmenu, NULL);
798         
799         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, "");
800         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Smooth|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SMOOTH, "");
801         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, "");
802         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Sphere|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SPHERE, "");
803         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, "");
804         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Root|Shift O",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_ROOT, "");
805         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, "");
806         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Sharp|Shift O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SHARP, "");
807         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, "");
808         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Linear|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_LIN, "");
809         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, "");
810         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Constant|Shift O",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_CONST, "");
811                 
812         uiBlockSetDirection(block, UI_RIGHT);
813         uiTextBoundsBlock(block, 60);
814         return block;
815 }
816
817 static void do_image_uvs_transformmenu(void *arg, int event)
818 {
819         switch(event) {
820         case 0: /* Grab */
821                 initTransform(TFM_TRANSLATION, CTX_NONE);
822                 Transform();
823                 break;
824         case 1: /* Rotate */
825                 initTransform(TFM_ROTATION, CTX_NONE);
826                 Transform();
827                 break;
828         case 2: /* Scale */
829                 initTransform(TFM_RESIZE, CTX_NONE);
830                 Transform();
831                 break;
832         }
833 }
834
835 static uiBlock *image_uvs_transformmenu(void *arg_unused)
836 {
837         uiBlock *block;
838         short yco = 20, menuwidth = 120;
839
840         block= uiNewBlock(&curarea->uiblocks, "image_uvs_transformmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
841         uiBlockSetButmFunc(block, do_image_uvs_transformmenu, NULL);
842         
843         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
844         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rotate|R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
845         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
846
847         uiBlockSetDirection(block, UI_RIGHT);
848         uiTextBoundsBlock(block, 60);
849         return block;
850 }
851
852 static void do_image_uvs_mirrormenu(void *arg, int event)
853 {
854         float mat[3][3];
855         
856         Mat3One(mat);
857         
858         switch(event) {
859         case 0: /* X axis */
860                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
861                 BIF_setSingleAxisConstraint(mat[0], " on global X axis");
862                 Transform();
863                 break;
864         case 1: /* Y axis */
865                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
866                 BIF_setSingleAxisConstraint(mat[1], " on global Y axis");
867                 Transform();
868                 break;
869         }
870         
871         BIF_undo_push("Mirror UV");
872 }
873
874 static uiBlock *image_uvs_mirrormenu(void *arg_unused)
875 {
876         uiBlock *block;
877         short yco = 20, menuwidth = 120;
878
879         block= uiNewBlock(&curarea->uiblocks, "image_uvs_mirrormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
880         uiBlockSetButmFunc(block, do_image_uvs_mirrormenu, NULL);
881         
882         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "X Axis|M, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
883         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Y Axis|M, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
884
885         uiBlockSetDirection(block, UI_RIGHT);
886         uiTextBoundsBlock(block, 60);
887         return block;
888 }
889
890 static void do_image_uvs_weldalignmenu(void *arg, int event)
891 {
892         switch(event) {
893         case 0: /* Weld */
894                 weld_align_tface_uv('w');
895                 break;
896         case 1: /* Align Auto */
897                 weld_align_tface_uv('a');
898                 break;
899         case 2: /* Align X */
900                 weld_align_tface_uv('x');
901                 break;
902         case 3: /* Align Y */
903                 weld_align_tface_uv('y');
904                 break;
905         }
906         
907         if(event==0) BIF_undo_push("Weld UV");
908         else if(ELEM3(event, 1, 2, 3)) BIF_undo_push("Align UV");
909 }
910
911 static uiBlock *image_uvs_weldalignmenu(void *arg_unused)
912 {
913         uiBlock *block;
914         short yco = 20, menuwidth = 120;
915
916         block= uiNewBlock(&curarea->uiblocks, "image_uvs_weldalignmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
917         uiBlockSetButmFunc(block, do_image_uvs_weldalignmenu, NULL);
918         
919         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Weld|W, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
920         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Auto|W, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
921         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align X|W, 3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
922         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Y|W, 4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
923
924         uiBlockSetDirection(block, UI_RIGHT);
925         uiTextBoundsBlock(block, 60);
926         return block;
927 }
928
929 static void do_image_uvs_scriptsmenu(void *arg, int event)
930 {
931         BPY_menu_do_python(PYMENU_UV, event);
932
933         allqueue(REDRAWIMAGE, 0);
934 }
935
936 static uiBlock *image_uvs_scriptsmenu (void *args_unused)
937 {
938         uiBlock *block;
939         BPyMenu *pym;
940         int i= 0;
941         short yco = 20, menuwidth = 120;
942         
943         block= uiNewBlock(&curarea->uiblocks, "image_uvs_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
944         uiBlockSetButmFunc(block, do_image_uvs_scriptsmenu, NULL);
945         
946         /* note that we acount for the N previous entries with i+20: */
947         for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
948                 
949                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
950                                                  NULL, 0.0, 0.0, 1, i, 
951                                                  pym->tooltip?pym->tooltip:pym->filename);
952         }
953         
954         uiBlockSetDirection(block, UI_RIGHT);
955         uiTextBoundsBlock(block, 60);
956         
957         return block;
958 }
959
960 static void do_image_uvsmenu(void *arg, int event)
961 {
962
963         switch(event) {
964 //      case 0: /* UV Transform Properties Panel... */
965 //              add_blockhandler(curarea, IMAGE_HANDLER_TRANSFORM_PROPERTIES, UI_PNL_UNSTOW);
966 //              break;
967         case 1: /* UVs Constrained Rectangular */
968                 if(G.sima->flag & SI_BE_SQUARE) G.sima->flag &= ~SI_BE_SQUARE;
969                 else G.sima->flag |= SI_BE_SQUARE;
970                 break;
971         case 2: /* UVs Clipped to Image Size */
972                 if(G.sima->flag & SI_CLIP_UV) G.sima->flag &= ~SI_CLIP_UV;
973                 else G.sima->flag |= SI_CLIP_UV;
974                 break;
975         case 3: /* Limit Stitch UVs */
976                 stitch_limit_uv_tface();
977                 break;
978         case 4: /* Stitch UVs */
979                 stitch_vert_uv_tface();
980                 break;
981         case 5: /* Proportional Edit (toggle) */
982                 if(G.scene->proportional)
983                         G.scene->proportional= 0;
984                 else
985                         G.scene->proportional= 1;
986                 break;
987         case 7: /* UVs Snap to Pixel */
988                 G.sima->flag ^= SI_PIXELSNAP;
989                 break;
990     case 8:
991                 pin_tface_uv(1);
992                 break;
993     case 9:
994                 pin_tface_uv(0);
995                 break;
996     case 10:
997                 unwrap_lscm(0);
998                 break;
999         case 11:
1000                 if(G.sima->flag & SI_LIVE_UNWRAP) G.sima->flag &= ~SI_LIVE_UNWRAP;
1001                 else G.sima->flag |= SI_LIVE_UNWRAP;
1002                 break;
1003         case 12:
1004                 minimize_stretch_tface_uv();
1005                 break;
1006         case 13:
1007                 pack_charts_tface_uv();
1008                 break;
1009         case 14:
1010                 average_charts_tface_uv();
1011                 break;
1012         }
1013 }
1014
1015 static uiBlock *image_uvsmenu(void *arg_unused)
1016 {
1017         uiBlock *block;
1018         short yco= 0, menuwidth=120;
1019
1020         block= uiNewBlock(&curarea->uiblocks, "image_uvsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1021         uiBlockSetButmFunc(block, do_image_uvsmenu, NULL);
1022         
1023         //uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1024         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1025         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, "");
1026         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1027
1028         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, "");
1029         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
1030         
1031         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, "");
1032         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, "");
1033
1034         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1035
1036         if(G.sima->flag & SI_LIVE_UNWRAP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Live Unwrap Transform", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
1037         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Live Unwrap Transform", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
1038         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unwrap|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
1039         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpin|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1040         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pin|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1041
1042         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1043
1044         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Islands|Ctrl P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 13, "");
1045         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Average Islands Scale|Ctrl A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
1046         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Minimize Stretch|Ctrl V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
1047         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Limit Stitch...|Shift V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
1048         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Stitch|V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
1049
1050         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1051         
1052         uiDefIconTextBlockBut(block, image_uvs_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 19, "");
1053         uiDefIconTextBlockBut(block, image_uvs_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 19, "");
1054         uiDefIconTextBlockBut(block, image_uvs_weldalignmenu, NULL, ICON_RIGHTARROW_THIN, "Weld/Align", 0, yco-=20, 120, 19, "");
1055         
1056         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1057
1058         if(G.scene->proportional)
1059                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1060         else
1061                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1062
1063         uiDefIconTextBlockBut(block, image_uvs_propfalloffmenu, NULL, ICON_RIGHTARROW_THIN, "Proportional Falloff", 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_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Faces", 0, yco-=20, menuwidth, 19, "");
1068
1069         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1070         
1071         uiDefIconTextBlockBut(block, image_uvs_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, "");
1072         
1073         if(curarea->headertype==HEADERTOP) {
1074                 uiBlockSetDirection(block, UI_DOWN);
1075         }
1076         else {
1077                 uiBlockSetDirection(block, UI_TOP);
1078                 uiBlockFlipOrder(block);
1079         }
1080
1081         uiTextBoundsBlock(block, 50);
1082
1083         return block;
1084 }
1085
1086 void image_buttons(void)
1087 {
1088         Image *ima;
1089         ImBuf *ibuf;
1090         uiBlock *block;
1091         short xco, xmax;
1092         char naam[256], *menuname;
1093         char is_render; /* true if the image is a render or composite */
1094         
1095         int allow_pin= B_SIMAPIN;
1096         
1097         /* This should not be a static var */
1098         static int headerbuttons_packdummy;
1099         
1100         
1101         is_render = ((G.sima->image!=NULL) && ((G.sima->image->type == IMA_TYPE_R_RESULT) || (G.sima->image->type == IMA_TYPE_COMPOSITE)));
1102
1103         headerbuttons_packdummy = 0;
1104                 
1105         sprintf(naam, "header %d", curarea->headwin);
1106         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
1107
1108         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
1109         else uiBlockSetCol(block, TH_HEADERDESEL);
1110
1111         what_image(G.sima);
1112         ima= G.sima->image;
1113         ibuf= BKE_image_get_ibuf(ima, &G.sima->iuser);
1114
1115         curarea->butspacetype= SPACE_IMAGE;
1116
1117         xco = 8;
1118         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.");
1119         xco+= XIC+14;
1120
1121         uiBlockSetEmboss(block, UI_EMBOSSN);
1122         if(curarea->flag & HEADER_NO_PULLDOWN) {
1123                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
1124                                 xco,2,XIC,YIC-2,
1125                                 &(curarea->flag), 0, 0, 0, 0, "Show pulldown menus");
1126         } else {
1127                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
1128                                 xco,2,XIC,YIC-2,
1129                                 &(curarea->flag), 0, 0, 0, 0, "Hide pulldown menus");
1130         }
1131         uiBlockSetEmboss(block, UI_EMBOSS);
1132         xco+=XIC;
1133
1134         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1135                 
1136                 /* pull down menus */
1137                 uiBlockSetEmboss(block, UI_EMBOSSP);
1138         
1139                 xmax= GetButStringLength("View");
1140                 uiDefPulldownBut(block, image_viewmenu, NULL, "View", xco, -2, xmax-3, 24, "");
1141                 xco+= xmax;
1142                 
1143                 if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
1144                         xmax= GetButStringLength("Select");
1145                         uiDefPulldownBut(block, image_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
1146                         xco+= xmax;
1147                 }
1148                 
1149                 if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
1150                         menuname= "Image*";
1151                 else
1152                         menuname= "Image";
1153                 xmax= GetButStringLength(menuname);
1154                 uiDefPulldownBut(block, image_imagemenu, NULL, menuname, xco, -2, xmax-3, 24, "");
1155                 xco+= xmax;
1156                 if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
1157                         xmax= GetButStringLength("UVs");
1158                         uiDefPulldownBut(block, image_uvsmenu, NULL, "UVs", xco, -2, xmax-3, 24, "");
1159                         xco+= xmax;
1160                 }
1161         }
1162         
1163         /* other buttons: */
1164         uiBlockSetEmboss(block, UI_EMBOSS);
1165
1166         if (is_render)
1167                 allow_pin = 0;
1168         
1169         xco= 8 + std_libbuttons(block, xco, 0, allow_pin, &G.sima->pin, B_SIMABROWSE, ID_IM, 0, (ID *)ima, 0, &(G.sima->imanr), 0, 0, B_IMAGEDELETE, 0, 0);
1170         
1171         if( ima && !ELEM3(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE, IMA_SRC_VIEWER) && ima->ok) {
1172
1173                 if (ima->packedfile) {
1174                         headerbuttons_packdummy = 1;
1175                 }
1176                 if (ima->packedfile && ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
1177                         uiDefIconButBitI(block, TOG, 1, B_SIMA_REPACK, ICON_UGLYPACKAGE,        xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Re-Pack this image as PNG");
1178                 else
1179                         uiDefIconButBitI(block, TOG, 1, B_SIMAPACKIMA, ICON_PACKAGE,    xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
1180                         
1181                 xco+= XIC+8;
1182         }
1183         
1184         /* UV EditMode buttons, not painting or rencering or compositing */
1185         if ( EM_texFaceCheck() && (G.sima->flag & SI_DRAWTOOL)==0 && !is_render) {
1186                 uiBut *ubut;
1187                 int layercount;
1188                 
1189                 uiDefIconTextButS(block, ICONTEXTROW, B_NOP, ICON_ROTATE,
1190                                 "Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1",
1191                                 xco,0,XIC+10,YIC, &(G.v2d->around), 0, 3.0, 0, 0,
1192                                 "Rotation/Scaling Pivot (Hotkeys: Comma, Shift Comma, Period)");
1193                 xco+= XIC + 18;
1194                 
1195                 
1196                 uiDefIconButBitI(block, TOG, SI_SYNC_UVSEL, B_REDR, ICON_EDIT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Sync UV and Mesh Selection");
1197                 xco+= XIC+8;
1198                 if (G.sima->flag & SI_SYNC_UVSEL) {
1199                         uiBlockBeginAlign(block);
1200                         
1201                         /* B_SEL_VERT & B_SEL_FACE are not defined here which is a bit bad, BUT it works even if image editor is fullscreen */
1202                         uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode (Ctrl Tab 1)");
1203                         xco+= XIC;
1204                         /* no edge */
1205                         /*uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Edge select mode (Ctrl Tab 2)");
1206                         xco+= XIC; */
1207                         uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Face select mode (Ctrl Tab 3)");
1208                         xco+= XIC+8;
1209                         uiBlockEndAlign(block);
1210                         
1211                 } else {
1212                         uiBlockBeginAlign(block);
1213                         uiDefIconButBitI(block, TOGN, SI_SELACTFACE, B_REDR, ICON_VERTEXSEL, xco,0,XIC,YIC, &G.sima->flag, 1.0, 0.0, 0, 0, "UV Vertex select mode");
1214                         xco+= XIC;
1215                         uiDefIconButBitI(block, TOG, SI_SELACTFACE, B_REDR, ICON_FACESEL, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "UV Face select mode");
1216                         xco+= XIC+8;
1217                         uiBlockEndAlign(block);
1218                         
1219                         /* would use these if const's could go in strings 
1220                          * SI_STICKY_LOC SI_STICKY_DISABLE SI_STICKY_VERTEX */
1221                         ubut = uiDefIconTextButC(block, ICONTEXTROW, B_REDR, ICON_STICKY_UVS_LOC,
1222                                         "Sticky UV Selection: %t|Disable%x1|Shared Location%x0|Shared Vertex%x2",
1223                                         xco,0,XIC+10,YIC, &(G.sima->sticky), 0, 3.0, 0, 0,
1224                                         "Sticky UV Selection (Hotkeys: Shift C, Alt C, Ctrl C)");
1225                         
1226                 }
1227                 xco+= XIC + 16;
1228                 
1229                 /* Snap copied right out of view3d header */
1230                         uiBlockBeginAlign(block);
1231
1232                         if (G.scene->snap_flag & SCE_SNAP) {
1233                                 uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEO,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Use Snap or Grid (Shift Tab)");   
1234                                 xco+= XIC;
1235                                 uiDefButS(block, MENU, B_NOP, "Mode%t|Closest%x0|Center%x1|Median%x2",xco,0,70,YIC, &G.scene->snap_target, 0, 0, 0, 0, "Snap Target Mode");
1236                                 xco+= 70;
1237                         } else {
1238                                 uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEAR,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Snap while Ctrl is held during transform (Shift Tab)");  
1239                                 xco+= XIC;
1240                         }
1241
1242                         uiBlockEndAlign(block);
1243                         xco+= 10;
1244                 /* end snap */
1245                         
1246                 /* Layer Menu */
1247                 layercount = CustomData_number_of_layers(&G.editMesh->fdata, CD_MTFACE); 
1248                 if (layercount>1 && layercount < 12) { /* could allow any number but limit of 11 means no malloc needed */
1249                         static int act;
1250                         char str_menu[384], *str_pt; /*384 allows for 11 layers */
1251                         
1252                         
1253                         act = CustomData_get_active_layer(&G.editMesh->fdata, CD_MTFACE);
1254                         
1255                         /*str_pt = (char *)MEM_mallocN(layercount*40 , "uvmenu"); str[0]='\0';*/
1256                         str_pt = str_menu;
1257                         str_pt[0]='\0';
1258                         mesh_layers_menu_concat(&G.editMesh->fdata, CD_MTFACE, str_pt);
1259                         ubut = uiDefButI(block, MENU, B_NOP, str_menu ,xco,0,85,YIC, &act, 0, 0, 0, 0, "Active UV Layer for editing");
1260                         uiButSetFunc(ubut, do_image_buttons_set_uvlayer_callback, &act, NULL);
1261                         
1262                         /*MEM_freeN(str);*/
1263                         xco+= 90;
1264                 }
1265         }
1266         
1267         if (ima) {
1268                 RenderResult *rr= BKE_image_get_renderresult(ima);
1269                 
1270                 xco+= 8;
1271         
1272                 if(rr) {
1273                         uiBlockBeginAlign(block);
1274                         uiblock_layer_pass_buttons(block, rr, &G.sima->iuser, B_REDR, xco, 0, 160);
1275                         uiBlockEndAlign(block);
1276                         xco+= 166;
1277                 }
1278                 uiDefIconButBitI(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");
1279                 
1280                 xco+= XIC+8;
1281
1282                 uiBlockBeginAlign(block);
1283                 if(ibuf==NULL || ibuf->channels==4) {
1284                         uiDefIconButBitI(block, TOG, SI_USE_ALPHA, B_SIMA_USE_ALPHA, ICON_TRANSP_HLT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws image with alpha");
1285                         xco+= XIC;
1286                         uiDefIconButBitI(block, TOG, SI_SHOW_ALPHA, B_SIMA_SHOW_ALPHA, ICON_DOT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws only alpha");
1287                         xco+= XIC;
1288                 }
1289                 if(ibuf) {
1290                         if(ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1)) {
1291                                 uiDefIconButBitI(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values (mapped from camera clip start to end)");
1292                                 xco+= XIC;
1293                         }
1294                 }               
1295                 xco+= 8;
1296                 
1297                 uiBlockBeginAlign(block);
1298                 if(ima->type==IMA_TYPE_COMPOSITE) {
1299                         uiDefIconBut(block, BUT, B_SIMA_RECORD, ICON_REC,  xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Record Composite");
1300                         xco+= XIC;
1301                 }
1302                 if((ima->type==IMA_TYPE_COMPOSITE) || ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
1303                         uiDefIconBut(block, BUT, B_SIMA_PLAY, ICON_PLAY, xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Play");
1304                         xco+= XIC;
1305                 }
1306                 uiBlockEndAlign(block);
1307                 xco+= 8;
1308         }
1309         
1310         /* draw LOCK */
1311         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");
1312
1313         /* Always do this last */
1314         curarea->headbutlen= xco+2*XIC;
1315         
1316         uiDrawBlock(block);
1317 }
1318