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

Author Topic: Cant get TGUI to adjust mouse coords when using a Viewport  (Read 2345 times)

0 Members and 1 Guest are viewing this topic.

ANDO1

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Hi
I'm having a problem with TGUI not adjusting mouse coordinates (responding to button events) when using sf::setViewport, but only on certain machines (windows 7 1366x768).  Note, I have looked at  Topic: Incorrect window mouse coords generated after window resize event but did not find it helpful as it relates to an older version of TGUI )I'm using TGUI-0.6.2). 
I'm trying to display a 1280x1024 picture widget with a button on a 1366x768 sized screen.  Using sf::setView I can get the picture to display correctly (i.e., resized to 1024x768 and positioned in the center of the screen, see newW and displace in minimum code below), but mouse coords are not converted (i.e., pressing the button does not trigger any events, but when I move the mouse pointer to actual screen corrds corresponding to non-resized button coords, I can press the button). 

Below is the minimum code. It works fine when simulating different screen sizes, or different view sizes, on some machines?  Is this a bug or do I have to tell tgui to use resized (viewport) coords?


#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>
#include <windows.h>

int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
{
   // Initialise SFML Render Window
   int   SWidth, SHeight;

   SWidth = GetSystemMetrics(SM_CXSCREEN);      // Problem machine has SWidth = 1366
   SHeight = GetSystemMetrics(SM_CYSCREEN);   //               and SHeight = 768

   // Create Render Window
   sf::RenderWindow window(sf::VideoMode(SWidth,SHeight), "Test", sf::Style::Fullscreen);

   // Determine Viewport size for View = 1280x1024
   float newW = (float)((SHeight*SWidth)/1024);   // For SWidth = 1366, newW = 1024
   float displace = (float)((SWidth-newW)/2);      

   sf::View      SView;  
   // Set view = 1280x1024
   SView.reset(sf::FloatRect(0, 0, 1280, 1024));  
   // Set viewport
   SView.setViewport(sf::FloatRect(displace/SWidth, 0, newW/SWidth, 1.0f));
   window.setView(SView);

   // Create GUI
   tgui::Gui gui(window);

   if (gui.setGlobalFont("../../Fonts/DejaVuSans.ttf") == false)
      return(false);

   // Load an 1280x1024 size form and button
   if (!gui.loadWidgetsFromFile("form.txt"))
      return(false);

   while (window.isOpen())
   {
        sf::Event event;

        while (window.pollEvent(event))
      {
            if (event.type == sf::Event::Closed)
         {
                window.close();
            }
         else if (event.type == sf::Event::KeyPressed)
         {
            switch (event.key.code)
            {
               case sf::Keyboard::Escape:
                  window.close();
                  break;
            }
         }

         gui.handleEvent(event);
        }

     tgui::Callback callback;
     while (gui.pollCallback(callback))
     {
           // Do event handler for gui here
     }
                   
      window.clear();
      gui.draw(false);
      window.display();
   
    }
   return(0);
}

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Cant get TGUI to adjust mouse coords when using a Viewport
« Reply #1 on: April 05, 2014, 11:15:25 am »
TGUI: C++ SFML GUI

 

anything