Welcome to mirror list, hosted at ThFree Co, Russian Federation.

info_header.c « space_info « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa6aadd00bc088d0ecc3a339119cc417b434928c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/**
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2008 Blender Foundation.
 * All rights reserved.
 *
 * 
 * Contributor(s): Blender Foundation
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#include <string.h>
#include <stdio.h>

#include "DNA_packedFile_types.h"
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"

#include "MEM_guardedalloc.h"

#include "BLI_blenlib.h"
#include "BLI_bpath.h"

#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_packedFile.h"
#include "BKE_screen.h"

#include "ED_screen.h"
#include "ED_types.h"
#include "ED_util.h"

#include "WM_api.h"
#include "WM_types.h"

#include "BIF_gl.h"
#include "BIF_glutil.h"

#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"

#include "IMB_imbuf_types.h"

#include "info_intern.h"

static int pupmenu() {return 0;}
static int okee() {return 0;}
static int error() {return 0;}

/* ************************ header area region *********************** */

#define B_STOPRENDER	1
#define B_STOPCAST		2
#define B_STOPANIM		3

static void do_viewmenu(bContext *C, void *arg, int event)
{
}

static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
{
	ScrArea *curarea= CTX_wm_area(C);
	uiBlock *block;
	short yco= 0, menuwidth=120;
	
	block= uiBeginBlock(C, ar, "dummy_viewmenu", UI_EMBOSSP);
	uiBlockSetButmFunc(block, do_viewmenu, NULL);
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
					 menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
	
	if(curarea->headertype==HEADERTOP) {
		uiBlockSetDirection(block, UI_DOWN);
	}
	else {
		uiBlockSetDirection(block, UI_TOP);
		uiBlockFlipOrder(block);
	}
	
	uiTextBoundsBlock(block, 50);
	uiEndBlock(C, block);
	
	return block;
}

static int buttons_do_unpack()
{
	int how;
	char menu[2048];
	char *line = menu;
	int ret_value = 1, count = 0;
	
	count = countPackedFiles();
	
	if(!count) {
		pupmenu("No packed files. Autopack disabled");
		return ret_value;
	}
	if (count == 1)
		line += sprintf(line, "Unpack 1 file%%t");
	else
		line += sprintf(line, "Unpack %d files%%t", count);
	
	line += sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
	line += sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
	line += sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
	line += sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
	line += sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
	line += sprintf(line, "|Ask for each file %%x%d", PF_ASK);
	
	how = pupmenu(menu);
	
	if(how == -1)
		ret_value = 0;
	else {
		if (how != PF_KEEP) unpackAll(how);
		G.fileflags &= ~G_AUTOPACK;
 	}
 	
	return ret_value;
}

static void check_packAll()
{
	// first check for dirty images
	Image *ima;
	
	for(ima = G.main->image.first; ima; ima= ima->id.next) {
		if (ima->ibufs.first) { /* XXX FIX */
			ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
			
			if (ibuf && (ibuf->userflags &= IB_BITMAPDIRTY))
				break;
		}
	}

	if (ima == NULL || okee("Some images are painted on. These changes will be lost. Continue ?")) {
		packAll();
		G.fileflags |= G_AUTOPACK;
	}
}

