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