2.5: ID datablock button back, previously known as std_libbuttons. The
[blender.git] / source / blender / editors / space_image / image_header.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_object_types.h"
33 #include "DNA_mesh_types.h"
34 #include "DNA_customdata_types.h"
35 #include "DNA_space_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_windowmanager_types.h"
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_editVert.h"
44
45 #include "BKE_context.h"
46 #include "BKE_customdata.h"
47 #include "BKE_image.h"
48 #include "BKE_screen.h"
49 #include "BKE_utildefines.h"
50
51 #include "IMB_imbuf.h"
52 #include "IMB_imbuf_types.h"
53
54 #include "ED_mesh.h"
55 #include "ED_screen.h"
56 #include "ED_types.h"
57 #include "ED_util.h"
58
59 #include "WM_api.h"
60 #include "WM_types.h"
61
62 #include "BIF_gl.h"
63 #include "BIF_glutil.h"
64
65 #include "UI_interface.h"
66 #include "UI_resources.h"
67 #include "UI_view2d.h"
68
69 #include "RNA_access.h"
70
71 #include "RE_pipeline.h"
72
73 #include "image_intern.h"
74
75 /* ************************ header area region *********************** */
76
77 #define B_NOP                           -1
78 #define B_REDR                          1
79 #define B_SIMAGEPAINTTOOL       4
80 #define B_SIMA_USE_ALPHA        5
81 #define B_SIMA_SHOW_ALPHA       6
82 #define B_SIMA_SHOW_ZBUF        7
83 #define B_SIMA_RECORD           8
84 #define B_SIMA_PLAY                     9
85
86 static void image_view_viewnavmenu(bContext *C, uiMenuItem *head, void *arg_unused)
87 {
88         int a;
89         
90         uiMenuItemO(head, 0, "IMAGE_OT_view_zoom_in");
91         uiMenuItemO(head, 0, "IMAGE_OT_view_zoom_out");
92
93         uiMenuSeparator(head);
94
95         for(a=0; a<7; a++) {
96                 const int ratios[7][2] = {{1, 8}, {1, 4}, {1, 2}, {1, 1}, {2, 1}, {4, 1}, {8, 1}};
97                 char namestr[128];
98
99                 sprintf(namestr, "Zoom %d:%d", ratios[a][0], ratios[a][1]);
100                 uiMenuItemFloatO(head, namestr, 0, "IMAGE_OT_view_zoom_ratio", "ratio", (float)ratios[a][0]/(float)ratios[a][1]);
101         }
102 }
103
104 #if 0
105 static void do_viewmenu(bContext *C, void *arg, int event)
106 {
107         add_blockhandler(curarea, IMAGE_HANDLER_VIEW_PROPERTIES, UI_PNL_UNSTOW);
108         add_blockhandler(curarea, IMAGE_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
109         add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
110         add_blockhandler(curarea, IMAGE_HANDLER_CURVES, UI_PNL_UNSTOW);
111
112         toggle_blockhandler(curarea, IMAGE_HANDLER_PREVIEW, 0);
113         scrarea_queue_winredraw(curarea);
114
115         add_blockhandler(curarea, IMAGE_HANDLER_GAME_PROPERTIES, UI_PNL_UNSTOW);
116         add_blockhandler(curarea, IMAGE_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW);
117
118         allqueue(REDRAWIMAGE, 0);
119         allqueue(REDRAWVIEW3D, 0);
120 }
121 #endif
122
123 static void image_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused)
124 {
125         bScreen *sc= CTX_wm_screen(C);
126         ScrArea *sa= CTX_wm_area(C);
127         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
128         PointerRNA spaceptr, uvptr;
129         int show_paint, show_render, show_uvedit;
130
131         /* retrieve state */
132         RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &spaceptr);
133         RNA_pointer_create(&sc->id, &RNA_SpaceUVEditor, sima, &uvptr);
134
135         show_render= get_space_image_show_render(sima);
136         show_paint= get_space_image_show_paint(sima);
137         show_uvedit= get_space_image_show_uvedit(sima, CTX_data_edit_object(C));
138         
139         /* create menu */
140         uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_view_properties_panel"); // View Properties...
141         uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_image_properties_panel"); // Image Properties...|N
142         uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_realtime_properties_panel"); // Real-time properties...
143         if(show_paint) uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_paint_panel"); // Paint Tool...|C
144         uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_curves_panel"); // Curves Tool...
145         if(show_render) uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_compositing_preview_panel"); // Compositing Preview...|Shift P
146         uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_grease_pencil_panel"); // Grease Pencil...
147
148         uiMenuSeparator(head);
149
150         uiMenuItemBooleanR(head, &spaceptr, "update_automatically");
151         // XXX if(show_uvedit) uiMenuItemBooleanR(head, &uvptr, "local_view"); // "UV Local View", Numpad /
152
153         uiMenuSeparator(head);
154
155         uiMenuLevel(head, "View Navigation", image_view_viewnavmenu);
156         if(show_uvedit) uiMenuItemO(head, 0, "IMAGE_OT_view_selected");
157         uiMenuItemO(head, 0, "IMAGE_OT_view_all");
158
159         if(sa->full) uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
160         else uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow
161 }
162
163 #if 0
164 static void do_selectmenu(bContext *C, void *arg, int event)
165 {
166         switch(event)
167         {
168         case 0: /* Border Select */
169                 borderselect_sima(UV_SELECT_ALL);
170                 break;
171         case 8: /* Border Select Pinned */
172                 borderselect_sima(UV_SELECT_PINNED);
173                 break;
174         case 7: /* Pinned UVs */
175                 select_pinned_tface_uv();
176                 break;
177         }
178 }
179 #endif
180
181 static void image_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused)
182 {
183         uiMenuItemO(head, 0, "UV_OT_border_select"); // Border Select|B
184         uiMenuItemO(head, 0, "UV_OT_border_select_pinned"); // Border Select Pinned|Shift B
185
186         uiMenuSeparator(head);
187         
188         uiMenuItemO(head, 0, "UV_OT_de_select_all");
189         uiMenuItemO(head, 0, "UV_OT_select_invert");
190         uiMenuItemO(head, 0, "UV_OT_unlink_selection"); // Unlink Selection|Alt L
191         
192         uiMenuSeparator(head);
193
194         uiMenuItemO(head, 0, "UV_OT_select_pinned"); // Select Pinned|Shift P
195         uiMenuItemO(head, 0, "UV_OT_select_linked"); // Select Linked|Ctrl L
196 }
197
198 #if 0
199 static void do_image_imagemenu(void *arg, int event)
200 {
201         /* events >=20 are registered bpython scripts */
202 #ifndef DISABLE_PYTHON
203         if (event >= 20) BPY_menu_do_python(PYMENU_IMAGE, event - 20);
204 #endif  
205         switch(event)
206         {
207         case 0:
208                 open_image_sima((G.qual==LR_CTRLKEY));
209                 break;
210         case 1:
211                 replace_image_sima((G.qual==LR_CTRLKEY));
212                 break;
213         case 2:
214                 pack_image_sima();
215                 break;
216         case 4: /* Texture Painting */
217                 brush_check_exists(&G.scene->toolsettings->imapaint.brush);
218                 if(sima->flag & SI_DRAWTOOL) sima->flag &= ~SI_DRAWTOOL;
219                 else sima->flag |= SI_DRAWTOOL;
220                 allqueue(REDRAWBUTSSHADING, 0);
221                 break;
222         case 5:
223                 save_as_image_sima();
224                 break;
225         case 6:
226                 reload_image_sima();
227                 break;
228         case 7:
229                 new_image_sima();
230                 break;
231         case 8:
232                 save_image_sima();
233                 break;
234         case 9:
235                 save_image_sequence_sima();
236                 break;
237         case 10:
238                 BKE_image_memorypack(sima->image);
239                 allqueue(REDRAWIMAGE, 0);
240                 break;
241         }
242 }
243 #endif
244
245 /* move to realtime properties panel */
246 #if 0
247 static void do_image_image_rtmappingmenu(void *arg, int event)
248 {
249         switch(event) {
250         case 0: /* UV Co-ordinates */
251                 sima->image->flag &= ~IMA_REFLECT;
252                 break;
253         case 1: /* Reflection */
254                 sima->image->flag |= IMA_REFLECT;
255                 break;
256         }
257
258         allqueue(REDRAWVIEW3D, 0);
259 }
260 #endif
261
262 static void image_imagemenu(bContext *C, uiMenuItem *head, void *arg_unused)
263 {
264         bScreen *sc= CTX_wm_screen(C);
265         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
266         PointerRNA spaceptr;
267         Image *ima;
268         ImBuf *ibuf;
269         int show_render;
270         
271         /* retrieve state */
272         ima= get_space_image(sima);
273         ibuf= get_space_image_buffer(sima);
274
275         show_render= get_space_image_show_render(sima);
276
277         RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &spaceptr);
278
279         /* create menu */
280         uiMenuItemO(head, 0, "IMAGE_OT_new"); // New...|Alt N
281         uiMenuItemO(head, 0, "IMAGE_OT_open"); // Open...|Alt O
282
283         if(ima) {
284                 uiMenuItemO(head, 0, "IMAGE_OT_replace"); // Replace...
285                 uiMenuItemO(head, 0, "IMAGE_OT_reload"); // Reload...|Alt R
286                 uiMenuItemO(head, 0, "IMAGE_OT_save"); // Save|Alt S
287                 uiMenuItemO(head, 0, "IMAGE_OT_save_as"); // Save As...
288                 if(ima->source == IMA_SRC_SEQUENCE)
289                         uiMenuItemO(head, 0, "IMAGE_OT_save_changed"); // Save Changed Images
290
291                 if(!show_render) {
292                         uiMenuSeparator(head);
293
294                         if(ima->packedfile) uiMenuItemO(head, 0, "IMAGE_OT_unpack"); // Unpack Image...
295                         else uiMenuItemO(head, 0, "IMAGE_OT_pack"); // Pack Image
296
297                         /* only for dirty && specific image types : XXX poll? */
298                         if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
299                                 if(ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_GENERATED) && ima->type != IMA_TYPE_MULTILAYER)
300                                         uiMenuItemO(head, 0, "IMAGE_OT_pack_as_png"); // Pack Image As PNG
301
302                         uiMenuSeparator(head);
303
304                         /* XXX check state better */
305                         uiMenuItemBooleanR(head, &spaceptr, "image_painting");
306                 }
307         }
308
309 #if 0
310 #ifndef DISABLE_PYTHON
311         {
312                 BPyMenu *pym;
313                 int i = 0;
314
315                 /* note that we acount for the N previous entries with i+20: */
316                 for (pym = BPyMenuTable[PYMENU_IMAGE]; pym; pym = pym->next, i++) {
317
318                         uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
319                                          NULL, 0.0, 0.0, 1, i+20, 
320                                          pym->tooltip?pym->tooltip:pym->filename);
321                 }
322         }
323 #endif
324 #endif
325 }
326
327 #if 0
328 static void do_image_uvs_showhidemenu(void *arg, int event)
329 {
330         switch(event) {
331         case 4: /* show hidden faces */
332                 reveal_tface_uv();
333                 break;
334         case 5: /* hide selected faces */
335                 hide_tface_uv(0);
336                 break;
337         case 6: /* hide deselected faces */
338                 hide_tface_uv(1);
339                 break;
340         }
341         allqueue(REDRAWVIEW3D, 0);
342 }
343 #endif
344
345 static void image_uvs_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused)
346 {
347         uiMenuItemO(head, 0, "UV_OT_show_hidden_faces"); // Show Hidden Faces|Alt H
348         uiMenuItemO(head, 0, "UV_OT_hide_selected_faces"); // Hide Selected Faces|H
349         uiMenuItemO(head, 0, "UV_OT_hide_deselected_faces"); // Hide Deselected Faces|Shift H
350 }
351
352 #if 0
353 static void do_image_uvs_transformmenu(void *arg, int event)
354 {
355         switch(event) {
356         case 0: /* Grab */
357                 initTransform(TFM_TRANSLATION, CTX_NONE);
358                 Transform();
359                 break;
360         case 1: /* Rotate */
361                 initTransform(TFM_ROTATION, CTX_NONE);
362                 Transform();
363                 break;
364         case 2: /* Scale */
365                 initTransform(TFM_RESIZE, CTX_NONE);
366                 Transform();
367                 break;
368         }
369 }
370 #endif
371
372 static void image_uvs_transformmenu(bContext *C, uiMenuItem *head, void *arg_unused)
373 {
374         uiMenuItemO(head, 0, "UV_OT_grab"); // Grab/Move|G
375         uiMenuItemO(head, 0, "UV_OT_rotate"); // Rotate|R
376         uiMenuItemO(head, 0, "UV_OT_scale"); // Scale|S
377 }
378
379 #if 0
380 static void do_image_uvs_mirrormenu(void *arg, int event)
381 {
382         float mat[3][3];
383         
384         Mat3One(mat);
385         
386         switch(event) {
387         case 0: /* X axis */
388                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
389                 BIF_setSingleAxisConstraint(mat[0], " on global X axis");
390                 Transform();
391                 break;
392         case 1: /* Y axis */
393                 initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
394                 BIF_setSingleAxisConstraint(mat[1], " on global Y axis");
395                 Transform();
396                 break;
397         }
398         
399         BIF_undo_push("Mirror UV");
400 }
401 #endif
402
403 static void image_uvs_mirrormenu(bContext *C, uiMenuItem *head, void *arg_unused)
404 {
405         uiMenuItemEnumO(head, 0, "UV_OT_mirror", "axis", 'x'); // "X Axis", M, 1
406         uiMenuItemEnumO(head, 0, "UV_OT_mirror", "axis", 'y'); // "Y Axis", M, 2
407 }
408
409 #if 0
410 static void do_image_uvs_weldalignmenu(void *arg, int event)
411 {
412         switch(event) {
413         case 0: /* Weld */
414                 weld_align_tface_uv('w');
415                 break;
416         case 1: /* Align Auto */
417                 weld_align_tface_uv('a');
418                 break;
419         case 2: /* Align X */
420                 weld_align_tface_uv('x');
421                 break;
422         case 3: /* Align Y */
423                 weld_align_tface_uv('y');
424                 break;
425         }
426         
427         if(event==0) BIF_undo_push("Weld UV");
428         else if(ELEM3(event, 1, 2, 3)) BIF_undo_push("Align UV");
429 }
430 #endif
431
432 static void image_uvs_weldalignmenu(bContext *C, uiMenuItem *head, void *arg_unused)
433 {
434         uiMenuItemO(head, 0, "UV_OT_weld"); // W, 1
435         uiMenuItemsEnumO(head, "UV_OT_align", "axis"); // W, 2/3/4
436 }
437
438 #if 0
439 #ifndef DISABLE_PYTHON
440 static void do_image_uvs_scriptsmenu(void *arg, int event)
441 {
442         BPY_menu_do_python(PYMENU_UV, event);
443
444         allqueue(REDRAWIMAGE, 0);
445 }
446
447 static void image_uvs_scriptsmenu (void *args_unused)
448 {
449         uiBlock *block;
450         BPyMenu *pym;
451         int i= 0;
452         short yco = 20, menuwidth = 120;
453         
454         block= uiNewBlock(&curarea->uiblocks, "image_uvs_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
455         uiBlockSetButmFunc(block, do_image_uvs_scriptsmenu, NULL);
456         
457         /* note that we acount for the N previous entries with i+20: */
458         for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
459                 
460                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
461                                                  NULL, 0.0, 0.0, 1, i, 
462                                                  pym->tooltip?pym->tooltip:pym->filename);
463         }
464         
465         uiBlockSetDirection(block, UI_RIGHT);
466         uiTextBoundsBlock(block, 60);
467         
468         return block;
469 }
470 #endif /* DISABLE_PYTHON */
471 #endif
472
473 #if 0
474 static void do_uvsmenu(bContext *C, void *arg, int event)
475 {
476         switch(event) {
477         case 2: /* UVs Clipped to Image Size */
478                 if(sima->flag & SI_CLIP_UV) sima->flag &= ~SI_CLIP_UV;
479                 else sima->flag |= SI_CLIP_UV;
480                 break;
481         case 5: /* Proportional Edit (toggle) */
482                 if(G.scene->proportional)
483                         G.scene->proportional= 0;
484                 else
485                         G.scene->proportional= 1;
486                 break;
487         case 7: /* UVs Snap to Pixel */
488                 sima->flag ^= SI_PIXELSNAP;
489                 break;
490     case 8:
491                 pin_tface_uv(1);
492                 break;
493     case 9:
494                 pin_tface_uv(0);
495                 break;
496     case 10:
497                 unwrap_lscm(0);
498                 break;
499         case 11:
500                 if(sima->flag & SI_LIVE_UNWRAP) sima->flag &= ~SI_LIVE_UNWRAP;
501                 else sima->flag |= SI_LIVE_UNWRAP;
502                 break;
503         case 12:
504                 minimize_stretch_tface_uv();
505                 break;
506         case 13:
507                 pack_charts_tface_uv();
508                 break;
509         case 14:
510                 average_charts_tface_uv();
511                 break;
512         }
513 }
514 #endif
515
516 static void image_uvsmenu(bContext *C, uiMenuItem *head, void *arg_unused)
517 {
518         bScreen *sc= CTX_wm_screen(C);
519         Scene *scene= CTX_data_scene(C);
520         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
521         PointerRNA uvptr, sceneptr;
522         Image *ima;
523         ImBuf *ibuf;
524         
525         /* retrieve state */
526         ima= get_space_image(sima);
527         ibuf= get_space_image_buffer(sima);
528
529         RNA_pointer_create(&sc->id, &RNA_SpaceUVEditor, sima, &uvptr);
530         RNA_id_pointer_create(&scene->id, &sceneptr);
531
532         /* create menu */
533         uiMenuItemBooleanR(head, &uvptr, "snap_to_pixels");
534         uiMenuItemBooleanR(head, &uvptr, "constrain_to_image_bounds");
535
536         uiMenuSeparator(head);
537
538         uiMenuItemBooleanR(head, &uvptr, "live_unwrap");
539         uiMenuItemO(head, 0, "UV_OT_unwrap"); // Unwrap|E
540         uiMenuItemO(head, 0, "UV_OT_unpin"); // Unpin|Alt P
541         uiMenuItemO(head, 0, "UV_OT_pin"); // Pin|P
542
543         uiMenuSeparator(head);
544
545         uiMenuItemO(head, 0, "UV_OT_pack_islands"); // Pack Islands|Ctr P
546         uiMenuItemO(head, 0, "UV_OT_average_islands"); // Average Islands Scale|Ctrl A
547         uiMenuItemO(head, 0, "UV_OT_minimize_stretch"); // Minimize Stretch...|Ctrl V
548         uiMenuItemO(head, 0, "UV_OT_stitch");
549
550         uiMenuSeparator(head);
551
552         uiMenuLevel(head, "Transform", image_uvs_transformmenu);
553         uiMenuLevel(head, "Mirror", image_uvs_mirrormenu);
554         uiMenuLevel(head, "Weld/Align", image_uvs_weldalignmenu);
555
556         uiMenuSeparator(head);
557
558         uiMenuItemBooleanR(head, &sceneptr, "proportional_editing");
559         uiMenuLevelEnumR(head, &sceneptr, "proportional_editing_falloff");
560
561         uiMenuSeparator(head);
562
563         uiMenuLevel(head, "Show/Hide Faces", image_uvs_showhidemenu);
564
565 #if 0
566 #ifndef DISABLE_PYTHON
567         uiMenuSeparator(head);
568
569         uiMenuLevel(head, "Scripts", image_uvs_scriptsmenu);
570 #endif
571 #endif
572 }
573
574 static void image_menu_uvlayers(Object *obedit, char *menustr, int *active)
575 {
576         Mesh *me= (Mesh*)obedit->data;
577         EditMesh *em= me->edit_mesh;
578         CustomDataLayer *layer;
579         int i, count = 0;
580
581         menustr[0]= '\0';
582
583         for(i=0; i<em->fdata.totlayer; i++) {
584                 layer = &em->fdata.layers[i];
585
586                 if(layer->type == CD_MTFACE) {
587                         menustr += sprintf(menustr, "%s%%x%d|", layer->name, count);
588                         count++;
589                 }
590         }
591
592         *active= CustomData_get_active_layer(&em->fdata, CD_MTFACE);
593 }
594
595 static void do_image_buttons(bContext *C, void *arg, int event)
596 {
597         switch(event) {
598                 case B_REDR:
599                         ED_area_tag_redraw(CTX_wm_area(C));
600                         break;
601         }
602
603 #if 0
604         ToolSettings *settings= G.scene->toolsettings;
605         ID *id, *idtest;
606         int nr;
607
608         if(curarea->win==0) return;
609
610         if(event<=100) {
611                 if(event<=50) do_global_buttons2(event);
612                 else do_global_buttons(event);
613                 return;
614         }
615         
616         switch(event) {
617         case B_SIMAPIN:
618                 allqueue (REDRAWIMAGE, 0);
619                 break;
620         case B_SIMAGEHOME:
621                 image_home();
622                 break;
623
624         case B_SIMABROWSE:      
625                 if(sima->imanr== -2) {
626                         if(G.qual & LR_CTRLKEY) {
627                                 activate_databrowse_imasel((ID *)sima->image, ID_IM, 0, B_SIMABROWSE,
628                                                                                         &sima->imanr, do_image_buttons);
629                         } else {
630                                 activate_databrowse((ID *)sima->image, ID_IM, 0, B_SIMABROWSE,
631                                                                                         &sima->imanr, do_image_buttons);
632                         }
633                         return;
634                 }
635                 if(sima->imanr < 0) break;
636         
637                 nr= 1;
638                 id= (ID *)sima->image;
639
640                 idtest= BLI_findlink(&G.main->image, sima->imanr-1);
641                 if(idtest==NULL) { /* no new */
642                         return;
643                 }
644         
645                 if(idtest!=id) {
646                         sima->image= (Image *)idtest;
647                         if(idtest->us==0) idtest->us= 1;
648                         BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
649                         allqueue(REDRAWIMAGE, 0);
650                 }
651                 /* also when image is the same: assign! 0==no tileflag: */
652                 image_changed(sima, (Image *)idtest);
653                 BIF_undo_push("Assign image UV");
654
655                 break;
656         case B_SIMAGETILE:
657                 image_set_tile(sima, 1);                /* 1: only tileflag */
658                 allqueue(REDRAWVIEW3D, 0);
659                 allqueue(REDRAWIMAGE, 0);
660                 break;
661         case B_SIMA3DVIEWDRAW:
662                 allqueue(REDRAWVIEW3D, 0);
663                 break;
664         case B_SIMA_REDR_IMA_3D:
665                 allqueue(REDRAWVIEW3D, 0);
666                 allqueue(REDRAWIMAGE, 0);
667                 break;
668         case B_SIMAGEPAINTTOOL:
669                 if(sima->flag & SI_DRAWTOOL)
670                         /* add new brush if none exists */
671                         brush_check_exists(&G.scene->toolsettings->imapaint.brush);
672                 allqueue(REDRAWBUTSSHADING, 0);
673                 allqueue(REDRAWIMAGE, 0);
674                 allqueue(REDRAWVIEW3D, 0);
675                 break;
676
677         case B_SIMAPACKIMA:
678                 pack_image_sima();
679                 break;
680                 
681         case B_SIMA_REPACK:
682                 BKE_image_memorypack(sima->image);
683                 allqueue(REDRAWIMAGE, 0);
684                 break;
685                 
686         case B_SIMA_USE_ALPHA:
687                 sima->flag &= ~(SI_SHOW_ALPHA|SI_SHOW_ZBUF);
688                 scrarea_queue_winredraw(curarea);
689                 scrarea_queue_headredraw(curarea);
690                 break;
691         case B_SIMA_SHOW_ALPHA:
692                 sima->flag &= ~(SI_USE_ALPHA|SI_SHOW_ZBUF);
693                 scrarea_queue_winredraw(curarea);
694                 scrarea_queue_headredraw(curarea);
695                 break;
696         case B_SIMA_SHOW_ZBUF:
697                 sima->flag &= ~(SI_SHOW_ALPHA|SI_USE_ALPHA);
698                 scrarea_queue_winredraw(curarea);
699                 scrarea_queue_headredraw(curarea);
700                 break;
701         case B_SIMARELOAD:
702                 reload_image_sima();
703                 break;
704         case B_SIMAGELOAD:
705                 open_image_sima(0);
706                 break;
707         case B_SIMANAME:
708                 if(sima->image) {
709                         Image *ima;
710                         char str[FILE_MAXDIR+FILE_MAXFILE];
711                         
712                         /* name in ima has been changed by button! */
713                         BLI_strncpy(str, sima->image->name, sizeof(str));
714                         ima= BKE_add_image_file(str);
715                         if(ima) {
716                                 BKE_image_signal(ima, &sima->iuser, IMA_SIGNAL_RELOAD);
717                                 image_changed(sima, ima);
718                         }
719                         BIF_undo_push("Load image");
720                         allqueue(REDRAWIMAGE, 0);
721                 }
722                 break;
723         case B_SIMAMULTI:
724                 if(sima && sima->image) {
725                         BKE_image_multilayer_index(sima->image->rr, &sima->iuser);
726                         allqueue(REDRAWIMAGE, 0);
727                 }
728                 break;
729         case B_TRANS_IMAGE:
730                 image_editvertex_buts(NULL);
731                 break;
732         case B_CURSOR_IMAGE:
733                 image_editcursor_buts(NULL);
734                 break;
735                 
736         case B_TWINANIM:
737         {
738                 Image *ima;
739                 int nr;
740                 
741                 ima = sima->image;
742                 if (ima) {
743                         if(ima->flag & IMA_TWINANIM) {
744                                 nr= ima->xrep*ima->yrep;
745                                 if(ima->twsta>=nr) ima->twsta= 1;
746                                 if(ima->twend>=nr) ima->twend= nr-1;
747                                 if(ima->twsta>ima->twend) ima->twsta= 1;
748                         }
749
750                         allqueue(REDRAWIMAGE, 0);
751                         allqueue(REDRAWVIEW3D, 0);
752                 }
753                 break;
754         }       
755         case B_SIMACLONEBROWSE:
756                 if(settings->imapaint.brush) {
757                         Brush *brush= settings->imapaint.brush;
758                 
759                         if(sima->menunr== -2) {
760                                 if(G.qual & LR_CTRLKEY) {
761                                         activate_databrowse_imasel((ID *)brush->clone.image, ID_IM, 0, B_SIMACLONEBROWSE,
762                                                                                                 &sima->menunr, do_image_buttons);
763                                 } else {
764                                         activate_databrowse((ID *)brush->clone.image, ID_IM, 0, B_SIMACLONEBROWSE,
765                                                                                                 &sima->menunr, do_image_buttons);
766                                 }
767                                 break;
768                         }
769                         if(sima->menunr < 0) break;
770
771                         if(brush_clone_image_set_nr(brush, sima->menunr))
772                                 allqueue(REDRAWIMAGE, 0);
773                 }
774                 break;
775                 
776         case B_SIMACLONEDELETE:
777                 if (settings->imapaint.brush)
778                         if (brush_clone_image_delete(settings->imapaint.brush))
779                                 allqueue(REDRAWIMAGE, 0);
780                 break;
781                 
782         case B_SIMABRUSHCHANGE:
783                 allqueue(REDRAWIMAGE, 0);
784                 allqueue(REDRAWBUTSEDIT, 0);
785                 break;
786                 
787         case B_SIMACURVES:
788                 curvemapping_do_ibuf(sima->cumap, imagewindow_get_ibuf(sima));
789                 allqueue(REDRAWIMAGE, 0);
790                 break;
791                 
792         case B_SIMARANGE:
793                 curvemapping_set_black_white(sima->cumap, NULL, NULL);
794                 curvemapping_do_ibuf(sima->cumap, imagewindow_get_ibuf(sima));
795                 allqueue(REDRAWIMAGE, 0);
796                 break;
797                 
798         case B_SIMABRUSHBROWSE:
799                 if(sima->menunr==-2) {
800                         activate_databrowse((ID*)settings->imapaint.brush, ID_BR, 0, B_SIMABRUSHBROWSE, &sima->menunr, do_global_buttons);
801                         break;
802                 }
803                 else if(sima->menunr < 0) break;
804                 
805                 if(brush_set_nr(&settings->imapaint.brush, sima->menunr)) {
806                         BIF_undo_push("Browse Brush");
807                         allqueue(REDRAWBUTSEDIT, 0);
808                         allqueue(REDRAWIMAGE, 0);
809                 }
810                 break;
811         case B_SIMABRUSHDELETE:
812                 if(brush_delete(&settings->imapaint.brush)) {
813                         BIF_undo_push("Unlink Brush");
814                         allqueue(REDRAWIMAGE, 0);
815                         allqueue(REDRAWBUTSEDIT, 0);
816                 }
817                 break;
818         case B_KEEPDATA:
819                 brush_toggled_fake_user(settings->imapaint.brush);
820                 allqueue(REDRAWIMAGE, 0);
821                 allqueue(REDRAWBUTSEDIT, 0);
822                 break;
823         case B_SIMABRUSHLOCAL:
824                 if(settings->imapaint.brush && settings->imapaint.brush->id.lib) {
825                         if(okee("Make local")) {
826                                 make_local_brush(settings->imapaint.brush);
827                                 allqueue(REDRAWIMAGE, 0);
828                                 allqueue(REDRAWBUTSEDIT, 0);
829                         }
830                 }
831                 break;
832         case B_SIMABTEXBROWSE:
833                 if(settings->imapaint.brush) {
834                         Brush *brush= settings->imapaint.brush;
835                         
836                         if(sima->menunr==-2) {
837                                 MTex *mtex= brush->mtex[brush->texact];
838                                 ID *id= (ID*)((mtex)? mtex->tex: NULL);
839                                 if(G.qual & LR_CTRLKEY) {
840                                         activate_databrowse_imasel(id, ID_TE, 0, B_SIMABTEXBROWSE, &sima->menunr, do_image_buttons);
841                                 } else {
842                                         activate_databrowse(id, ID_TE, 0, B_SIMABTEXBROWSE, &sima->menunr, do_image_buttons);
843                                 }
844                                 break;
845                         }
846                         else if(sima->menunr < 0) break;
847                         
848                         if(brush_texture_set_nr(brush, sima->menunr)) {
849                                 BIF_undo_push("Browse Brush Texture");
850                                 allqueue(REDRAWBUTSSHADING, 0);
851                                 allqueue(REDRAWBUTSEDIT, 0);
852                                 allqueue(REDRAWIMAGE, 0);
853                         }
854                 }
855                 break;
856         case B_SIMABTEXDELETE:
857                 if(settings->imapaint.brush) {
858                         if (brush_texture_delete(settings->imapaint.brush)) {
859                                 BIF_undo_push("Unlink Brush Texture");
860                                 allqueue(REDRAWBUTSSHADING, 0);
861                                 allqueue(REDRAWBUTSEDIT, 0);
862                                 allqueue(REDRAWIMAGE, 0);
863                         }
864                 }
865                 break;
866         case B_SIMA_PLAY:
867                 play_anim(0);
868                 break;
869         case B_SIMA_RECORD:
870                 imagespace_composite_flipbook(curarea);
871                 break;
872         }
873 #endif
874 }
875
876 #if 0
877 static void do_image_buttons_set_uvlayer_callback(void *act, void *data)
878 {
879         CustomData_set_layer_active(&G.editMesh->fdata, CD_MTFACE, *((int *)act));
880         
881         BIF_undo_push("Set Active UV Texture");
882         allqueue(REDRAWVIEW3D, 0);
883         allqueue(REDRAWBUTSEDIT, 0);
884         allqueue(REDRAWIMAGE, 0);
885 }
886 #endif
887
888 static void sima_idpoin_handle(bContext *C, ID *id, int event)
889 {
890         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
891         Scene *scene= CTX_data_scene(C);
892         Object *obedit= CTX_data_edit_object(C);
893
894         switch(event) {
895                 case UI_ID_BROWSE:
896                 case UI_ID_DELETE:
897                         set_space_image(sima, scene, obedit, sima->image);
898
899                         if(sima->image && sima->image->id.us==0)
900                                 sima->image->id.us= 1;
901
902                         ED_area_tag_redraw(CTX_wm_area(C));
903                         ED_undo_push(C, "Assign Image UV");
904                         break;
905                 case UI_ID_RENAME:
906                         break;
907                 case UI_ID_ADD_NEW:
908                         /* XXX not implemented */
909                         break;
910                 case UI_ID_OPEN:
911                         /* XXX not implemented */
912                         break;
913                 case UI_ID_ALONE:
914                         /* XXX not implemented */
915                         break;
916                 case UI_ID_PIN:
917                         break;
918         }
919 }
920
921 void image_header_buttons(const bContext *C, ARegion *ar)
922 {
923         bScreen *sc= CTX_wm_screen(C);
924         ScrArea *sa= CTX_wm_area(C);
925         Scene *scene= CTX_data_scene(C);
926         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
927         Image *ima;
928         ImBuf *ibuf;
929         uiBlock *block;
930         uiBut *but;
931         PointerRNA spaceptr, uvptr, sceneptr;
932         int xco, yco= 3, show_uvedit, show_render, show_paint;
933
934         /* retrieve state */
935         ima= get_space_image(sima);
936         ibuf= get_space_image_buffer(sima);
937
938         show_render= get_space_image_show_render(sima);
939         show_paint= get_space_image_show_paint(sima);
940         show_uvedit= get_space_image_show_uvedit(sima, CTX_data_edit_object(C));
941
942         RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &spaceptr);
943         RNA_pointer_create(&sc->id, &RNA_SpaceUVEditor, sima, &uvptr);
944         RNA_id_pointer_create(&scene->id, &sceneptr);
945         
946         /* create block */
947         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
948         uiBlockSetHandleFunc(block, do_image_buttons, NULL);
949         
950         xco= ED_area_header_standardbuttons(C, block, yco);
951         
952         /* create pulldown menus */
953         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
954                 char *menuname;
955                 int xmax;
956                 
957                 uiBlockSetEmboss(block, UI_EMBOSSP);
958                 
959                 xmax= GetButStringLength("View");
960                 uiDefMenuBut(block, image_viewmenu, NULL, "View", xco, yco-2, xmax-3, 24, "");
961                 xco+= xmax;
962                 
963                 if(show_uvedit) {
964                         xmax= GetButStringLength("Select");
965                         uiDefMenuBut(block, image_selectmenu, NULL, "Select", xco, yco-2, xmax-3, 24, "");
966                         xco+= xmax;
967                 }
968                 
969                 menuname= (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))? "Image*": "Image";
970                 xmax= GetButStringLength(menuname);
971                 uiDefMenuBut(block, image_imagemenu, NULL, menuname, xco, yco-2, xmax-3, 24, "");
972                 xco+= xmax;
973
974                 if(show_uvedit) {
975                         xmax= GetButStringLength("UVs");
976                         uiDefMenuBut(block, image_uvsmenu, NULL, "UVs", xco, yco-2, xmax-3, 24, "");
977                         xco+= xmax;
978                 }
979         }
980
981         uiBlockSetEmboss(block, UI_EMBOSS);
982
983         /* image select */
984
985         xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&sima->image, ID_IM, &sima->pin, xco, yco,
986                 sima_idpoin_handle, UI_ID_BROWSE|UI_ID_BROWSE_RENDER|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE|UI_ID_ALONE|UI_ID_PIN);
987         xco += 8;
988
989 #if 0
990         char naam[256];
991         
992         /* This should not be a static var */
993         static int headerbuttons_packdummy;
994         
995         headerbuttons_packdummy = 0;
996
997         int allow_pin= (show_render)? 0: B_SIMAPIN;
998         
999         xco= 8 + std_libbuttons(block, xco, yco, allow_pin, &sima->pin, B_SIMABROWSE, ID_IM, 0, (ID *)ima, 0, &(sima->imanr), 0, 0, B_IMAGEDELETE, 0, 0);
1000         
1001         if(ima && !ELEM3(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE, IMA_SRC_VIEWER) && ima->ok) {
1002
1003                 if (ima->packedfile) {
1004                         headerbuttons_packdummy = 1;
1005                 }
1006                 if (ima->packedfile && ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
1007                         uiDefIconButBitI(block, TOG, 1, B_SIMA_REPACK, ICON_UGLYPACKAGE,        xco,yco,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Re-Pack this image as PNG");
1008                 else
1009                         uiDefIconButBitI(block, TOG, 1, B_SIMAPACKIMA, ICON_PACKAGE,    xco,yco,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
1010                         
1011                 xco+= XIC+8;
1012         }
1013 #endif
1014         
1015         /* uv editing */
1016         if(show_uvedit) {
1017                 /* pivot */
1018                 uiDefIconTextButS(block, ICONTEXTROW, B_NOP, ICON_ROTATE,
1019                                 "Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1",
1020                                 xco,yco,XIC+10,YIC, &ar->v2d.around, 0, 3.0, 0, 0,
1021                                 "Rotation/Scaling Pivot (Hotkeys: Comma, Shift Comma, Period)");
1022                 xco+= XIC + 18;
1023                 
1024                 /* selection modes */
1025                 uiDefIconButBitS(block, TOG, UV_SYNC_SELECTION, B_REDR, ICON_EDIT, xco,yco,XIC,YIC, &scene->toolsettings->uv_flag, 0, 0, 0, 0, "Sync UV and Mesh Selection");
1026                 xco+= XIC+8;
1027
1028                 if(scene->toolsettings->uv_flag & UV_SYNC_SELECTION) {
1029                         uiBlockBeginAlign(block);
1030                         
1031                         uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_REDR, ICON_VERTEXSEL,
1032                                 xco,yco,XIC,YIC, &scene->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
1033                         uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_REDR, ICON_EDGESEL,
1034                                 xco+=XIC,yco,XIC,YIC, &scene->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
1035                         uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_REDR, ICON_FACESEL,
1036                                 xco+=XIC,yco,XIC,YIC, &scene->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
1037
1038                         uiBlockEndAlign(block);
1039                 }
1040                 else {
1041                         uiBlockBeginAlign(block);
1042
1043                         uiDefIconButS(block, ROW, B_REDR, ICON_VERTEXSEL,
1044                                 xco,yco,XIC,YIC, &scene->toolsettings->uv_selectmode, 1.0, UV_SELECT_VERTEX, 0, 0, "Vertex select mode");
1045                         uiDefIconButS(block, ROW, B_REDR, ICON_EDGESEL,
1046                                 xco+=XIC,yco,XIC,YIC, &scene->toolsettings->uv_selectmode, 1.0, UV_SELECT_EDGE, 0, 0, "Edge select mode");
1047                         uiDefIconButS(block, ROW, B_REDR, ICON_FACESEL,
1048                                 xco+=XIC,yco,XIC,YIC, &scene->toolsettings->uv_selectmode, 1.0, UV_SELECT_FACE, 0, 0, "Face select mode");
1049                         uiDefIconButS(block, ROW, B_REDR, ICON_MESH,
1050                                 xco+=XIC,yco,XIC,YIC, &scene->toolsettings->uv_selectmode, 1.0, UV_SELECT_ISLAND, 0, 0, "Island select mode");
1051
1052                         uiBlockEndAlign(block);
1053
1054                         /* would use these if const's could go in strings 
1055                          * SI_STICKY_LOC SI_STICKY_DISABLE SI_STICKY_VERTEX */
1056                         but = uiDefIconTextButC(block, ICONTEXTROW, B_REDR, ICON_STICKY_UVS_LOC,
1057                                         "Sticky UV Selection: %t|Disable%x1|Shared Location%x0|Shared Vertex%x2",
1058                                         xco+=XIC+10,yco,XIC+10,YIC, &(sima->sticky), 0, 3.0, 0, 0,
1059                                         "Sticky UV Selection (Hotkeys: Shift C, Alt C, Ctrl C)");
1060                 }
1061
1062                 xco+= XIC + 16;
1063                 
1064                 /* snap options, identical to options in 3d view header */
1065                 uiBlockBeginAlign(block);
1066
1067                 if (scene->snap_flag & SCE_SNAP) {
1068                         uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEO,xco,yco,XIC,YIC, &scene->snap_flag, 0, 0, 0, 0, "Use Snap or Grid (Shift Tab).");
1069                         xco+= XIC;
1070                         uiDefButS(block, MENU, B_NOP, "Mode%t|Closest%x0|Center%x1|Median%x2",xco,yco,70,YIC, &scene->snap_target, 0, 0, 0, 0, "Snap Target Mode.");
1071                         xco+= 70;
1072                 }
1073                 else {
1074                         uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEAR,xco,yco,XIC,YIC, &scene->snap_flag, 0, 0, 0, 0, "Snap while Ctrl is held during transform (Shift Tab)."); 
1075                         xco+= XIC;
1076                 }
1077
1078                 uiBlockEndAlign(block);
1079                 xco+= 10;
1080
1081                 /* uv layers */
1082                 {
1083                         Object *obedit= CTX_data_edit_object(C);
1084                         char menustr[34*MAX_MTFACE];
1085                         static int act;
1086                         
1087                         image_menu_uvlayers(obedit, menustr, &act);
1088
1089                         but = uiDefButI(block, MENU, B_NOP, menustr ,xco,yco,85,YIC, &act, 0, 0, 0, 0, "Active UV Layer for editing.");
1090                         // uiButSetFunc(but, do_image_buttons_set_uvlayer_callback, &act, NULL);
1091                         
1092                         xco+= 90;
1093                 }
1094         }
1095         
1096         if(ima) {
1097                 RenderResult *rr;
1098                 
1099                 xco+= 8;
1100         
1101                 /* render layers and passes */
1102                 rr= BKE_image_get_renderresult(scene, ima);
1103                 if(rr) {
1104                         uiBlockBeginAlign(block);
1105 #if 0
1106                         uiblock_layer_pass_buttons(block, rr, &sima->iuser, B_REDR, xco, 0, 160);
1107 #endif
1108                         uiBlockEndAlign(block);
1109                         xco+= 166;
1110                 }
1111
1112                 /* painting */
1113                 uiDefIconButR(block, TOG, B_REDR, ICON_TPAINT_HLT, xco,yco,XIC,YIC, &spaceptr, "image_painting", 0, 0, 0, 0, 0, NULL);
1114                 xco+= XIC+8;
1115
1116                 /* image draw options */
1117                 uiBlockBeginAlign(block);
1118                 uiDefIconButR(block, ROW, B_REDR, ICON_TEXTURE, xco,yco,XIC,YIC, &spaceptr, "draw_channels", 0, 0, 0, 0, 0, NULL);
1119                 xco+= XIC;
1120                 if(ibuf==NULL || ibuf->channels==4) {
1121                         uiDefIconButR(block, ROW, B_REDR, ICON_TRANSP_HLT, xco,yco,XIC,YIC, &spaceptr, "draw_channels", 0, 0, SI_USE_ALPHA, 0, 0, NULL);
1122                         xco+= XIC;
1123                         uiDefIconButR(block, ROW, B_REDR, ICON_DOT, xco,yco,XIC,YIC, &spaceptr, "draw_channels", 0, 0, SI_SHOW_ALPHA, 0, 0, NULL);
1124                         xco+= XIC;
1125                 }
1126                 if(ibuf) {
1127                         if(ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1)) {
1128                                 uiDefIconButR(block, ROW, B_REDR, ICON_SOLID, xco,yco,XIC,YIC, &spaceptr, "draw_channels", 0, 0, SI_SHOW_ZBUF, 0, 0, NULL);
1129                                 xco+= XIC;
1130                         }
1131                 }               
1132                 xco+= 8;
1133                 
1134                 /* record & play */
1135                 uiBlockBeginAlign(block);
1136                 if(ima->type==IMA_TYPE_COMPOSITE) {
1137 //XXX                   uiDefIconButO(block, BUT, "IMAGE_OT_record_composite", WM_OP_INVOKE_REGION_WIN, ICON_REC, xco, yco, XIC, YIC, NULL); // Record Composite
1138                         xco+= XIC;
1139                 }
1140                 if((ima->type==IMA_TYPE_COMPOSITE) || ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
1141 //XXX                   uiDefIconButO(block, BUT, "IMAGE_OT_play_composite", WM_OP_INVOKE_REGION_WIN, ICON_PLAY, xco, yco, XIC, YIC, NULL); // PLAY
1142                         xco+= XIC;
1143                 }
1144                 uiBlockEndAlign(block);
1145                 xco+= 8;
1146         }
1147         
1148         /* draw lock */
1149         uiDefIconButR(block, ICONTOG, 0, ICON_UNLOCKED, xco,yco,XIC,YIC, &spaceptr, "update_automatically", 0, 0, 0, 0, 0, NULL);
1150
1151         /* always as last  */
1152         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
1153         
1154         uiEndBlock(C, block);
1155         uiDrawBlock(C, block);
1156 }
1157
1158 /********************** toolbox operator *********************/
1159
1160 static int toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event)
1161 {
1162         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
1163         Object *obedit= CTX_data_edit_object(C);
1164         uiMenuItem *head;
1165         int show_uvedit;
1166
1167         show_uvedit= get_space_image_show_uvedit(sima, obedit);
1168
1169         head= uiPupMenuBegin("Toolbox", 0);
1170
1171         uiMenuLevel(head, "View", image_viewmenu);
1172         if(show_uvedit) uiMenuLevel(head, "Select", image_selectmenu);
1173         uiMenuLevel(head, "Image", image_imagemenu);
1174         if(show_uvedit) uiMenuLevel(head, "UVs", image_uvsmenu);
1175
1176         uiPupMenuEnd(C, head);
1177
1178         return OPERATOR_CANCELLED;
1179 }
1180
1181 void IMAGE_OT_toolbox(wmOperatorType *ot)
1182 {
1183         /* identifiers */
1184         ot->name= "Toolbox";
1185         ot->idname= "IMAGE_OT_toolbox";
1186         
1187         /* api callbacks */
1188         ot->invoke= toolbox_invoke;
1189         ot->poll= space_image_main_area_poll;
1190 }
1191
1192