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