~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/src/header_image.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Functions to draw the "UV/Image Editor" window header
5
5
 * and handle user events sent to it.
6
6
 * 
7
 
 * $Id: header_image.c,v 1.60 2006/07/03 11:21:38 ton Exp $
 
7
 * $Id: header_image.c 14824 2008-05-13 06:12:33Z campbellbarton $
8
8
 *
9
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
9
 * ***** BEGIN GPL LICENSE BLOCK *****
10
10
 *
11
11
 * This program is free software; you can redistribute it and/or
12
12
 * modify it under the terms of the GNU General Public License
13
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.
 
14
 * of the License, or (at your option) any later version.
18
15
 *
19
16
 * This program is distributed in the hope that it will be useful,
20
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
29
 *
33
30
 * Contributor(s): none yet.
34
31
 *
35
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
32
 * ***** END GPL LICENSE BLOCK *****
36
33
 */
37
34
 
38
35
#include <stdlib.h>
42
39
#include <config.h>
43
40
#endif
44
41
 
 
42
#include "DNA_brush_types.h"
45
43
#include "DNA_ID.h"
46
44
#include "DNA_image_types.h"
47
 
#include "DNA_mesh_types.h"
48
 
#include "DNA_object_types.h"
49
 
#include "DNA_packedFile_types.h"
50
45
#include "DNA_scene_types.h"
51
46
#include "DNA_screen_types.h"
52
47
#include "DNA_space_types.h"
 
48
#include "DNA_texture_types.h"
53
49
#include "DNA_userdef_types.h"
 
50
#include "DNA_customdata_types.h" /* for UV layer menu */
 
51
 
 
52
#include "BLI_arithb.h"
 
53
#include "BLI_blenlib.h"
54
54
 
55
55
#include "BDR_drawmesh.h"
56
56
#include "BDR_unwrapper.h"
 
57
 
 
58
#include "BKE_brush.h"
 
59
#include "BKE_colortools.h"
57
60
#include "BKE_global.h"
58
61
#include "BKE_image.h"
59
 
#include "BKE_library.h"
60
62
#include "BKE_main.h"
61
 
#include "BKE_packedFile.h"
62
63
#include "BKE_utildefines.h"
63
 
#include "BKE_depsgraph.h"
 
64
#include "BLI_editVert.h" /* for UV layer menu */
 
65
#include "BKE_customdata.h" /* ditto */
64
66
 
65
 
#include "BLI_blenlib.h"
 
67
#include "BIF_butspace.h"
66
68
#include "BIF_drawimage.h"
67
69
#include "BIF_editsima.h"
 
70
#include "BIF_imasel.h"
68
71
#include "BIF_interface.h"
69
 
#include "BIF_previewrender.h"
70
72
#include "BIF_resources.h"
71
73
#include "BIF_screen.h"
72
74
#include "BIF_space.h"
73
 
#include "BIF_toets.h"
 
75
#include "BIF_transform.h"
74
76
#include "BIF_toolbox.h"
75
 
#include "BIF_transform.h"
76
 
#include "BIF_writeimage.h"
 
77
#include "BIF_editmesh.h"
77
78
 
 
79
#include "BSE_drawview.h"
78
80
#include "BSE_filesel.h"
79
81
#include "BSE_headerbuttons.h"
 
82
#include "BSE_trans_types.h"
 
83
#include "BSE_edit.h"
80
84
 
81
85
#include "BPY_extern.h"
82
86
#include "BPY_menus.h"
83
87
 
84
 
#include "IMB_imbuf.h"
85
88
#include "IMB_imbuf_types.h"
86
 
#include "BSE_trans_types.h"
 
89
 
 
90
#include "RE_pipeline.h"
87
91
 
88
92
#include "blendef.h"
 
93
#include "butspace.h"
89
94
#include "mydevice.h"
90
95
 
91
 
static void load_space_image(char *str) /* called from fileselect */
92
 
{
93
 
        Image *ima=0;
94
 
 
95
 
        if(G.obedit) {
96
 
                error("Can't perfom this in editmode");
97
 
                return;
98
 
        }
99
 
 
100
 
        ima= add_image(str);
101
 
        if(ima) {
102
 
 
103
 
                G.sima->image= ima;
104
 
 
105
 
                free_image_buffers(ima);        /* force read again */
106
 
                ima->ok= 1;
107
 
                image_changed(G.sima, 0);
108
 
 
109
 
        }
110
 
        BIF_undo_push("Load image UV");
111
 
        allqueue(REDRAWIMAGE, 0);
112
 
}
113
 
 
114
 
static void image_replace(Image *old, Image *new)
115
 
{
116
 
        TFace *tface;
117
 
        Mesh *me;
118
 
        int a, rep=0;
119
 
 
120
 
        new->tpageflag= old->tpageflag;
121
 
        new->twsta= old->twsta;
122
 
        new->twend= old->twend;
123
 
        new->xrep= old->xrep;
124
 
        new->yrep= old->yrep;
125
 
 
126
 
        me= G.main->mesh.first;
127
 
        while(me) {
128
 
 
129
 
                if(me->tface) {
130
 
                        tface= me->tface;
131
 
                        a= me->totface;
132
 
                        while(a--) {
133
 
                                if(tface->tpage==old) {
134
 
                                        tface->tpage= new;
135
 
                                        rep++;
136
 
                                }
137
 
                                tface++;
138
 
                        }
139
 
                }
140
 
                me= me->id.next;
141
 
 
142
 
        }
143
 
        if(rep) {
144
 
                if(new->id.us==0) new->id.us= 1;
145
 
        }
146
 
        else error("Nothing replaced");
147
 
}
148
 
 
149
 
static void replace_space_image(char *str)              /* called from fileselect */
150
 
{
151
 
        Image *ima=0;
152
 
 
153
 
        if(G.obedit) {
154
 
                error("Can't perfom this in editmode");
155
 
                return;
156
 
        }
157
 
 
158
 
        ima= add_image(str);
159
 
        if(ima) {
160
 
 
161
 
                if(G.sima->image && G.sima->image != ima) {
162
 
                        image_replace(G.sima->image, ima);
163
 
                }
164
 
 
165
 
                G.sima->image= ima;
166
 
 
167
 
                free_image_buffers(ima);        /* force read again */
168
 
                ima->ok= 1;
169
 
                /* replace also assigns: */
170
 
                image_changed(G.sima, 0);
171
 
 
172
 
        }
173
 
        BIF_undo_push("Replace image UV");
174
 
        allqueue(REDRAWIMAGE, 0);
175
 
}
176
 
 
177
 
static void save_paint(char *name)
178
 
