英文:
Detecting mouse clicks for SDL_Surfaces in SDL2
问题
I wanna make a program where if you select a surface it gets put in the selectedPiece variable, but I'm using SDL_PointInRect. And it gives this error "the argument of type "SDL_Surface" is incompatible with parameter of type "const SDL_Rect"" Do you know alternatives to PointInRect that are compatible with Surfaces?
SDL_Surface* selectedPiece;
std::list<SDL_Surface*> pieces;
bool leftClick;
if (SDL_MOUSEBUTTONDOWN)
{
if (!leftClick && windowEvent.button.button == SDL_BUTTON_LEFT)
{
leftClick = true;
for (auto surface : pieces
{
if (SDL_PointInRect(&mousePos, surface)) //<<<--- the sdl point in rect isnt compatible with the surface
{
selectedPiece = surface;
}
}
}
}
英文:
I wanna make a program where if you select a surface it gets put in the selectedPiece variable, but I'm using SDL_PointInRect. And it gives this error "the argument of type "SDL_Surface" is incompatible with parameter of type "const SDL_Rect"" Do you know alternatives to PointInRect that are compatible with Surfaces?
SDL_Surface* selectedPiece;
std::list<SDL_Surface*> pieces;
bool leftClick;
if (SDL_MOUSEBUTTONDOWN)
{
if (!leftClick && windowEvent.button.button == SDL_BUTTON_LEFT)
{
leftClick = true;
for (auto surface : pieces
{
if (SDL_PointInRect(&mousePos, surface)) //<<<--- the sdl point in rect isnt compatible with the surface
{
selectedPiece = surface;
}
}
}
}
答案1
得分: 0
由于您执行了SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
,这意味着目标矩形的左上角位于(0,0)。
正确的检查应该是:
SDL_Rect surfacerect{0, 0, surface->w, surface->h};
if (SDL_PointInRect(&mousePos, &surfacerect))
英文:
Since you SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
it means that the destination rectangle's top left corner is at (0,0).
The proper check would then be:
SDL_Rect surfacerect{0, 0, surface->w, surface->h};
if (SDL_PointInRect(&mousePos, &surfacerect))
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论