SFML community forums

Help => Graphics => Topic started by: graider on October 19, 2013, 07:51:02 pm

Title: Mouse not accurate when using views how can I fix this?
Post by: graider on October 19, 2013, 07:51:02 pm
I have a split view as the code will show below. the mouse seems to only be close to the rect displayed in the center and as it moves towards the edges it drifts farther from the rect. I'm thinking this is caused by the fact that the mouse uses the total window for it positioning but the draw function scales with the view??? is there a way to tie the mouse to a view.

   sf::View tileView, mapView;
   tileView.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
   //tileView.setSize(100, DWIN_HEIGHT);
   mapView.setViewport(sf::FloatRect(0, 0.074f, 1.0f, 1.0f));
   //mapView.setSize(DWIN_WIDTH, DWIN_HEIGHT - (DWIN_HEIGHT/10) );
        ...

      displayWindow.setView(tileView);
      currentLevel->UpdateTileView(pWindow);

      //display are map here
      displayWindow.setView(mapView);
      currentLevel->UpdateMapView(pWindow);

         //event I'm using
            case sf::Event::MouseMoved:
               currentLevel->setTilePosistion(sf::Mouse::getPosition(displayWindow));
               break;

// last but not least drawing the rect
   sf::RectangleShape selector(sf::Vector2f(30, 30));
   selector.setFillColor(sf::Color::Transparent);
   selector.setOutlineColor(sf::Color::Black);
   selector.setOutlineThickness(1.0f);
   selector.setPosition((tileSelectedX), (tileSelectedY));

   window->draw(selector);

 
Title: Re: Mouse not accurate when using views how can I fix this?
Post by: victorlevasseur on October 19, 2013, 08:38:55 pm
I think you should use that function provided just for what you want to do : http://www.sfml-dev.org/documentation/2.1/classsf_1_1RenderTarget.php#a46eb08f775dd1420d6207ea87dde6e54
Title: Re: Mouse not accurate when using views how can I fix this?
Post by: graider on October 19, 2013, 09:27:19 pm
Thanks. This fixed some graphical glitches I was having as well, (rectangle would chop off when moved.)

can fix the same glitches with my other view.
Quote from: victorlevasseur

link=topic=13294.msg93314#msg93314 date=1382207935
I think you should use that function provided just for what you want to do : http://www.sfml-dev.org/documentation/2.1/classsf_1_1RenderTarget.php#a46eb08f775dd1420d6207ea87dde6e54