Esempio n. 1
0
/* check if can open a handle to the spaceball, load the driver functions
   and start receiving input from the spaceball */
int SPW_CheckForSpaceballWin32(void * win)
{
  char classname[25];
  SiOpenData oData;

  if (Spw_DeviceHandle == SI_NO_HANDLE) {
    if (SiInitialize() != SPW_DLL_LOAD_ERROR) {
      GetClassName((HWND)win, classname, sizeof(classname));
      SiOpenWinInit(&oData, (HWND)win);
      
      Spw_DeviceHandle = SiOpen(classname, SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);

      if (Spw_DeviceHandle != SI_NO_HANDLE) {
        SiSetUiMode(Spw_DeviceHandle, SI_UI_ALL_CONTROLS);
        return TRUE;
      }
      else {
        SiTerminate();
        return FALSE;
      }
    }
    else return FALSE;
  } 
  else return TRUE;
}
Esempio n. 2
0
/*--------------------------------------------------------------------------
 * Function: SbInit()
 *
 * Description:
 *    This function initializes the Spaceball and opens ball for use.
 *
 *
 * Args: None
 *
 *
 * Return Value:
 *    int  res         result of SiOpen, =0 if Fail =1 if it Works
 *
 *--------------------------------------------------------------------------*/
int
SbInit()
{
    int res;                             /* result of SiOpen, to be returned  */
    SiOpenData oData;                    /* OS Independent data to open ball  */

    /*init the SpaceWare input library */
    if (SiInitialize() == SPW_DLL_LOAD_ERROR)
    {
        MessageBox(hWndMain,"Error: Could not load SiAppDll dll files",
                   NULL, MB_ICONEXCLAMATION);
    }

    SiOpenWinInit (&oData, hWndMain);    /* init Win. platform specific data  */
    SiSetUiMode(devHdl, SI_UI_ALL_CONTROLS); /* Config SoftButton Win Display */

    /* open data, which will check for device type and return the device handle
       to be used by this function */
    if ( (devHdl = SiOpen ("sbtest32", SI_ANY_DEVICE, SI_NO_MASK,
                           SI_EVENT, &oData)) == NULL)
    {
        SiTerminate();  /* called to shut down the SpaceWare input library */
        res = 0;        /* could not open device */
        return res;
    }
    else
    {
        res = 1;        /* opened device succesfully */
        return res;
    }
}
Esempio n. 3
0
// SpaceBallConfig_Activate():
XCALL_ (int) SpaceBallConfig_Activate( long version, GlobalFunc *global,
                                       void *local, void *serverData ) {
  if( version != LWLAYOUTGENERIC_VERSION )
    return AFUNC_BADVERSION;

  SiSetUiMode(hdl, SI_UI_ALL_CONTROLS);

  return AFUNC_OK;
}
Esempio n. 4
0
void InitializeSpaceball(SPW_WINPARAM dpy, 
                         SPW_WINDOW win,
                         SiSpwHandlers *DspHandlers,
                         SpaceballControlStruct *scs)
{
  
#ifdef OS_WIN32
   SiOpenData oData;
   if (SiInitialize() == SPW_DLL_LOAD_ERROR)  
     {
	  MessageBox(NULL,"Error: Could not load SiAppDll dll files",
		         NULL, MB_ICONEXCLAMATION);
	 }
   SiOpenWinInit (&oData, win);

   if (!(scs->devHdl = SiOpen ("Widget World", SI_ANY_DEVICE, SI_NO_MASK,
                             SI_EVENT, &oData)))

      {
      SiTerminate();
      MessageBox( win, "Sorry - No supported Spacetec IMC device available.\n",
                 NULL, MB_OK );
      if (win)
         DestroyWindow(win);
      
      ExitProcess(1);
   }
   SiSetUiMode(scs->devHdl, SI_UI_ALL_CONTROLS);

#else /* X11 */
  if (!SPW_InputCheckForSpaceball(dpy, win, "Widget World"))
    {
      printf ("Sorry - No Spaceball found.\n");
      exit(0);
    }
#endif

   DspHandlers->button.func    = SbButtonEvent;
   DspHandlers->motion.func    = SbMotionEvent;
   DspHandlers->zero.func      = SbMotionEvent;
   DspHandlers->exception.func = NULL;

   DspHandlers->button.data    = (void *)(scs);
   DspHandlers->motion.data    = (void *)(scs);
   DspHandlers->zero.data      = (void *)(scs);
   DspHandlers->exception.data = NULL;

#ifndef OS_WIN32
  spw_dispatch->display = dpy;
  spw_dispatch->spwbw   = NULL;
#endif

} /* end of InitializeSpaceball */
Esempio n. 5
0
// SpaceBall_Create():
LWInstance SpaceBall_Create( void *data, void *context, LWError *error ) {
  // Check for LWSN; if so, exit now
  unsigned long sysid = ( unsigned long )global( LWSYSTEMID_GLOBAL, GFUSE_TRANSIENT );
  if( (sysid & LWSYS_TYPEBITS) != LWSYS_LAYOUT )
    return &instance_count;

  if( instance_count > 0 ) {
    *error = "SpaceBall Error:  Only one instance of the driver can be activate at a time";
    return NULL;
  }

  instance_count++;

  // Get some globals
  command         = (LWCommandFunc   *)global( "LW Command Interface",   GFUSE_ACQUIRE );
  instance_update = (LWInstUpdate    *)global( LWINSTUPDATE_GLOBAL,      GFUSE_ACQUIRE );
  hdi             = (HostDisplayInfo *)global( LWHOSTDISPLAYINFO_GLOBAL, GFUSE_ACQUIRE );
  message         = (LWMessageFuncs  *)global( LWMESSAGEFUNCS_GLOBAL,    GFUSE_ACQUIRE );

  // Hijack Layout's window function
  orig_window_proc = (WNDPROC)SetWindowLong( hdi->window, GWL_WNDPROC, (long)SpaceBallWindowProc );

  // Load Settings
  LoadSettings();

  // Initialize the SpaceBall drivers
  SiInitialize();
  SiOpenWinInit (&oData, hdi->window);
  SiSetUiMode(hdl, (open_config_on_startup ? SI_UI_ALL_CONTROLS : SI_UI_NO_CONTROLS ) );
  hdl = SiOpen ("Lightwave 3D (Layout)", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);
  if( hdl == SI_NO_HANDLE)  {
    SpaceBall_End();
    *error = "SpaceBall Error:  Couldn't open spaceball drivers";
    return NULL;
  }

  error = NULL;
  return &instance_count;
}
// Windows code to talk to Spaceball device
static void vmd_setupwin32spaceball(wgldata *glwsrv) {
  SiOpenData oData;
  enum SpwRetVal res;

  // init the sball pointer to NULL by default, used to determine if we
  // had a healthy init later on.
  glwsrv->sball = NULL;

  switch (SiInitialize()) {
    case SPW_NO_ERROR:
      break;

    case SPW_DLL_LOAD_ERROR:
      msgInfo << "Spaceball driver not installed.  Spaceball interface disabled." << sendmsg;
      return;

    default:
      msgInfo << "Spaceball did not initialize properly.  Spaceball interface disabled." << sendmsg;
      return;
  }

  SiOpenWinInit(&oData, glwsrv->hWnd);            // init win platform data
  SiSetUiMode(glwsrv->sball, SI_UI_ALL_CONTROLS); // config softbutton display

  // actually start a connection to the device now that the UI mode
  // and window system data are setup.
  glwsrv->sball = SiOpen("VMD", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);
  if ((glwsrv->sball == NULL) || (glwsrv->sball == SI_NO_HANDLE)) {
    SiTerminate(); // shutdown spaceware input library
    msgInfo << "Spaceball is unresponsive.  Spaceball interface disabled." << sendmsg;
    glwsrv->sball = NULL; // NULL out the handle for sure.
    return;
  }

  res = SiBeep(glwsrv->sball, "CcCc"); // beep the spaceball
  if ((glwsrv->sball != NULL) && (glwsrv->sball != SI_NO_HANDLE))
    msgInfo << "Spaceball found, software interface initialized." << sendmsg;
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
// Entry point into the program.
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, INT nCmdShow)
{
    Instance = hInstance;

    InitCommonControls();

    // A monospaced font
    FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0,
        FW_REGULAR, false,
        false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console");
    if(!FixedFont)
        FixedFont = (HFONT)GetStockObject(SYSTEM_FONT);

    // Create the root windows: one for control, with text, and one for
    // the graphics
    CreateMainWindows();

    ThawWindowPos(TextWnd);
    ThawWindowPos(GraphicsWnd);

    ShowWindow(TextWnd, SW_SHOWNOACTIVATE);
    ShowWindow(GraphicsWnd, SW_SHOW);

    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    SwapBuffers(GetDC(GraphicsWnd));
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    SwapBuffers(GetDC(GraphicsWnd));

    // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc)
    InitHeaps();

    // A filename may have been specified on the command line; if so, then
    // strip any quotation marks, and make it absolute.
    char file[MAX_PATH] = "";
    if(strlen(lpCmdLine)+1 < MAX_PATH) {
        char *s = lpCmdLine;
        while(*s == ' ' || *s == '"') s++;
        strcpy(file, s);
        s = strrchr(file, '"');
        if(s) *s = '\0';
    }
    if(*file != '\0') {
        GetAbsoluteFilename(file);
    }

#ifdef HAVE_SPACEWARE
    // Initialize the SpaceBall, if present. Test if the driver is running
    // first, to avoid a long timeout if it's not.
    HWND swdc = FindWindow("SpaceWare Driver Class", NULL);
    if(swdc != NULL) {
        SiOpenData sod;
        SiInitialize();
        SiOpenWinInit(&sod, GraphicsWnd);
        SpaceNavigator =
            SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod);
        SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS);
    }
