- fixed redraw for copy button in new themes editor
[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.qual & LR_SHIFTKEY) selectrow_nurb();
1124                                 else transform('r');
1125                                 break;
1126                         case SKEY:
1127                                 if(G.qual & LR_ALTKEY) {
1128                                         if(G.obedit) transform('N');    /* scale by vertex normal */
1129                                         else clear_object('s');
1130                                 }
1131                                 else if(G.qual & LR_SHIFTKEY) snapmenu();
1132                                 else if(G.qual & LR_CTRLKEY) {
1133                                         if(G.obedit) transform('S');
1134                                 }
1135                                 else transform('s');
1136                                 break;
1137                         case TKEY:
1138                                 if(G.qual & LR_CTRLKEY) {
1139                                         if(G.obedit) {
1140                                                 if(G.obedit->type==OB_MESH) {
1141                                                         convert_to_triface(0);
1142                                                         allqueue(REDRAWVIEW3D, 0);
1143                                                         countall();
1144                                                         makeDispList(G.obedit);
1145                                                 }
1146                                         }
1147                                         else make_track();
1148                                 }
1149                                 else if(G.qual & LR_ALTKEY) {
1150                                         if(G.obedit && G.obedit->type==OB_CURVE) clear_tilt();
1151                                         else clear_track();
1152                                 }
1153                                 else {
1154                                         if(G.obedit) transform('t');
1155                                         else texspace_edit();
1156                                 }
1157                                 
1158                                 break;
1159                         case UKEY:
1160                                 if(G.obedit) {
1161                                         if(G.obedit->type==OB_MESH) remake_editMesh();
1162                                         else if(G.obedit->type==OB_ARMATURE) remake_editArmature();
1163                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) remake_editNurb();
1164                                         else if(G.obedit->type==OB_LATTICE) remake_editLatt();
1165                                 }
1166                                 else if(G.f & G_FACESELECT) uv_autocalc_tface();
1167                                 else if(G.f & G_WEIGHTPAINT) wpaint_undo();
1168                                 else if(G.f & G_VERTEXPAINT) vpaint_undo();
1169                                 else single_user();
1170                                 
1171                                 break;
1172                         case VKEY:
1173                                 if(G.qual==LR_SHIFTKEY) {
1174                                         if (G.obedit && G.obedit->type==OB_MESH) {
1175                                                 align_view_to_selected(v3d);
1176                                         } else if (G.f & G_FACESELECT) {
1177                                                 align_view_to_selected(v3d);
1178                                         }
1179                                 } else {
1180                                         if(G.obedit) {
1181                                                 if(G.obedit->type==OB_CURVE) {
1182                                                         sethandlesNurb(2);
1183                                                         makeDispList(G.obedit);
1184                                                         allqueue(REDRAWVIEW3D, 0);
1185                                                 }
1186                                         }
1187                                         else if(G.qual & LR_ALTKEY) image_aspect();
1188                                         else set_vpaint();
1189                                 }
1190                                 break;
1191                         case WKEY:
1192                                 if(G.qual & LR_SHIFTKEY) {
1193                                         transform('w');
1194                                 }
1195                                 else if(G.qual & LR_ALTKEY) {
1196                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1197                                 }
1198                                 else if(G.qual & LR_CTRLKEY) {
1199                                         if(G.obedit) {
1200                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1201                                                         switchdirectionNurb2();
1202                                                 }
1203                                         }
1204                                 }
1205                                 else special_editmenu();
1206                                 
1207                                 break;
1208                         case XKEY:
1209                         case DELKEY:
1210                                 delete_context_selected();
1211                                 break;
1212                         case YKEY:
1213                                 if(G.obedit) {
1214                                         if(G.obedit->type==OB_MESH) split_mesh();
1215                                 }
1216                                 break;
1217                         case ZKEY:
1218                                 toggle_shading();
1219                                 
1220                                 scrarea_queue_headredraw(curarea);
1221                                 scrarea_queue_winredraw(curarea);
1222                                 break;
1223                                 
1224                         
1225                         case HOMEKEY:
1226                                 view3d_home(0);
1227                                 break;
1228                         case COMMAKEY:
1229                                 G.vd->around= V3D_CENTRE;
1230                                 scrarea_queue_headredraw(curarea);
1231                                 break;
1232                                 
1233                         case PERIODKEY:
1234                                 G.vd->around= V3D_CURSOR;
1235                                 scrarea_queue_headredraw(curarea);
1236                                 break;
1237                         
1238                         case PADSLASHKEY:
1239                                 if(G.vd->localview) {
1240                                         G.vd->localview= 0;
1241                                         endlocalview(curarea);
1242                                 }
1243                                 else {
1244                                         G.vd->localview= 1;
1245                                         initlocalview();
1246                                 }
1247                                 scrarea_queue_headredraw(curarea);
1248                                 break;
1249                         case PADASTERKEY:       /* '*' */
1250                                 ob= OBACT;
1251                                 if(ob) {
1252                                         obmat_to_viewmat(ob);
1253                                         if(G.vd->persp==2) G.vd->persp= 1;
1254                                         scrarea_queue_winredraw(curarea);
1255                                 }
1256                                 break;
1257                         case PADPERIOD: /* '.' */
1258                                 centreview();
1259                                 break;
1260                         
1261                         case PAGEUPKEY:
1262                                 if(G.qual & LR_CTRLKEY) movekey_obipo(1);
1263                                 else nextkey_obipo(1);  /* in editipo.c */
1264                                 break;
1265
1266                         case PAGEDOWNKEY:
1267                                 if(G.qual & LR_CTRLKEY) movekey_obipo(-1);
1268                                 else nextkey_obipo(-1);
1269                                 break;
1270                                 
1271                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1272                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1273                         case PADMINUS: case PADPLUSKEY: case PADENTER:
1274                                 persptoetsen(event);
1275                                 doredraw= 1;
1276                                 break;
1277                         
1278                         case ESCKEY:
1279                                 if (G.vd->flag & V3D_DISPIMAGE) {
1280                                         G.vd->flag &= ~V3D_DISPIMAGE;
1281                                         doredraw= 1;
1282                                 }
1283                                 break;
1284                         }
1285                 }
1286         }
1287         
1288         if(doredraw) {
1289                 scrarea_queue_winredraw(curarea);
1290                 scrarea_queue_headredraw(curarea);
1291         }
1292 }
1293
1294 void initview3d(ScrArea *sa)
1295 {
1296         View3D *vd;
1297         
1298         vd= MEM_callocN(sizeof(View3D), "initview3d");
1299         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1300
1301         vd->spacetype= SPACE_VIEW3D;
1302         vd->viewquat[0]= 1.0;
1303         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1304         vd->persp= 1;
1305         vd->drawtype= OB_WIRE;
1306         vd->view= 7;
1307         vd->dist= 10.0;
1308         vd->lens= 35.0;
1309         vd->near= 0.01;
1310         vd->far= 500.0;
1311         vd->grid= 1.0;
1312         vd->gridlines= 16;
1313         vd->lay= vd->layact= 1;
1314         if(G.scene) {
1315                 vd->lay= vd->layact= G.scene->lay;
1316                 vd->camera= G.scene->camera;
1317         }
1318         vd->scenelock= 1;
1319 }
1320
1321
1322 /* ******************** SPACE: IPO ********************** */
1323
1324 static void changeview2dspace(ScrArea *sa, void *spacedata)
1325 {
1326         if(G.v2d==0) return;
1327
1328         test_view2d(G.v2d, curarea->winx, curarea->winy);
1329         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1330 }
1331
1332 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1333 {
1334         unsigned short event= evt->event;
1335         short val= evt->val;
1336         SpaceIpo *sipo= curarea->spacedata.first;
1337         View2D *v2d= &sipo->v2d;
1338         float dx, dy;
1339         int cfra, doredraw= 0;
1340         short mval[2];
1341         
1342         if(curarea->win==0) return;
1343
1344         if(val) {
1345                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
1346
1347                 switch(event) {
1348                 case UI_BUT_EVENT:
1349                         if(val>0) do_ipowin_buts(val-1);
1350                         break;
1351                 case LEFTMOUSE:
1352                         if( in_ipo_buttons() ) {
1353                                 do_ipo_selectbuttons();
1354                                 doredraw= 1;
1355                         }                       
1356                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1357                         else {
1358                                 do {
1359                                         getmouseco_areawin(mval);
1360                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1361                                         
1362                                         cfra= (int)dx;
1363                                         if(cfra< 1) cfra= 1;
1364                                         
1365                                         if( cfra!=CFRA ) {
1366                                                 CFRA= cfra;
1367                                                 update_for_newframe();
1368                                                 force_draw_plus(SPACE_VIEW3D);
1369                                                 force_draw_plus(SPACE_ACTION);
1370                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1371                                         }
1372                                 
1373                                 } while(get_mbut()&L_MOUSE);
1374                         }
1375                         
1376                         break;
1377                 case MIDDLEMOUSE:
1378                         if(in_ipo_buttons()) {
1379                                 scroll_ipobuts();
1380                         }
1381                         else view2dmove(event); /* in drawipo.c */
1382                         break;
1383
1384                 case WHEELUPMOUSE:
1385                 case WHEELDOWNMOUSE:
1386                         view2dmove(event);      /* in drawipo.c */
1387                         break;
1388
1389                 case RIGHTMOUSE:
1390                         mouse_select_ipo();
1391                         allqueue (REDRAWACTION, 0);
1392                         allqueue(REDRAWNLA, 0);
1393                         break;
1394                 case PADPLUSKEY:
1395                         view2d_zoom(v2d, 0.1154, curarea->winx, curarea->winy);
1396                         doredraw= 1;
1397                         break;
1398                 case PADMINUS:
1399                         view2d_zoom(v2d, -0.15, curarea->winx, curarea->winy);
1400                         doredraw= 1;
1401                         break;
1402                 case PAGEUPKEY:
1403                         if(G.qual & LR_CTRLKEY) movekey_ipo(1);
1404                         else nextkey_ipo(1);
1405                         break;
1406                 case PAGEDOWNKEY:
1407                         if(G.qual & LR_CTRLKEY) movekey_ipo(-1);
1408                         else nextkey_ipo(-1);
1409                         break;
1410                 case HOMEKEY:
1411                         do_ipo_buttons(B_IPOHOME);
1412                         break;
1413                         
1414                 case AKEY:
1415                         if(in_ipo_buttons()) {
1416                                 swap_visible_editipo();
1417                         }
1418                         else swap_selectall_editipo();
1419                         allspace (REMAKEIPO, 0);
1420                         allqueue (REDRAWNLA, 0);
1421                         allqueue (REDRAWACTION, 0);
1422                         break;
1423                 case BKEY:
1424                         borderselect_ipo();
1425                         break;
1426                 case CKEY:
1427                         move_to_frame();
1428                         break;
1429                 case DKEY:
1430                         if(G.qual & LR_SHIFTKEY) add_duplicate_editipo();
1431                         break;
1432                 case GKEY:
1433                         transform_ipo('g');
1434                         break;
1435                 case HKEY:
1436                         if(G.qual & LR_SHIFTKEY) sethandles_ipo(HD_AUTO);
1437                         else sethandles_ipo(HD_ALIGN);
1438                         break;
1439                 case JKEY:
1440                         join_ipo();
1441                         break;
1442                 case KKEY:
1443                         ipo_toggle_showkey();
1444                         scrarea_queue_headredraw(curarea);
1445                         allqueue(REDRAWVIEW3D, 0);
1446                         doredraw= 1;
1447                         break;
1448                 case RKEY:
1449                         ipo_record();
1450                         break;
1451                 case SKEY:
1452                         if(G.qual & LR_SHIFTKEY) ipo_snapmenu();
1453                         else transform_ipo('s');
1454                         break;
1455                 case TKEY:
1456                         set_ipotype();
1457                         break;
1458                 case VKEY:
1459                         sethandles_ipo(HD_VECT);
1460                         break;
1461                 case XKEY:
1462                 case DELKEY:
1463                         if(G.qual & LR_SHIFTKEY) delete_key();
1464                         else del_ipo();
1465                         break;
1466                 }
1467         }
1468
1469         if(doredraw) scrarea_queue_winredraw(curarea);
1470 }
1471
1472 void initipo(ScrArea *sa)
1473 {
1474         SpaceIpo *sipo;
1475         
1476         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1477         BLI_addhead(&sa->spacedata, sipo);
1478
1479         sipo->spacetype= SPACE_IPO;
1480         /* sipo space loopt van (0,-?) tot (??,?) */
1481         sipo->v2d.tot.xmin= 0.0;
1482         sipo->v2d.tot.ymin= -10.0;
1483         sipo->v2d.tot.xmax= G.scene->r.efra;
1484         sipo->v2d.tot.ymax= 10.0;
1485
1486         sipo->v2d.cur= sipo->v2d.tot;
1487
1488         sipo->v2d.min[0]= 0.01;
1489         sipo->v2d.min[1]= 0.01;
1490
1491         sipo->v2d.max[0]= 15000.0;
1492         sipo->v2d.max[1]= 10000.0;
1493         
1494         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1495         sipo->v2d.keeptot= 0;
1496
1497         sipo->blocktype= ID_OB;
1498 }
1499
1500 /* ******************** SPACE: INFO ********************** */
1501
1502 void space_mipmap_button_function(int event) {
1503         set_mipmap(!(U.gameflags & USERDEF_DISABLE_MIPMAP));
1504
1505         allqueue(REDRAWVIEW3D, 0);
1506 }
1507
1508 void space_sound_button_function(int event)
1509 {
1510         int a;
1511         SYS_SystemHandle syshandle;
1512
1513         if ((syshandle = SYS_GetSystem()))
1514         {
1515                 a = (U.gameflags & USERDEF_DISABLE_SOUND);
1516                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1517         }
1518 }
1519
1520 #define B_ADD_THEME     3301
1521 #define B_DEL_THEME     3302
1522 #define B_NAME_THEME    3303
1523 #define B_THEMECOL              3304
1524 #define B_UPDATE_THEME  3305
1525 #define B_CHANGE_THEME  3306
1526 #define B_THEME_COPY    3307
1527 #define B_THEME_PASTE   3308
1528
1529
1530 // needed for event; choose new 'curmain' resets it...
1531 static short th_curcol= TH_BACK;
1532 static char *th_curcol_ptr= NULL;
1533 static char th_curcol_arr[4]={0, 0, 0, 255};
1534
1535 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1536 {
1537         bTheme *btheme, *bt;
1538         int spacetype= 0;
1539         static short cur=1, curmain=2;
1540         short a, tot=0, isbuiltin= 0;
1541         char string[20*32], *strp;
1542         
1543         y3= y2+23;      // exception!
1544         
1545         /* count total, max 16! */
1546         for(bt= U.themes.first; bt; bt= bt->next) tot++;
1547         
1548         /* if cur not is 1; move that to front of list */
1549         if(cur!=1) {
1550                 a= 1;
1551                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
1552                         if(a==cur) {
1553                                 BLI_remlink(&U.themes, bt);
1554                                 BLI_addhead(&U.themes, bt);
1555                                 cur= 1;
1556                                 break;
1557                         }
1558                 }
1559         }
1560         
1561         /* the current theme */
1562         btheme= U.themes.first;
1563         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
1564
1565         /* construct popup script */
1566         string[0]= 0;
1567         for(bt= U.themes.first; bt; bt= bt->next) {
1568                 strcat(string, bt->name);
1569                 if(btheme->next) strcat(string, "   |");
1570         }
1571         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
1572         
1573         /* add / delete / name */
1574         uiBlockSetCol(block, BUTSALMON);
1575         if(tot<16)
1576                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
1577         if(tot>1 && isbuiltin==0)
1578                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
1579         uiBlockSetCol(block, BUTGREY);
1580
1581         if(isbuiltin) return;
1582         
1583         /* name */
1584         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
1585
1586         /* main choices pup */
1587         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|3D View %x2|Ipo Window %x3|Buttons Window %x4|File Select %x5",
1588                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
1589         if(curmain==2) spacetype= SPACE_VIEW3D;
1590         if(curmain==3) spacetype= SPACE_IPO;
1591         if(curmain==4) spacetype= SPACE_BUTS;
1592         if(curmain==5) spacetype= SPACE_FILE;
1593
1594         /* color choices pup */
1595         if(curmain==1) strp= BIF_ThemeColorsPup(0);
1596         else strp= BIF_ThemeColorsPup(spacetype);
1597         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
1598         MEM_freeN(strp);
1599         
1600         /* always make zero, ugly global... */
1601         th_curcol_ptr= NULL;
1602         
1603         /* sliders */
1604         if(curmain==1);
1605         else {
1606                 char *col;
1607                 
1608                 th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
1609                 
1610                 if(col && th_curcol==TH_VERTEX_SIZE) {
1611                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, B_THEMECOL, 0, "");
1612                 
1613                 }
1614                 else if(col) {
1615                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
1616                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
1617                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
1618
1619                         uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
1620                         
1621                         if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
1622                                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
1623                         }
1624                         
1625                         /* copy paste */
1626                         uiBlockSetCol(block, BUTSALMON);
1627                         uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
1628                         uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
1629
1630                         uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
1631                         
1632                 }
1633         }
1634         
1635         
1636         
1637         uiClearButLock();
1638 }
1639
1640
1641 void drawinfospace(ScrArea *sa, void *spacedata)
1642 {
1643         uiBlock *block;
1644         float fac;
1645         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
1646         short smallprefbut, medprefbut, largeprefbut, smfileselbut;
1647         short edgespace, midspace;
1648         char naam[32];
1649
1650         if(curarea->win==0) return;
1651
1652         glClearColor(0.6, 0.6, 0.6, 0.0); 
1653         glClear(GL_COLOR_BUFFER_BIT);
1654
1655         fac= ((float)curarea->winx)/1280.0;
1656         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
1657         
1658         sprintf(naam, "infowin %d", curarea->win);
1659         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSSX, UI_HELV, curarea->win);
1660
1661
1662         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
1663
1664         xpos = 45;              /* left padding */
1665         ypos = 50;              /* bottom padding for buttons */
1666         ypostab = 10;           /* bottom padding for 'tab' row */
1667
1668
1669         buth = 20;              /* standard button height */
1670
1671         smallprefbut = 94;      /* standard size for small preferences button */
1672         medprefbut = 193;       /* standard size for medium preferences button */
1673         largeprefbut = 292;     /* standard size for large preferences button */
1674         smfileselbut = buth;    /* standard size for fileselect button (square) */
1675         
1676         edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
1677         midspace = 5;           /* horizontal space between buttons */
1678
1679         rspace = 3;             /* default space between rows */
1680
1681         y1 = ypos;              /* bottom padding of 1st (bottom) button row */
1682         y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
1683         y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
1684         y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
1685
1686         y2label = y2-2;         /* adjustments to offset the labels down to align better */
1687         y3label = y3-(3*rspace)-2;      /* again for 3rd row */
1688         y4label = y4-2;         /* again for 4th row */
1689
1690
1691         /* set the colour to blue and draw the main 'tab' controls */
1692
1693         uiBlockSetCol(block, BUTBLUE);
1694
1695         uiDefButI(block, ROW,B_USERPREF,"View & Controls",
1696                 xpos,ypostab,(short)dx,buth,
1697                 &U.userpref,1.0,0.0, 0, 0,"");
1698                 
1699         uiDefButI(block, ROW,B_USERPREF,"Edit Methods",
1700                 (short)(xpos+dx),ypostab,(short)dx,buth,
1701                 &U.userpref,1.0,1.0, 0, 0,"");
1702
1703         uiDefButI(block, ROW,B_USERPREF,"Language & Font",
1704                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
1705                 &U.userpref,1.0,2.0, 0, 0,"");
1706
1707         uiDefButI(block, ROW,B_USERPREF,"Themes",
1708                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
1709                 &U.userpref,1.0,6.0, 0, 0,"");
1710
1711         uiDefButI(block, ROW,B_USERPREF,"Auto Save",
1712                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
1713                 &U.userpref,1.0,3.0, 0, 0,"");
1714
1715         uiDefButI(block, ROW,B_USERPREF,"System & OpenGL",
1716                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
1717                 &U.userpref,1.0,4.0, 0, 0,"");
1718                 
1719         uiDefButI(block, ROW,B_USERPREF,"File Paths",
1720                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
1721                 &U.userpref,1.0,5.0, 0, 0,"");
1722
1723         uiBlockSetEmboss(block, UI_EMBOSSX);
1724         uiBlockSetCol(block, BUTGREY);
1725
1726         /* end 'tab' controls */
1727
1728         /* line 2: left x co-ord, top y co-ord, width, height */
1729
1730         if(U.userpref == 6) {
1731                 info_user_themebuts(block, y1, y2, y3);
1732         }
1733         else if (U.userpref == 0) { /* view & controls */
1734
1735                 uiDefBut(block, LABEL,0,"Display:",
1736                         xpos,y3label,medprefbut,buth,
1737                         0, 0, 0, 0, 0, "");
1738
1739                 uiDefButS(block, TOG|BIT|11, 0, "ToolTips",
1740                         (xpos+edgespace),y2,smallprefbut,buth,
1741                         &(U.flag), 0, 0, 0, 0,
1742                         "Displays tooltips (help tags) over buttons");
1743
1744                 uiDefButS(block, TOG|BIT|4, B_DRAWINFO, "Object Info",
1745                         (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
1746                         &(U.uiflag), 0, 0, 0, 0,
1747                         "Displays current object name and frame number in the 3D viewport");
1748
1749                 uiDefButS(block, TOG|BIT|4, 0, "Global Scene",
1750                         (xpos+edgespace),y1,medprefbut,buth,
1751                         &(U.flag), 0, 0, 0, 0,
1752                         "Forces the current Scene to be displayed in all Screens");
1753
1754
1755                 uiDefBut(block, LABEL,0,"Snap to grid:",
1756                         (xpos+edgespace+medprefbut),y3label,medprefbut,buth,
1757                         0, 0, 0, 0, 0, "");
1758
1759                 uiDefButS(block, TOG|BIT|1, 0, "Grab",
1760                         (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
1761                         &(U.flag), 0, 0, 0, 0,
1762                         "Move objects to grid units");
1763
1764                 uiDefButS(block, TOG|BIT|3, 0, "Size",
1765                         (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
1766                         &(U.flag), 0, 0, 0, 0,
1767                         "Scale objects to grid units");
1768
1769                 uiDefButS(block, TOG|BIT|2, 0, "Rotate",
1770                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y2,smallprefbut,buth,
1771                         &(U.flag), 0, 0, 0, 0,
1772                         "Rotate objects to grid units");
1773
1774
1775
1776                 uiBlockSetCol(block, BUTGREEN);
1777
1778                 uiDefBut(block, LABEL,0,"Menu Buttons:",
1779                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3label,medprefbut,buth,
1780                         0, 0, 0, 0, 0, "");
1781
1782                 uiDefButS(block, TOG|BIT|9, 0, "Auto Open",
1783                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
1784                         &(U.uiflag), 0, 0, 0, 0,
1785                         "Automatic opening of menu buttons");
1786
1787                 uiBlockSetCol(block, BUTGREY);
1788
1789                 uiDefButS(block, NUM, 0, "ThresA:",
1790                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
1791                         &(U.menuthreshold1), 1, 40, 0, 0,
1792                         "Time in 1/10 seconds for auto open");
1793
1794                 uiDefButS(block, NUM, 0, "ThresB:",
1795                         (xpos+edgespace+medprefbut+(4*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
1796                         &(U.menuthreshold2), 1, 40, 0, 0,
1797                         "Time in 1/10 seconds for auto open sublevels");
1798                         
1799
1800                 uiBlockSetCol(block, BUTGREEN);
1801
1802                 uiDefButS(block, TOGN|BIT|10, B_DRAWINFO, "Rotate View",
1803                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
1804                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
1805
1806                 uiDefButS(block, TOG|BIT|10, B_DRAWINFO, "Pan View",
1807                         (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
1808                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
1809
1810                 uiBlockSetCol(block, BUTGREY);
1811                 
1812                 uiDefBut(block, LABEL,0,"Middle mouse button:",
1813                         (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
1814                         0, 0, 0, 0, 0, "");
1815                 uiDefButS(block, TOG|BIT|12, 0, "Emulate 3 Buttons",
1816                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
1817                         &(U.flag), 0, 0, 0, 0,
1818                         "Emulates a middle mouse button with ALT+LeftMouse");
1819
1820
1821
1822                 uiDefBut(block, LABEL,0,"View rotation method:",
1823                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
1824                         0, 0, 0, 0, 0, "");
1825
1826                 uiBlockSetCol(block, BUTGREEN);
1827
1828                 uiDefButS(block, TOG|BIT|5, B_DRAWINFO, "Trackball",
1829                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,(smallprefbut+2),buth,
1830                         &(U.flag), 0, 0, 0, 0,
1831                         "Use trackball style rotation with middle mouse button");
1832
1833                 uiDefButS(block, TOGN|BIT|5, B_DRAWINFO, "Turntable",
1834                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
1835                         &(U.flag), 0, 0, 0, 0,
1836                         "Use turntable style rotation with middle mouse button");
1837
1838                 uiBlockSetCol(block, BUTGREY);
1839
1840                 uiDefBut(block, LABEL,0,"Mousewheel:",
1841                         (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
1842                         0, 0, 0, 0, 0, "");
1843                 uiDefButS(block, TOG|BIT|2, 0, "Invert Wheel Zoom",
1844                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,medprefbut,buth,
1845                         &(U.uiflag), 0, 0, 0, 0,
1846                         "Swaps mouse wheel zoom direction");
1847
1848
1849                 uiDefButI(block, NUM, 0, "Scroll Lines:",
1850                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,medprefbut,buth,
1851                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
1852                         "The number of lines scrolled at a time with the mouse wheel");
1853
1854
1855         } else if (U.userpref == 1) { /* edit methods */
1856
1857
1858                 uiDefBut(block, LABEL,0,"Material linked to:",
1859                         xpos,y3label,medprefbut,buth,
1860                         0, 0, 0, 0, 0, "");
1861
1862                 uiBlockSetCol(block, BUTGREEN);
1863
1864                 uiDefButS(block, TOGN|BIT|8, B_DRAWINFO, "ObData",
1865                         (xpos+edgespace),y2,(smallprefbut+2),buth,
1866                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
1867
1868                 uiDefButS(block, TOG|BIT|8, B_DRAWINFO, "Object",
1869                         (xpos+edgespace+smallprefbut+2),y2,(smallprefbut+2),buth,
1870                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
1871
1872                 uiBlockSetCol(block, BUTGREY);
1873
1874
1875
1876                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
1877                         (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
1878                         0, 0, 0, 0, 0, "");
1879
1880                 uiDefButS(block, TOG|BIT|0, 0, "Action",
1881                         (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
1882                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
1883
1884                 uiDefButS(block, TOG|BIT|1, 0, "Object",
1885                         (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
1886                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
1887
1888
1889
1890                 uiDefBut(block, LABEL,0,"Duplicate with object:",
1891                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
1892                         0, 0, 0, 0, 0, "");
1893
1894                 uiDefButS(block, TOG|BIT|0, 0, "Mesh",
1895                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
1896                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
1897                 uiDefButS(block, TOG|BIT|9, 0, "Armature",
1898                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
1899                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
1900
1901                 uiDefButS(block, TOG|BIT|2, 0, "Surface",
1902                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
1903                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
1904                 uiDefButS(block, TOG|BIT|5, 0, "Lamp",
1905                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
1906                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
1907
1908                 uiDefButS(block, TOG|BIT|1, 0, "Curve",
1909                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
1910                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
1911                 uiDefButS(block, TOG|BIT|7, 0, "Material",
1912                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
1913                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
1914
1915                 uiDefButS(block, TOG|BIT|3, 0, "Text",
1916                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
1917                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
1918                 uiDefButS(block, TOG|BIT|8, 0, "Texture",
1919                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
1920                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
1921
1922                 uiDefButS(block, TOG|BIT|4, 0, "Metaball",
1923                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
1924                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
1925                 uiDefButS(block, TOG|BIT|6, 0, "Ipo",
1926                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
1927                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
1928
1929
1930         } else if(U.userpref == 2) { /* language & colors */
1931
1932 #ifdef INTERNATIONAL
1933                 char curfont[64];
1934
1935                 sprintf(curfont, "Interface Font: ");
1936                 strcat(curfont,U.fontname);
1937
1938                 uiDefButS(block, TOG|BIT|5, B_DOLANGUIFONT, "International Fonts",
1939                         xpos,y2,medprefbut,buth,
1940                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
1941
1942                 if(U.transopts & TR_ALL) {
1943                         uiDefBut(block, LABEL,0,curfont,
1944                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
1945                                 0, 0, 0, 0, 0, "");
1946
1947                         uiBlockSetCol(block, BUTSALMON);
1948         //(xpos+edgespace)
1949                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
1950                                 xpos,y1,medprefbut,buth,
1951                                 0, 0, 0, 0, 0, "Select a new font for the interface");
1952
1953                         uiBlockSetCol(block, BUTGREY);
1954
1955
1956                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
1957                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
1958                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
1959
1960 /*
1961                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
1962                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
1963                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
1964
1965
1966                         uiDefBut(block, LABEL,0,"Translate:",
1967                                 (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
1968                                 0, 0, 0, 0, 0, "");
1969 */
1970
1971                         uiDefButS(block, TOG|BIT|0, B_SETTRANSBUTS, "Tooltips",
1972                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
1973                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
1974
1975                         uiDefButS(block, TOG|BIT|1, B_SETTRANSBUTS, "Buttons",
1976                                 (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
1977                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
1978
1979                         uiDefButS(block, TOG|BIT|2, B_SETTRANSBUTS, "Toolbox",
1980                                 (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
1981                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
1982
1983                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
1984                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
1985                                 &U.language, 0, 0, 0, 0, "Select interface language");
1986                                 
1987                         /* uiDefButS(block, TOG|BIT|3, B_SETTRANSBUTS, "FTF All windows",
1988                                 (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
1989                                 &(U.transopts), 0, 0, 0, 0,
1990                                 "Use FTF drawing for fileselect and textwindow "
1991                                 "(under construction)");
1992                         */
1993                 }
1994
1995 /* end of INTERNATIONAL */
1996 #endif
1997
1998         } else if(U.userpref == 3) { /* auto save */
1999
2000
2001                 uiDefButS(block, TOG|BIT|0, B_RESETAUTOSAVE, "Auto Save Temp Files",
2002                         (xpos+edgespace),y2,medprefbut,buth,
2003                         &(U.flag), 0, 0, 0, 0,
2004                         "Enables automatic saving of temporary files");
2005
2006                 if(U.flag & AUTOSAVE) {
2007                         uiBlockSetCol(block, BUTSALMON);
2008
2009                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2010                                 (xpos+edgespace),y1,medprefbut,buth,
2011                                 0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
2012
2013                         uiBlockSetCol(block, BUTGREY);
2014
2015
2016                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2017                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2018                                 &(U.savetime), 1.0, 60.0, 0, 0,
2019                                 "The time (in minutes) to wait between automatic temporary saves");
2020
2021                         uiDefButS(block, NUM, 0, "Versions:",
2022                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2023                                 &U.versions, 0.0, 32.0, 0, 0,
2024                                 "The number of old versions to maintain when saving");
2025                 }
2026
2027         } else if (U.userpref == 4) { /* system & opengl */
2028
2029
2030 /*
2031                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2032                         (xpos+edgespace),y2,largeprefbut,buth,
2033                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2034
2035                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2036                         (xpos+edgespace), y1, largeprefbut,buth,
2037                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2038
2039                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2040                         (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
2041                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2042 */
2043
2044 #ifdef _WIN32
2045                 uiDefBut(block, LABEL,0,"Win Codecs:",
2046                         (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
2047                         0, 0, 0, 0, 0, "");
2048
2049                 uiDefButS(block, TOG|BIT|8, 0, "Enable all codecs",
2050                         (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
2051                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2052 #endif
2053
2054                 uiDefBut(block, LABEL,0,"Keyboard:",
2055                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2056                         0, 0, 0, 0, 0, "");
2057
2058                 uiDefButS(block, TOG|BIT|9, B_U_CAPSLOCK, "Disable Caps Lock",
2059                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
2060                         &(U.flag), 0, 0, 0, 0,
2061                         "Disables the Caps Lock key when entering text");
2062
2063                 uiDefButS(block, TOG|BIT|13, 0, "Emulate Numpad",
2064                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
2065                         &(U.flag), 0, 0, 0, 0,
2066                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2067
2068
2069                 uiDefBut(block, LABEL,0,"System:",
2070                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2071                         0, 0, 0, 0, 0, "");
2072
2073                 uiDefButI(block, TOG|BIT|USERDEF_DISABLE_SOUND_BIT, B_SOUNDTOGGLE, "Disable Sound",
2074                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
2075                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2076
2077                 uiDefButS(block, TOG|BIT|3, 0, "Filter File Extensions",
2078                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2079                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2080
2081
2082                 uiDefBut(block, LABEL,0,"OpenGL:",
2083                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2084                         0, 0, 0, 0, 0, "");
2085
2086                 uiDefButI(block, TOGN|BIT|USERDEF_DISABLE_MIPMAP_BIT, B_MIPMAPCHANGED, "Mipmaps",
2087                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
2088                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2089
2090                 uiDefButI(block, TOG|BIT|USERDEF_VERTEX_ARRAYS_BIT, 0, "Vertex Arrays",
2091                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
2092                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2093
2094                 uiDefBut(block, LABEL,0,"Audio:",
2095                         (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
2096                         0, 0, 0, 0, 0, "");
2097
2098                 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");
2099                 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");      
2100                 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");               
2101                 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");                   
2102
2103         } else if(U.userpref == 5) { /* file paths */
2104
2105
2106                 uiDefBut(block, TEX, 0, "Fonts: ",
2107                         (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
2108                         U.fontdir, 1.0, 63.0, 0, 0,
2109                         "The default directory to search for loading fonts");
2110                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2111                         (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
2112                         0, 0, 0, 0, 0, "Select the default font directory");
2113
2114                 uiDefBut(block, TEX, 0, "Textures: ",
2115                         (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
2116                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2117                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2118                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
2119                         0, 0, 0, 0, 0, "Select the default texture location");
2120
2121
2122                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2123                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
2124                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2125                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2126                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
2127                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2128
2129                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2130                         (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
2131                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2132                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2133                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
2134                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2135
2136
2137                 uiDefBut(block, TEX, 0, "Render: ",
2138                         (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
2139                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2140                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2141                         (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
2142                         0, 0, 0, 0, 0, "Select the default render output location");
2143
2144                 uiDefBut(block, TEX, 0, "Python: ",
2145                         (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-smfileselbut),buth,
2146                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2147                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2148                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
2149                         0, 0, 0, 0, 0, "Select the default Python script location");
2150
2151
2152                 uiDefBut(block, TEX, 0, "Sounds: ",
2153                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
2154                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2155                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2156                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
2157                         0, 0, 0, 0, 0, "Select the default sound location");
2158
2159                 uiDefBut(block, TEX, 0, "Temp: ",
2160                          (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
2161                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2162                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2163                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
2164                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2165
2166         }
2167
2168         uiDrawBlock(block);
2169         
2170         myortho2(-0.5, (float)(sa->winx)-.05, -0.5, (float)(sa->winy)-0.5);
2171         draw_area_emboss(sa);
2172         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2173         sa->win_swap= WIN_BACK_OK;
2174         
2175 }
2176
2177
2178 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2179 {
2180         unsigned short event= evt->event;
2181         short val= evt->val;
2182         
2183         if(val) {
2184                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2185
2186                 switch(event) {
2187                 case UI_BUT_EVENT:
2188                         if(val==B_ADD_THEME) {
2189                                 bTheme *btheme, *new;
2190                                 
2191                                 btheme= U.themes.first;
2192                                 new= MEM_callocN(sizeof(bTheme), "theme");
2193                                 memcpy(new, btheme, sizeof(bTheme));
2194                                 BLI_addhead(&U.themes, new);
2195                                 strcpy(new->name, "New User Theme");
2196                                 addqueue(sa->win, REDRAW, 1);
2197                         }
2198                         else if(val==B_DEL_THEME) {
2199                                 bTheme *btheme= U.themes.first;
2200                                 BLI_remlink(&U.themes, btheme);
2201                                 MEM_freeN(btheme);
2202                                 addqueue(sa->win, REDRAW, 1);
2203                         }
2204                         else if(val==B_NAME_THEME) {
2205                                 bTheme *btheme= U.themes.first;
2206                                 if(strcmp(btheme->name, "Default")==0) {
2207                                         strcpy(btheme->name, "New User Theme");
2208                                         addqueue(sa->win, REDRAW, 1);
2209                                 }
2210                         }
2211                         else if(val==B_UPDATE_THEME) {
2212                                 allqueue(REDRAWALL, 0);
2213                         }
2214                         else if(val==B_CHANGE_THEME) {
2215                                 th_curcol= TH_BACK;     // backdrop color is always there...
2216                                 addqueue(sa->win, REDRAW, 1);
2217                         }
2218                         else if(val==B_THEME_COPY) {
2219                                 if(th_curcol_ptr) {
2220                                         th_curcol_arr[0]= th_curcol_ptr[0];
2221                                         th_curcol_arr[1]= th_curcol_ptr[1];
2222                                         th_curcol_arr[2]= th_curcol_ptr[2];
2223                                         th_curcol_arr[3]= th_curcol_ptr[3];
2224                                         addqueue(sa->win, REDRAW, 1);
2225                                 }
2226                         }
2227                         else if(val==B_THEME_PASTE) {
2228                                 if(th_curcol_ptr) {
2229                                         th_curcol_ptr[0]= th_curcol_arr[0];
2230                                         th_curcol_ptr[1]= th_curcol_arr[1];
2231                                         th_curcol_ptr[2]= th_curcol_arr[2];
2232                                         th_curcol_ptr[3]= th_curcol_arr[3];
2233                                         allqueue(REDRAWALL, 0);
2234                                 }
2235                         }
2236                         else do_global_buttons(val);
2237                         
2238                         break;  
2239                 }
2240         }
2241 }
2242
2243 void init_infospace(ScrArea *sa)
2244 {
2245         SpaceInfo *sinfo;
2246         
2247         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2248         BLI_addhead(&sa->spacedata, sinfo);
2249
2250         sinfo->spacetype=SPACE_INFO;
2251 }
2252
2253 /* ******************** SPACE: BUTS ********************** */
2254
2255 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2256
2257 static void changebutspace(ScrArea *sa, void *spacedata)
2258 {
2259         if(G.v2d==0) return;
2260         
2261         test_view2d(G.v2d, curarea->winx, curarea->winy);
2262         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin-0.6, G.v2d->cur.ymax+0.6);
2263 }
2264
2265 void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2266 {
2267         unsigned short event= evt->event;
2268         short val= evt->val;
2269         SpaceButs *sbuts= curarea->spacedata.first;
2270         ScrArea *sa2, *sa3d;
2271         int nr, doredraw= 0;
2272
2273         if(val) {
2274                 
2275                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2276
2277                 switch(event) {
2278                 case UI_BUT_EVENT:
2279                         do_butspace(val);
2280                         break;
2281                         
2282                 case MIDDLEMOUSE:
2283                 case WHEELUPMOUSE:
2284                 case WHEELDOWNMOUSE:
2285                         view2dmove(event);      /* in drawipo.c */
2286                         break;
2287                 case PAGEUPKEY:
2288                         event= WHEELUPMOUSE;
2289                         view2dmove(event);      /* in drawipo.c */
2290                         break;
2291                 case PAGEDOWNKEY:
2292                         event= WHEELDOWNMOUSE;
2293                         view2dmove(event);      /* in drawipo.c */
2294                         break;
2295                         
2296                 case RIGHTMOUSE:
2297                         nr= pupmenu("Align buttons%t|Free %x0|Horizontal%x1|Vertical%x2");
2298                         if (nr>=0) {
2299                                 sbuts->align= nr;
2300                                 if(nr) {
2301                                         uiAlignPanelStep(sa, 1.0);
2302                                         do_buts_buttons(B_BUTSHOME);
2303                                 }
2304                         }
2305
2306                         break;
2307                 case PADPLUSKEY:
2308                         view2d_zoom(&sbuts->v2d, 0.06, curarea->winx, curarea->winy);
2309                         scrarea_queue_winredraw(curarea);
2310                         break;
2311                 case PADMINUS:
2312                         view2d_zoom(&sbuts->v2d, -0.075, curarea->winx, curarea->winy);
2313                         scrarea_queue_winredraw(curarea);
2314                         break;
2315                 case RENDERPREVIEW:
2316                         BIF_previewrender(sbuts);
2317                         break;
2318                 
2319                 case HOMEKEY:
2320                         do_buts_buttons(B_BUTSHOME);
2321                         break;
2322
2323
2324                 /* if only 1 view, also de persp, excluding arrowkeys */
2325                 case PAD0: case PAD1: case PAD3:
2326                 case PAD5: case PAD7: case PAD9:
2327                 case PADENTER: case ZKEY: case PKEY:
2328                         sa3d= 0;
2329                         sa2= G.curscreen->areabase.first;
2330                         while(sa2) {
2331                                 if(sa2->spacetype==SPACE_VIEW3D) {
2332                                         if(sa3d) return;
2333                                         sa3d= sa2;
2334                                 }
2335                                 sa2= sa2->next;
2336                         }
2337                         if(sa3d) {
2338                                 sa= curarea;
2339                                 areawinset(sa3d->win);
2340                                 
2341                                 if(event==PKEY) start_game();
2342                                 else if(event==ZKEY) toggle_shading();
2343                                 else persptoetsen(event);
2344                                 
2345                                 scrarea_queue_winredraw(sa3d);
2346                                 scrarea_queue_headredraw(sa3d);
2347                                 areawinset(sa->win);
2348                         }
2349                 }
2350         }
2351
2352         if(doredraw) scrarea_queue_winredraw(curarea);
2353 }
2354
2355 void set_rects_butspace(SpaceButs *buts)
2356 {
2357         /* buts space goes from (0,0) to (1280, 228) */
2358
2359         buts->v2d.tot.xmin= 0.0;
2360         buts->v2d.tot.ymin= 0.0;
2361         buts->v2d.tot.xmax= 1279.0;
2362         buts->v2d.tot.ymax= 228.0;
2363         
2364         buts->v2d.min[0]= 256.0;
2365         buts->v2d.min[1]= 42.0;
2366
2367         buts->v2d.max[0]= 2048.0;
2368         buts->v2d.max[1]= 450.0;
2369         
2370         buts->v2d.minzoom= 0.5;
2371         buts->v2d.maxzoom= 1.21;
2372         
2373         buts->v2d.scroll= 0;
2374         buts->v2d.keepaspect= 1;
2375         buts->v2d.keepzoom= 1;
2376         buts->v2d.keeptot= 1;
2377         
2378 }
2379
2380 void test_butspace(void)
2381 {
2382         ScrArea *area= curarea;
2383         int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
2384         
2385         G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
2386 }
2387
2388 void init_butspace(ScrArea *sa)
2389 {
2390         SpaceButs *buts;
2391         
2392         buts= MEM_callocN(sizeof(SpaceButs), "initbuts");
2393         BLI_addhead(&sa->spacedata, buts);
2394
2395         buts->spacetype= SPACE_BUTS;
2396         buts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
2397
2398         /* set_rects only does defaults, so after reading a file the cur has not changed */
2399         set_rects_butspace(buts);
2400         buts->v2d.cur= buts->v2d.tot;
2401 }
2402
2403 void extern_set_butspace(int fkey)
2404 {
2405         ScrArea *sa;
2406         SpaceButs *sbuts;
2407         
2408         /* when a f-key pressed: closest button window is initialized */
2409         if(curarea->spacetype==SPACE_BUTS) sa= curarea;
2410         else {
2411                 /* find area */
2412                 sa= G.curscreen->areabase.first;
2413                 while(sa) {
2414                         if(sa->spacetype==SPACE_BUTS) break;
2415                         sa= sa->next;
2416                 }
2417         }
2418         
2419         if(sa==0) return;
2420         
2421         if(sa!=curarea) areawinset(sa->win);
2422         
2423         sbuts= sa->spacedata.first;
2424         
2425         if(fkey==F4KEY) {
2426                 sbuts->mainb= CONTEXT_LOGIC;
2427         }
2428         else if(fkey==F5KEY) {
2429                 sbuts->mainb= CONTEXT_SHADING;
2430                 if(OBACT) {
2431                         if(OBACT->type==OB_CAMERA) 
2432                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2433                         else if(OBACT->type==OB_LAMP) 
2434                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
2435                         else  
2436                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2437                 }
2438                 else sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2439         }
2440         else if(fkey==F6KEY) {
2441                 sbuts->mainb= CONTEXT_SHADING;
2442                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
2443         }
2444         else if(fkey==F7KEY) sbuts->mainb= CONTEXT_OBJECT;
2445         else if(fkey==F8KEY) {
2446                 sbuts->mainb= CONTEXT_SHADING;
2447                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2448         }
2449         else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
2450         else if(fkey==F10KEY) sbuts->mainb= CONTEXT_SCENE;
2451
2452         scrarea_queue_headredraw(sa);
2453         scrarea_queue_winredraw(sa);
2454         BIF_preview_changed(sbuts);
2455 }
2456
2457 /* ******************** SPACE: SEQUENCE ********************** */
2458
2459 /*  extern void drawseqspace(ScrArea *sa, void *spacedata); BIF_drawseq.h */
2460
2461 void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2462 {
2463         unsigned short event= evt->event;
2464         short val= evt->val;
2465         SpaceSeq *sseq= curarea->spacedata.first;
2466         View2D *v2d= &sseq->v2d;
2467         extern Sequence *last_seq;
2468         float dx, dy;
2469         int doredraw= 0, cfra, first;
2470         short mval[2];
2471         
2472         if(curarea->win==0) return;
2473
2474         if(val) {
2475                 
2476                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2477
2478                 switch(event) {
2479                 case LEFTMOUSE:
2480                         if(sseq->mainb || view2dmove(event)==0) {
2481                                 
2482                                 first= 1;               
2483                                 set_special_seq_update(1);
2484
2485                                 do {
2486                                         getmouseco_areawin(mval);
2487                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
2488                                         
2489                                         cfra= (int)dx;
2490                                         if(cfra< 1) cfra= 1;
2491                                         /* else if(cfra> EFRA) cfra= EFRA; */
2492                                         
2493                                         if( cfra!=CFRA || first ) {
2494                                                 first= 0;
2495                                 
2496                                                 CFRA= cfra;
2497                                                 force_draw();
2498                                                 update_for_newframe();  /* for audio scrubbing */                                               
2499                                         }
2500                                 
2501                                 } while(get_mbut()&L_MOUSE);
2502                                 
2503                                 set_special_seq_update(0);
2504                                 
2505                                 update_for_newframe();
2506                         }
2507                         break;
2508                 case MIDDLEMOUSE:
2509                 case WHEELUPMOUSE:
2510                 case WHEELDOWNMOUSE:
2511                         if(sseq->mainb) break;
2512                         view2dmove(event);      /* in drawipo.c */
2513                         break;
2514                 case RIGHTMOUSE:
2515                         if(sseq->mainb) break;
2516                         mouse_select_seq();
2517                         break;
2518                 case PADPLUSKEY:
2519                         if(sseq->mainb) {
2520                                 sseq->zoom++;
2521                                 if(sseq->zoom>8) sseq->zoom= 8;
2522                         }
2523                         else {
2524                                 if(G.qual) {
2525                                         if(G.qual & LR_SHIFTKEY) insert_gap(25, CFRA);
2526                                         else if(G.qual & LR_ALTKEY) insert_gap(250, CFRA);
2527                                         allqueue(REDRAWSEQ, 0);
2528                                 }
2529                                 else {
2530                                         dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
2531                                         v2d->cur.xmin+= dx;
2532                                         v2d->cur.xmax-= dx;
2533                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2534                                 }
2535                         }
2536                         doredraw= 1;
2537                         break;
2538                 case PADMINUS:
2539                         if(sseq->mainb) {
2540                                 sseq->zoom--;
2541                                 if(sseq->zoom<1) sseq->zoom= 1;
2542                         }
2543                         else {
2544                                 if(G.qual) {
2545                                         if(G.qual & LR_SHIFTKEY) no_gaps();
2546                                 }
2547                                 else {
2548                                         dx= 0.15*(v2d->cur.xmax-v2d->cur.xmin);
2549                                         v2d->cur.xmin-= dx;
2550                                         v2d->cur.xmax+= dx;
2551                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2552                                 }
2553                         }
2554                         doredraw= 1;
2555                         break;
2556                 case HOMEKEY:
2557                         do_seq_buttons(B_SEQHOME);
2558                         break;
2559                 case PADPERIOD: 
2560                         if(last_seq) {
2561                                 CFRA= last_seq->startdisp;
2562                                 v2d->cur.xmin= last_seq->startdisp- (last_seq->len/20);
2563                                 v2d->cur.xmax= last_seq->enddisp+ (last_seq->len/20);
2564                                 update_for_newframe();
2565                         }
2566                         break;
2567                         
2568                 case AKEY:
2569                         if(sseq->mainb) break;
2570                         if(G.qual & LR_SHIFTKEY) {
2571                                 add_sequence(0);
2572                         }
2573                         else swap_select_seq();
2574                         break;
2575                 case BKEY:
2576                         if(sseq->mainb) break;
2577                         borderselect_seq();
2578                         break;
2579                 case CKEY:
2580                         if(last_seq && (last_seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))) {
2581                                 if(last_seq->flag & SEQ_LEFTSEL) CFRA= last_seq->startdisp;
2582                                 else CFRA= last_seq->enddisp-1;
2583                                 
2584                                 dx= CFRA-(v2d->cur.xmax+v2d->cur.xmin)/2;
2585                                 v2d->cur.xmax+= dx;
2586                                 v2d->cur.xmin+= dx;
2587                                 update_for_newframe();
2588                         }
2589                         else change_sequence();
2590                         break;
2591                 case DKEY:
2592                         if(sseq->mainb) break;
2593                         if(G.qual & LR_SHIFTKEY) add_duplicate_seq();
2594                         break;
2595                 case EKEY:
2596                         break;
2597                 case FKEY:
2598                         set_filter_seq();
2599                         break;
2600                 case GKEY:
2601                         if(sseq->mainb) break;
2602                         transform_seq('g');
2603                         break;
2604                 case MKEY:
2605                         if(G.qual & LR_ALTKEY) un_meta();
2606                         else {
2607                                 if ((last_seq) && (last_seq->type == SEQ_SOUND)) 
2608                                 {
2609                                         last_seq->flag ^= SEQ_MUTE;
2610                                         doredraw = 1;
2611                                 }
2612                                 else make_meta();
2613                         }
2614                         break;
2615                 case SKEY:
2616                         if(G.qual & LR_SHIFTKEY) seq_snapmenu();
2617                         break;
2618                 case TKEY:
2619                         touch_seq_files();
2620                         break;
2621                 case XKEY:
2622                 case DELKEY:
2623                         if(sseq->mainb) break;
2624                         del_seq();
2625                         break;
2626                 }
2627         }
2628
2629         if(doredraw) scrarea_queue_winredraw(curarea);
2630 }
2631
2632
2633 void init_seqspace(ScrArea *sa)
2634 {
2635         SpaceSeq *sseq;
2636         
2637         sseq= MEM_callocN(sizeof(SpaceSeq), "initseqspace");
2638         BLI_addhead(&sa->spacedata, sseq);
2639
2640         sseq->spacetype= SPACE_SEQ;
2641         sseq->zoom= 1;
2642         
2643         /* seq space goes from (0,8) to (250, 0) */
2644
2645         sseq->v2d.tot.xmin= 0.0;
2646         sseq->v2d.tot.ymin= 0.0;
2647         sseq->v2d.tot.xmax= 250.0;
2648         sseq->v2d.tot.ymax= 8.0;
2649         
2650         sseq->v2d.cur= sseq->v2d.tot;
2651
2652         sseq->v2d.min[0]= 10.0;
2653         sseq->v2d.min[1]= 4.0;
2654
2655         sseq->v2d.max[0]= 32000.0;
2656         sseq->v2d.max[1]= MAXSEQ;
2657         
2658         sseq->v2d.minzoom= 0.1;
2659         sseq->v2d.maxzoom= 10.0;
2660         
2661         sseq->v2d.scroll= L_SCROLL+B_SCROLL;
2662         sseq->v2d.keepaspect= 0;
2663         sseq->v2d.keepzoom= 0;
2664         sseq->v2d.keeptot= 0;
2665 }
2666
2667 /* ******************** SPACE: ACTION ********************** */
2668 extern void drawactionspace(ScrArea *sa, void *spacedata);
2669 extern void winqreadactionspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
2670
2671 static void changeactionspace(ScrArea *sa, void *spacedata)
2672 {
2673         if(G.v2d==0) return;
2674
2675         /* this sets the sub-areas correct, for scrollbars */
2676         test_view2d(G.v2d, curarea->winx, curarea->winy);
2677         
2678         /* action space uses weird matrices... local calculated in a function */
2679         // myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
2680 }
2681
2682
2683 void init_actionspace(ScrArea *sa)
2684 {
2685         SpaceAction *saction;
2686         
2687         saction= MEM_callocN(sizeof(SpaceAction), "initactionspace");
2688         BLI_addhead(&sa->spacedata, saction);
2689
2690         saction->spacetype= SPACE_ACTION;
2691
2692         saction->v2d.tot.xmin= 1.0;
2693         saction->v2d.tot.ymin=  0.0;
2694         saction->v2d.tot.xmax= 1000.0;
2695         saction->v2d.tot.ymax= 1000.0;
2696         
2697         saction->v2d.cur.xmin= -5.0;
2698         saction->v2d.cur.ymin= 0.0;
2699         saction->v2d.cur.xmax= 65.0;
2700         saction->v2d.cur.ymax= 1000.0;
2701
2702         saction->v2d.min[0]= 0.0;
2703         saction->v2d.min[1]= 0.0;
2704
2705         saction->v2d.max[0]= 32000.0;
2706         saction->v2d.max[1]= 1000.0;
2707         
2708         saction->v2d.minzoom= 0.01;
2709         saction->v2d.maxzoom= 10;
2710
2711         saction->v2d.scroll= R_SCROLL+B_SCROLL;
2712         saction->v2d.keepaspect= 0;
2713         saction->v2d.keepzoom= V2D_LOCKZOOM_Y;
2714         saction->v2d.keeptot= 0;
2715         
2716 }
2717
2718 void free_actionspace(SpaceAction *saction)
2719 {
2720         /* don't free saction itself */
2721         
2722         /* __PINFAKE */
2723 /*      if (saction->flag & SACTION_PIN)
2724                 if (saction->action)
2725                         saction->action->id.us --;
2726
2727 */      /* end PINFAKE */
2728 }
2729
2730
2731 /* ******************** SPACE: FILE ********************** */
2732
2733 void init_filespace(ScrArea *sa)
2734 {
2735         SpaceFile *sfile;
2736         
2737         sfile= MEM_callocN(sizeof(SpaceFile), "initfilespace");
2738         BLI_addhead(&sa->spacedata, sfile);
2739
2740         sfile->dir[0]= '/';
2741         sfile->type= FILE_UNIX;
2742
2743         sfile->spacetype= SPACE_FILE;
2744 }
2745
2746 void init_textspace(ScrArea *sa)
2747 {
2748         SpaceText *st;
2749         
2750         st= MEM_callocN(sizeof(SpaceText), "inittextspace");
2751         BLI_addhead(&sa->spacedata, st);
2752
2753         st->spacetype= SPACE_TEXT;      
2754         
2755         st->text= NULL;
2756         st->flags= 0;
2757         
2758         st->font_id= 5;
2759         st->lheight= 12;
2760         st->showlinenrs= 0;
2761         
2762         st->top= 0;
2763 }
2764
2765 void init_imaselspace(ScrArea *sa)
2766 {
2767         SpaceImaSel *simasel;
2768         
2769         simasel= MEM_callocN(sizeof(SpaceImaSel), "initimaselspace");
2770         BLI_addhead(&sa->spacedata, simasel);
2771
2772         simasel->spacetype= SPACE_IMASEL;
2773         
2774         simasel->mode = 7;
2775         strcpy (simasel->dir,  U.textudir);     /* TON */
2776         strcpy (simasel->file, "");
2777         strcpy(simasel->fole, simasel->file);
2778         strcpy(simasel->dor,  simasel->dir);
2779
2780         simasel->first_sel_ima  =  0;
2781         simasel->hilite_ima         =  0;
2782         simasel->firstdir               =  0;
2783         simasel->firstfile              =  0;
2784         simasel->cmap           =  0;
2785         simasel->returnfunc     =  0;
2786         
2787         simasel->title[0]       =  0;
2788         
2789         clear_ima_dir(simasel);
2790         
2791         // simasel->cmap= IMB_loadiffmem((int*)datatoc_cmap_tga, IB_rect|IB_cmap);
2792         simasel->cmap= IMB_ibImageFromMemory((int *)datatoc_cmap_tga, datatoc_cmap_tga_size, IB_rect|IB_cmap);
2793         if (!simasel->cmap) {
2794                 error("in console");
2795                 printf("Image select cmap file not found \n");
2796         }
2797 }
2798
2799 /* ******************** SPACE: SOUND ********************** */
2800
2801 extern void drawsoundspace(ScrArea *sa, void *spacedata);
2802 extern void winqreadsoundspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
2803
2804 void init_soundspace(ScrArea *sa)
2805 {
2806         SpaceSound *ssound;
2807         
2808         ssound= MEM_callocN(sizeof(SpaceSound), "initsoundspace");
2809         BLI_addhead(&sa->spacedata, ssound);
2810
2811         ssound->spacetype= SPACE_SOUND;
2812         
2813         /* sound space goes from (0,8) to (250, 0) */
2814
2815         ssound->v2d.tot.xmin= -4.0;
2816         ssound->v2d.tot.ymin= -4.0;
2817         ssound->v2d.tot.xmax= 250.0;
2818         ssound->v2d.tot.ymax= 255.0;
2819         
2820         ssound->v2d.cur.xmin= -4.0;
2821         ssound->v2d.cur.ymin= -4.0;
2822         ssound->v2d.cur.xmax= 50.0;
2823         ssound->v2d.cur.ymax= 255.0;
2824
2825         ssound->v2d.min[0]= 1.0;
2826         ssound->v2d.min[1]= 259.0;
2827
2828         ssound->v2d.max[0]= 32000.0;
2829         ssound->v2d.max[1]= 259;
2830         
2831         ssound->v2d.minzoom= 0.1;
2832         ssound->v2d.maxzoom= 10.0;
2833         
2834         ssound->v2d.scroll= B_SCROLL;
2835         ssound->v2d.keepaspect= 0;
2836         ssound->v2d.keepzoom= 0;
2837         ssound->v2d.keeptot= 0;
2838         
2839 }
2840
2841 void free_soundspace(SpaceSound *ssound)
2842 {
2843         /* don't free ssound itself */
2844         
2845         
2846 }
2847
2848 /* ******************** SPACE: IMAGE ********************** */
2849
2850 /*  extern void drawimagespace(ScrArea *sa, void *spacedata); BIF_drawimage.h */
2851
2852 void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2853 {
2854         unsigned short event= evt->event;
2855         short val= evt->val;
2856         SpaceImage *sima= curarea->spacedata.first;
2857         View2D *v2d= &sima->v2d;
2858 #ifdef NAN_TPT
2859         IMG_BrushPtr brush;
2860         IMG_CanvasPtr canvas;
2861         int rowBytes;
2862         short xy_prev[2], xy_curr[2];
2863         float uv_prev[2], uv_curr[2];
2864         extern VPaint Gvp;
2865 #endif /* NAN_TPT */    
2866         if(val==0) return;
2867
2868         if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2869         
2870         if (sima->flag & SI_DRAWTOOL) {
2871 #ifdef NAN_TPT
2872                 /* Draw tool is active */
2873                 switch(event) {
2874                         case LEFTMOUSE:
2875                                 /* Paranoia checks */
2876                                 if (!sima) break;
2877                                 if (!sima->image) break;
2878                                 if (!sima->image->ibuf) break;
2879                                 if (sima->image->packedfile) {
2880                                         error("Painting in packed images not supported");
2881                                         break;
2882                                 }
2883                         
2884                                 brush = IMG_BrushCreate(Gvp.size, Gvp.size, Gvp.r, Gvp.g, Gvp.b, Gvp.a);
2885                                 /* skipx is not set most of the times. Make a guess. */
2886                                 rowBytes = sima->image->ibuf->skipx ? sima->image->ibuf->skipx : sima->image->ibuf->x * 4;
2887                                 canvas = IMG_CanvasCreateFromPtr(sima->image->ibuf->rect, sima->image->ibuf->x, sima->image->ibuf->y, rowBytes);
2888
2889                                 getmouseco_areawin(xy_prev);
2890                                 while (get_mbut() & L_MOUSE) {
2891                                         getmouseco_areawin(xy_curr);
2892                                         /* Check if mouse position changed */
2893                                         if ((xy_prev[0] != xy_curr[0]) || (xy_prev[1] != xy_curr[1])) {
2894                                                 /* Convert mouse coordinates to u,v and draw */
2895                                                 areamouseco_to_ipoco(v2d, xy_prev, &uv_prev[0], &uv_prev[1]);
2896                                                 areamouseco_to_ipoco(v2d, xy_curr, &uv_curr[0], &uv_curr[1]);
2897                                                 IMG_CanvasDrawLineUV(canvas, brush, uv_prev[0], uv_prev[1], uv_curr[0], uv_curr[1]);
2898                                                 if (G.sima->lock) {
2899                                                         /* Make OpenGL aware of a changed texture */
2900                                                         free_realtime_image(sima->image);
2901                                                         /* Redraw this view and the 3D view */
2902                                                         force_draw_plus(SPACE_VIEW3D);
2903                                                 }
2904                                                 else {
2905                                                         /* Redraw only this view */
2906                                                         force_draw();
2907                                                 }
2908                                                 xy_prev[0] = xy_curr[0];
2909                                                 xy_prev[1] = xy_curr[1];
2910                                         }
2911                                 }
2912                                 /* Set the dirty bit in the image so that it is clear that it has been modified. */
2913                                 sima->image->ibuf->userflags |= IB_BITMAPDIRTY;
2914                                 if (!G.sima->lock) {
2915                                         /* Make OpenGL aware of a changed texture */
2916                                         free_realtime_image(sima->image);
2917                                         /* Redraw this view and the 3D view */
2918                                         force_draw_plus(SPACE_VIEW3D);
2919                                 }
2920                                 IMG_BrushDispose(brush);
2921                                 IMG_CanvasDispose(canvas);
2922                                 allqueue(REDRAWHEADERS, 0);
2923                                 break;
2924                 }
2925 #endif /* NAN_TPT */
2926         }
2927         else {
2928                 /* Draw tool is inactive */
2929                 switch(event) {
2930                         case LEFTMOUSE:
2931                                 if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
2932                                 else gesture();
2933                                 break;
2934                         case MIDDLEMOUSE:
2935                                 image_viewmove();
2936                                 break;
2937                         case RIGHTMOUSE:
2938                                 mouse_select_sima();
2939                                 break;
2940                         case AKEY:
2941                                 select_swap_tface_uv();
2942                                 break;
2943                         case BKEY:
2944                                 borderselect_sima();
2945                                 break;
2946                         case GKEY:
2947                                 transform_tface_uv('g');
2948                                 break;
2949                         case NKEY:
2950                                 if(G.qual & LR_CTRLKEY) replace_names_but();
2951                                 break;
2952                         case RKEY:
2953                                 transform_tface_uv('r');
2954                                 break;
2955                         case SKEY:
2956                                 transform_tface_uv('s');
2957                                 break;
2958                 }
2959         }
2960
2961         /* Events handled always (whether the draw tool is active or not) */
2962         switch (event) {
2963                 case MIDDLEMOUSE:
2964                         image_viewmove();
2965                         break;