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 $
4
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
* ***** BEGIN GPL LICENSE BLOCK *****
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
9
* of the License, or (at your option) any later version.
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
76
81
GHOST_WindowHandle ghostwin;
78
/* Handler and private data for handler */
83
/* Handler and private data for handler */
79
84
WindowHandlerFP handler;
83
88
int size[2], position[2];
84
89
int active, visible;
86
/* Last known mouse/button/qualifier state */
91
/* Last known mouse/button/qualifier state */
88
93
int lqual; /* (LR_SHFTKEY, LR_CTRLKEY, LR_ALTKEY, LR_COMMANDKEY) */
89
94
int lmbut; /* (L_MOUSE, M_MOUSE, R_MOUSE) */
91
/* Tracks the faked mouse button, if non-zero it is
92
* the event number of the last faked button.
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
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) */
110
/* Tracks the faked mouse button, if non-zero it is
111
* the event number of the last faked button.
115
/* Last known ndof device state
116
* note that the ghost device manager
117
* can handle any number of devices, but ghostwinlay can't
119
float ndof[7]; /* tx, ty, tz, rx, ry, rz, dt */
96
121
GHOST_TimerTaskHandle timer;
320
345
GHOST_WindowHandle ghostwin;
321
346
GHOST_TWindowState inital_state;
322
347
int scr_w, scr_h;
324
350
winlay_get_screensize(&scr_w, &scr_h);
325
351
posy= (scr_h-posy-sizey);
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;
332
#ifdef _WIN32 // FULLSCREEN
333
// if (start_maximized == G_WINDOWSTATE_FULLSCREEN)
334
// inital_state= GHOST_kWindowStateFullScreen;
336
inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
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;
356
inital_state = start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
339
358
inital_state += macPrefState;
343
361
ghostwin= GHOST_CreateWindow(g_system,
435
456
void window_set_custom_cursor_ex(Window *win, BCursor *cursor, int 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);
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);
512
static void update_tablet_data(Window *win, GHOST_WindowHandle ghostwin) {
513
const GHOST_TabletData *td= GHOST_GetTabletData(ghostwin);
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;
523
win->activedevice = DEV_MOUSE;
525
win->xtilt = win->ytilt = 0.0;
491
530
static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
493
532
GHOST_TEventType type= GHOST_GetEventType(evt);
557
case GHOST_kEventNDOFMotion: {
558
// update ndof device data, and dispatch motion event
560
GHOST_TEventNDOFData *sb= data;
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]);
574
// window_handle(win, NDOFMOTION, win->ndof[6]);
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);
589
case GHOST_kEventNDOFButton: {
590
GHOST_TEventNDOFData *sb= data;
592
// printf("this is a button %i\n", sb->buttons);
593
window_handle(win, NDOFBUTTON, sb->buttons);
517
596
case GHOST_kEventCursorMove: {
518
597
if(win->active == 1) {
519
598
GHOST_TEventCursorData *cd= data;
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;
606
update_tablet_data(win, ghostwin);
526
607
window_handle(win, MOUSEX, win->lmouse[0]);
527
608
window_handle(win, MOUSEY, win->lmouse[1]);
709
799
mval[1]= win->lmouse[1];
802
float window_get_pressure(Window *win) {
803
return win->pressure;
806
void window_get_tilt(Window *win, float *xtilt, float *ytilt) {
811
short window_get_activedevice(Window *win) {
812
return win->activedevice;
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;
898
#define PATH_SEP "\\"
904
void window_open_ndof(Window* win)
906
char *inst_path, *plug_path;
907
const char *plug_dir = "plugins";
908
const char *plug_name = "3DxNdofBlender.plug";
911
// build the plugin path
913
inst_path = get_install_dir(); // path to main blender exec/bundle
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");
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);
926
MEM_freeN(inst_path);
929
ndofLib = PIL_dynlib_open(plug_path);
931
/* On systems where blender is installed in /usr/bin/blender, ~/.blender/plugins/ is a better place to look */
935
MEM_freeN(plug_path);
938
inst_path = BLI_gethome();
940
size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2
941
+ strlen(plug_name) + 1;
943
if (!strstr(inst_path, ".blender")) {
944
len += strlen(".blender") + strlen(PATH_SEP);
947
plug_path = MEM_mallocN(len, "ndofpluginpath");
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);
955
strcat(plug_path, plug_dir);
956
strcat(plug_path, PATH_SEP);
957
strcat(plug_path, plug_name);
961
ndofLib = PIL_dynlib_open(plug_path);
967
fprintf(stderr, "plugin path=%s; ndofLib=%p\n", plug_path, (void*)ndofLib);
971
MEM_freeN(plug_path);
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"));
981
GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0);
986
char *getClipboard(int flag) {
987
return (char*)GHOST_getClipboard(flag);
990
void putClipboard(char *buffer, int flag) {
991
GHOST_putClipboard((GHOST_TInt8*)buffer, flag);