Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mouse not accurate when using views how can I fix this?  (Read 1441 times)

0 Members and 1 Guest are viewing this topic.

graider

  • Newbie
  • *
  • Posts: 2
    • View Profile
Mouse not accurate when using views how can I fix this?
« 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);

 

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Mouse not accurate when using views how can I fix this?
« Reply #1 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

graider

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Mouse not accurate when using views how can I fix this?
« Reply #2 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

 

anything