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
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 *****
43 #include "BLI_winstuff.h"
46 #include "MEM_guardedalloc.h"
48 #include "DNA_object_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_view3d_types.h"
52 #include "DNA_space_types.h"
53 #include "DNA_texture_types.h"
55 #include "BKE_global.h"
57 #include "BKE_library.h"
58 #include "BKE_utildefines.h"
60 #include "BLI_blenlib.h"
62 #include "BSE_drawview.h" // for do_viewbuttons.c .... hurms
65 #include "BIF_graphics.h"
66 #include "BIF_keyval.h"
67 #include "BIF_interface.h"
68 #include "BIF_toolbox.h"
69 #include "BIF_space.h"
70 #include "BIF_screen.h"
71 #include "BIF_butspace.h"
72 #include "BSE_headerbuttons.h"
73 #include "BIF_previewrender.h"
74 #include "BIF_mywindow.h"
75 #include "BIF_glutil.h"
76 #include "BIF_resources.h"
79 #include "butspace.h" // own module
82 /* Local vars ---------------------------------------------------------- */
83 short bgpicmode=0, near=1000, far=1000;
87 char texstr[20][12]= {"None" , "Clouds" , "Wood", "Marble", "Magic" , "Blend",
88 "Stucci", "Noise" , "Image", "Plugin", "EnvMap" , "Musgrave",
89 "Voronoi", "DistNoise", "", "", "", "", "", ""};
90 /* ---------------------------------------------------------------------- */
92 void test_idbutton_cb(void *namev, void *arg2_unused)
95 test_idbutton(name+2);
99 void test_scriptpoin_but(char *name, ID **idpp)
103 id= G.main->text.first;
105 if( strcmp(name, id->name+2)==0 ) {
114 void test_actionpoin_but(char *name, ID **idpp)
118 id= G.main->action.first;
120 if( strcmp(name, id->name+2)==0 ) {
130 void test_obpoin_but(char *name, ID **idpp)
134 if(idpp == (ID **)&(emptytex.object)) {
135 error("You must add a texture first");
140 id= G.main->object.first;
142 if( strcmp(name, id->name+2)==0 ) {
151 void test_obcurpoin_but(char *name, ID **idpp)
155 if(idpp == (ID **)&(emptytex.object)) {
156 error("You must add a texture first");
161 id= G.main->object.first;
163 if( strcmp(name, id->name+2)==0 ) {
164 if (((Object *)id)->type != OB_CURVE) {
165 error ("Bevel object must be a curve");
176 void test_meshpoin_but(char *name, ID **idpp)
180 if( *idpp ) (*idpp)->us--;
182 id= G.main->mesh.first;
184 if( strcmp(name, id->name+2)==0 ) {
194 void test_matpoin_but(char *name, ID **idpp)
198 if( *idpp ) (*idpp)->us--;
200 id= G.main->mat.first;
202 if( strcmp(name, id->name+2)==0 ) {
212 void test_scenepoin_but(char *name, ID **idpp)
216 if( *idpp ) (*idpp)->us--;
218 id= G.main->scene.first;
220 if( strcmp(name, id->name+2)==0 ) {
231 /* --------------------------------- */
236 void do_butspace(unsigned short event)
240 /* redraw windows of the same type? */
241 buts= curarea->spacedata.first;
242 if(buts->mainb==CONTEXT_SCENE) allqueue(REDRAWBUTSSCENE, curarea->win);
243 if(buts->mainb==CONTEXT_OBJECT) allqueue(REDRAWBUTSOBJECT, curarea->win);
244 if(buts->mainb==CONTEXT_SHADING) allqueue(REDRAWBUTSSHADING, curarea->win);
245 if(buts->mainb==CONTEXT_EDITING) allqueue(REDRAWBUTSEDIT, curarea->win);
246 if(buts->mainb==CONTEXT_SCRIPT) allqueue(REDRAWBUTSSCRIPT, curarea->win);
247 if(buts->mainb==CONTEXT_LOGIC) allqueue(REDRAWBUTSLOGIC, curarea->win);
250 do_global_buttons2(event);
252 else if(event<=100) {
253 do_global_buttons(event);
255 else if(event < 1000) {
256 do_headerbuttons(event);
258 else if(event<=B_VIEWBUTS) {
261 else if(event<=B_LAMPBUTS) {
264 else if(event<=B_MATBUTS) {
267 else if(event<=B_TEXBUTS) {
270 else if(event<=B_ANIMBUTS) {
271 do_object_panels(event);
273 else if(event<=B_WORLDBUTS) {
276 else if(event<=B_RENDERBUTS) {
277 do_render_panels(event); // buttons_scene.c
279 else if(event<=B_COMMONEDITBUTS) {
280 do_common_editbuts(event);
282 else if(event<=B_MESHBUTS) {
285 else if(event<=B_CURVEBUTS) {
288 else if(event<=B_FONTBUTS) {
291 else if(event<=B_CAMBUTS) {
294 else if(event<=B_MBALLBUTS) {
297 else if(event<=B_LATTBUTS) {
298 do_latticebuts(event);
300 else if(event<=B_GAMEBUTS) {
301 do_logic_buts(event); // buttons_logic.c
303 else if(event<=B_FPAINTBUTS) {
304 do_fpaintbuts(event);
306 else if(event<=B_RADIOBUTS) {
309 else if(event<=B_SCRIPTBUTS) {
310 do_scriptbuts(event);
312 else if(event<=B_SOUNDBUTS) {
315 else if(event<=B_CONSTRAINTBUTS) {
316 do_constraintbuts(event);
318 else if(event<=B_UVAUTOCALCBUTS) {
319 do_uvautocalculationbuts(event);
321 else if(event==REDRAWVIEW3D) allqueue(event, 1); // 1=do header too
322 else if(event>REDRAWVIEW3D) allqueue(event, 0);
325 void butspace_context_switch(SpaceButs *buts, Base *new)
327 // change type automatically
329 int tab= buts->tab[CONTEXT_SHADING];
331 if(tab == TAB_SHADING_WORLD) {
332 if(new->object->type==OB_LAMP) {
333 buts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
335 else buts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
338 else if(tab == TAB_SHADING_TEX) {
339 if(new->object->type==OB_LAMP) buts->texfrom= 2;
340 else if(new->object->type==OB_CAMERA) buts->texfrom= 1;
341 else buts->texfrom= 0;
343 else if(tab == TAB_SHADING_RAD) {
345 else if(new->object->type==OB_CAMERA) {
346 buts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
348 else if(new->object->type==OB_LAMP) {
349 buts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
352 buts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
357 /* new active object */
358 void redraw_test_buttons(Base *new)
363 sa= G.curscreen->areabase.first;
365 if(sa->spacetype==SPACE_BUTS) {
366 buts= sa->spacedata.first;
368 if(ELEM5(buts->mainb, CONTEXT_OBJECT, CONTEXT_EDITING, CONTEXT_SHADING, CONTEXT_LOGIC, CONTEXT_SCRIPT)) {
369 addqueue(sa->win, REDRAW, 1);
373 BIF_preview_changed(buts);
376 // always to context switch
377 if(new) butspace_context_switch(buts, new);
386 void drawbutspace(ScrArea *sa, void *spacedata)
388 SpaceButs *sbuts= sa->spacedata.first;
389 View2D *v2d= &sbuts->v2d;
393 myortho2(v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
395 BIF_GetThemeColor3fv(TH_BACK, col);
396 glClearColor(col[0], col[1], col[2], 0.0);
397 glClear(GL_COLOR_BUFFER_BIT);
399 uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
400 uiFreeBlocksWin(&sa->uiblocks, sa->win);
402 /* select the context to be drawn, per contex/tab the actual context is tested */
403 switch(sbuts->mainb) {
405 tab= sbuts->tab[CONTEXT_SCENE];
407 if(tab== TAB_SCENE_RENDER)
409 else if(tab == TAB_SCENE_ANIM)
411 else if(tab == TAB_SCENE_SOUND)
421 case CONTEXT_SHADING:
422 tab= sbuts->tab[CONTEXT_SHADING];
424 if(tab==TAB_SHADING_MAT)
426 else if(tab==TAB_SHADING_LAMP)
428 else if(tab==TAB_SHADING_WORLD)
430 else if(tab==TAB_SHADING_RAD)
432 else if(tab==TAB_SHADING_TEX)
436 case CONTEXT_EDITING:
453 /* when align changes, also do this for new panels */
454 /* don't always align, this function is called during AnmatePanels too */
456 if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb || sbuts->tabo!=sbuts->tab[sbuts->mainb])
459 uiDrawBlocksPanels(sa, align);
461 /* since panels give different layouts, we have to make sure v2d.tot matches */
462 uiMatchPanel_view2d(sa);
465 // also for memory for finding which texture you'd like to see
466 sbuts->mainbo= sbuts->mainb;
467 sbuts->tabo= sbuts->tab[sbuts->mainb];
469 myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
470 draw_area_emboss(sa);
471 myortho2(v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
474 sa->win_swap= WIN_BACK_OK;