コード例 #1
0
ファイル: MouseTool.cpp プロジェクト: VisualIdeation/Vrui
void MouseTool::frame(void)
{
    if(transformEnabled)
    {
        /* Calculate the ray equation: */
        Ray ray=getDeviceRay(0);

        /* Find the closest intersection with any screen: */
        std::pair<VRScreen*,Scalar> si=findScreen(ray);

        if(si.first!=0)
        {
            /* Set the virtual input device's transformation: */
            TrackerState ts=TrackerState::translateFromOriginTo(ray(si.second));

            /* Update the virtual input device's transformation: */
            transformedDevice->setTransformation(ts);
            transformedDevice->setDeviceRayDirection(Geometry::normalize(ray.getDirection()));
        }
    }
    else
    {
        /* Set the transformed device to the same position / orientation as the source device: */
        InputDevice* device=input.getDevice(0);
        transformedDevice->setTransformation(device->getTransformation());
        transformedDevice->setDeviceRayDirection(device->getDeviceRayDirection());
    }
}
コード例 #2
0
ToolKillZoneFrustum::ToolKillZoneFrustum(const Misc::ConfigurationFileSection& configFileSection)
	:ToolKillZone(configFileSection),
	 viewer(0),screen(0)
	{
	/* Get the viewer: */
	std::string viewerName=configFileSection.retrieveString("./killZoneViewerName");
	viewer=findViewer(viewerName.c_str());
	if(viewer==0)
		Misc::throwStdErr("ToolKillZoneFrustum::ToolKillZoneFrustum: Viewer %s not found",viewerName.c_str());
	
	/* Get the screen: */
	std::string screenName=configFileSection.retrieveString("./killZoneScreenName");
	screen=findScreen(screenName.c_str());
	if(screen==0)
		Misc::throwStdErr("ToolKillZoneFrustum::ToolKillZoneFrustum: Screen %s not found",screenName.c_str());
	
	/* Read box' center and size: */
	Point boxCenter=configFileSection.retrieveValue<Point>("./killZoneCenter");
	Vector boxSize=configFileSection.retrieveValue<Vector>("./killZoneSize");
	
	/* Transform box center and size to screen coordinates: */
	ONTransform screenT=screen->getScreenTransformation();
	boxCenter=screenT.inverseTransform(boxCenter);
	boxCenter[2]=Scalar(0);
	boxSize=screenT.inverseTransform(boxSize);
	boxSize[2]=Scalar(0);
	box=Box(boxCenter-boxSize*Scalar(0.5),boxCenter+boxSize*Scalar(0.5));
	}
コード例 #3
0
    void updateScreenPosition(const std::string& root, const glm::vec3& newPos)
    {
        int index = findScreen(root);

        if (index == -1)
        {
            JOP_DEBUG_INFO("updateScreen not found: " << root);
            return;
        }

        m_screens[index].obj->setPosition(newPos);
    }
コード例 #4
0
void MouseCursorFaker::glRenderActionTransparent(GLContextData& contextData) const
	{
	/* Get the data item: */
	DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);
	
	/* Calculate the device's ray equation: */
	Ray deviceRay(device->getPosition(),device->getRayDirection());
	
	/* Find the nearest screen intersected by the device ray: */
	std::pair<VRScreen*,Scalar> fsResult=findScreen(deviceRay);
	if(fsResult.first!=0)
		{
		/* Calculate the cursor position on the screen: */
		Point cursorPos=deviceRay(fsResult.second);
		Vector x=fsResult.first->getScreenTransformation().getDirection(0)*cursorSize[0];
		Vector y=fsResult.first->getScreenTransformation().getDirection(1)*cursorSize[1];
		cursorPos-=x*cursorHotspot[0];
		cursorPos-=y*cursorHotspot[1];
		
		/* Draw the mouse cursor: */
		glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT);
		GLdouble depthRange[2];
		glGetDoublev(GL_DEPTH_RANGE,depthRange);
		glDepthRange(0.0,0.0);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId);
		glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GEQUAL,0.5f);
		glDisable(GL_BLEND);
		glDepthMask(GL_TRUE);
		glBegin(GL_QUADS);
		glTexCoord(cursorTexCoordBox.getVertex(0));
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(1));
		cursorPos+=x;
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(3));
		cursorPos+=y;
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(2));
		cursorPos-=x;
		glVertex(cursorPos);
		glEnd();
		glBindTexture(GL_TEXTURE_2D,0);
		glDepthRange(depthRange[0],depthRange[1]);
		glPopAttrib();
		}
	}
