~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/src/ghostwinlay.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: ghostwinlay.c,v 1.44 2006/06/18 11:38:34 ton Exp $
 
2
 * $Id: ghostwinlay.c 14673 2008-05-04 11:00:33Z campbellbarton $
3
3
 *
4
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
8
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.
 
9
 * of the License, or (at your option) any later version.
13
10
 *
14
11
 * This program is distributed in the hope that it will be useful,
15
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
24
 *
28
25
 * Contributor(s): none yet.
29
26
 *
30
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
27
 * ***** END GPL LICENSE BLOCK *****
31
28
 */
32
29
#include <stdlib.h>
33
30
#include <stdio.h>
 
31
#include <string.h>
34
32
 
35
33
#ifdef HAVE_CONFIG_H
36
34
#include <config.h>
55
53
#include "BIF_usiblender.h"
56
54
#include "BIF_cursors.h"
57
55
 
 
56
#include "PIL_dynlib.h"
 
57
 
58
58
#include "mydevice.h"
59
59
#include "blendef.h"
60
60
 
61
61
#include "winlay.h"
62
62
 
 
63
#include <math.h>
 
64
 
 
65
 
63
66
#ifdef __APPLE__
64
67
#include <OpenGL/OpenGL.h>
65
68
#define __CARBONSOUND__
 
69
  /* XXX BIG WARNING: carbon.h should not be included in blender/src code, it conflicts with struct ID */
 
70
#define ID ID_
66
71
#include <Carbon/Carbon.h>
67
72
 
68
73
/*declarations*/
75
80
struct _Window {
76
81
        GHOST_WindowHandle      ghostwin;
77
82
        
78
 
                /* Handler and private data for handler */
 
83
        /* Handler and private data for handler */
79
84
        WindowHandlerFP         handler;
80
85
        void                            *user_data;
81
86
        
82
 
                /* Window state */
 
87
        /* Window state */
83
88
        int             size[2], position[2];
84
89
        int             active, visible;
85
90
        
86
 
                /* Last known mouse/button/qualifier state */
 
91
        /* Last known mouse/button/qualifier state */
87
92
        int             lmouse[2];
88
93
        int             lqual;          /* (LR_SHFTKEY, LR_CTRLKEY, LR_ALTKEY, LR_COMMANDKEY) */
89
94
        int             lmbut;          /* (L_MOUSE, M_MOUSE, R_MOUSE) */
90
95
 
91
 
                /* Tracks the faked mouse button, if non-zero it is
92
 
                 * the event number of the last faked button.
93
 
                 */
 
96
        /* xtilt and ytilt represent how much the pen is tilted away from 
 
97
         * vertically upright in either the X or Y direction, with X and Y the
 
98
         * axes of the tablet surface.
 
99
         * In other words, Xtilt and Ytilt are components of a vector created by projecting
 
100
         * the pen's angle in 3D space vertically downwards on to the XY plane
 
101
         * --Matt
 
102
         */
 
103
        float pressure;                 /* tablet pressure - 0.0 (no pressure) to 1.0 (full pressure) */
 
104
                                                        /* mouse clicks and non-contacting stylus buttons generate pressure of 0.0. */
 
105
        float xtilt, ytilt;             /* tablet tilt value - x and y components of 3D angle 
 
106
                                                         * ranging from 0.0 (pen upright) to 1.0 (pen fully leaning over) */
 
107
        short activedevice;             /* Active input device currently in use (DEV_MOUSE, DEV_STYLUS, DEV_ERASER) */
 
108
        
 
109
        
 
110
        /* Tracks the faked mouse button, if non-zero it is
 
111
         * the event number of the last faked button.
 
112
         */
94
113
        int             faked_mbut;
95
114
 
 
115
                /* Last known ndof device state
 
116
         * note that the ghost device manager 
 
117
         * can handle any number of devices, but ghostwinlay can't
 
118
         */
 
119
    float   ndof[7];    /* tx, ty, tz, rx, ry, rz, dt */
 
120
 
96
121
        GHOST_TimerTaskHandle   timer;
97
122
        int                                             timer_event;
98
123
};
320
345
        GHOST_WindowHandle ghostwin;