#endif

    // Call in to the platform-independent code, and let them do their init
    SS.Init();
    if(strcmp(file, ""))
        SS.OpenFile(file);

    // And now it's the message loop. All calls in to the rest of the code
    // will be from the wndprocs.
    MSG msg;
    DWORD ret;
    while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) {
#ifdef HAVE_SPACEWARE
        // Is it a message from the six degree of freedom input device?
        if(ProcessSpaceNavigatorMsg(&msg)) goto done;
#endif

        // A message from the keyboard, which should be processed as a keyboard
        // accelerator?
        if(msg.message == WM_KEYDOWN) {
            if(ProcessKeyDown(msg.wParam)) goto done;
        }
        if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) {
            // If the user presses the Alt key when the text window has focus,
            // then that should probably go to the graphics window instead.
            SetForegroundWindow(GraphicsWnd);
        }

        // None of the above; so just a normal message to process.
        TranslateMessage(&msg);
        DispatchMessage(&msg);
done:
        SS.DoLater();
    }

#ifdef HAVE_SPACEWARE
    if(swdc != NULL) {
        if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator);
        SiTerminate();
    }
#endif

    // Write everything back to the registry
    FreezeWindowPos(TextWnd);
    FreezeWindowPos(GraphicsWnd);

    // Free the memory we've used; anything that remains is a leak.
    SK.Clear();
    SS.Clear();

    return 0;
}