{
179
 
        Image *ima = G.sima->image;
180
 
        int len;
181
 
        char str[FILE_MAXDIR+FILE_MAXFILE];
182
 
 
183
 
        if (ima  && ima->ibuf) {
184
 
                BLI_strncpy(str, name, sizeof(str));
185
 
 
186
 
                BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
187
 
                
188
 
                if(G.scene->r.scemode & R_EXTENSION) 
189
 
                        BKE_add_image_extension(str, G.scene->r.imtype);
190
 
 
191
 
                if (saveover(str)) {
192
 
                        
193
 
                        /* enforce user setting for RGB or RGBA, but skip BW */
194
 
                        if(G.scene->r.planes==32)
195
 
                                ima->ibuf->depth= 32;
196
 
                        else if(G.scene->r.planes==24)
197
 
                                ima->ibuf->depth= 24;
198
 
                        
199
 
                        waitcursor(1);
200
 
                        if (BKE_write_ibuf(ima->ibuf, str, G.scene->r.imtype, G.scene->r.subimtype, G.scene->r.quality)) {
201
 
                                BLI_strncpy(ima->name, name, sizeof(ima->name));
202
 
                                ima->ibuf->userflags &= ~IB_BITMAPDIRTY;
203
 
                                allqueue(REDRAWHEADERS, 0);
204
 
                                allqueue(REDRAWBUTSSHADING, 0);
205
 
                        } else {
206
 
                                error("Couldn't write image: %s", str);
207
 
                        }
208
 
                        
209
 
                        /* name image as how we saved it */
210
 
                        len= strlen(str);
211
 
                        while (len > 0 && str[len - 1] != '/' && str[len - 1] != '\\') len--;
212
 
                        rename_id(&ima->id, str+len);
213
 
 
214
 
                        waitcursor(0);
215
 
                }
216
 
        }
217
 
}
218
 
 
219
96
void do_image_buttons(unsigned short event)
220
97
{
221
 
        Image *ima;
 
98
        ToolSettings *settings= G.scene->toolsettings;
222
99
        ID *id, *idtest;
223
100
        int nr;
224
 
        char name[256];
225
101
 
226
102
        if(curarea->win==0) return;
227
103
 
 
104
        if(event<=100) {
 
105
                if(event<=50) do_global_buttons2(event);
 
106
                else do_global_buttons(event);
 
107
                return;
 
108
        }
 
109
        
228
110
        switch(event) {
 
111
        case B_SIMAPIN:
 
112
                allqueue (REDRAWIMAGE, 0);
 
113
                break;
229
114
        case B_SIMAGEHOME:
230
115
                image_home();
231
116
                break;
232
117
 
233
118
        case B_SIMABROWSE:      
234
119
                if(G.sima->imanr== -2) {
235
 
                        activate_databrowse((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
236
 
                                                                                        &G.sima->imanr, do_image_buttons);
 
120
                        if(G.qual & LR_CTRLKEY) {
 
121
                                activate_databrowse_imasel((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
 
122
                                                                                        &G.sima->imanr, do_image_buttons);
 
123
                        } else {
 
124
                                activate_databrowse((ID *)G.sima->image, ID_IM, 0, B_SIMABROWSE,
 
125
                                                                                        &G.sima->imanr, do_image_buttons);
 
126
                        }
237
127
                        return;
238
128
                }
239
129
                if(G.sima->imanr < 0) break;
241
131
                nr= 1;
242
132
                id= (ID *)G.sima->image;
243
133
 
244
 
                idtest= G.main->image.first;
245
 
                while(idtest) {
246
 
                        if(nr==G.sima->imanr) {
247
 
                                break;
248
 
                        }
249
 
                        nr++;
250
 
                        idtest= idtest->next;
251
 
                }
252
 
                if(idtest==0) { /* no new */
 
134
                idtest= BLI_findlink(&G.main->image, G.sima->imanr-1);
 
135
                if(idtest==NULL) { /* no new */
253
136
                        return;
254
137
                }
255
138
        
256
139
                if(idtest!=id) {
257
140
                        G.sima->image= (Image *)idtest;
258
141
                        if(idtest->us==0) idtest->us= 1;
 
142
                        BKE_image_signal(G.sima->image, &G.sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
259
143
                        allqueue(REDRAWIMAGE, 0);
260
144
                }
261
145
                /* also when image is the same: assign! 0==no tileflag: */
262
 
                image_changed(G.sima, 0);
 
146
                image_changed(G.sima, (Image *)idtest);
263
147
                BIF_undo_push("Assign image UV");
264
148
 
265
149
                break;
266
 
        case B_SIMAGELOAD:
267
 
                
268
 
                if(G.sima->image) strcpy(name, G.sima->image->name);
269
 
                else strcpy(name, U.textudir);
270
 
                
271
 
                if(G.qual==LR_CTRLKEY)
272
 
                        activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image);
273
 
                else
274
 
                        activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image);
275
 
                break;
276
 
                
277
 
        case B_SIMAGEREPLACE:
278
 
                
279
 
                if(G.sima->image) strcpy(name, G.sima->image->name);
280
 
                else strcpy(name, U.textudir);
281
 
                
282
 
                if(G.qual==LR_CTRLKEY)
283
 
                        activate_imageselect(FILE_SPECIAL, "REPLACE IMAGE", name, replace_space_image);
284
 
                else
285
 
                        activate_fileselect(FILE_SPECIAL, "REPLACE IMAGE", name, replace_space_image);
286
 
                break;
287
 
                
288
 
        case B_SIMAGEDRAW:
289
 
                
290
 
                if(G.f & G_FACESELECT) {
291
 
                        make_repbind(G.sima->image);
292
 
                        image_changed(G.sima, 1);
293
 
                }
294
 
                allqueue(REDRAWVIEW3D, 0);
295
 
                allqueue(REDRAWIMAGE, 0);
296
 
                break;
297
 
 
298
 
        case B_SIMAGEDRAW1:
299
 
                image_changed(G.sima, 2);               /* 2: only tileflag */
300
 
                allqueue(REDRAWVIEW3D, 0);
301
 
                allqueue(REDRAWIMAGE, 0);
302
 
                break;
303
 
                
304
 
        case B_TWINANIM:
305
 
                ima = G.sima->image;
306
 
                if (ima) {
307
 
                        if(ima->flag & IMA_TWINANIM) {
308
 
                                nr= ima->xrep*ima->yrep;
309
 
                                if(ima->twsta>=nr) ima->twsta= 1;
310
 
                                if(ima->twend>=nr) ima->twend= nr-1;
311
 
                                if(ima->twsta>ima->twend) ima->twsta= 1;
312
 
                                allqueue(REDRAWIMAGE, 0);
313
 
                        }
314
 
                }
315
 
                break;
316
 
 
 
150
        case B_SIMAGETILE:
 
151
                image_set_tile(G.sima, 1);              /* 1: only tileflag */
 
152
                allqueue(REDRAWVIEW3D, 0);
 
153
                allqueue(REDRAWIMAGE, 0);
 
154
                break;
 
155
        case B_SIMA3DVIEWDRAW:
 
156
                allqueue(REDRAWVIEW3D, 0);
 
157
                break;
 
158
        case B_SIMA_REDR_IMA_3D:
 
159
                allqueue(REDRAWVIEW3D, 0);
 
160
                allqueue(REDRAWIMAGE, 0);
 
161
                break;
317
162
        case B_SIMAGEPAINTTOOL:
318
 
                // check for packed file here
 
163
                if(G.sima->flag & SI_DRAWTOOL)
 
164
                        /* add new brush if none exists */
 
165
                        brush_check_exists(&G.scene->toolsettings->imapaint.brush);
 
166
                allqueue(REDRAWBUTSSHADING, 0);
319
167
                allqueue(REDRAWIMAGE, 0);
320
168
                allqueue(REDRAWVIEW3D, 0);
321
169
                break;
 
170
 
322
171
        case B_SIMAPACKIMA:
323
 
                ima = G.sima->image;
324
 
                if (ima) {
325
 
                        if (ima->packedfile) {
326
 
                                if (G.fileflags & G_AUTOPACK) {
327
 
                                        if (okee("Disable AutoPack ?")) {
328
 
                                                G.fileflags &= ~G_AUTOPACK;
329
 
                                        }
330
 
                                }
331
 
                                
332
 
                                if ((G.fileflags & G_AUTOPACK) == 0) {
333
 
                                        unpackImage(ima, PF_ASK);
334
 
                                }
335
 
                        } else {
336
 
                                if (ima->ibuf && (ima->ibuf->userflags & IB_BITMAPDIRTY)) {
337
 
                                        error("Can't pack painted image. Save image first.");
338
 
                                } else {
339
 
                                        ima->packedfile = newPackedFile(ima->name);
340
 
                                }
341
 
                        }
342
 
                        allqueue(REDRAWBUTSSHADING, 0);
343
 
                        allqueue(REDRAWHEADERS, 0);
344
 
                }
345
 
                break;
346
 
        case B_SIMAGESAVE:
347
 
                ima = G.sima->image;
348
 
                if (ima) {
349
 
                        strcpy(name, ima->name);
350
 
                        if (ima->ibuf) {
351
 
                                char str[64];
352
 
                                save_image_filesel_str(str);
353
 
                                
354
 
                                /* so it shows extension in file window */
355
 
                                if(G.scene->r.scemode & R_EXTENSION) 
356
 
                                        BKE_add_image_extension(name, G.scene->r.imtype);
357
 
                                
358
 
                                activate_fileselect(FILE_SPECIAL, str, name, save_paint);
359
 
                        }
360
 
                }
361
 
                break;
 
172
                pack_image_sima();
 
173
                break;
 
174
                
 
175
        case B_SIMA_REPACK:
 
176
                BKE_image_memorypack(G.sima->image);
 
177
                allqueue(REDRAWIMAGE, 0);
 
178
                break;
 
179
                
362
180
        case B_SIMA_USE_ALPHA:
363
181
                G.sima->flag &= ~(SI_SHOW_ALPHA|SI_SHOW_ZBUF);
364
182
                scrarea_queue_winredraw(curarea);
374
192
                scrarea_queue_winredraw(curarea);
375
193
                scrarea_queue_headredraw(curarea);
376
194
                break;
 
195
        case B_SIMARELOAD:
 
196
                reload_image_sima();
 
197
                break;
 
198
        case B_SIMAGELOAD:
 
199
                open_image_sima(0);
 
200
                break;
 
201
        case B_SIMANAME:
 
202
                if(G.sima->image) {
 
203
                        Image *ima;
 
204
                        char str[FILE_MAXDIR+FILE_MAXFILE];
 
205
                        
 
206
                        /* name in ima has been changed by button! */
 
207
                        BLI_strncpy(str, G.sima->image->name, sizeof(str));
 
208
                        ima= BKE_add_image_file(str);
 
209
                        if(ima) {
 
210
                                BKE_image_signal(ima, &G.sima->iuser, IMA_SIGNAL_RELOAD);
 
211
                                image_changed(G.sima, ima);
 
212
                        }
 
213
                        BIF_undo_push("Load image");
 
214
                        allqueue(REDRAWIMAGE, 0);
 
215
                }
 
216
                break;
 
217
        case B_SIMAMULTI:
 
218
                if(G.sima && G.sima->image) {
 
219
                        BKE_image_multilayer_index(G.sima->image->rr, &G.sima->iuser);
 
220
                        allqueue(REDRAWIMAGE, 0);
 
221
                }
 
222
                break;
 
223
        case B_TRANS_IMAGE:
 
224
                image_editvertex_buts(NULL);
 
225
                break;
 
226
        case B_CURSOR_IMAGE:
 
227
                image_editcursor_buts(NULL);
 
228
                break;
 
229
                
 
230
        case B_TWINANIM:
 
231
        {
 
232
                Image *ima;
 
233
                int nr;
 
234
                
 
235
                ima = G.sima->image;
 
236
                if (ima) {
 
237
                        if(ima->flag & IMA_TWINANIM) {
 
238
                                nr= ima->xrep*ima->yrep;
 
239
                                if(ima->twsta>=nr) ima->twsta= 1;
 
240
                                if(ima->twend>=nr) ima->twend= nr-1;
 
241
                                if(ima->twsta>ima->twend) ima->twsta= 1;
 
242
                                allqueue(REDRAWIMAGE, 0);
 
243
                        }
 
244
                }
 
245
                break;
 
246
        }       
 
247
        case B_SIMACLONEBROWSE:
 
248
                if (settings->imapaint.brush)
 
249
                        if (brush_clone_image_set_nr(settings->imapaint.brush, G.sima->menunr))
 
250
                                allqueue(REDRAWIMAGE, 0);
 
251
                break;
 
252
                
 
253
        case B_SIMACLONEDELETE:
 
254
                if (settings->imapaint.brush)
 
255
                        if (brush_clone_image_delete(settings->imapaint.brush))
 
256
                                allqueue(REDRAWIMAGE, 0);
 
257
                break;
 
258
                
 
259
        case B_SIMABRUSHCHANGE:
 
260
                allqueue(REDRAWIMAGE, 0);
 
261
                allqueue(REDRAWBUTSEDIT, 0);
 
262
                break;
 
263
                
 
264
        case B_SIMACURVES:
 
265
                curvemapping_do_ibuf(G.sima->cumap, imagewindow_get_ibuf(G.sima));
 
266
                allqueue(REDRAWIMAGE, 0);
 
267
                break;
 
268
                
 
269
        case B_SIMARANGE:
 
270
                curvemapping_set_black_white(G.sima->cumap, NULL, NULL);
 
271
                curvemapping_do_ibuf(G.sima->cumap, imagewindow_get_ibuf(G.sima));
 
272
                allqueue(REDRAWIMAGE, 0);
 
273
                break;
 
274
                
 
275
        case B_SIMABRUSHBROWSE:
 
276
                if(G.sima->menunr==-2) {
 
277
                        activate_databrowse((ID*)settings->imapaint.brush, ID_BR, 0, B_SIMABRUSHBROWSE, &G.sima->menunr, do_global_buttons);
 
278
                        break;
 
279
                }
 
280
                else if(G.sima->menunr < 0) break;
 
281
                
 
282
                if(brush_set_nr(&settings->imapaint.brush, G.sima->menunr)) {
 
283
                        BIF_undo_push("Browse Brush");
 
284
                        allqueue(REDRAWBUTSEDIT, 0);
 
285
                        allqueue(REDRAWIMAGE, 0);
 
286
                }
 
287
                break;
 
288
        case B_SIMABRUSHDELETE:
 
289
                if(brush_delete(&settings->imapaint.brush)) {
 
290
                        BIF_undo_push("Unlink Brush");
 
291
                        allqueue(REDRAWIMAGE, 0);
 
292
                        allqueue(REDRAWBUTSEDIT, 0);
 
293
                }
 
294
                break;
 
295
        case B_KEEPDATA:
 
296
                brush_toggled_fake_user(settings->imapaint.brush);
 
297
                allqueue(REDRAWIMAGE, 0);
 
298
                allqueue(REDRAWBUTSEDIT, 0);
 
299
                break;
 
300
        case B_SIMABRUSHLOCAL:
 
301
                if(settings->imapaint.brush && settings->imapaint.brush->id.lib) {
 
302
                        if(okee("Make local")) {
 
303
                                make_local_brush(settings->imapaint.brush);
 
304
                                allqueue(REDRAWIMAGE, 0);
 
305
                                allqueue(REDRAWBUTSEDIT, 0);
 
306
                        }
 
307
                }
 
308
                break;
 
309
        case B_SIMABTEXBROWSE:
 
310
                if(settings->imapaint.brush) {
 
311
                        Brush *brush= settings->imapaint.brush;
 
312
                        
 
313
                        if(G.sima->menunr==-2) {
 
314
                                MTex *mtex= brush->mtex[brush->texact];
 
315
                                ID *id= (ID*)((mtex)? mtex->tex: NULL);
 
316
                                if(G.qual & LR_CTRLKEY) {
 
317
                                        activate_databrowse_imasel(id, ID_TE, 0, B_SIMABTEXBROWSE, &G.sima->menunr, do_image_buttons);
 
318
                                } else {
 
319
                                        activate_databrowse(id, ID_TE, 0, B_SIMABTEXBROWSE, &G.sima->menunr, do_image_buttons);
 
320
                                }
 
321
                                break;
 
322
                        }
 
323
                        else if(G.sima->menunr < 0) break;
 
324
                        
 
325
                        if(brush_texture_set_nr(brush, G.sima->menunr)) {
 
326
                                BIF_undo_push("Browse Brush Texture");
 
327
                                allqueue(REDRAWBUTSSHADING, 0);
 
328
                                allqueue(REDRAWBUTSEDIT, 0);
 
329
                                allqueue(REDRAWIMAGE, 0);
 
330
                        }
 
331
                }
 
332
                break;
 
333
        case B_SIMABTEXDELETE:
 
334
                if(settings->imapaint.brush) {
 
335
                        if (brush_texture_delete(settings->imapaint.brush)) {
 
336
                                BIF_undo_push("Unlink Brush Texture");
 
337
                                allqueue(REDRAWBUTSSHADING, 0);
 
338
                                allqueue(REDRAWBUTSEDIT, 0);
 
339
                                allqueue(REDRAWIMAGE, 0);
 
340
                        }
 
341
                }
 
342
                break;
 
343
        case B_SIMA_PLAY:
 
344
                play_anim(0);
 
345
                break;
 
346
        case B_SIMA_RECORD:
 
347
                imagespace_composite_flipbook(curarea);
 
348
                break;
377
349
        }
378
350
}
379
351
 
 
352
static void do_image_buttons_set_uvlayer_callback(void *act, void *data)
 
353
{
 
354
        CustomData_set_layer_active(&G.editMesh->fdata, CD_MTFACE, *((int *)act));
 
355
        
 
356
        BIF_undo_push("Set Active UV Texture");
 
357
        allqueue(REDRAWVIEW3D, 0);
 
358
        allqueue(REDRAWBUTSEDIT, 0);
 
359
        allqueue(REDRAWIMAGE, 0);
 
360
}
 
361
 
380
362
static void do_image_view_viewnavmenu(void *arg, int event)
381
363
{
382
364
        switch(event) {
452
434
        case 2: /* Maximize Window */
453
435
                /* using event B_FULL */
454
436
                break;
455
 
        case 5: /* Draw Shadow Mesh */
456
 
                if(G.sima->flag & SI_DRAWSHADOW)
457
 
                        G.sima->flag &= ~SI_DRAWSHADOW;
458
 
                else
459
 
                        G.sima->flag |= SI_DRAWSHADOW;
460
 
                allqueue(REDRAWIMAGE, 0);
461
 
                break;
462
 
        case 6: /* Draw Faces */
463
 
                if(G.f & G_DRAWFACES)
464
 
                        G.f &= ~G_DRAWFACES;
465
 
                else
466
 
                        G.f |= G_DRAWFACES;
467
 
                allqueue(REDRAWIMAGE, 0);
 
437
        case 4: /* Realtime Panel... */
 
438
                add_blockhandler(curarea, IMAGE_HANDLER_VIEW_PROPERTIES, UI_PNL_UNSTOW);
468
439
                break;
469
440
        case 7: /* Properties  Panel */
470
441
                add_blockhandler(curarea, IMAGE_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
473
444
                add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
474
445
                break;
475
446
        case 9:
476
 
                image_viewcentre();
477
 
        case 10: /* Display Normalized Coordinates */
478
 
                G.sima->flag ^= SI_COORDFLOATS;
479
 
                allqueue(REDRAWIMAGE, 0);
 
447
                image_viewcenter();
480
448
                break;
481
449
        case 11: /* Curves Panel... */
482
450
                add_blockhandler(curarea, IMAGE_HANDLER_CURVES, UI_PNL_UNSTOW);
484
452
        case 12: /* composite preview */
485
453
                toggle_blockhandler(curarea, IMAGE_HANDLER_PREVIEW, 0);
486
454
                scrarea_queue_winredraw(curarea);
487
 
 
 
455
                break;
 
456
        case 13: /* Realtime Panel... */
 
457
                add_blockhandler(curarea, IMAGE_HANDLER_GAME_PROPERTIES, UI_PNL_UNSTOW);
 
458
                break;
 
459
        case 14: /* Draw active image UV's only*/
 
460
                G.sima->flag ^= SI_LOCAL_UV;
 
461
                allqueue(REDRAWIMAGE, 0);
 
462
                break;
488
463
        }
489
464
        allqueue(REDRAWVIEW3D, 0);
490
465
}
498
473
        block= uiNewBlock(&curarea->uiblocks, "image_viewmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
499
474
        uiBlockSetButmFunc(block, do_image_viewmenu, NULL);
500
475
 
501
 
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Properties...",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
502
 
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Paint Tool...|C",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
 
476
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Properties...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
 
477
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Image Properties...|N",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
 
478
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Real-time Properties...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 13, "");
 
479
        if (G.sima->image && (G.sima->flag & SI_DRAWTOOL)) {
 
480
                uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Paint Tool...|C",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
 
481
        }
503
482
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Curves Tool...",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
504
483
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Composite Preview...|Shift P",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
505
 
 
506
 
        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, "");
507
 
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Display Normalized Coordinates|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
508
 
        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, "");
509
 
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Faces|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
510
 
        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, "");
