gpt4 book ai didi

opengl - SDL 鼠标位置调整大小后裁剪

转载 作者:行者123 更新时间:2023-12-02 01:39:04 24 4
gpt4 key购买 nike

我在 SDL 中的鼠标位置上遇到了一些奇怪的行为。如果我将窗口大小调整得更大,则任一鼠标事件的 x、y 位置似乎都限制为原始窗口的宽度和高度。

如果我缺少一些函数调用来告诉 SDL 鼠标区域的大小已增加。

应用程序的相关部分:

void Resize(int width, int height)
{
WindowWidth = width;
WindowHeight = height;
/* update OpenGL */
}

void Init()
{
glClearColor(0.f, 0.f, 0.f, 1.f);
Resize(WindowWidth, WindowHeight);
}

void MouseClick(int button, int state, int x, int y)
{
unsigned int MouseButton = unsigned(Mouse.z);
unsigned int b = (1 << (button-1));
if (state)
MouseButton = MouseButton | b;
else
MouseButton = MouseButton & (~b);
Mouse.z = MouseButton;
Mouse.x = x;
Mouse.y = y;
}

void MouseMove(int x, int y)
{
MouseRel.x = x - Mouse.x;
MouseRel.y = y - Mouse.y;
Mouse.x = x;
Mouse.y = y;
}

int main(int agrc, char *argv[])
{
bool quit = false;
SDL_Event event;

if ( SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;

if (SDL_SetVideoMode(WindowWidth, WindowHeight, 0, SDL_OPENGL | SDL_RESIZABLE) == NULL)
return 2;

Init();

while (!quit)
{
DrawScene();
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_VIDEORESIZE)
{
Resize(event.resize.w, event.resize.h);
}
else if ( event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP )
{
MouseClick(event.button.button, event.button.state, event.button.x, WindowHeight - event.button.y);
printf("event.button (%i, %i)\n", event.button.x, event.button.y);
MouseHandler();
}
else if ( event.type == SDL_MOUSEMOTION )
{
MouseMove(event.motion.x, WindowHeight - event.motion.y);
printf("event.motion (%i, %i)\n", event.motion.x, event.motion.y);
MouseHandler();
}
else if (event.type == SDL_QUIT)
quit |= true;
}
quit |= KeyboardHandler();
SDL_Delay(10);
}
SDL_Quit();
return 0;
}

最佳答案

尝试重新调用 SDL_SetVideoMode()在您的 SDL_VIDEORESIZE 处理程序中。

关于opengl - SDL 鼠标位置调整大小后裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4272506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com