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