Preliminary work on faceloop selection and faceloop cutting. Commiting in steps to...
[blender.git] / source / blender / src / space.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
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.
13  *
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.
18  *
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.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  *
32  *
33  * - here initialize and free and handling SPACE data
34  */
35
36 #include <string.h>
37 #include <stdio.h>
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #ifdef WIN32
44 #include "BLI_winstuff.h"
45 #endif
46
47 #include "MEM_guardedalloc.h"
48
49 #ifdef INTERNATIONAL
50 #include "BIF_language.h"
51 #endif
52
53 #include "IMB_imbuf_types.h"
54 #include "IMB_imbuf.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58 #include "BLI_editVert.h"
59 #include "BLI_linklist.h"
60
61 #include "DNA_action_types.h"
62 #include "DNA_curve_types.h"
63 #include "DNA_image_types.h"
64 #include "DNA_ipo_types.h"
65 #include "DNA_mesh_types.h"
66 #include "DNA_object_types.h"
67 #include "DNA_scene_types.h"
68 #include "DNA_screen_types.h"
69 #include "DNA_sequence_types.h"
70 #include "DNA_sound_types.h"
71 #include "DNA_space_types.h"
72 #include "DNA_userdef_types.h"
73 #include "DNA_view2d_types.h"
74 #include "DNA_view3d_types.h"
75
76 #include "BKE_blender.h"
77 #include "BKE_curve.h"
78 #include "BKE_displist.h"
79 #include "BKE_global.h"
80 #include "BKE_ipo.h"
81 #include "BKE_main.h"
82 #include "BKE_scene.h"
83 #include "BKE_utildefines.h"
84
85 #include "BIF_butspace.h"
86 #include "BIF_drawimage.h"
87 #include "BIF_drawseq.h"
88 #include "BIF_drawtext.h"
89 #include "BIF_editarmature.h"
90 #include "BIF_editfont.h"
91 #include "BIF_editika.h"
92 #include "BIF_editkey.h"
93 #include "BIF_editlattice.h"
94 #include "BIF_editmesh.h"
95 #include "BIF_editoops.h"
96 #include "BIF_editseq.h"
97 #include "BIF_editsima.h"
98 #include "BIF_editsound.h"
99 #include "BIF_editview.h"
100 #include "BIF_gl.h"
101 #include "BIF_imasel.h"
102 #include "BIF_interface.h"
103 #include "BIF_mywindow.h"
104 #include "BIF_oops.h"
105 #include "BIF_resources.h"
106 #include "BIF_screen.h"
107 #include "BIF_space.h"
108 #include "BIF_spacetypes.h"
109 #include "BIF_toets.h"
110 #include "BIF_toolbox.h"
111 #include "BIF_usiblender.h"
112 #include "BIF_previewrender.h"
113
114 #include "BSE_edit.h"
115 #include "BSE_view.h"
116 #include "BSE_editipo.h"
117 #include "BSE_drawipo.h"
118 #include "BSE_drawview.h"
119 #include "BSE_drawnla.h"
120 #include "BSE_filesel.h"
121 #include "BSE_headerbuttons.h"
122 #include "BSE_editnla_types.h"
123
124 #include "BDR_vpaint.h"
125 #include "BDR_editmball.h"
126 #include "BDR_editobject.h"
127 #include "BDR_editcurve.h"
128 #include "BDR_editface.h"
129 #include "BDR_drawmesh.h"
130 #include "BDR_drawobject.h"
131
132 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
133
134 #include "mydevice.h"
135 #include "blendef.h"
136 #include "datatoc.h"
137
138 #include "BPY_extern.h" // Blender Python library
139
140 #include "TPT_DependKludge.h"
141 #ifdef NAN_TPT
142 #include "BSE_trans_types.h"
143 #include "IMG_Api.h"
144 #endif /* NAN_TPT */
145
146 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
147
148 extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, int always_use_expand_framing);
149
150 /**
151  * When the mipmap setting changes, we want to redraw the view right
152  * away to reflect this setting.
153  */
154 void space_mipmap_button_function(int event);
155
156
157 unsigned short convert_for_nonumpad(unsigned short event);
158 void free_soundspace(SpaceSound *ssound);
159
160 /* *************************************** */
161
162 /* don't know yet how the handlers will evolve, for simplicity
163    i choose for an array with eventcodes, this saves in a file!
164    */
165 void add_blockhandler(ScrArea *sa, short eventcode, short val)
166 {
167         SpaceLink *sl= sa->spacedata.first;
168         short a;
169         
170         // find empty spot
171         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
172                 if( sl->blockhandler[a]==eventcode ) {
173                         sl->blockhandler[a+1]= val;
174                         break;
175                 }
176                 else if( sl->blockhandler[a]==0) {
177                         sl->blockhandler[a]= eventcode;
178                         sl->blockhandler[a+1]= val;
179                         break;
180                 }
181         }
182         if(a==SPACE_MAXHANDLER) printf("error; max (4) blockhandlers reached!\n");
183 }
184
185 void rem_blockhandler(ScrArea *sa, short eventcode)
186 {
187         SpaceLink *sl= sa->spacedata.first;
188         short a;
189         
190         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
191                 if( sl->blockhandler[a]==eventcode) {
192                         sl->blockhandler[a]= 0;
193                         break;
194                 }
195         }
196 }
197
198
199
200
201 /* ************* SPACE: VIEW3D  ************* */
202
203 /*  extern void drawview3dspace(ScrArea *sa, void *spacedata); BSE_drawview.h */
204
205
206 void copy_view3d_lock(short val)
207 {
208         bScreen *sc;
209         int bit;
210         
211         /* from G.scene copy to the other views */
212         sc= G.main->screen.first;
213         
214         while(sc) {
215                 if(sc->scene==G.scene) {
216                         ScrArea *sa= sc->areabase.first;
217                         while(sa) {
218                                 SpaceLink *sl= sa->spacedata.first;
219                                 while(sl) {
220                                         if(sl->spacetype==SPACE_OOPS && val==REDRAW) {
221                                                 if(sa->win) scrarea_queue_winredraw(sa);
222                                         }
223                                         else if(sl->spacetype==SPACE_VIEW3D) {
224                                                 View3D *vd= (View3D*) sl;
225                                                 if(vd->scenelock && vd->localview==0) {
226                                                         vd->lay= G.scene->lay;
227                                                         vd->camera= G.scene->camera;
228                                                         
229                                                         if(vd->camera==0 && vd->persp>1) vd->persp= 1;
230                                                         
231                                                         if( (vd->lay & vd->layact) == 0) {
232                                                                 bit= 0;
233                                                                 while(bit<32) {
234                                                                         if(vd->lay & (1<<bit)) {
235                                                                                 vd->layact= 1<<bit;
236                                                                                 break;
237                                                                         }
238                                                                         bit++;
239                                                                 }
240                                                         }
241                                                         
242                                                         if(val==REDRAW && vd==sa->spacedata.first) {
243                                                                 if(sa->win) scrarea_queue_redraw(sa);
244                                                         }
245                                                 }
246                                         }
247                                         sl= sl->next;
248                                 }
249                                 sa= sa->next;
250                         }
251                 }
252                 sc= sc->id.next;
253         }
254 }
255
256 void handle_view3d_lock()
257 {
258         if (G.vd != NULL) {
259                 if(G.vd->localview==0 && G.vd->scenelock && curarea->spacetype==SPACE_VIEW3D) {
260
261                         /* copy to scene */
262                         G.scene->lay= G.vd->lay;
263                         G.scene->camera= G.vd->camera;
264         
265                         copy_view3d_lock(REDRAW);
266                 }
267         }
268 }
269
270 void space_set_commmandline_options(void) {
271         SYS_SystemHandle syshandle;
272         int a;
273                 
274         if ( (syshandle = SYS_GetSystem()) ) {
275                 /* User defined settings */
276                 a= (U.gameflags & USERDEF_VERTEX_ARRAYS);
277                 SYS_WriteCommandLineInt(syshandle, "vertexarrays", a);
278
279                 a= (U.gameflags & USERDEF_DISABLE_SOUND);
280                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
281
282                 a= (U.gameflags & USERDEF_DISABLE_MIPMAP);
283                 set_mipmap(!a);
284                 SYS_WriteCommandLineInt(syshandle, "nomipmap", a);
285
286                 /* File specific settings: */
287                 /* Only test the first one. These two are switched
288                  * simultaneously. */
289                 a= (G.fileflags & G_FILE_SHOW_FRAMERATE);
290                 SYS_WriteCommandLineInt(syshandle, "show_framerate", a);
291                 SYS_WriteCommandLineInt(syshandle, "show_profile", a);
292
293                 /* When in wireframe mode, always draw debug props. */
294                 if (G.vd) {
295                         a = ( (G.fileflags & G_FILE_SHOW_DEBUG_PROPS) 
296                                   || (G.vd->drawtype == OB_WIRE)          
297                                   || (G.vd->drawtype == OB_SOLID)         );
298                         SYS_WriteCommandLineInt(syshandle, "show_properties", a);
299                 }
300
301                 a= (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
302                 SYS_WriteCommandLineInt(syshandle, "fixedtime", a);
303         }
304 }
305
306         /**
307          * These two routines imported from the gameengine, 
308          * I suspect a lot of the resetting stuff is cruft
309          * and can be removed, but it should be checked.
310          */
311 static void SaveState(void)
312 {
313         glPushAttrib(GL_ALL_ATTRIB_BITS);
314
315         init_realtime_GL();
316         init_gl_stuff();
317
318         if(G.scene->camera==0 || G.scene->camera->type!=OB_CAMERA)
319                 error("no (correct) camera");
320
321         waitcursor(1);
322 }
323
324 static void RestoreState(void)
325 {
326         curarea->win_swap = 0;
327         curarea->head_swap=0;
328         allqueue(REDRAWVIEW3D, 0);
329         allqueue(REDRAWBUTSALL, 0);
330         reset_slowparents();
331         waitcursor(0);
332         G.qual= 0;
333         glPopAttrib();
334 }
335
336 static LinkNode *save_and_reset_all_scene_cfra(void)
337 {
338         LinkNode *storelist= NULL;
339         Scene *sc;
340         
341         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
342                 BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
343                 sc->r.cfra= 1;
344
345                 set_scene_bg(sc);
346         }
347         
348         BLI_linklist_reverse(&storelist);
349         
350         return storelist;
351 }
352
353 static void restore_all_scene_cfra(LinkNode *storelist) {
354         LinkNode *sc_store= storelist;
355         Scene *sc;
356         
357         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
358                 int stored_cfra= (int) sc_store->link;
359                 
360                 sc->r.cfra= stored_cfra;
361                 set_scene_bg(sc);
362                 
363                 sc_store= sc_store->next;
364         }
365         
366         BLI_linklist_free(storelist, NULL);
367 }
368
369 void start_game(void)
370 {
371 #if GAMEBLENDER == 1
372         Scene *sc, *startscene = G.scene;
373         LinkNode *scene_cfra_store;
374
375                 /* XXX, silly code -  the game engine can
376                  * access any scene through logic, so we try 
377                  * to make sure each scene has a valid camera, 
378                  * just in case the game engine tries to use it.
379                  * 
380                  * Better would be to make a better routine
381                  * in the game engine for finding the camera.
382                  *  - zr
383                  */
384         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
385                 if (!sc->camera) {
386                         Base *base;
387         
388                         for (base= sc->base.first; base; base= base->next)
389                                 if (base->object->type==OB_CAMERA)
390                                         break;
391                         
392                         sc->camera= base?base->object:NULL;
393                 }
394         }
395
396         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
397         markdirty_all();
398         screen_swapbuffers();
399
400         /* can start from header */
401         mywinset(curarea->win);
402     
403         scene_cfra_store= save_and_reset_all_scene_cfra();
404         
405         BPY_end_python();
406
407         sound_stop_all_sounds();
408
409         /* Before jumping into Ketsji, we configure some settings. */
410         space_set_commmandline_options();
411
412         SaveState();
413         StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
414         RestoreState();
415
416         BPY_start_python();
417
418         restore_all_scene_cfra(scene_cfra_store);
419         set_scene_bg(startscene);
420         
421         if (G.flags & G_FLAGS_AUTOPLAY)
422                 exit_usiblender();
423
424                 /* groups could have changed ipo */
425         allqueue(REDRAWNLA, 0);
426         allqueue(REDRAWACTION, 0);
427         allspace(REMAKEIPO, 0);
428         allqueue(REDRAWIPO, 0);
429 #else
430         notice("Game engine is disabled in this release!");
431 #endif
432 }
433
434 static void changeview3dspace(ScrArea *sa, void *spacedata)
435 {
436         setwinmatrixview3d(0);  /* 0= no pick rect */
437 }
438
439         /* Callable from editmode and faceselect mode from the
440          * moment, would be nice (and is easy) to generalize
441          * to any mode.
442          */
443 static void align_view_to_selected(View3D *v3d)
444 {
445         int nr= pupmenu("Align view%t|To selection (top)%x2|To selection (front)%x1|To selection (side)%x0");
446
447         if (nr!=-1) {
448                 int axis= nr;
449
450                 if (G.obedit && (G.obedit->type == OB_MESH)) {
451                         editmesh_align_view_to_selected(v3d, axis);
452                         addqueue(v3d->area->win, REDRAW, 1);
453                 } else if (G.f & G_FACESELECT) {
454                         Object *obact= OBACT;
455                         if (obact && obact->type==OB_MESH) {
456                                 Mesh *me= obact->data;
457
458                                 if (me->tface) {
459                                         faceselect_align_view_to_selected(v3d, me, axis);
460                                         addqueue(v3d->area->win, REDRAW, 1);
461                                 }
462                         }
463                 }
464         }
465 }
466
467 void select_children(Object *ob, int recursive)
468 {
469         Base *base;
470
471         for (base= FIRSTBASE; base; base= base->next)
472                 if (ob == base->object->parent) {
473                         base->flag |= SELECT;
474                         base->object->flag |= SELECT;
475                         if (recursive) select_children(base->object, 1);
476                 }
477 }
478
479 void select_parent(void)        /* Makes parent active and de-selected OBACT */
480 {
481         Base *base, *startbase, *basact=NULL, *oldbasact;
482
483         if (!(OBACT->parent)) return;
484         BASACT->flag &= (~SELECT);
485         BASACT->object->flag &= (~SELECT);
486         startbase=  FIRSTBASE;
487         if(BASACT && BASACT->next) startbase= BASACT->next;
488         base = startbase;
489         while(base) {
490                 if(base->object==BASACT->object->parent) { basact=base; break; }
491                 base=base->next;
492                 if(base==0) base= FIRSTBASE;
493                 if(base==startbase) break;
494         }
495         oldbasact = BASACT;
496         BASACT = basact;
497         basact->flag |= SELECT;         
498         if(oldbasact) if(oldbasact != basact) draw_object_ext(oldbasact);
499         basact->object->flag= basact->flag;
500         draw_object_ext(basact);
501         set_active_base(basact);
502 }
503
504 void group_menu(void)
505 {
506         Base *base;
507         short nr;
508         char *str;
509
510         /* make menu string */
511         
512         str= MEM_mallocN(160, "groupmenu");
513         strcpy(str, "Group selection%t|Children%x1|"
514                     "Immediate children%x2|Parent%x3|"
515                     "Objects on shared layers%x4");
516
517         /* here we go */
518         
519         nr= pupmenu(str);
520         MEM_freeN(str);
521
522         if(nr==4) {
523                 base= FIRSTBASE;
524                 while(base) {
525                         if (base->lay & OBACT->lay) {
526                                 base->flag |= SELECT;
527                                 base->object->flag |= SELECT;
528                         }
529                         base= base->next;
530                 }               
531         }
532         else if(nr==2) select_children(OBACT, 0);
533         else if(nr==1) select_children(OBACT, 1);
534         else if(nr==3) select_parent();
535         
536         allqueue(REDRAWVIEW3D, 0);
537         allqueue(REDRAWBUTSOBJECT, 0);
538         allspace(REMAKEIPO, 0);
539         allqueue(REDRAWIPO, 0);
540 }
541
542 void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
543 {
544         unsigned short event= evt->event;
545         short val= evt->val;
546         char ascii= evt->ascii;
547         View3D *v3d= curarea->spacedata.first;
548         Object *ob;
549         float *curs;
550         int doredraw= 0, pupval;
551         
552         if(curarea->win==0) return;     /* when it comes from sa->headqread() */
553         
554         
555         if(val) {
556
557                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
558                 if(event==MOUSEY) return;
559                 
560                 if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
561
562                 
563                 /* TEXTEDITING?? */
564                 if(G.obedit && G.obedit->type==OB_FONT) {
565                         switch(event) {
566                         
567                         case LEFTMOUSE:
568                                 mouse_cursor();
569                                 break;
570                         case MIDDLEMOUSE:
571                                 if(U.flag & VIEWMOVE) {
572                                         if(G.qual & LR_SHIFTKEY) viewmove(0);
573                                         else if(G.qual & LR_CTRLKEY) viewmove(2);
574                                         else viewmove(1);
575                                 }
576                                 else {
577                                         if(G.qual & LR_SHIFTKEY) viewmove(1);
578                                         else if(G.qual & LR_CTRLKEY) viewmove(2);
579                                         else viewmove(0);
580                                 }
581                         case WHEELUPMOUSE:
582                                 /* Regular:   Zoom in */
583                                 /* Shift:     Scroll up */
584                                 /* Ctrl:      Scroll right */
585                                 /* Alt-Shift: Rotate up */
586                                 /* Alt-Ctrl:  Rotate right */
587
588                                 if( G.qual & LR_SHIFTKEY ) {
589                                         if( G.qual & LR_ALTKEY ) { 
590                                                 G.qual &= ~LR_SHIFTKEY;
591                                                 persptoetsen(PAD2);
592                                                 G.qual |= LR_SHIFTKEY;
593                                         } else {
594                                                 persptoetsen(PAD2);
595                                         }
596                                 } else if( G.qual & LR_CTRLKEY ) {
597                                         if( G.qual & LR_ALTKEY ) { 
598                                                 G.qual &= ~LR_CTRLKEY;
599                                                 persptoetsen(PAD4);
600                                                 G.qual |= LR_CTRLKEY;
601                                         } else {
602                                                 persptoetsen(PAD4);
603                                         }
604                                 } else if(U.uiflag & WHEELZOOMDIR) 
605                                         persptoetsen(PADMINUS);
606                                 else
607                                         persptoetsen(PADPLUSKEY);
608
609                                 doredraw= 1;
610                                 break;
611
612                         case WHEELDOWNMOUSE:
613                                 /* Regular:   Zoom out */
614                                 /* Shift:     Scroll down */
615                                 /* Ctrl:      Scroll left */
616                                 /* Alt-Shift: Rotate down */
617                                 /* Alt-Ctrl:  Rotate left */
618
619                                 if( G.qual & LR_SHIFTKEY ) {
620                                         if( G.qual & LR_ALTKEY ) { 
621                                                 G.qual &= ~LR_SHIFTKEY;
622                                                 persptoetsen(PAD8);
623                                                 G.qual |= LR_SHIFTKEY;
624                                         } else {
625                                                 persptoetsen(PAD8);
626                                         }
627                                 } else if( G.qual & LR_CTRLKEY ) {
628                                         if( G.qual & LR_ALTKEY ) { 
629                                                 G.qual &= ~LR_CTRLKEY;
630                                                 persptoetsen(PAD6);
631                                                 G.qual |= LR_CTRLKEY;
632                                         } else {
633                                                 persptoetsen(PAD6);
634                                         }
635                                 } else if(U.uiflag & WHEELZOOMDIR) 
636                                         persptoetsen(PADPLUSKEY);
637                                 else
638                                         persptoetsen(PADMINUS);
639                                 
640                                 doredraw= 1;
641                                 break;
642
643                         case UKEY:
644                                 if(G.qual & LR_ALTKEY) {
645                                         remake_editText();
646                                         doredraw= 1;
647                                 } else {
648                                         do_textedit(event, val, ascii);
649                                 }
650                                 break;
651                         case VKEY:
652                                 if(G.qual & LR_ALTKEY) {
653                                         paste_editText();
654                                         doredraw= 1;
655                                 } else {
656                                         do_textedit(event, val, ascii);
657                                 }
658                                 break;
659                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
660                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
661                         case PADENTER:
662                                 persptoetsen(event);
663                                 doredraw= 1;
664                                 break;
665                                 
666                         default:
667                                 do_textedit(event, val, ascii);
668                                 break;
669                         }
670                 }
671                 else {
672                         switch(event) {
673                         
674                         case BACKBUFDRAW:
675                                 backdrawview3d(1);
676                                 break;
677                                 
678                         case LEFTMOUSE:
679                                 if (G.obedit || !(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
680                                         mouse_cursor();
681                                 }
682                                 else if (G.f & G_VERTEXPAINT) {
683                                         vertex_paint();
684                                 }
685                                 else if (G.f & G_WEIGHTPAINT){
686                                         weight_paint();
687                                 }
688                                 else if (G.f & G_TEXTUREPAINT) {
689                                         face_draw();
690                                 }
691                                 break;
692                         case MIDDLEMOUSE:
693                                 if(U.flag & VIEWMOVE) {
694                                         if(G.qual & LR_SHIFTKEY) viewmove(0);
695                                         else if(G.qual & LR_CTRLKEY) viewmove(2);
696                                         else viewmove(1);
697                                 }
698                                 else {
699                                         if(G.qual & LR_SHIFTKEY) viewmove(1);
700                                         else if(G.qual & LR_CTRLKEY) viewmove(2);
701                                         else viewmove(0);
702                                 }
703                                 break;
704                         case RIGHTMOUSE:
705                                 if(G.obedit && (G.qual & LR_CTRLKEY)==0) {
706                                         if(G.obedit->type==OB_MESH) mouse_mesh();
707                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) mouse_nurb();
708                                         else if(G.obedit->type==OB_MBALL) mouse_mball();
709                                         else if(G.obedit->type==OB_LATTICE) mouse_lattice();
710                                         else if(G.obedit->type==OB_ARMATURE) mouse_armature();
711                                 }
712                                 else if(G.obedit && ((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY))) mouse_mesh();
713                                 else if(G.obpose) { 
714                                         if (G.obpose->type==OB_ARMATURE) mousepose_armature();
715                                 }
716                                 else if( G.qual & LR_CTRLKEY ) mouse_select();
717                                 else if(G.f & G_FACESELECT) face_select();
718                                 else if( G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) sample_vpaint();
719                                 else
720                                         mouse_select();
721                                 break;
722
723                         case WHEELUPMOUSE:
724                                 /* Regular:   Zoom in */
725                                 /* Shift:     Scroll up */
726                                 /* Ctrl:      Scroll right */
727                                 /* Alt-Shift: Rotate up */
728                                 /* Alt-Ctrl:  Rotate right */
729
730                                 if( G.qual & LR_SHIFTKEY ) {
731                                         if( G.qual & LR_ALTKEY ) { 
732                                                 G.qual &= ~LR_SHIFTKEY;
733                                                 persptoetsen(PAD2);
734                                                 G.qual |= LR_SHIFTKEY;
735                                         } else {
736                                                 persptoetsen(PAD2);
737                                         }
738                                 } else if( G.qual & LR_CTRLKEY ) {
739                                         if( G.qual & LR_ALTKEY ) { 
740                                                 G.qual &= ~LR_CTRLKEY;
741                                                 persptoetsen(PAD4);
742                                                 G.qual |= LR_CTRLKEY;
743                                         } else {
744                                                 persptoetsen(PAD4);
745                                         }
746                                 } else if(U.uiflag & WHEELZOOMDIR) 
747                                         persptoetsen(PADMINUS);
748                                 else
749                                         persptoetsen(PADPLUSKEY);
750
751                                 doredraw= 1;
752                                 break;
753                         case WHEELDOWNMOUSE:
754                                 /* Regular:   Zoom out */
755                                 /* Shift:     Scroll down */
756                                 /* Ctrl:      Scroll left */
757                                 /* Alt-Shift: Rotate down */
758                                 /* Alt-Ctrl:  Rotate left */
759
760                                 if( G.qual & LR_SHIFTKEY ) {
761                                         if( G.qual & LR_ALTKEY ) { 
762                                                 G.qual &= ~LR_SHIFTKEY;
763                                                 persptoetsen(PAD8);
764                                                 G.qual |= LR_SHIFTKEY;
765                                         } else {
766                                                 persptoetsen(PAD8);
767                                         }
768                                 } else if( G.qual & LR_CTRLKEY ) {
769                                         if( G.qual & LR_ALTKEY ) { 
770                                                 G.qual &= ~LR_CTRLKEY;
771                                                 persptoetsen(PAD6);
772                                                 G.qual |= LR_CTRLKEY;
773                                         } else {
774                                                 persptoetsen(PAD6);
775                                         }
776                                 } else if(U.uiflag & WHEELZOOMDIR) 
777                                         persptoetsen(PADPLUSKEY);
778                                 else
779                                         persptoetsen(PADMINUS);
780                                 
781                                 doredraw= 1;
782                                 break;
783                         
784                         case ONEKEY:
785                                 ob= OBACT;
786                                 if(G.qual & LR_CTRLKEY) {
787                                         if(G.obedit) {
788                                                         flip_subdivison(G.obedit, 1);
789                                         }
790                                         else if(ob->type == OB_MESH) {
791                                                 flip_subdivison(ob, 1);
792                                         }
793                                 }
794                                 else
795                                         do_layer_buttons(0); break;
796                         case TWOKEY:
797                                 ob= OBACT;
798                                 if(G.qual & LR_CTRLKEY) {
799                                         if(G.obedit) {
800                                                         flip_subdivison(G.obedit, 2);
801                                         }
802                                         else if(ob->type == OB_MESH) {
803                                                 flip_subdivison(ob, 2);
804                                         }
805                                 }
806                                 else
807                                         do_layer_buttons(1); 
808                                 break;
809                         case THREEKEY:
810                                 ob= OBACT;
811                                 if(G.qual & LR_CTRLKEY) {
812                                         if(G.obedit) {
813                                                         flip_subdivison(G.obedit, 3);
814                                         }
815                                         else if(ob->type == OB_MESH) {
816                                                 flip_subdivison(ob, 3);
817                                         }
818                                 }
819                                 else
820                                 do_layer_buttons(2); break;
821                         case FOURKEY:
822                                 ob= OBACT;
823                                 if(G.qual & LR_CTRLKEY) {
824                                         if(G.obedit) {
825                                                         flip_subdivison(G.obedit, 4);
826                                         }
827                                         else if(ob->type == OB_MESH) {
828                                                 flip_subdivison(ob, 4);
829                                         }
830                                 }
831                                 else
832                                 do_layer_buttons(3); break;
833                         case FIVEKEY:
834                                 do_layer_buttons(4); break;
835                         case SIXKEY:
836                                 do_layer_buttons(5); break;
837                         case SEVENKEY:
838                                 do_layer_buttons(6); break;
839                         case EIGHTKEY:
840                                 do_layer_buttons(7); break;
841                         case NINEKEY:
842                                 do_layer_buttons(8); break;
843                         case ZEROKEY:
844                                 do_layer_buttons(9); break;
845                         case MINUSKEY:
846                                 do_layer_buttons(10); break;
847                         case EQUALKEY:
848                                 do_layer_buttons(11); break;
849                         case ACCENTGRAVEKEY:
850                                 do_layer_buttons(-1); break;
851                                 
852                         case AKEY:
853                                 if(G.qual & LR_CTRLKEY) apply_object();
854                                 else if(G.qual & LR_SHIFTKEY) {
855                                         tbox_setmain(0);
856                                         toolbox();
857                                 }
858                                 else {
859                                         if(G.obedit) {
860                                                 if(G.obedit->type==OB_MESH) deselectall_mesh();
861                                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
862                                                 else if(G.obedit->type==OB_MBALL) deselectall_mball();
863                                                 else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
864                                                 else if(G.obedit->type==OB_ARMATURE) deselectall_armature();
865                                         }
866                                         else if (G.obpose){
867                                                 switch (G.obpose->type){
868                                                 case OB_ARMATURE:
869                                                         deselectall_posearmature(1);
870                                                         break;
871                                                 }
872                                         }
873                                         else {
874                                                 if(G.f & G_FACESELECT) deselectall_tface();
875                                                 else {
876                                                         /* by design, the center of the active object 
877                                                          * (which need not necessarily by selected) will
878                                                          * still be drawn as if it were selected.
879                                                          */
880                                                         deselectall();
881                                                 }
882                                         }
883                                 }
884                                 break;
885                         case BKEY:
886                                 if(G.qual & LR_SHIFTKEY) set_render_border();
887                                 else borderselect();
888                                 break;
889                         case CKEY:
890                                 if(G.qual & LR_CTRLKEY) {
891                                         copymenu();
892                                 }
893                                 else if(G.qual & LR_ALTKEY) {
894                                         convertmenu();  /* editobject.c */
895                                 }
896                                 else if(G.qual & LR_SHIFTKEY) {
897                                         view3d_home(1);
898                                         curs= give_cursor();
899                                         curs[0]=curs[1]=curs[2]= 0.0;
900                                         allqueue(REDRAWVIEW3D, 0);
901                                 }
902                                 else if(G.obedit!=0 && ELEM(G.obedit->type, OB_CURVE, OB_SURF) ) {
903                                         makecyclicNurb();
904                                         makeDispList(G.obedit);
905                                         allqueue(REDRAWVIEW3D, 0);
906                                 }
907                                 else {
908                                         curs= give_cursor();
909                                         G.vd->ofs[0]= -curs[0];
910                                         G.vd->ofs[1]= -curs[1];
911                                         G.vd->ofs[2]= -curs[2];
912                                         scrarea_queue_winredraw(curarea);
913                                 }
914                         
915                                 break;
916                         case DKEY:
917                                 if(G.qual & LR_SHIFTKEY) {
918                                         duplicate_context_selected();
919                                 }
920                                 else if(G.qual & LR_ALTKEY) {
921                                         if(G.obpose) error ("Duplicate not possible in posemode.");
922                                         else
923                                         if(G.obedit==0) adduplicate(0);
924                                 }
925                                 else if(G.qual & LR_CTRLKEY) {
926                                         imagestodisplist();
927                                 }
928                                 else {
929                                         pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
930                                         if(pupval>0) {
931                                                 G.vd->drawtype= pupval;
932                                                 doredraw= 1;
933                                         
934                                         }
935                                 }
936                                 
937                                 break;
938                         case EKEY:
939                                 if(G.obedit) {
940                                         if(G.obedit->type==OB_MESH) extrude_mesh();
941                                         else if(G.obedit->type==OB_CURVE) addvert_Nurb('e');
942                                         else if(G.obedit->type==OB_SURF) extrude_nurb();
943                                         else if(G.obedit->type==OB_ARMATURE) extrude_armature();
944                                 }
945                                 else {
946                                         ob= OBACT;
947                                         if(ob && ob->type==OB_IKA) if(okee("extrude IKA")) extrude_ika(ob, 1);
948                                 }
949                                 break;
950                         case FKEY:
951                                 if(G.obedit) {
952                                         if(G.obedit->type==OB_MESH) {
953                                                 if(G.qual & LR_SHIFTKEY) fill_mesh();
954                                                 else if(G.qual & LR_ALTKEY) beauty_fill();
955                                                 else if(G.qual & LR_CTRLKEY) edge_flip();
956                                                 else addedgevlak_mesh();
957                                         }
958                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
959                                 }
960                                 else if(G.qual & LR_CTRLKEY) sort_faces();
961                                 else if(G.qual & LR_SHIFTKEY) fly();
962                                 else {
963                                                 set_faceselect();
964                                         }
965                                 
966                                 break;
967                         case GKEY:
968                                 /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
969                                 else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
970                                 
971                                 if(G.qual & LR_SHIFTKEY) group_menu();
972                                 else if(G.qual & LR_ALTKEY) clear_object('g');
973                                 else
974                                         transform('g');
975                                 break;
976                         case HKEY:
977                                 if(G.obedit) {
978                                         if(G.obedit->type==OB_MESH) {
979                                                 if(G.qual & LR_ALTKEY) reveal_mesh();
980                                                 else hide_mesh(G.qual & LR_SHIFTKEY);
981                                         }
982                                         else if(G.obedit->type== OB_SURF) {
983                                                 if(G.qual & LR_ALTKEY) revealNurb();
984                                                 else hideNurb(G.qual & LR_SHIFTKEY);
985                                         }
986                                         else if(G.obedit->type==OB_CURVE) {
987                                         
988                                                 if(G.qual & LR_CTRLKEY) autocalchandlesNurb_all(1);     /* flag=1, selected */
989                                                 else if(G.qual & LR_SHIFTKEY) sethandlesNurb(1);
990                                                 else sethandlesNurb(3);
991                                                 
992                                                 makeDispList(G.obedit);
993                                                 
994                                                 allqueue(REDRAWVIEW3D, 0);
995                                         }
996                                 }
997                                 else if(G.f & G_FACESELECT) hide_tface();
998                                 
999                                 break;
1000                         case IKEY:
1001                                 break;
1002                                 
1003                         case JKEY:
1004                                 if(G.qual & LR_CTRLKEY) {
1005                                         if( (ob= OBACT) ) {
1006                                                 if(ob->type == OB_MESH) join_mesh();
1007                                                 else if(ob->type == OB_CURVE) join_curve(OB_CURVE);
1008                                                 else if(ob->type == OB_SURF) join_curve(OB_SURF);
1009                                                 else if(ob->type == OB_ARMATURE) join_armature ();
1010                                         }
1011                                         else if (G.obedit && ELEM(G.obedit->type, OB_CURVE, OB_SURF)) addsegment_nurb();
1012                                 } else if(G.obedit) {
1013                                         if(G.obedit->type==OB_MESH) {
1014                                                 join_triangles();
1015                                         }
1016                                 }
1017
1018                                 break;
1019                         case KKEY:
1020                                 if(G.obedit) {
1021                                         if (G.qual & LR_SHIFTKEY ){
1022                                                 if (G.obedit->type==OB_MESH) KnifeSubdivide();
1023                                         }
1024                                         else if(G.obedit->type==OB_SURF) printknots();
1025                                 }
1026                                 else {
1027                                         if(G.qual & LR_SHIFTKEY) {
1028                                                 if(G.f & G_FACESELECT) clear_vpaint_selectedfaces();
1029                                                 else if(G.f & G_VERTEXPAINT) clear_vpaint();
1030                                                 else select_select_keys();
1031                                         }
1032                                         else if(G.qual & LR_CTRLKEY) make_skeleton();
1033 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1034                                         else set_ob_ipoflags();
1035                                 }
1036                                 
1037                                 break;
1038                         case LKEY:
1039                                 if(G.obedit) {
1040                                         if(G.obedit->type==OB_MESH) selectconnected_mesh();
1041                                         if(G.obedit->type==OB_ARMATURE) selectconnected_armature();
1042                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectconnected_nurb();
1043                                 }
1044                                 else if(G.obpose) {
1045                                         if(G.obpose->type==OB_ARMATURE) selectconnected_posearmature();
1046                                 }
1047                                 else {
1048                                 
1049                                         if(G.qual & LR_SHIFTKEY) selectlinks();
1050                                         else if(G.qual & LR_CTRLKEY) linkmenu();
1051                                         else if(G.f & G_FACESELECT) select_linked_tfaces();
1052                                         else make_local();
1053                                 }
1054                                 break;
1055                         case MKEY:
1056                                 if((G.obedit) && (G.qual & LR_ALTKEY)) {
1057                                         if(G.obedit->type==OB_MESH) mergemenu();
1058                                 }
1059                                 else {
1060                                         movetolayer();
1061                                 }
1062                                 break;
1063                         case NKEY:
1064                                 if(G.obedit && (G.qual & LR_CTRLKEY)) {
1065                                         switch (G.obedit->type){
1066                                         case OB_ARMATURE:
1067                                                 if (okee("Recalc bone roll angles")) auto_align_armature();
1068                                                 break;
1069                                         case OB_MESH: 
1070                                                 if(G.qual & LR_SHIFTKEY) {
1071                                                         if(okee("Recalc normals inside")) righthandfaces(2);
1072                                                 }
1073                                                 else {
1074                                                         if(okee("Recalc normals outside")) righthandfaces(1);
1075                                                 }
1076                                                 break;
1077                                         }
1078                                         allqueue(REDRAWVIEW3D, 0);
1079                                 }
1080                                 else {
1081                                         if(G.obedit);
1082                                         else add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1083                                         
1084                                         allqueue(REDRAWVIEW3D, 0);
1085                                 }
1086                                 break;
1087                         case OKEY:
1088                                 ob= OBACT;
1089                                 if(G.obedit) {
1090                                         extern int prop_mode;
1091
1092                                         if (G.qual & LR_SHIFTKEY) prop_mode= !prop_mode;
1093                                         else G.f ^= G_PROPORTIONAL;
1094
1095                                         allqueue(REDRAWHEADERS, 0);
1096                                 }
1097                                 else if(G.qual & LR_SHIFTKEY) {
1098                                         if(ob && ob->type == OB_MESH) {
1099                                                 flip_subdivison(ob, 0);
1100                                         }
1101                                 }
1102                                 else if(G.qual & LR_ALTKEY) clear_object('o');
1103                                 break;
1104
1105                         case PKEY:
1106                                 
1107                                 if(G.obedit) {
1108                                         if(G.qual) {
1109                                                 if(G.qual & LR_CTRLKEY) make_parent();
1110                                         }
1111                                         else if(G.obedit->type==OB_MESH) separatemenu();
1112                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) separate_nurb();
1113                                 }
1114                                 else if(G.qual & LR_CTRLKEY) make_parent();
1115                                 else if(G.qual & LR_ALTKEY) clear_parent();
1116                                 else {
1117                         start_game();
1118                                 }
1119                                 break;                          
1120                         case RKEY:
1121                                 if(G.obedit==0 && (G.f & G_FACESELECT)) rotate_uv_tface();
1122                                 else if(G.qual & LR_ALTKEY) clear_object('r');
1123                                 else if (G.obedit) {
1124                                         if(G.qual & LR_SHIFTKEY) {
1125                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1126                                                         selectrow_nurb();
1127                                                 else if (G.obedit->type==OB_MESH)
1128                                                         loop('s');
1129                                         }
1130                                         else if(G.qual & LR_CTRLKEY) {
1131                                                 if (G.obedit->type==OB_MESH)
1132                                                         loop('c');
1133                                         }
1134                                         else transform('r');
1135                                 }
1136                                 else transform('r');
1137                                 break;
1138                         case SKEY:
1139                                 if(G.qual & LR_ALTKEY) {
1140                                         if(G.obedit) transform('N');    /* scale by vertex normal */
1141                                         else clear_object('s');
1142                                 }
1143                                 else if(G.qual & LR_SHIFTKEY) snapmenu();
1144                                 else if(G.qual & LR_CTRLKEY) {
1145                                         if(G.obedit) transform('S');
1146                                 }
1147                                 else transform('s');
1148                                 break;
1149                         case TKEY:
1150                                 if(G.qual & LR_CTRLKEY) {
1151                                         if(G.obedit) {
1152                                                 if(G.obedit->type==OB_MESH) {
1153                                                         convert_to_triface(0);
1154                                                         allqueue(REDRAWVIEW3D, 0);
1155                                                         countall();
1156                                                         makeDispList(G.obedit);
1157                                                 }
1158                                         }
1159                                         else make_track();
1160                                 }
1161                                 else if(G.qual & LR_ALTKEY) {
1162                                         if(G.obedit && G.obedit->type==OB_CURVE) clear_tilt();
1163                                         else clear_track();
1164                                 }
1165                                 else {
1166                                         if(G.obedit) transform('t');
1167                                         else texspace_edit();
1168                                 }
1169                                 
1170                                 break;
1171                         case UKEY:
1172                                 if(G.obedit) {
1173                                         if(G.obedit->type==OB_MESH) remake_editMesh();
1174                                         else if(G.obedit->type==OB_ARMATURE) remake_editArmature();
1175                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) remake_editNurb();
1176                                         else if(G.obedit->type==OB_LATTICE) remake_editLatt();
1177                                 }
1178                                 else if(G.f & G_FACESELECT) uv_autocalc_tface();
1179                                 else if(G.f & G_WEIGHTPAINT) wpaint_undo();
1180                                 else if(G.f & G_VERTEXPAINT) vpaint_undo();
1181                                 else single_user();
1182                                 
1183                                 break;
1184                         case VKEY:
1185                                 if(G.qual==LR_SHIFTKEY) {
1186                                         if (G.obedit && G.obedit->type==OB_MESH) {
1187                                                 align_view_to_selected(v3d);
1188                                         } else if (G.f & G_FACESELECT) {
1189                                                 align_view_to_selected(v3d);
1190                                         }
1191                                 } else {
1192                                         if(G.obedit) {
1193                                                 if(G.obedit->type==OB_CURVE) {
1194                                                         sethandlesNurb(2);
1195                                                         makeDispList(G.obedit);
1196                                                         allqueue(REDRAWVIEW3D, 0);
1197                                                 }
1198                                         }
1199                                         else if(G.qual & LR_ALTKEY) image_aspect();
1200                                         else set_vpaint();
1201                                 }
1202                                 break;
1203                         case WKEY:
1204                                 if(G.qual & LR_SHIFTKEY) {
1205                                         transform('w');
1206                                 }
1207                                 else if(G.qual & LR_ALTKEY) {
1208                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1209                                 }
1210                                 else if(G.qual & LR_CTRLKEY) {
1211                                         if(G.obedit) {
1212                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1213                                                         switchdirectionNurb2();
1214                                                 }
1215                                         }
1216                                 }
1217                                 else special_editmenu();
1218                                 
1219                                 break;
1220                         case XKEY:
1221                         case DELKEY:
1222                                 delete_context_selected();
1223                                 break;
1224                         case YKEY:
1225                                 if(G.obedit) {
1226                                         if(G.obedit->type==OB_MESH) split_mesh();
1227                                 }
1228                                 break;
1229                         case ZKEY:
1230                                 toggle_shading();
1231                                 
1232                                 scrarea_queue_headredraw(curarea);
1233                                 scrarea_queue_winredraw(curarea);
1234                                 break;
1235                                 
1236                         
1237                         case HOMEKEY:
1238                                 view3d_home(0);
1239                                 break;
1240                         case COMMAKEY:
1241                                 G.vd->around= V3D_CENTRE;
1242                                 scrarea_queue_headredraw(curarea);
1243                                 break;
1244                                 
1245                         case PERIODKEY:
1246                                 G.vd->around= V3D_CURSOR;
1247                                 scrarea_queue_headredraw(curarea);
1248                                 break;
1249                         
1250                         case PADSLASHKEY:
1251                                 if(G.vd->localview) {
1252                                         G.vd->localview= 0;
1253                                         endlocalview(curarea);
1254                                 }
1255                                 else {
1256                                         G.vd->localview= 1;
1257                                         initlocalview();
1258                                 }
1259                                 scrarea_queue_headredraw(curarea);
1260                                 break;
1261                         case PADASTERKEY:       /* '*' */
1262                                 ob= OBACT;
1263                                 if(ob) {
1264                                         obmat_to_viewmat(ob);
1265                                         if(G.vd->persp==2) G.vd->persp= 1;
1266                                         scrarea_queue_winredraw(curarea);
1267                                 }
1268                                 break;
1269                         case PADPERIOD: /* '.' */
1270                                 centreview();
1271                                 break;
1272                         
1273                         case PAGEUPKEY:
1274                                 if(G.qual & LR_CTRLKEY) movekey_obipo(1);
1275                                 else nextkey_obipo(1);  /* in editipo.c */
1276                                 break;
1277
1278                         case PAGEDOWNKEY:
1279                                 if(G.qual & LR_CTRLKEY) movekey_obipo(-1);
1280                                 else nextkey_obipo(-1);
1281                                 break;
1282                                 
1283                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1284                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1285                         case PADMINUS: case PADPLUSKEY: case PADENTER:
1286                                 persptoetsen(event);
1287                                 doredraw= 1;
1288                                 break;
1289                         
1290                         case ESCKEY:
1291                                 if (G.vd->flag & V3D_DISPIMAGE) {
1292                                         G.vd->flag &= ~V3D_DISPIMAGE;
1293                                         doredraw= 1;
1294                                 }
1295                                 break;
1296                         }
1297                 }
1298         }
1299         
1300         if(doredraw) {
1301                 scrarea_queue_winredraw(curarea);
1302                 scrarea_queue_headredraw(curarea);
1303         }
1304 }
1305
1306 void initview3d(ScrArea *sa)
1307 {
1308         View3D *vd;
1309         
1310         vd= MEM_callocN(sizeof(View3D), "initview3d");
1311         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1312
1313         vd->spacetype= SPACE_VIEW3D;
1314         vd->viewquat[0]= 1.0;
1315         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1316         vd->persp= 1;
1317         vd->drawtype= OB_WIRE;
1318         vd->view= 7;
1319         vd->dist= 10.0;
1320         vd->lens= 35.0;
1321         vd->near= 0.01;
1322         vd->far= 500.0;
1323         vd->grid= 1.0;
1324         vd->gridlines= 16;
1325         vd->lay= vd->layact= 1;
1326         if(G.scene) {
1327                 vd->lay= vd->layact= G.scene->lay;
1328                 vd->camera= G.scene->camera;
1329         }
1330         vd->scenelock= 1;
1331 }
1332
1333
1334 /* ******************** SPACE: IPO ********************** */
1335
1336 static void changeview2dspace(ScrArea *sa, void *spacedata)
1337 {
1338         if(G.v2d==0) return;
1339
1340         test_view2d(G.v2d, curarea->winx, curarea->winy);
1341         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1342 }
1343
1344 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1345 {
1346         unsigned short event= evt->event;
1347         short val= evt->val;
1348         SpaceIpo *sipo= curarea->spacedata.first;
1349         View2D *v2d= &sipo->v2d;
1350         float dx, dy;
1351         int cfra, doredraw= 0;
1352         short mval[2];
1353         
1354         if(curarea->win==0) return;
1355
1356         if(val) {
1357                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
1358
1359                 switch(event) {
1360                 case UI_BUT_EVENT:
1361                         if(val>0) do_ipowin_buts(val-1);
1362                         break;
1363                 case LEFTMOUSE:
1364                         if( in_ipo_buttons() ) {
1365                                 do_ipo_selectbuttons();
1366                                 doredraw= 1;
1367                         }                       
1368                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1369                         else {
1370                                 do {
1371                                         getmouseco_areawin(mval);
1372                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1373                                         
1374                                         cfra= (int)dx;
1375                                         if(cfra< 1) cfra= 1;
1376                                         
1377                                         if( cfra!=CFRA ) {
1378                                                 CFRA= cfra;
1379                                                 update_for_newframe();
1380                                                 force_draw_plus(SPACE_VIEW3D);
1381                                                 force_draw_plus(SPACE_ACTION);
1382                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1383                                         }
1384                                 
1385                                 } while(get_mbut()&L_MOUSE);
1386                         }
1387                         
1388                         break;
1389                 case MIDDLEMOUSE:
1390                         if(in_ipo_buttons()) {
1391                                 scroll_ipobuts();
1392                         }
1393                         else view2dmove(event); /* in drawipo.c */
1394                         break;
1395
1396                 case WHEELUPMOUSE:
1397                 case WHEELDOWNMOUSE:
1398                         view2dmove(event);      /* in drawipo.c */
1399                         break;
1400
1401                 case RIGHTMOUSE:
1402                         mouse_select_ipo();
1403                         allqueue (REDRAWACTION, 0);
1404                         allqueue(REDRAWNLA, 0);
1405                         break;
1406                 case PADPLUSKEY:
1407                         view2d_zoom(v2d, 0.1154, curarea->winx, curarea->winy);
1408                         doredraw= 1;
1409                         break;
1410                 case PADMINUS:
1411                         view2d_zoom(v2d, -0.15, curarea->winx, curarea->winy);
1412                         doredraw= 1;
1413                         break;
1414                 case PAGEUPKEY:
1415                         if(G.qual & LR_CTRLKEY) movekey_ipo(1);
1416                         else nextkey_ipo(1);
1417                         break;
1418                 case PAGEDOWNKEY:
1419                         if(G.qual & LR_CTRLKEY) movekey_ipo(-1);
1420                         else nextkey_ipo(-1);
1421                         break;
1422                 case HOMEKEY:
1423                         do_ipo_buttons(B_IPOHOME);
1424                         break;
1425                         
1426                 case AKEY:
1427                         if(in_ipo_buttons()) {
1428                                 swap_visible_editipo();
1429                         }
1430                         else swap_selectall_editipo();
1431                         allspace (REMAKEIPO, 0);
1432                         allqueue (REDRAWNLA, 0);
1433                         allqueue (REDRAWACTION, 0);
1434                         break;
1435                 case BKEY:
1436                         borderselect_ipo();
1437                         break;
1438                 case CKEY:
1439                         move_to_frame();
1440                         break;
1441                 case DKEY:
1442                         if(G.qual & LR_SHIFTKEY) add_duplicate_editipo();
1443                         break;
1444                 case GKEY:
1445                         transform_ipo('g');
1446                         break;
1447                 case HKEY:
1448                         if(G.qual & LR_SHIFTKEY) sethandles_ipo(HD_AUTO);
1449                         else sethandles_ipo(HD_ALIGN);
1450                         break;
1451                 case JKEY:
1452                         join_ipo();
1453                         break;
1454                 case KKEY:
1455                         ipo_toggle_showkey();
1456                         scrarea_queue_headredraw(curarea);
1457                         allqueue(REDRAWVIEW3D, 0);
1458                         doredraw= 1;
1459                         break;
1460                 case RKEY:
1461                         ipo_record();
1462                         break;
1463                 case SKEY:
1464                         if(G.qual & LR_SHIFTKEY) ipo_snapmenu();
1465                         else transform_ipo('s');
1466                         break;
1467                 case TKEY:
1468                         set_ipotype();
1469                         break;
1470                 case VKEY:
1471                         sethandles_ipo(HD_VECT);
1472                         break;
1473                 case XKEY:
1474                 case DELKEY:
1475                         if(G.qual & LR_SHIFTKEY) delete_key();
1476                         else del_ipo();
1477                         break;
1478                 }
1479         }
1480
1481         if(doredraw) scrarea_queue_winredraw(curarea);
1482 }
1483
1484 void initipo(ScrArea *sa)
1485 {
1486         SpaceIpo *sipo;
1487         
1488         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1489         BLI_addhead(&sa->spacedata, sipo);
1490
1491         sipo->spacetype= SPACE_IPO;
1492         /* sipo space loopt van (0,-?) tot (??,?) */
1493         sipo->v2d.tot.xmin= 0.0;
1494         sipo->v2d.tot.ymin= -10.0;
1495         sipo->v2d.tot.xmax= G.scene->r.efra;
1496         sipo->v2d.tot.ymax= 10.0;
1497
1498         sipo->v2d.cur= sipo->v2d.tot;
1499
1500         sipo->v2d.min[0]= 0.01;
1501         sipo->v2d.min[1]= 0.01;
1502
1503         sipo->v2d.max[0]= 15000.0;
1504         sipo->v2d.max[1]= 10000.0;
1505         
1506         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1507         sipo->v2d.keeptot= 0;
1508
1509         sipo->blocktype= ID_OB;
1510 }
1511
1512 /* ******************** SPACE: INFO ********************** */
1513
1514 void space_mipmap_button_function(int event) {
1515         set_mipmap(!(U.gameflags & USERDEF_DISABLE_MIPMAP));
1516
1517         allqueue(REDRAWVIEW3D, 0);
1518 }
1519
1520 void space_sound_button_function(int event)
1521 {
1522         int a;
1523         SYS_SystemHandle syshandle;
1524
1525         if ((syshandle = SYS_GetSystem()))
1526         {
1527                 a = (U.gameflags & USERDEF_DISABLE_SOUND);
1528                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1529         }
1530 }
1531
1532 #define B_ADD_THEME     3301
1533 #define B_DEL_THEME     3302
1534 #define B_NAME_THEME    3303
1535 #define B_THEMECOL              3304
1536 #define B_UPDATE_THEME  3305
1537 #define B_CHANGE_THEME  3306
1538 #define B_THEME_COPY    3307
1539 #define B_THEME_PASTE   3308
1540
1541
1542 // needed for event; choose new 'curmain' resets it...
1543 static short th_curcol= TH_BACK;
1544 static char *th_curcol_ptr= NULL;
1545 static char th_curcol_arr[4]={0, 0, 0, 255};
1546
1547 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1548 {
1549         bTheme *btheme, *bt;
1550         int spacetype= 0;
1551         static short cur=1, curmain=2;
1552         short a, tot=0, isbuiltin= 0;
1553         char string[20*32], *strp;
1554         
1555         y3= y2+23;      // exception!
1556         
1557         /* count total, max 16! */
1558         for(bt= U.themes.first; bt; bt= bt->next) tot++;
1559         
1560         /* if cur not is 1; move that to front of list */
1561         if(cur!=1) {
1562                 a= 1;
1563                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
1564                         if(a==cur) {
1565                                 BLI_remlink(&U.themes, bt);
1566                                 BLI_addhead(&U.themes, bt);
1567                                 cur= 1;
1568                                 break;
1569                         }
1570                 }
1571         }
1572         
1573         /* the current theme */
1574         btheme= U.themes.first;
1575         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
1576
1577         /* construct popup script */
1578         string[0]= 0;
1579         for(bt= U.themes.first; bt; bt= bt->next) {
1580                 strcat(string, bt->name);
1581                 if(btheme->next) strcat(string, "   |");
1582         }
1583         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
1584         
1585         /* add / delete / name */
1586         uiBlockSetCol(block, BUTSALMON);
1587         if(tot<16)
1588                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
1589         if(tot>1 && isbuiltin==0)
1590                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
1591         uiBlockSetCol(block, BUTGREY);
1592
1593         if(isbuiltin) return;
1594         
1595         /* name */
1596         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
1597
1598         /* main choices pup */
1599         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|3D View %x2|Ipo Window %x3|Buttons Window %x4|File Select %x5",
1600                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
1601         if(curmain==2) spacetype= SPACE_VIEW3D;
1602         if(curmain==3) spacetype= SPACE_IPO;
1603         if(curmain==4) spacetype= SPACE_BUTS;
1604         if(curmain==5) spacetype= SPACE_FILE;
1605
1606         /* color choices pup */
1607         if(curmain==1) strp= BIF_ThemeColorsPup(0);
1608         else strp= BIF_ThemeColorsPup(spacetype);
1609         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
1610         MEM_freeN(strp);
1611         
1612         /* always make zero, ugly global... */
1613         th_curcol_ptr= NULL;
1614         
1615         /* sliders */
1616         if(curmain==1);
1617         else {
1618                 char *col;
1619                 
1620                 th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
1621                 
1622                 if(col && th_curcol==TH_VERTEX_SIZE) {
1623                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, B_THEMECOL, 0, "");
1624                 
1625                 }
1626                 else if(col) {
1627                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
1628                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
1629                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
1630
1631                         uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
1632                         
1633                         if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
1634                                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
1635                         }
1636                         
1637                         /* copy paste */
1638                         uiBlockSetCol(block, BUTSALMON);
1639                         uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
1640                         uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
1641
1642                         uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
1643                         
1644                 }
1645         }
1646         
1647         
1648         
1649         uiClearButLock();
1650 }
1651
1652
1653 void drawinfospace(ScrArea *sa, void *spacedata)
1654 {
1655         uiBlock *block;
1656         float fac;
1657         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
1658         short smallprefbut, medprefbut, largeprefbut, smfileselbut;
1659         short edgespace, midspace;
1660         char naam[32];
1661
1662         if(curarea->win==0) return;
1663
1664         glClearColor(0.6, 0.6, 0.6, 0.0); 
1665         glClear(GL_COLOR_BUFFER_BIT);
1666
1667         fac= ((float)curarea->winx)/1280.0;
1668         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
1669         
1670         sprintf(naam, "infowin %d", curarea->win);
1671         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSSX, UI_HELV, curarea->win);
1672
1673
1674         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
1675
1676         xpos = 45;              /* left padding */
1677         ypos = 50;              /* bottom padding for buttons */
1678         ypostab = 10;           /* bottom padding for 'tab' row */
1679
1680
1681         buth = 20;              /* standard button height */
1682
1683         smallprefbut = 94;      /* standard size for small preferences button */
1684         medprefbut = 193;       /* standard size for medium preferences button */
1685         largeprefbut = 292;     /* standard size for large preferences button */
1686         smfileselbut = buth;    /* standard size for fileselect button (square) */
1687         
1688         edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
1689         midspace = 5;           /* horizontal space between buttons */
1690
1691         rspace = 3;             /* default space between rows */
1692
1693         y1 = ypos;              /* bottom padding of 1st (bottom) button row */
1694         y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
1695         y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
1696         y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
1697
1698         y2label = y2-2;         /* adjustments to offset the labels down to align better */
1699         y3label = y3-(3*rspace)-2;      /* again for 3rd row */
1700         y4label = y4-2;         /* again for 4th row */
1701
1702
1703         /* set the colour to blue and draw the main 'tab' controls */
1704
1705         uiBlockSetCol(block, BUTBLUE);
1706
1707         uiDefButI(block, ROW,B_USERPREF,"View & Controls",
1708                 xpos,ypostab,(short)dx,buth,
1709                 &U.userpref,1.0,0.0, 0, 0,"");
1710                 
1711         uiDefButI(block, ROW,B_USERPREF,"Edit Methods",
1712                 (short)(xpos+dx),ypostab,(short)dx,buth,
1713                 &U.userpref,1.0,1.0, 0, 0,"");
1714
1715         uiDefButI(block, ROW,B_USERPREF,"Language & Font",
1716                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
1717                 &U.userpref,1.0,2.0, 0, 0,"");
1718
1719         uiDefButI(block, ROW,B_USERPREF,"Themes",
1720                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
1721                 &U.userpref,1.0,6.0, 0, 0,"");
1722
1723         uiDefButI(block, ROW,B_USERPREF,"Auto Save",
1724                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
1725                 &U.userpref,1.0,3.0, 0, 0,"");
1726
1727         uiDefButI(block, ROW,B_USERPREF,"System & OpenGL",
1728                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
1729                 &U.userpref,1.0,4.0, 0, 0,"");
1730                 
1731         uiDefButI(block, ROW,B_USERPREF,"File Paths",
1732                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
1733                 &U.userpref,1.0,5.0, 0, 0,"");
1734
1735         uiBlockSetEmboss(block, UI_EMBOSSX);
1736         uiBlockSetCol(block, BUTGREY);
1737
1738         /* end 'tab' controls */
1739
1740         /* line 2: left x co-ord, top y co-ord, width, height */
1741
1742         if(U.userpref == 6) {
1743                 info_user_themebuts(block, y1, y2, y3);
1744         }
1745         else if (U.userpref == 0) { /* view & controls */
1746
1747                 uiDefBut(block, LABEL,0,"Display:",
1748                         xpos,y3label,medprefbut,buth,
1749                         0, 0, 0, 0, 0, "");
1750
1751                 uiDefButS(block, TOG|BIT|11, 0, "ToolTips",
1752                         (xpos+edgespace),y2,smallprefbut,buth,
1753                         &(U.flag), 0, 0, 0, 0,
1754                         "Displays tooltips (help tags) over buttons");
1755
1756                 uiDefButS(block, TOG|BIT|4, B_DRAWINFO, "Object Info",
1757                         (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
1758                         &(U.uiflag), 0, 0, 0, 0,
1759                         "Displays current object name and frame number in the 3D viewport");
1760
1761                 uiDefButS(block, TOG|BIT|4, 0, "Global Scene",
1762                         (xpos+edgespace),y1,medprefbut,buth,
1763                         &(U.flag), 0, 0, 0, 0,
1764                         "Forces the current Scene to be displayed in all Screens");
1765
1766
1767                 uiDefBut(block, LABEL,0,"Snap to grid:",
1768                         (xpos+edgespace+medprefbut),y3label,medprefbut,buth,
1769                         0, 0, 0, 0, 0, "");
1770
1771                 uiDefButS(block, TOG|BIT|1, 0, "Grab",
1772                         (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
1773                         &(U.flag), 0, 0, 0, 0,
1774                         "Move objects to grid units");
1775
1776                 uiDefButS(block, TOG|BIT|3, 0, "Size",
1777                         (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
1778                         &(U.flag), 0, 0, 0, 0,
1779                         "Scale objects to grid units");
1780
1781                 uiDefButS(block, TOG|BIT|2, 0, "Rotate",
1782                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y2,smallprefbut,buth,
1783                         &(U.flag), 0, 0, 0, 0,
1784                         "Rotate objects to grid units");
1785
1786
1787
1788                 uiBlockSetCol(block, BUTGREEN);
1789
1790                 uiDefBut(block, LABEL,0,"Menu Buttons:",
1791                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3label,medprefbut,buth,
1792                         0, 0, 0, 0, 0, "");
1793
1794                 uiDefButS(block, TOG|BIT|9, 0, "Auto Open",
1795                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
1796                         &(U.uiflag), 0, 0, 0, 0,
1797                         "Automatic opening of menu buttons");
1798
1799                 uiBlockSetCol(block, BUTGREY);
1800
1801                 uiDefButS(block, NUM, 0, "ThresA:",
1802                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
1803                         &(U.menuthreshold1), 1, 40, 0, 0,
1804                         "Time in 1/10 seconds for auto open");
1805
1806                 uiDefButS(block, NUM, 0, "ThresB:",
1807                         (xpos+edgespace+medprefbut+(4*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
1808                         &(U.menuthreshold2), 1, 40, 0, 0,
1809                         "Time in 1/10 seconds for auto open sublevels");
1810                         
1811
1812                 uiBlockSetCol(block, BUTGREEN);
1813
1814                 uiDefButS(block, TOGN|BIT|10, B_DRAWINFO, "Rotate View",
1815                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
1816                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
1817
1818                 uiDefButS(block, TOG|BIT|10, B_DRAWINFO, "Pan View",
1819                         (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
1820                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
1821
1822                 uiBlockSetCol(block, BUTGREY);
1823                 
1824                 uiDefBut(block, LABEL,0,"Middle mouse button:",
1825                         (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
1826                         0, 0, 0, 0, 0, "");
1827                 uiDefButS(block, TOG|BIT|12, 0, "Emulate 3 Buttons",
1828                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
1829                         &(U.flag), 0, 0, 0, 0,
1830                         "Emulates a middle mouse button with ALT+LeftMouse");
1831
1832
1833
1834                 uiDefBut(block, LABEL,0,"View rotation method:",
1835                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
1836                         0, 0, 0, 0, 0, "");
1837
1838                 uiBlockSetCol(block, BUTGREEN);
1839
1840                 uiDefButS(block, TOG|BIT|5, B_DRAWINFO, "Trackball",
1841                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,(smallprefbut+2),buth,
1842                         &(U.flag), 0, 0, 0, 0,
1843                         "Use trackball style rotation with middle mouse button");
1844
1845                 uiDefButS(block, TOGN|BIT|5, B_DRAWINFO, "Turntable",
1846                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
1847                         &(U.flag), 0, 0, 0, 0,
1848                         "Use turntable style rotation with middle mouse button");
1849
1850                 uiBlockSetCol(block, BUTGREY);
1851
1852                 uiDefBut(block, LABEL,0,"Mousewheel:",
1853                         (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
1854                         0, 0, 0, 0, 0, "");
1855                 uiDefButS(block, TOG|BIT|2, 0, "Invert Wheel Zoom",
1856                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,medprefbut,buth,
1857                         &(U.uiflag), 0, 0, 0, 0,
1858                         "Swaps mouse wheel zoom direction");
1859
1860
1861                 uiDefButI(block, NUM, 0, "Scroll Lines:",
1862                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,medprefbut,buth,
1863                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
1864                         "The number of lines scrolled at a time with the mouse wheel");
1865
1866
1867         } else if (U.userpref == 1) { /* edit methods */
1868
1869
1870                 uiDefBut(block, LABEL,0,"Material linked to:",
1871                         xpos,y3label,medprefbut,buth,
1872                         0, 0, 0, 0, 0, "");
1873
1874                 uiBlockSetCol(block, BUTGREEN);
1875
1876                 uiDefButS(block, TOGN|BIT|8, B_DRAWINFO, "ObData",
1877                         (xpos+edgespace),y2,(smallprefbut+2),buth,
1878                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
1879
1880                 uiDefButS(block, TOG|BIT|8, B_DRAWINFO, "Object",
1881                         (xpos+edgespace+smallprefbut+2),y2,(smallprefbut+2),buth,
1882                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
1883
1884                 uiBlockSetCol(block, BUTGREY);
1885
1886
1887
1888                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
1889                         (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
1890                         0, 0, 0, 0, 0, "");
1891
1892                 uiDefButS(block, TOG|BIT|0, 0, "Action",
1893                         (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
1894                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
1895
1896                 uiDefButS(block, TOG|BIT|1, 0, "Object",
1897                         (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
1898                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
1899
1900
1901
1902                 uiDefBut(block, LABEL,0,"Duplicate with object:",
1903                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
1904                         0, 0, 0, 0, 0, "");
1905
1906                 uiDefButS(block, TOG|BIT|0, 0, "Mesh",
1907                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
1908                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
1909                 uiDefButS(block, TOG|BIT|9, 0, "Armature",
1910                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
1911                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
1912
1913                 uiDefButS(block, TOG|BIT|2, 0, "Surface",
1914                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
1915                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
1916                 uiDefButS(block, TOG|BIT|5, 0, "Lamp",
1917                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
1918                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
1919
1920                 uiDefButS(block, TOG|BIT|1, 0, "Curve",
1921                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
1922                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
1923                 uiDefButS(block, TOG|BIT|7, 0, "Material",
1924                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
1925                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
1926
1927                 uiDefButS(block, TOG|BIT|3, 0, "Text",
1928                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
1929                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
1930                 uiDefButS(block, TOG|BIT|8, 0, "Texture",
1931                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
1932                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
1933
1934                 uiDefButS(block, TOG|BIT|4, 0, "Metaball",
1935                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
1936                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
1937                 uiDefButS(block, TOG|BIT|6, 0, "Ipo",
1938                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
1939                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
1940
1941
1942         } else if(U.userpref == 2) { /* language & colors */
1943
1944 #ifdef INTERNATIONAL
1945                 char curfont[64];
1946
1947                 sprintf(curfont, "Interface Font: ");
1948                 strcat(curfont,U.fontname);
1949
1950                 uiDefButS(block, TOG|BIT|5, B_DOLANGUIFONT, "International Fonts",
1951                         xpos,y2,medprefbut,buth,
1952                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
1953
1954                 if(U.transopts & TR_ALL) {
1955                         uiDefBut(block, LABEL,0,curfont,
1956                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
1957                                 0, 0, 0, 0, 0, "");
1958
1959                         uiBlockSetCol(block, BUTSALMON);
1960         
1961                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
1962                                 xpos,y1,medprefbut,buth,
1963                                 0, 0, 0, 0, 0, "Select a new font for the interface");
1964
1965                         uiBlockSetCol(block, BUTGREY);
1966
1967
1968                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
1969                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
1970                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
1971
1972 /*
1973                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
1974                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
1975                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
1976
1977
1978                         uiDefBut(block, LABEL,0,"Translate:",
1979                                 (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
1980                                 0, 0, 0, 0, 0, "");
1981 */
1982
1983                         uiDefButS(block, TOG|BIT|0, B_SETTRANSBUTS, "Tooltips",
1984                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
1985                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
1986
1987                         uiDefButS(block, TOG|BIT|1, B_SETTRANSBUTS, "Buttons",
1988                                 (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
1989                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
1990
1991                         uiDefButS(block, TOG|BIT|2, B_SETTRANSBUTS, "Toolbox",
1992                                 (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
1993                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
1994
1995                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
1996                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
1997                                 &U.language, 0, 0, 0, 0, "Select interface language");
1998                                 
1999                         /* uiDefButS(block, TOG|BIT|3, B_SETTRANSBUTS, "FTF All windows",
2000                                 (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2001                                 &(U.transopts), 0, 0, 0, 0,
2002                                 "Use FTF drawing for fileselect and textwindow "
2003                                 "(under construction)");
2004                         */
2005                 }
2006
2007 /* end of INTERNATIONAL */
2008 #endif
2009
2010         } else if(U.userpref == 3) { /* auto save */
2011
2012
2013                 uiDefButS(block, TOG|BIT|0, B_RESETAUTOSAVE, "Auto Save Temp Files",
2014                         (xpos+edgespace),y2,medprefbut,buth,
2015                         &(U.flag), 0, 0, 0, 0,
2016                         "Enables automatic saving of temporary files");
2017
2018                 if(U.flag & AUTOSAVE) {
2019                         uiBlockSetCol(block, BUTSALMON);
2020
2021                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2022                                 (xpos+edgespace),y1,medprefbut,buth,
2023                                 0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
2024
2025                         uiBlockSetCol(block, BUTGREY);
2026
2027
2028                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2029                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2030                                 &(U.savetime), 1.0, 60.0, 0, 0,
2031                                 "The time (in minutes) to wait between automatic temporary saves");
2032
2033                         uiDefButS(block, NUM, 0, "Versions:",
2034                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2035                                 &U.versions, 0.0, 32.0, 0, 0,
2036                                 "The number of old versions to maintain when saving");
2037                 }
2038
2039         } else if (U.userpref == 4) { /* system & opengl */
2040
2041
2042 /*
2043                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2044                         (xpos+edgespace),y2,largeprefbut,buth,
2045                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2046
2047                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2048                         (xpos+edgespace), y1, largeprefbut,buth,
2049                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2050
2051                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2052                         (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
2053                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2054 */
2055
2056 #ifdef _WIN32
2057                 uiDefBut(block, LABEL,0,"Win Codecs:",
2058                         (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
2059                         0, 0, 0, 0, 0, "");
2060
2061                 uiDefButS(block, TOG|BIT|8, 0, "Enable all codecs",
2062                         (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
2063                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2064 #endif
2065
2066                 uiDefBut(block, LABEL,0,"Keyboard:",
2067                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2068                         0, 0, 0, 0, 0, "");
2069
2070                 uiDefButS(block, TOG|BIT|9, B_U_CAPSLOCK, "Disable Caps Lock",
2071                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
2072                         &(U.flag), 0, 0, 0, 0,
2073                         "Disables the Caps Lock key when entering text");
2074
2075                 uiDefButS(block, TOG|BIT|13, 0, "Emulate Numpad",
2076                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
2077                         &(U.flag), 0, 0, 0, 0,
2078                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2079
2080
2081                 uiDefBut(block, LABEL,0,"System:",
2082                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2083                         0, 0, 0, 0, 0, "");
2084
2085                 uiDefButI(block, TOG|BIT|USERDEF_DISABLE_SOUND_BIT, B_SOUNDTOGGLE, "Disable Sound",
2086                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
2087                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2088
2089                 uiDefButS(block, TOG|BIT|3, 0, "Filter File Extensions",
2090                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2091                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2092
2093
2094                 uiDefBut(block, LABEL,0,"OpenGL:",
2095                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2096                         0, 0, 0, 0, 0, "");
2097
2098                 uiDefButI(block, TOGN|BIT|USERDEF_DISABLE_MIPMAP_BIT, B_MIPMAPCHANGED, "Mipmaps",
2099                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
2100                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2101
2102                 uiDefButI(block, TOG|BIT|USERDEF_VERTEX_ARRAYS_BIT, 0, "Vertex Arrays",
2103                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
2104                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2105
2106                 uiDefBut(block, LABEL,0,"Audio:",
2107                         (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
2108                         0, 0, 0, 0, 0, "");
2109
2110                 uiDefButI(block, ROW, 0, "Mixing buffer 256", (xpos+edgespace+(2*midspace)+(2*medprefbut)),y2,medprefbut,buth, &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio buffer size to 256 samples");
2111                 uiDefButI(block, ROW, 0, "512", (xpos+edgespace+(2*midspace)+(2*medprefbut)),y1,61,buth, &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio buffer size to 512 samples");      
2112                 uiDefButI(block, ROW, 0, "1024", (xpos+edgespace+(2*midspace)+(2*medprefbut))+61+midspace,y1,61,buth, &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio buffer size to 1024 samples");               
2113                 uiDefButI(block, ROW, 0, "2048", (xpos+edgespace+(2*midspace)+(2*medprefbut))+2*(61+midspace),y1,61,buth, &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio buffer size to 2048 samples");                   
2114
2115         } else if(U.userpref == 5) { /* file paths */
2116
2117
2118                 uiDefBut(block, TEX, 0, "Fonts: ",
2119                         (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
2120                         U.fontdir, 1.0, 63.0, 0, 0,
2121                         "The default directory to search for loading fonts");
2122                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2123                         (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
2124                         0, 0, 0, 0, 0, "Select the default font directory");
2125
2126                 uiDefBut(block, TEX, 0, "Textures: ",
2127                         (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
2128                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2129                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2130                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
2131                         0, 0, 0, 0, 0, "Select the default texture location");
2132
2133
2134                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2135                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
2136                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2137                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2138                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
2139                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2140
2141                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2142                         (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
2143                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2144                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2145                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
2146                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2147
2148
2149                 uiDefBut(block, TEX, 0, "Render: ",
2150                         (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
2151                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2152                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2153                         (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
2154                         0, 0, 0, 0, 0, "Select the default render output location");
2155
2156                 uiDefBut(block, TEX, 0, "Python: ",
2157                         (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-smfileselbut),buth,
2158                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2159                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2160                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
2161                         0, 0, 0, 0, 0, "Select the default Python script location");
2162
2163
2164                 uiDefBut(block, TEX, 0, "Sounds: ",
2165                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
2166                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2167                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2168                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
2169                         0, 0, 0, 0, 0, "Select the default sound location");
2170
2171                 uiDefBut(block, TEX, 0, "Temp: ",
2172                          (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
2173                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2174                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2175                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
2176                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2177
2178         }
2179
2180         uiDrawBlock(block);
2181         
2182         myortho2(-0.5, (float)(sa->winx)-.05, -0.5, (float)(sa->winy)-0.5);
2183         draw_area_emboss(sa);
2184         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2185         sa->win_swap= WIN_BACK_OK;
2186         
2187 }
2188
2189
2190 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2191 {
2192         unsigned short event= evt->event;
2193         short val= evt->val;
2194         
2195         if(val) {
2196                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2197
2198                 switch(event) {
2199                 case UI_BUT_EVENT:
2200                         if(val==B_ADD_THEME) {
2201                                 bTheme *btheme, *new;
2202                                 
2203                                 btheme= U.themes.first;
2204                                 new= MEM_callocN(sizeof(bTheme), "theme");
2205                                 memcpy(new, btheme, sizeof(bTheme));
2206                                 BLI_addhead(&U.themes, new);
2207                                 strcpy(new->name, "New User Theme");
2208                                 addqueue(sa->win, REDRAW, 1);
2209                         }
2210                         else if(val==B_DEL_THEME) {
2211                                 bTheme *btheme= U.themes.first;
2212                                 BLI_remlink(&U.themes, btheme);
2213                                 MEM_freeN(btheme);
2214                                 addqueue(sa->win, REDRAW, 1);
2215                         }
2216                         else if(val==B_NAME_THEME) {
2217                                 bTheme *btheme= U.themes.first;
2218                                 if(strcmp(btheme->name, "Default")==0) {
2219                                         strcpy(btheme->name, "New User Theme");
2220                                         addqueue(sa->win, REDRAW, 1);
2221                                 }
2222                         }
2223                         else if(val==B_UPDATE_THEME) {
2224                                 allqueue(REDRAWALL, 0);
2225                         }
2226                         else if(val==B_CHANGE_THEME) {
2227                                 th_curcol= TH_BACK;     // backdrop color is always there...
2228                                 addqueue(sa->win, REDRAW, 1);
2229                         }
2230                         else if(val==B_THEME_COPY) {
2231                                 if(th_curcol_ptr) {
2232                                         th_curcol_arr[0]= th_curcol_ptr[0];
2233                                         th_curcol_arr[1]= th_curcol_ptr[1];
2234                                         th_curcol_arr[2]= th_curcol_ptr[2];
2235                                         th_curcol_arr[3]= th_curcol_ptr[3];
2236                                         addqueue(sa->win, REDRAW, 1);
2237                                 }
2238                         }
2239                         else if(val==B_THEME_PASTE) {
2240                                 if(th_curcol_ptr) {
2241                                         th_curcol_ptr[0]= th_curcol_arr[0];
2242                                         th_curcol_ptr[1]= th_curcol_arr[1];
2243                                         th_curcol_ptr[2]= th_curcol_arr[2];
2244                                         th_curcol_ptr[3]= th_curcol_arr[3];
2245                                         allqueue(REDRAWALL, 0);
2246                                 }
2247                         }
2248                         else do_global_buttons(val);
2249                         
2250                         break;  
2251                 }
2252         }
2253 }
2254
2255 void init_infospace(ScrArea *sa)
2256 {
2257         SpaceInfo *sinfo;
2258         
2259         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2260         BLI_addhead(&sa->spacedata, sinfo);
2261
2262         sinfo->spacetype=SPACE_INFO;
2263 }
2264
2265 /* ******************** SPACE: BUTS ********************** */
2266
2267 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2268
2269 static void changebutspace(ScrArea *sa, void *spacedata)
2270 {
2271         if(G.v2d==0) return;
2272         
2273         test_view2d(G.v2d, curarea->winx, curarea->winy);
2274         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin-0.6, G.v2d->cur.ymax+0.6);
2275 }
2276
2277 void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2278 {
2279         unsigned short event= evt->event;
2280         short val= evt->val;
2281         SpaceButs *sbuts= curarea->spacedata.first;
2282         ScrArea *sa2, *sa3d;
2283         int nr, doredraw= 0;
2284
2285         if(val) {
2286                 
2287                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2288
2289                 switch(event) {
2290                 case UI_BUT_EVENT:
2291                         do_butspace(val);
2292                         break;
2293                         
2294                 case MIDDLEMOUSE:
2295                 case WHEELUPMOUSE:
2296                 case WHEELDOWNMOUSE:
2297                         view2dmove(event);      /* in drawipo.c */
2298                         break;
2299                 case PAGEUPKEY:
2300                         event= WHEELUPMOUSE;
2301                         view2dmove(event);      /* in drawipo.c */
2302                         break;
2303                 case PAGEDOWNKEY:
2304                         event= WHEELDOWNMOUSE;
2305                         view2dmove(event);      /* in drawipo.c */
2306                         break;
2307                         
2308                 case RIGHTMOUSE:
2309                         nr= pupmenu("Align buttons%t|Free %x0|Horizontal%x1|Vertical%x2");
2310                         if (nr>=0) {
2311                                 sbuts->align= nr;
2312                                 if(nr) {
2313                                         uiAlignPanelStep(sa, 1.0);
2314                                         do_buts_buttons(B_BUTSHOME);
2315                                 }
2316                         }
2317
2318                         break;
2319                 case PADPLUSKEY:
2320                         view2d_zoom(&sbuts->v2d, 0.06, curarea->winx, curarea->winy);
2321                         scrarea_queue_winredraw(curarea);
2322                         break;
2323                 case PADMINUS:
2324                         view2d_zoom(&sbuts->v2d, -0.075, curarea->winx, curarea->winy);
2325                         scrarea_queue_winredraw(curarea);
2326                         break;
2327                 case RENDERPREVIEW:
2328                         BIF_previewrender(sbuts);
2329                         break;
2330                 
2331                 case HOMEKEY:
2332                         do_buts_buttons(B_BUTSHOME);
2333                         break;
2334
2335
2336                 /* if only 1 view, also de persp, excluding arrowkeys */
2337                 case PAD0: case PAD1: case PAD3:
2338                 case PAD5: case PAD7: case PAD9:
2339                 case PADENTER: case ZKEY: case PKEY:
2340                         sa3d= 0;
2341                         sa2= G.curscreen->areabase.first;
2342                         while(sa2) {
2343                                 if(sa2->spacetype==SPACE_VIEW3D) {
2344                                         if(sa3d) return;
2345                                         sa3d= sa2;
2346                                 }
2347                                 sa2= sa2->next;
2348                         }
2349                         if(sa3d) {
2350                                 sa= curarea;
2351                                 areawinset(sa3d->win);
2352                                 
2353                                 if(event==PKEY) start_game();
2354                                 else if(event==ZKEY) toggle_shading();
2355                                 else persptoetsen(event);
2356                                 
2357                                 scrarea_queue_winredraw(sa3d);
2358                                 scrarea_queue_headredraw(sa3d);
2359                                 areawinset(sa->win);
2360                         }
2361                 }
2362         }
2363
2364         if(doredraw) scrarea_queue_winredraw(curarea);
2365 }
2366
2367 void set_rects_butspace(SpaceButs *buts)
2368 {
2369         /* buts space goes from (0,0) to (1280, 228) */
2370
2371         buts->v2d.tot.xmin= 0.0;
2372         buts->v2d.tot.ymin= 0.0;
2373         buts->v2d.tot.xmax= 1279.0;
2374         buts->v2d.tot.ymax= 228.0;
2375         
2376         buts->v2d.min[0]= 256.0;
2377         buts->v2d.min[1]= 42.0;
2378
2379         buts->v2d.max[0]= 2048.0;
2380         buts->v2d.max[1]= 450.0;
2381         
2382         buts->v2d.minzoom= 0.5;
2383         buts->v2d.maxzoom= 1.21;
2384         
2385         buts->v2d.scroll= 0;
2386         buts->v2d.keepaspect= 1;
2387         buts->v2d.keepzoom= 1;
2388         buts->v2d.keeptot= 1;
2389         
2390 }
2391
2392 void test_butspace(void)
2393 {
2394         ScrArea *area= curarea;
2395         int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
2396         
2397         G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
2398 }
2399
2400 void init_butspace(ScrArea *sa)
2401 {
2402         SpaceButs *buts;
2403         
2404         buts= MEM_callocN(sizeof(SpaceButs), "initbuts");
2405         BLI_addhead(&sa->spacedata, buts);
2406
2407         buts->spacetype= SPACE_BUTS;
2408         buts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
2409
2410         /* set_rects only does defaults, so after reading a file the cur has not changed */
2411         set_rects_butspace(buts);
2412         buts->v2d.cur= buts->v2d.tot;
2413 }
2414
2415 void extern_set_butspace(int fkey)
2416 {
2417         ScrArea *sa;
2418         SpaceButs *sbuts;
2419         
2420         /* when a f-key pressed: closest button window is initialized */
2421         if(curarea->spacetype==SPACE_BUTS) sa= curarea;
2422         else {
2423                 /* find area */
2424                 sa= G.curscreen->areabase.first;
2425                 while(sa) {
2426                         if(sa->spacetype==SPACE_BUTS) break;
2427                         sa= sa->next;
2428                 }
2429         }
2430         
2431         if(sa==0) return;
2432         
2433         if(sa!=curarea) areawinset(sa->win);
2434         
2435         sbuts= sa->spacedata.first;
2436         
2437         if(fkey==F4KEY) {
2438                 sbuts->mainb= CONTEXT_LOGIC;
2439         }
2440         else if(fkey==F5KEY) {
2441                 sbuts->mainb= CONTEXT_SHADING;
2442                 if(OBACT) {
2443                         if(OBACT->type==OB_CAMERA) 
2444                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2445                         else if(OBACT->type==OB_LAMP) 
2446                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
2447                         else  
2448                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2449                 }
2450                 else sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2451         }
2452         else if(fkey==F6KEY) {
2453                 sbuts->mainb= CONTEXT_SHADING;
2454                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
2455         }
2456         else if(fkey==F7KEY) sbuts->mainb= CONTEXT_OBJECT;
2457         else if(fkey==F8KEY) {
2458                 sbuts->mainb= CONTEXT_SHADING;
2459                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2460         }
2461         else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
2462         else if(fkey==F10KEY) sbuts->mainb= CONTEXT_SCENE;
2463
2464         scrarea_queue_headredraw(sa);
2465         scrarea_queue_winredraw(sa);
2466         BIF_preview_changed(sbuts);
2467 }
2468
2469 /* ******************** SPACE: SEQUENCE ********************** */
2470
2471 /*  extern void drawseqspace(ScrArea *sa, void *spacedata); BIF_drawseq.h */
2472
2473 void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2474 {
2475         unsigned short event= evt->event;
2476         short val= evt->val;
2477         SpaceSeq *sseq= curarea->spacedata.first;
2478         View2D *v2d= &sseq->v2d;
2479         extern Sequence *last_seq;
2480         float dx, dy;
2481         int doredraw= 0, cfra, first;
2482         short mval[2];
2483         
2484         if(curarea->win==0) return;
2485
2486         if(val) {
2487                 
2488                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2489
2490                 switch(event) {
2491                 case LEFTMOUSE:
2492                         if(sseq->mainb || view2dmove(event)==0) {
2493                                 
2494                                 first= 1;               
2495                                 set_special_seq_update(1);
2496
2497                                 do {
2498                                         getmouseco_areawin(mval);
2499                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
2500                                         
2501                                         cfra= (int)dx;
2502                                         if(cfra< 1) cfra= 1;
2503                                         /* else if(cfra> EFRA) cfra= EFRA; */
2504                                         
2505                                         if( cfra!=CFRA || first ) {
2506                                                 first= 0;
2507                                 
2508                                                 CFRA= cfra;
2509                                                 force_draw();
2510                                                 update_for_newframe();  /* for audio scrubbing */                                               
2511                                         }
2512                                 
2513                                 } while(get_mbut()&L_MOUSE);
2514                                 
2515                                 set_special_seq_update(0);
2516                                 
2517                                 update_for_newframe();
2518                         }
2519                         break;
2520                 case MIDDLEMOUSE:
2521                 case WHEELUPMOUSE:
2522                 case WHEELDOWNMOUSE:
2523                         if(sseq->mainb) break;
2524                         view2dmove(event);      /* in drawipo.c */
2525                         break;
2526                 case RIGHTMOUSE:
2527                         if(sseq->mainb) break;
2528                         mouse_select_seq();
2529                         break;
2530                 case PADPLUSKEY:
2531                         if(sseq->mainb) {
2532                                 sseq->zoom++;
2533                                 if(sseq->zoom>8) sseq->zoom= 8;
2534                         }
2535                         else {
2536                                 if(G.qual) {
2537                                         if(G.qual & LR_SHIFTKEY) insert_gap(25, CFRA);
2538                                         else if(G.qual & LR_ALTKEY) insert_gap(250, CFRA);
2539                                         allqueue(REDRAWSEQ, 0);
2540                                 }
2541                                 else {
2542                                         dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
2543                                         v2d->cur.xmin+= dx;
2544                                         v2d->cur.xmax-= dx;
2545                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2546                                 }
2547                         }
2548                         doredraw= 1;
2549                         break;
2550                 case PADMINUS:
2551                         if(sseq->mainb) {
2552                                 sseq->zoom--;
2553                                 if(sseq->zoom<1) sseq->zoom= 1;
2554                         }
2555                         else {
2556                                 if(G.qual) {
2557                                         if(G.qual & LR_SHIFTKEY) no_gaps();
2558                                 }
2559                                 else {
2560                                         dx= 0.15*(v2d->cur.xmax-v2d->cur.xmin);
2561                                         v2d->cur.xmin-= dx;
2562                                         v2d->cur.xmax+= dx;
2563                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2564                                 }
2565                         }
2566                         doredraw= 1;
2567                         break;
2568                 case HOMEKEY:
2569                         do_seq_buttons(B_SEQHOME);
2570                         break;
2571                 case PADPERIOD: 
2572                         if(last_seq) {
2573                                 CFRA= last_seq->startdisp;
2574                                 v2d->cur.xmin= last_seq->startdisp- (last_seq->len/20);
2575                                 v2d->cur.xmax= last_seq->enddisp+ (last_seq->len/20);
2576                                 update_for_newframe();
2577                         }
2578                         break;
2579                         
2580                 case AKEY:
2581                         if(sseq->mainb) break;
2582                         if(G.qual & LR_SHIFTKEY) {
2583                                 add_sequence(0);
2584                         }
2585                         else swap_select_seq();
2586                         break;
2587                 case BKEY:
2588                         if(sseq->mainb) break;
2589                         borderselect_seq();
2590                         break;
2591                 case CKEY:
2592                         if(last_seq && (last_seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))) {
2593                                 if(last_seq->flag & SEQ_LEFTSEL) CFRA= last_seq->startdisp;
2594                                 else CFRA= last_seq->enddisp-1;
2595                                 
2596                                 dx= CFRA-(v2d->cur.xmax+v2d->cur.xmin)/2;
2597                                 v2d->cur.xmax+= dx;
2598                                 v2d->cur.xmin+= dx;
2599                                 update_for_newframe();
2600                         }
2601                         else change_sequence();
2602                         break;
2603                 case DKEY:
2604                         if(sseq->mainb) break;
2605                         if(G.qual & LR_SHIFTKEY) add_duplicate_seq();
2606                         break;
2607                 case EKEY:
2608                         break;
2609                 case FKEY:
2610                         set_filter_seq();
2611                         break;
2612                 case GKEY:
2613                         if(sseq->mainb) break;
2614                         transform_seq('g');
2615                         break;
2616                 case MKEY:
2617                         if(G.qual & LR_ALTKEY) un_meta();
2618                         else {
2619                                 if ((last_seq) && (last_seq->type == SEQ_SOUND)) 
2620                                 {
2621                                         last_seq->flag ^= SEQ_MUTE;
2622                                         doredraw = 1;
2623                                 }
2624                                 else make_meta();
2625                         }
2626                         break;
2627                 case SKEY:
2628                         if(G.qual & LR_SHIFTKEY) seq_snapmenu();
2629                         break;
2630                 case TKEY:
2631                         touch_seq_files();
2632                         break;
2633                 case XKEY:
2634                 case DELKEY:
2635                         if(sseq->mainb) break;
2636                         del_seq();
2637                         break;
2638                 }
2639         }
2640
2641         if(doredraw) scrarea_queue_winredraw(curarea);
2642 }
2643
2644
2645 void init_seqspace(ScrArea *sa)
2646 {
2647         SpaceSeq *sseq;
2648         
2649         sseq= MEM_callocN(sizeof(SpaceSeq), "initseqspace");
2650         BLI_addhead(&sa->spacedata, sseq);
2651
2652         sseq->spacetype= SPACE_SEQ;
2653         sseq->zoom= 1;
2654         
2655         /* seq space goes from (0,8) to (250, 0) */
2656
2657         sseq->v2d.tot.xmin= 0.0;
2658         sseq->v2d.tot.ymin= 0.0;
2659         sseq->v2d.tot.xmax= 250.0;
2660         sseq->v2d.tot.ymax= 8.0;
2661         
2662         sseq->v2d.cur= sseq->v2d.tot;
2663
2664         sseq->v2d.min[0]= 10.0;
2665         sseq->v2d.min[1]= 4.0;
2666
2667         sseq->v2d.max[0]= 32000.0;
2668         sseq->v2d.max[1]= MAXSEQ;
2669         
2670         sseq->v2d.minzoom= 0.1;
2671         sseq->v2d.maxzoom= 10.0;
2672         
2673         sseq->v2d.scroll= L_SCROLL+B_SCROLL;
2674         sseq->v2d.keepaspect= 0;
2675         sseq->v2d.keepzoom= 0;
2676         sseq->v2d.keeptot= 0;
2677 }
2678
2679 /* ******************** SPACE: ACTION ********************** */
2680 extern void drawactionspace(ScrArea *sa, void *spacedata);
2681 extern void winqreadactionspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
2682
2683 static void changeactionspace(ScrArea *sa, void *spacedata)
2684 {
2685         if(G.v2d==0) return;
2686
2687         /* this sets the sub-areas correct, for scrollbars */
2688         test_view2d(G.v2d, curarea->winx, curarea->winy);
2689         
2690         /* action space uses weird matrices... local calculated in a function */
2691         // myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
2692 }
2693
2694
2695 void init_actionspace(ScrArea *sa)
2696 {
2697         SpaceAction *saction;
2698         
2699         saction= MEM_callocN(sizeof(SpaceAction), "initactionspace");
2700         BLI_addhead(&sa->spacedata, saction);
2701
2702         saction->spacetype= SPACE_ACTION;
2703
2704         saction->v2d.tot.xmin= 1.0;
2705         saction->v2d.tot.ymin=  0.0;
2706         saction->v2d.tot.xmax= 1000.0;
2707         saction->v2d.tot.ymax= 1000.0;
2708         
2709         saction->v2d.cur.xmin= -5.0;
2710         saction->v2d.cur.ymin= 0.0;
2711         saction->v2d.cur.xmax= 65.0;
2712         saction->v2d.cur.ymax= 1000.0;
2713
2714         saction->v2d.min[0]= 0.0;
2715         saction->v2d.min[1]= 0.0;
2716
2717         saction->v2d.max[0]= 32000.0;
2718         saction->v2d.max[1]= 1000.0;
2719         
2720         saction->v2d.minzoom= 0.01;
2721         saction->v2d.maxzoom= 10;
2722
2723         saction->v2d.scroll= R_SCROLL+B_SCROLL;
2724         saction->v2d.keepaspect= 0;
2725         saction->v2d.keepzoom= V2D_LOCKZOOM_Y;
2726         saction->v2d.keeptot= 0;
2727         
2728 }
2729
2730 void free_actionspace(SpaceAction *saction)
2731 {
2732         /* don't free saction itself */
2733         
2734         /* __PINFAKE */
2735 /*      if (saction->flag & SACTION_PIN)
2736                 if (saction->action)
2737                         saction->action->id.us --;
2738
2739 */      /* end PINFAKE */
2740 }
2741
2742
2743 /* ******************** SPACE: FILE ********************** */
2744
2745 void init_filespace(ScrArea *sa)
2746 {
2747         SpaceFile *sfile;
2748         
2749         sfile= MEM_callocN(sizeof(SpaceFile), "initfilespace");
2750         BLI_addhead(&sa->spacedata, sfile);
2751
2752         sfile->dir[0]= '/';
2753         sfile->type= FILE_UNIX;
2754
2755         sfile->spacetype= SPACE_FILE;
2756 }
2757
2758 void init_textspace(ScrArea *sa)
2759 {
2760         SpaceText *st;
2761         
2762         st= MEM_callocN(sizeof(SpaceText), "inittextspace");
2763         BLI_addhead(&sa->spacedata, st);
2764
2765         st->spacetype= SPACE_TEXT;      
2766         
2767         st->text= NULL;
2768         st->flags= 0;
2769         
2770         st->font_id= 5;
2771         st->lheight= 12;
2772         st->showlinenrs= 0;
2773         
2774         st->top= 0;
2775 }
2776
2777 void init_imaselspace(ScrArea *sa)
2778 {
2779         SpaceImaSel *simasel;
2780         
2781         simasel= MEM_callocN(sizeof(SpaceImaSel), "initimaselspace");
2782         BLI_addhead(&sa->spacedata, simasel);
2783
2784         simasel->spacetype= SPACE_IMASEL;
2785         
2786         simasel->mode = 7;
2787         strcpy (simasel->dir,  U.textudir);     /* TON */
2788         strcpy (simasel->file, "");
2789         strcpy(simasel->fole, simasel->file);
2790         strcpy(simasel->dor,  simasel->dir);
2791
2792         simasel->first_sel_ima  =  0;
2793         simasel->hilite_ima         =  0;
2794         simasel->firstdir               =  0;
2795         simasel->firstfile              =  0;
2796         simasel->cmap           =  0;
2797         simasel->returnfunc     =  0;
2798         
2799         simasel->title[0]       =  0;
2800         
2801         clear_ima_dir(simasel);
2802         
2803         // simasel->cmap= IMB_loadiffmem((int*)datatoc_cmap_tga, IB_rect|IB_cmap);
2804         simasel->cmap= IMB_ibImageFromMemory((int *)datatoc_cmap_tga, datatoc_cmap_tga_size, IB_rect|IB_cmap);
2805         if (!simasel->cmap) {
2806                 error("in console");
2807                 printf("Image select cmap file not found \n");
2808         }
2809 }
2810
2811 /* ******************** SPACE: SOUND ********************** */
2812
2813 extern void drawsoundspace(ScrArea *sa, void *spacedata);
2814 extern void winqreadsoundspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
2815
2816 void init_soundspace(ScrArea *sa)
2817 {
2818         SpaceSound *ssound;
2819         
2820         ssound= MEM_callocN(sizeof(SpaceSound), "initsoundspace");
2821         BLI_addhead(&sa->spacedata, ssound);
2822
2823         ssound->spacetype= SPACE_SOUND;
2824         
2825         /* sound space goes from (0,8) to (250, 0) */
2826
2827         ssound->v2d.tot.xmin= -4.0;
2828         ssound->v2d.tot.ymin= -4.0;
2829         ssound->v2d.tot.xmax= 250.0;
2830         ssound->v2d.tot.ymax= 255.0;
2831         
2832         ssound->v2d.cur.xmin= -4.0;
2833         ssound->v2d.cur.ymin= -4.0;
2834         ssound->v2d.cur.xmax= 50.0;
2835         ssound->v2d.cur.ymax= 255.0;
2836
2837         ssound->v2d.min[0]= 1.0;
2838         ssound->v2d.min[1]= 259.0;
2839
2840         ssound->v2d.max[0]= 32000.0;
2841         ssound->v2d.max[1]= 259;
2842         
2843         ssound->v2d.minzoom= 0.1;
2844         ssound->v2d.maxzoom= 10.0;
2845         
2846         ssound->v2d.scroll= B_SCROLL;
2847         ssound->v2d.keepaspect= 0;
2848         ssound->v2d.keepzoom= 0;
2849         ssound->v2d.keeptot= 0;
2850         
2851 }
2852
2853 void free_soundspace(SpaceSound *ssound)
2854 {
2855         /* don't free ssound itself */
2856         
2857         
2858 }
2859
2860 /* ******************** SPACE: IMAGE ********************** */
2861
2862 /*  extern void drawimagespace(ScrArea *sa, void *spacedata); BIF_drawimage.h */
2863
2864 void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2865 {
2866         unsigned short event= evt->event;
2867         short val= evt->val;
2868         SpaceImage *sima= curarea->spacedata.first;
2869         View2D *v2d= &sima->v2d;
2870 #ifdef NAN_TPT
2871         IMG_BrushPtr brush;
2872         IMG_CanvasPtr canvas;
2873         int rowBytes;
2874         short xy_prev[2], xy_curr[2];
2875         float uv_prev[2], uv_curr[2];
2876         extern VPaint Gvp;
2877 #endif /* NAN_TPT */    
2878         if(val==0) return;
2879
2880         if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2881         
2882         if (sima->flag & SI_DRAWTOOL) {
2883 #ifdef NAN_TPT
2884                 /* Draw tool is active */
2885                 switch(event) {
2886                         case LEFTMOUSE:
2887                                 /* Paranoia checks */
2888                                 if (!sima) break;
2889                                 if (!sima->image) break;
2890                                 if (!sima->image->ibuf) break;
2891                                 if (sima->image->packedfile) {
2892                                         error("Painting in packed images not supported");
2893                                         break;
2894                                 }
2895                         
2896                                 brush = IMG_BrushCreate(Gvp.size, Gvp.size, Gvp.r, Gvp.g, Gvp.b, Gvp.a);
2897                                 /* skipx is not set most of the times. Make a guess. */
2898                                 rowBytes = sima->image->ibuf->skipx ? sima->image->ibuf->skipx : sima->image->ibuf->x * 4;
2899                                 canvas = IMG_CanvasCreateFromPtr(sima->image->ibuf->rect, sima->image->ibuf->x, sima->image->ibuf->y, rowBytes);
2900
2901                                 getmouseco_areawin(xy_prev);
2902                                 while (get_mbut() & L_MOUSE) {
2903                                         getmouseco_areawin(xy_curr);
2904                                         /* Check if mouse position changed */
2905                                         if ((xy_prev[0] != xy_curr[0]) || (xy_prev[1] != xy_curr[1])) {
2906                                                 /* Convert mouse coordinates to u,v and draw */
2907                                                 areamouseco_to_ipoco(v2d, xy_prev, &uv_prev[0], &uv_prev[1]);
2908                                                 areamouseco_to_ipoco(v2d, xy_curr, &uv_curr[0], &uv_curr[1]);
2909                                                 IMG_CanvasDrawLineUV(canvas, brush, uv_prev[0], uv_prev[1], uv_curr[0], uv_curr[1]);
2910                                                 if (G.sima->lock) {
2911                                                         /* Make OpenGL aware of a changed texture */
2912                                                         free_realtime_image(sima->image);
2913                                                         /* Redraw this view and the 3D view */
2914                                                         force_draw_plus(SPACE_VIEW3D);
2915                                                 }
2916                                                 else {
2917                                                         /* Redraw only this view */
2918                                                         force_draw();
2919                                                 }
2920                                                 xy_prev[0] = xy_curr[0];
2921                                                 xy_prev[1] = xy_curr[1];
2922                                         }
2923                                 }
2924                                 /* Set the dirty bit in the image so that it is clear that it has been modified. */
2925                                 sima->image->ibuf->userflags |= IB_BITMAPDIRTY;
2926                                 if (!G.sima->lock) {
2927                                         /* Make OpenGL aware of a changed texture */
2928                                         free_realtime_image(sima->image);
2929                                         /* Redraw this view and the 3D view */
2930                                         force_draw_plus(SPACE_VIEW3D);
2931                                 }
2932                                 IMG_BrushDispose(brush);
2933                                 IMG_CanvasDispose(canvas);
2934                                 allqueue(REDRAWHEADERS, 0);
2935                                 break;
2936                 }
2937 #endif /* NAN_TPT */
2938         }
2939         else {
2940                 /* Draw tool is inactive */
2941                 switch(event) {
2942                         case LEFTMOUSE:
2943                                 if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
2944                                 else gesture();
2945                                 break;
2946                         case MIDDLEMOUSE:
2947                                 image_viewmove();
2948                                 break;
2949                         case RIGHTMOUSE:
2950                                 mouse_select_sima();
2951                                 break;
2952                         case AKEY:
2953                                 select_swap_tface_uv();
2954                                 break;
2955                         case BKEY:
2956                                 borderselect_sima();
2957                                 break;
2958                         case GKEY:
2959                                 transform_tface_uv('g');