Hey, iam back
I Show you my mouse/touch Code with an Button where you can push it
(Android compatible)
nclude <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
SDL_Event event;
SDL_Init(SDL_INIT_EVERYTHING);
//----------------
SDL_Window *window = SDL_CreateWindow("Mouse Test " , 50, 50, 480, 252, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
//----------------
SDL_Surface *background = SDL_LoadBMP("background.bmp");
SDL_Texture *texture_background = SDL_CreateTextureFromSurface(renderer,background);
SDL_Surface *blank_up = SDL_LoadBMP("hwnd_blank_up.bmp");
SDL_Texture *texture_blank_up = SDL_CreateTextureFromSurface(renderer,blank_up);
SDL_Surface *blank_down = SDL_LoadBMP("hwnd_blank_down.bmp");
SDL_Texture *texture_blank_down = SDL_CreateTextureFromSurface(renderer,blank_down);
//-----------------------------------
int hwnd_size_x = 118; // 48 on landsacpe: 118
int hwnd_size_y = 106; // 42 on landscape 106
int mouse_x = 100;
int mouse_y = 100;
int hwnd_button1_x = hwnd_size_x;
int hwnd_button1_y = hwnd_size_y;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
//--------------
int quit = 1;
while(quit == 1)
{
SDL_WaitEvent(&event);
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
quit = 0;
break;
case SDL_MOUSEMOTION:
if (event.type == SDL_MOUSEMOTION )
{
mouse_x = event.motion.x;
mouse_y = event.motion.y;
}
// break;
case SDL_MOUSEBUTTONDOWN:
if (event.type == SDL_MOUSEBUTTONDOWN)
{
mouse_x = event.motion.x;
mouse_y = event.motion.y;
}
//break;
// case SDL_MOUSEBUTTONDOWN:
if (event.type == SDL_MOUSEBUTTONDOWN)
{
if(((( event.type == SDL_MOUSEBUTTONDOWN && mouse_x + 6 >= hwnd_button1_x) &&
(mouse_x +6 <= hwnd_button1_x + hwnd_size_x)) ||
((hwnd_button1_x + hwnd_size_x >= mouse_x) &&
(hwnd_button1_x + hwnd_size_x <= mouse_x + 6))) &&
(((mouse_y + 12 >= hwnd_button1_y)&&
(mouse_y + 12 <= hwnd_button1_y + hwnd_size_y)) ||
((hwnd_button1_y + hwnd_size_y >= mouse_y) &&
(hwnd_button1_y + hwnd_size_y <= mouse_y+ 12))))
{
// collision
quit = 0;
break;
}
}
} // end of switch event
} // end of pollevent
//---------------------------------
SDL_Rect dstrect_back = { 0, 0, 480, 252};
SDL_RenderCopy(renderer,texture_background, NULL, &dstrect_back);
SDL_Rect dstrect0 = { hwnd_button1_x, hwnd_button1_y, hwnd_size_x, hwnd_size_y};
SDL_RenderCopy(renderer,texture_blank_up, NULL, &dstrect0);
SDL_Rect dstrect1 = { hwnd_size_x *1, 0, hwnd_size_x, hwnd_size_y};
SDL_RenderCopy(renderer,texture_blank_up, NULL, &dstrect1);
SDL_Rect dstrect2 = { hwnd_size_x *2, 0, hwnd_size_x, hwnd_size_y};
SDL_RenderCopy(renderer,texture_blank_up, NULL, &dstrect2);
SDL_Rect dstrect3 = { hwnd_size_x *3, 0, hwnd_size_x, hwnd_size_y};
SDL_RenderCopy(renderer,texture_blank_up, NULL, &dstrect3);
//....
SDL_Rect dstrect_m = { mouse_x, mouse_y, 50 , 50} ;
SDL_RenderCopy(renderer,texture_blank_up, NULL, &dstrect_m);
SDL_RenderPresent(renderer);
} //end of whlie_loop
//----------
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Hope you like it
hwnd_blank_up.bmp (6.0 KB)
hwnd_blank_down.bmp (6.0 KB)