Its like the title suggests, i want to draw a "1" texture at mouse coords using a keyboard key press. I am using switch statements for input:
switch (e.type)
{
case SDL_QUIT:
{
quit = true;
break;
}
case SDL_MOUSEBUTTONDOWN:
{
switch (e.button.button)
{
case SDL_BUTTON_LEFT:
{
SDL_Rect rect = {e.motion.x - 10, e.motion.y - 10, 20, 20};
SDL_RenderCopy(gRenderer, gT[0], NULL, &rect);
printf("nod\n");
break;
}
}
break;
}
case SDL_KEYDOWN:
{
switch (e.key.keysym.sym)
{
case SDLK_c:
{
SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255);
SDL_RenderClear(gRenderer);
printf("tot ecranul\n");
break;
}
case SDLK_1:
{
SDL_Rect rect = {e.motion.x - 8, e.motion.y - 8, 16, 16};
SDL_RenderCopy(gRenderer, gT[3], NULL, &rect);
printf("1\n");
break;
}
}
break;
}
}
I tried some random things, and no success so far.
gT[3]
is the "1" texture.
CodePudding user response:
e.motion
only makes sense when e
is a mouse event.
Call SDL_GetMouseState
to get the current mouse position.