511
 
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Shadow Mesh|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
512
 
 
 
484
        
 
485
        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, "");
 
486
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Local View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
 
487
        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, "");
 
488
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "UV Global View|NumPad /",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
 
489
        
513
490
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 
491
        
514
492
        uiDefIconTextBlockBut(block, image_view_viewnavmenu, NULL, ICON_RIGHTARROW_THIN, "View Navigation", 0, yco-=20, 120, 19, "");
515
493
 
516
494
        if(G.sima->lock) {
553
531
        case 1: /* Select/Deselect All */
554
532
                select_swap_tface_uv();
555
533
                break;
 
534
        case 9: /* Select Inverse */
 
535
                select_invert_tface_uv();
 
536
                break;
556
537
        case 2: /* Unlink Selection */
557
538
                unlink_selection();
558
539
                break;
559
540
        case 3: /* Linked UVs */
560
541
                select_linked_tface_uv(2);
561
542
                break;
562
 
        case 4: /* Toggle Local UVs Stick to Vertex in Mesh */
563
 
                if(G.sima->flag & SI_LOCALSTICKY)
564
 
                        G.sima->flag &= ~SI_LOCALSTICKY;
565
 
                else {
566
 
                        G.sima->flag |= SI_LOCALSTICKY;
567
 
                        G.sima->flag &= ~SI_STICKYUVS;
568
 
                }
569
 
                allqueue(REDRAWIMAGE, 0);
570
 
                break;  
571
 
        case 5: /* Toggle UVs Stick to Vertex in Mesh */
572
 
                if(G.sima->flag & SI_STICKYUVS) {
573
 
                        G.sima->flag &= ~SI_STICKYUVS;
574
 
                        G.sima->flag |= SI_LOCALSTICKY;
575
 
                }
576
 
                else {
577
 
                        G.sima->flag |= SI_STICKYUVS;
578
 
                        G.sima->flag &= ~SI_LOCALSTICKY;
579
 
                }
580
 
                allqueue(REDRAWIMAGE, 0);
581
 
                break;  
582
543
        case 6: /* Toggle Active Face Select */
583
544
                if(G.sima->flag & SI_SELACTFACE)
584
545
                        G.sima->flag &= ~SI_SELACTFACE;
599
560
 
600
561
        block= uiNewBlock(&curarea->uiblocks, "image_selectmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
601
562
        uiBlockSetButmFunc(block, do_image_selectmenu, NULL);
602
 
 
603
 
        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, "");
604
 
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
605
 
 
606
 
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
607
 
 
608
 
        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, "");