コード例 #5
0
Point RayMenuTool::calcHotSpot(void) const
	{
	if(isUseEyeRay()||interactionDevice->isRayDevice())
		{
		/* Find the intersection point of the interaction ray and a screen: */
		std::pair<VRScreen*,Scalar> si=findScreen(GUIInteractor::getRay());
		if(si.first!=0)
			return GUIInteractor::getRay()(si.second);
		else
			return getDisplayCenter();
		}
	else
		{
		/* Return a position in front of the input device: */
		return GUIInteractor::getRay()(factory->initialMenuOffset);
		}
	}
コード例 #6
0
    void setNewMask(const std::string& root, const unsigned int mask)
    {
        int index = findScreen(root);

        if (index == -1)
        {
            JOP_DEBUG_INFO("updateScreen not found: " << root);
            return;
        }

        auto s = m_screens[index];

        for (unsigned int i = 0u; i < s.obj->getChildren().size() - 1u; ++i)
        {
            s.obj->findChild(s.names[i])->getComponent<jop::Text>()->setRenderGroup(mask);
        }
    }
コード例 #7
0
    void updateScreenValues(const std::string& root, const std::vector<int>& newValues)
    {
        int index = findScreen(root);

        if (index == -1)
        {
            JOP_DEBUG_INFO("updateScreen not found: " << root);
            return;
        }

        auto& s = m_screens[index];

        JOP_ASSERT(s.names.size() == newValues.size(), "updateScreen newValues size not matching with old.");

        for (unsigned int i = 0u; i < s.obj->getChildren().size() - 1u; ++i)
        {
            s.obj->findChild(s.names[i])->getComponent<jop::Text>()->setString(std::to_string(newValues[i]));
        }

    }
コード例 #8
0
ファイル: MouseTool.cpp プロジェクト: jrevote/3DA-Vrui
void MouseTool::frame(void)
	{
	/* Get pointer to input device: */
	InputDevice* device=input.getDevice(0);
	
	/* Calculate ray equation: */
	Ray deviceRay(device->getPosition(),device->getRayDirection());
	
	/* Find the closest intersection with any screen: */
	std::pair<VRScreen*,Scalar> si=findScreen(deviceRay);
	
	if(si.first!=0)
		{
		/* Set the virtual input device's transformation: */
		TrackerState ts=TrackerState::translateFromOriginTo(deviceRay(si.second));
		
		/* Update the virtual input device's transformation: */
		transformedDevice->setTransformation(ts);
		transformedDevice->setDeviceRayDirection(Geometry::normalize(deviceRay.getDirection()));
		}
	}
コード例 #9
0
void RayScreenMenuTool::frame(void)
	{
	/* Update the selection ray: */
	selectionRay=calcSelectionRay();
	
	if(factory->interactWithWidgets)
		insideWidget=getWidgetManager()->findPrimaryWidget(selectionRay)!=0;
	
	if(widgetActive)
		{
		/* Deliver the event: */
		GLMotif::Event event(true);
		event.setWorldLocation(selectionRay);
		getWidgetManager()->pointerMotion(event);
		
		if(dragging)
			{
			/* Find the closest intersection with any screen: */
			std::pair<VRScreen*,Scalar> si=findScreen(selectionRay);
			
			if(si.first!=0)
				{
				/* Update the dragged widget's transformation: */
				NavTrackerState current=NavTrackerState::translateFromOriginTo(selectionRay(si.second));
				current*=preScale;
				getWidgetManager()->setPrimaryWidgetTransformation(draggedWidget,GLMotif::WidgetManager::Transformation(current));
				}
			}
		}
	else if(isActive())
		{
		/* Update the selection ray: */
		selectionRay=calcSelectionRay();
		
		/* Deliver the event: */
		GLMotif::Event event(true);
		event.setWorldLocation(selectionRay);
		getWidgetManager()->pointerMotion(event);
		}
	}
