a93e79fa77372b5ae66e7913a87bc81924efa33f
[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         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Paint Tool...|C",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
480         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Curves Tool...",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
481         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Composite Preview...|Shift P",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
482         
483         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, "");
484         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Local View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
485         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, "");
486         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Global View|NumPad /",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
487         
488         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
489         
490         uiDefIconTextBlockBut(block, image_view_viewnavmenu, NULL, ICON_RIGHTARROW_THIN, "View Navigation", 0, yco-=20, 120, 19, "");
491
492         if(G.sima->lock) {
493                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
494         } else {
495                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
496         } 
497
498         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
499         
500         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View Selected|NumPad .",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
501         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
502                 
503         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, "");
504         else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
505         
506         if(curarea->headertype==HEADERTOP) {
507                 uiBlockSetDirection(block, UI_DOWN);
508         }
509         else {
510                 uiBlockSetDirection(block, UI_TOP);
511                 uiBlockFlipOrder(block);
512         }
513
514         uiTextBoundsBlock(block, 50);
515         
516         return block;
517 }
518
519 static void do_image_selectmenu(void *arg, int event)
520 {
521         switch(event)
522         {
523         case 0: /* Border Select */
524                 borderselect_sima(UV_SELECT_ALL);
525                 break;
526         case 8: /* Border Select Pinned */
527                 borderselect_sima(UV_SELECT_PINNED);
528                 break;
529         case 1: /* Select/Deselect All */
530                 select_swap_tface_uv();
531                 break;
532         case 9: /* Select Inverse */
533                 select_invert_tface_uv();
534                 break;
535         case 2: /* Unlink Selection */
536                 unlink_selection();
537                 break;
538         case 3: /* Linked UVs */
539                 select_linked_tface_uv(2);
540                 break;
541         case 6: /* Toggle Active Face Select */
542                 if(G.sima->flag & SI_SELACTFACE)
543                         G.sima->flag &= ~SI_SELACTFACE;
544                 else
545                         G.sima->flag |= SI_SELACTFACE;
546                 allqueue(REDRAWIMAGE, 0);
547                 break;
548         case 7: /* Pinned UVs */
549                 select_pinned_tface_uv();
550                 break;
551         }
552 }
553
554 static uiBlock *image_selectmenu(void *arg_unused)
555 {
556         uiBlock *block;
557         short yco= 0, menuwidth=120;
558
559         block= uiNewBlock(&curarea->uiblocks, "image_selectmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
560         uiBlockSetButmFunc(block, do_image_selectmenu, NULL);
561         
562         
563         if ((G.sima->flag & SI_SYNC_UVSEL)==0 || (G.sima->flag & SI_SYNC_UVSEL && (G.scene->selectmode != SCE_SELECT_FACE))) {
564                 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, "");
565                 else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
566         
567                 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
568         }
569         
570         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
571         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select Pinned|Shift B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
572
573         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
574
575         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
576
577         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
578
579         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unlink Selection|Alt L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
580         
581         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
582
583         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pinned UVs|Shift P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
584         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Linked UVs|Ctrl L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
585
586         if(curarea->headertype==HEADERTOP) {
587                 uiBlockSetDirection(block, UI_DOWN);
588         }
589         else {
590                 uiBlockSetDirection(block, UI_TOP);
591                 uiBlockFlipOrder(block);
592         }
593
594         uiTextBoundsBlock(block, 50);
595
596         return block;
597 }
598
599 static void do_image_image_rtmappingmenu(void *arg, int event)
600 {
601         switch(event) {
602         case 0: /* UV Co-ordinates */
603                 G.sima->image->flag &= ~IMA_REFLECT;
604                 break;
605         case 1: /* Reflection */
606                 G.sima->image->flag |= IMA_REFLECT;
607                 break;
608         }
609
610         allqueue(REDRAWVIEW3D, 0);
611 }
612
613 static uiBlock *image_image_rtmappingmenu(void *arg_unused)
614 {
615         uiBlock *block;
616         short yco = 20, menuwidth = 120;
617
618         block= uiNewBlock(&curarea->uiblocks, "image_image_rtmappingmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
619         uiBlockSetButmFunc(block, do_image_image_rtmappingmenu, NULL);
620         
621         if (G.sima->image->flag & IMA_REFLECT) {
622                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Co-ordinates",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
623                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Reflection",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
624         } else {
625                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "UV Co-ordinates",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
626                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Reflection",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
627         }
628
629         uiBlockSetDirection(block, UI_RIGHT);
630         uiTextBoundsBlock(block, 60);
631         return block;
632 }
633
634 static void do_image_imagemenu(void *arg, int event)
635 {
636         /* events >=20 are registered bpython scripts */
637         if (event >= 20) BPY_menu_do_python(PYMENU_IMAGE, event - 20);
638         
639         switch(event)
640         {
641         case 0:
642                 open_image_sima((G.qual==LR_CTRLKEY));
643                 break;
644         case 1:
645                 replace_image_sima((G.qual==LR_CTRLKEY));
646                 break;
647         case 2:
648                 pack_image_sima();
649                 break;
650         case 4: /* Texture Painting */
651                 brush_check_exists(&G.scene->toolsettings->imapaint.brush);
652                 if(G.sima->flag & SI_DRAWTOOL) G.sima->flag &= ~SI_DRAWTOOL;
653                 else G.sima->flag |= SI_DRAWTOOL;
654                 allqueue(REDRAWBUTSSHADING, 0);
655                 break;
656         case 5:
657                 save_as_image_sima();
658                 break;
659         case 6:
660                 reload_image_sima();
661                 break;
662         case 7:
663                 new_image_sima();
664                 break;
665         case 8:
666                 save_image_sima();
667                 break;
668         case 9:
669                 save_image_sequence_sima();
670                 break;
671         case 10:
672                 BKE_image_memorypack(G.sima->image);
673                 allqueue(REDRAWIMAGE, 0);
674                 break;
675         }
676 }
677
678 static uiBlock *image_imagemenu(void *arg_unused)
679 {
680         ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
681         uiBlock *block;
682         short yco= 0, menuwidth=150;
683         BPyMenu *pym;
684         int i = 0;
685
686         block= uiNewBlock(&curarea->uiblocks, "image_imagemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
687         uiBlockSetButmFunc(block, do_image_imagemenu, NULL);
688
689         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New...|Alt N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
690         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|Alt O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
691         
692         if (G.sima->image) {
693                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
694                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reload|Alt R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
695                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
696
697                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
698                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
699                 if(G.sima->image->source==IMA_SRC_SEQUENCE)
700                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Changed Images", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
701                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
702                 
703                 if (G.sima->image->packedfile) {
704                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
705                 } else {
706                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
707                 }
708                 
709                 /* only for dirty && specific image types */
710                 if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
711                         if( ELEM(G.sima->image->source, IMA_SRC_FILE, IMA_SRC_GENERATED))
712                                 if(G.sima->image->type!=IMA_TYPE_MULTILAYER)
713                                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image as PNG", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
714                 
715                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
716
717                 if(G.sima->flag & SI_DRAWTOOL) {
718                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
719                 } else {
720                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Texture Painting", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
721                 }
722                 
723                 uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
724                 
725                 uiDefIconTextBlockBut(block, image_image_rtmappingmenu, NULL, ICON_RIGHTARROW_THIN, "Realtime Texture Mapping", 0, yco-=20, 120, 19, "");
726                 // uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Realtime Texture Animation|",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
727         }
728         
729         /* note that we acount for the N previous entries with i+20: */
730         for (pym = BPyMenuTable[PYMENU_IMAGE]; pym; pym = pym->next, i++) {
731
732                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
733                                  NULL, 0.0, 0.0, 1, i+20, 
734                                  pym->tooltip?pym->tooltip:pym->filename);
735         }
736         
737         if(curarea->headertype==HEADERTOP) {
738                 uiBlockSetDirection(block, UI_DOWN);
739         }
740         else {
741                 uiBlockSetDirection(block, UI_TOP);
742                 uiBlockFlipOrder(block);
743         }
744
745         uiTextBoundsBlock(block, 80);
746
747         return block;
748 }
749
750 static void do_image_uvs_showhidemenu(void *arg, int event)
751 {
752         switch(event) {
753         case 4: /* show hidden faces */
754                 reveal_tface_uv();
755                 break;
756         case 5: /* hide selected faces */
757                 hide_tface_uv(0);
758                 break;
759         case 6: /* hide deselected faces */
760                 hide_tface_uv(1);
761                 break;
762         }
763         allqueue(REDRAWVIEW3D, 0);
764 }
765
766 static uiBlock *image_uvs_showhidemenu(void *arg_unused)
767 {
768         uiBlock *block;
769         short yco = 20, menuwidth = 120;
770
771         block= uiNewBlock(&curarea->uiblocks, "image_uvs_showhidemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
772         uiBlockSetButmFunc(block, do_image_uvs_showhidemenu, NULL);
773         
774         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden Faces|Alt H",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
775         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected Faces|H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
776         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected Faces|Shift H",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
777
778         uiBlockSetDirection(block, UI_RIGHT);
779         uiTextBoundsBlock(block, 60);
780         return block;
781 }
782
783 static void do_image_uvs_propfalloffmenu(void *arg, int event)
784 {
785         G.scene->prop_mode= event;
786         allqueue(REDRAWVIEW3D, 1);
787 }
788
789 static uiBlock *image_uvs_propfalloffmenu(void *arg_unused)
790 {
791         uiBlock *block;
792         short yco = 20, menuwidth = 120;
793
794         block= uiNewBlock(&curarea->uiblocks, "image_uvs_propfalloffmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
795         uiBlockSetButmFunc(block, do_image_uvs_propfalloffmenu, NULL);
796         
797         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, "");
798         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Smooth|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SMOOTH, "");
799         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, "");
800         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Sphere|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SPHERE, "");
801         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, "");
802         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Root|Shift O",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_ROOT, "");
803         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, "");
804         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Sharp|Shift O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_SHARP, "");
805         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, "");
806         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Linear|Shift O",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_LIN, "");
807         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, "");
808         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Constant|Shift O",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, PROP_CONST, "");
809                 
810         uiBlockSetDirection(block, UI_RIGHT);
811         uiTextBoundsBlock(block, 60);
812         return block;
813 }
814
815 static void do_image_uvs_transformmenu(void *arg, int event)
816 {
817         switch(event) {
818         case 0: /* Grab */
819                 initTransform(TFM_TRANSLATION, CTX_NONE);
820                 Transform();
821                 break;
822         case 1: /* Rotate */
823                 initTransform(TFM_ROTATION, CTX_NONE);
824                 Transform();
825                 break;
826         case 2: /* Scale */
827                 initTransform(TFM_RESIZE, CTX_NONE);
828                 Transform();
829                 break;
830         }
831 }
832
833 static uiBlock *image_uvs_transformmenu(void *arg_unused)
834 {
835         uiBlock *block;
836         short yco = 20, menuwidth = 120;
837
838         block= uiNewBlock(&curarea->uiblocks, "image_uvs_transformmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
839         uiBlockSetButmFunc(block, do_image_uvs_transformmenu, NULL);
840         
841         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
842         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rotate|R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
843         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
844
845         uiBlockSetDirection(block, UI_RIGHT);
846         uiTextBoundsBlock(block, 60);
847         return block;
848 }
849
850 static void do_image_uvs_mirrormenu(void *arg, int event)
851 {
852         float mat[3][3];
853         
854         Mat3One(mat);
855         
856         switch(event) {
857         case 0: /* X axis */
858                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
859                 BIF_setSingleAxisConstraint(mat[0], " on global X axis");
860                 Transform();
861                 break;
862         case 1: /* Y axis */
863                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
864                 BIF_setSingleAxisConstraint(mat[1], " on global Y axis");
865                 Transform();
866                 break;
867         }
868         
869         BIF_undo_push("Mirror UV");
870 }
871
872 static uiBlock *image_uvs_mirrormenu(void *arg_unused)
873 {
874         uiBlock *block;
875         short yco = 20, menuwidth = 120;
876
877         block= uiNewBlock(&curarea->uiblocks, "image_uvs_mirrormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
878         uiBlockSetButmFunc(block, do_image_uvs_mirrormenu, NULL);
879         
880         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "X Axis|M, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
881         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Y Axis|M, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
882
883         uiBlockSetDirection(block, UI_RIGHT);
884         uiTextBoundsBlock(block, 60);
885         return block;
886 }
887
888 static void do_image_uvs_weldalignmenu(void *arg, int event)
889 {
890         switch(event) {
891         case 0: /* Weld */
892                 weld_align_tface_uv('w');
893                 break;
894         case 1: /* Align Auto */
895                 weld_align_tface_uv('a');
896                 break;
897         case 2: /* Align X */
898                 weld_align_tface_uv('x');
899                 break;
900         case 3: /* Align Y */
901                 weld_align_tface_uv('y');
902                 break;
903         }
904         
905         if(event==0) BIF_undo_push("Weld UV");
906         else if(ELEM3(event, 1, 2, 3)) BIF_undo_push("Align UV");
907 }
908
909 static uiBlock *image_uvs_weldalignmenu(void *arg_unused)
910 {
911         uiBlock *block;
912         short yco = 20, menuwidth = 120;
913
914         block= uiNewBlock(&curarea->uiblocks, "image_uvs_weldalignmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
915         uiBlockSetButmFunc(block, do_image_uvs_weldalignmenu, NULL);
916         
917         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Weld|W, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
918         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Auto|W, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
919         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align X|W, 3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
920         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Y|W, 4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
921
922         uiBlockSetDirection(block, UI_RIGHT);
923         uiTextBoundsBlock(block, 60);
924         return block;
925 }
926
927 static void do_image_uvs_scriptsmenu(void *arg, int event)
928 {
929         BPY_menu_do_python(PYMENU_UV, event);
930
931         allqueue(REDRAWIMAGE, 0);
932 }
933
934 static uiBlock *image_uvs_scriptsmenu (void *args_unused)
935 {
936         uiBlock *block;
937         BPyMenu *pym;
938         int i= 0;
939         short yco = 20, menuwidth = 120;
940         
941         block= uiNewBlock(&curarea->uiblocks, "image_uvs_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
942         uiBlockSetButmFunc(block, do_image_uvs_scriptsmenu, NULL);
943         
944         /* note that we acount for the N previous entries with i+20: */
945         for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
946                 
947                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
948                                                  NULL, 0.0, 0.0, 1, i, 
949                                                  pym->tooltip?pym->tooltip:pym->filename);
950         }
951         
952         uiBlockSetDirection(block, UI_RIGHT);
953         uiTextBoundsBlock(block, 60);
954         
955         return block;
956 }
957
958 static void do_image_uvsmenu(void *arg, int event)
959 {
960
961         switch(event) {
962 //      case 0: /* UV Transform Properties Panel... */
963 //              add_blockhandler(curarea, IMAGE_HANDLER_TRANSFORM_PROPERTIES, UI_PNL_UNSTOW);
964 //              break;
965         case 1: /* UVs Constrained Rectangular */
966                 if(G.sima->flag & SI_BE_SQUARE) G.sima->flag &= ~SI_BE_SQUARE;
967                 else G.sima->flag |= SI_BE_SQUARE;
968                 break;
969         case 2: /* UVs Clipped to Image Size */
970                 if(G.sima->flag & SI_CLIP_UV) G.sima->flag &= ~SI_CLIP_UV;
971                 else G.sima->flag |= SI_CLIP_UV;
972                 break;
973         case 3: /* Limit Stitch UVs */
974                 stitch_limit_uv_tface();
975                 break;
976         case 4: /* Stitch UVs */
977                 stitch_vert_uv_tface();
978                 break;
979         case 5: /* Proportional Edit (toggle) */
980                 if(G.scene->proportional)
981                         G.scene->proportional= 0;
982                 else
983                         G.scene->proportional= 1;
984                 break;
985         case 7: /* UVs Snap to Pixel */
986                 G.sima->flag ^= SI_PIXELSNAP;
987                 break;
988     case 8:
989                 pin_tface_uv(1);
990                 break;
991     case 9:
992                 pin_tface_uv(0);
993                 break;
994     case 10:
995                 unwrap_lscm(0);
996                 break;
997         case 11:
998                 if(G.sima->flag & SI_LIVE_UNWRAP) G.sima->flag &= ~SI_LIVE_UNWRAP;
999                 else G.sima->flag |= SI_LIVE_UNWRAP;
1000                 break;
1001         case 12:
1002                 minimize_stretch_tface_uv();
1003                 break;
1004         case 13:
1005                 pack_charts_tface_uv();
1006                 break;
1007         case 14:
1008                 average_charts_tface_uv();
1009                 break;
1010         }
1011 }
1012
1013 static uiBlock *image_uvsmenu(void *arg_unused)
1014 {
1015         uiBlock *block;
1016         short yco= 0, menuwidth=120;
1017
1018         block= uiNewBlock(&curarea->uiblocks, "image_uvsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1019         uiBlockSetButmFunc(block, do_image_uvsmenu, NULL);
1020         
1021         //uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1022         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1023         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, "");
1024         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1025
1026         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, "");
1027         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
1028         
1029         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, "");
1030         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, "");
1031
1032         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1033
1034         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, "");
1035         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Live Unwrap Transform", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
1036         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unwrap|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
1037         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpin|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
1038         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pin|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
1039
1040         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1041
1042         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Islands|Ctrl P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 13, "");
1043         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Average Islands Scale|Ctrl A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
1044         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Minimize Stretch|Ctrl V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
1045         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Limit Stitch...|Shift V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
1046         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Stitch|V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
1047
1048         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1049         
1050         uiDefIconTextBlockBut(block, image_uvs_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 19, "");
1051         uiDefIconTextBlockBut(block, image_uvs_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 19, "");
1052         uiDefIconTextBlockBut(block, image_uvs_weldalignmenu, NULL, ICON_RIGHTARROW_THIN, "Weld/Align", 0, yco-=20, 120, 19, "");
1053         
1054         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1055
1056         if(G.scene->proportional)
1057                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1058         else
1059                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Proportional Editing|O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1060
1061         uiDefIconTextBlockBut(block, image_uvs_propfalloffmenu, NULL, ICON_RIGHTARROW_THIN, "Proportional Falloff", 0, yco-=20, 120, 19, "");
1062
1063         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1064
1065         uiDefIconTextBlockBut(block, image_uvs_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Faces", 0, yco-=20, menuwidth, 19, "");
1066
1067         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1068         
1069         uiDefIconTextBlockBut(block, image_uvs_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, "");
1070         
1071         if(curarea->headertype==HEADERTOP) {
1072                 uiBlockSetDirection(block, UI_DOWN);
1073         }
1074         else {
1075                 uiBlockSetDirection(block, UI_TOP);
1076                 uiBlockFlipOrder(block);
1077         }
1078
1079         uiTextBoundsBlock(block, 50);
1080
1081         return block;
1082 }
1083
1084 void image_buttons(void)
1085 {
1086         Image *ima;
1087         ImBuf *ibuf;
1088         uiBlock *block;
1089         short xco, xmax;
1090         char naam[256], *menuname;
1091         char is_render; /* true if the image is a render or composite */
1092         
1093         int allow_pin= B_SIMAPIN;
1094         
1095         /* This should not be a static var */
1096         static int headerbuttons_packdummy;
1097         
1098         
1099         is_render = ((G.sima->image!=NULL) && ((G.sima->image->type == IMA_TYPE_R_RESULT) || (G.sima->image->type == IMA_TYPE_COMPOSITE)));
1100
1101         headerbuttons_packdummy = 0;
1102                 
1103         sprintf(naam, "header %d", curarea->headwin);
1104         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
1105
1106         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
1107         else uiBlockSetCol(block, TH_HEADERDESEL);
1108
1109         what_image(G.sima);
1110         ima= G.sima->image;
1111         ibuf= BKE_image_get_ibuf(ima, &G.sima->iuser);
1112
1113         curarea->butspacetype= SPACE_IMAGE;
1114
1115         xco = 8;
1116         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.");
1117         xco+= XIC+14;
1118
1119         uiBlockSetEmboss(block, UI_EMBOSSN);
1120         if(curarea->flag & HEADER_NO_PULLDOWN) {
1121                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
1122                                 xco,2,XIC,YIC-2,
1123                                 &(curarea->flag), 0, 0, 0, 0, "Show pulldown menus");
1124         } else {
1125                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
1126                                 xco,2,XIC,YIC-2,
1127                                 &(curarea->flag), 0, 0, 0, 0, "Hide pulldown menus");
1128         }
1129         uiBlockSetEmboss(block, UI_EMBOSS);
1130         xco+=XIC;
1131
1132         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1133                 
1134                 /* pull down menus */
1135                 uiBlockSetEmboss(block, UI_EMBOSSP);
1136         
1137                 xmax= GetButStringLength("View");
1138                 uiDefPulldownBut(block, image_viewmenu, NULL, "View", xco, -2, xmax-3, 24, "");
1139                 xco+= xmax;
1140                 
1141                 if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
1142                         xmax= GetButStringLength("Select");
1143                         uiDefPulldownBut(block, image_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
1144                         xco+= xmax;
1145                 }
1146                 
1147                 if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
1148                         menuname= "Image*";
1149                 else
1150                         menuname= "Image";
1151                 xmax= GetButStringLength(menuname);
1152                 uiDefPulldownBut(block, image_imagemenu, NULL, menuname, xco, -2, xmax-3, 24, "");
1153                 xco+= xmax;
1154                 if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
1155                         xmax= GetButStringLength("UVs");
1156                         uiDefPulldownBut(block, image_uvsmenu, NULL, "UVs", xco, -2, xmax-3, 24, "");
1157                         xco+= xmax;
1158                 }
1159         }
1160         
1161         /* other buttons: */
1162         uiBlockSetEmboss(block, UI_EMBOSS);
1163
1164         if (is_render)
1165                 allow_pin = 0;
1166         
1167         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);
1168         
1169         if( ima && !ELEM3(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE, IMA_SRC_VIEWER) && ima->ok) {
1170
1171                 if (ima->packedfile) {
1172                         headerbuttons_packdummy = 1;
1173                 }
1174                 if (ima->packedfile && ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
1175                         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");
1176                 else
1177                         uiDefIconButBitI(block, TOG, 1, B_SIMAPACKIMA, ICON_PACKAGE,    xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
1178                         
1179                 xco+= XIC+8;
1180         }
1181         
1182         /* UV EditMode buttons, not painting or rencering or compositing */
1183         if ( EM_texFaceCheck() && (G.sima->flag & SI_DRAWTOOL)==0 && !is_render) {
1184                 uiBut *ubut;
1185                 int layercount;
1186                 
1187                 uiDefIconTextButS(block, ICONTEXTROW, B_NOP, ICON_ROTATE,
1188                                 "Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1",
1189                                 xco,0,XIC+10,YIC, &(G.v2d->around), 0, 3.0, 0, 0,
1190                                 "Rotation/Scaling Pivot (Hotkeys: Comma, Shift Comma, Period)");
1191                 xco+= XIC + 18;
1192                 
1193                 
1194                 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");
1195                 xco+= XIC+8;
1196                 if (G.sima->flag & SI_SYNC_UVSEL) {
1197                         uiBlockBeginAlign(block);
1198                         
1199                         /* B_SEL_VERT & B_SEL_FACE are not defined here which is a bit bad, BUT it works even if image editor is fullscreen */
1200                         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)");
1201                         xco+= XIC;
1202                         /* no edge */
1203                         /*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)");
1204                         xco+= XIC; */
1205                         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)");
1206                         xco+= XIC+8;
1207                         uiBlockEndAlign(block);
1208                         
1209                 } else {
1210                         uiBlockBeginAlign(block);
1211                         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");
1212                         xco+= XIC;
1213                         uiDefIconButBitI(block, TOG, SI_SELACTFACE, B_REDR, ICON_FACESEL, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "UV Face select mode");
1214                         xco+= XIC+8;
1215                         uiBlockEndAlign(block);
1216                         
1217                         /* would use these if const's could go in strings 
1218                          * SI_STICKY_LOC SI_STICKY_DISABLE SI_STICKY_VERTEX */
1219                         ubut = uiDefIconTextButC(block, ICONTEXTROW, B_REDR, ICON_STICKY_UVS_LOC,
1220                                         "Sticky UV Selection: %t|Disable%x1|Shared Location%x0|Shared Vertex%x2",
1221                                         xco,0,XIC+10,YIC, &(G.sima->sticky), 0, 3.0, 0, 0,
1222                                         "Sticky UV Selection (Hotkeys: Shift C, Alt C, Ctrl C)");
1223                         
1224                 }
1225                 xco+= XIC + 16;
1226                 
1227                 /* Snap copied right out of view3d header */
1228                         uiBlockBeginAlign(block);
1229
1230                         if (G.scene->snap_flag & SCE_SNAP) {
1231                                 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)");   
1232                                 xco+= XIC;
1233                                 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");
1234                                 xco+= 70;
1235                         } else {
1236                                 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)");  
1237                                 xco+= XIC;
1238                         }
1239
1240                         uiBlockEndAlign(block);
1241                         xco+= 10;
1242                 /* end snap */
1243                         
1244                 /* Layer Menu */
1245                 layercount = CustomData_number_of_layers(&G.editMesh->fdata, CD_MTFACE); 
1246                 if (layercount>1 && layercount < 12) { /* could allow any number but limit of 11 means no malloc needed */
1247                         static int act;
1248                         char str_menu[384], *str_pt; /*384 allows for 11 layers */
1249                         
1250                         
1251                         act = CustomData_get_active_layer(&G.editMesh->fdata, CD_MTFACE);
1252                         
1253                         /*str_pt = (char *)MEM_mallocN(layercount*40 , "uvmenu"); str[0]='\0';*/
1254                         str_pt = str_menu;
1255                         str_pt[0]='\0';
1256                         mesh_layers_menu_concat(&G.editMesh->fdata, CD_MTFACE, str_pt);
1257                         ubut = uiDefButI(block, MENU, B_NOP, str_menu ,xco,0,85,YIC, &act, 0, 0, 0, 0, "Active UV Layer for editing");
1258                         uiButSetFunc(ubut, do_image_buttons_set_uvlayer_callback, &act, NULL);
1259                         
1260                         /*MEM_freeN(str);*/
1261                         xco+= 90;
1262                 }
1263         }
1264         
1265         if (ima) {
1266                 RenderResult *rr= BKE_image_get_renderresult(ima);
1267                 
1268                 xco+= 8;
1269         
1270                 if(rr) {
1271                         uiBlockBeginAlign(block);
1272                         uiblock_layer_pass_buttons(block, rr, &G.sima->iuser, B_REDR, xco, 0, 160);
1273                         uiBlockEndAlign(block);
1274                         xco+= 166;
1275                 }
1276                 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");
1277                 
1278                 xco+= XIC+8;
1279
1280                 uiBlockBeginAlign(block);
1281                 if(ibuf==NULL || ibuf->channels==4) {
1282                         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");
1283                         xco+= XIC;
1284                         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");
1285                         xco+= XIC;
1286                 }
1287                 if(ibuf) {
1288                         if(ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1)) {
1289                                 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)");
1290                                 xco+= XIC;
1291                         }
1292                 }               
1293                 xco+= 8;
1294                 
1295                 uiBlockBeginAlign(block);
1296                 if(ima->type==IMA_TYPE_COMPOSITE) {
1297                         uiDefIconBut(block, BUT, B_SIMA_RECORD, ICON_REC,  xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Record Composite");
1298                         xco+= XIC;
1299                 }
1300                 if((ima->type==IMA_TYPE_COMPOSITE) || ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
1301                         uiDefIconBut(block, BUT, B_SIMA_PLAY, ICON_PLAY, xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Play");
1302                         xco+= XIC;
1303                 }
1304                 uiBlockEndAlign(block);
1305                 xco+= 8;
1306         }
1307         
1308         /* draw LOCK */
1309         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");
1310
1311         /* Always do this last */
1312         curarea->headbutlen= xco+2*XIC;
1313         
1314         uiDrawBlock(block);
1315 }
1316