609
 
        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, "");
610
 
 
611
 
        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, "");
612
 
        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, "");
613
 
 
614
 
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
615
 
 
 
563
        
 
564
        
 
565
        if ((G.sima->flag & SI_SYNC_UVSEL)==0 || (G.sima->flag & SI_SYNC_UVSEL && (G.scene->selectmode != SCE_SELECT_FACE))) {
 
566
                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, "");
 
567
                else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Active Face Select|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
 
568
        
 
569
                uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 
570
        }
 
571
        
616
572
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
617
573
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select Pinned|Shift B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
618
574
 
620
576
 
621
577
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
622
578
 
 
579
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
 
580
 
623
581
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unlink Selection|Alt L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
624
582
        
625
583
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
644
602
{
645
603
        switch(event) {
646
604
        case 0: /* UV Co-ordinates */
647
 
                G.sima->image->flag = BCLR(G.sima->image->flag, 4);
 
605
                G.sima->image->flag &= ~IMA_REFLECT;
648
606
                break;
649
607
        case 1: /* Reflection */
650
 
                G.sima->image->flag = BSET(G.sima->image->flag, 4);
 
608
                G.sima->image->flag |= IMA_REFLECT;
651
609
                break;
652
 
                }
 
610
        }
653
611
 
654
612
        allqueue(REDRAWVIEW3D, 0);
