Fix for bug #8746: the fake user button for datablocks was not a toggle
[plumiferos.git] / source / blender / src / headerbuttons.c
blobb771be71d18f80d376c01159c3188c6d6d3af2e4
1 /**
2 * $Id: headerbuttons.c 10757 2007-05-22 14:20:18Z campbellbarton $
4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
12 * about this.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
33 #include <stdlib.h>
34 #include <string.h>
35 #include <math.h>
37 #include <sys/types.h>
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
43 #include "MEM_guardedalloc.h"
45 #include "BMF_Api.h"
46 #include "BIF_language.h"
47 #ifdef INTERNATIONAL
48 #include "FTF_Api.h"
49 #endif
51 #include "BLI_blenlib.h"
52 #include "BLI_arithb.h"
53 #include "BLI_storage_types.h"
55 #include "IMB_imbuf_types.h"
56 #include "IMB_imbuf.h"
58 #include "DNA_ID.h"
59 #include "DNA_action_types.h"
60 #include "DNA_armature_types.h"
61 #include "DNA_brush_types.h"
62 #include "DNA_camera_types.h"
63 #include "DNA_curve_types.h"
64 #include "DNA_group_types.h"
65 #include "DNA_image_types.h"
66 #include "DNA_ipo_types.h"
67 #include "DNA_key_types.h"
68 #include "DNA_lamp_types.h"
69 #include "DNA_lattice_types.h"
70 #include "DNA_material_types.h"
71 #include "DNA_mesh_types.h"
72 #include "DNA_meta_types.h"
73 #include "DNA_object_types.h"
74 #include "DNA_oops_types.h"
75 #include "DNA_packedFile_types.h"
76 #include "DNA_scene_types.h"
77 #include "DNA_screen_types.h"
78 #include "DNA_sequence_types.h"
79 #include "DNA_sound_types.h"
80 #include "DNA_space_types.h"
81 #include "DNA_texture_types.h"
82 #include "DNA_text_types.h"
83 #include "DNA_userdef_types.h"
84 #include "DNA_view2d_types.h"
85 #include "DNA_view3d_types.h"
86 #include "DNA_world_types.h"
87 #include "DNA_constraint_types.h"
89 #include "BKE_utildefines.h"
91 #include "BKE_action.h"
92 #include "BKE_armature.h"
93 #include "BKE_blender.h"
94 #include "BKE_brush.h"
95 #include "BKE_constraint.h"
96 #include "BKE_curve.h"
97 #include "BKE_depsgraph.h"
98 #include "BKE_exotic.h"
99 #include "BKE_global.h"
100 #include "BKE_image.h"
101 #include "BKE_ipo.h"
102 #include "BKE_key.h"
103 #include "BKE_lattice.h"
104 #include "BKE_library.h"
105 #include "BKE_main.h"
106 #include "BKE_material.h"
107 #include "BKE_mball.h"
108 #include "BKE_mesh.h"
109 #include "BKE_node.h"
110 #include "BKE_object.h"
111 #include "BKE_packedFile.h"
112 #include "BKE_sca.h"
113 #include "BKE_scene.h"
114 #include "BKE_texture.h"
115 #include "BKE_text.h"
116 #include "BKE_world.h"
118 #include "BLO_readfile.h"
119 #include "BLO_writefile.h"
121 #include "BIF_drawimage.h"
122 #include "BIF_drawoops.h"
123 #include "BIF_drawscene.h"
124 #include "BIF_drawtext.h"
125 #include "BIF_editaction.h"
126 #include "BIF_editarmature.h"
127 #include "BIF_editfont.h"
128 #include "BIF_editlattice.h"
129 #include "BIF_editconstraint.h"
130 #include "BIF_editmesh.h"
131 #include "BIF_editmesh.h"
132 #include "BIF_editsima.h"
133 #include "BIF_editsound.h"
134 #include "BIF_gl.h"
135 #include "BIF_imasel.h"
136 #include "BIF_interface.h"
137 #include "BIF_mainqueue.h"
138 #include "BIF_mywindow.h"
139 #include "BIF_poseobject.h"
140 #include "BIF_renderwin.h"
141 #include "BIF_resources.h"
142 #include "BIF_screen.h"
143 #include "BIF_space.h"
144 #include "BIF_toets.h"
145 #include "BIF_toolbox.h"
146 #include "BIF_usiblender.h"
147 #include "BIF_previewrender.h"
148 #include "BIF_writeimage.h"
149 #include "BIF_butspace.h"
151 #include "BPI_script.h"
153 #include "BSE_edit.h"
154 #include "BSE_filesel.h"
155 #include "BSE_headerbuttons.h"
156 #include "BSE_node.h"
157 #include "BSE_view.h"
158 #include "BSE_sequence.h"
159 #include "BSE_editipo.h"
160 #include "BSE_drawipo.h"
162 #include "BDR_drawmesh.h"
163 #include "BDR_vpaint.h"
164 #include "BDR_editface.h"
165 #include "BDR_editobject.h"
166 #include "BDR_editcurve.h"
167 #include "BDR_editmball.h"
168 #include "BDR_sculptmode.h"
170 #include "BPY_extern.h"
171 #include "BPY_menus.h"
173 #include "mydevice.h"
174 #include "blendef.h"
175 #include "interface.h"
176 #include "nla.h" /* __NLA : To be removed later */
177 #include "butspace.h" // test_idbutton
179 #include "BIF_poseobject.h"
181 #include "SYS_System.h"
183 /* WATCH IT: always give all headerbuttons for same window the same name
184 * event B_REDR is a standard redraw
188 char *windowtype_pup(void)
190 return(
191 "Window type:%t" //14
192 "|3D View %x1" //30
194 "|%l" // 33
196 "|Ipo Curve Editor %x2" //54
197 "|Action Editor %x12" //73
198 "|NLA Editor %x13" //94
200 "|%l" //97
202 "|UV/Image Editor %x6" //117
204 "|Video Sequence Editor %x8" //143
205 "|Timeline %x15" //163
206 "|Audio Window %x11" //163
207 "|Text Editor %x9" //179
209 "|%l" //192
212 "|User Preferences %x7" //213
213 "|Outliner %x3" //232
214 "|Buttons Window %x4" //251
215 "|Node Editor %x16"
216 "|%l" //254
218 "|Image Browser %x10" //273
219 "|File Browser %x5" //290
221 "|%l" //293
223 "|Scripts Window %x14"//313
227 int GetButStringLength(char *str) {
228 int rt;
230 rt= BIF_GetStringWidth(G.font, str, (U.transopts & USER_TR_BUTTONS));
232 return rt + 15;
235 /* ********************** GLOBAL ****************************** */
237 int std_libbuttons(uiBlock *block, short xco, short yco,
238 int pin, short *pinpoin, int browse, short id_code, short special, ID *id,
239 ID *parid, short *menupoin, int users, int lib,
240 int del, int autobut, int keepbut)
242 ListBase *lb;
243 uiBut *but;
244 int len, oldcol, add_addbutton=0;
245 char *str=NULL, str1[10];
247 uiBlockBeginAlign(block);
248 oldcol= uiBlockGetCol(block);
250 if(id && pin) {
251 uiDefIconButS(block, ICONTOG, pin, ICON_PIN_DEHLT, xco,yco,XIC,YIC, pinpoin, 0, 0, 0, 0, "Keeps this view displaying the current data regardless of what object is selected");
252 xco+= XIC;
254 /* browse menu */
255 if(browse) {
256 char *extrastr= NULL;
258 if(ELEM3(id_code, ID_MA, ID_TE, ID_BR)) add_addbutton= 1;
260 lb= wich_libbase(G.main, id_code);
262 if(id && id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
264 if (pin && *pinpoin) {
265 uiBlockSetCol(block, TH_BUT_SETTING2);
268 if ELEM8( id_code, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC, ID_BR) extrastr= "ADD NEW %x 32767";
269 else if (id_code==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
270 else if (id_code==ID_SO) extrastr= "OPEN NEW %x 32766";
272 uiSetButLock(G.scene->id.lib!=0, ERROR_LIBDATA_MESSAGE);
273 if( id_code==ID_SCE || id_code==ID_SCR ) uiClearButLock();
275 if(curarea->spacetype==SPACE_BUTS)
276 uiSetButLock(id_code!=ID_SCR && G.obedit!=0 && G.buts->mainb==CONTEXT_EDITING, "Cannot perform in EditMode");
278 if(parid) uiSetButLock(parid->lib!=0, ERROR_LIBDATA_MESSAGE);
280 if (lb) {
281 if( id_code==ID_IP)
282 IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
283 else if(browse!=B_SIMABROWSE && id_code==ID_IM )
284 IMAnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
285 else
286 IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
289 uiDefButS(block, MENU, browse, str, xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses existing choices or adds NEW");
290 xco+= XIC;
292 uiClearButLock();
294 MEM_freeN(str);
297 uiBlockSetCol(block, oldcol);
299 if(id) { /* text button with name */
301 /* name */
302 if(id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
303 /* Pinned data ? */
304 if (pin && *pinpoin) {
305 uiBlockSetCol(block, TH_BUT_SETTING2);
307 /* Redalert overrides pin color */
308 if(id->us<=0) uiBlockSetCol(block, TH_REDALERT);
310 uiSetButLock(id->lib!=0, ERROR_LIBDATA_MESSAGE);
312 if(GS(id->name)==ID_SCE) strcpy(str1, "SCE:");
313 else if(GS(id->name)==ID_SCE) strcpy(str1, "SCR:");
314 else if(GS(id->name)==ID_MA) {
315 if( ((Material *)id)->use_nodes )
316 strcpy(str1, "NT:");
317 else
318 strcpy(str1, "MA:");
320 else {
321 str1[0]= id->name[0];
322 str1[1]= id->name[1];
323 str1[2]= ':';
324 str1[3]= 0;
327 if( GS(id->name)==ID_IP) len= 110;
328 else if(yco) len= 140; // comes from button panel
329 else len= 120;
331 but= uiDefBut(block, TEX, B_IDNAME, str1,xco, yco, (short)len, YIC, id->name+2, 0.0, 21.0, 0, 0, "Displays current Datablock name. Click to change.");
332 uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
334 uiClearButLock();
336 xco+= len;
338 if(id->lib) {
340 if(id->flag & LIB_INDIRECT) uiDefIconBut(block, BUT, 0, ICON_DATALIB,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Indirect Library Datablock. Cannot change.");
341 else uiDefIconBut(block, BUT, lib, ICON_PARLIB, xco,yco,XIC,YIC, 0, 0, 0, 0, 0,
342 lib?"Direct linked Library Datablock. Click to make local.":"Direct linked Library Datablock, cannot make local."
345 xco+= XIC;
349 if(users && id->us>1) {
350 uiSetButLock (pin && *pinpoin, "Can't make pinned data single-user");
352 sprintf(str1, "%d", id->us);
353 if(id->us<10) {
355 uiDefBut(block, BUT, users, str1, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
356 xco+= XIC;
358 else {
359 uiDefBut(block, BUT, users, str1, xco, yco, XIC+10, YIC, 0, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy.");
360 xco+= XIC+10;
363 uiClearButLock();
367 if(del) {
369 uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
370 if(parid && parid->lib);
371 else {
372 uiDefIconBut(block, BUT, del, ICON_X, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes link to this Datablock");
373 xco+= XIC;
376 uiClearButLock();
379 if(autobut) {
380 if(parid && parid->lib);
381 else {
382 uiDefIconBut(block, BUT, autobut, ICON_AUTO,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Generates an automatic name");
383 xco+= XIC;
388 if(keepbut) {
389 uiDefButBitS(block, TOG, LIB_FAKEUSER, keepbut, "F", xco,yco,XIC,YIC, &id->flag, 0, 0, 0, 0, "Saves this datablock even if it has no users");
390 xco+= XIC;
393 else if(add_addbutton) { /* "add new" button */
394 uiBlockSetCol(block, oldcol);
395 uiDefButS(block, TOG, browse, "Add New" ,xco, yco, 110, YIC, menupoin, (float)*menupoin, 32767.0, 0, 0, "Add new data block");
396 xco+= 110;
398 //xco+=XIC;
400 uiBlockSetCol(block, oldcol);
401 uiBlockEndAlign(block);
403 return xco;
407 /* results in fully updated anim system */
408 static void do_update_for_newframe(int mute, int events)
410 extern void audiostream_scrub(unsigned int frame); /* seqaudio.c */
412 if(events) {
413 allqueue(REDRAWALL, 0);
416 /* this function applies the changes too */
417 scene_update_for_newframe(G.scene, screen_view3d_layers()); /* BKE_scene.h */
419 if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB))
420 audiostream_scrub( CFRA );
422 /* 3d window, preview */
423 BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
425 /* all movie/sequence images */
426 BIF_image_update_frame();
428 /* composite */
429 if(G.scene->use_nodes && G.scene->nodetree)
430 ntreeCompositTagAnimated(G.scene->nodetree);
433 void update_for_newframe(void)
435 do_update_for_newframe(0, 1);
438 void update_for_newframe_muted(void)
440 do_update_for_newframe(1, 1);
443 /* used by new animated UI playback */
444 void update_for_newframe_nodraw(int nosound)
446 do_update_for_newframe(nosound, 0);
450 static void show_splash(void)
452 extern char datatoc_splash_jpg[];
453 extern int datatoc_splash_jpg_size;
454 char *string = NULL;
456 #ifdef NAN_BUILDINFO
457 char buffer[1024];
458 extern char * build_date;
459 extern char * build_time;
460 extern char * build_rev;
461 extern char * build_platform;
462 extern char * build_type;
464 string = &buffer[0];
465 sprintf(string,"Built on %s %s, Rev-%s Version %s %s", build_date, build_time, build_rev, build_platform, build_type);
466 #endif
468 splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
472 /* Functions for user preferences fileselect windows */
474 /* yafray: export dir select */
475 static void filesel_u_yfexportdir(char *name)
477 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
479 BLI_cleanup_dir(G.sce, name);
480 BLI_split_dirfile(name, dir, file);
482 strcpy(U.yfexportdir, dir);
483 allqueue(REDRAWALL, 0);
486 static void filesel_u_fontdir(char *name)
488 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
490 BLI_cleanup_dir(G.sce, name);
491 BLI_split_dirfile(name, dir, file);
493 strcpy(U.fontdir, dir);
494 allqueue(REDRAWALL, 0);
497 static void filesel_u_textudir(char *name)
499 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
501 BLI_cleanup_dir(G.sce, name);
502 BLI_split_dirfile(name, dir, file);
504 strcpy(U.textudir, dir);
505 allqueue(REDRAWALL, 0);
508 static void filesel_u_plugtexdir(char *name)
510 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
512 BLI_cleanup_dir(G.sce, name);
513 BLI_split_dirfile(name, dir, file);
515 strcpy(U.plugtexdir, dir);
516 allqueue(REDRAWALL, 0);
519 static void filesel_u_plugseqdir(char *name)
521 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
523 BLI_cleanup_dir(G.sce, name);
524 BLI_split_dirfile(name, dir, file);
526 strcpy(U.plugseqdir, dir);
527 allqueue(REDRAWALL, 0);
530 static void filesel_u_renderdir(char *name)
532 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
534 BLI_cleanup_dir(G.sce, name);
535 BLI_split_dirfile(name, dir, file);
537 strcpy(U.renderdir, dir);
538 allqueue(REDRAWALL, 0);
541 static void filesel_u_pythondir(char *name)
543 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
545 BLI_cleanup_dir(G.sce, name);
546 BLI_split_dirfile(name, dir, file);
548 strcpy(U.pythondir, dir);
549 allqueue(REDRAWALL, 0);
552 static void filesel_u_sounddir(char *name)
554 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
556 BLI_cleanup_dir(G.sce, name);
557 BLI_split_dirfile(name, dir, file);
559 strcpy(U.sounddir, dir);
560 allqueue(REDRAWALL, 0);
563 static void filesel_u_tempdir(char *name)
565 char dir[FILE_MAXDIR], file[FILE_MAXFILE];
567 BLI_cleanup_dir(G.sce, name);
568 BLI_split_dirfile(name, dir, file);
570 strcpy(U.tempdir, dir);
571 allqueue(REDRAWALL, 0);
574 /* END Functions for user preferences fileselect windows */
577 void do_global_buttons(unsigned short event)
579 ListBase *lb;
580 Object *ob;
581 Material *ma;
582 MTex *mtex;
583 Ipo *ipo;
584 Lamp *la;
585 World *wrld;
586 bAction *act;
587 ID *id, *idtest, *from=NULL;
588 ScrArea *sa;
589 Brush *br;
590 int nr= 1;
592 ob= OBACT;
594 id= NULL; /* id at null for texbrowse */
597 switch(event) {
599 case B_NEWFRAME:
600 scrarea_queue_winredraw(curarea);
601 scrarea_queue_headredraw(curarea);
603 update_for_newframe();
604 break;
605 case B_REDR:
606 scrarea_queue_winredraw(curarea);
607 scrarea_queue_headredraw(curarea);
608 break;
609 case B_REDRCURW3D:
610 allqueue(REDRAWVIEW3D, 0);
611 scrarea_queue_winredraw(curarea);
612 scrarea_queue_headredraw(curarea);
613 break;
614 case B_EDITBROWSE:
615 if(ob==NULL) return;
616 if(ob->id.lib) return;
617 id= ob->data;
618 if(id==NULL) return;
620 if(G.buts->menunr== -2) {
621 activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
622 return;
624 if(G.buts->menunr < 0) return;
626 lb= wich_libbase(G.main, GS(id->name));
627 idtest= lb->first;
628 while(idtest) {
629 if(nr==G.buts->menunr) {
630 if(idtest!=id) {
631 id->us--;
632 id_us_plus(idtest);
634 ob->data= idtest;
636 test_object_materials(idtest);
638 if( GS(idtest->name)==ID_CU ) {
639 test_curve_type(ob);
641 else if( ob->type==OB_ARMATURE) {
642 armature_rebuild_pose(ob, ob->data);
644 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
646 allqueue(REDRAWBUTSEDIT, 0);
647 allqueue(REDRAWVIEW3D, 0);
648 allqueue(REDRAWACTION,0);
649 allqueue(REDRAWIPO, 0);
650 allqueue(REDRAWNLA,0);
652 break;
654 nr++;
655 idtest= idtest->next;
658 break;
659 case B_MESHBROWSE:
660 if(ob==0) return;
661 if(ob->id.lib) return;
663 id= ob->data;
664 if(id==0) id= G.main->mesh.first;
665 if(id==0) return;
667 if(G.buts->menunr== -2) {
668 activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
669 return;
671 if(G.buts->menunr < 0) return;
674 idtest= G.main->mesh.first;
675 while(idtest) {
676 if(nr==G.buts->menunr) {
677 set_mesh(ob, (Mesh *)idtest);
679 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
681 BIF_undo_push("Browse Mesh");
682 allqueue(REDRAWBUTSEDIT, 0);
683 allqueue(REDRAWVIEW3D, 0);
684 allqueue(REDRAWACTION,0);
685 allqueue(REDRAWIPO, 0);
687 break;
689 nr++;
690 idtest= idtest->next;
693 break;
694 case B_MATBROWSE:
696 void *lockpoin= NULL;
697 short *menunr= 0;
699 /* this is called now from Node editor too, buttons might not exist */
700 if(curarea->spacetype==SPACE_NODE) {
701 SpaceNode *snode= curarea->spacedata.first;
702 menunr= &snode->menunr;
703 lockpoin= snode->id;
705 else if(G.buts) {
706 menunr= &G.buts->menunr;
707 lockpoin= G.buts->lockpoin;
709 else return;
711 if(*menunr== -2) {
712 activate_databrowse((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
713 return;
716 if(*menunr < 0) return;
718 if(0) { /* future pin */
721 else {
723 ma= give_current_material(ob, ob->actcol);
724 nr= 1;
726 id= (ID *)ma;
728 idtest= G.main->mat.first;
729 while(idtest) {
730 if(nr== *menunr) {
731 break;
733 nr++;
734 idtest= idtest->next;
736 if(idtest==0) { /* new mat */
737 if(id) idtest= (ID *)copy_material((Material *)id);
738 else {
739 idtest= (ID *)add_material("Material");
741 idtest->us--;
743 if(idtest!=id) {
744 assign_material(ob, (Material *)idtest, ob->actcol);
746 BIF_undo_push("Browse Material");
747 allqueue(REDRAWBUTSSHADING, 0);
748 allqueue(REDRAWIPO, 0);
749 allqueue(REDRAWNODE, 0);
750 BIF_preview_changed(ID_MA);
755 break;
756 case B_MATDELETE:
757 if(0) { /* future pin */
760 else {
761 ma= give_current_material(ob, ob->actcol);
762 if(ma) {
763 assign_material(ob, 0, ob->actcol);
764 BIF_undo_push("Unlink Material");
765 allqueue(REDRAWBUTSSHADING, 0);
766 allqueue(REDRAWIPO, 0);
767 allqueue(REDRAWOOPS, 0);
768 allqueue(REDRAWVIEW3D, 0);
769 BIF_preview_changed(ID_MA);
772 break;
773 case B_TEXDELETE:
774 if(G.buts->pin) {
777 else {
778 if(G.buts->texfrom==0) { /* from mat */
779 ma= give_current_material(ob, ob->actcol);
780 ma= editnode_get_active_material(ma);
781 if(ma) {
782 mtex= ma->mtex[ ma->texact ];
783 if(mtex) {
784 if(mtex->tex) mtex->tex->id.us--;
785 MEM_freeN(mtex);
786 ma->mtex[ ma->texact ]= NULL;
787 allqueue(REDRAWBUTSSHADING, 0);
788 allqueue(REDRAWIPO, 0);
789 BIF_preview_changed(ID_MA);
793 else if(G.buts->texfrom==1) { /* from world */
794 wrld= G.scene->world;
795 if(wrld) {
796 mtex= wrld->mtex[ wrld->texact ];
797 if(mtex) {
798 if(mtex->tex) mtex->tex->id.us--;
799 MEM_freeN(mtex);
800 wrld->mtex[ wrld->texact ]= NULL;
801 allqueue(REDRAWBUTSSHADING, 0);
802 allqueue(REDRAWIPO, 0);
803 BIF_preview_changed(ID_WO);
807 else if(G.buts->texfrom==2) { /* from lamp */
808 la= ob->data;
809 if(la && ob->type==OB_LAMP) { /* to be sure */
810 mtex= la->mtex[ la->texact ];
811 if(mtex) {
812 if(mtex->tex) mtex->tex->id.us--;
813 MEM_freeN(mtex);
814 la->mtex[ la->texact ]= NULL;
815 allqueue(REDRAWBUTSSHADING, 0);
816 allqueue(REDRAWIPO, 0);
817 BIF_preview_changed(ID_LA);
821 else { /* from brush */
822 br= G.scene->toolsettings->imapaint.brush;
823 if(G.f & G_SCULPTMODE) {
824 sculptmode_rem_tex(NULL, NULL);
825 allqueue(REDRAWBUTSSHADING, 0);
826 } else if(br) {
827 mtex= br->mtex[ br->texact ];
828 if(mtex) {
829 if(mtex->tex) mtex->tex->id.us--;
830 MEM_freeN(mtex);
831 br->mtex[ br->texact ]= NULL;
832 allqueue(REDRAWBUTSSHADING, 0);
833 allqueue(REDRAWIMAGE, 0);
834 allqueue(REDRAWIPO, 0);
835 /*BIF_preview_changed(ID_BR);*/
839 BIF_undo_push("Unlink Texture");
841 break;
842 case B_EXTEXBROWSE:
843 case B_TEXBROWSE:
845 if(G.buts->texnr== -2) {
847 id= G.buts->lockpoin;
848 if(event==B_EXTEXBROWSE) {
849 id= NULL;
850 ma= give_current_material(ob, ob->actcol);
851 ma= editnode_get_active_material(ma);
852 if(ma) {
853 mtex= ma->mtex[ ma->texact ];
854 if(mtex) id= (ID *)mtex->tex;
858 activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
859 return;
861 if(G.buts->texnr < 0) break;
863 if(G.buts->pin) {
866 else {
867 id= NULL;
869 ma= give_current_material(ob, ob->actcol);
870 ma= editnode_get_active_material(ma);
871 if(ma) {
872 mtex= ma->mtex[ ma->texact ];
873 if(mtex) id= (ID *)mtex->tex;
876 idtest= G.main->tex.first;
877 while(idtest) {
878 if(nr==G.buts->texnr) {
879 break;
881 nr++;
882 idtest= idtest->next;
884 if(idtest==0) { /* new tex */
885 if(id) idtest= (ID *)copy_texture((Tex *)id);
886 else idtest= (ID *)add_texture("Tex");
887 idtest->us--;
889 if(idtest!=id && ma) {
891 if( ma->mtex[ma->texact]==0) ma->mtex[ma->texact]= add_mtex();
893 ma->mtex[ ma->texact ]->tex= (Tex *)idtest;
894 id_us_plus(idtest);
895 if(id) id->us--;
897 BIF_undo_push("Browse Texture");
898 allqueue(REDRAWBUTSSHADING, 0);
899 allqueue(REDRAWIPO, 0);
900 allqueue(REDRAWOOPS, 0);
901 BIF_preview_changed(ID_MA);
904 break;
905 case B_ACTIONDELETE:
906 act=ob->action;
908 if (act)
909 act->id.us--;
910 ob->action=NULL;
911 if(ob->pose) { // clear flag, also used for draw colors
912 bPoseChannel *pchan;
913 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
914 pchan->flag= 0;
916 BIF_undo_push("Unlink Action");
918 allqueue(REDRAWVIEW3D, 0);
919 allqueue(REDRAWACTION, 0);
920 allqueue(REDRAWNLA, 0);
921 allqueue(REDRAWIPO, 0);
922 break;
923 case B_ACTIONBROWSE:
924 if (!ob)
925 break;
926 act=ob->action;
927 id= (ID *)act;
929 if (G.saction->actnr== -2){
930 activate_databrowse((ID *)G.saction->action, ID_AC, 0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
931 return;
934 if(G.saction->actnr < 0) break;
936 /* See if we have selected a valid action */
937 for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
938 if(nr==G.saction->actnr) {
939 break;
941 nr++;
945 if(G.saction->pin) {
946 G.saction->action= (bAction *)idtest;
947 allqueue(REDRAWACTION, 0);
949 else {
951 /* Store current action */
952 if (!idtest){
953 if (act) {
954 idtest= (ID *)copy_action(act);
955 } else {
956 if (ID_OB==ob->type) {
957 idtest=(ID *)add_empty_action("ObAction");
958 } else {
959 idtest=(ID *)add_empty_action("Action");
962 idtest->us--;
966 if(idtest!=id && ob) {
967 act= (bAction *)idtest;
969 ob->action= act;
970 id_us_plus(idtest);
972 if(id) id->us--;
974 // Update everything
975 BIF_undo_push("Browse Action");
976 do_global_buttons (B_NEWFRAME);
977 allqueue(REDRAWVIEW3D, 0);
978 allqueue(REDRAWNLA, 0);
979 allqueue(REDRAWACTION, 0);
980 allqueue(REDRAWHEADERS, 0);
984 break;
985 case B_IPOBROWSE:
987 ipo= G.sipo->ipo;
988 from= G.sipo->from;
989 id= (ID *)ipo;
990 if(from==NULL) return;
992 if(G.sipo->menunr== -2) {
993 activate_databrowse((ID *)G.sipo->ipo, ID_IP, G.sipo->blocktype, B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
994 return;
997 if(G.sipo->menunr < 0) break;
999 idtest= G.main->ipo.first;
1000 while(idtest) {
1001 if( ((Ipo *)idtest)->blocktype == G.sipo->blocktype) {
1002 if(nr==G.sipo->menunr) {
1003 break;
1005 nr++;
1007 idtest= idtest->next;
1010 if(G.sipo->pin) {
1011 if(idtest) {
1012 G.sipo->ipo= (Ipo *)idtest;
1013 allspace(REMAKEIPO, 0); // in fact it should only do this one, but there is no function for it
1016 else {
1017 // assign the ipo to ...
1019 if(idtest==0) {
1020 if(ipo) idtest= (ID *)copy_ipo(ipo);
1021 else {
1022 nr= G.sipo->blocktype;
1023 if(nr==ID_OB) idtest= (ID *)add_ipo("ObIpo", ID_OB);
1024 else if(nr==ID_CO) idtest= (ID *)add_ipo("CoIpo", ID_CO);
1025 else if(nr==ID_PO) idtest= (ID *)add_ipo("ActIpo", nr);
1026 else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
1027 else if(nr==ID_TE) idtest= (ID *)add_ipo("TexIpo", nr);
1028 else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
1029 else if(nr==ID_CU) idtest= (ID *)add_ipo("CuIpo", nr);
1030 else if(nr==ID_KE) idtest= (ID *)add_ipo("KeyIpo", nr);
1031 else if(nr==ID_WO) idtest= (ID *)add_ipo("WoIpo", nr);
1032 else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
1033 else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
1034 else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
1035 else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
1036 else error("Warn bugtracker!");
1038 idtest->us--;
1040 if(idtest!=id && from) {
1041 spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
1043 BIF_undo_push("Browse Ipo");
1046 break;
1047 case B_IPODELETE:
1048 ipo= G.sipo->ipo;
1049 from= G.sipo->from;
1051 spaceipo_assign_ipo(G.sipo, NULL);
1053 editipo_changed(G.sipo, 1); /* doredraw */
1055 BIF_undo_push("Unlink Ipo");
1057 break;
1058 case B_WORLDBROWSE:
1060 if(G.buts->menunr==-2) {
1061 activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1062 break;
1065 if(G.buts->menunr < 0) break;
1066 /* no lock */
1068 wrld= G.scene->world;
1069 nr= 1;
1071 id= (ID *)wrld;
1073 idtest= G.main->world.first;
1074 while(idtest) {
1075 if(nr==G.buts->menunr) {
1076 break;
1078 nr++;
1079 idtest= idtest->next;
1081 if(idtest==0) { /* new world */
1082 if(id) idtest= (ID *)copy_world((World *)id);
1083 else idtest= (ID *)add_world("World");
1084 idtest->us--;
1086 if(idtest!=id) {
1087 G.scene->world= (World *)idtest;
1088 id_us_plus(idtest);
1089 if(id) id->us--;
1091 BIF_undo_push("Browse World");
1092 allqueue(REDRAWBUTSSHADING, 0);
1093 allqueue(REDRAWIPO, 0);
1094 allqueue(REDRAWOOPS, 0);
1095 BIF_preview_changed(ID_WO);
1097 break;
1098 case B_WORLDDELETE:
1099 if(G.scene->world) {
1100 G.scene->world->id.us--;
1101 G.scene->world= NULL;
1103 BIF_undo_push("Unlink World");
1104 allqueue(REDRAWBUTSSHADING, 0);
1105 allqueue(REDRAWIPO, 0);
1108 break;
1109 case B_WTEXBROWSE:
1111 if(G.buts->texnr== -2) {
1112 id= NULL;
1113 wrld= G.scene->world;
1114 if(wrld) {
1115 mtex= wrld->mtex[ wrld->texact ];
1116 if(mtex) id= (ID *)mtex->tex;
1119 activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1120 return;
1122 if(G.buts->texnr < 0) break;
1124 if(G.buts->pin) {
1127 else {
1128 id= NULL;
1130 wrld= G.scene->world;
1131 if(wrld) {
1132 mtex= wrld->mtex[ wrld->texact ];
1133 if(mtex) id= (ID *)mtex->tex;
1136 idtest= G.main->tex.first;
1137 while(idtest) {
1138 if(nr==G.buts->texnr) {
1139 break;
1141 nr++;
1142 idtest= idtest->next;
1144 if(idtest==0) { /* new tex */
1145 if(id) idtest= (ID *)copy_texture((Tex *)id);
1146 else idtest= (ID *)add_texture("Tex");
1147 idtest->us--;
1149 if(idtest!=id && wrld) {
1151 if( wrld->mtex[wrld->texact]==0) {
1152 wrld->mtex[wrld->texact]= add_mtex();
1153 wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1155 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1156 id_us_plus(idtest);
1157 if(id) id->us--;
1159 BIF_undo_push("Texture browse");
1160 allqueue(REDRAWBUTSSHADING, 0);
1161 allqueue(REDRAWIPO, 0);
1162 allqueue(REDRAWOOPS, 0);
1163 BIF_preview_changed(ID_WO);
1166 break;
1167 case B_LAMPBROWSE:
1168 /* no lock */
1169 if(ob==0) return;
1170 if(ob->type!=OB_LAMP) return;
1172 if(G.buts->menunr== -2) {
1173 activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1174 return;
1176 if(G.buts->menunr < 0) break;
1178 la= ob->data;
1179 nr= 1;
1180 id= (ID *)la;
1182 idtest= G.main->lamp.first;
1183 while(idtest) {
1184 if(nr==G.buts->menunr) {
1185 break;
1187 nr++;
1188 idtest= idtest->next;
1190 if(idtest==0) { /* no new lamp */
1191 return;
1193 if(idtest!=id) {
1194 ob->data= (Lamp *)idtest;
1195 id_us_plus(idtest);
1196 if(id) id->us--;
1198 BIF_undo_push("Lamp browse");
1199 allqueue(REDRAWBUTSSHADING, 0);
1200 allqueue(REDRAWVIEW3D, 0);
1201 allqueue(REDRAWIPO, 0);
1202 allqueue(REDRAWOOPS, 0);
1203 BIF_preview_changed(ID_LA);
1205 break;
1207 case B_LTEXBROWSE:
1209 if(ob==0) return;
1210 if(ob->type!=OB_LAMP) return;
1212 if(G.buts->texnr== -2) {
1213 id= NULL;
1214 la= ob->data;
1215 mtex= la->mtex[ la->texact ];
1216 if(mtex) id= (ID *)mtex->tex;
1218 activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1219 return;
1221 if(G.buts->texnr < 0) break;
1223 if(G.buts->pin) {
1226 else {
1227 id= NULL;
1229 la= ob->data;
1230 mtex= la->mtex[ la->texact ];
1231 if(mtex) id= (ID *)mtex->tex;
1233 idtest= G.main->tex.first;
1234 while(idtest) {
1235 if(nr==G.buts->texnr) {
1236 break;
1238 nr++;
1239 idtest= idtest->next;
1241 if(idtest==0) { /* new tex */
1242 if(id) idtest= (ID *)copy_texture((Tex *)id);
1243 else idtest= (ID *)add_texture("Tex");
1244 idtest->us--;
1246 if(idtest!=id && la) {
1248 if( la->mtex[la->texact]==0) {
1249 la->mtex[la->texact]= add_mtex();
1250 la->mtex[la->texact]->texco= TEXCO_GLOB;
1252 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1253 id_us_plus(idtest);
1254 if(id) id->us--;
1256 BIF_undo_push("Texture Browse");
1257 allqueue(REDRAWBUTSSHADING, 0);
1258 allqueue(REDRAWIPO, 0);
1259 allqueue(REDRAWOOPS, 0);
1260 BIF_preview_changed(ID_LA);
1263 break;
1265 case B_IMAGEDELETE:
1267 if(G.sima->image && BLI_streq(G.sima->image->id.name+2, "Render Result")==0) {
1268 /* Run on non render images, unlink normally */
1269 G.sima->image= NULL;
1270 image_changed(G.sima, 0);
1271 BIF_undo_push("Unlink Image");
1272 allqueue(REDRAWIMAGE, 0);
1273 } else {
1274 /* Run if G.sima is render, remove the render and display the meshes image if it exists */
1275 G.sima->image= NULL;
1276 what_image(G.sima);
1277 allqueue(REDRAWIMAGE, 0);
1279 break;
1281 case B_AUTOMATNAME:
1282 /* this is called now from Node editor too, buttons might not exist */
1283 if(curarea->spacetype==SPACE_NODE) {
1284 SpaceNode *snode= curarea->spacedata.first;
1285 automatname((Material *)snode->id);
1287 else if(G.buts) {
1288 automatname(G.buts->lockpoin);
1290 else return;
1292 BIF_undo_push("Auto name");
1293 allqueue(REDRAWBUTSSHADING, 0);
1294 allqueue(REDRAWNODE, 0);
1295 allqueue(REDRAWOOPS, 0);
1296 break;
1297 case B_AUTOTEXNAME:
1298 if(G.buts->mainb==CONTEXT_SHADING) {
1299 if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX) {
1300 autotexname(G.buts->lockpoin);
1302 else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT) {
1303 ma= G.buts->lockpoin;
1304 if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1306 else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD) {
1307 wrld= G.buts->lockpoin;
1308 if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1310 else if(G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP) {
1311 la= G.buts->lockpoin;
1312 if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1314 BIF_undo_push("Auto name");
1315 allqueue(REDRAWBUTSSHADING, 0);
1316 allqueue(REDRAWOOPS, 0);
1317 allqueue(REDRAWIMAGE, 0);
1319 else if(G.buts->mainb==CONTEXT_EDITING) {
1320 SculptData *sd= &G.scene->sculptdata;
1321 if(sd && sd->texact != -1) {
1322 if(sd->mtex[sd->texact]) autotexname(sd->mtex[sd->texact]->tex);
1324 BIF_undo_push("Auto name");
1325 allqueue(REDRAWBUTSEDIT, 0);
1326 allqueue(REDRAWOOPS, 0);
1329 break;
1331 case B_RESETAUTOSAVE:
1332 reset_autosave();
1333 allqueue(REDRAWINFO, 0);
1334 break;
1335 case B_SOUNDTOGGLE:
1336 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USER_DISABLE_SOUND));
1337 break;
1338 case B_SHOWSPLASH:
1339 show_splash();
1340 break;
1341 case B_MIPMAPCHANGED:
1342 set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1343 allqueue(REDRAWVIEW3D, 0);
1344 break;
1345 case B_GLRESLIMITCHANGED:
1346 free_all_realtime_images(); /* force reloading with new res limit */
1347 allqueue(REDRAWVIEW3D, 0);
1348 break;
1349 case B_NEWSPACE:
1350 newspace(curarea, curarea->butspacetype);
1351 break;
1352 case B_LOADTEMP: /* is button from space.c */
1353 BIF_read_autosavefile();
1354 break;
1356 case B_USERPREF:
1357 allqueue(REDRAWINFO, 0);
1358 break;
1360 case B_DRAWINFO: /* is button from space.c *info* */
1361 allqueue(REDRAWVIEW3D, 0);
1362 break;
1364 case B_PLAINMENUS: /* is button from space.c *info* */
1365 reset_toolbox();
1366 break;
1368 case B_FLIPINFOMENU: /* is button from space.c *info* */
1369 scrarea_queue_headredraw(curarea);
1370 break;
1372 #if 0
1373 //#ifdef _WIN32 // FULLSCREEN
1374 case B_FLIPFULLSCREEN:
1375 if(U.uiflag & USER_FLIPFULLSCREEN)
1376 U.uiflag &= ~USER_FLIPFULLSCREEN;
1377 else
1378 U.uiflag |= USER_FLIPFULLSCREEN;
1379 mainwindow_toggle_fullscreen((U.uiflag & USER_FLIPFULLSCREEN));
1380 break;
1381 #endif
1383 /* Fileselect windows for user preferences file paths */
1385 /* yafray: xml export dir. select */
1386 case B_YAFRAYDIRFILESEL: /* space.c */
1387 if(curarea->spacetype==SPACE_INFO) {
1388 sa= closest_bigger_area();
1389 areawinset(sa->win);
1392 activate_fileselect(FILE_SPECIAL, "SELECT YFEXPORT PATH", U.yfexportdir, filesel_u_yfexportdir);
1393 break;
1395 case B_FONTDIRFILESEL: /* is button from space.c *info* */
1396 if(curarea->spacetype==SPACE_INFO) {
1397 sa= closest_bigger_area();
1398 areawinset(sa->win);
1401 activate_fileselect(FILE_SPECIAL, "SELECT FONT PATH", U.fontdir, filesel_u_fontdir);
1402 break;
1404 case B_TEXTUDIRFILESEL: /* is button from space.c *info* */
1405 if(curarea->spacetype==SPACE_INFO) {
1406 sa= closest_bigger_area();
1407 areawinset(sa->win);
1410 activate_fileselect(FILE_SPECIAL, "SELECT TEXTURE PATH", U.textudir, filesel_u_textudir);
1411 break;
1413 case B_PLUGTEXDIRFILESEL: /* is button form space.c *info* */
1414 if(curarea->spacetype==SPACE_INFO) {
1415 sa= closest_bigger_area();
1416 areawinset(sa->win);
1419 activate_fileselect(FILE_SPECIAL, "SELECT TEX PLUGIN PATH", U.plugtexdir, filesel_u_plugtexdir);
1420 break;
1422 case B_PLUGSEQDIRFILESEL: /* is button from space.c *info* */
1423 if(curarea->spacetype==SPACE_INFO) {
1424 sa= closest_bigger_area();
1425 areawinset(sa->win);
1428 activate_fileselect(FILE_SPECIAL, "SELECT SEQ PLUGIN PATH", U.plugseqdir, filesel_u_plugseqdir);
1429 break;
1431 case B_RENDERDIRFILESEL: /* is button from space.c *info* */
1432 if(curarea->spacetype==SPACE_INFO) {
1433 sa= closest_bigger_area();
1434 areawinset(sa->win);
1437 activate_fileselect(FILE_SPECIAL, "SELECT RENDER PATH", U.renderdir, filesel_u_renderdir);
1438 break;
1440 case B_PYMENUEVAL: /* is button from space.c *info* */
1441 waitcursor( 1 ); /* can take some time */
1442 BPyMenu_RemoveAllEntries(); /* free old data */
1443 if (BPyMenu_Init(1) == -1) { /* re-eval scripts registration in menus */
1444 waitcursor( 0 );
1445 error("Invalid scripts dir: check console");
1447 waitcursor( 0 );
1448 break;
1449 case B_PYTHONDIRFILESEL: /* is button from space.c *info* */
1450 if(curarea->spacetype==SPACE_INFO) {
1451 sa= closest_bigger_area();
1452 areawinset(sa->win);
1455 activate_fileselect(FILE_SPECIAL, "SELECT SCRIPT PATH", U.pythondir, filesel_u_pythondir);
1456 break;
1458 case B_SOUNDDIRFILESEL: /* is button from space.c *info* */
1459 if(curarea->spacetype==SPACE_INFO) {
1460 sa= closest_bigger_area();
1461 areawinset(sa->win);
1464 activate_fileselect(FILE_SPECIAL, "SELECT SOUND PATH", U.sounddir, filesel_u_sounddir);
1465 break;
1467 case B_TEMPDIRFILESEL: /* is button from space.c *info* */
1468 if(curarea->spacetype==SPACE_INFO) {
1469 sa= closest_bigger_area();
1470 areawinset(sa->win);
1473 activate_fileselect(FILE_SPECIAL, "SELECT TEMP FILE PATH", U.tempdir, filesel_u_tempdir);
1474 break;
1476 /* END Fileselect windows for user preferences file paths */
1478 #ifdef INTERNATIONAL
1479 case B_LOADUIFONT: /* is button from space.c *info* */
1480 if(curarea->spacetype==SPACE_INFO) {
1481 sa= closest_bigger_area();
1482 areawinset(sa->win);
1484 BLI_make_file_string("/", buf, U.fontdir, U.fontname);
1485 activate_fileselect(FILE_SPECIAL, "LOAD UI FONT", buf, set_interface_font);
1486 break;
1488 case B_SETLANGUAGE: /* is button from space.c *info* */
1489 lang_setlanguage();
1490 allqueue(REDRAWALL, 0);
1491 break;
1493 case B_SETFONTSIZE: /* is button from space.c *info* */
1494 refresh_interface_font();
1495 FTF_SetSize(U.fontsize);
1496 allqueue(REDRAWALL, 0);
1497 break;
1499 case B_SETTRANSBUTS: /* is button from space.c *info* */
1500 allqueue(REDRAWALL, 0);
1501 break;
1503 case B_RESTOREFONT: /* is button from space.c *info* */
1504 U.fontsize= 0;
1505 start_interface_font();
1506 allqueue(REDRAWALL, 0);
1507 break;
1509 case B_USETEXTUREFONT: /* is button from space.c *info* */
1510 refresh_interface_font();
1511 allqueue(REDRAWALL, 0);
1512 break;
1514 case B_DOLANGUIFONT: /* is button from space.c *info* */
1515 if(U.transopts & USER_DOTRANSLATE)
1516 start_interface_font();
1517 else
1518 G.ui_international = FALSE;
1519 allqueue(REDRAWALL, 0);
1520 break;
1521 #endif
1523 case B_FULL:
1524 if(curarea->spacetype!=SPACE_INFO) {
1525 area_fullscreen();
1527 break;
1529 case B_IDNAME:
1530 /* changing a metaballs name, sadly enough,
1531 * can require it to be updated because its
1532 * basis might have changed... -zr
1534 if (ob && ob->type==OB_MBALL) {
1535 DAG_scene_sort(G.scene);
1536 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1538 /* redraw because name has changed: new pup */
1539 scrarea_queue_headredraw(curarea);
1540 allqueue(REDRAWINFO, 1);
1541 allqueue(REDRAWOOPS, 1);
1542 allqueue(REDRAWACTION, 1);
1543 allqueue(REDRAWNLA, 1);
1544 /* name scene also in set PUPmenu */
1545 allqueue(REDRAWBUTSALL, 0);
1546 allqueue(REDRAWIMAGE, 0);
1547 allqueue(REDRAWHEADERS, 0);
1548 break;
1550 case B_KEEPDATA:
1551 /* keep datablock. similar to pressing FKEY in a fileselect window
1552 * maybe we can move that stuff to a seperate function? -- sg
1554 if (curarea->spacetype==SPACE_BUTS) {
1555 id= (ID *)G.buts->lockpoin;
1556 } else if(curarea->spacetype==SPACE_IPO) {
1557 id = (ID *)G.sipo->ipo;
1558 } else if(curarea->spacetype==SPACE_NODE) {
1559 id = ((SpaceNode *)curarea->spacedata.first)->id;
1560 } /* similar for other spacetypes ? */
1561 if (id) {
1562 /* flag was already toggled, just need to update user count */
1563 if(id->flag & LIB_FAKEUSER)
1564 id->us++;
1565 else
1566 id->us--;
1568 allqueue(REDRAWHEADERS, 0);
1570 break;
1576 void do_global_buttons2(short event)
1578 Base *base;
1579 Object *ob;
1580 Material *ma;
1581 MTex *mtex;
1582 Mesh *me;
1583 Curve *cu;
1584 MetaBall *mb;
1585 Ipo *ipo;
1586 Lamp *la;
1587 Lattice *lt;
1588 World *wrld;
1589 ID *idfrom;
1590 bAction *act;
1591 Brush *br;
1593 /* general: Single User is allowed when from==LOCAL
1594 * Make Local is allowed when (from==LOCAL && id==LIB)
1597 if(event<B_LOCAL_ALONE) return;
1599 ob= OBACT;
1601 switch(event) {
1603 case B_LAMPALONE:
1604 if(ob && ob->id.lib==0) {
1605 la= ob->data;
1606 if(la->id.us>1) {
1607 if(okee("Single user")) {
1608 ob->data= copy_lamp(la);
1609 la->id.us--;
1613 break;
1614 case B_LAMPLOCAL:
1615 if(ob && ob->id.lib==0) {
1616 la= ob->data;
1617 if(la->id.lib) {
1618 if(okee("Make local")) {
1619 make_local_lamp(la);
1623 break;
1625 case B_ARMLOCAL:
1626 if (ob&&ob->id.lib==0){
1627 bArmature *arm=ob->data;
1628 if (arm->id.lib){
1629 if(okee("Make local")) {
1630 make_local_armature(arm);
1634 break;
1635 case B_ARMALONE:
1636 if(ob && ob->id.lib==0) {
1637 bArmature *arm=ob->data;
1638 if(arm->id.us>1) {
1639 if(okee("Single user")) {
1640 ob->data= copy_armature(arm);
1641 armature_rebuild_pose(ob, ob->data);
1642 arm->id.us--;
1646 break;
1647 case B_ACTLOCAL:
1648 if(ob && ob->id.lib==0) {
1649 act= ob->action;
1650 if(act->id.lib) {
1651 if(okee("Make local")) {
1652 make_local_action(act);
1653 allqueue(REDRAWACTION,0);
1657 break;
1658 case B_ACTALONE:
1659 if(ob && ob->id.lib==0) {
1660 act= ob->action;
1662 if(act->id.us>1) {
1663 if(okee("Single user")) {
1664 ob->action=copy_action(act);
1665 act->id.us--;
1666 allqueue(REDRAWACTION, 0);
1670 break;
1672 case B_CAMERAALONE:
1673 if(ob && ob->id.lib==0) {
1674 Camera *ca= ob->data;
1675 if(ca->id.us>1) {
1676 if(okee("Single user")) {
1677 ob->data= copy_camera(ca);
1678 ca->id.us--;
1682 break;
1683 case B_CAMERALOCAL:
1684 if(ob && ob->id.lib==0) {
1685 Camera *ca= ob->data;
1686 if(ca->id.lib) {
1687 if(okee("Make local")) {
1688 make_local_camera(ca);
1692 break;
1693 case B_WORLDALONE:
1694 wrld= G.scene->world;
1695 if(wrld->id.us>1) {
1696 if(okee("Single user")) {
1697 G.scene->world= copy_world(wrld);
1698 wrld->id.us--;
1701 break;
1702 case B_WORLDLOCAL:
1703 wrld= G.scene->world;
1704 if(wrld && wrld->id.lib) {
1705 if(okee("Make local")) {
1706 make_local_world(wrld);
1709 break;
1711 case B_LATTALONE:
1712 if(ob && ob->id.lib==0) {
1713 lt= ob->data;
1714 if(lt->id.us>1) {
1715 if(okee("Single user")) {
1716 ob->data= copy_lattice(lt);
1717 lt->id.us--;
1721 break;
1722 case B_LATTLOCAL:
1723 if(ob && ob->id.lib==0) {
1724 lt= ob->data;
1725 if(lt->id.lib) {
1726 if(okee("Make local")) {
1727 make_local_lattice(lt);
1731 break;
1733 case B_MATALONE:
1734 if(ob==0) return;
1735 ma= give_current_material(ob, ob->actcol);
1736 idfrom= material_from(ob, ob->actcol);
1737 if(idfrom && idfrom->lib==0) {
1738 if(ma->id.us>1) {
1739 if(okee("Single user")) {
1740 ma= copy_material(ma);
1741 ma->id.us= 0;
1742 assign_material(ob, ma, ob->actcol);
1746 break;
1747 case B_MATLOCAL:
1748 if(ob==0) return;
1749 idfrom= material_from(ob, ob->actcol);
1750 if(idfrom->lib==0) {
1751 ma= give_current_material(ob, ob->actcol);
1752 if(ma && ma->id.lib) {
1753 if(okee("Make local")) {
1754 make_local_material(ma);
1758 break;
1760 case B_MESHLOCAL:
1761 if(ob && ob->id.lib==0) {
1762 me= ob->data;
1763 if(me && me->id.lib) {
1764 if(okee("Make local")) {
1765 make_local_mesh(me);
1766 make_local_key( me->key );
1768 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1772 break;
1774 case B_MBALLALONE:
1775 if(ob && ob->id.lib==0) {
1776 mb= ob->data;
1777 if(mb->id.us>1) {
1778 if(okee("Single user")) {
1779 ob->data= copy_mball(mb);
1780 mb->id.us--;
1781 if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1785 break;
1786 case B_MBALLLOCAL:
1787 if(ob && ob->id.lib==0) {
1788 mb= ob->data;
1789 if(mb->id.lib) {
1790 if(okee("Make local")) {
1791 make_local_mball(mb);
1795 break;
1797 case B_CURVEALONE:
1798 if(ob && ob->id.lib==0) {
1799 cu= ob->data;
1800 if(cu->id.us>1) {
1801 if(okee("Single user")) {
1802 ob->data= copy_curve(cu);
1803 cu->id.us--;
1804 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1805 if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1809 break;
1810 case B_CURVELOCAL:
1811 if(ob && ob->id.lib==0) {
1812 cu= ob->data;
1813 if(cu->id.lib) {
1814 if(okee("Make local")) {
1815 make_local_curve(cu);
1816 make_local_key( cu->key );
1817 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1821 break;
1823 case B_TEXALONE:
1824 if(G.buts->texfrom==0) { /* from mat */
1825 if(ob==0) return;
1826 ma= give_current_material(ob, ob->actcol);
1827 ma= editnode_get_active_material(ma);
1828 if(ma && ma->id.lib==0) {
1829 mtex= ma->mtex[ ma->texact ];
1830 if(mtex->tex && mtex->tex->id.us>1) {
1831 if(okee("Single user")) {
1832 mtex->tex->id.us--;
1833 mtex->tex= copy_texture(mtex->tex);
1838 else if(G.buts->texfrom==1) { /* from world */
1839 wrld= G.scene->world;
1840 if(wrld->id.lib==0) {
1841 mtex= wrld->mtex[ wrld->texact ];
1842 if(mtex->tex && mtex->tex->id.us>1) {
1843 if(okee("Single user")) {
1844 mtex->tex->id.us--;
1845 mtex->tex= copy_texture(mtex->tex);
1850 else if(G.buts->texfrom==2) { /* from lamp */
1851 if(ob==0 || ob->type!=OB_LAMP) return;
1852 la= ob->data;
1853 if(la->id.lib==0) {
1854 mtex= la->mtex[ la->texact ];
1855 if(mtex->tex && mtex->tex->id.us>1) {
1856 if(okee("Single user")) {
1857 mtex->tex->id.us--;
1858 mtex->tex= copy_texture(mtex->tex);
1863 else if(G.buts->texfrom==3) { /* from brush */
1864 br= G.scene->toolsettings->imapaint.brush;
1865 if(br==0) return;
1866 if(br->id.lib==0) {
1867 mtex= br->mtex[ br->texact ];
1868 if(mtex->tex && mtex->tex->id.us>1) {
1869 if(okee("Single user")) {
1870 mtex->tex->id.us--;
1871 mtex->tex= copy_texture(mtex->tex);
1872 allqueue(REDRAWIMAGE, 0);
1877 break;
1878 case B_TEXLOCAL:
1879 if(G.buts->texfrom==0) { /* from mat */
1880 if(ob==0) return;
1881 ma= give_current_material(ob, ob->actcol);
1882 ma= editnode_get_active_material(ma);
1883 if(ma && ma->id.lib==0) {
1884 mtex= ma->mtex[ ma->texact ];
1885 if(mtex->tex && mtex->tex->id.lib) {
1886 if(okee("Make local")) {
1887 make_local_texture(mtex->tex);
1892 else if(G.buts->texfrom==1) { /* from world */
1893 wrld= G.scene->world;
1894 if(wrld->id.lib==0) {
1895 mtex= wrld->mtex[ wrld->texact ];
1896 if(mtex->tex && mtex->tex->id.lib) {
1897 if(okee("Make local")) {
1898 make_local_texture(mtex->tex);
1903 else if(G.buts->texfrom==2) { /* from lamp */
1904 if(ob==0 || ob->type!=OB_LAMP) return;
1905 la= ob->data;
1906 if(la->id.lib==0) {
1907 mtex= la->mtex[ la->texact ];
1908 if(mtex->tex && mtex->tex->id.lib) {
1909 if(okee("Make local")) {
1910 make_local_texture(mtex->tex);
1915 else if(G.buts->texfrom==3) { /* from brush */
1916 br= G.scene->toolsettings->imapaint.brush;
1917 if(br==0) return;
1918 if(br->id.lib==0) {
1919 mtex= br->mtex[ br->texact ];
1920 if(mtex->tex && mtex->tex->id.lib) {
1921 if(okee("Make local")) {
1922 make_local_texture(mtex->tex);
1923 allqueue(REDRAWIMAGE, 0);
1928 break;
1930 case B_IPOALONE:
1931 ipo= G.sipo->ipo;
1932 idfrom= G.sipo->from;
1934 if(idfrom && idfrom->lib==NULL) {
1935 if(ipo->id.us>1) {
1936 if(okee("Single user")) {
1937 ipo= copy_ipo(ipo);
1938 ipo->id.us= 0; /* assign_ipo adds users, copy_ipo sets to 1 */
1939 spaceipo_assign_ipo(G.sipo, ipo);
1940 allqueue(REDRAWIPO, 0);
1944 break;
1945 case B_IPOLOCAL:
1946 ipo= G.sipo->ipo;
1947 idfrom= G.sipo->from;
1949 if(idfrom && idfrom->lib==0) {
1950 if(ipo->id.lib) {
1951 if(okee("Make local")) {
1952 make_local_ipo(ipo);
1953 allqueue(REDRAWIPO, 0);
1957 break;
1959 case B_OBALONE:
1960 if(G.scene->id.lib==0) {
1961 if(ob->id.us>1) {
1962 if(okee("Single user")) {
1963 base= FIRSTBASE;
1964 while(base) {
1965 if(base->object==ob) {
1966 base->object= copy_object(ob);
1967 ob->id.us--;
1968 allqueue(REDRAWVIEW3D, 0);
1969 break;
1971 base= base->next;
1976 break;
1977 case B_OBLOCAL:
1978 if(G.scene->id.lib==0) {
1979 if(ob->id.lib) {
1980 if(okee("Make local")) {
1981 make_local_object(ob);
1982 allqueue(REDRAWVIEW3D, 0);
1986 break;
1987 case B_MESHALONE:
1988 if(ob && ob->id.lib==0) {
1990 me= ob->data;
1992 if(me && me->id.us>1) {
1993 if(okee("Single user")) {
1994 Mesh *men= copy_mesh(me);
1995 men->id.us= 0;
1997 set_mesh(ob, men);
1999 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2001 if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
2005 break;
2008 BIF_undo_push("Make single user or local");
2009 allqueue(REDRAWBUTSALL, 0);
2010 allqueue(REDRAWOOPS, 0);
2013 /* ******************** GENERAL ********************** */
2015 void do_headerbuttons(short event)
2018 if(event<=50) do_global_buttons2(event);
2019 else if(event<=100) do_global_buttons(event);
2020 else if(event<200) do_view3d_buttons(event);
2021 else if(event<250) do_ipo_buttons(event);
2022 else if(event<300) do_oops_buttons(event);
2023 else if(event<350) do_info_buttons(event);
2024 else if(event<400) do_image_buttons(event);
2025 else if(event<450) do_buts_buttons(event);
2026 else if(event<500) do_imasel_buttons(event);
2027 else if(event<525) do_text_buttons(event);
2028 else if(event<550) do_script_buttons(event);
2029 else if(event<600) do_file_buttons(event);
2030 else if(event<650) do_seq_buttons(event);
2031 else if(event<700) do_sound_buttons(event);
2032 else if(event<750) do_action_buttons(event);
2033 else if(event<800) do_time_buttons(curarea, event);
2034 else if(event<850) do_nla_buttons(event);
2035 else if(event<900) do_node_buttons(curarea, event);
2036 else if(event>=REDRAWVIEW3D) allqueue(event, 0);