コード例 #10
0
void RayScreenMenuTool::buttonCallback(int,int,InputDevice::ButtonCallbackData* cbData)
	{
	if(cbData->newButtonState) // Activation button has just been pressed
		{
		/* Check if the tool is interacting with a widget: */
		if(factory->interactWithWidgets)
			{
			/* If the widget manager accepts the event, preempt any cascaded tools until the button is released: */
			Ray ray=calcSelectionRay();
			GLMotif::Event event(false);
			event.setWorldLocation(ray);
			if(getWidgetManager()->pointerButtonDown(event))
				{
				/* Activate the widget tool: */
				widgetActive=true;
				
				/* Drag the entire root widget if the event's target widget is a title bar: */
				if(dynamic_cast<GLMotif::TitleBar*>(event.getTargetWidget())!=0)
					{
					/* Find the closest intersection with any screen: */
					std::pair<VRScreen*,Scalar> si=findScreen(ray);
					if(si.first!=0)
						{
						/* Start dragging: */
						dragging=true;
						draggedWidget=event.getTargetWidget();
						
						/* Calculate the dragging transformation: */
						NavTrackerState initialTracker=NavTrackerState::translateFromOriginTo(ray(si.second));
						preScale=Geometry::invert(initialTracker);
						GLMotif::WidgetManager::Transformation initialWidget=getWidgetManager()->calcWidgetTransformation(draggedWidget);
						preScale*=NavTrackerState(initialWidget);
						}
					}
				
				/* Cancel processing of this callback to preempt cascaded tools: */
				cbData->callbackList->requestInterrupt();
				}
			}
		
		/* Try activating this tool: */
		if(!widgetActive&&activate())
			{
			/* Calculate the menu selection ray: */
			Ray ray=calcSelectionRay();
			
			/* Find the closest intersection with any screen: */
			std::pair<VRScreen*,Scalar> si=findScreen(ray);
			
			if(si.first!=0)
				{
				typedef GLMotif::WidgetManager::Transformation WTransform;
				typedef WTransform::Point WPoint;
				typedef WTransform::Vector WVector;
				
				/* Calculate the menu transformation: */
				WPoint globalHotSpot=ray(si.second);
				
				/* Try to align the menu with the viewing direction: */
				ONTransform screenT=si.first->getScreenTransformation();
				WTransform menuTransformation=WTransform::translate(globalHotSpot-screenT.getOrigin());
				menuTransformation*=screenT;
				GLMotif::Vector menuHotSpot=menu->getPopup()->calcHotSpot();
				menuTransformation*=WTransform::translate(-WVector(menuHotSpot.getXyzw()));
				
				/* Pop up the menu: */
				getWidgetManager()->popupPrimaryWidget(menu->getPopup(),menuTransformation);
				
				/* Deliver the event: */
				GLMotif::Event event(false);
				event.setWorldLocation(ray);
				getWidgetManager()->pointerButtonDown(event);
				}
			else
				deactivate();
			}
		}
	else // Activation button has just been released
		{
		if(widgetActive)
			{
			/* Deliver the event: */
			GLMotif::Event event(true);
			event.setWorldLocation(calcSelectionRay());
			getWidgetManager()->pointerButtonUp(event);
			
			/* Deactivate this tool: */
			dragging=false;
			widgetActive=false;
			
			/* Cancel processing of this callback to preempt cascaded tools: */
			cbData->callbackList->requestInterrupt();
			}
		else if(isActive())
			{
			/* Deliver the event: */
			GLMotif::Event event(true);
			event.setWorldLocation(calcSelectionRay());
			getWidgetManager()->pointerButtonUp(event);
			
			/* Pop down the menu: */
			getWidgetManager()->popdownWidget(menu->getPopup());
			
			/* Deactivate the tool: */
			deactivate();
			}
		}
	}