655
613
}
677
635
 
678
636
static void do_image_imagemenu(void *arg, int event)
679
637
{
680
 
        Image *ima;
681
 
        char name[256];
682
 
 
 
638
        /* events >=20 are registered bpython scripts */
 
639
        if (event >= 20) BPY_menu_do_python(PYMENU_IMAGE, event - 20);
 
640
        
683
641
        switch(event)
684
642
        {
685
 
        case 0: /* Open */
686
 
                if(G.sima->image) strcpy(name, G.sima->image->name);
687
 
                else strcpy(name, U.textudir);
688
 
                if(G.qual==LR_CTRLKEY)
689
 
                        activate_imageselect(FILE_SPECIAL, "Open Image", name, load_space_image);
690
 
                else
691
 
                        activate_fileselect(FILE_SPECIAL, "Open Image", name, load_space_image);
692
 
                break;
693
 
        case 1: /* Replace */
694
 
                if(G.sima->image) strcpy(name, G.sima->image->name);
695
 
                else strcpy(name, U.textudir);
696
 
                
697
 
                if(G.qual==LR_CTRLKEY)
698
 
                        activate_imageselect(FILE_SPECIAL, "Replace Image", name, replace_space_image);
699
 
                else
700
 
                        activate_fileselect(FILE_SPECIAL, "Replace Image", name, replace_space_image);
701
 
                break;
702
 
        case 2: /* Pack Image */
703
 
                ima = G.sima->image;
704
 
                if (ima) {
705
 
                        if (ima->packedfile) {
706
 
                                error("Image is already packed.");
707
 
                        } else {
708
 
                                if (ima->ibuf && (ima->ibuf->userflags & IB_BITMAPDIRTY)) {
709
 
                                        error("Can't pack painted image. Save the painted image first.");
710
 
                                } else {
711
 
                                        ima->packedfile = newPackedFile(ima->name);
712
 
                                }
713
 
                        }
714
 
                }
715
 
                BIF_undo_push("Pack image");
716
 
                allqueue(REDRAWBUTSSHADING, 0);
717
 
                allqueue(REDRAWHEADERS, 0);
718
 
                break;
719
 
        case 3: /* Unpack Image */
720
 
                ima = G.sima->image;
721
 
                if (ima) {
722
 
                        if (ima->packedfile) {
723
 
                                if (G.fileflags & G_AUTOPACK) {
724
 
                                        if (okee("Disable AutoPack?")) {
725
 
                                                G.fileflags &= ~G_AUTOPACK;
726
 
                                        }
727
 
                                }
728
 
                                
729
 
                                if ((G.fileflags & G_AUTOPACK) == 0) {
730
 
                                        unpackImage(ima, PF_ASK);
731
 
                                }
732
 
                        } else {
733
 
                                error("There are no packed images to unpack");
734
 
                        }
735
 
                }
736
 
                BIF_undo_push("Unpack image");
737
 
                allqueue(REDRAWBUTSSHADING, 0);
738
 
                allqueue(REDRAWHEADERS, 0);
 
643
        case 0:
 
644
                open_image_sima((G.qual==LR_CTRLKEY));
 
645
                break;
 
646
        case 1:
 
647
                replace_image_sima((G.qual==LR_CTRLKEY));
 
648
                break;
 
649
        case 2:
 
650
                pack_image_sima();
739
651
                break;
740
652
        case 4: /* Texture Painting */
 
653
                brush_check_exists(&G.scene->toolsettings->imapaint.brush);
741
654
                if(G.sima->flag & SI_DRAWTOOL) G.sima->flag &= ~SI_DRAWTOOL;
742
655
                else G.sima->flag |= SI_DRAWTOOL;
743
 
                break;
744
 
        case 5: /* Save Painted Image */
745
 
                ima = G.sima->image;
746
 
                if (ima) {
747
 
                        strcpy(name, ima->name);
748
 
                        if (ima->ibuf) {
749
 
                                char str[64];
750
 
                                save_image_filesel_str(str);
751
 
                                
752
 
                                /* so it shows an extension in filewindow */
753
 
                                if(G.scene->r.scemode & R_EXTENSION) 
754
 
                                        BKE_add_image_extension(name, G.scene->r.imtype);
755
 
                                
756
 
                                activate_fileselect(FILE_SPECIAL, str, name, save_paint);
757
 
                        }
758
 
                }
759
 
                break;
760
 
        case 6: /* Reload Image */
761
 
                ima = G.sima->image;
762
 
                if (ima) {
763
 
                        if (ima->packedfile) {
764
 
                                PackedFile *pf;
765
 
                                pf = newPackedFile(ima->name);
766
 
                                if (pf) {
767
 
                                        freePackedFile(ima->packedfile);
768
 
                                        ima->packedfile = pf;
769
 
                                }
770
 
                                else
771
 
                                        error("Image not available. Keeping packed image.");
772
 
                        }
773
 
                        if (ima->preview) {
774
 
                                free_image_preview(ima);
775
 
                        }
776
 
                        free_image_buffers(ima);        /* force read again */
777
 
                        ima->ok= 1;
778
 
                        image_changed(G.sima, 0);
779
 
                }
 
656
                allqueue(REDRAWBUTSSHADING, 0);
 
657
                break;
 
658
        case 5:
 
659
                save_as_image_sima();
 
660
                break;
 
661
        case 6:
 
662
                reload_image_sima();
 
663
                break;
 
664
        case 7:
 
665
                new_image_sima();
 
666
                break;
 
667
        case 8:
 
668
                save_image_sima();
 
669
                break;
 
670
        case 9:
 
671
                save_image_sequence_sima();
 
672
                break;
 
673
        case 10:
 
674
                BKE_image_memorypack(G.sima->image);
780
675
                allqueue(REDRAWIMAGE, 0);
781
 
                allqueue(REDRAWVIEW3D, 0);
782
 
                BIF_preview_changed(ID_TE);
783
676
                break;
784
 
        case 7: /* New Image */
785
 
                {
786
 
                        static int width= 256, height= 256;
787
 
                        static short uvtestgrid=0;
788
 
                        char name[256];
789
 
 
790
 
                        strcpy(name, "Image");
791
 
 
792
 
                        add_numbut(0, TEX, "Name:", 0, 255, name, NULL);
793
 
                        add_numbut(1, NUM|INT, "Width:", 1, 5000, &width, NULL);
794
 
                        add_numbut(2, NUM|INT, "Height:", 1, 5000, &height, NULL);
795
 
                        add_numbut(3, TOG|SHO, "UV Test Grid", 0, 0, &uvtestgrid, NULL);
796
 
                        if (!do_clever_numbuts("New Image", 4, REDRAW))
797
 
                                return;
798
 
 
799
 
                        G.sima->image= new_image(width, height, name, uvtestgrid);
800
 
                        image_changed(G.sima, 0);
801
 
 
802
 
                        allqueue(REDRAWIMAGE, 0);
803
 
                        allqueue(REDRAWVIEW3D, 0);
804
 
 
805
 
                        break;
806
 
                }
807
677
        }
808
678
}
809
679
 
