I got strange problems with sf::Event. I'm creating 2 widnows, one for openGL drawings, second is some kind of settings for first one, so you can set parameters to that openGL.
I'm using this function to call updating of second window for main() function, which handles updating the primary one:
void Settings::update(){
Win.SetActive();
const sf::Input& Input = Win.GetInput();
std::ostringstream oss;
// Process events
sf::Event Event;
while (Win.GetEvent(Event)){
if(Event.MouseMoved){
active = Input.GetMouseY() / cellHeight;
}
if ((Event.Key.Code==sf::Key::Return||Event.Key.Code==sf::Key::Right) && !input){
oss << active;
ID += oss.str();
updateText();
}
if (Event.Key.Code==sf::Key::Space||Event.Key.Code==sf::Key::Left||
Event.MouseButton.Button == sf::Mouse::Right){
if(ID.size() > 0)
ID.erase(ID.size()-1);
updateText();
}
if (Event.Key.Code==sf::Key::Up){
active--;
if(active < 0)
active = cellsH-1;
Win.SetCursorPosition(cellWidth/2,active*cellHeight+cellHeight/2);
}
if (Event.Key.Code==sf::Key::Down){
active++;
if(active >= cellsH)
active = 0;
Win.SetCursorPosition(cellWidth/2,active*cellHeight+cellHeight/2);
}
if(Event.MouseButton.Button == sf::Mouse::Left && !input){
active = Event.MouseButton.Y / cellHeight;
oss << active;
ID += oss.str();
updateText();
}
}
}
There's quite much of variables not defined in text because I am using class for second window, however the names should be intuitive. Cells are separated choices to choose in the menu which is specified by ID, and adding active to this ID you go into that choice or back from it.
What's wrong about that is, that when I simply move mouse over window for some time, setting just active(activated cell gets green so just some kind of indicator where are you pointing at), using Event.MouseMoved.
Pressing nothing, moving just mouse it suddenly generates Event.Key.Code=Space etc. jumping into other choices, and as you can see, invalidating my ID because I was just moving mouse, but ID down in menu.
I'll include window creation also:
void Settings::init(){
input = false;
ScreenX = 500;
ScreenY = 600;
sideMargin = 40;
Win.Create(sf::VideoMode(ScreenX, ScreenY, 32), "Settings",sf::Style::Titlebar);
Win.PreserveOpenGLStates(true);
Win.GetDefaultView().SetFromRect(sf::FloatRect(0, 0,(float)ScreenX, (float)ScreenY));
Win.SetActive();
Win.EnableKeyRepeat(false);
fontHeight = ScreenY/4;
std::string fontName = "ARIALN.TTF";
if(!font.LoadFromFile(fontName,fontHeight))
std::cout << "Couldn't load font " << fontName << std::endl;
ID += "0";
prepText = new std::wstring[10];
updateText();
resizeWindow();
}
void Settings::resizeWindow(){
Win.SetSize(ScreenX,ScreenY);
Win.GetDefaultView().SetFromRect(sf::FloatRect(0, 0,(float)ScreenX, (float)ScreenY));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,ScreenX,ScreenY,0);
glGetFloatv (GL_PROJECTION_MATRIX, proj.elements);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( 0, 0, 1, 0, 0, 0, 0, 1, 0);
glGetFloatv (GL_MODELVIEW_MATRIX, model.elements);
}
calling from main looks like this:
Settings uInf;
uInf.init();
while (App.IsOpened())
{
uInf.update();
uInf.render();
}
If you need anything else like screenshot I'll add them, but I think it's just a mistake somewhere. However I searched for it for hours now and I am getting exahusted.