コード例 #11
0
void RayMenuTool::buttonCallback(int,InputDevice::ButtonCallbackData* cbData)
	{
	if(cbData->newButtonState) // Button has just been pressed
		{
		/* Check if the GUI interactor refuses the event: */
		GUIInteractor::updateRay();
		if(!(factory->interactWithWidgets&&GUIInteractor::buttonDown(false)))
			{
			/* Try activating this tool: */
			if(GUIInteractor::canActivate()&&activate())
				{
				/***************************************************************
				Pop up the tool's menu at the appropriate position and
				orientation:
				***************************************************************/
				
				if(isUseEyeRay()||interactionDevice->isRayDevice())
					{
					/* Find the intersection point of the interaction ray and a screen: */
					std::pair<VRScreen*,Scalar> si=findScreen(GUIInteractor::getRay());

					/* Pop up the menu: */
					if(si.first!=0)
						popupPrimaryWidget(menu->getPopup(),GUIInteractor::getRay()(si.second),false);
					else
						popupPrimaryWidget(menu->getPopup()); // ,GUIInteractor::getRay().getOrigin());
					}
				else
					{
					/* Pop up the menu: */
					popupPrimaryWidget(menu->getPopup(),GUIInteractor::getRay()(factory->initialMenuOffset),false);
					}
				
				/* Grab the pointer: */
				getWidgetManager()->grabPointer(menu->getPopup());
				
				/* Force the event on the GUI interactor: */
				GUIInteractor::buttonDown(true);
				}
			}
		}
	else // Button has just been released
		{
		/* Check if the GUI interactor is active: */
		if(GUIInteractor::isActive())
			{
			/* Deliver the event: */
			GUIInteractor::buttonUp();
			
			/* Check if the tool's menu is popped up: */
			if(MenuTool::isActive())
				{
				/* Release the pointer: */
				getWidgetManager()->releasePointer(menu->getPopup());
				
				/* Pop down the menu: */
				getWidgetManager()->popdownWidget(menu->getPopup());
				
				/* Deactivate the tool: */
				deactivate();
				}
			}
		}
	}
