Jump to content

[SOLVED] getMouseX and Y of the AppWall gui always return zero


photo

Recommended Posts

Hi I'm working with the AppWall plugin and I need to now the mouse coordinates relative of each wall gui. I've attached an example where you can see how the engine.gui.getMouseX() and getMouseY() returns a valid position relative to the primary display. But if you ask to the gui of each wall, always returns zero.

I'm making something wrong or it's a bug of the AppWall plugin.

Thanks

app_wall_01.cpp

app_wall_01.world

Link to comment

Hi Ivan,
 
You can check the getPlayerMouseDirection function inside <SDK>/data/core/utils.h script. Unfortunately, this approach will only work if engine is running in fullscreen mode or when windows are arranged correctly (no gaps in between).
 

int width = engine.app.getWidth();
int height = engine.app.getHeight();
int mouse_x = engine.app.getMouseX();
int mouse_y = engine.app.getMouseY();

int wall_x = clamp(engine.wall.getPrimaryX() + mouse_x / width - (mouse_x < 0),0,engine.wall.getWidth() - 1);
int wall_y = clamp(engine.wall.getPrimaryY() + mouse_y / height - (mouse_y < 0),0,engine.wall.getHeight() - 1);
	
if(engine.wall.getWidth() > 1 || engine.wall.getHeight() > 1) {
	mouse_x -= width * (wall_x - engine.wall.getPrimaryX());
	mouse_y -= height * (wall_y - engine.wall.getPrimaryY());
}
	
labelMousePos.setText(format("x: %d  y: %d",mouse_x,mouse_y));

app_wall_01.cpp

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

First of all thanks for the answer

I've implemented a similar code to calculate the wall mouse position but as you have said this solution only works when the windows are arranged correctly. Now I've found other most important problems with the elements displayed in the wall's gui like WidgetButton or WidgetIcon that I think are related to the fact that the methods getMouseX an Y returns 0. The hover and clicks are not detected in the elements displayed in the wall's gui. I've attached an example where you can watch like the button displayed in the engine.gui works properly but the other can't receive click and hover events. The button displayed in the left top corner always has the hover state because is at (0,0) point.

app_wall_01.cpp

post-1380-0-98404500-1401890707.png

Link to comment

Hi,

 

getMouseX(), getMouseY() returns zero because in AppWall::render_gui only zeroes are passed to the Unigine::Gui::render(). This issue is already submitted to our bug tracker, but we can't promise that it would be fixed in the next sdk update, sorry.

 

You can try to modify AppWall.cpp and calculate correct mouse position for wall gui. Please, check the <SDK>/souce/plugins/App/AppWall/AppWall.cpp on line 977.

 

Sorry for the inconvenience caused.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
  • 1 month later...

Hi Silent,

I've modified the render_gui method as follow and now works properly:

 

void AppWall::render_gui(int index) {
 
   if (!guiEnabled) return;
// check gui
GuiPtr gui = displays[index].gui;
if(gui.get() == NULL) return;
 
// render gui
int button = gui->getMouseButton();
gui->enable(getWidth(),getHeight());
 
   int x = getMouseX();
   int y = getMouseY();
   int wallX = index % wall_width;
   int wallY = index / wall_width;
   x = x + (getWidth() * (primary_x - wallX));
   y = y + (getHeight() * (primary_y - wallY));
 
   gui->render(x,y,button,0);
//gui->render(0,0,0,0);
gui->disable();
gui->setMouseButton(button);
}
 
The variable guiEnabled it's a boolean that it's set to true after start-up. With this modifications i've solved the crash that occurs using WidgetsSprites and the interaction at wall gui.
Thanks
Link to comment
  • 5 weeks later...
×
×
  • Create New...