static void do_info_externalfiles(bContext *C, void *arg, int event)
{
	switch (event) {
		
		case 1: /* pack data */
			check_packAll();
			break;
		case 3: /* unpack data */
			if (buttons_do_unpack() != 0) {
				/* Clear autopack bit only if user selected one of the unpack options */
				G.fileflags &= ~G_AUTOPACK;
			}
			break;
		case 10: /* make all paths relative */
			if (G.relbase_valid) {
				int tot,changed,failed,linked;
				char str[512];
				char txtname[24]; /* text block name */
				txtname[0] = '\0';
				makeFilesRelative(txtname, &tot, &changed, &failed, &linked);
				if (failed) sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
				else		sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
				pupmenu(str);
			} else {
				pupmenu("Can't set relative paths with an unsaved blend file");
			}
			break;
		case 11: /* make all paths absolute */
		{
			int tot,changed,failed,linked;
			char str[512];
			char txtname[24]; /* text block name */
			txtname[0] = '\0';
			makeFilesAbsolute(txtname, &tot, &changed, &failed, &linked);
			sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
			if (failed) sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
			else		sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
			
			pupmenu(str);
		}
			break;
		case 12: /* check images exist */
		{
			char txtname[24]; /* text block name */
			txtname[0] = '\0';
			
			/* run the missing file check */
			checkMissingFiles( txtname );
			
			if (txtname[0] == '\0') {
				okee("No external files missing");
			} else {
				char str[128];
				sprintf(str, "Missing files listed in Text \"%s\"", txtname );
				error(str);
			}
		}
			break;
		case 13: /* search for referenced files that are not available  */
// XXX			if(curarea->spacetype==SPACE_INFO) {
//				ScrArea *sa;
//				sa= closest_bigger_area();
//				areawinset(sa->win);
//			}
//			activate_fileselect(FILE_SPECIAL, "Find Missing Files", "", findMissingFiles);
			break;
	}
	
}


uiBlock *info_externalfiles(bContext *C, ARegion *ar, void *arg_unused)
{
	uiBlock *block;
	short yco = 20, menuwidth = 120;
	
	block= uiBeginBlock(C, ar, "info_externalfiles", UI_EMBOSSP);
	uiBlockSetButmFunc(block, do_info_externalfiles, NULL);
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack into .blend file",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack into Files...",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
	
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Relative",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Absolute",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Report Missing Files...",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Missing Files...",				0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, "");
	
	uiBlockSetDirection(block, UI_RIGHT);
	uiTextBoundsBlock(block, 60);
	return block;
}



static void info_filemenu(bContext *C, uiLayout *layout, void *arg_unused)
{
	
	uiLayoutContext(layout, WM_OP_EXEC_AREA);
	uiItemO(layout, NULL, 0, "WM_OT_read_homefile"); 
	uiLayoutContext(layout, WM_OP_INVOKE_AREA);
	uiItemO(layout, NULL, 0, "WM_OT_open_mainfile"); 
//	uiDefIconTextBlockBut(block, info_openrecentmenu, NULL, ICON_RIGHTARROW_THIN, "Open Recent",0, yco-=20, 120, 19, "");
//	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",				0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
	
	uiItemS(layout);
	
	uiLayoutContext(layout, WM_OP_EXEC_AREA);
	uiItemO(layout, NULL, 0, "WM_OT_save_mainfile"); 
	uiLayoutContext(layout, WM_OP_INVOKE_AREA);
	uiItemO(layout, NULL, 0, "WM_OT_save_as_mainfile"); 

#if 0
	if(U.flag & USER_FILECOMPRESS) {
		uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Compress File",	 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
	} else {
		uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Compress File",	 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
	}
	
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Rendered Image...|F3",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot Subwindow|Ctrl F3",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot All|Ctrl Shift F3",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
#if GAMEBLENDER == 1
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Game As Runtime...",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
#endif
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Load Factory Settings",				0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 32, "");
	
	
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append or Link|Shift F1",	0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append or Link (Image Browser)|Ctrl F1",	0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
//	uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
//	uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
	
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBlockBut(block, info_externalfiles, NULL, ICON_RIGHTARROW_THIN, "External Data",0, yco-=20, 120, 19, "");
	
	uiDefBut(block, SEPR, 0, "",					0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
	
	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Quit Blender|Ctrl Q",				0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
	uiBlockSetDirection(block, UI_DOWN);
	uiTextBoundsBlock(block, 80);
	
	uiEndBlock(C, block);
	return block;
#endif
}


static void do_info_buttons(bContext *C, void *arg, int event)
{
	switch(event) {
		case B_STOPRENDER:
			G.afbreek= 1;
			break;
		case B_STOPCAST:
			WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C));
			break;
		case B_STOPANIM:
			ED_screen_animation_timer(C, 0, 0);
			break;
	}
}