コード例 #12
0
ファイル: blackbox.cpp プロジェクト: burzumishi/blackbox
void Blackbox::process_event(XEvent *e) {
  switch (e->type) {
  case MapRequest: {
#ifdef    DEBUG
    fprintf(stderr, "Blackbox::process_event(): MapRequest for 0x%lx\n",
            e->xmaprequest.window);
#endif // DEBUG

    BlackboxWindow *win = findWindow(e->xmaprequest.window);

    if (win) {
      if ((!activeScreen() || activeScreen() == win->screen()) &&
          (win->isTransient() || _resource.focusNewWindows()))
        win->activate();
    } else {
      BScreen *screen = findScreen(e->xmaprequest.parent);

      if (! screen) {
        /*
          we got a map request for a window who's parent isn't root. this
          can happen in only one circumstance:

          a client window unmapped a managed window, and then remapped it
          somewhere between unmapping the client window and reparenting it
          to root.

          regardless of how it happens, we need to find the screen that
          the window is on
        */
        XWindowAttributes wattrib;
        if (! XGetWindowAttributes(XDisplay(), e->xmaprequest.window,
                                   &wattrib)) {
          // failed to get the window attributes, perhaps the window has
          // now been destroyed?
          break;
        }

        screen = findScreen(wattrib.root);
        assert(screen != 0); // this should never happen
      }
      screen->addWindow(e->xmaprequest.window);
    }

    break;
  }

  case ConfigureRequest: {
    BlackboxWindow *win = findWindow(e->xconfigurerequest.window);
    if (win) {
      // a window wants to resize
      win->configureRequestEvent(&e->xconfigurerequest);
      break;
    }

    Slit *slit =
      dynamic_cast<Slit *>(findEventHandler(e->xconfigurerequest.parent));
    if (slit) {
      // something in the slit wants to resize
      slit->configureRequestEvent(&e->xconfigurerequest);
      break;
    }

    /*
      handle configure requests for windows that have no EventHandlers
      by simply configuring them as requested.

      note: the event->window parameter points to the window being
      configured, and event->parent points to the window that received
      the event (in this case, the root window, since
      SubstructureRedirect has been selected).
    */
    XWindowChanges xwc;
    xwc.x = e->xconfigurerequest.x;
    xwc.y = e->xconfigurerequest.y;
    xwc.width = e->xconfigurerequest.width;
    xwc.height = e->xconfigurerequest.height;
    xwc.border_width = e->xconfigurerequest.border_width;
    xwc.sibling = e->xconfigurerequest.above;
    xwc.stack_mode = e->xconfigurerequest.detail;
    XConfigureWindow(XDisplay(),
                     e->xconfigurerequest.window,
                     e->xconfigurerequest.value_mask,
                     &xwc);
    break;
  }

  case FocusIn: {
#ifdef FOCUS_DEBUG
    printf("FocusIn : window %8lx mode %s detail %s\n",
           e->xfocus.window, Mode[e->xfocus.mode], Detail[e->xfocus.detail]);
#endif

    if (e->xfocus.mode == NotifyGrab
        || (e->xfocus.detail != NotifyNonlinearVirtual
            && e->xfocus.detail != NotifyVirtual)) {
      /*
        don't process FocusIns when:
        1. they are the result of a grab
        2. the new focus window isn't an ancestor or inferior of the
        old focus window (NotifyNonlinearVirtual and NotifyVirtual)
      */
      break;
    }

    BlackboxWindow *win = findWindow(e->xfocus.window);
    if (!win || win->isFocused())
      break;

#ifdef FOCUS_DEBUG
    printf("          win %p got focus\n", win);
#endif
    win->setFocused(true);
    setFocusedWindow(win);

    /*
      set the event window to None.  when the FocusOut event handler calls
      this function recursively, it uses this as an indication that focus
      has moved to a known window.
    */
    e->xfocus.window = None;

    break;
  }

  case FocusOut: {
#ifdef FOCUS_DEBUG
    printf("FocusOut: window %8lx mode %s detail %s\n",
           e->xfocus.window, Mode[e->xfocus.mode], Detail[e->xfocus.detail]);
#endif

    if (e->xfocus.mode == NotifyGrab
        || (e->xfocus.detail != NotifyNonlinearVirtual
            && e->xfocus.detail != NotifyVirtual)) {
      /*
        don't process FocusOuts when:
        1. they are the result of a grab
        2. the new focus window isn't an ancestor or inferior of the
        old focus window (NotifyNonlinearVirtual and NotifyNonlinearVirtual)
      */
      break;
    }

    BlackboxWindow *win = findWindow(e->xfocus.window);
    if (!win || !win->isFocused())
      break;

    bool lost_focus = true; // did the window really lose focus?
    bool no_focus = true;   // did another window get focus?

    XSync(XDisplay(), False);
    XEvent event;
    if (XCheckIfEvent(XDisplay(), &event, scanForFocusIn, NULL)) {
      process_event(&event);

      if (event.xfocus.window == None)
        no_focus = false;
    } else {
      XWindowAttributes attr;
      Window w;
      int unused;
      XGetInputFocus(XDisplay(), &w, &unused);
      if (w != None
          && XGetWindowAttributes(XDisplay(), w, &attr)
          && attr.override_redirect) {
#ifdef FOCUS_DEBUG
        printf("          focused moved to an override_redirect window\n");
#endif
        lost_focus = (e->xfocus.mode == NotifyNormal);
      }
    }

    if (lost_focus) {
#ifdef FOCUS_DEBUG
      printf("          win %p lost focus\n", win);
#endif
      win->setFocused(false);

      if (no_focus) {
#ifdef FOCUS_DEBUG
        printf("          no window has focus\n");
#endif
        setFocusedWindow(0);
      }
    }

    break;
  }

  default:
    // Send the event through the default EventHandlers.
    bt::Application::process_event(e);
    break;
  } // switch
}