321
346
        GHOST_TWindowState inital_state;
322
347
        int scr_w, scr_h;
 
348
    int i;
323
349
 
324
350
        winlay_get_screensize(&scr_w, &scr_h);
325
351
        posy= (scr_h-posy-sizey);
326
352
        
327
 
        /* create a fullscreen window on unix by default*/
328
 
#if !defined(WIN32) && !defined(__APPLE__)
329
 
        inital_state= start_maximized?
330
 
                GHOST_kWindowStateFullScreen:GHOST_kWindowStateNormal;
331
 
#else
332
 
#ifdef _WIN32   // FULLSCREEN
333
 
//      if (start_maximized == G_WINDOWSTATE_FULLSCREEN)
334
 
//              inital_state= GHOST_kWindowStateFullScreen;
335
 
//      else
336
 
                inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
337
 
#else                   // APPLE
338
 
        inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
 
353
        if (start_maximized == G_WINDOWSTATE_FULLSCREEN)
 
354
                inital_state = start_maximized?GHOST_kWindowStateFullScreen:GHOST_kWindowStateNormal;
 
355
        else
 
356
                inital_state = start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
 
357
#ifdef __APPLE__
339
358
        inital_state += macPrefState;
340
359
#endif
341
 
#endif
342
360
 
343
361
        ghostwin= GHOST_CreateWindow(g_system, 
344
362
                                                                title, 
360
378
                        
361
379
                        win->lmouse[0]= win->size[0]/2;
362
380
                        win->lmouse[1]= win->size[1]/2;
363
 
                        
 
381
 
 
382
            for (i = 0; i < 7; ++i)
 
383
                win->ndof[i] = 0;
 
384
                
364
385
                        
365
386
                } else {
366
387
                        GHOST_DisposeWindow(g_system, ghostwin);
435
456
void window_set_custom_cursor_ex(Window *win, BCursor *cursor, int useBig) {
436
457
        if (useBig) {
437
458
                GHOST_SetCustomCursorShapeEx(win->ghostwin, 
438
 
                        cursor->big_bm, cursor->big_mask, 
 
459
                        (GHOST_TUns8 *)cursor->big_bm, (GHOST_TUns8 *)cursor->big_mask, 
439
460
                        cursor->big_sizex,cursor->big_sizey,
440
461
                        cursor->big_hotx,cursor->big_hoty,
441
462
                        cursor->fg_color, cursor->bg_color);
442
463
        } else {
443
464
                GHOST_SetCustomCursorShapeEx(win->ghostwin, 
444
 
                        cursor->small_bm, cursor->small_mask, 
 
465
                        (GHOST_TUns8 *)cursor->small_bm, (GHOST_TUns8 *)cursor->small_mask, 
445
466
                        cursor->small_sizex,cursor->small_sizey,
446
467
                        cursor->small_hotx,cursor->small_hoty,
447
468
                        cursor->fg_color, cursor->bg_color);
488
509
        return to_on?(val|bit):(val&~bit);
489
510
}
490
511
 
 
512
static void update_tablet_data(Window *win, GHOST_WindowHandle ghostwin) {
 
513
        const GHOST_TabletData *td= GHOST_GetTabletData(ghostwin);
 
514
        
 
515
        /* if there's tablet data from an active tablet device then use it,
 
516
         * otherwise set all tablet related data to default */
 
517
        if ((td != NULL) && ELEM(td->Active, DEV_STYLUS, DEV_ERASER)) {
 
518
                win->activedevice = (short)td->Active;
 
519
                win->pressure = td->Pressure;
 
520
                win->xtilt = td->Xtilt;
 
521
                win->ytilt = td->Ytilt;
 
522
        } else {
 
523
                win->activedevice = DEV_MOUSE;
 
524
                win->pressure = 1.0;
 
525
                win->xtilt = win->ytilt = 0.0;
 
526
        }
 
527
}
 
528
 
 
529
 
491
530
static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) 
492
531
{
493
532
        GHOST_TEventType type= GHOST_GetEventType(evt);
514
553
                }
515
554
                
516
555
                switch (type) {
 
556
 
 
557
        case GHOST_kEventNDOFMotion: {
 
558
            // update ndof device data, and dispatch motion event
 
559
 
 
560
            GHOST_TEventNDOFData *sb= data;
 
561
                        
 
562
                                // no scaling per sfgoros patch
 
563
            win->ndof[0] = sb->tx;
 
564
            win->ndof[1] = sb->ty;
 
565
            win->ndof[2] = sb->tz;
 
566
            win->ndof[3] = sb->rx;
 
567
            win->ndof[4] = sb->ry;
 
568
            win->ndof[5] = sb->rz;
 
569
            win->ndof[6] = sb->delta;
 
570
 //             printf(" motion capted %f %f %f %f %f %f %f \n", win->ndof[0], win->ndof[1], win->ndof[2],
 
571
 //                                                              win->ndof[3], win->ndof[4], win->ndof[5], win->ndof[6]);
 
572
 
 
573
 
 
574
 //          window_handle(win, NDOFMOTION, win->ndof[6]);
 
575
 
 
576
 //       start interaction for larger than teeny-tiny motions
 
577
 //         if (fabs(win->ndof[0] > 0.003f) ||
 
578
 //             fabs(win->ndof[1] > 0.003f) ||
 
579
 //          fabs(win->ndof[2] > 0.003f) ||
 
580
 //               fabs(win->ndof[3] > 0.003f) ||
 
581
 //               fabs(win->ndof[4] > 0.003f) ||
 
582
 //              fabs(win->ndof[5] > 0.003f)) {
 
583
                    window_handle(win, NDOFMOTION, 1);
 
584
 //    printf("ok\n");
 
585
 //    }
 
586
;
 
587
          break;
 
588
        }
 
589
        case GHOST_kEventNDOFButton: {
 
590
                        GHOST_TEventNDOFData *sb= data;
 
591
                        
 
592
//                      printf("this is a button %i\n", sb->buttons);
 
593
                        window_handle(win, NDOFBUTTON, sb->buttons);
 
594
                        break;
 
595
        }
517
596
                case GHOST_kEventCursorMove: {
518
597
                        if(win->active == 1) {
519
598
                                GHOST_TEventCursorData *cd= data;
 
599
                                
520
600
                                int cx, cy;
521
601
                                
522
602
                                GHOST_ScreenToClient(win->ghostwin, cd->x, cd->y, &cx, &cy);
523
603
                                win->lmouse[0]= cx;
524
604
                                win->lmouse[1]= (win->size[1]-1) - cy;
525
605
                                
 
606
                                update_tablet_data(win, ghostwin);                      
526
607
                                window_handle(win, MOUSEX, win->lmouse[0]);
527
608
                                window_handle(win, MOUSEY, win->lmouse[1]);
528
609
                        }
557
638
                        } else {
558
639
                                win->lmbut= change_bit(win->lmbut, R_MOUSE, val);
559
640
                        }
 
641
                        
 
642
                        update_tablet_data(win, ghostwin);
560
643
                        window_handle(win, bbut, val);
561
644
                        
562
645
                        break;
677
760
        return 1;
678
761
}
679
762
 
 
763
void window_get_ndof(Window* win, float* sbval) {
 
764
    int i;
 
765
    for (i = 0; i < 7; ++i) {
 
766
        *sbval++ = win->ndof[i];
 
767
    }
 
768
}
 
769
 
680
770
char *window_get_title(Window *win) {
681
771
        char *title= GHOST_GetTitle(win->ghostwin);
682
772
        char *mem_title= BLI_strdup(title);
709
799
        mval[1]= win->lmouse[1];
710
800
}
711
801
 
 
802
float window_get_pressure(Window *win) {
 
803
        return win->pressure;
 
804
}
 
805
 
 
806
void window_get_tilt(Window *win, float *xtilt, float *ytilt) {
 
807
        *xtilt= win->xtilt;
 
808
        *ytilt= win->ytilt;
 
809
}
 
810
 
 
811
short window_get_activedevice(Window *win) {
 
812
        return win->activedevice;
 
813
}
 
814
 
712
815
void window_get_position(Window *win, int *posx_r, int *posy_r) {
713
816
        *posx_r= win->position[0];
714
817
        *posy_r= win->position[1];
790
893
Window *winlay_get_active_window(void) {
791
894
        return active_gl_window;
792
895
}
 
896
 
 
897
#ifdef _WIN32
 
898
#define PATH_SEP                "\\"
 
899
#else
 
900
#define PATH_SEP                "/"
 
901
#endif
 
902
 
 
903
 
 
904
void window_open_ndof(Window* win)
 
905
{
 
906
        char *inst_path, *plug_path;
 
907
        const char *plug_dir = "plugins";
 
908
        const char *plug_name = "3DxNdofBlender.plug";
 
909
        PILdynlib *ndofLib;
 
910
        
 
911
        // build the plugin path
 
912
        plug_path = NULL;
 
913
        inst_path = get_install_dir(); // path to main blender exec/bundle
 
914
        if (inst_path) {
 
915
                // assume the ndof plugin is located in the plug-in dir
 
916
                size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2
 
917
                             + strlen(plug_name) + 1;
 
918
                plug_path = MEM_mallocN(len, "ndofpluginpath");
 
919
                if (plug_path) {
 
920
                        strncpy(plug_path, inst_path, len);
 
921
                        strcat(plug_path, PATH_SEP);
 
922
                        strcat(plug_path, plug_dir);
 
923
                        strcat(plug_path, PATH_SEP);
 
924
                        strcat(plug_path, plug_name);
 
925
                }
 
926
                MEM_freeN(inst_path);
 
927
        }
 
928
        
 
929
        ndofLib = PIL_dynlib_open(plug_path);
 
930
        
 
931
        /* On systems where blender is installed in /usr/bin/blender, ~/.blender/plugins/ is a better place to look */
 
932
        if (ndofLib==NULL) {
 
933
                
 
934
                if (plug_path) {
 
935
                        MEM_freeN(plug_path);
 
936
                }
 
937
                
 
938
                inst_path = BLI_gethome();
 
939
                if (inst_path) {
 
940
                        size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2
 
941
                                         + strlen(plug_name) + 1;
 
942
                        
 
943
                        if (!strstr(inst_path, ".blender")) {
 
944
                                len += strlen(".blender") + strlen(PATH_SEP);
 
945
                        }
 
946
                        
 
947
                        plug_path = MEM_mallocN(len, "ndofpluginpath");
 
948
                        if (plug_path) {
 
949
                                strncpy(plug_path, inst_path, len);
 
950
                                strcat(plug_path, PATH_SEP);
 
951
                                if (!strstr(inst_path, ".blender")) {
 
952
                                        strcat(plug_path, ".blender");
 
953
                                        strcat(plug_path, PATH_SEP);
 
954
                                }
 
955
                                strcat(plug_path, plug_dir);
 
956
                                strcat(plug_path, PATH_SEP);
 
957
                                strcat(plug_path, plug_name);
 
958
                        }
 
959
                }
 
960
                
 
961
                ndofLib = PIL_dynlib_open(plug_path);
 
962
        }
 
963
        
 
964
        
 
965
        
 
966
#if 0
 
967
        fprintf(stderr, "plugin path=%s; ndofLib=%p\n", plug_path, (void*)ndofLib);
 
968
#endif
 
969
        
 
970
        if (plug_path)
 
971
                MEM_freeN(plug_path);
 
972
        
 
973
        if (ndofLib) {
 
974
                G.ndofdevice = 0 - GHOST_OpenNDOF(g_system, win->ghostwin, 
 
975
                               PIL_dynlib_find_symbol(ndofLib, "ndofInit"),
 
976
                               PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"),
 
977
                               PIL_dynlib_find_symbol(ndofLib, "ndofOpen"));
 
978
                
 
979
                }
 
980
    else {
 
981
        GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0);
 
982
        G.ndofdevice = -1;
 
983
    }
 
984
 }
 
985
 
 
986
char *getClipboard(int flag) {
 
987
        return (char*)GHOST_getClipboard(flag);
 
988
}
 
989
 
 
990
void putClipboard(char *buffer, int flag) {
 
991
        GHOST_putClipboard((GHOST_TInt8*)buffer, flag);
 
992
}