static void screen_idpoin_handle(bContext *C, ID *id, int event)
{
	switch(event) {
		case UI_ID_BROWSE:
			/* exception: can't set screens inside of area/region handers */
			WM_event_add_notifier(C, NC_SCREEN|ND_SCREENBROWSE, id);
			break;
		case UI_ID_DELETE:
			ED_undo_push(C, "");
			break;
		case UI_ID_RENAME:
			break;
		case UI_ID_ADD_NEW:
			/* XXX not implemented */
			break;
		case UI_ID_OPEN:
			/* XXX not implemented */
			break;
		case UI_ID_ALONE:
			/* XXX not implemented */
			break;
		case UI_ID_PIN:
			break;
	}
}

static void scene_idpoin_handle(bContext *C, ID *id, int event)
{
	switch(event) {
		case UI_ID_BROWSE:
			/* exception: can't set screens inside of area/region handers */
			WM_event_add_notifier(C, NC_SCENE|ND_SCENEBROWSE, id);
			break;
		case UI_ID_DELETE:
			ED_undo_push(C, "");
			break;
		case UI_ID_RENAME:
			break;
		case UI_ID_ADD_NEW:
			/* XXX not implemented */
			break;
		case UI_ID_OPEN:
			/* XXX not implemented */
			break;
		case UI_ID_ALONE:
			/* XXX not implemented */
			break;
		case UI_ID_PIN:
			break;
	}
}


void info_header_buttons(const bContext *C, ARegion *ar)
{
	wmWindow *win= CTX_wm_window(C);
	bScreen *screen= CTX_wm_screen(C);
	ScrArea *sa= CTX_wm_area(C);
	uiBlock *block;
	int xco, yco= 3;
	
	block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
	uiBlockSetHandleFunc(block, do_info_buttons, NULL);
	
	xco= ED_area_header_standardbuttons(C, block, yco);
	
	if((sa->flag & HEADER_NO_PULLDOWN)==0) {
		int xmax;
		
		xmax= GetButStringLength("File");
		uiDefMenuBut(block, info_filemenu, NULL, "File", xco, yco, xmax-3, 20, "");
		xco+= xmax;
		
		xmax= GetButStringLength("Add");
		uiDefPulldownBut(block, dummy_viewmenu, sa, "Add",	xco, yco, xmax-3, 20, "");
		xco+= xmax;
		
		xmax= GetButStringLength("Timeline");
		uiDefPulldownBut(block, dummy_viewmenu, sa, "Timeline",	xco, yco, xmax-3, 20, "");
		xco+= xmax;
		
		xmax= GetButStringLength("Game");
		uiDefPulldownBut(block, dummy_viewmenu, sa, "Game",	xco, yco, xmax-3, 20, "");
		xco+= xmax;
		
		xmax= GetButStringLength("Render");
		uiDefPulldownBut(block, dummy_viewmenu, sa, "Render",	xco, yco, xmax-3, 20, "");
		xco+= xmax;
		
		xmax= GetButStringLength("Help");
		uiDefPulldownBut(block, dummy_viewmenu, NULL, "Help",	xco, yco, xmax-3, 20, "");
		xco+= xmax;
	}
	
	uiBlockSetEmboss(block, UI_EMBOSS);
	
	if(screen->full==0) {
		xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)win->screen, ID_SCR, NULL, xco, yco,
						 screen_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
		xco += 8;
		xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)screen->scene, ID_SCE, NULL, xco, yco,
							 scene_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
		xco += 8;
	}	

	if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) {
		uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", xco+5,yco,75,19, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
		xco+= 80;
	}
	if(WM_jobs_test(CTX_wm_manager(C), CTX_wm_screen(C))) {
		uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_REC, "Capture", xco+5,yco,85,19, NULL, 0.0f, 0.0f, 0, 0, "Stop screencast");
		xco+= 90;
	}
	if(screen->animtimer) {
		uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_REC, "Anim Player", xco+5,yco,85,19, NULL, 0.0f, 0.0f, 0, 0, "Stop animation playback");
		xco+= 90;
	}
	
	/* always as last  */
	UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
	
	uiEndBlock(C, block);
	uiDrawBlock(C, block);
}