810
680
static uiBlock *image_imagemenu(void *arg_unused)
811
681
{
 
682
        ImBuf *ibuf= BKE_image_get_ibuf(G.sima->image, &G.sima->iuser);
812
683
        uiBlock *block;
813
684
        short yco= 0, menuwidth=150;
 
685
        BPyMenu *pym;
 
686
        int i = 0;
814
687
 
815
688
        block= uiNewBlock(&curarea->uiblocks, "image_imagemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
816
689
        uiBlockSetButmFunc(block, do_image_imagemenu, NULL);
817
690
 
818
 
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
819
 
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
 
691
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New...|Alt N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
 
692
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|Alt O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
820
693
        
821
694
        if (G.sima->image) {
 
695
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
 
696
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reload|Alt R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
 
697
                uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
 
698
 
 
699
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
822
700
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
823
 
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Replace...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
824
 
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reload", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
825
 
 
 
701
                if(G.sima->image->source==IMA_SRC_SEQUENCE)
 
702
                        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Changed Images", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
826
703
                uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
827
704
                
828
705
                if (G.sima->image->packedfile) {
829
 
                        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
 
706
                        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
830
707
                } else {
831
708
                        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
832
709
                }
833
 
                        
 
710
                
 
711
                /* only for dirty && specific image types */
 
712
                if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
 
713
                        if( ELEM(G.sima->image->source, IMA_SRC_FILE, IMA_SRC_GENERATED))
 
714
                                if(G.sima->image->type!=IMA_TYPE_MULTILAYER)
 
715
                                        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Image as PNG", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
 
716
                
834
717
                uiDefBut(block, SEPR, 0, "",        0, yco-=7, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
835
718
 
836
719
                if(G.sima->flag & SI_DRAWTOOL) {
845
728
                // uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Realtime Texture Animation|",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
846
729
        }
847
730
        
 
731
        /* note that we acount for the N previous entries with i+20: */
 
732
        for (pym = BPyMenuTable[PYMENU_IMAGE]; pym; pym = pym->next, i++) {
 
733
 
 
734
                uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
 
735
                                 NULL, 0.0, 0.0, 1, i+20, 
 
736
                                 pym->tooltip?pym->tooltip:pym->filename);
 
737
        }
 
738
        
848
739
        if(curarea->headertype==HEADERTOP) {
849
740
                uiBlockSetDirection(block, UI_DOWN);
850
741
        }
960
851
 
961
852
static void do_image_uvs_mirrormenu(void *arg, int event)
962
853
{
 
854
        float mat[3][3];
 
855
        
 
856
        Mat3One(mat);
 
857
        
963
858
        switch(event) {
964
859
        case 0: /* X axis */
965
 
                mirror_tface_uv('x');
 
860
                initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
 
861
                BIF_setSingleAxisConstraint(mat[0], " on global X axis");
 
862
                Transform();
966
863
                break;
967
864
        case 1: /* Y axis */
968
 
                mirror_tface_uv('y');
 
865
                initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
 
866
                BIF_setSingleAxisConstraint(mat[1], " on global Y axis");
 
867
                Transform();
969
868
                break;
970
869
        }
971
870
        
994
893
        case 0: /* Weld */
995
894
                weld_align_tface_uv('w');
996
895
                break;
997
 
        case 1: /* Align X */
 
896
        case 1: /* Align Auto */
 
897
                weld_align_tface_uv('a');
 
898
                break;
 
899
        case 2: /* Align X */
998
900
                weld_align_tface_uv('x');
999
901
                break;
1000
 
        case 2: /* Align Y */
 
902
        case 3: /* Align Y */
1001
903
                weld_align_tface_uv('y');
1002
904
                break;
1003
905
        }
1004
906
        
1005
907
        if(event==0) BIF_undo_push("Weld UV");
1006
 
        else if(event==1 || event==2) BIF_undo_push("Align UV");
 
908
        else if(ELEM3(event, 1, 2, 3)) BIF_undo_push("Align UV");
1007
909
}
1008
910
 
1009
911
static uiBlock *image_uvs_weldalignmenu(void *arg_unused)
1015
917
        uiBlockSetButmFunc(block, do_image_uvs_weldalignmenu, NULL);
1016
918
        
1017
919
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Weld|W, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1018
 
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align X|W, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
1019
 
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Y|W, 3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
1020
 
 
1021
 
        uiBlockSetDirection(block, UI_RIGHT);
1022
 
        uiTextBoundsBlock(block, 60);
 
920
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Auto|W, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
 
921
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align X|W, 3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
 
922
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Align Y|W, 4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
 
923
 
 
924
        uiBlockSetDirection(block, UI_RIGHT);
 
925
        uiTextBoundsBlock(block, 60);
 
926
        return block;
 
927
}
 
928
 
 
929
static void do_image_uvs_scriptsmenu(void *arg, int event)
 
930
{
 
931
        BPY_menu_do_python(PYMENU_UV, event);
 
932
 
 
933
        allqueue(REDRAWIMAGE, 0);
 
934
}
 
935
 
 
936
static uiBlock *image_uvs_scriptsmenu (void *args_unused)
 
937
{
 
938
        uiBlock *block;
 
939
        BPyMenu *pym;
 
940
        int i= 0;
 
941
        short yco = 20, menuwidth = 120;
 
942
        
 
943
        block= uiNewBlock(&curarea->uiblocks, "image_uvs_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
 
944
        uiBlockSetButmFunc(block, do_image_uvs_scriptsmenu, NULL);
 
945
        
 
946
        /* note that we acount for the N previous entries with i+20: */
 
947
        for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
 
948
                
 
949
                uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
 
950
                                                 NULL, 0.0, 0.0, 1, i, 
 
951
                                                 pym->tooltip?pym->tooltip:pym->filename);
 
952
        }
 
953
        
 
954
        uiBlockSetDirection(block, UI_RIGHT);
 
955
        uiTextBoundsBlock(block, 60);
 
956
        
1023
957
        return block;
1024
958
}
1025
959
 
1026
960
static void do_image_uvsmenu(void *arg, int event)
1027
961
{
1028
 
        /* events >=20 are registered bpython scripts */
1029
 
        if (event >= 20) BPY_menu_do_python(PYMENU_UV, event - 20);
1030
962
 
1031
 
        else switch(event)
1032
 
        {
 
963
        switch(event) {
 
964
//      case 0: /* UV Transform Properties Panel... */
 
965
//              add_blockhandler(curarea, IMAGE_HANDLER_TRANSFORM_PROPERTIES, UI_PNL_UNSTOW);
 
966
//              break;
1033
967
        case 1: /* UVs Constrained Rectangular */
1034
968
                if(G.sima->flag & SI_BE_SQUARE) G.sima->flag &= ~SI_BE_SQUARE;
1035
969
                else G.sima->flag |= SI_BE_SQUARE;
1039
973
                else G.sima->flag |= SI_CLIP_UV;
1040
974
                break;
1041
975
        case 3: /* Limit Stitch UVs */
1042
 
                stitch_uv_tface(1);
 
976
                stitch_limit_uv_tface();
1043
977
                break;
1044
978
        case 4: /* Stitch UVs */
1045
 
                stitch_uv_tface(0);
 
979
                stitch_vert_uv_tface();
1046
980
                break;
1047
981
        case 5: /* Proportional Edit (toggle) */
1048
982
                if(G.scene->proportional)
1069
1003
        case 12:
1070
1004
                minimize_stretch_tface_uv();
1071
1005
                break;
 
1006
        case 13:
 
1007
                pack_charts_tface_uv();
 
1008
                break;
 
1009
        case 14:
 
1010
                average_charts_tface_uv();
 
1011
                break;
1072
1012
        }
1073
1013
}
1074
1014
 
1076
1016
{
1077
1017
        uiBlock *block;
1078
1018
        short yco= 0, menuwidth=120;
1079
 
        BPyMenu *pym;
1080
 
        int i = 0;
1081
1019
 
1082
1020
        block= uiNewBlock(&curarea->uiblocks, "image_uvsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1083
1021
        uiBlockSetButmFunc(block, do_image_uvsmenu, NULL);
1084
 
 
1085
 
        // uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1086
 
        // uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 
1022
        
 
1023
        //uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
 
1024
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1087
1025
        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, "");
1088
1026
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
1089
1027
 
1103
1041
 
1104
1042
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1105
1043
 
 
1044
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Islands|Ctrl P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 13, "");
 
1045
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Average Islands Scale|Ctrl A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
1106
1046
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Minimize Stretch|Ctrl V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 12, "");
1107
1047
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Limit Stitch...|Shift V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
1108
1048
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Stitch|V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
 
