~strahinja/lav-sdl

c1105ac65b1835b533e225e8c5529671e44ecc21 — Страхиња Радић 6 months ago c696c5a mouse
Only hide mouse pointer when inside the window, don't draw

Signed-off-by: Страхиња Радић <contact@strahinja.org>
1 files changed, 1 insertions(+), 27 deletions(-)

M lav-sdl.c
M lav-sdl.c => lav-sdl.c +1 -27
@@ 100,7 100,6 @@ static SDL_Point* location_stack = NULL;
static SDL_FPoint pointer;
static int help_shown		  = 0;
static int redraw		  = 1;
static int draw_pointer		  = 1;
static SDL_Renderer* renderer	  = NULL;
static int running		  = 1;
static float scale_factor	  = 1.0f;


@@ 329,20 328,6 @@ draw(void)
	if (help_shown)
		draw_help_dialog();

	if (draw_pointer)
	{
		SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
		SDL_RenderDrawLineF(renderer, pointer.x - 10 + 1, pointer.y + 1,
			pointer.x + 10 + 1, pointer.y + 1);
		SDL_RenderDrawLineF(renderer, pointer.x + 1, pointer.y - 10 + 1,
			pointer.x + 1, pointer.y + 10 + 1);
		SDL_SetRenderDrawColor(renderer, 255, 255, 255,
			SDL_ALPHA_OPAQUE);
		SDL_RenderDrawLineF(renderer, pointer.x - 10, pointer.y,
			pointer.x + 10, pointer.y);
		SDL_RenderDrawLineF(renderer, pointer.x, pointer.y - 10,
			pointer.x, pointer.y + 10);
	}
	SDL_RenderPresent(renderer);
	// SDL_RenderFlush(renderer);
}


@@ 575,18 560,9 @@ handle_event(SDL_Event* event)
		if (pointer.x <= 0 || pointer.y <= 0
			|| pointer.x + 1 >= screen_width
			|| pointer.y + 1 >= screen_height)
		{
			// SDL_SetRelativeMouseMode(SDL_FALSE);
			draw_pointer = 0;
			SDL_ShowCursor(1);
		}
		else
		{
			// SDL_SetRelativeMouseMode(SDL_TRUE);
			draw_pointer = 1;
			SDL_ShowCursor(0);
		}
		redraw = 1;
		break;
	}
}


@@ 912,6 888,7 @@ int
main(int argc, char** argv)
{
	SDL_Event event;
	int px, py;

	atexit(&cleanup);



@@ 946,10 923,7 @@ main(int argc, char** argv)
	update_size();
	animation.active = 0;

	// SDL_SetWindowGrab(window, SDL_TRUE);
	// SDL_SetRelativeMouseMode(SDL_TRUE);
	SDL_ShowCursor(0);
	int px, py;
	SDL_GetMouseState(&px, &py);
	pointer.x = (float)px;
	pointer.y = (float)py;