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