wayland ignores window size requests -> test on macos
This commit is contained in:
+23
-9
@@ -31,12 +31,7 @@ void free_image(Image* image){
|
||||
|
||||
SDL_Window* create_window(const char* title, int w, int h){
|
||||
const SDL_InitFlags init_flags = SDL_INIT_VIDEO | SDL_INIT_EVENTS;
|
||||
const SDL_WindowFlags window_flags = SDL_WINDOW_BORDERLESS
|
||||
// | SDL_WINDOW_MAXIMIZED
|
||||
// | SDL_WINDOW_TRANSPARENT
|
||||
// | SDL_WINDOW_ALWAYS_ON_TOP
|
||||
| SDL_WINDOW_RESIZABLE
|
||||
| SDL_WINDOW_KEYBOARD_GRABBED;
|
||||
const SDL_WindowFlags window_flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE;
|
||||
|
||||
SDL_Init(init_flags);
|
||||
|
||||
@@ -92,6 +87,22 @@ void draw_image(SDL_Surface* surface, Image* image){
|
||||
}
|
||||
}
|
||||
|
||||
int clamp(const int in, const int low, const int high){
|
||||
return in < low ? low : in > high ? high : in;
|
||||
}
|
||||
|
||||
int clamp_low(const int in, const int low){
|
||||
return in < low ? low : in;
|
||||
}
|
||||
|
||||
void on_wheel(SDL_Event* event, SDL_Window* window){
|
||||
printf("a");
|
||||
int last_w, last_h;
|
||||
SDL_GetWindowSize(window, &last_w, &last_h);
|
||||
int new_w = clamp_low(last_w + (int)event->wheel.y, 50);
|
||||
SDL_SetWindowSize(window, new_w, new_w * last_h / last_w);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
if(argc < 2){
|
||||
printf("Usage: %s [image filepath]\n", argv[0]);
|
||||
@@ -146,11 +157,11 @@ int main(int argc, char** argv){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_EVENT_QUIT) run = false;
|
||||
if(event.type == SDL_EVENT_QUIT || event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) run = false;
|
||||
if(event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.button == SDL_BUTTON_LEFT){
|
||||
drag_mouse = true;
|
||||
last_pointer_x = event.motion.x;
|
||||
last_pointer_y = event.motion.y;
|
||||
last_pointer_x = (int)event.motion.x;
|
||||
last_pointer_y = (int)event.motion.y;
|
||||
}
|
||||
if(event.type == SDL_EVENT_MOUSE_BUTTON_UP && event.button.button == SDL_BUTTON_LEFT) drag_mouse = false;
|
||||
if(event.type == SDL_EVENT_MOUSE_MOTION && drag_mouse){
|
||||
@@ -158,6 +169,9 @@ int main(int argc, char** argv){
|
||||
SDL_GetWindowPosition(window, &last_x, &last_y);
|
||||
SDL_SetWindowPosition(window, last_x + (int)event.motion.x - last_pointer_x, last_y + (int)event.motion.y - last_pointer_y);
|
||||
}
|
||||
if(event.type == SDL_EVENT_MOUSE_WHEEL){
|
||||
on_wheel(&event, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user