1049
 
 
1050
        uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 
1051
        
1109
1052
        uiDefIconTextBlockBut(block, image_uvs_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 19, "");
1110
 
 
1111
 
        uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1112
 
        
1113
1053
        uiDefIconTextBlockBut(block, image_uvs_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 19, "");
1114
1054
        uiDefIconTextBlockBut(block, image_uvs_weldalignmenu, NULL, ICON_RIGHTARROW_THIN, "Weld/Align", 0, yco-=20, 120, 19, "");
1115
1055
        
1123
1063
        uiDefIconTextBlockBut(block, image_uvs_propfalloffmenu, NULL, ICON_RIGHTARROW_THIN, "Proportional Falloff", 0, yco-=20, 120, 19, "");
1124
1064
 
1125
1065
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1126
 
        
1127
 
        /* note that we acount for the 3 previous entries with i+3: */
1128
 
        for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) {
1129
 
 
1130
 
                uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
1131
 
                                 NULL, 0.0, 0.0, 1, i+20, 
1132
 
                                 pym->tooltip?pym->tooltip:pym->filename);
1133
 
        }
1134
 
 
1135
 
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
1136
1066
 
1137
1067
        uiDefIconTextBlockBut(block, image_uvs_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Faces", 0, yco-=20, menuwidth, 19, "");
1138
1068
 
 
1069
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");        
 
1070
        
 
1071
        uiDefIconTextBlockBut(block, image_uvs_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, "");
 
1072
        
1139
1073
        if(curarea->headertype==HEADERTOP) {
1140
1074
                uiBlockSetDirection(block, UI_DOWN);
1141
1075
        }
1151
1085
 
1152
1086
void image_buttons(void)
1153
1087
{
 
1088
        Image *ima;
 
1089
        ImBuf *ibuf;
1154
1090
        uiBlock *block;
1155
1091
        short xco, xmax;
1156
 
        char naam[256];
 
1092
        char naam[256], *menuname;
 
1093
        char is_render; /* true if the image is a render or composite */
 
1094
        
 
1095
        int allow_pin= B_SIMAPIN;
 
1096
        
1157
1097
        /* This should not be a static var */
1158
1098
        static int headerbuttons_packdummy;
 
1099
        
 
1100
        
 
1101
        is_render = ((G.sima->image!=NULL) && ((G.sima->image->type == IMA_TYPE_R_RESULT) || (G.sima->image->type == IMA_TYPE_COMPOSITE)));
1159
1102
 
1160
1103
        headerbuttons_packdummy = 0;
1161
1104
                
1166
1109
        else uiBlockSetCol(block, TH_HEADERDESEL);
1167
1110
 
1168
1111
        what_image(G.sima);
 
1112
        ima= G.sima->image;
 
1113
        ibuf= BKE_image_get_ibuf(ima, &G.sima->iuser);
1169
1114
 
1170
1115
        curarea->butspacetype= SPACE_IMAGE;
1171
1116
 
1187
1132
        xco+=XIC;
1188
1133
 
1189
1134
        if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
 
1135
                
1190
1136
                /* pull down menus */
1191
1137
                uiBlockSetEmboss(block, UI_EMBOSSP);
1192
1138
        
1194
1140
                uiDefPulldownBut(block, image_viewmenu, NULL, "View", xco, -2, xmax-3, 24, "");
1195
1141
                xco+= xmax;
1196
1142
                
1197
 
                xmax= GetButStringLength("Select");
1198
 
                uiDefPulldownBut(block, image_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
1199
 
        
1200
 
                xco+= xmax;
1201
 
                
1202
 
                xmax= GetButStringLength("Image");
1203
 
                uiDefPulldownBut(block, image_imagemenu, NULL, "Image", xco, -2, xmax-3, 24, "");
1204
 
                xco+= xmax;
1205
 
                
1206
 
                xmax= GetButStringLength("UVs");
1207
 
                uiDefPulldownBut(block, image_uvsmenu, NULL, "UVs", xco, -2, xmax-3, 24, "");
1208
 
                xco+= xmax;
 
1143
                if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
 
1144
                        xmax= GetButStringLength("Select");
 
1145
                        uiDefPulldownBut(block, image_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
 
1146
                        xco+= xmax;
 
1147
                }
 
1148
                
 
1149
                if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
 
1150
                        menuname= "Image*";
 
1151
                else
 
1152
                        menuname= "Image";
 
1153
                xmax= GetButStringLength(menuname);
 
1154
                uiDefPulldownBut(block, image_imagemenu, NULL, menuname, xco, -2, xmax-3, 24, "");
 
1155
                xco+= xmax;
 
1156
                if((EM_texFaceCheck()) && !(ima && (G.sima->flag & SI_DRAWTOOL))) {
 
1157
                        xmax= GetButStringLength("UVs");
 
1158
                        uiDefPulldownBut(block, image_uvsmenu, NULL, "UVs", xco, -2, xmax-3, 24, "");
 
1159
                        xco+= xmax;
 
1160
                }
1209
1161
        }
1210
1162
        
1211
1163
        /* other buttons: */
1212
1164
        uiBlockSetEmboss(block, UI_EMBOSS);
1213
1165
 
1214
 
        xco= std_libbuttons(block, xco, 0, 0, NULL, B_SIMABROWSE, ID_IM, 0, (ID *)G.sima->image, 0, &(G.sima->imanr), 0, 0, B_IMAGEDELETE, 0, 0);
 
1166
        if (is_render)
 
1167
                allow_pin = 0;
 
1168
        
 
1169
        xco= 8 + std_libbuttons(block, xco, 0, allow_pin, &G.sima->pin, B_SIMABROWSE, ID_IM, 0, (ID *)ima, 0, &(G.sima->imanr), 0, 0, B_IMAGEDELETE, 0, 0);
 
1170
        
 
1171
        if( ima && !ELEM3(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE, IMA_SRC_VIEWER) && ima->ok) {
1215
1172
 
1216
 
        if (G.sima->image) {
1217
 
                xco+= 8;
1218
 
        
1219
 
                if (G.sima->image->packedfile) {
 
1173
                if (ima->packedfile) {
1220
1174
                        headerbuttons_packdummy = 1;
1221
1175
                }
1222
 
                uiDefIconButBitI(block, TOG, 1, B_SIMAPACKIMA, ICON_PACKAGE,    xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
1223
 
                xco+= XIC+8;
1224
 
 
 
1176
                if (ima->packedfile && ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
 
1177
                        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");
 
1178
                else
 
1179
                        uiDefIconButBitI(block, TOG, 1, B_SIMAPACKIMA, ICON_PACKAGE,    xco,0,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
 
1180
                        
 
1181
                xco+= XIC+8;
 
1182
        }
 
1183
        
 
1184
        /* UV EditMode buttons, not painting or rencering or compositing */
 
1185
        if ( EM_texFaceCheck() && (G.sima->flag & SI_DRAWTOOL)==0 && !is_render) {
 
1186
                uiBut *ubut;
 
1187
                int layercount;
 
1188
                
 
1189
                uiDefIconTextButS(block, ICONTEXTROW, B_NOP, ICON_ROTATE,
 
1190
                                "Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1",
 
1191
                                xco,0,XIC+10,YIC, &(G.v2d->around), 0, 3.0, 0, 0,
 
1192
                                "Rotation/Scaling Pivot (Hotkeys: Comma, Shift Comma, Period)");
 
1193
                xco+= XIC + 18;
 
1194
                
 
1195
                
 
1196
                uiDefIconButBitI(block, TOG, SI_SYNC_UVSEL, B_REDR, ICON_EDIT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Sync UV and Mesh Selection");
 
1197
                xco+= XIC+8;
 
1198
                if (G.sima->flag & SI_SYNC_UVSEL) {
 
1199
                        uiBlockBeginAlign(block);
 
1200
                        
 
1201
                        /* B_SEL_VERT & B_SEL_FACE are not defined here which is a bit bad, BUT it works even if image editor is fullscreen */
 
1202
                        uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode (Ctrl Tab 1)");
 
1203
                        xco+= XIC;
 
1204
                        /* no edge */
 
1205
                        /*uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Edge select mode (Ctrl Tab 2)");
 
1206
                        xco+= XIC; */
 
1207
                        uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, xco,0,XIC,YIC, &G.scene->selectmode, 1.0, 0.0, 0, 0, "Face select mode (Ctrl Tab 3)");
 
1208
                        xco+= XIC+8;
 
1209
                        uiBlockEndAlign(block);
 
1210
                        
 
1211
                } else {
 
1212
                        uiBlockBeginAlign(block);
 
1213
                        uiDefIconButBitI(block, TOGN, SI_SELACTFACE, B_REDR, ICON_VERTEXSEL, xco,0,XIC,YIC, &G.sima->flag, 1.0, 0.0, 0, 0, "UV Vertex select mode");
 
1214
                        xco+= XIC;
 
1215
                        uiDefIconButBitI(block, TOG, SI_SELACTFACE, B_REDR, ICON_FACESEL, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "UV Face select mode");
 
1216
                        xco+= XIC+8;
 
1217
                        uiBlockEndAlign(block);
 
1218
                        
 
1219
                        /* would use these if const's could go in strings 
 
1220
                         * SI_STICKY_LOC SI_STICKY_DISABLE SI_STICKY_VERTEX */
 
1221
                        ubut = uiDefIconTextButC(block, ICONTEXTROW, B_REDR, ICON_STICKY_UVS_LOC,
 
1222
                                        "Sticky UV Selection: %t|Disable%x1|Shared Location%x0|Shared Vertex%x2",
 
1223
                                        xco,0,XIC+10,YIC, &(G.sima->sticky), 0, 3.0, 0, 0,
 
1224
                                        "Sticky UV Selection (Hotkeys: Shift C, Alt C, Ctrl C)");
 
1225
                        
 
1226
                }
 
1227
                xco+= XIC + 16;
 
1228
                
 
1229
                /* Snap copied right out of view3d header */
 
1230
                        uiBlockBeginAlign(block);
 
1231
 
 
1232
                        if (G.scene->snap_flag & SCE_SNAP) {
 
1233
                                uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEO,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Use Snap or Grid (Shift Tab)");   
 
1234
                                xco+= XIC;
 
1235
                                uiDefButS(block, MENU, B_NOP, "Mode%t|Closest%x0|Center%x1|Median%x2",xco,0,70,YIC, &G.scene->snap_target, 0, 0, 0, 0, "Snap Target Mode");
 
1236
                                xco+= 70;
 
1237
                        } else {
 
1238
                                uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEAR,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Snap while Ctrl is held during transform (Shift Tab)");  
 
1239
                                xco+= XIC;
 
1240
                        }
 
1241
 
 
1242
                        uiBlockEndAlign(block);
 
1243
                        xco+= 10;
 
1244
                /* end snap */
 
1245
                        
 
1246
                /* Layer Menu */
 
1247
                layercount = CustomData_number_of_layers(&G.editMesh->fdata, CD_MTFACE); 
 
1248
                if (layercount>1 && layercount < 12) { /* could allow any number but limit of 11 means no malloc needed */
 
1249
                        static int act;
 
1250
                        char str_menu[384], *str_pt; /*384 allows for 11 layers */
 
1251
                        
 
1252
                        
 
1253
                        act = CustomData_get_active_layer(&G.editMesh->fdata, CD_MTFACE);
 
1254
                        
 
1255
                        /*str_pt = (char *)MEM_mallocN(layercount*40 , "uvmenu"); str[0]='\0';*/
 
1256
                        str_pt = str_menu;
 
1257
                        str_pt[0]='\0';
 
1258
                        mesh_layers_menu_concat(&G.editMesh->fdata, CD_MTFACE, str_pt);
 
1259
                        ubut = uiDefButI(block, MENU, B_NOP, str_menu ,xco,0,85,YIC, &act, 0, 0, 0, 0, "Active UV Layer for editing");
 
1260
                        uiButSetFunc(ubut, do_image_buttons_set_uvlayer_callback, &act, NULL);
 
1261
                        
 
1262
                        /*MEM_freeN(str);*/
 
1263
                        xco+= 90;
 
1264
                }
 
1265
        }
 
1266
        
 
1267
        if (ima) {
 
1268
                RenderResult *rr= BKE_image_get_renderresult(ima);
 
1269
                
 
1270
                xco+= 8;
 
1271
        
 
1272
                if(rr) {
 
1273
                        uiBlockBeginAlign(block);
 
1274
                        uiblock_layer_pass_buttons(block, rr, &G.sima->iuser, B_REDR, xco, 0, 160);
 
1275
                        uiBlockEndAlign(block);
 
1276
                        xco+= 166;
 
1277
                }
1225
1278
                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");
 
1279
                
1226
1280
                xco+= XIC+8;
1227
1281
 
1228
1282
                uiBlockBeginAlign(block);
1229
 
                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");
1230
 
                xco+= XIC;
1231
 
                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");
1232
 
                xco+= XIC;
1233
 
                if(G.sima->image->ibuf) {
1234
 
                        if(G.sima->image->ibuf->zbuf || G.sima->image->ibuf->zbuf_float) {
1235
 
                                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");
 
1283
                if(ibuf==NULL || ibuf->channels==4) {
 
1284
                        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");
 
1285
                        xco+= XIC;
 
1286
                        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");
 
1287
                        xco+= XIC;
 
1288
                }
 
1289
                if(ibuf) {
 
1290
                        if(ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1)) {
 
1291
                                uiDefIconButBitI(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values (mapped from camera clip start to end)");
1236
1292
                                xco+= XIC;
1237
1293
                        }
1238
 
                        else G.sima->flag &= ~SI_SHOW_ZBUF;     /* no confusing display for non-zbuf images */
1239
1294
                }               
 
1295
                xco+= 8;
 
1296
                
 
1297
                uiBlockBeginAlign(block);
 
1298
                if(ima->type==IMA_TYPE_COMPOSITE) {
 
1299
                        uiDefIconBut(block, BUT, B_SIMA_RECORD, ICON_REC,  xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Record Composite");
 
1300
                        xco+= XIC;
 
1301
                }
 
1302
                if((ima->type==IMA_TYPE_COMPOSITE) || ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
 
1303
                        uiDefIconBut(block, BUT, B_SIMA_PLAY, ICON_PLAY, xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Play");
 
1304
                        xco+= XIC;
 
1305
                }
1240
1306
                uiBlockEndAlign(block);
1241
1307
                xco+= 8;
1242
1308
        }
1243
 
 
 
1309
        
1244
1310
        /* draw LOCK */
1245
1311
        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");
1246
1312