Region

Asked by Natanael Morais

Match window = new Match();
Location posicao;

                //window is the inicial imagem
                posicao = window.getCenter();

                //the position that I want to clikc
                posicao.x = posicao.x - calculo;

                //creating a new region with the correct position
                Region botao = window.setLocation(posicao);
                botao.hover();
                botao.highlight(5);

In this code, when I use botao.highlight() the mark stays in the center of the image that I want (variable posicao) , but when I use botao.hover() the mouse pointer goes to a different place (the center of the old image - variable window).
What is wrong?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

I cannot reproduce this behaviour with version 1.0.1.
works as expected.

pls. provide more info on your environment.

comments:
--- window.setLocation(posicao)
... modifies the (x,y) top left corner of Region window (which in fact is a Match)

--- Region botao = window.setLocation(posicao)
... does not create a new Region object, but only a new reference to the Region object windows

to create a new Region object:
Region botao = Region.create(window.setLocation(posicao));

But one should not change window, so this is better:
Region botao = Region.create(window); // duplicate Region object
botao.setLocation(posicao);

I guess, that you want to finally click on a point relative to the found match.
For this we have targetOffset:
(simplified Java ;-)
pattern = new Pattern(some_image).targetOffset(xoff, yoff)
match = region.find(pattern)
screen.click(match)

the final click will not click on the centre of the match, but on the point calculated as:
Location(match.getCenter().x + xoff, match.getCenter().y + yoff)

Revision history for this message
Natanael Morais (natanael) said :
#3

RaiMan this function worked very well:
--to create a new Region object:
--Region botao = Region.create(window.setLocation(posicao));"

Thanks a lot, but why this way below is better?
--Region botao = Region.create(window); // duplicate Region object
--botao.setLocation(posicao);

Revision history for this message
RaiMan (raimund-hocke) said :
#4

better or not? you have to decide:

- your version changes the object window (it has a new position afterwards)

- my version first duplicates the object window in a new object, whose location is then changed. My version leaves window object untouched. so when used later, it will still have it's original position.

So if you do not need window at it's original position any longer, both versions have the same effect.

But I recommend to generally use my version: it avoids odd situations, if it is not intended, that an object like window is changed.